Correct server parsing.
This commit is contained in:
parent
03fac2e637
commit
b6ee7e3ea8
@ -139,27 +139,13 @@ namespace Components
|
||||
|
||||
ServerList::RefreshContainer.Mutex.lock();
|
||||
|
||||
// Is this safe? If server ip/port is encoded as '\', it might fail
|
||||
// TODO: Rather parse six bytes and skip the seventh
|
||||
auto servers = Utils::Explode(data, '\\');
|
||||
ServerList::MasterEntry* entry = (ServerList::MasterEntry*)data.data();
|
||||
|
||||
if (servers.size())
|
||||
for (int i = 0; !entry[i].IsEndToken() && entry[i].HasSeparator(); i++)
|
||||
{
|
||||
if (servers[servers.size() - 1] == "EOT")
|
||||
{
|
||||
Logger::Print("We got an invalid response from the master. Trying to parse it anyways...\n");
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < servers.size() - 1; i++)
|
||||
{
|
||||
const char* server = servers[i].data();
|
||||
|
||||
DWORD ip = *(DWORD*)server;
|
||||
uint16_t port = *(uint16_t*)(server + 4);
|
||||
|
||||
Network::Address serverAddr = address;
|
||||
serverAddr.SetIP(ip);
|
||||
serverAddr.SetPort(port);
|
||||
serverAddr.SetIP(entry[i].IP);
|
||||
serverAddr.SetPort(entry[i].Port);
|
||||
serverAddr.Get()->type = Game::NA_IP;
|
||||
|
||||
ServerList::Container::ServerContainer container;
|
||||
@ -172,7 +158,8 @@ namespace Components
|
||||
|
||||
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();
|
||||
});
|
||||
|
@ -37,6 +37,29 @@ namespace Components
|
||||
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 ServerContainer
|
||||
|
Loading…
Reference in New Issue
Block a user