From 1ef4d3cf19160745cd473d5de09f6f53bc6fd240 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 14 Aug 2021 23:24:02 +0200 Subject: [PATCH] Remove: COMPANY_INFO packets and related code (#9475) --- src/network/core/core.h | 2 - src/network/core/tcp_game.cpp | 4 -- src/network/core/tcp_game.h | 40 +----------- src/network/network.cpp | 2 +- src/network/network_client.cpp | 25 +------ src/network/network_client.h | 4 +- src/network/network_server.cpp | 115 --------------------------------- src/network/network_server.h | 2 - 8 files changed, 8 insertions(+), 186 deletions(-) diff --git a/src/network/core/core.h b/src/network/core/core.h index 3e470ef5f1..84d5b62013 100644 --- a/src/network/core/core.h +++ b/src/network/core/core.h @@ -71,8 +71,6 @@ public: * Reopen the socket so we can send/receive stuff again. */ void Reopen() { this->has_quit = false; } - - void SendCompanyInformation(Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len = NETWORK_COMPANY_NAME_LENGTH); }; #endif /* NETWORK_CORE_CORE_H */ diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp index 7a1d183495..9ac53c597f 100644 --- a/src/network/core/tcp_game.cpp +++ b/src/network/core/tcp_game.cpp @@ -73,8 +73,6 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p) case PACKET_SERVER_ERROR: return this->Receive_SERVER_ERROR(p); case PACKET_CLIENT_GAME_INFO: return this->Receive_CLIENT_GAME_INFO(p); case PACKET_SERVER_GAME_INFO: return this->Receive_SERVER_GAME_INFO(p); - case PACKET_CLIENT_COMPANY_INFO: return this->Receive_CLIENT_COMPANY_INFO(p); - case PACKET_SERVER_COMPANY_INFO: return this->Receive_SERVER_COMPANY_INFO(p); case PACKET_SERVER_CLIENT_INFO: return this->Receive_SERVER_CLIENT_INFO(p); case PACKET_SERVER_NEED_GAME_PASSWORD: return this->Receive_SERVER_NEED_GAME_PASSWORD(p); case PACKET_SERVER_NEED_COMPANY_PASSWORD: return this->Receive_SERVER_NEED_COMPANY_PASSWORD(p); @@ -161,8 +159,6 @@ NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p) { ret NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_ERROR); } NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_GAME_INFO); } NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_GAME_INFO); } -NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_COMPANY_INFO); } -NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_INFO); } NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CLIENT_INFO); } NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_GAME_PASSWORD); } NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_NEED_COMPANY_PASSWORD); } diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h index cbef799cf9..833b9077f8 100644 --- a/src/network/core/tcp_game.h +++ b/src/network/core/tcp_game.h @@ -38,9 +38,9 @@ enum PacketGameType { PACKET_CLIENT_JOIN, ///< The client telling the server it wants to join. PACKET_SERVER_ERROR, ///< Server sending an error message to the client. - /* Packets used for the pre-game lobby (unused, but remain for backward/forward compatibility). */ - PACKET_CLIENT_COMPANY_INFO, ///< Request information about all companies. - PACKET_SERVER_COMPANY_INFO, ///< Information about a single company. + /* Unused packet types, formerly used for the pre-game lobby. */ + PACKET_CLIENT_UNUSED, ///< Unused. + PACKET_SERVER_UNUSED, ///< Unused. /* Packets used to get the game info. */ PACKET_SERVER_GAME_INFO, ///< Information about the server. @@ -200,40 +200,6 @@ protected: */ virtual NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet *p); - /** - * Request company information (in detail). - * @param p The packet that was just received. - */ - virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p); - - /** - * Sends information about the companies (one packet per company): - * uint8 Version of the structure of this packet (NETWORK_COMPANY_INFO_VERSION). - * bool Contains data (false marks the end of updates). - * uint8 ID of the company. - * string Name of the company. - * uint32 Year the company was inaugurated. - * uint64 Value. - * uint64 Money. - * uint64 Income. - * uint16 Performance (last quarter). - * bool Company is password protected. - * uint16 Number of trains. - * uint16 Number of lorries. - * uint16 Number of busses. - * uint16 Number of planes. - * uint16 Number of ships. - * uint16 Number of train stations. - * uint16 Number of lorry stations. - * uint16 Number of bus stops. - * uint16 Number of airports and heliports. - * uint16 Number of harbours. - * bool Company is an AI. - * string Client names (comma separated list) - * @param p The packet that was just received. - */ - virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p); - /** * Send information about a client: * uint32 ID of the client (always unique on a server. 1 = server, 0 is invalid). diff --git a/src/network/network.cpp b/src/network/network.cpp index 929e50450f..07b4840d2f 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -640,7 +640,7 @@ public: { _networking = true; new ClientNetworkGameSocketHandler(s, this->connection_string); - MyClient::SendInformationQuery(false); + MyClient::SendInformationQuery(); } }; diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index d2b5b489b2..3196f4ce93 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -331,19 +331,11 @@ static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1); /** * Query the server for server information. */ -NetworkRecvStatus ClientNetworkGameSocketHandler::SendInformationQuery(bool request_company_info) +NetworkRecvStatus ClientNetworkGameSocketHandler::SendInformationQuery() { my_client->status = STATUS_GAME_INFO; my_client->SendPacket(new Packet(PACKET_CLIENT_GAME_INFO)); - if (request_company_info) { - 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); - - my_client->SendPacket(new Packet(PACKET_CLIENT_COMPANY_INFO)); - } - return NETWORK_RECV_STATUS_OKAY; } @@ -567,7 +559,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet * NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p) { - if (this->status != STATUS_COMPANY_INFO && this->status != STATUS_GAME_INFO) return NETWORK_RECV_STATUS_MALFORMED_PACKET; + if (this->status != STATUS_GAME_INFO) return NETWORK_RECV_STATUS_MALFORMED_PACKET; NetworkGameList *item = NetworkGameListAddItem(this->connection_string); @@ -582,17 +574,6 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packe UpdateNetworkGameWindow(); - /* 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; - - /* Unused, but this packet is part of the "this will never change" packet group. */ - return NETWORK_RECV_STATUS_CLOSE_QUERY; } @@ -688,7 +669,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p * NETWORK_ERROR_NOT_EXPECTED on requesting the game info. Show a special * error popup in that case. */ - if (error == NETWORK_ERROR_NOT_EXPECTED && (this->status == STATUS_GAME_INFO || this->status == STATUS_COMPANY_INFO)) { + if (error == NETWORK_ERROR_NOT_EXPECTED && this->status == STATUS_GAME_INFO) { ShowErrorMessage(STR_NETWORK_ERROR_SERVER_TOO_OLD, INVALID_STRING_ID, WL_CRITICAL); return NETWORK_RECV_STATUS_CLOSE_QUERY; } diff --git a/src/network/network_client.h b/src/network/network_client.h index 37deece813..85f954a125 100644 --- a/src/network/network_client.h +++ b/src/network/network_client.h @@ -23,7 +23,6 @@ private: enum ServerStatus { STATUS_INACTIVE, ///< The client is not connected nor active. STATUS_GAME_INFO, ///< We are trying to get the game information. - STATUS_COMPANY_INFO, ///< We are trying to get company information. STATUS_JOIN, ///< We are trying to join a server. STATUS_NEWGRFS_CHECK, ///< Last action was checking NewGRFs. STATUS_AUTH_GAME, ///< Last action was requesting game (server) password. @@ -46,7 +45,6 @@ protected: 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; NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) override; @@ -82,7 +80,7 @@ public: NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override; void ClientError(NetworkRecvStatus res); - static NetworkRecvStatus SendInformationQuery(bool request_company_info); + static NetworkRecvStatus SendInformationQuery(); static NetworkRecvStatus SendJoin(); static NetworkRecvStatus SendCommand(const CommandPacket *cp); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index c817acc900..fecaa2e00a 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -362,64 +362,6 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendGameInfo() return NETWORK_RECV_STATUS_OKAY; } -/** Send the client information about the companies. */ -NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo() -{ - /* Fetch the latest version of the stats */ - NetworkCompanyStats company_stats[MAX_COMPANIES]; - NetworkPopulateCompanyStats(company_stats); - - /* Make a list of all clients per company */ - std::string clients[MAX_COMPANIES]; - - /* Add the local player (if not dedicated) */ - const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER); - if (ci != nullptr && Company::IsValidID(ci->client_playas)) { - clients[ci->client_playas] = ci->client_name; - } - - for (NetworkClientSocket *csi : NetworkClientSocket::Iterate()) { - std::string client_name = static_cast(csi)->GetClientName(); - - ci = csi->GetInfo(); - if (ci != nullptr && Company::IsValidID(ci->client_playas)) { - if (!clients[ci->client_playas].empty()) { - clients[ci->client_playas] += ", "; - } - - clients[ci->client_playas] += client_name; - } - } - - /* Now send the data */ - - Packet *p; - - for (const Company *company : Company::Iterate()) { - p = new Packet(PACKET_SERVER_COMPANY_INFO); - - p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION); - p->Send_bool (true); - this->SendCompanyInformation(p, company, &company_stats[company->index]); - - if (clients[company->index].empty()) { - p->Send_string(""); - } else { - p->Send_string(clients[company->index]); - } - - this->SendPacket(p); - } - - p = new Packet(PACKET_SERVER_COMPANY_INFO); - - p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION); - p->Send_bool (false); - - this->SendPacket(p); - return NETWORK_RECV_STATUS_OKAY; -} - /** * Send an error to the client, and close its connection. * @param error The error to disconnect for. @@ -835,11 +777,6 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(Packe return this->SendGameInfo(); } -NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO(Packet *p) -{ - return this->SendCompanyInfo(); -} - NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) { if (this->status != STATUS_NEWGRFS_CHECK) { @@ -1446,58 +1383,6 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p) return NETWORK_RECV_STATUS_OKAY; } -/** - * Package some generic company information into a packet. - * @param p The packet that will contain the data. - * @param c The company to put the of into the packet. - * @param stats The statistics to put in the packet. - * @param max_len The maximum length of the company name. - */ -void NetworkSocketHandler::SendCompanyInformation(Packet *p, const Company *c, const NetworkCompanyStats *stats, uint max_len) -{ - /* Grab the company name */ - char company_name[NETWORK_COMPANY_NAME_LENGTH]; - SetDParam(0, c->index); - - assert(max_len <= lengthof(company_name)); - GetString(company_name, STR_COMPANY_NAME, company_name + max_len - 1); - - /* Get the income */ - Money income = 0; - if (_cur_year - 1 == c->inaugurated_year) { - /* The company is here just 1 year, so display [2], else display[1] */ - for (uint i = 0; i < lengthof(c->yearly_expenses[2]); i++) { - income -= c->yearly_expenses[2][i]; - } - } else { - for (uint i = 0; i < lengthof(c->yearly_expenses[1]); i++) { - income -= c->yearly_expenses[1][i]; - } - } - - /* Send the information */ - p->Send_uint8 (c->index); - p->Send_string(company_name); - p->Send_uint32(c->inaugurated_year); - p->Send_uint64(c->old_economy[0].company_value); - p->Send_uint64(c->money); - p->Send_uint64(income); - p->Send_uint16(c->old_economy[0].performance_history); - - /* Send 1 if there is a password for the company else send 0 */ - p->Send_bool (!_network_company_states[c->index].password.empty()); - - for (uint i = 0; i < NETWORK_VEH_END; i++) { - p->Send_uint16(stats->num_vehicle[i]); - } - - for (uint i = 0; i < NETWORK_VEH_END; i++) { - p->Send_uint16(stats->num_station[i]); - } - - p->Send_bool(c->is_ai); -} - /** * Populate the company stats. * @param stats the stats to update diff --git a/src/network/network_server.h b/src/network/network_server.h index 76bc95dbc9..419d1e6be0 100644 --- a/src/network/network_server.h +++ b/src/network/network_server.h @@ -25,7 +25,6 @@ class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem< protected: NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p) override; NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet *p) override; - NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p) override; NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p) override; NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p) override; NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p) override; @@ -42,7 +41,6 @@ protected: NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p) override; NetworkRecvStatus SendGameInfo(); - NetworkRecvStatus SendCompanyInfo(); NetworkRecvStatus SendNewGRFCheck(); NetworkRecvStatus SendWelcome(); NetworkRecvStatus SendNeedGamePassword();