summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2004-12-16 11:36:57 +0000
committertruelight <truelight@openttd.org>2004-12-16 11:36:57 +0000
commit74a149127dbcb4b6c62c7b5adcbb4cba54ddaeb8 (patch)
tree1bbe6a65fbab389221996b854b42c5fd5a0d12a9
parentdccd3adb9bfc0d17f8b078e0e43b0da5315a89ed (diff)
downloadopenttd-74a149127dbcb4b6c62c7b5adcbb4cba54ddaeb8.tar.xz
(svn r1129) -Add: [Network] Added 'reset_company <company-id>'. If a company is
empty (no clients logged on to it), a server can delete a company via this command in the console.
-rw-r--r--console_cmds.c61
-rw-r--r--players.c22
2 files changed, 79 insertions, 4 deletions
diff --git a/console_cmds.c b/console_cmds.c
index 1cb33ede1..3c2a8e0c9 100644
--- a/console_cmds.c
+++ b/console_cmds.c
@@ -214,6 +214,59 @@ DEF_CONSOLE_CMD(ConKick)
return NULL;
}
+DEF_CONSOLE_CMD(ConResetCompany)
+{
+ Player *p;
+ ClientState *cs;
+ NetworkClientInfo *ci;
+
+ if (argc == 2) {
+ uint32 index = atoi(argv[1]);
+
+ /* Check valid range */
+ if (index < 1 || index > MAX_PLAYERS) {
+ IConsolePrintF(_iconsole_color_error, "Company does not exist. Company-ID must be between 1 and %d.", MAX_PLAYERS);
+ return NULL;
+ }
+
+ /* Check if company does exist */
+ index--;
+ p = DEREF_PLAYER(index);
+ if (!p->is_active) {
+ IConsolePrintF(_iconsole_color_error, "Company does not exist.");
+ return NULL;
+ }
+
+ if (p->is_ai) {
+ IConsolePrintF(_iconsole_color_error, "Company is owned by an AI.");
+ return NULL;
+ }
+
+ /* Check if the company has active players */
+ FOR_ALL_CLIENTS(cs) {
+ ci = DEREF_CLIENT_INFO(cs);
+ if (ci->client_playas-1 == index) {
+ IConsolePrintF(_iconsole_color_error, "Cannot remove company: a client is connected to that company.");
+ return NULL;
+ }
+ }
+ ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
+ if (ci->client_playas-1 == index) {
+ IConsolePrintF(_iconsole_color_error, "Cannot remove company: a client is connected to that company.");
+ return NULL;
+ }
+
+ /* It is safe to remove this company */
+ DoCommandP(0, 2, index, NULL, CMD_PLAYER_CTRL);
+ IConsolePrint(_iconsole_color_default, "Company deleted.");
+ return NULL;
+ }
+
+ IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: reset_company <company-id>.");
+
+ return NULL;
+}
+
DEF_CONSOLE_CMD(ConNetworkClients)
{
NetworkClientInfo *ci;
@@ -720,6 +773,10 @@ DEF_CONSOLE_CMD(ConSet) {
// setting the server advertising on/off
if (strcmp(argv[1],"server_advertise") == 0) {
+ if (!_network_server) {
+ IConsolePrintF(_iconsole_color_error, "You are not the server");
+ return NULL;
+ }
if (argc == 3) {
if (strcmp(argv[2], "on") == 0 || atoi(argv[2]) == 1)
_network_advertise = true;
@@ -844,6 +901,8 @@ void IConsoleStdLibRegister(void)
IConsoleCmdHook("say_client", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
IConsoleCmdRegister("kick", ConKick);
IConsoleCmdHook("kick", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
+ IConsoleCmdRegister("reset_company", ConResetCompany);
+ IConsoleCmdHook("reset_company", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
IConsoleCmdRegister("connect", ConNetworkConnect);
IConsoleCmdHook("connect", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetServer);
IConsoleCmdRegister("clients", ConNetworkClients);
@@ -851,6 +910,8 @@ void IConsoleStdLibRegister(void)
IConsoleCmdHook("status", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
IConsoleCmdHook("resetengines", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetwork);
+ IConsoleAliasRegister("clean_company", "reset_company");
+
IConsoleVarRegister("net_frame_freq", &_network_frame_freq, ICONSOLE_VAR_UINT8);
IConsoleVarHook("net_frame_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient);
IConsoleVarRegister("net_sync_freq", &_network_sync_freq, ICONSOLE_VAR_UINT16);
diff --git a/players.c b/players.c
index 2bddbecee..377001ff3 100644
--- a/players.c
+++ b/players.c
@@ -629,7 +629,7 @@ static void DeletePlayerStuff(int pi)
// functionality.
// 0 - make new player
// 1 - make new AI player
-// 2 - delete player (p1 >> 8) & 0xFF
+// 2 - delete player (p2)
// 3 - join player (p1 >> 8) & 0xFF with (p1 >> 16) & 0xFF
int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
@@ -686,9 +686,23 @@ int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2)
DoStartupNewPlayer(true);
break;
case 2: // delete player
- pi = (byte)(p1 >> 8);
- ChangeOwnershipOfPlayerItems(pi, 255);
- DeletePlayerStuff(pi);
+ p = DEREF_PLAYER(p2);
+
+ /* Only allow removal of HUMAN companies */
+ if (IS_HUMAN_PLAYER(p2)) {
+ /* Delete any open window of the company */
+ DeletePlayerWindows(p2);
+
+ /* Show the bankrupt news */
+ SetDParam(0, p->name_1);
+ SetDParam(1, p->name_2);
+ AddNewsItem( (StringID)(p2 + 16*3), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
+
+ /* Remove the company */
+ ChangeOwnershipOfPlayerItems(p2, 255);
+ p->money64 = p->player_money = 100000000;
+ p->is_active = false;
+ }
break;
case 3: // join player