Changeset - r18192:da213da57034
[Not reviewed]
master
0 8 0
rubidium - 13 years ago 2011-10-15 20:42:32
rubidium@openttd.org
(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
8 files changed with 41 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -1027,7 +1027,7 @@ struct AIDebugWindow : public QueryStrin
 
		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;
 

	
src/company_cmd.cpp
Show inline comments
 
@@ -770,13 +770,14 @@ void CompanyAdminUpdate(const Company *c
 
}
 

	
 
/**
 
 * 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 til
 
			}
 

	
 
			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 til
 
			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 til
 
			CompanyID c_index = c->index;
 
			delete c;
 
			AI::BroadcastNewEvent(new AIEventCompanyBankrupt(c_index));
 
			CompanyAdminBankrupt(c_index);
 
			CompanyAdminRemove(c_index, (CompanyRemoveReason)reason);
 
			break;
 
		}
 

	
src/company_type.h
Show inline comments
 
@@ -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 */
src/console_cmds.cpp
Show inline comments
 
@@ -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;
src/economy.cpp
Show inline comments
 
@@ -561,7 +561,7 @@ static void CompanyCheckBankrupt(Company
 
			 * 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;
 
	}
 
}
src/network/core/tcp_admin.cpp
Show inline comments
 
@@ -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 NetworkAdminSocketHand
 
		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);
src/network/core/tcp_admin.h
Show inline comments
 
@@ -99,7 +99,9 @@ DECLARE_ENUM_AS_BIT_SET(AdminUpdateFrequ
 
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. */
src/network/network_server.cpp
Show inline comments
 
@@ -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 {
0 comments (0 inline, 0 general)