(svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.

This commit is contained in:
rubidium 2007-02-02 21:04:50 +00:00
parent 6fd39ebb7c
commit fe996cb13d
5 changed files with 14 additions and 20 deletions

View File

@ -851,14 +851,12 @@ static void NetworkInitialize(void)
// Query a server to fetch his game-info
// If game_info is true, only the gameinfo is fetched,
// else only the client_info is fetched
NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool game_info)
void NetworkTCPQueryServer(const char* host, unsigned short port)
{
if (!_network_available) return NULL;
if (!_network_available) return;
NetworkDisconnect();
if (game_info) return NetworkUDPQueryServer(host, port);
NetworkInitialize();
_network_server = false;
@ -872,8 +870,6 @@ NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool
} else { // No networking, close everything down again
NetworkDisconnect();
}
return NULL;
}
/* Validates an address entered as a string and adds the server to
@ -882,7 +878,6 @@ NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool
void NetworkAddServer(const char *b)
{
if (*b != '\0') {
NetworkGameList *item;
const char *port = NULL;
const char *player = NULL;
char host[NETWORK_HOSTNAME_LENGTH];
@ -896,8 +891,7 @@ void NetworkAddServer(const char *b)
ParseConnectionString(&player, &port, host);
if (port != NULL) rport = atoi(port);
item = NetworkQueryServer(host, rport, true);
item->manually = true;
NetworkUDPQueryServer(host, rport, true);
}
}

View File

@ -163,7 +163,7 @@ VARDEF uint8 _network_autoclean_protected; // Unprotect a company after X mont
VARDEF Year _network_restart_game_year; // If this year is reached, the server automaticly restarts
VARDEF uint8 _network_min_players; // Minimum number of players for game to unpause
NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool game_info);
void NetworkTCPQueryServer(const char* host, unsigned short port);
byte NetworkSpectatorCount(void);

View File

@ -446,7 +446,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
break;
case 17: // Refresh
if (nd->server != NULL)
NetworkQueryServer(nd->server->info.hostname, nd->server->port, true);
NetworkUDPQueryServer(nd->server->info.hostname, nd->server->port);
break;
case 18: // NewGRF Settings
if (nd->server != NULL) ShowNewGRFSettings(false, false, false, &nd->server->info.grfconfig);
@ -945,8 +945,8 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
NetworkClientConnectGame(_network_last_host, _network_last_port);
break;
case 10: /* Refresh */
NetworkQueryServer(_network_last_host, _network_last_port, false); // company info
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
break;
} break;
@ -994,8 +994,8 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
Window *w;
DeleteWindowById(WC_NETWORK_WINDOW, 0);
NetworkQueryServer(_network_last_host, _network_last_port, false); // company info
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
w = AllocateWindowDesc(&_network_lobby_window_desc);
if (w != NULL) {

View File

@ -481,14 +481,14 @@ void NetworkUDPSearchGame(void)
_network_udp_broadcast = 300; // Stay searching for 300 ticks
}
NetworkGameList *NetworkUDPQueryServer(const char* host, unsigned short port)
void NetworkUDPQueryServer(const char* host, unsigned short port, bool manually)
{
struct sockaddr_in out_addr;
NetworkGameList *item;
// No UDP-socket yet..
if (!_udp_client_socket->IsConnected()) {
if (!_udp_client_socket->Listen(0, 0, true)) return NULL;
if (!_udp_client_socket->Listen(0, 0, true)) return;
}
out_addr.sin_family = AF_INET;
@ -500,14 +500,14 @@ NetworkGameList *NetworkUDPQueryServer(const char* host, unsigned short port)
memset(&item->info, 0, sizeof(item->info));
ttd_strlcpy(item->info.server_name, host, lengthof(item->info.server_name));
ttd_strlcpy(item->info.hostname, host, lengthof(item->info.hostname));
item->online = false;
item->online = false;
item->manually = manually;
// Init the packet
Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
_udp_client_socket->SendPacket(&p, &out_addr);
UpdateNetworkGameWindow(false);
return item;
}
/* Remove our advertise from the master-server */

View File

@ -8,7 +8,7 @@
void NetworkUDPInitialize(void);
void NetworkUDPSearchGame(void);
void NetworkUDPQueryMasterServer(void);
NetworkGameList *NetworkUDPQueryServer(const char* host, unsigned short port);
void NetworkUDPQueryServer(const char* host, unsigned short port, bool manually = false);
void NetworkUDPAdvertise(void);
void NetworkUDPRemoveAdvertise(void);
void NetworkUDPShutdown(void);