From e46b08f8e1f3b7de9eb20b4a8173e0ce093986bd Mon Sep 17 00:00:00 2001 From: Cyp Date: Thu, 13 Jan 2011 16:40:34 +0100 Subject: [PATCH] Fix not sending player info for players 8+. --- lib/gamelib/gtime.cpp | 35 ++++++++++++++++++++++++++--------- lib/netplay/netplay.cpp | 10 +++++----- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/gamelib/gtime.cpp b/lib/gamelib/gtime.cpp index 00b9e1547..5cfe4507d 100644 --- a/lib/gamelib/gtime.cpp +++ b/lib/gamelib/gtime.cpp @@ -69,6 +69,24 @@ static uint16_t wantedLatencies[MAX_PLAYERS]; static void updateLatency(void); +static std::string listToString(char const *format, char const *separator, uint32_t const *begin, uint32_t const *end) +{ + std::string ret; + uint32_t const *i = begin; + while (i != end) + { + char tmp[100]; + ssprintf(tmp, format, *i); + ret += tmp; + + if (++i != end) + { + ret += separator; + } + } + return ret; +} + /* Initialise the game clock */ void gameTimeInit(void) { @@ -176,10 +194,10 @@ void gameTimeUpdate() baseTime = currTime; timeOffset = graphicsTime; - debug(LOG_SYNC, "Waiting for other players. gameTime = %u, player times are {%u, %u, %u, %u, %u, %u, %u, %u}", gameTime, gameQueueTime[0], gameQueueTime[1], gameQueueTime[2], gameQueueTime[3], gameQueueTime[4], gameQueueTime[5], gameQueueTime[6], gameQueueTime[7]); + debug(LOG_SYNC, "Waiting for other players. gameTime = %u, player times are {%s}", gameTime, listToString("%u", ", ", gameQueueTime, gameQueueTime + game.maxPlayers).c_str()); mayUpdate = false; - for (player = 0; player < MAX_PLAYERS; ++player) + for (player = 0; player < game.maxPlayers; ++player) { if (!checkPlayerGameTime(player)) { @@ -206,11 +224,10 @@ void gameTimeUpdate() deltaGameTime = GAME_TICKS_PER_UPDATE; updateLatency(); - if (crcError) { - debug(LOG_ERROR, "Synch error, gameTimes were: {%10u, %10u, %10u, %10u, %10u, %10u, %10u, %10u}", gameQueueCheckTime[0], gameQueueCheckTime[1], gameQueueCheckTime[2], gameQueueCheckTime[3], gameQueueCheckTime[4], gameQueueCheckTime[5], gameQueueCheckTime[6], gameQueueCheckTime[7]); - debug(LOG_ERROR, "Synch error, CRCs were: {0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X}", gameQueueCheckCrc[0], gameQueueCheckCrc[1], gameQueueCheckCrc[2], gameQueueCheckCrc[3], gameQueueCheckCrc[4], gameQueueCheckCrc[5], gameQueueCheckCrc[6], gameQueueCheckCrc[7]); + debug(LOG_ERROR, "Synch error, gameTimes were: {%s}", listToString("%10u", ", ", gameQueueCheckTime, gameQueueCheckTime + game.maxPlayers).c_str()); + debug(LOG_ERROR, "Synch error, CRCs were: {%s}", listToString("0x%08X", ", ", gameQueueCheckCrc, gameQueueCheckCrc + game.maxPlayers).c_str()); crcError = false; } } @@ -347,7 +364,7 @@ static void updateLatency() uint16_t prevDiscreteChosenLatency = discreteChosenLatency; // Find out what latency has been agreed on, next. - for (player = 0; player < MAX_PLAYERS; ++player) + for (player = 0; player < game.maxPlayers; ++player) { if (!NetPlay.players[player].kick) // .kick: Don't wait for dropped players. { @@ -380,7 +397,7 @@ void sendPlayerGameTime() uint32_t checkTime = gameTime; uint32_t checkCrc = nextDebugSync(); - for (player = 0; player < MAX_PLAYERS; ++player) + for (player = 0; player < game.maxPlayers; ++player) { if (!myResponsibility(player) && whosResponsible(player) != realSelectedPlayer) { @@ -434,7 +451,7 @@ bool checkPlayerGameTime(unsigned player) if (player == NET_ALL_PLAYERS) { begin = 0; - end = MAX_PLAYERS; + end = game.maxPlayers; } for (player = begin; player < end; ++player) @@ -452,7 +469,7 @@ void setPlayerGameTime(unsigned player, uint32_t time) { if (player == NET_ALL_PLAYERS) { - for (player = 0; player < MAX_PLAYERS; ++player) + for (player = 0; player < game.maxPlayers; ++player) { gameQueueTime[player] = time; } diff --git a/lib/netplay/netplay.cpp b/lib/netplay/netplay.cpp index e1850ce9c..f7faa98b7 100644 --- a/lib/netplay/netplay.cpp +++ b/lib/netplay/netplay.cpp @@ -332,7 +332,6 @@ static void NETSendNPlayerInfoTo(uint32_t *index, uint32_t indexLen, unsigned to NETint8_t(&NetPlay.players[index[n]].ai); NETint8_t(&NetPlay.players[index[n]].difficulty); } - NETuint32_t(&NetPlay.hostPlayer); NETend(); } @@ -343,7 +342,11 @@ static void NETSendPlayerInfoTo(uint32_t index, unsigned to) static void NETSendAllPlayerInfoTo(unsigned to) { - static uint32_t indices[MAX_PLAYERS] = {0, 1, 2, 3, 4, 5, 6, 7}; + static uint32_t indices[MAX_PLAYERS]; + for (int i = 0; i < MAX_PLAYERS; ++i) + { + indices[i] = i; + } ASSERT_OR_RETURN( , NetPlay.isHost == true, "Invalid call for non-host"); NETSendNPlayerInfoTo(indices, ARRAY_SIZE(indices), to); @@ -1431,7 +1434,6 @@ static BOOL NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t type) int32_t colour = 0; int32_t position = 0; int32_t team = 0; - uint32_t hostPlayer = 0; int8_t ai = 0; int8_t difficulty = 0; bool error = false; @@ -1457,7 +1459,6 @@ static BOOL NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t type) 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); - NETend(); error = true; break; } @@ -1496,7 +1497,6 @@ static BOOL NETprocessSystemMessage(NETQUEUE playerQueue, uint8_t type) printConsoleNameChange(oldName, NetPlay.players[index].name); } } - NETuint32_t(&hostPlayer); NETend(); // If we're the game host make sure to send the updated // data to all other clients as well.