Mercurial > hg > openttd
changeset 5916:33f17e261853 draft
(svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 02 Feb 2007 21:04:50 +0000 |
parents | 83c7ced841a0 |
children | ad77d11aeccf |
files | src/network/network.cpp src/network/network.h src/network/network_gui.cpp src/network/network_udp.cpp src/network/network_udp.h |
diffstat | 5 files changed, 14 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -851,14 +851,12 @@ // 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 @@ } 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 @@ 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 @@ ParseConnectionString(&player, &port, host); if (port != NULL) rport = atoi(port); - item = NetworkQueryServer(host, rport, true); - item->manually = true; + NetworkUDPQueryServer(host, rport, true); } }
--- a/src/network/network.h +++ b/src/network/network.h @@ -163,7 +163,7 @@ 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);
--- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -446,7 +446,7 @@ 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 @@ 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 @@ 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) {
--- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -481,14 +481,14 @@ _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 @@ 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 */
--- a/src/network/network_udp.h +++ b/src/network/network_udp.h @@ -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);