mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-09 17:48:19 +00:00
Merge pull request #8085 from dobrykafe/pr-timecp
Improve `/timecp` chat command
This commit is contained in:
commit
3489131d78
|
@ -1949,5 +1949,5 @@ void CGameContext::ConTimeCP(IConsole::IResult *pResult, void *pUserData)
|
|||
return;
|
||||
|
||||
const char *pName = pResult->GetString(0);
|
||||
pSelf->Score()->LoadPlayerData(pResult->m_ClientId, pName);
|
||||
pSelf->Score()->LoadPlayerTimeCp(pResult->m_ClientId, pName);
|
||||
}
|
||||
|
|
|
@ -1445,7 +1445,7 @@ void CCharacter::SetTimeCheckpoint(int TimeCheckpoint)
|
|||
if(m_pPlayer->GetClientVersion() >= VERSION_DDRACE)
|
||||
{
|
||||
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCid());
|
||||
if(pData->m_BestTime && pData->m_aBestTimeCp[m_LastTimeCp] != 0.0f)
|
||||
if(pData->m_aBestTimeCp[m_LastTimeCp] != 0.0f)
|
||||
{
|
||||
CNetMsg_Sv_DDRaceTime Msg;
|
||||
Msg.m_Time = (int)(m_Time * 100.0f);
|
||||
|
|
|
@ -910,6 +910,7 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result)
|
|||
GameServer()->CallVote(m_ClientId, Result.m_Data.m_MapVote.m_aMap, aCmd, "/map", aChatmsg);
|
||||
break;
|
||||
case CScorePlayerResult::PLAYER_INFO:
|
||||
{
|
||||
if(Result.m_Data.m_Info.m_Time.has_value())
|
||||
{
|
||||
GameServer()->Score()->PlayerData(m_ClientId)->Set(Result.m_Data.m_Info.m_Time.value(), Result.m_Data.m_Info.m_aTimeCp);
|
||||
|
@ -933,5 +934,13 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result)
|
|||
GameServer()->SendRecord(m_ClientId);
|
||||
break;
|
||||
}
|
||||
case CScorePlayerResult::PLAYER_TIMECP:
|
||||
GameServer()->Score()->PlayerData(m_ClientId)->SetBestTimeCp(Result.m_Data.m_Info.m_aTimeCp);
|
||||
char aBuf[128], aTime[32];
|
||||
str_time_float(Result.m_Data.m_Info.m_Time.value(), TIME_HOURS_CENTISECS, aTime, sizeof(aTime));
|
||||
str_format(aBuf, sizeof(aBuf), "Showing the checkpoint times for '%s' with a race time of %s", Result.m_Data.m_Info.m_aRequestedPlayer, aTime);
|
||||
GameServer()->SendChatTarget(m_ClientId, aBuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,6 +126,11 @@ void CScore::LoadPlayerData(int ClientId, const char *pName)
|
|||
ExecPlayerThread(CScoreWorker::LoadPlayerData, "load player data", ClientId, pName, 0);
|
||||
}
|
||||
|
||||
void CScore::LoadPlayerTimeCp(int ClientId, const char *pName)
|
||||
{
|
||||
ExecPlayerThread(CScoreWorker::LoadPlayerTimeCp, "load player timecp", ClientId, pName, 0);
|
||||
}
|
||||
|
||||
void CScore::MapVote(int ClientId, const char *pMapName)
|
||||
{
|
||||
if(RateLimitPlayer(ClientId))
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
void MapInfo(int ClientId, const char *pMapName);
|
||||
void MapVote(int ClientId, const char *pMapName);
|
||||
void LoadPlayerData(int ClientId, const char *pName = "");
|
||||
void LoadPlayerTimeCp(int ClientId, const char *pName = "");
|
||||
void SaveScore(int ClientId, float Time, const char *pTimestamp, const float aTimeCp[NUM_CHECKPOINTS], bool NotEligible);
|
||||
|
||||
void SaveTeamScore(int *pClientIds, unsigned int Size, float Time, const char *pTimestamp);
|
||||
|
|
|
@ -43,6 +43,13 @@ void CScorePlayerResult::SetVariant(Variant v)
|
|||
m_Data.m_Info.m_Time.reset();
|
||||
for(float &TimeCp : m_Data.m_Info.m_aTimeCp)
|
||||
TimeCp = 0;
|
||||
break;
|
||||
case PLAYER_TIMECP:
|
||||
m_Data.m_Info.m_aRequestedPlayer[0] = '\0';
|
||||
m_Data.m_Info.m_Time.reset();
|
||||
for(float &TimeCp : m_Data.m_Info.m_aTimeCp)
|
||||
TimeCp = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,6 +210,56 @@ bool CScoreWorker::LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGa
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CScoreWorker::LoadPlayerTimeCp(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
|
||||
{
|
||||
const auto *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData);
|
||||
auto *pResult = dynamic_cast<CScorePlayerResult *>(pGameData->m_pResult.get());
|
||||
auto *paMessages = pResult->m_Data.m_aaMessages;
|
||||
|
||||
char aBuf[1024];
|
||||
str_format(aBuf, sizeof(aBuf),
|
||||
"SELECT"
|
||||
" Time, cp1, cp2, cp3, cp4, cp5, cp6, cp7, cp8, cp9, cp10, cp11, cp12, cp13, "
|
||||
" cp14, cp15, cp16, cp17, cp18, cp19, cp20, cp21, cp22, cp23, cp24, cp25, "
|
||||
" (cp1 + cp2 + cp3 + cp4 + cp5 + cp6 + cp7 + cp8 + cp9 + cp10 + cp11 + cp12 + cp13 + cp14 + "
|
||||
" cp15 + cp16 + cp17 + cp18 + cp19 + cp20 + cp21 + cp22 + cp23 + cp24 + cp25 > 0) AS hasCP "
|
||||
"FROM %s_race "
|
||||
"WHERE Map = ? AND Name = ? AND hasCP = true "
|
||||
"ORDER BY Time ASC "
|
||||
"LIMIT 1",
|
||||
pSqlServer->GetPrefix());
|
||||
if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *pPlayer = pData->m_aName[0] != '\0' ? pData->m_aName : pData->m_aRequestingPlayer;
|
||||
pSqlServer->BindString(1, pData->m_aMap);
|
||||
pSqlServer->BindString(2, pPlayer);
|
||||
|
||||
bool End;
|
||||
if(pSqlServer->Step(&End, pError, ErrorSize))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!End)
|
||||
{
|
||||
pResult->SetVariant(CScorePlayerResult::PLAYER_TIMECP);
|
||||
pResult->m_Data.m_Info.m_Time = pSqlServer->GetFloat(1);
|
||||
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||
{
|
||||
pResult->m_Data.m_Info.m_aTimeCp[i] = pSqlServer->GetFloat(i + 2);
|
||||
}
|
||||
str_copy(pResult->m_Data.m_Info.m_aRequestedPlayer, pPlayer, sizeof(pResult->m_Data.m_Info.m_aRequestedPlayer));
|
||||
}
|
||||
else
|
||||
{
|
||||
pResult->SetVariant(CScorePlayerResult::DIRECT);
|
||||
str_format(paMessages[0], sizeof(paMessages[0]), "'%s' has no checkpoint times available", pPlayer);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CScoreWorker::MapVote(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize)
|
||||
{
|
||||
const auto *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData);
|
||||
|
|
|
@ -39,6 +39,7 @@ struct CScorePlayerResult : ISqlResult
|
|||
BROADCAST,
|
||||
MAP_VOTE,
|
||||
PLAYER_INFO,
|
||||
PLAYER_TIMECP,
|
||||
} m_MessageKind;
|
||||
union
|
||||
{
|
||||
|
@ -49,6 +50,7 @@ struct CScorePlayerResult : ISqlResult
|
|||
std::optional<float> m_Time;
|
||||
float m_aTimeCp[NUM_CHECKPOINTS];
|
||||
int m_Birthday; // 0 indicates no birthday
|
||||
char m_aRequestedPlayer[MAX_NAME_LENGTH];
|
||||
} m_Info = {};
|
||||
struct
|
||||
{
|
||||
|
@ -244,6 +246,12 @@ public:
|
|||
m_aBestTimeCp[i] = aTimeCp[i];
|
||||
}
|
||||
|
||||
void SetBestTimeCp(const float aTimeCp[NUM_CHECKPOINTS])
|
||||
{
|
||||
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||
m_aBestTimeCp[i] = aTimeCp[i];
|
||||
}
|
||||
|
||||
float m_BestTime;
|
||||
float m_aBestTimeCp[NUM_CHECKPOINTS];
|
||||
|
||||
|
@ -284,6 +292,7 @@ struct CScoreWorker
|
|||
static bool MapVote(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
|
||||
|
||||
static bool LoadPlayerData(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
|
||||
static bool LoadPlayerTimeCp(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
|
||||
static bool MapInfo(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
|
||||
static bool ShowRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
|
||||
static bool ShowTeamRank(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize);
|
||||
|
|
Loading…
Reference in a new issue