From 9a29bec49b7f52d01d9617fc1bb43085a6a05fee Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:41:04 -0400 Subject: [PATCH] TEMP: Backwards-compatible change for testing only - DO NOT MERGE --- lib/netplay/netplay.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/netplay/netplay.cpp b/lib/netplay/netplay.cpp index 9f3381eb226..9d1669ed3b3 100644 --- a/lib/netplay/netplay.cpp +++ b/lib/netplay/netplay.cpp @@ -743,6 +743,10 @@ static void NETSendNPlayerInfoTo(uint32_t *index, uint32_t indexLen, unsigned to NETint8_t(reinterpret_cast(&NetPlay.players[index[n]].difficulty)); NETuint8_t(reinterpret_cast(&NetPlay.players[index[n]].faction)); NETbool(&NetPlay.players[index[n]].isSpectator); + } + for (unsigned n = 0; n < indexLen; ++n) + { + NETuint32_t(&index[n]); NETbool(&NetPlay.players[index[n]].isAdmin); } NETend(); @@ -2589,7 +2593,6 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t *type) NETint8_t(&difficulty); NETuint8_t(&faction); NETbool(&isSpectator); - NETbool(&isAdmin); auto newFactionId = uintToFactionID(faction); if (!newFactionId.has_value()) @@ -2609,7 +2612,6 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t *type) NetPlay.players[index].difficulty = static_cast(difficulty); NetPlay.players[index].faction = newFactionId.value(); NetPlay.players[index].isSpectator = isSpectator; - NetPlay.players[index].isAdmin = isAdmin; } debug(LOG_NET, "%s for player %u (%s)", n == 0 ? "Receiving MSG_PLAYER_INFO" : " and", (unsigned int)index, NetPlay.players[index].allocated ? "human" : "AI"); @@ -2619,6 +2621,29 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t *type) printConsoleNameChange(oldName.c_str(), NetPlay.players[index].name); } } + + for (n = 0; n < indexLen; ++n) + { + // Retrieve the player's ID + NETuint32_t(&index); + + // Bail out if the given ID number is out of range + if (index >= MAX_CONNECTED_PLAYERS || (playerQueue.index != NetPlay.hostPlayer && (playerQueue.index != index || !NetPlay.players[index].allocated))) + { + debug(LOG_ERROR, "MSG_PLAYER_INFO from %u: Player ID (%u) out of range (max %u)", playerQueue.index, index, (unsigned int)MAX_CONNECTED_PLAYERS); + error = true; + break; + } + + NETbool(&isAdmin); + + // Don't let anyone except the host change these, otherwise it will end up inconsistent at some point, and the game gets really messed up. + if (playerQueue.index == NetPlay.hostPlayer) + { + NetPlay.players[index].isAdmin = isAdmin; + } + } + NETend(); // If we're the game host make sure to send the updated // data to all other clients as well.