diff --git a/lib/netplay/netplay.cpp b/lib/netplay/netplay.cpp index d9092d4f50a..f14fb719a99 100644 --- a/lib/netplay/netplay.cpp +++ b/lib/netplay/netplay.cpp @@ -864,6 +864,13 @@ static void NET_DestroyPlayer(unsigned int index, bool suppressActivityUpdates = } } +bool NETplayerHasConnection(uint32_t index) +{ + ASSERT_HOST_ONLY(return false); + ASSERT_OR_RETURN(false, index < MAX_CONNECTED_PLAYERS, "Invalid index: %" PRIu32, index); + return connected_bsocket[index] != nullptr; +} + /** * @note Connection dropped. Handle it gracefully. * \param index @@ -2174,10 +2181,13 @@ static inline bool NETFilterMessageWhileSwappingPlayer(uint8_t sender, uint8_t t { // this client did not acknowledge the player index change before the timeout - kick them char msg[256] = {'\0'}; - ssprintf(msg, "Auto-kicking player %u, did not ack player index change within required timeframe.", (unsigned int)sender); - sendInGameSystemMessage(msg); - debug(LOG_INFO, "Client (player: %u) failed to ack player index swap (ignoring message type: %" PRIu8 ")", sender, type); - kickPlayer(sender, _("Client failed to ack player index swap"), ERROR_INVALID, false); + if (NETplayerHasConnection(sender) || NetPlay.players[sender].allocated) + { + ssprintf(msg, "Auto-kicking player %u, did not ack player index change within required timeframe.", (unsigned int)sender); + sendInGameSystemMessage(msg); + debug(LOG_INFO, "Client (player: %u) failed to ack player index swap (ignoring message type: %" PRIu8 ")", sender, type); + kickPlayer(sender, _("Client failed to ack player index swap"), ERROR_INVALID, false); + } return true; // filter original message, of course } diff --git a/lib/netplay/netplay.h b/lib/netplay/netplay.h index 1353c1287b9..1c029eb3b01 100644 --- a/lib/netplay/netplay.h +++ b/lib/netplay/netplay.h @@ -392,6 +392,8 @@ size_t NETgetStatistic(NetStatisticType type, bool sent, bool isTotal = false); void NETplayerKicked(UDWORD index); // Cleanup after player has been kicked +bool NETplayerHasConnection(uint32_t index); + bool NETcanOpenNewSpectatorSlot(); bool NETopenNewSpectatorSlot(); bool NETmovePlayerToSpectatorOnlySlot(uint32_t playerIdx, bool hostOverride = false); diff --git a/src/multiplay.cpp b/src/multiplay.cpp index 2f550d9e251..3d636072b70 100644 --- a/src/multiplay.cpp +++ b/src/multiplay.cpp @@ -1394,8 +1394,11 @@ void HandleBadParam(const char *msg, const int from, const int actual) NETlogEntry(buf, SYNC_FLAG, actual); if (NetPlay.isHost) { - ssprintf(buf, _("Auto kicking player %s, invalid command received."), NetPlay.players[actual].name); - sendInGameSystemMessage(buf); + if (NETplayerHasConnection(actual)) + { + ssprintf(buf, _("Auto kicking player %s, invalid command received."), NetPlay.players[actual].name); + sendInGameSystemMessage(buf); + } kickPlayer(actual, buf, KICK_TYPE, false); } }