Correct server parsing.
This commit is contained in:
parent
03fac2e637
commit
b6ee7e3ea8
@ -139,41 +139,28 @@ namespace Components
|
|||||||
|
|
||||||
ServerList::RefreshContainer.Mutex.lock();
|
ServerList::RefreshContainer.Mutex.lock();
|
||||||
|
|
||||||
// Is this safe? If server ip/port is encoded as '\', it might fail
|
ServerList::MasterEntry* entry = (ServerList::MasterEntry*)data.data();
|
||||||
// TODO: Rather parse six bytes and skip the seventh
|
|
||||||
auto servers = Utils::Explode(data, '\\');
|
|
||||||
|
|
||||||
if (servers.size())
|
for (int i = 0; !entry[i].IsEndToken() && entry[i].HasSeparator(); i++)
|
||||||
{
|
{
|
||||||
if (servers[servers.size() - 1] == "EOT")
|
Network::Address serverAddr = address;
|
||||||
{
|
serverAddr.SetIP(entry[i].IP);
|
||||||
Logger::Print("We got an invalid response from the master. Trying to parse it anyways...\n");
|
serverAddr.SetPort(entry[i].Port);
|
||||||
}
|
serverAddr.Get()->type = Game::NA_IP;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < servers.size() - 1; i++)
|
ServerList::Container::ServerContainer container;
|
||||||
{
|
container.SendTime = Game::Com_Milliseconds();
|
||||||
const char* server = servers[i].data();
|
container.Challenge = Utils::VA("%d", container.SendTime);
|
||||||
|
container.Sent = true;
|
||||||
|
container.Target = serverAddr;
|
||||||
|
|
||||||
DWORD ip = *(DWORD*)server;
|
ServerList::RefreshContainer.Servers.push_back(container);
|
||||||
uint16_t port = *(uint16_t*)(server + 4);
|
|
||||||
|
|
||||||
Network::Address serverAddr = address;
|
Network::Send(container.Target, Utils::VA("getinfo %s\n", container.Challenge.data()));
|
||||||
serverAddr.SetIP(ip);
|
|
||||||
serverAddr.SetPort(port);
|
|
||||||
serverAddr.Get()->type = Game::NA_IP;
|
|
||||||
|
|
||||||
ServerList::Container::ServerContainer container;
|
|
||||||
container.SendTime = Game::Com_Milliseconds();
|
|
||||||
container.Challenge = Utils::VA("%d", container.SendTime);
|
|
||||||
container.Sent = true;
|
|
||||||
container.Target = serverAddr;
|
|
||||||
|
|
||||||
ServerList::RefreshContainer.Servers.push_back(container);
|
|
||||||
|
|
||||||
Network::Send(container.Target, Utils::VA("getinfo %s\n", container.Challenge.data()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger::Print("Parsed %d servers from master\n", ServerList::RefreshContainer.Servers.size());
|
||||||
|
|
||||||
ServerList::RefreshContainer.Mutex.unlock();
|
ServerList::RefreshContainer.Mutex.unlock();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -37,6 +37,29 @@ namespace Components
|
|||||||
Ping,
|
Ping,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
union MasterEntry
|
||||||
|
{
|
||||||
|
char Token[7];
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint32_t IP;
|
||||||
|
uint16_t Port;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool IsEndToken()
|
||||||
|
{
|
||||||
|
// End of transmission token
|
||||||
|
return (Token[0] == 'E' && Token[1] == 'O' && Token[2] == 'T');
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HasSeparator()
|
||||||
|
{
|
||||||
|
return (Token[6] == '\\');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
struct Container
|
struct Container
|
||||||
{
|
{
|
||||||
struct ServerContainer
|
struct ServerContainer
|
||||||
|
Loading…
Reference in New Issue
Block a user