mirror of https://github.com/OpenTTD/OpenTTD
(svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
parent
07b9d95c3c
commit
6a820a30d1
|
@ -851,14 +851,12 @@ static void NetworkInitialize(void)
|
||||||
// Query a server to fetch his game-info
|
// Query a server to fetch his game-info
|
||||||
// If game_info is true, only the gameinfo is fetched,
|
// If game_info is true, only the gameinfo is fetched,
|
||||||
// else only the client_info 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();
|
NetworkDisconnect();
|
||||||
|
|
||||||
if (game_info) return NetworkUDPQueryServer(host, port);
|
|
||||||
|
|
||||||
NetworkInitialize();
|
NetworkInitialize();
|
||||||
|
|
||||||
_network_server = false;
|
_network_server = false;
|
||||||
|
@ -872,8 +870,6 @@ NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool
|
||||||
} else { // No networking, close everything down again
|
} else { // No networking, close everything down again
|
||||||
NetworkDisconnect();
|
NetworkDisconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validates an address entered as a string and adds the server to
|
/* 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)
|
void NetworkAddServer(const char *b)
|
||||||
{
|
{
|
||||||
if (*b != '\0') {
|
if (*b != '\0') {
|
||||||
NetworkGameList *item;
|
|
||||||
const char *port = NULL;
|
const char *port = NULL;
|
||||||
const char *player = NULL;
|
const char *player = NULL;
|
||||||
char host[NETWORK_HOSTNAME_LENGTH];
|
char host[NETWORK_HOSTNAME_LENGTH];
|
||||||
|
@ -896,8 +891,7 @@ void NetworkAddServer(const char *b)
|
||||||
ParseConnectionString(&player, &port, host);
|
ParseConnectionString(&player, &port, host);
|
||||||
if (port != NULL) rport = atoi(port);
|
if (port != NULL) rport = atoi(port);
|
||||||
|
|
||||||
item = NetworkQueryServer(host, rport, true);
|
NetworkUDPQueryServer(host, rport, true);
|
||||||
item->manually = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 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
|
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);
|
byte NetworkSpectatorCount(void);
|
||||||
|
|
||||||
|
|
|
@ -446,7 +446,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
|
||||||
break;
|
break;
|
||||||
case 17: // Refresh
|
case 17: // Refresh
|
||||||
if (nd->server != NULL)
|
if (nd->server != NULL)
|
||||||
NetworkQueryServer(nd->server->info.hostname, nd->server->port, true);
|
NetworkUDPQueryServer(nd->server->info.hostname, nd->server->port);
|
||||||
break;
|
break;
|
||||||
case 18: // NewGRF Settings
|
case 18: // NewGRF Settings
|
||||||
if (nd->server != NULL) ShowNewGRFSettings(false, false, false, &nd->server->info.grfconfig);
|
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);
|
NetworkClientConnectGame(_network_last_host, _network_last_port);
|
||||||
break;
|
break;
|
||||||
case 10: /* Refresh */
|
case 10: /* Refresh */
|
||||||
NetworkQueryServer(_network_last_host, _network_last_port, false); // company info
|
NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
|
||||||
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
|
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
|
||||||
break;
|
break;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
@ -994,8 +994,8 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
|
||||||
Window *w;
|
Window *w;
|
||||||
DeleteWindowById(WC_NETWORK_WINDOW, 0);
|
DeleteWindowById(WC_NETWORK_WINDOW, 0);
|
||||||
|
|
||||||
NetworkQueryServer(_network_last_host, _network_last_port, false); // company info
|
NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
|
||||||
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
|
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
|
||||||
|
|
||||||
w = AllocateWindowDesc(&_network_lobby_window_desc);
|
w = AllocateWindowDesc(&_network_lobby_window_desc);
|
||||||
if (w != NULL) {
|
if (w != NULL) {
|
||||||
|
|
|
@ -481,14 +481,14 @@ void NetworkUDPSearchGame(void)
|
||||||
_network_udp_broadcast = 300; // Stay searching for 300 ticks
|
_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;
|
struct sockaddr_in out_addr;
|
||||||
NetworkGameList *item;
|
NetworkGameList *item;
|
||||||
|
|
||||||
// No UDP-socket yet..
|
// No UDP-socket yet..
|
||||||
if (!_udp_client_socket->IsConnected()) {
|
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;
|
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));
|
memset(&item->info, 0, sizeof(item->info));
|
||||||
ttd_strlcpy(item->info.server_name, host, lengthof(item->info.server_name));
|
ttd_strlcpy(item->info.server_name, host, lengthof(item->info.server_name));
|
||||||
ttd_strlcpy(item->info.hostname, host, lengthof(item->info.hostname));
|
ttd_strlcpy(item->info.hostname, host, lengthof(item->info.hostname));
|
||||||
item->online = false;
|
item->online = false;
|
||||||
|
item->manually = manually;
|
||||||
|
|
||||||
// Init the packet
|
// Init the packet
|
||||||
Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
|
Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
|
||||||
_udp_client_socket->SendPacket(&p, &out_addr);
|
_udp_client_socket->SendPacket(&p, &out_addr);
|
||||||
|
|
||||||
UpdateNetworkGameWindow(false);
|
UpdateNetworkGameWindow(false);
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove our advertise from the master-server */
|
/* Remove our advertise from the master-server */
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
void NetworkUDPInitialize(void);
|
void NetworkUDPInitialize(void);
|
||||||
void NetworkUDPSearchGame(void);
|
void NetworkUDPSearchGame(void);
|
||||||
void NetworkUDPQueryMasterServer(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 NetworkUDPAdvertise(void);
|
||||||
void NetworkUDPRemoveAdvertise(void);
|
void NetworkUDPRemoveAdvertise(void);
|
||||||
void NetworkUDPShutdown(void);
|
void NetworkUDPShutdown(void);
|
||||||
|
|
Loading…
Reference in New Issue