From ea59769cfdbb7bcfc847ab1176618682e113f3f7 Mon Sep 17 00:00:00 2001 From: ZehM4tt Date: Fri, 16 Jun 2017 07:53:20 +0200 Subject: [PATCH] Fixes clients receiving commands before the map data is sent and loaded. --- src/openrct2/network/network.cpp | 13 +++++++++++-- src/openrct2/network/network.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/openrct2/network/network.cpp b/src/openrct2/network/network.cpp index afbbe9a487..b6128b1797 100644 --- a/src/openrct2/network/network.cpp +++ b/src/openrct2/network/network.cpp @@ -595,9 +595,18 @@ const char* Network::FormatChat(NetworkPlayer* fromplayer, const char* text) return formatted; } -void Network::SendPacketToClients(NetworkPacket& packet, bool front) +void Network::SendPacketToClients(NetworkPacket& packet, bool front, bool gameCmd) { for (auto it = client_connection_list.begin(); it != client_connection_list.end(); it++) { + + if (gameCmd) { + // If marked as game command we can not send the packet to connections that are not fully connected. + // Sending the packet would cause the client to store a command that is behind the tick where he starts, + // which would be essentially never executed. The clients do not require commands before the map is loaded. + if ((*it)->Player == nullptr) { + continue; + } + } (*it)->QueuePacket(NetworkPacket::Duplicate(packet), front); } } @@ -1122,7 +1131,7 @@ void Network::Server_Send_GAMECMD(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx std::unique_ptr packet(NetworkPacket::Allocate()); *packet << (uint32)NETWORK_COMMAND_GAMECMD << (uint32)gCurrentTicks << eax << (ebx | GAME_COMMAND_FLAG_NETWORKED) << ecx << edx << esi << edi << ebp << playerid << callback; - SendPacketToClients(*packet); + SendPacketToClients(*packet, false, true); } void Network::Server_Send_TICK() diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 33ad9366d0..559dd98127 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -113,7 +113,7 @@ public: std::vector>::iterator GetGroupIteratorByID(uint8 id); NetworkGroup* GetGroupByID(uint8 id); static const char* FormatChat(NetworkPlayer* fromplayer, const char* text); - void SendPacketToClients(NetworkPacket& packet, bool front = false); + void SendPacketToClients(NetworkPacket& packet, bool front = false, bool gameCmd = false); bool CheckSRAND(uint32 tick, uint32 srand0); void KickPlayer(sint32 playerId); void SetPassword(const char* password);