mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #2298
2298: Log save/load in teehistorian r=heinrich5991 a=Zwelf Including tests Co-authored-by: Zwelf <zwelf@strct.cc>
This commit is contained in:
commit
ec472a9d0a
|
@ -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")
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 <engine/shared/config.h>
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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_success 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_failure 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", "load_success 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", "load_failure team=%d", Team);
|
||||
}
|
||||
|
||||
WriteExtra(UUID_TEEHISTORIAN_LOAD_FAILURE, Buffer.Data(), Buffer.Size());
|
||||
}
|
||||
|
||||
void CTeeHistorian::EndInputs()
|
||||
{
|
||||
dbg_assert(m_State == STATE_INPUTS, "invalid teehistorian state");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -434,3 +434,98 @@ TEST_F(TeeHistorian, JoinLeave)
|
|||
Finish();
|
||||
Expect(EXPECTED, sizeof(EXPECTED));
|
||||
}
|
||||
|
||||
TEST_F(TeeHistorian, SaveSuccess)
|
||||
{
|
||||
const unsigned char EXPECTED[] = {
|
||||
// EX uuid=4560c756-da29-3036-81d4-90a50f0182cd datalen=42
|
||||
0x4a,
|
||||
0x45, 0x60, 0xc7, 0x56, 0xda, 0x29, 0x30, 0x36,
|
||||
0x81, 0xd4, 0x90, 0xa5, 0x0f, 0x01, 0x82, 0xcd,
|
||||
0x1a,
|
||||
// team=21
|
||||
0x15,
|
||||
// save_id
|
||||
0xfb, 0x13, 0xa5, 0x76, 0xd3, 0x5f, 0x48, 0x93,
|
||||
0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b,
|
||||
// team_save
|
||||
'2', '\t', 'H', '.', '\n', 'l', 'l', '0', 0x00,
|
||||
// FINISH
|
||||
0x40
|
||||
};
|
||||
|
||||
CUuid SaveID = {
|
||||
0xfb, 0x13, 0xa5, 0x76, 0xd3, 0x5f, 0x48, 0x93,
|
||||
0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b,
|
||||
};
|
||||
const char *pTeamSave = "2\tH.\nll0";
|
||||
m_TH.RecordTeamSaveSuccess(21, SaveID, pTeamSave);
|
||||
Finish();
|
||||
Expect(EXPECTED, sizeof(EXPECTED));
|
||||
}
|
||||
|
||||
TEST_F(TeeHistorian, SaveFailed)
|
||||
{
|
||||
const unsigned char EXPECTED[] = {
|
||||
// EX uuid=b29901d5-1244-3bd0-bbde-23d04b1f7ba9 datalen=42
|
||||
0x4a,
|
||||
0xb2, 0x99, 0x01, 0xd5, 0x12, 0x44, 0x3b, 0xd0,
|
||||
0xbb, 0xde, 0x23, 0xd0, 0x4b, 0x1f, 0x7b, 0xa9,
|
||||
0x01,
|
||||
// team=12
|
||||
0x0c,
|
||||
0x40
|
||||
};
|
||||
|
||||
m_TH.RecordTeamSaveFailure(12);
|
||||
Finish();
|
||||
Expect(EXPECTED, sizeof(EXPECTED));
|
||||
}
|
||||
|
||||
TEST_F(TeeHistorian, LoadSuccess)
|
||||
{
|
||||
const unsigned char EXPECTED[] = {
|
||||
// EX uuid=e05408d3-a313-33df-9eb3-ddb990ab954a datalen=42
|
||||
0x4a,
|
||||
0xe0, 0x54, 0x08, 0xd3, 0xa3, 0x13, 0x33, 0xdf,
|
||||
0x9e, 0xb3, 0xdd, 0xb9, 0x90, 0xab, 0x95, 0x4a,
|
||||
0x1a,
|
||||
// team=21
|
||||
0x15,
|
||||
// save_id
|
||||
0xfb, 0x13, 0xa5, 0x76, 0xd3, 0x5f, 0x48, 0x93,
|
||||
0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b,
|
||||
// team_save
|
||||
'2', '\t', 'H', '.', '\n', 'l', 'l', '0', 0x00,
|
||||
// FINISH
|
||||
0x40
|
||||
};
|
||||
|
||||
CUuid SaveID = {
|
||||
0xfb, 0x13, 0xa5, 0x76, 0xd3, 0x5f, 0x48, 0x93,
|
||||
0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b,
|
||||
};
|
||||
const char *pTeamSave = "2\tH.\nll0";
|
||||
m_TH.RecordTeamLoadSuccess(21, SaveID, pTeamSave);
|
||||
Finish();
|
||||
Expect(EXPECTED, sizeof(EXPECTED));
|
||||
}
|
||||
|
||||
TEST_F(TeeHistorian, LoadFailed)
|
||||
{
|
||||
const unsigned char EXPECTED[] = {
|
||||
// EX uuid=ef8905a2-c695-3591-a1cd-53d2015992dd datalen=42
|
||||
0x4a,
|
||||
0xef, 0x89, 0x05, 0xa2, 0xc6, 0x95, 0x35, 0x91,
|
||||
0xa1, 0xcd, 0x53, 0xd2, 0x01, 0x59, 0x92, 0xdd,
|
||||
0x01,
|
||||
// team=12
|
||||
0x0c,
|
||||
0x40
|
||||
};
|
||||
|
||||
m_TH.RecordTeamLoadFailure(12);
|
||||
Finish();
|
||||
Expect(EXPECTED, sizeof(EXPECTED));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue