| 44 | } |
| 45 | |
| 46 | void CServerList::ParsePacket(CDataReader &reader) |
| 47 | { |
| 48 | m_Servers.clear(); |
| 49 | g_ServerList.LastServerIndex = 0; |
| 50 | |
| 51 | reader.Move(1); |
| 52 | |
| 53 | uint16_t numServers = reader.ReadUInt16BE(); |
| 54 | |
| 55 | if (numServers == 0) |
| 56 | { |
| 57 | Warning(Network, "empty server list"); |
| 58 | } |
| 59 | |
| 60 | for (uint16_t i = 0; i < numServers; i++) |
| 61 | { |
| 62 | uint16_t id = reader.ReadUInt16BE(); |
| 63 | auto name = reader.ReadString(32); |
| 64 | uint8_t fullPercent = reader.ReadUInt8(); |
| 65 | uint8_t timezoneType = reader.ReadUInt8(); |
| 66 | uint32_t ip = reader.ReadUInt32LE(); //little-endian!!! |
| 67 | |
| 68 | const bool selected = (name == g_ServerList.LastServerName); |
| 69 | if (selected) |
| 70 | { |
| 71 | g_ServerList.LastServerIndex = (int)i; |
| 72 | } |
| 73 | m_Servers.push_back(CServer(id, name, fullPercent, timezoneType, ip, selected)); |
| 74 | |
| 75 | #if USE_PING |
| 76 | if (!g_DisablePing) |
| 77 | { |
| 78 | char ipString[30] = { 0 }; |
| 79 | sprintf_s( |
| 80 | ipString, |
| 81 | "%i.%i.%i.%i", |
| 82 | (ip >> 24) & 0xFF, |
| 83 | (ip >> 16) & 0xFF, |
| 84 | (ip >> 8) & 0xFF, |
| 85 | ip & 0xFF); |
| 86 | CPingThread *pingThread = new CPingThread(i, ipString, 100); |
| 87 | pingThread->Run(); |
| 88 | } |
| 89 | #endif // USE_PING |
| 90 | } |
| 91 | |
| 92 | if (g_ServerList.LastServerIndex < numServers && g_MainScreen.m_AutoLogin->Checked) |
| 93 | { |
| 94 | g_Game.ServerSelection(g_ServerList.LastServerIndex); |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | g_Game.InitScreen(GS_SERVER); |
| 99 | } |
| 100 | |
| 101 | g_ServerScreen.UpdateContent(); |
| 102 | } |
| 103 |
no test coverage detected