diff --git a/src/engine/shared/teehistorian_ex_chunks.h b/src/engine/shared/teehistorian_ex_chunks.h index 0cfccaa91..d4187a31a 100644 --- a/src/engine/shared/teehistorian_ex_chunks.h +++ b/src/engine/shared/teehistorian_ex_chunks.h @@ -8,3 +8,7 @@ UUID(TEEHISTORIAN_AUTH_LOGIN, "teehistorian-auth-login@ddnet.tw") UUID(TEEHISTORIAN_AUTH_LOGOUT, "teehistorian-auth-logout@ddnet.tw") UUID(TEEHISTORIAN_JOINVER6, "teehistorian-joinver6@ddnet.tw") UUID(TEEHISTORIAN_JOINVER7, "teehistorian-joinver7@ddnet.tw") +UUID(TEEHISTORIAN_SAVE_SUCCESS, "teehistorian-save-success@ddnet.tw") +UUID(TEEHISTORIAN_SAVE_FAILURE, "teehistorian-save-failure@ddnet.tw") +UUID(TEEHISTORIAN_LOAD_SUCCESS, "teehistorian-load-success@ddnet.tw") +UUID(TEEHISTORIAN_LOAD_FAILURE, "teehistorian-load-failure@ddnet.tw") diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 0a05fb08e..bdca41b86 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -127,6 +127,8 @@ public: CTuningParams *Tuning() { return &m_Tuning; } CTuningParams *TuningList() { return &m_aTuningList[0]; } IAntibot *Antibot() { return m_pAntibot; } + CTeeHistorian *TeeHistorian() { return &m_TeeHistorian; } + bool TeeHistorianActive() const { return m_TeeHistorianActive; } CGameContext(); ~CGameContext(); diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index ac4250e98..815ab100b 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -1,5 +1,6 @@ /* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */ #include "teams.h" +#include "teehistorian.h" #include "score.h" #include @@ -681,11 +682,17 @@ void CGameTeams::ProcessSaveTeam() GameServer()->SendBroadcast(m_pSaveTeamResult[Team]->m_aBroadcast, -1); if(m_pSaveTeamResult[Team]->m_aMessage[0] != '\0' && m_pSaveTeamResult[Team]->m_Status != CScoreSaveResult::LOAD_FAILED) GameServer()->SendChatTeam(Team, m_pSaveTeamResult[Team]->m_aMessage); - // TODO: log load/save success/fail in teehistorian switch(m_pSaveTeamResult[Team]->m_Status) { case CScoreSaveResult::SAVE_SUCCESS: { + if(GameServer()->TeeHistorianActive()) + { + GameServer()->TeeHistorian()->RecordTeamSaveSuccess( + Team, + m_pSaveTeamResult[Team]->m_SaveID, + m_pSaveTeamResult[Team]->m_SavedTeam.GetString()); + } ResetSavedTeam(m_pSaveTeamResult[Team]->m_RequestingPlayer, Team); char aSaveID[UUID_MAXSTRSIZE]; FormatUuid(m_pSaveTeamResult[Team]->m_SaveID, aSaveID, UUID_MAXSTRSIZE); @@ -693,11 +700,20 @@ void CGameTeams::ProcessSaveTeam() break; } case CScoreSaveResult::SAVE_FAILED: + if(GameServer()->TeeHistorianActive()) + GameServer()->TeeHistorian()->RecordTeamSaveFailure(Team); if(Count(Team) > 0) m_pSaveTeamResult[Team]->m_SavedTeam.load(Team); break; case CScoreSaveResult::LOAD_SUCCESS: { + if(GameServer()->TeeHistorianActive()) + { + GameServer()->TeeHistorian()->RecordTeamLoadSuccess( + Team, + m_pSaveTeamResult[Team]->m_SaveID, + m_pSaveTeamResult[Team]->m_SavedTeam.GetString()); + } if(Count(Team) > 0) m_pSaveTeamResult[Team]->m_SavedTeam.load(Team); char aSaveID[UUID_MAXSTRSIZE]; @@ -706,6 +722,8 @@ void CGameTeams::ProcessSaveTeam() break; } case CScoreSaveResult::LOAD_FAILED: + if(GameServer()->TeeHistorianActive()) + GameServer()->TeeHistorian()->RecordTeamLoadFailure(Team); if(m_pSaveTeamResult[Team]->m_aMessage[0] != '\0') GameServer()->SendChatTarget(m_pSaveTeamResult[Team]->m_RequestingPlayer, m_pSaveTeamResult[Team]->m_aMessage); break; diff --git a/src/game/server/teehistorian.cpp b/src/game/server/teehistorian.cpp index c617e0d7e..4b59d4ecd 100644 --- a/src/game/server/teehistorian.cpp +++ b/src/game/server/teehistorian.cpp @@ -490,6 +490,70 @@ void CTeeHistorian::RecordTestExtra() WriteExtra(UUID_TEEHISTORIAN_TEST, "", 0); } +void CTeeHistorian::RecordTeamSaveSuccess(int Team, CUuid SaveID, const char *pTeamSave) +{ + CPacker Buffer; + Buffer.Reset(); + Buffer.AddInt(Team); + Buffer.AddRaw(&SaveID, sizeof(SaveID)); + Buffer.AddString(pTeamSave, 0); + + if(m_Debug) + { + char aSaveID[UUID_MAXSTRSIZE]; + FormatUuid(SaveID, aSaveID, sizeof(aSaveID)); + dbg_msg("teehistorian", "save_load team=%d save_id=%s team_save='%s'", Team, aSaveID, pTeamSave); + } + + WriteExtra(UUID_TEEHISTORIAN_SAVE_SUCCESS, Buffer.Data(), Buffer.Size()); +} + +void CTeeHistorian::RecordTeamSaveFailure(int Team) +{ + CPacker Buffer; + Buffer.Reset(); + Buffer.AddInt(Team); + + if(m_Debug) + { + dbg_msg("teehistorian", "save_load team=%d", Team); + } + + WriteExtra(UUID_TEEHISTORIAN_SAVE_FAILURE, Buffer.Data(), Buffer.Size()); +} + +void CTeeHistorian::RecordTeamLoadSuccess(int Team, CUuid SaveID, const char *pTeamSave) +{ + CPacker Buffer; + Buffer.Reset(); + Buffer.AddInt(Team); + Buffer.AddRaw(&SaveID, sizeof(SaveID)); + Buffer.AddString(pTeamSave, 0); + + if(m_Debug) + { + char aSaveID[UUID_MAXSTRSIZE]; + FormatUuid(SaveID, aSaveID, sizeof(aSaveID)); + dbg_msg("teehistorian", "save_load team=%d save_id=%s team_save='%s'", Team, aSaveID, pTeamSave); + } + + WriteExtra(UUID_TEEHISTORIAN_LOAD_SUCCESS, Buffer.Data(), Buffer.Size()); +} + +void CTeeHistorian::RecordTeamLoadFailure(int Team) +{ + CPacker Buffer; + Buffer.Reset(); + Buffer.AddInt(Team); + + if(m_Debug) + { + dbg_msg("teehistorian", "save_load team=%d", Team); + } + + WriteExtra(UUID_TEEHISTORIAN_LOAD_FAILURE, Buffer.Data(), Buffer.Size()); +} + void CTeeHistorian::EndInputs() { dbg_assert(m_State == STATE_INPUTS, "invalid teehistorian state"); diff --git a/src/game/server/teehistorian.h b/src/game/server/teehistorian.h index 045b62e1f..62599b530 100644 --- a/src/game/server/teehistorian.h +++ b/src/game/server/teehistorian.h @@ -66,6 +66,10 @@ public: void RecordPlayerDrop(int ClientID, const char *pReason); void RecordConsoleCommand(int ClientID, int FlagMask, const char *pCmd, IConsole::IResult *pResult); void RecordTestExtra(); + void RecordTeamSaveSuccess(int Team, CUuid SaveID, const char *pTeamSave); + void RecordTeamSaveFailure(int Team); + void RecordTeamLoadSuccess(int Team, CUuid SaveID, const char *pTeamSave); + void RecordTeamLoadFailure(int Team); void EndInputs(); void EndTick();