iw4x-client/src/Components/Modules/Discovery.cpp

66 lines
1.5 KiB
C++
Raw Normal View History

2016-01-03 13:28:47 -05:00
#include "..\..\STDInclude.hpp"
namespace Components
{
2016-01-03 18:00:07 -05:00
void Discovery::Perform()
{
static bool performing = false;
if (performing) return;
std::async([] ()
{
performing = true;
int start = Game::Com_Milliseconds();
Logger::Print("Starting local server discovery...\n");
//Network::BroadcastAll("discovery\n");
Network::BroadcastRange(28960, 38960, "discovery\n");
Logger::Print("Discovery sent within %dms, awaiting responses...\n", Game::Com_Milliseconds() - start);
performing = false;
});
}
2016-01-03 13:28:47 -05:00
Discovery::Discovery()
{
2016-01-03 18:00:07 -05:00
Network::Handle("discovery", [] (Network::Address address, std::string data)
2016-01-03 13:28:47 -05:00
{
2016-01-03 18:00:07 -05:00
if (address.IsSelf()) return;
if (!address.IsLocal())
{
Logger::Print("Received discovery request from non-local address: %s\n", address.GetString());
return;
}
Logger::Print("Received discovery request from %s\n", address.GetString());
Network::Send(address, "discoveryResponse\n");
});
Network::Handle("discoveryResponse", [] (Network::Address address, std::string data)
{
if (address.IsSelf()) return;
if (!address.IsLocal())
{
Logger::Print("Received discovery response from non-local address: %s\n", address.GetString());
return;
}
Logger::Print("Received discovery response from %s\n", address.GetString());
if (ServerList::IsOfflineList())
{
OutputDebugStringA("Inserting!");
ServerList::InsertRequest(address, true);
}
2016-01-03 13:28:47 -05:00
});
}
Discovery::~Discovery()
{
}
}