mirror of https://github.com/OpenTTD/OpenTTD.git
Remove: COMPANY_INFO packets and related code (#9475)
This commit is contained in:
parent
3d55ea2d4d
commit
1ef4d3cf19
|
@ -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 */
|
||||
|
|
|
@ -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); }
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -640,7 +640,7 @@ public:
|
|||
{
|
||||
_networking = true;
|
||||
new ClientNetworkGameSocketHandler(s, this->connection_string);
|
||||
MyClient::SendInformationQuery(false);
|
||||
MyClient::SendInformationQuery();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ServerNetworkGameSocketHandler*>(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("<none>");
|
||||
} 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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue