Fixes and stuff.

This commit is contained in:
momo5502 2016-01-04 11:32:05 +01:00
parent c392eba620
commit 1e3a832be7
7 changed files with 30 additions and 8 deletions

View File

@ -24,8 +24,12 @@ namespace Components
int start = Game::Com_Milliseconds(); int start = Game::Com_Milliseconds();
Logger::Print("Starting local server discovery...\n"); Logger::Print("Starting local server discovery...\n");
Discovery::DiscoveryContainer.Challenge = Utils::VA("%d", Game::Com_Milliseconds());
//Network::BroadcastAll("discovery\n"); //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); Logger::Print("Discovery sent within %dms, awaiting responses...\n", Game::Com_Milliseconds() - start);
Discovery::DiscoveryContainer.Perform = false; Discovery::DiscoveryContainer.Perform = false;
@ -46,7 +50,7 @@ namespace Components
} }
Logger::Print("Received discovery request from %s\n", address.GetString()); 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) Network::Handle("discoveryResponse", [] (Network::Address address, std::string data)
@ -59,7 +63,13 @@ namespace Components
return; 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()) if (ServerList::IsOfflineList())
{ {

View File

@ -15,6 +15,7 @@ namespace Components
bool Perform; bool Perform;
bool Terminate; bool Terminate;
std::thread* Thread; std::thread* Thread;
std::string Challenge;
}; };
static Container DiscoveryContainer; static Container DiscoveryContainer;

View File

@ -249,11 +249,8 @@ namespace Components
clientCount = Game::PartyHost_CountMembers((Game::PartyData_s*)0x1081C00); clientCount = Game::PartyHost_CountMembers((Game::PartyData_s*)0x1081C00);
} }
// Ensure line break
data.append("\n");
Utils::InfoString info; 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("gamename", "IW4");
info.Set("hostname", Dvar::Var("sv_hostname").Get<const char*>()); info.Set("hostname", Dvar::Var("sv_hostname").Get<const char*>());
info.Set("gametype", Dvar::Var("g_gametype").Get<const char*>()); info.Set("gametype", Dvar::Var("g_gametype").Get<const char*>());

View File

@ -90,7 +90,7 @@ namespace Components
if (Playlist::ReceivedPlaylistBuffer.size() == maxBytes) 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()); Game::Live_ParsePlaylists(Playlist::ReceivedPlaylistBuffer.data());
Party::PlaylistContinue(); Party::PlaylistContinue();

View File

@ -457,5 +457,10 @@ namespace Components
ServerList::OfflineList.clear(); ServerList::OfflineList.clear();
ServerList::FavouriteList.clear(); ServerList::FavouriteList.clear();
ServerList::VisibleList.clear(); ServerList::VisibleList.clear();
ServerList::RefreshContainer.Mutex.lock();
ServerList::RefreshContainer.AwatingList = false;
ServerList::RefreshContainer.Servers.clear();
ServerList::RefreshContainer.Mutex.unlock();
} }
} }

View File

@ -97,6 +97,13 @@ namespace Utils
return LTrim(RTrim(s)); 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 // Infostring class
void InfoString::Set(std::string key, std::string value) void InfoString::Set(std::string key, std::string value)
{ {

View File

@ -10,6 +10,8 @@ namespace Utils
std::string &RTrim(std::string &s); std::string &RTrim(std::string &s);
std::string &Trim(std::string &s); std::string &Trim(std::string &s);
std::string ParseChallenge(std::string data);
class InfoString class InfoString
{ {
public: public: