diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index ceb96188..3eb7103b 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -128,7 +128,7 @@ namespace auth const auto offset = sizeof("connect") + 4; proto::network::connect_info info; - if (!info.ParseFromArray(msg->data + offset, msg->cursize - offset)) + if (msg->cursize < offset || !info.ParseFromArray(msg->data + offset, msg->cursize - offset)) { network::send(*from, "error", "Invalid connect data!", '\n'); return; @@ -159,6 +159,13 @@ namespace auth key.set(info.publickey()); const auto xuid = strtoull(steam_id.data(), nullptr, 16); + + if (xuid == auth::get_guid()) + { + network::send(*from, "error", "You are already connected to this server!", '\n'); + return; + } + if (xuid != key.get_hash()) { //MessageBoxA(nullptr, steam_id.data(), std::to_string(key.get_hash()).data(), 0); @@ -228,6 +235,8 @@ namespace auth // Check for sending connect packet utils::hook::set(0x14059A6E0, 0xC301B0); + // Don't instantly timeout the connecting client ? not sure about this + utils::hook::set(0x14025136B, 0xC3); } command::add("guid", []() diff --git a/src/client/component/network.cpp b/src/client/component/network.cpp index 5df17798..c0529c5f 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -96,6 +96,33 @@ 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) + { + // 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; } void on(const std::string& command, const callback& callback) @@ -280,6 +307,10 @@ namespace network const std::string message{data}; console::info(message.data()); }); + + // Use our own socket since the game's socket doesn't work with non localhost addresses + // why? no idea + utils::hook::jump(0x140512B40, create_socket); } } };