From 783f4e3093f50577c07453d0d6f808c01f543cae Mon Sep 17 00:00:00 2001 From: Zwelf Date: Sun, 14 Apr 2024 20:32:31 +0200 Subject: [PATCH] Record player name in Teehistorian files --- src/engine/server.h | 1 + src/engine/server/server.cpp | 3 ++- src/engine/shared/teehistorian_ex_chunks.h | 1 + src/game/server/gamecontext.cpp | 8 ++++++++ src/game/server/gamecontext.h | 1 + src/game/server/teehistorian.cpp | 17 +++++++++++++++++ src/game/server/teehistorian.h | 1 + src/test/teehistorian.cpp | 18 ++++++++++++++++++ 8 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/engine/server.h b/src/engine/server.h index af9c395bc..7111141a3 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -356,6 +356,7 @@ public: virtual void TeehistorianRecordPlayerJoin(int ClientId, bool Sixup) = 0; virtual void TeehistorianRecordPlayerDrop(int ClientId, const char *pReason) = 0; virtual void TeehistorianRecordPlayerRejoin(int ClientId) = 0; + virtual void TeehistorianRecordPlayerName(int ClientId, const char *pName) = 0; virtual void FillAntibot(CAntibotRoundData *pData) = 0; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index f258dea50..403d6cf8c 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -354,10 +354,11 @@ bool CServer::SetClientNameImpl(int ClientId, const char *pNameRequest, bool Set bool Changed = str_comp(m_aClients[ClientId].m_aName, aNameTry) != 0; - if(Set) + if(Set && Changed) { // set the client name str_copy(m_aClients[ClientId].m_aName, aNameTry); + GameServer()->TeehistorianRecordPlayerName(ClientId, m_aClients[ClientId].m_aName); } return Changed; diff --git a/src/engine/shared/teehistorian_ex_chunks.h b/src/engine/shared/teehistorian_ex_chunks.h index b1f07fefd..e0f3f281a 100644 --- a/src/engine/shared/teehistorian_ex_chunks.h +++ b/src/engine/shared/teehistorian_ex_chunks.h @@ -18,3 +18,4 @@ UUID(TEEHISTORIAN_TEAM_PRACTICE, "teehistorian-team-practice@ddnet.tw") UUID(TEEHISTORIAN_PLAYER_READY, "teehistorian-player-ready@ddnet.tw") UUID(TEEHISTORIAN_PLAYER_REJOIN, "teehistorian-rejoinver6@ddnet.org") UUID(TEEHISTORIAN_ANTIBOT, "teehistorian-antibot@ddnet.org") +UUID(TEEHISTORIAN_PLAYER_NAME, "teehistorian-player-name@ddnet.org") diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 9e806cd33..8bc85ce77 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1767,6 +1767,14 @@ void CGameContext::TeehistorianRecordPlayerRejoin(int ClientId) } } +void CGameContext::TeehistorianRecordPlayerName(int ClientId, const char *pName) +{ + if(m_TeeHistorianActive) + { + m_TeeHistorian.RecordPlayerName(ClientId, pName); + } +} + bool CGameContext::OnClientDDNetVersionKnown(int ClientId) { IServer::CClientInfo Info; diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index a47effe24..bc6acb129 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -328,6 +328,7 @@ public: void TeehistorianRecordPlayerJoin(int ClientId, bool Sixup) override; void TeehistorianRecordPlayerDrop(int ClientId, const char *pReason) override; void TeehistorianRecordPlayerRejoin(int ClientId) override; + void TeehistorianRecordPlayerName(int ClientId, const char *pName) override; bool IsClientReady(int ClientId) const override; bool IsClientPlayer(int ClientId) const override; diff --git a/src/game/server/teehistorian.cpp b/src/game/server/teehistorian.cpp index f0a4f36b5..021ecd6be 100644 --- a/src/game/server/teehistorian.cpp +++ b/src/game/server/teehistorian.cpp @@ -573,6 +573,23 @@ void CTeeHistorian::RecordPlayerDrop(int ClientId, const char *pReason) Write(Buffer.Data(), Buffer.Size()); } +void CTeeHistorian::RecordPlayerName(int ClientId, const char *pName) +{ + EnsureTickWritten(); + + CPacker Buffer; + Buffer.Reset(); + Buffer.AddInt(ClientId); + Buffer.AddString(pName, 0); + + if(m_Debug) + { + dbg_msg("teehistorian", "drop cid=%d reason='%s'", ClientId, pName); + } + + WriteExtra(UUID_TEEHISTORIAN_PLAYER_NAME, Buffer.Data(), Buffer.Size()); +} + void CTeeHistorian::RecordConsoleCommand(int ClientId, int FlagMask, const char *pCmd, IConsole::IResult *pResult) { EnsureTickWritten(); diff --git a/src/game/server/teehistorian.h b/src/game/server/teehistorian.h index e9a8eb343..fc5203fc2 100644 --- a/src/game/server/teehistorian.h +++ b/src/game/server/teehistorian.h @@ -70,6 +70,7 @@ public: void RecordPlayerRejoin(int ClientId); void RecordPlayerReady(int ClientId); void RecordPlayerDrop(int ClientId, const char *pReason); + void RecordPlayerName(int ClientId, const char *pName); void RecordConsoleCommand(int ClientId, int FlagMask, const char *pCmd, IConsole::IResult *pResult); void RecordTestExtra(); void RecordPlayerSwap(int ClientId1, int ClientId2); diff --git a/src/test/teehistorian.cpp b/src/test/teehistorian.cpp index 7dceea260..d2d589aff 100644 --- a/src/test/teehistorian.cpp +++ b/src/test/teehistorian.cpp @@ -838,6 +838,24 @@ TEST_F(TeeHistorian, AntibotEmptyMessage) Expect(EXPECTED, sizeof(EXPECTED)); } +TEST_F(TeeHistorian, PlayerName) +{ + const unsigned char EXPECTED[] = { + // EX uuid=d016f9b9-4151-3b87-87e5-3a6087eb5f26 datalen=4 + 0x4a, + 0xd0, 0x16, 0xf9, 0xb9, 0x41, 0x51, 0x3b, 0x87, + 0x87, 0xe5, 0x3a, 0x60, 0x87, 0xeb, 0x5f, 0x26, + 0x0e, + // (PLAYER_NAME) id=21 name="nameless tee" + 0x15, + 0x6e, 0x61, 0x6d, 0x65, 0x6c, 0x65, 0x73, 0x73, + 0x20, 0x74, 0x65, 0x65 + }; + + m_TH.RecordPlayerName(21, "nameless tee"); + Expect(EXPECTED, sizeof(EXPECTED)); +} + TEST_F(TeeHistorian, PrevGameUuid) { m_GameInfo.m_HavePrevGameUuid = true;