mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-13 11:38:19 +00:00
Unify time score handling in the server
It's now always -1 for "no time" or a nonnegative integer for the number of seconds it took the player to finish the map.
This commit is contained in:
parent
f977a382f3
commit
d8053fba7d
|
@ -296,7 +296,7 @@ void CServer::CClient::Reset()
|
||||||
m_LastAckedSnapshot = -1;
|
m_LastAckedSnapshot = -1;
|
||||||
m_LastInputTick = -1;
|
m_LastInputTick = -1;
|
||||||
m_SnapRate = CClient::SNAPRATE_INIT;
|
m_SnapRate = CClient::SNAPRATE_INIT;
|
||||||
m_Score = 0;
|
m_Score = -1;
|
||||||
m_NextMapChunk = 0;
|
m_NextMapChunk = 0;
|
||||||
m_Flags = 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
|
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_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?
|
ADD_INT(q, GameServer()->IsClientPlayer(i) ? 1 : 0); // is player?
|
||||||
if(Type == SERVERINFO_EXTENDED)
|
if(Type == SERVERINFO_EXTENDED)
|
||||||
q.AddString("", 0); // extra info, reserved
|
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(ClientName(i), MAX_NAME_LENGTH); // client name
|
||||||
Packer.AddString(ClientClan(i), MAX_CLAN_LENGTH); // client clan
|
Packer.AddString(ClientClan(i), MAX_CLAN_LENGTH); // client clan
|
||||||
Packer.AddInt(m_aClients[i].m_Country); // client country
|
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)
|
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(aCName, sizeof(aCName), ClientName(i)),
|
||||||
EscapeJson(aCClan, sizeof(aCClan), ClientClan(i)),
|
EscapeJson(aCClan, sizeof(aCClan), ClientClan(i)),
|
||||||
m_aClients[i].m_Country,
|
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)));
|
JsonBool(GameServer()->IsClientPlayer(i)));
|
||||||
str_append(aInfo, aClientInfo, sizeof(aInfo));
|
str_append(aInfo, aClientInfo, sizeof(aInfo));
|
||||||
FirstPlayer = false;
|
FirstPlayer = false;
|
||||||
|
|
|
@ -119,8 +119,7 @@ void CPlayer::Reset()
|
||||||
m_DND = false;
|
m_DND = false;
|
||||||
|
|
||||||
m_LastPause = 0;
|
m_LastPause = 0;
|
||||||
m_Score = -9999;
|
m_Score = -1;
|
||||||
m_HasFinishScore = false;
|
|
||||||
|
|
||||||
// Variable initialized:
|
// Variable initialized:
|
||||||
m_Last_Team = 0;
|
m_Last_Team = 0;
|
||||||
|
@ -337,11 +336,10 @@ void CPlayer::Snap(int SnappingClient)
|
||||||
|
|
||||||
int SnappingClientVersion = GameServer()->GetClientVersion(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 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
|
// send 0 if times of others are not shown
|
||||||
if(SnappingClient != m_ClientID && g_Config.m_SvHideScore)
|
if(SnappingClient != m_ClientID && g_Config.m_SvHideScore)
|
||||||
Score = -9999;
|
Score = -1;
|
||||||
|
|
||||||
if(!Server()->IsSixup(SnappingClient))
|
if(!Server()->IsSixup(SnappingClient))
|
||||||
{
|
{
|
||||||
|
@ -350,7 +348,10 @@ void CPlayer::Snap(int SnappingClient)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pPlayerInfo->m_Latency = Latency;
|
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_Local = (int)(m_ClientID == SnappingClient && (m_Paused != PAUSE_PAUSED || SnappingClientVersion >= VERSION_DDNET_OLD));
|
||||||
pPlayerInfo->m_ClientID = id;
|
pPlayerInfo->m_ClientID = id;
|
||||||
pPlayerInfo->m_Team = m_Team;
|
pPlayerInfo->m_Team = m_Team;
|
||||||
|
@ -373,7 +374,7 @@ void CPlayer::Snap(int SnappingClient)
|
||||||
pPlayerInfo->m_PlayerFlags |= protocol7::PLAYERFLAG_ADMIN;
|
pPlayerInfo->m_PlayerFlags |= protocol7::PLAYERFLAG_ADMIN;
|
||||||
|
|
||||||
// Times are in milliseconds for 0.7
|
// 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;
|
pPlayerInfo->m_Latency = Latency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,13 +879,7 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result)
|
||||||
break;
|
break;
|
||||||
case CScorePlayerResult::PLAYER_INFO:
|
case CScorePlayerResult::PLAYER_INFO:
|
||||||
GameServer()->Score()->PlayerData(m_ClientID)->Set(Result.m_Data.m_Info.m_Time, Result.m_Data.m_Info.m_aTimeCp);
|
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_Score = Result.m_Data.m_Info.m_Time;
|
||||||
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;
|
|
||||||
Server()->ExpireServerInfo();
|
Server()->ExpireServerInfo();
|
||||||
int Birthday = Result.m_Data.m_Info.m_Birthday;
|
int Birthday = Result.m_Data.m_Info.m_Birthday;
|
||||||
if(Birthday != 0 && !m_BirthdayAnnounced)
|
if(Birthday != 0 && !m_BirthdayAnnounced)
|
||||||
|
|
|
@ -182,7 +182,6 @@ public:
|
||||||
bool m_SpecTeam;
|
bool m_SpecTeam;
|
||||||
bool m_NinjaJetpack;
|
bool m_NinjaJetpack;
|
||||||
bool m_Afk;
|
bool m_Afk;
|
||||||
bool m_HasFinishScore;
|
|
||||||
|
|
||||||
int m_ChatScore;
|
int m_ChatScore;
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,8 @@ void CScorePlayerResult::SetVariant(Variant v)
|
||||||
m_Data.m_MapVote.m_aServer[0] = '\0';
|
m_Data.m_MapVote.m_aServer[0] = '\0';
|
||||||
break;
|
break;
|
||||||
case PLAYER_INFO:
|
case PLAYER_INFO:
|
||||||
m_Data.m_Info.m_Score = -9999;
|
|
||||||
m_Data.m_Info.m_Birthday = 0;
|
m_Data.m_Info.m_Birthday = 0;
|
||||||
m_Data.m_Info.m_HasFinishScore = false;
|
m_Data.m_Info.m_Time = -1;
|
||||||
m_Data.m_Info.m_Time = 0;
|
|
||||||
for(float &TimeCp : m_Data.m_Info.m_aTimeCp)
|
for(float &TimeCp : m_Data.m_Info.m_aTimeCp)
|
||||||
TimeCp = 0;
|
TimeCp = 0;
|
||||||
}
|
}
|
||||||
|
@ -165,8 +163,6 @@ bool CScoreWorker::LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGa
|
||||||
// get the best time
|
// get the best time
|
||||||
float Time = pSqlServer->GetFloat(1);
|
float Time = pSqlServer->GetFloat(1);
|
||||||
pResult->m_Data.m_Info.m_Time = Time;
|
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++)
|
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||||
|
|
|
@ -45,10 +45,8 @@ struct CScorePlayerResult : ISqlResult
|
||||||
char m_aBroadcast[1024];
|
char m_aBroadcast[1024];
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
float m_Time;
|
float m_Time; // -1 for no time.
|
||||||
float m_aTimeCp[NUM_CHECKPOINTS];
|
float m_aTimeCp[NUM_CHECKPOINTS];
|
||||||
int m_Score;
|
|
||||||
int m_HasFinishScore;
|
|
||||||
int m_Birthday; // 0 indicates no birthday
|
int m_Birthday; // 0 indicates no birthday
|
||||||
} m_Info;
|
} m_Info;
|
||||||
struct
|
struct
|
||||||
|
|
|
@ -809,10 +809,9 @@ void CGameTeams::OnFinish(CPlayer *Player, float Time, const char *pTimestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
int TTime = 0 - (int)Time;
|
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_Score = TTime;
|
||||||
Player->m_HasFinishScore = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue