/** * Threaded part for resolving the IP of a server and querying it. * @param pntr the NetworkUDPQueryServerInfo. */ static void NetworkUDPQueryServerThread(void *pntr) { NetworkUDPQueryServerInfo *info = (NetworkUDPQueryServerInfo*)pntr; NetworkUDPQueryServer(info, true, info->manually); delete info; }
DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_MASTER_RESPONSE_LIST) { /* packet begins with the protocol version (uint8) * then an uint16 which indicates how many * ip:port pairs are in this packet, after that * an uint32 (ip) and an uint16 (port) for each pair. */ ServerListType type = (ServerListType)(p->Recv_uint8() - 1); if (type < SLT_END) { for (int i = p->Recv_uint16(); i != 0 ; i--) { sockaddr_storage addr_storage; memset(&addr_storage, 0, sizeof(addr_storage)); if (type == SLT_IPv4) { addr_storage.ss_family = AF_INET; ((sockaddr_in*)&addr_storage)->sin_addr.s_addr = TO_LE32(p->Recv_uint32()); } else { assert(type == SLT_IPv6); addr_storage.ss_family = AF_INET6; byte *addr = (byte*)&((sockaddr_in6*)&addr_storage)->sin6_addr; for (uint i = 0; i < sizeof(in6_addr); i++) *addr++ = p->Recv_uint8(); } NetworkAddress addr(addr_storage, type == SLT_IPv4 ? sizeof(sockaddr_in) : sizeof(sockaddr_in6)); addr.SetPort(p->Recv_uint16()); /* Somehow we reached the end of the packet */ if (this->HasClientQuit()) return; NetworkUDPQueryServer(addr); } } }
/** Requeries the (game) servers we have not gotten a reply from */ void NetworkGameListRequery() { NetworkGameListHandleDelayedInsert(); static uint8 requery_cnt = 0; if (++requery_cnt < REQUERY_EVERY_X_GAMELOOPS) return; requery_cnt = 0; for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) { item->retries++; if (item->retries < REFRESH_GAMEINFO_X_REQUERIES && (item->online || item->retries >= MAX_GAME_LIST_REQUERY_COUNT)) continue; /* item gets mostly zeroed by NetworkUDPQueryServer */ uint8 retries = item->retries; NetworkUDPQueryServer(NetworkAddress(item->address)); item->retries = (retries >= REFRESH_GAMEINFO_X_REQUERIES) ? 0 : retries; } }