From 27d9ac54b0cdd1e8f7e7a12768e7a8917b0ce064 Mon Sep 17 00:00:00 2001 From: Learath2 Date: Thu, 13 Feb 2020 16:16:35 +0100 Subject: [PATCH 1/3] Implement dry saves --- src/game/ddracecommands.h | 1 + src/game/server/ddracecommands.cpp | 42 ++++++++++++++++++++++++++++++ src/game/server/gamecontext.h | 1 + 3 files changed, 44 insertions(+) diff --git a/src/game/ddracecommands.h b/src/game/ddracecommands.h index becf5441a..d7b993450 100644 --- a/src/game/ddracecommands.h +++ b/src/game/ddracecommands.h @@ -52,6 +52,7 @@ CONSOLE_COMMAND("unmute", "v[id]", CFGFLAG_SERVER, ConUnmute, this, "") CONSOLE_COMMAND("mutes", "", CFGFLAG_SERVER, ConMutes, this, "") CONSOLE_COMMAND("moderate", "", CFGFLAG_SERVER, ConModerate, this, "Enables/disables active moderator mode for the player") CONSOLE_COMMAND("vote_no", "", CFGFLAG_SERVER, ConVoteNo, this, "Same as \"vote no\"") +CONSOLE_COMMAND("dry_save", "", CFGFLAG_SERVER, ConDrySave, this, "Dump the current savestring") CONSOLE_COMMAND("freezehammer", "v[id]", CFGFLAG_SERVER|CMDFLAG_TEST, ConFreezeHammer, this, "Gives a player Freeze Hammer") CONSOLE_COMMAND("unfreezehammer", "v[id]", CFGFLAG_SERVER|CMDFLAG_TEST, ConUnFreezeHammer, this, "Removes Freeze Hammer from a player") diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index 0f396120b..44bbe442b 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #if defined(CONF_SQL) #include @@ -705,3 +706,44 @@ void CGameContext::ConVoteNo(IConsole::IResult *pResult, void *pUserData) pSelf->ForceVote(pResult->m_ClientID, false); } + +void CGameContext::ConDrySave(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + + if(!pPlayer || pSelf->Server()->GetAuthedState(pResult->m_ClientID) != AUTHED_ADMIN) + return; + + + CSaveTeam SavedTeam(pSelf->m_pController); + int Num = SavedTeam.save(pPlayer->GetTeam()); + switch (Num) + { + case 1: + pSelf->SendChatTarget(pResult->m_ClientID, "You have to be in a team (from 1-63)"); + break; + case 2: + pSelf->SendChatTarget(pResult->m_ClientID, "Could not find your Team"); + break; + case 3: + pSelf->SendChatTarget(pResult->m_ClientID, "Unable to find all Characters"); + break; + case 4: + pSelf->SendChatTarget(pResult->m_ClientID, "Your team is not started yet"); + break; + } + if(!Num) + { + char aBuf[64]; + str_format(aBuf, sizeof(aBuf), "%s-%lld-%s.save", pSelf->Server()->GetMapName(), time_get(), pSelf->Server()->GetAuthName(pResult->m_ClientID)); + IOHANDLE File = pSelf->Storage()->OpenFile(aBuf, IOFLAG_WRITE, IStorage::TYPE_ALL); + if(!File) + return; + + int Len = str_length(SavedTeam.GetString()); + io_write(File, SavedTeam.GetString(), Len); + io_close(File); + } +} diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 8ae148cd1..36972ad50 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -111,6 +111,7 @@ class CGameContext : public IGameServer static void ConClearVotes(IConsole::IResult *pResult, void *pUserData); static void ConVote(IConsole::IResult *pResult, void *pUserData); static void ConVoteNo(IConsole::IResult *pResult, void *pUserData); + static void ConDrySave(IConsole::IResult *pResult, void *pUserData); static void ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); CGameContext(int Resetting); From ec42ce88f674934e877e8f2f7839018070d21815 Mon Sep 17 00:00:00 2001 From: Learath2 Date: Thu, 13 Feb 2020 17:04:58 +0100 Subject: [PATCH 2/3] Change command name, refactor error handling --- src/game/ddracecommands.h | 2 +- src/game/server/ddracecommands.cpp | 22 +++++----------------- src/game/server/save.cpp | 23 +++++++++++++++++++++++ src/game/server/save.h | 1 + src/game/server/score/sql_score.cpp | 18 +++--------------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/game/ddracecommands.h b/src/game/ddracecommands.h index d7b993450..dc7b3c50c 100644 --- a/src/game/ddracecommands.h +++ b/src/game/ddracecommands.h @@ -52,7 +52,7 @@ CONSOLE_COMMAND("unmute", "v[id]", CFGFLAG_SERVER, ConUnmute, this, "") CONSOLE_COMMAND("mutes", "", CFGFLAG_SERVER, ConMutes, this, "") CONSOLE_COMMAND("moderate", "", CFGFLAG_SERVER, ConModerate, this, "Enables/disables active moderator mode for the player") CONSOLE_COMMAND("vote_no", "", CFGFLAG_SERVER, ConVoteNo, this, "Same as \"vote no\"") -CONSOLE_COMMAND("dry_save", "", CFGFLAG_SERVER, ConDrySave, this, "Dump the current savestring") +CONSOLE_COMMAND("save_dry", "", CFGFLAG_SERVER, ConDrySave, this, "Dump the current savestring") CONSOLE_COMMAND("freezehammer", "v[id]", CFGFLAG_SERVER|CMDFLAG_TEST, ConFreezeHammer, this, "Gives a player Freeze Hammer") CONSOLE_COMMAND("unfreezehammer", "v[id]", CFGFLAG_SERVER|CMDFLAG_TEST, ConUnFreezeHammer, this, "Removes Freeze Hammer from a player") diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index 44bbe442b..3a0629730 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -718,23 +718,11 @@ void CGameContext::ConDrySave(IConsole::IResult *pResult, void *pUserData) CSaveTeam SavedTeam(pSelf->m_pController); - int Num = SavedTeam.save(pPlayer->GetTeam()); - switch (Num) - { - case 1: - pSelf->SendChatTarget(pResult->m_ClientID, "You have to be in a team (from 1-63)"); - break; - case 2: - pSelf->SendChatTarget(pResult->m_ClientID, "Could not find your Team"); - break; - case 3: - pSelf->SendChatTarget(pResult->m_ClientID, "Unable to find all Characters"); - break; - case 4: - pSelf->SendChatTarget(pResult->m_ClientID, "Your team is not started yet"); - break; - } - if(!Num) + int Result = SavedTeam.save(pPlayer->GetTeam()); + if(CSaveTeam::HandleSaveError(Result, pResult->m_ClientID, pSelf)) + return; + + if(!Result) { char aBuf[64]; str_format(aBuf, sizeof(aBuf), "%s-%lld-%s.save", pSelf->Server()->GetMapName(), time_get(), pSelf->Server()->GetAuthName(pResult->m_ClientID)); diff --git a/src/game/server/save.cpp b/src/game/server/save.cpp index ce5126fb4..4cc4697ed 100644 --- a/src/game/server/save.cpp +++ b/src/game/server/save.cpp @@ -279,6 +279,29 @@ int CSaveTeam::save(int Team) return 1; } +bool CSaveTeam::HandleSaveError(int Result, int ClientID, CGameContext *pGameContext) +{ + switch(Result) + { + case 1: + pGameContext->SendChatTarget(ClientID, "You have to be in a team (from 1-63)"); + break; + case 2: + pGameContext->SendChatTarget(ClientID, "Could not find your Team"); + break; + case 3: + pGameContext->SendChatTarget(ClientID, "Unable to find all Characters"); + break; + case 4: + pGameContext->SendChatTarget(ClientID, "Your team is not started yet"); + break; + default: + return false; + } + + return true; +} + int CSaveTeam::load(int Team) { if(Team <= 0 || Team >= MAX_CLIENTS) diff --git a/src/game/server/save.h b/src/game/server/save.h index 078560d51..e50273c08 100644 --- a/src/game/server/save.h +++ b/src/game/server/save.h @@ -100,6 +100,7 @@ public: int load(int Team); CSaveTee* SavedTees; + static bool HandleSaveError(int Result, int ClientID, CGameContext *pGameContext); private: int MatchPlayer(char name[16]); CCharacter* MatchCharacter(char name[16], int SaveID); diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index e645798ab..4dfdd9bdb 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -1409,21 +1409,9 @@ bool CSqlScore::SaveTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData { CSaveTeam SavedTeam(pData->GameServer()->m_pController); Num = SavedTeam.save(Team); - switch (Num) - { - case 1: - pData->GameServer()->SendChatTarget(pData->m_ClientID, "You have to be in a team (from 1-63)"); - break; - case 2: - pData->GameServer()->SendChatTarget(pData->m_ClientID, "Could not find your Team"); - break; - case 3: - pData->GameServer()->SendChatTarget(pData->m_ClientID, "Unable to find all Characters"); - break; - case 4: - pData->GameServer()->SendChatTarget(pData->m_ClientID, "Your team is not started yet"); - break; - } + if(CSaveTeam::HandleSaveError(Num, pData->m_ClientID, pData->GameServer())) + return true; + if(!Num) { str_copy(TeamString, SavedTeam.GetString(), sizeof(TeamString)); From 06e948e9445b627a2c1b3062e3de9107df22645d Mon Sep 17 00:00:00 2001 From: Learath2 Date: Fri, 14 Feb 2020 00:03:49 +0100 Subject: [PATCH 3/3] Cleanup --- src/game/server/ddracecommands.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index 3a0629730..b8d901712 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -716,22 +716,18 @@ void CGameContext::ConDrySave(IConsole::IResult *pResult, void *pUserData) if(!pPlayer || pSelf->Server()->GetAuthedState(pResult->m_ClientID) != AUTHED_ADMIN) return; - CSaveTeam SavedTeam(pSelf->m_pController); int Result = SavedTeam.save(pPlayer->GetTeam()); if(CSaveTeam::HandleSaveError(Result, pResult->m_ClientID, pSelf)) return; - if(!Result) - { - char aBuf[64]; - str_format(aBuf, sizeof(aBuf), "%s-%lld-%s.save", pSelf->Server()->GetMapName(), time_get(), pSelf->Server()->GetAuthName(pResult->m_ClientID)); - IOHANDLE File = pSelf->Storage()->OpenFile(aBuf, IOFLAG_WRITE, IStorage::TYPE_ALL); - if(!File) - return; + char aBuf[64]; + str_format(aBuf, sizeof(aBuf), "%s-%lld-%s.save", pSelf->Server()->GetMapName(), time_get(), pSelf->Server()->GetAuthName(pResult->m_ClientID)); + IOHANDLE File = pSelf->Storage()->OpenFile(aBuf, IOFLAG_WRITE, IStorage::TYPE_ALL); + if(!File) + return; - int Len = str_length(SavedTeam.GetString()); - io_write(File, SavedTeam.GetString(), Len); - io_close(File); - } + int Len = str_length(SavedTeam.GetString()); + io_write(File, SavedTeam.GetString(), Len); + io_close(File); }