示例#1
0
/**
 * Helper function doing the actual work for querying the server.
 * @param address The address of the server.
 * @param needs_mutex Whether we need to acquire locks when sending the packet or not.
 * @param manually Whether the address was entered manually.
 */
static void NetworkUDPQueryServer(NetworkAddress *address, bool needs_mutex, bool manually)
{
	/* Clear item in gamelist */
	NetworkGameList *item = CallocT<NetworkGameList>(1);
	address->GetAddressAsString(item->info.server_name, lastof(item->info.server_name));
	strecpy(item->info.hostname, address->GetHostname(), lastof(item->info.hostname));
	item->address = *address;
	item->manually = manually;
	NetworkGameListAddItemDelayed(item);

	if (needs_mutex) _network_udp_mutex->BeginCritical();
	/* Init the packet */
	Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
	if (_udp_client_socket != NULL) _udp_client_socket->SendPacket(&p, address);
	if (needs_mutex) _network_udp_mutex->EndCritical();
}
示例#2
0
/**
 * 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;

	/* Clear item in gamelist */
	NetworkGameList *item = CallocT<NetworkGameList>(1);
	item->address = *info;
	info->GetAddressAsString(item->info.server_name, lastof(item->info.server_name));
	strecpy(item->info.hostname, info->GetHostname(), lastof(item->info.hostname));
	item->manually = info->manually;
	NetworkGameListAddItemDelayed(item);

	_network_udp_mutex->BeginCritical();
	/* Init the packet */
	Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
	if (_udp_client_socket != NULL) _udp_client_socket->SendPacket(&p, info);
	_network_udp_mutex->EndCritical();

	delete info;
}