diff options
author | rubidium <rubidium@openttd.org> | 2011-10-15 20:42:32 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-10-15 20:42:32 +0000 |
commit | de27205e6c8aec594f7ae3b8205e8a1d60c24751 (patch) | |
tree | 84a180f9001812109677d95c57ee446178dada0d /src | |
parent | 16e1314f58fa96915d79ca8419465ab2e5e8639e (diff) | |
download | openttd-de27205e6c8aec594f7ae3b8205e8a1d60c24751.tar.xz |
(svn r23031) -Fix [FS#4804]: for the admin "bots" there was no distinction between bankruptcy and manual removal of companies even though the API suggested that
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/ai_gui.cpp | 2 | ||||
-rw-r--r-- | src/company_cmd.cpp | 15 | ||||
-rw-r--r-- | src/company_type.h | 9 | ||||
-rw-r--r-- | src/console_cmds.cpp | 6 | ||||
-rw-r--r-- | src/economy.cpp | 2 | ||||
-rw-r--r-- | src/network/core/tcp_admin.cpp | 20 | ||||
-rw-r--r-- | src/network/core/tcp_admin.h | 4 | ||||
-rw-r--r-- | src/network/network_server.cpp | 6 |
8 files changed, 41 insertions, 23 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index debed35a2..243f96e6f 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -1027,7 +1027,7 @@ struct AIDebugWindow : public QueryStringBaseWindow { switch (widget) { case AID_WIDGET_RELOAD_TOGGLE: /* First kill the company of the AI, then start a new one. This should start the current AI again */ - DoCommandP(0, 2 | ai_debug_company << 16, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 2 | ai_debug_company << 16, CRR_MANUAL, CMD_COMPANY_CTRL); DoCommandP(0, 1 | ai_debug_company << 16, 0, CMD_COMPANY_CTRL); break; diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 07b8e3f92..91ac65861 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -770,13 +770,14 @@ void CompanyAdminUpdate(const Company *company) } /** - * Called whenever a company goes bankrupt in order to notify admins. - * @param company_id The company that went bankrupt. + * Called whenever a company is removed in order to notify admins. + * @param company_id The company that was removed. + * @param reason The reason the company was removed. */ -void CompanyAdminBankrupt(CompanyID company_id) +void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason) { #ifdef ENABLE_NETWORK - if (_network_server) NetworkAdminCompanyRemove(company_id, ADMIN_CRR_BANKRUPT); + if (_network_server) NetworkAdminCompanyRemove(company_id, (AdminCompanyRemoveReason)reason); #endif /* ENABLE_NETWORK */ } @@ -843,7 +844,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } if (_network_server) { - CompanyID old_playas = ci->client_playas; ci->client_playas = c->index; NetworkUpdateClientInfo(ci->client_id); @@ -882,6 +882,9 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 break; case 2: { // Delete a company + CompanyRemoveReason reason = (CompanyRemoveReason)GB(p2, 0, 2); + if (reason >= CRR_END) return CMD_ERROR; + Company *c = Company::GetIfValid(company_id); if (c == NULL) return CMD_ERROR; @@ -905,7 +908,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 CompanyID c_index = c->index; delete c; AI::BroadcastNewEvent(new AIEventCompanyBankrupt(c_index)); - CompanyAdminBankrupt(c_index); + CompanyAdminRemove(c_index, (CompanyRemoveReason)reason); break; } diff --git a/src/company_type.h b/src/company_type.h index aa73abe63..249cce7d1 100644 --- a/src/company_type.h +++ b/src/company_type.h @@ -54,4 +54,13 @@ typedef uint16 CompanyMask; struct Company; typedef uint32 CompanyManagerFace; ///< Company manager face bits, info see in company_manager_face.h +/** The reason why the company was removed. */ +enum CompanyRemoveReason { + CRR_MANUAL, ///< The company is manually removed. + CRR_AUTOCLEAN, ///< The company is removed due to autoclean. + CRR_BANKRUPT, ///< The company went belly-up. + + CRR_END ///< Sentinel for end. +}; + #endif /* COMPANY_TYPE_H */ diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index d632d0280..7775a4a31 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -836,7 +836,7 @@ DEF_CONSOLE_CMD(ConResetCompany) } /* It is safe to remove this company */ - DoCommandP(0, 2 | index << 16, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 2 | index << 16, CRR_MANUAL, CMD_COMPANY_CTRL); IConsolePrint(CC_DEFAULT, "Company deleted."); return true; @@ -1196,7 +1196,7 @@ DEF_CONSOLE_CMD(ConReloadAI) } /* First kill the company of the AI, then start a new one. This should start the current AI again */ - DoCommandP(0, 2 | company_id << 16, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL); DoCommandP(0, 1 | company_id << 16, 0, CMD_COMPANY_CTRL); IConsolePrint(CC_DEFAULT, "AI reloaded."); @@ -1233,7 +1233,7 @@ DEF_CONSOLE_CMD(ConStopAI) } /* Now kill the company of the AI. */ - DoCommandP(0, 2 | company_id << 16, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL); IConsolePrint(CC_DEFAULT, "AI stopped, company deleted."); return true; diff --git a/src/economy.cpp b/src/economy.cpp index 92babd802..78d271242 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -561,7 +561,7 @@ static void CompanyCheckBankrupt(Company *c) * that changing the current company is okay. In case of single * player we are sure (the above check) that we are not the local * company and thus we won't be moved. */ - if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), 0, CMD_COMPANY_CTRL); + if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL); break; } } diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp index 077ac3048..fbf9ac580 100644 --- a/src/network/core/tcp_admin.cpp +++ b/src/network/core/tcp_admin.cpp @@ -19,6 +19,12 @@ #include "tcp_admin.h" #include "../../debug.h" +/* Make sure that these enums match. */ +assert_compile((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL); +assert_compile((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN); +assert_compile((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT); +assert_compile((int)CRR_END == (int)ADMIN_CRR_END); + /** * Create the admin handler for the given socket. * @param s The socket to communicate over. @@ -55,13 +61,13 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p) case ADMIN_PACKET_ADMIN_CHAT: return this->Receive_ADMIN_CHAT(p); case ADMIN_PACKET_ADMIN_RCON: return this->Receive_ADMIN_RCON(p); - case ADMIN_PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p); - case ADMIN_PACKET_SERVER_BANNED: return this->Receive_SERVER_BANNED(p); - case ADMIN_PACKET_SERVER_ERROR: return this->Receive_SERVER_ERROR(p); - case ADMIN_PACKET_SERVER_PROTOCOL: return this->Receive_SERVER_PROTOCOL(p); - case ADMIN_PACKET_SERVER_WELCOME: return this->Receive_SERVER_WELCOME(p); - case ADMIN_PACKET_SERVER_NEWGAME: return this->Receive_SERVER_NEWGAME(p); - case ADMIN_PACKET_SERVER_SHUTDOWN: return this->Receive_SERVER_SHUTDOWN(p); + case ADMIN_PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p); + case ADMIN_PACKET_SERVER_BANNED: return this->Receive_SERVER_BANNED(p); + case ADMIN_PACKET_SERVER_ERROR: return this->Receive_SERVER_ERROR(p); + case ADMIN_PACKET_SERVER_PROTOCOL: return this->Receive_SERVER_PROTOCOL(p); + case ADMIN_PACKET_SERVER_WELCOME: return this->Receive_SERVER_WELCOME(p); + case ADMIN_PACKET_SERVER_NEWGAME: return this->Receive_SERVER_NEWGAME(p); + case ADMIN_PACKET_SERVER_SHUTDOWN: return this->Receive_SERVER_SHUTDOWN(p); case ADMIN_PACKET_SERVER_DATE: return this->Receive_SERVER_DATE(p); case ADMIN_PACKET_SERVER_CLIENT_JOIN: return this->Receive_SERVER_CLIENT_JOIN(p); diff --git a/src/network/core/tcp_admin.h b/src/network/core/tcp_admin.h index c0491f0cc..46b876952 100644 --- a/src/network/core/tcp_admin.h +++ b/src/network/core/tcp_admin.h @@ -99,7 +99,9 @@ DECLARE_ENUM_AS_BIT_SET(AdminUpdateFrequency) enum AdminCompanyRemoveReason { ADMIN_CRR_MANUAL, ///< The company is manually removed. ADMIN_CRR_AUTOCLEAN, ///< The company is removed due to autoclean. - ADMIN_CRR_BANKRUPT ///< The company went belly-up. + ADMIN_CRR_BANKRUPT, ///< The company went belly-up. + + ADMIN_CRR_END ///< Sentinel for end. }; /** Main socket handler for admin related connections. */ diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 507c9232e..ebf78a320 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1643,8 +1643,7 @@ static void NetworkAutoCleanCompanies() /* Is the company empty for autoclean_unprotected-months, and is there no protection? */ if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) { /* Shut the company down */ - DoCommandP(0, 2 | c->index << 16, 0, CMD_COMPANY_CTRL); - NetworkAdminCompanyRemove(c->index, ADMIN_CRR_AUTOCLEAN); + DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL); IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1); } /* Is the company empty for autoclean_protected-months, and there is a protection? */ @@ -1658,8 +1657,7 @@ static void NetworkAutoCleanCompanies() /* Is the company empty for autoclean_novehicles-months, and has no vehicles? */ if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) { /* Shut the company down */ - DoCommandP(0, 2 | c->index << 16, 0, CMD_COMPANY_CTRL); - NetworkAdminCompanyRemove(c->index, ADMIN_CRR_AUTOCLEAN); + DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL); IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1); } } else { |