diff --git a/src/engine/shared/teehistorian_ex_chunks.h b/src/engine/shared/teehistorian_ex_chunks.h index b3e25c3ba..a67558971 100644 --- a/src/engine/shared/teehistorian_ex_chunks.h +++ b/src/engine/shared/teehistorian_ex_chunks.h @@ -13,3 +13,4 @@ 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") UUID(TEEHISTORIAN_TEAM_CHANGE, "teehistorian-team-change@ddnet.tw") +UUID(TEEHISTORIAN_TEAM_PRACTICE, "teehistorian-team-practice@ddnet.tw") diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index bee16c3db..17aea7647 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1078,6 +1078,10 @@ void CGameContext::OnTick() m_TeeHistorian.RecordPlayerTeam(i, pController->m_Teams.m_Core.Team(i)); } } + for(int i = 0; i < MAX_CLIENTS; i++) + { + m_TeeHistorian.RecordTeamPractice(i, pController->m_Teams.IsPractice(i)); + } m_TeeHistorian.EndPlayers(); m_TeeHistorian.BeginInputs(); } diff --git a/src/game/server/teehistorian.cpp b/src/game/server/teehistorian.cpp index c102d43af..561ec9f21 100644 --- a/src/game/server/teehistorian.cpp +++ b/src/game/server/teehistorian.cpp @@ -52,6 +52,10 @@ void CTeeHistorian::Reset(const CGameInfo *pGameInfo, WRITE_CALLBACK pfnWriteCal { PrevPlayerTeam = 0; } + for(auto &PrevTeamPractice : m_aPrevTeamPractice) + { + PrevTeamPractice = false; + } // `m_PrevMaxClientID` is initialized in `BeginPlayers` for(auto &PrevPlayer : m_aPrevPlayers) @@ -338,6 +342,28 @@ void CTeeHistorian::RecordPlayerTeam(int ClientID, int Team) } } +void CTeeHistorian::RecordTeamPractice(int Team, bool Practice) +{ + if(m_aPrevTeamPractice[Team] != Practice) + { + m_aPrevTeamPractice[Team] = Practice; + + EnsureTickWritten(); + + CPacker Buffer; + Buffer.Reset(); + Buffer.AddInt(Team); + Buffer.AddInt(Practice); + + if(m_Debug) + { + dbg_msg("teehistorian", "team_rescue team=%d practice=%d", Team, Practice); + } + + WriteExtra(UUID_TEEHISTORIAN_TEAM_PRACTICE, Buffer.Data(), Buffer.Size()); + } +} + void CTeeHistorian::Write(const void *pData, int DataSize) { m_pfnWriteCallback(pData, DataSize, m_pWriteCallbackUserdata); diff --git a/src/game/server/teehistorian.h b/src/game/server/teehistorian.h index 9e404ac0e..dd52f4c1a 100644 --- a/src/game/server/teehistorian.h +++ b/src/game/server/teehistorian.h @@ -58,6 +58,7 @@ public: void RecordPlayer(int ClientID, const CNetObj_CharacterCore *pChar); void RecordDeadPlayer(int ClientID); void RecordPlayerTeam(int ClientID, int Team); + void RecordTeamPractice(int Team, bool Practice); void EndPlayers(); void BeginInputs(); @@ -125,6 +126,7 @@ private: int m_PrevMaxClientID; int m_MaxClientID; int m_aPrevPlayerTeam[MAX_CLIENTS]; + bool m_aPrevTeamPractice[MAX_CLIENTS]; CPlayer m_aPrevPlayers[MAX_CLIENTS]; }; diff --git a/src/test/teehistorian.cpp b/src/test/teehistorian.cpp index 8751f5f41..7920c2d18 100644 --- a/src/test/teehistorian.cpp +++ b/src/test/teehistorian.cpp @@ -552,3 +552,23 @@ TEST_F(TeeHistorian, TeamChange) Finish(); Expect(EXPECTED, sizeof(EXPECTED)); } + +TEST_F(TeeHistorian, TeamPractice) +{ + const unsigned char EXPECTED[] = { + // EX uuid=5792834e-81d1-34c9-a29b-b5ff25dac3bc datalen=2 + 0x4a, + 0x57, 0x92, 0x83, 0x4e, 0x81, 0xd1, 0x34, 0xc9, + 0xa2, 0x9b, 0xb5, 0xff, 0x25, 0xda, 0xc3, 0xbc, + 0x02, + // team=23 + 0x17, + // practice=1 + 0x01, + // FINISH + 0x40}; + + m_TH.RecordTeamPractice(23, 1); + Finish(); + Expect(EXPECTED, sizeof(EXPECTED)); +}