summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_object.cpp7
-rw-r--r--src/command.cpp2
-rw-r--r--src/command_func.h4
-rw-r--r--src/company_cmd.cpp5
-rw-r--r--src/network/network_client.cpp2
-rw-r--r--src/network/network_command.cpp5
-rw-r--r--src/settings.cpp2
-rw-r--r--src/toolbar_gui.cpp2
8 files changed, 11 insertions, 18 deletions
diff --git a/src/ai/api/ai_object.cpp b/src/ai/api/ai_object.cpp
index c9abc9ea4..43103afb7 100644
--- a/src/ai/api/ai_object.cpp
+++ b/src/ai/api/ai_object.cpp
@@ -230,12 +230,7 @@ bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const c
#ifdef ENABLE_NETWORK
/* Send the command */
if (_networking) {
- /* NetworkSend_Command needs _local_company to be set correctly, so
- * adjust it, and put it back right after the function */
- CompanyID old_company = _local_company;
- _local_company = _current_company;
- ::NetworkSend_Command(tile, p1, p2, cmd, CcAI, text);
- _local_company = old_company;
+ ::NetworkSend_Command(tile, p1, p2, cmd, CcAI, text, _current_company);
SetLastCost(res.GetCost());
/* Suspend the AI till the command is really executed */
diff --git a/src/command.cpp b/src/command.cpp
index 2dbd53d65..d0c85adad 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -589,7 +589,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
* send it to the command-queue and abort execution
*/
if (_networking && !(cmd & CMD_NETWORK_COMMAND)) {
- NetworkSend_Command(tile, p1, p2, cmd & ~CMD_FLAGS_MASK, callback, text);
+ NetworkSend_Command(tile, p1, p2, cmd & ~CMD_FLAGS_MASK, callback, text, _current_company);
_docommand_recursive = 0;
ClearStorageChanges(false);
return true;
diff --git a/src/command_func.h b/src/command_func.h
index 14a683623..85b089398 100644
--- a/src/command_func.h
+++ b/src/command_func.h
@@ -13,6 +13,7 @@
#define COMMAND_FUNC_H
#include "command_type.h"
+#include "company_type.h"
/**
* Checks if a command failes.
@@ -70,11 +71,10 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
#ifdef ENABLE_NETWORK
-
/**
* Send a command over the network
*/
-void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text);
+void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company);
#endif /* ENABLE_NETWORK */
extern Money _additional_cash_required;
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 2150b43ab..9629a0cb6 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -790,7 +790,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
NetworkUpdateClientInfo(ci->client_id);
if (Company::IsValidID(ci->client_playas)) {
- CompanyID company_backup = _local_company;
_network_company_states[c->index].months_empty = 0;
_network_company_states[c->index].password[0] = '\0';
NetworkServerUpdateCompanyPassworded(ci->client_playas, false);
@@ -806,9 +805,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
* TODO: Perhaps this could be improved by when the client is ready
* with joining to let it send itself the command, and not the server?
* For example in network_client.c:534? */
- _local_company = ci->client_playas;
- NetworkSend_Command(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name);
- _local_company = company_backup;
+ NetworkSend_Command(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name, ci->client_playas);
}
/* Announce new company on network, if the client was a SPECTATOR before */
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index c7029e8f4..dd9f2a7f8 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -643,7 +643,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
* the server will give us a client-id and let us in */
_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
ShowJoinStatusWindow();
- NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL);
+ NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
}
} else {
/* take control over an existing company */
diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp
index 9a6a064b5..834d28da4 100644
--- a/src/network/network_command.cpp
+++ b/src/network/network_command.cpp
@@ -78,13 +78,14 @@ void NetworkAddCommandQueue(CommandPacket cp, NetworkClientSocket *cs)
* @param cmd The command to execute (a CMD_* value)
* @param callback A callback function to call after the command is finished
* @param text The text to pass
+ * @param company The company that wants to send the command
*/
-void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text)
+void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
{
assert((cmd & CMD_FLAGS_MASK) == 0);
CommandPacket c;
- c.company = _local_company;
+ c.company = company;
c.next = NULL;
c.tile = tile;
c.p1 = p1;
diff --git a/src/settings.cpp b/src/settings.cpp
index d4980b07e..00c0f21cc 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1579,7 +1579,7 @@ void SyncCompanySettings()
const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
- if (old_value != new_value) NetworkSend_Command(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, NULL, NULL);
+ if (old_value != new_value) NetworkSend_Command(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, NULL, NULL, _local_company);
}
}
#endif /* ENABLE_NETWORK */
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 3f4d8e1b0..f5c61cdcf 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -486,7 +486,7 @@ static void MenuClickCompany(int index)
if (_network_server) {
DoCommandP(0, 0, _network_own_client_id, CMD_COMPANY_CTRL);
} else {
- NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL);
+ NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
}
return;