From d12fc08abc9f6da27b2a3c78c56f39ac2b0e9b6a Mon Sep 17 00:00:00 2001 From: Josh Allen Date: Fri, 17 Sep 2004 22:22:39 +0000 Subject: [PATCH] Fixed SortStats --- stepmania/src/NetworkSyncServer.cpp | 51 ++++++++++------------------- stepmania/src/NetworkSyncServer.h | 1 - 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/stepmania/src/NetworkSyncServer.cpp b/stepmania/src/NetworkSyncServer.cpp index f73fa7ca53..fb2cd39d56 100644 --- a/stepmania/src/NetworkSyncServer.cpp +++ b/stepmania/src/NetworkSyncServer.cpp @@ -159,7 +159,7 @@ void StepManiaLanServer::ParseData(PacketFunctions& Packet, const unsigned int c case NSCGSU: // StatsUpdate Client[clientNum]->UpdateStats(Packet); - if (Client[clientNum]->lowerJudge) + if (!Client[clientNum]->lowerJudge) CheckLowerJudge(clientNum); break; case NSCSU: @@ -390,32 +390,23 @@ void StepManiaLanServer::PopulatePlayersPtr(vector &playersPtr) { int StepManiaLanServer::SortStats(vector &playersPtr) { LanPlayer *tmp; - StatsNameChange = false; //Set it to no name so stats will not send if there is not a change - bool allZero = true; + bool isChanged; PopulatePlayersPtr(playersPtr); - for (unsigned int x = 0; x < playersPtr.size(); ++x) - { - //See if all the players have zero. Used to send names if everyone is 0 - if ((playersPtr[x]->score > 0) && allZero) - allZero = false; - if ((x+1) < playersPtr.size()) + do + { + isChanged = false; + for (int x = 0; x < int(playersPtr.size())-1; ++x) if ((playersPtr[x]->score) < (playersPtr[x+1]->score)) { tmp = playersPtr[x]; playersPtr[x] = playersPtr[x+1]; playersPtr[x+1] = tmp; - x = 0; - StatsNameChange = true; + isChanged = true; } - - } - //If there are players all at 0, the name lsit won't be updated - //this make sure it is sent to the server eventually - if (!StatsNameChange && allZero) - StatsNameChange = true; + } while (isChanged); return playersPtr.size(); } @@ -426,24 +417,18 @@ void StepManiaLanServer::SendStatsToClients() SortStats(playersPtr); //Return number of players - //If there was a change in the name data, send it to the clients. - //Used to save bandwidth and some processing time. - //Disabled this. FUTURE: Figure out why it dosn't work correctly and fix. -// if (StatsNameChange) -// { - /* Write and Send name packet */ - Reply.ClearPacket(); - Reply.Write1(NSCGSU + NSServerOffset); - Reply.Write1(0); - Reply.Write1( (uint8_t) playersPtr.size()); - StatsNameColumn(Reply, playersPtr); + /* Write and Send name packet */ + Reply.ClearPacket(); + Reply.Write1(NSCGSU + NSServerOffset); + Reply.Write1(0); + Reply.Write1( (uint8_t) playersPtr.size()); + StatsNameColumn(Reply, playersPtr); - //Send to in game clients only. - for (x = 0; x < Client.size(); ++x) - if (Client[x]->InGame) - SendNetPacket(x, Reply); + //Send to in game clients only. + for (x = 0; x < Client.size(); ++x) + if (Client[x]->InGame) + SendNetPacket(x, Reply); -// } /* Write and send Combo packet */ Reply.ClearPacket(); diff --git a/stepmania/src/NetworkSyncServer.h b/stepmania/src/NetworkSyncServer.h index c8750404fc..3395864372 100644 --- a/stepmania/src/NetworkSyncServer.h +++ b/stepmania/src/NetworkSyncServer.h @@ -90,7 +90,6 @@ private: time_t statsTime; GameInfo CurrentSongInfo; GameInfo LastSongInfo; - bool StatsNameChange; bool SecondSameSelect; vector bannedIPs;