diff --git a/src/Components/Modules/Discovery.cpp b/src/Components/Modules/Discovery.cpp index df552d62..aea8ce0f 100644 --- a/src/Components/Modules/Discovery.cpp +++ b/src/Components/Modules/Discovery.cpp @@ -24,8 +24,12 @@ namespace Components int start = Game::Com_Milliseconds(); Logger::Print("Starting local server discovery...\n"); + + Discovery::DiscoveryContainer.Challenge = Utils::VA("%d", Game::Com_Milliseconds()); + //Network::BroadcastAll("discovery\n"); - Network::BroadcastRange(28960, 38960, "discovery\n"); + Network::BroadcastRange(28960, 38960, Utils::VA("discovery\n%s", Discovery::DiscoveryContainer.Challenge.data())); + Logger::Print("Discovery sent within %dms, awaiting responses...\n", Game::Com_Milliseconds() - start); Discovery::DiscoveryContainer.Perform = false; @@ -46,7 +50,7 @@ namespace Components } Logger::Print("Received discovery request from %s\n", address.GetString()); - Network::Send(address, "discoveryResponse\n"); + Network::Send(address, Utils::VA("discoveryResponse\n%s", data.data())); }); Network::Handle("discoveryResponse", [] (Network::Address address, std::string data) @@ -59,7 +63,13 @@ namespace Components return; } - Logger::Print("Received discovery response from %s\n", address.GetString()); + if (Utils::ParseChallenge(data) != Discovery::DiscoveryContainer.Challenge) + { + Logger::Print("Received discovery with invalid challenge from: %s\n", address.GetString()); + return; + } + + Logger::Print("Received discovery response from: %s\n", address.GetString()); if (ServerList::IsOfflineList()) { diff --git a/src/Components/Modules/Discovery.hpp b/src/Components/Modules/Discovery.hpp index 3771225e..3a8b8a5c 100644 --- a/src/Components/Modules/Discovery.hpp +++ b/src/Components/Modules/Discovery.hpp @@ -15,6 +15,7 @@ namespace Components bool Perform; bool Terminate; std::thread* Thread; + std::string Challenge; }; static Container DiscoveryContainer; diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 5837dce4..bd830638 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -249,11 +249,8 @@ namespace Components clientCount = Game::PartyHost_CountMembers((Game::PartyData_s*)0x1081C00); } - // Ensure line break - data.append("\n"); - Utils::InfoString info; - info.Set("challenge", data.substr(0, data.find_first_of("\n")).data()); + info.Set("challenge", Utils::ParseChallenge(data)); info.Set("gamename", "IW4"); info.Set("hostname", Dvar::Var("sv_hostname").Get()); info.Set("gametype", Dvar::Var("g_gametype").Get()); diff --git a/src/Components/Modules/Playlist.cpp b/src/Components/Modules/Playlist.cpp index 32dd57f2..ee60aa66 100644 --- a/src/Components/Modules/Playlist.cpp +++ b/src/Components/Modules/Playlist.cpp @@ -90,7 +90,7 @@ namespace Components if (Playlist::ReceivedPlaylistBuffer.size() == maxBytes) { - Logger::Print("Received playlist response, loading and continuing connection.\n"); + Logger::Print("Received playlist, loading and continuing connection...\n"); Game::Live_ParsePlaylists(Playlist::ReceivedPlaylistBuffer.data()); Party::PlaylistContinue(); diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 00b6d88b..8d0b2bb8 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -457,5 +457,10 @@ namespace Components ServerList::OfflineList.clear(); ServerList::FavouriteList.clear(); ServerList::VisibleList.clear(); + + ServerList::RefreshContainer.Mutex.lock(); + ServerList::RefreshContainer.AwatingList = false; + ServerList::RefreshContainer.Servers.clear(); + ServerList::RefreshContainer.Mutex.unlock(); } } diff --git a/src/Utils/Utils.cpp b/src/Utils/Utils.cpp index 2744b927..4b8e28a6 100644 --- a/src/Utils/Utils.cpp +++ b/src/Utils/Utils.cpp @@ -97,6 +97,13 @@ namespace Utils return LTrim(RTrim(s)); } + std::string ParseChallenge(std::string data) + { + // Ensure line break + data.append("\n"); + return data.substr(0, data.find_first_of("\n")).data(); + } + // Infostring class void InfoString::Set(std::string key, std::string value) { diff --git a/src/Utils/Utils.hpp b/src/Utils/Utils.hpp index bec91d3d..9a49a956 100644 --- a/src/Utils/Utils.hpp +++ b/src/Utils/Utils.hpp @@ -10,6 +10,8 @@ namespace Utils std::string &RTrim(std::string &s); std::string &Trim(std::string &s); + std::string ParseChallenge(std::string data); + class InfoString { public: