(svn r23822) -Fix-ish: when replaying make sure companies get created even if their creating client doesn't exist during the replay

This commit is contained in:
rubidium 2012-01-17 21:13:02 +00:00
parent ede8c86f77
commit a66debfadd
2 changed files with 32 additions and 6 deletions

View File

@ -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;

View File

@ -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;