Skip to content

Commit

Permalink
TEMP: Backwards-compatible change for testing only - DO NOT MERGE
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 9, 2024
1 parent 68e23e3 commit 9a29bec
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions lib/netplay/netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ static void NETSendNPlayerInfoTo(uint32_t *index, uint32_t indexLen, unsigned to
NETint8_t(reinterpret_cast<int8_t*>(&NetPlay.players[index[n]].difficulty));
NETuint8_t(reinterpret_cast<uint8_t *>(&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();
Expand Down Expand Up @@ -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())
Expand All @@ -2609,7 +2612,6 @@ static bool NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t *type)
NetPlay.players[index].difficulty = static_cast<AIDifficulty>(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");
Expand All @@ -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.
Expand Down

0 comments on commit 9a29bec

Please sign in to comment.