summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/company_cmd.cpp34
-rw-r--r--src/network/network_internal.h4
2 files changed, 32 insertions, 6 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index a95bc9fbc..2850ad912 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -810,7 +810,13 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* Has the network client a correct ClientIndex? */
if (!(flags & DC_EXEC)) return CommandCost();
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
+#ifndef DEBUG_DUMP_COMMANDS
+ /* When replaying the client ID is not a valid client; there
+ * are actually no clients at all. However, the company has to
+ * be created, otherwise we cannot rerun the game properly.
+ * So only allow a NULL client info in that case. */
if (ci == NULL) return CommandCost();
+#endif /* NOT DEBUG_DUMP_COMMANDS */
/* Delete multiplayer progress bar */
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
@@ -842,13 +848,17 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
if (_network_server) {
- ci->client_playas = c->index;
- NetworkUpdateClientInfo(ci->client_id);
+ if (ci != NULL) {
+ /* ci is only NULL when replaying.
+ * When replaying no client is actually in need of an update. */
+ ci->client_playas = c->index;
+ NetworkUpdateClientInfo(ci->client_id);
+ }
- if (Company::IsValidID(ci->client_playas)) {
+ if (Company::IsValidID(c->index)) {
_network_company_states[c->index].months_empty = 0;
_network_company_states[c->index].password[0] = '\0';
- NetworkServerUpdateCompanyPassworded(ci->client_playas, false);
+ NetworkServerUpdateCompanyPassworded(c->index, false);
/* XXX - When a client joins, we automatically set its name to the
* client's name (for some reason). As it stands now only the server
@@ -861,12 +871,24 @@ 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? */
- NetworkSendCommand(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name, ci->client_playas);
+ if (ci != NULL) {
+ /* ci is only NULL when replaying.
+ * When replaying, the command to rename the president will
+ * automatically be ran, so this is not even needed to get
+ * the exact same state. */
+ NetworkSendCommand(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name, c->index);
+ }
}
/* Announce new company on network. */
NetworkAdminCompanyInfo(c, true);
- NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, ci->client_playas + 1);
+
+ if (ci != NULL) {
+ /* ci is only NULL when replaying.
+ * When replaying, the message that someone started a new company
+ * is not interesting at all. */
+ NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, c->index + 1);
+ }
}
#endif /* ENABLE_NETWORK */
break;
diff --git a/src/network/network_internal.h b/src/network/network_internal.h
index ccbb23b74..18d21c152 100644
--- a/src/network/network_internal.h
+++ b/src/network/network_internal.h
@@ -43,6 +43,10 @@
* Used to load the desync debug logs, i.e. for reproducing a desync.
* There's basically no need to ever enable this, unless you really know what
* you are doing, i.e. debugging a desync.
+ *
+ * NOTE: Define DEBUG_DUMP_COMMANDS in network.h or globally, else it does not
+ * have enough effects. For example CmdCompanyCtrl needs it to be able
+ * to create companies when there are not clients on this server.
*/
#ifdef DEBUG_DUMP_COMMANDS
extern bool _ddc_fastforward;