From 82af70554242c2c7acf09045fd812612fb9e0bc2 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 27 Sep 2024 11:41:39 +0800 Subject: [PATCH] Cleanup sql worker request/result naming convention There are two interfaces for score worker data: There is ``ISqlResult`` and every class inheriting from it should have the suffix ``Result`` Then there is ``ISqlData`` and every class inheriting from it should have the suffix ``Data`` if it is data that should be written in an INSERT statement. Or ``Request`` if it is used to perform a read operation and will be used in a SELECT statament. The convention was mostly established alreay. In this commit the last three classes that broke this convention got fixed. --- src/game/server/score.cpp | 6 +++--- src/game/server/scoreworker.cpp | 6 +++--- src/game/server/scoreworker.h | 16 ++++++++-------- src/test/score.cpp | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/game/server/score.cpp b/src/game/server/score.cpp index ee7c21167..6c4454c3f 100644 --- a/src/game/server/score.cpp +++ b/src/game/server/score.cpp @@ -112,7 +112,7 @@ void CScore::LoadBestTime() auto LoadBestTimeResult = std::make_shared(); m_pGameServer->m_pController->m_pLoadBestTimeResult = LoadBestTimeResult; - auto Tmp = std::make_unique(LoadBestTimeResult); + auto Tmp = std::make_unique(LoadBestTimeResult); str_copy(Tmp->m_aMap, Server()->GetMapName(), sizeof(Tmp->m_aMap)); m_pPool->Execute(CScoreWorker::LoadBestTime, std::move(Tmp), "load best time"); } @@ -308,7 +308,7 @@ void CScore::SaveTeam(int ClientId, const char *pCode, const char *pServer) return; pController->Teams().SetSaving(Team, SaveResult); - auto Tmp = std::make_unique(SaveResult); + auto Tmp = std::make_unique(SaveResult); str_copy(Tmp->m_aCode, pCode, sizeof(Tmp->m_aCode)); str_copy(Tmp->m_aMap, Server()->GetMapName(), sizeof(Tmp->m_aMap)); str_copy(Tmp->m_aServer, pServer, sizeof(Tmp->m_aServer)); @@ -370,7 +370,7 @@ void CScore::LoadTeam(const char *pCode, int ClientId) auto SaveResult = std::make_shared(ClientId); SaveResult->m_Status = CScoreSaveResult::LOAD_FAILED; pController->Teams().SetSaving(Team, SaveResult); - auto Tmp = std::make_unique(SaveResult); + auto Tmp = std::make_unique(SaveResult); str_copy(Tmp->m_aCode, pCode, sizeof(Tmp->m_aCode)); str_copy(Tmp->m_aMap, Server()->GetMapName(), sizeof(Tmp->m_aMap)); Tmp->m_ClientId = ClientId; diff --git a/src/game/server/scoreworker.cpp b/src/game/server/scoreworker.cpp index aa2b14314..76d85f5a5 100644 --- a/src/game/server/scoreworker.cpp +++ b/src/game/server/scoreworker.cpp @@ -101,7 +101,7 @@ bool CTeamrank::SamePlayers(const std::vector *pvSortedNames) bool CScoreWorker::LoadBestTime(IDbConnection *pSqlServer, const ISqlData *pGameData, char *pError, int ErrorSize) { - const auto *pData = dynamic_cast(pGameData); + const auto *pData = dynamic_cast(pGameData); auto *pResult = dynamic_cast(pGameData->m_pResult.get()); char aBuf[512]; @@ -1568,7 +1568,7 @@ bool CScoreWorker::RandomUnfinishedMap(IDbConnection *pSqlServer, const ISqlData bool CScoreWorker::SaveTeam(IDbConnection *pSqlServer, const ISqlData *pGameData, Write w, char *pError, int ErrorSize) { - const auto *pData = dynamic_cast(pGameData); + const auto *pData = dynamic_cast(pGameData); auto *pResult = dynamic_cast(pGameData->m_pResult.get()); if(w == Write::NORMAL_SUCCEEDED) @@ -1715,7 +1715,7 @@ bool CScoreWorker::LoadTeam(IDbConnection *pSqlServer, const ISqlData *pGameData { if(w == Write::NORMAL_SUCCEEDED || w == Write::BACKUP_FIRST) return false; - const auto *pData = dynamic_cast(pGameData); + const auto *pData = dynamic_cast(pGameData); auto *pResult = dynamic_cast(pGameData->m_pResult.get()); pResult->m_Status = CScoreSaveResult::LOAD_FAILED; diff --git a/src/game/server/scoreworker.h b/src/game/server/scoreworker.h index 9e38501e5..ae641fe2a 100644 --- a/src/game/server/scoreworker.h +++ b/src/game/server/scoreworker.h @@ -72,9 +72,9 @@ struct CScoreLoadBestTimeResult : ISqlResult float m_CurrentRecord; }; -struct CSqlLoadBestTimeData : ISqlData +struct CSqlLoadBestTimeRequest : ISqlData { - CSqlLoadBestTimeData(std::shared_ptr pResult) : + CSqlLoadBestTimeRequest(std::shared_ptr pResult) : ISqlData(std::move(pResult)) { } @@ -188,13 +188,13 @@ struct CSqlTeamScoreData : ISqlData CUuid m_TeamrankUuid; }; -struct CSqlTeamSave : ISqlData +struct CSqlTeamSaveData : ISqlData { - CSqlTeamSave(std::shared_ptr pResult) : + CSqlTeamSaveData(std::shared_ptr pResult) : ISqlData(std::move(pResult)) { } - virtual ~CSqlTeamSave(){}; + virtual ~CSqlTeamSaveData(){}; char m_aClientName[MAX_NAME_LENGTH]; char m_aMap[MAX_MAP_LENGTH]; @@ -203,13 +203,13 @@ struct CSqlTeamSave : ISqlData char m_aServer[5]; }; -struct CSqlTeamLoad : ISqlData +struct CSqlTeamLoadRequest : ISqlData { - CSqlTeamLoad(std::shared_ptr pResult) : + CSqlTeamLoadRequest(std::shared_ptr pResult) : ISqlData(std::move(pResult)) { } - virtual ~CSqlTeamLoad(){}; + virtual ~CSqlTeamLoadRequest(){}; char m_aCode[128]; char m_aMap[MAX_MAP_LENGTH]; diff --git a/src/test/score.cpp b/src/test/score.cpp index c9c9e190e..4bd3dcdec 100644 --- a/src/test/score.cpp +++ b/src/test/score.cpp @@ -70,9 +70,9 @@ struct Score : public testing::TestWithParam void LoadBestTime() { - CSqlLoadBestTimeData loadBestTimeData(std::make_shared()); - str_copy(loadBestTimeData.m_aMap, "Kobra 3", sizeof(loadBestTimeData.m_aMap)); - ASSERT_FALSE(CScoreWorker::LoadBestTime(m_pConn, &loadBestTimeData, m_aError, sizeof(m_aError))) << m_aError; + CSqlLoadBestTimeRequest loadBestTimeReq(std::make_shared()); + str_copy(loadBestTimeReq.m_aMap, "Kobra 3", sizeof(loadBestTimeReq.m_aMap)); + ASSERT_FALSE(CScoreWorker::LoadBestTime(m_pConn, &loadBestTimeReq, m_aError, sizeof(m_aError))) << m_aError; } void InsertMap()