diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index fc637a0f8..fd2400840 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -296,7 +296,7 @@ void CServer::CClient::Reset() m_LastAckedSnapshot = -1; m_LastInputTick = -1; m_SnapRate = CClient::SNAPRATE_INIT; - m_Score = 0; + m_Score = -1; m_NextMapChunk = 0; m_Flags = 0; } @@ -2014,7 +2014,7 @@ void CServer::CacheServerInfo(CCache *pCache, int Type, bool SendClients) q.AddString(ClientClan(i), MAX_CLAN_LENGTH); // client clan ADD_INT(q, m_aClients[i].m_Country); // client country - ADD_INT(q, m_aClients[i].m_Score); // client score + ADD_INT(q, m_aClients[i].m_Score == -1 ? -9999 : m_aClients[i].m_Score == 9999 ? -10000 : -m_aClients[i].m_Score); // client score ADD_INT(q, GameServer()->IsClientPlayer(i) ? 1 : 0); // is player? if(Type == SERVERINFO_EXTENDED) q.AddString("", 0); // extra info, reserved @@ -2096,7 +2096,7 @@ void CServer::CacheServerInfoSixup(CCache *pCache, bool SendClients) Packer.AddString(ClientName(i), MAX_NAME_LENGTH); // client name Packer.AddString(ClientClan(i), MAX_CLAN_LENGTH); // client clan Packer.AddInt(m_aClients[i].m_Country); // client country - Packer.AddInt(m_aClients[i].m_Score == -9999 ? -1 : -m_aClients[i].m_Score); // client score + Packer.AddInt(m_aClients[i].m_Score); // client score Packer.AddInt(GameServer()->IsClientPlayer(i) ? 0 : 1); // flag spectator=1, bot=2 (player=0) } } @@ -2250,7 +2250,7 @@ void CServer::UpdateRegisterServerInfo() EscapeJson(aCName, sizeof(aCName), ClientName(i)), EscapeJson(aCClan, sizeof(aCClan), ClientClan(i)), m_aClients[i].m_Country, - m_aClients[i].m_Score, + m_aClients[i].m_Score == -1 ? -9999 : m_aClients[i].m_Score == 9999 ? -10000 : -m_aClients[i].m_Score, JsonBool(GameServer()->IsClientPlayer(i))); str_append(aInfo, aClientInfo, sizeof(aInfo)); FirstPlayer = false; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index b29bcd4f8..37f0ebf9d 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -119,8 +119,7 @@ void CPlayer::Reset() m_DND = false; m_LastPause = 0; - m_Score = -9999; - m_HasFinishScore = false; + m_Score = -1; // Variable initialized: m_Last_Team = 0; @@ -337,11 +336,10 @@ void CPlayer::Snap(int SnappingClient) int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient); int Latency = SnappingClient == SERVER_DEMO_CLIENT ? m_Latency.m_Min : GameServer()->m_apPlayers[SnappingClient]->m_aCurLatency[m_ClientID]; - int Score = abs(m_Score) * -1; - + int Score = m_Score; // send 0 if times of others are not shown if(SnappingClient != m_ClientID && g_Config.m_SvHideScore) - Score = -9999; + Score = -1; if(!Server()->IsSixup(SnappingClient)) { @@ -350,7 +348,10 @@ void CPlayer::Snap(int SnappingClient) return; pPlayerInfo->m_Latency = Latency; - pPlayerInfo->m_Score = Score; + // -9999 stands for no time and isn't displayed in scoreboard, so + // shift the time by a second if the player actually took 9999 + // seconds to finish the map. + pPlayerInfo->m_Score = Score == -1 ? -9999 : Score == 9999 ? -10000 : -Score; pPlayerInfo->m_Local = (int)(m_ClientID == SnappingClient && (m_Paused != PAUSE_PAUSED || SnappingClientVersion >= VERSION_DDNET_OLD)); pPlayerInfo->m_ClientID = id; pPlayerInfo->m_Team = m_Team; @@ -373,7 +374,7 @@ void CPlayer::Snap(int SnappingClient) pPlayerInfo->m_PlayerFlags |= protocol7::PLAYERFLAG_ADMIN; // Times are in milliseconds for 0.7 - pPlayerInfo->m_Score = Score == -9999 ? -1 : -Score * 1000; + pPlayerInfo->m_Score = Score == -1 ? -1 : Score * 1000; pPlayerInfo->m_Latency = Latency; } @@ -878,13 +879,7 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result) break; case CScorePlayerResult::PLAYER_INFO: GameServer()->Score()->PlayerData(m_ClientID)->Set(Result.m_Data.m_Info.m_Time, Result.m_Data.m_Info.m_aTimeCp); - m_Score = Result.m_Data.m_Info.m_Score; - m_HasFinishScore = Result.m_Data.m_Info.m_HasFinishScore; - // -9999 stands for no time and isn't displayed in scoreboard, so - // shift the time by a second if the player actually took 9999 - // seconds to finish the map. - if(m_HasFinishScore && m_Score == -9999) - m_Score = -10000; + m_Score = Result.m_Data.m_Info.m_Time; Server()->ExpireServerInfo(); int Birthday = Result.m_Data.m_Info.m_Birthday; if(Birthday != 0 && !m_BirthdayAnnounced) diff --git a/src/game/server/player.h b/src/game/server/player.h index 0251ba9ab..1cdb65afa 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -182,7 +182,6 @@ public: bool m_SpecTeam; bool m_NinjaJetpack; bool m_Afk; - bool m_HasFinishScore; int m_ChatScore; diff --git a/src/game/server/scoreworker.cpp b/src/game/server/scoreworker.cpp index 7fe17776b..04f0ec9e7 100644 --- a/src/game/server/scoreworker.cpp +++ b/src/game/server/scoreworker.cpp @@ -37,10 +37,8 @@ void CScorePlayerResult::SetVariant(Variant v) m_Data.m_MapVote.m_aServer[0] = '\0'; break; case PLAYER_INFO: - m_Data.m_Info.m_Score = -9999; m_Data.m_Info.m_Birthday = 0; - m_Data.m_Info.m_HasFinishScore = false; - m_Data.m_Info.m_Time = 0; + m_Data.m_Info.m_Time = -1; for(float &TimeCp : m_Data.m_Info.m_aTimeCp) TimeCp = 0; } @@ -165,8 +163,6 @@ bool CScoreWorker::LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGa // get the best time float Time = pSqlServer->GetFloat(1); pResult->m_Data.m_Info.m_Time = Time; - pResult->m_Data.m_Info.m_Score = -Time; - pResult->m_Data.m_Info.m_HasFinishScore = true; } for(int i = 0; i < NUM_CHECKPOINTS; i++) diff --git a/src/game/server/scoreworker.h b/src/game/server/scoreworker.h index 733d3b5b6..f6559c226 100644 --- a/src/game/server/scoreworker.h +++ b/src/game/server/scoreworker.h @@ -45,10 +45,8 @@ struct CScorePlayerResult : ISqlResult char m_aBroadcast[1024]; struct { - float m_Time; + float m_Time; // -1 for no time. float m_aTimeCp[NUM_CHECKPOINTS]; - int m_Score; - int m_HasFinishScore; int m_Birthday; // 0 indicates no birthday } m_Info; struct diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index 15d9a72e6..849926ff4 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -809,10 +809,9 @@ void CGameTeams::OnFinish(CPlayer *Player, float Time, const char *pTimestamp) } int TTime = 0 - (int)Time; - if(Player->m_Score < TTime || !Player->m_HasFinishScore) + if(Player->m_Score == -1 || Player->m_Score < TTime) { Player->m_Score = TTime; - Player->m_HasFinishScore = true; } }