From 0eda36b7a180124826989800a2caaf51a1e7d260 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 28 Feb 2022 15:07:22 +0100 Subject: [PATCH] Fix --- src/client/component/network.cpp | 50 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/client/component/network.cpp b/src/client/component/network.cpp index 335255d7..4baa57b2 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -102,33 +102,35 @@ namespace network // Rather than try and let the player in, just tell them they are a duplicate player and reject connection game::NET_OutOfBandPrint(game::NS_SERVER, from, "error\nYou are already connected to the server."); } - SOCKET create_socket(const char* net_interface, int port, int protocol) - { - sockaddr_in address{}; - if (net_interface && net_interface != "localhost"s) + SOCKET create_socket(const char* net_interface, int port, int protocol) { - // Sys_StringToSockaddr - utils::hook::invoke(0x1404F6580, net_interface, &address); + sockaddr_in address{}; + + if (net_interface && net_interface != "localhost"s) + { + // Sys_StringToSockaddr + utils::hook::invoke(0x1404F6580, net_interface, &address); + } + + address.sin_family = AF_INET; + address.sin_port = ntohs(port); + + const auto sock = ::socket(AF_INET, SOCK_DGRAM, protocol); + + u_long arg = 1; + ioctlsocket(sock, FIONBIO, &arg); + char optval[4] = { 1 }; + setsockopt(sock, 0xFFFF, 32, optval, 4); + + if (bind(sock, reinterpret_cast(&address), sizeof(address)) != -1) + { + return sock; + } + + closesocket(sock); + return 0; } - - address.sin_family = AF_INET; - address.sin_port = ntohs(port); - - const auto sock = ::socket(AF_INET, SOCK_DGRAM, protocol); - - u_long arg = 1; - ioctlsocket(sock, FIONBIO, &arg); - char optval[4] = {1}; - setsockopt(sock, 0xFFFF, 32, optval, 4); - - if (bind(sock, reinterpret_cast(&address), sizeof(address)) != -1) - { - return sock; - } - - closesocket(sock); - return 0; } void on(const std::string& command, const callback& callback)