summaryrefslogtreecommitdiff
path: root/src/company_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2012-01-17 21:13:02 +0000
committerrubidium <rubidium@openttd.org>2012-01-17 21:13:02 +0000
commita66debfaddb2b714d6620af2e902863391dd32ae (patch)
tree0184f3d49ca9d78c68772e8a52193f4891aac7ad /src/company_cmd.cpp
parentede8c86f778583e9dc5b1cb20aaa450eff0e6c6c (diff)
downloadopenttd-a66debfaddb2b714d6620af2e902863391dd32ae.tar.xz
(svn r23822) -Fix-ish: when replaying make sure companies get created even if their creating client doesn't exist during the replay
Diffstat (limited to 'src/company_cmd.cpp')
-rw-r--r--src/company_cmd.cpp34
1 files changed, 28 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;