summaryrefslogtreecommitdiff
path: root/src/network/network_command.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-04-13 18:55:31 +0000
committerrubidium <rubidium@openttd.org>2010-04-13 18:55:31 +0000
commit088282bcf8ce6d301fd8a5b0d8a3409bceaab32d (patch)
treee6a40c2bdaa2011f11cc3aaed25d4db3355ae9ad /src/network/network_command.cpp
parentd2ed777fa5a9a1c39923ace958cd7e01f60de7f8 (diff)
downloadopenttd-088282bcf8ce6d301fd8a5b0d8a3409bceaab32d.tar.xz
(svn r19620) -Fix: desync when a command is received and in the queue while a client starts joining, i.e. save the game state. This can happen in two ways: with frame_freq > 1 a command received in a previous frame might not be executed yet or when a command is received in the same frame as the join but before the savegame is made. In both cases the joining client would not get all commands to get in-sync with the server (and the other clients).
Diffstat (limited to 'src/network/network_command.cpp')
-rw-r--r--src/network/network_command.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp
index 111ee7e3f..725b034d0 100644
--- a/src/network/network_command.cpp
+++ b/src/network/network_command.cpp
@@ -130,6 +130,24 @@ void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comma
}
/**
+ * Sync our local command queue to the command queue of the given
+ * socket. This is needed for the case where we receive a command
+ * before saving the game for a joining client, but without the
+ * execution of those commands. Not syncing those commands means
+ * that the client will never get them and as such will be in a
+ * desynced state from the time it started with joining.
+ * @param cs The client to sync the queue to.
+ */
+void NetworkSyncCommandQueue(NetworkClientSocket *cs)
+{
+ for (CommandPacket *p = _local_command_queue; p != NULL; p = p->next) {
+ CommandPacket c = *p;
+ c.callback = 0;
+ NetworkAddCommandQueue(c, cs);
+ }
+}
+
+/**
* Execute all commands on the local command queue that ought to be executed this frame.
*/
void NetworkExecuteLocalCommandQueue()