Skip to content

Commit

Permalink
netplay: Avoid some message spam / redundant kickPlayer calls
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 14, 2023
1 parent bf7f5a6 commit 86e60d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
18 changes: 14 additions & 4 deletions lib/netplay/netplay.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions lib/netplay/netplay.h
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/multiplay.cpp
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 86e60d7

Please sign in to comment.