Skip to content

Commit

Permalink
Address review to make code more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwelf committed Sep 15, 2021
1 parent eacd314 commit e9dec00
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/engine/shared/teehistorian_ex_chunks.h
Expand Up @@ -12,5 +12,5 @@ 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")
UUID(TEEHISTORIAN_TEAM_CHANGE, "teehistorian-team-change@ddnet.tw")
UUID(TEEHISTORIAN_PLAYER_TEAM, "teehistorian-player-team@ddnet.tw")
UUID(TEEHISTORIAN_TEAM_PRACTICE, "teehistorian-team-practice@ddnet.tw")
25 changes: 11 additions & 14 deletions src/game/server/teehistorian.cpp
Expand Up @@ -48,20 +48,17 @@ void CTeeHistorian::Reset(const CGameInfo *pGameInfo, WRITE_CALLBACK pfnWriteCal
// Tick 0 is implicit at the start, game starts as tick 1.
m_TickWritten = true;
m_MaxClientID = MAX_CLIENTS;
for(auto &PrevPlayerTeam : m_aPrevPlayerTeam)
{
PrevPlayerTeam = 0;
}
for(auto &PrevTeamPractice : m_aPrevTeamPractice)
{
PrevTeamPractice = false;
}

// `m_PrevMaxClientID` is initialized in `BeginPlayers`
for(auto &PrevPlayer : m_aPrevPlayers)
{
PrevPlayer.m_Alive = false;
PrevPlayer.m_InputExists = false;
PrevPlayer.m_Team = 0;
}
for(auto &PrevTeam : m_aPrevTeams)
{
PrevTeam.m_Practice = false;
}
m_pfnWriteCallback = pfnWriteCallback;
m_pWriteCallbackUserdata = pUser;
Expand Down Expand Up @@ -100,7 +97,7 @@ void CTeeHistorian::WriteHeader(const CGameInfo *pGameInfo)
"{"
"\"comment\":\"%s\","
"\"version\":\"%s\","
"\"minor_version\":\"%s\","
"\"version_minor\":\"%s\","
"\"game_uuid\":\"%s\","
"\"server_version\":\"%s\","
"\"start_time\":\"%s\","
Expand Down Expand Up @@ -322,9 +319,9 @@ void CTeeHistorian::RecordDeadPlayer(int ClientID)

void CTeeHistorian::RecordPlayerTeam(int ClientID, int Team)
{
if(m_aPrevPlayerTeam[ClientID] != Team)
if(m_aPrevPlayers[ClientID].m_Team != Team)
{
m_aPrevPlayerTeam[ClientID] = Team;
m_aPrevPlayers[ClientID].m_Team = Team;

EnsureTickWritten();

Expand All @@ -338,15 +335,15 @@ void CTeeHistorian::RecordPlayerTeam(int ClientID, int Team)
dbg_msg("teehistorian", "team_change cid=%d team=%d", ClientID, Team);
}

WriteExtra(UUID_TEEHISTORIAN_TEAM_CHANGE, Buffer.Data(), Buffer.Size());
WriteExtra(UUID_TEEHISTORIAN_PLAYER_TEAM, Buffer.Data(), Buffer.Size());
}
}

void CTeeHistorian::RecordTeamPractice(int Team, bool Practice)
{
if(m_aPrevTeamPractice[Team] != Practice)
if(m_aPrevTeams[Team].m_Practice != Practice)
{
m_aPrevTeamPractice[Team] = Practice;
m_aPrevTeams[Team].m_Practice = Practice;

EnsureTickWritten();

Expand Down
11 changes: 9 additions & 2 deletions src/game/server/teehistorian.h
Expand Up @@ -113,6 +113,14 @@ class CTeeHistorian

CNetObj_PlayerInput m_Input;
bool m_InputExists;

// DDNet team
int m_Team;
};

struct CTeam
{
bool m_Practice;
};

WRITE_CALLBACK m_pfnWriteCallback;
Expand All @@ -125,9 +133,8 @@ class CTeeHistorian
int m_Tick;
int m_PrevMaxClientID;
int m_MaxClientID;
int m_aPrevPlayerTeam[MAX_CLIENTS];
bool m_aPrevTeamPractice[MAX_CLIENTS];
CPlayer m_aPrevPlayers[MAX_CLIENTS];
CTeam m_aPrevTeams[MAX_CLIENTS];
};

#endif // GAME_SERVER_TEEHISTORIAN_H
10 changes: 5 additions & 5 deletions src/test/teehistorian.cpp
Expand Up @@ -89,7 +89,7 @@ class TeeHistorian : public ::testing::Test
void Expect(const unsigned char *pOutput, int OutputSize)
{
static CUuid TEEHISTORIAN_UUID = CalculateUuid("teehistorian@ddnet.tw");
static const char PREFIX1[] = "{\"comment\":\"teehistorian@ddnet.tw\",\"version\":\"2\",\"minor_version\":\"2\",\"game_uuid\":\"a1eb7182-796e-3b3e-941d-38ca71b2a4a8\",\"server_version\":\"DDNet test\",\"start_time\":\"";
static const char PREFIX1[] = "{\"comment\":\"teehistorian@ddnet.tw\",\"version\":\"2\",\"version_minor\":\"2\",\"game_uuid\":\"a1eb7182-796e-3b3e-941d-38ca71b2a4a8\",\"server_version\":\"DDNet test\",\"start_time\":\"";
static const char PREFIX2[] = "\",\"server_name\":\"server name\",\"server_port\":\"8303\",\"game_type\":\"game type\",\"map_name\":\"Kobra 3 Solo\",\"map_size\":\"903514\",\"map_sha256\":\"0123456789012345678901234567890123456789012345678901234567890123\",\"map_crc\":\"eceaf25c\",\"prng_description\":\"test-prng:02468ace\",\"config\":{},\"tuning\":{},\"uuids\":[";
static const char PREFIX3[] = "]}";

Expand Down Expand Up @@ -533,13 +533,13 @@ TEST_F(TeeHistorian, LoadFailed)
Expect(EXPECTED, sizeof(EXPECTED));
}

TEST_F(TeeHistorian, TeamChange)
TEST_F(TeeHistorian, PlayerTeam)
{
const unsigned char EXPECTED[] = {
// EX uuid=39707241-b64d-3201-b4d8-b6ec24b2b6c9 datalen=2
// EX uuid=a111c04e-1ea8-38e0-90b1-d7f993ca0da9 datalen=2
0x4a,
0x39, 0x70, 0x72, 0x41, 0xb6, 0x4d, 0x32, 0x01,
0xb4, 0xd8, 0xb6, 0xec, 0x24, 0xb2, 0xb6, 0xc9,
0xa1, 0x11, 0xc0, 0x4e, 0x1e, 0xa8, 0x38, 0xe0,
0x90, 0xb1, 0xd7, 0xf9, 0x93, 0xca, 0x0d, 0xa9,
0x02,
// player_id=33
0x21,
Expand Down

0 comments on commit e9dec00

Please sign in to comment.