diff options
author | Patric Stout <truebrain@openttd.org> | 2021-04-26 20:04:02 +0200 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-04-27 20:18:53 +0200 |
commit | 31f1db2d3ab1614f00a08a7f44b518a04aeadd3e (patch) | |
tree | 474f59901b61f9b918ba265c68589613ee3d10c0 /src/network | |
parent | b57d845e55f733514d235e24f64b09a8744f3abc (diff) | |
download | openttd-31f1db2d3ab1614f00a08a7f44b518a04aeadd3e.tar.xz |
Change: no longer use UDP when entering the lobby of a server
The lobby of a server requested some parts via UDP and some via
TCP. This is strictly seen fine, but for future extensions it
is a lot easier if just one protocol is used.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network.cpp | 2 | ||||
-rw-r--r-- | src/network/network_client.cpp | 34 | ||||
-rw-r--r-- | src/network/network_client.h | 3 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 17 | ||||
-rw-r--r-- | src/network/network_gui.h | 2 |
5 files changed, 48 insertions, 10 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index 9a45ce06e..c0b2e06fd 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -598,7 +598,7 @@ public: { _networking = true; new ClientNetworkGameSocketHandler(s); - MyClient::SendCompanyInformationQuery(); + MyClient::SendInformationQuery(); } }; diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index f49692307..af7073e55 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -27,6 +27,7 @@ #include "network.h" #include "network_base.h" #include "network_client.h" +#include "network_gamelist.h" #include "../core/backup_type.hpp" #include "../thread.h" @@ -341,15 +342,18 @@ static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1); * DEF_CLIENT_SEND_COMMAND has no parameters ************/ -/** Query the server for company information. */ -NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyInformationQuery() +/** + * Query the server for server information. + */ +NetworkRecvStatus ClientNetworkGameSocketHandler::SendInformationQuery() { my_client->status = STATUS_COMPANY_INFO; _network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO; SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); - Packet *p = new Packet(PACKET_CLIENT_COMPANY_INFO); - my_client->SendPacket(p); + my_client->SendPacket(new Packet(PACKET_CLIENT_GAME_INFO)); + my_client->SendPacket(new Packet(PACKET_CLIENT_COMPANY_INFO)); + return NETWORK_RECV_STATUS_OKAY; } @@ -571,6 +575,28 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet * return NETWORK_RECV_STATUS_SERVER_BANNED; } +NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p) +{ + if (this->status != STATUS_COMPANY_INFO && this->status != STATUS_INACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; + + NetworkGameList *item = GetLobbyGameInfo(); + + /* Clear any existing GRFConfig chain. */ + ClearGRFConfigList(&item->info.grfconfig); + /* Retrieve the NetworkGameInfo from the packet. */ + DeserializeNetworkGameInfo(p, &item->info); + /* Check for compatability with the client. */ + CheckGameCompatibility(item->info); + /* Ensure we consider the server online. */ + item->online = true; + + SetWindowDirty(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_LOBBY); + + /* We will receive company info next, so keep connection open. */ + if (this->status == STATUS_COMPANY_INFO) return NETWORK_RECV_STATUS_OKAY; + return NETWORK_RECV_STATUS_CLOSE_QUERY; +} + NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(Packet *p) { if (this->status != STATUS_COMPANY_INFO) return NETWORK_RECV_STATUS_MALFORMED_PACKET; diff --git a/src/network/network_client.h b/src/network/network_client.h index d1ffe1c1d..66cdb8ba5 100644 --- a/src/network/network_client.h +++ b/src/network/network_client.h @@ -43,6 +43,7 @@ protected: NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override; NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override; NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override; + NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet *p) override; NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p) override; NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p) override; NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) override; @@ -79,7 +80,7 @@ public: NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override; void ClientError(NetworkRecvStatus res); - static NetworkRecvStatus SendCompanyInformationQuery(); + static NetworkRecvStatus SendInformationQuery(); static NetworkRecvStatus SendJoin(); static NetworkRecvStatus SendCommand(const CommandPacket *cp); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index ebba47d85..57127aee8 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1482,10 +1482,10 @@ struct NetworkLobbyWindow : public Window { break; case WID_NL_REFRESH: // Refresh - NetworkTCPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); // company info - NetworkUDPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); // general data /* Clear the information so removed companies don't remain */ for (auto &company : this->company_info) company = {}; + + NetworkTCPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); break; } } @@ -1553,8 +1553,7 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl) DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_START); DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_GAME); - NetworkTCPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); // company info - NetworkUDPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); // general data + NetworkTCPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); new NetworkLobbyWindow(&_network_lobby_window_desc, ngl); } @@ -1570,6 +1569,16 @@ NetworkCompanyInfo *GetLobbyCompanyInfo(CompanyID company) return (lobby != nullptr && company < MAX_COMPANIES) ? &lobby->company_info[company] : nullptr; } +/** + * Get the game information for the lobby. + * @return the game info struct to write the (downloaded) data to. + */ +NetworkGameList *GetLobbyGameInfo() +{ + NetworkLobbyWindow *lobby = dynamic_cast<NetworkLobbyWindow *>(FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_LOBBY)); + return lobby != nullptr ? lobby->server : nullptr; +} + /* The window below gives information about the connected clients * and also makes able to kick them (if server) and stuff like that. */ diff --git a/src/network/network_gui.h b/src/network/network_gui.h index b8ed68225..e4ccf4e78 100644 --- a/src/network/network_gui.h +++ b/src/network/network_gui.h @@ -15,6 +15,7 @@ #include "../economy_type.h" #include "../window_type.h" #include "network_type.h" +#include "network_gamelist.h" void ShowNetworkNeedPassword(NetworkPasswordType npt); void ShowNetworkChatQueryWindow(DestType type, int dest); @@ -37,5 +38,6 @@ struct NetworkCompanyInfo : NetworkCompanyStats { }; NetworkCompanyInfo *GetLobbyCompanyInfo(CompanyID company); +NetworkGameList *GetLobbyGameInfo(); #endif /* NETWORK_GUI_H */ |