2017-09-12 12:58:44 +00:00
|
|
|
#include "teehistorian.h"
|
|
|
|
|
2017-09-13 20:35:09 +00:00
|
|
|
#include <engine/shared/config.h>
|
2017-09-12 12:58:44 +00:00
|
|
|
#include <engine/shared/snapshot.h>
|
2017-09-13 20:35:09 +00:00
|
|
|
#include <game/gamecore.h>
|
2017-09-12 12:58:44 +00:00
|
|
|
|
2017-09-24 19:11:04 +00:00
|
|
|
static const char TEEHISTORIAN_NAME[] = "teehistorian@ddnet.tw";
|
|
|
|
static const CUuid TEEHISTORIAN_UUID = CalculateUuid(TEEHISTORIAN_NAME);
|
2017-09-12 12:58:44 +00:00
|
|
|
static const char TEEHISTORIAN_VERSION[] = "1";
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TEEHISTORIAN_NONE,
|
|
|
|
TEEHISTORIAN_FINISH,
|
|
|
|
TEEHISTORIAN_TICK,
|
|
|
|
TEEHISTORIAN_PLAYER_NEW,
|
|
|
|
TEEHISTORIAN_PLAYER_OLD,
|
|
|
|
TEEHISTORIAN_INPUT_DIFF,
|
|
|
|
TEEHISTORIAN_INPUT_NEW,
|
2017-09-13 20:35:09 +00:00
|
|
|
TEEHISTORIAN_MESSAGE,
|
|
|
|
TEEHISTORIAN_JOIN,
|
|
|
|
TEEHISTORIAN_DROP,
|
|
|
|
TEEHISTORIAN_CONSOLE_COMMAND,
|
2017-09-12 12:58:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static char EscapeJsonChar(char c)
|
|
|
|
{
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case '\"': return '\"';
|
|
|
|
case '\\': return '\\';
|
|
|
|
case '\b': return 'b';
|
|
|
|
case '\n': return 'n';
|
|
|
|
case '\r': return 'r';
|
|
|
|
case '\t': return 't';
|
|
|
|
// Don't escape '\f', who uses that. :)
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *EscapeJson(char *pBuffer, int BufferSize, const char *pString)
|
|
|
|
{
|
|
|
|
dbg_assert(BufferSize > 0, "can't null-terminate the string");
|
|
|
|
// Subtract the space for null termination early.
|
|
|
|
BufferSize--;
|
|
|
|
|
|
|
|
char *pResult = pBuffer;
|
|
|
|
while(BufferSize && *pString)
|
|
|
|
{
|
|
|
|
char c = *pString;
|
|
|
|
pString++;
|
|
|
|
char Escaped = EscapeJsonChar(c);
|
|
|
|
if(Escaped)
|
|
|
|
{
|
|
|
|
if(BufferSize < 2)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*pBuffer++ = '\\';
|
|
|
|
*pBuffer++ = Escaped;
|
|
|
|
BufferSize -= 2;
|
|
|
|
}
|
|
|
|
// Assuming ASCII/UTF-8, "if control character".
|
|
|
|
else if(c < 0x20)
|
|
|
|
{
|
|
|
|
// \uXXXX
|
|
|
|
if(BufferSize < 6)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
str_format(pBuffer, BufferSize, "\\u%04x", c);
|
|
|
|
BufferSize -= 6;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pBuffer++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pBuffer = 0;
|
|
|
|
return pResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTeeHistorian::CTeeHistorian()
|
|
|
|
{
|
|
|
|
m_State = STATE_START;
|
|
|
|
m_pfnWriteCallback = 0;
|
|
|
|
m_pWriteCallbackUserdata = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::Reset(const CGameInfo *pGameInfo, WRITE_CALLBACK pfnWriteCallback, void *pUser)
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_START || m_State == STATE_BEFORE_TICK, "invalid teehistorian state");
|
|
|
|
|
2017-09-18 16:26:37 +00:00
|
|
|
m_Debug = 0;
|
2017-09-12 12:58:44 +00:00
|
|
|
|
|
|
|
m_Tick = 0;
|
|
|
|
m_LastWrittenTick = 0;
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
|
|
|
{
|
|
|
|
m_aPrevPlayers[i].m_Alive = false;
|
|
|
|
m_aPrevPlayers[i].m_InputExists = false;
|
|
|
|
}
|
|
|
|
m_pfnWriteCallback = pfnWriteCallback;
|
|
|
|
m_pWriteCallbackUserdata = pUser;
|
|
|
|
|
|
|
|
WriteHeader(pGameInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::WriteHeader(const CGameInfo *pGameInfo)
|
|
|
|
{
|
|
|
|
Write(&TEEHISTORIAN_UUID, sizeof(TEEHISTORIAN_UUID));
|
|
|
|
|
|
|
|
char aGameUuid[UUID_MAXSTRSIZE];
|
|
|
|
char aStartTime[128];
|
|
|
|
|
|
|
|
FormatUuid(pGameInfo->m_GameUuid, aGameUuid, sizeof(aGameUuid));
|
|
|
|
str_timestamp_ex(pGameInfo->m_StartTime, aStartTime, sizeof(aStartTime), "%Y-%m-%d %H:%M:%S %z");
|
|
|
|
|
2017-09-24 19:11:04 +00:00
|
|
|
char aCommentBuffer[128];
|
2017-09-12 12:58:44 +00:00
|
|
|
char aServerVersionBuffer[128];
|
|
|
|
char aStartTimeBuffer[128];
|
|
|
|
char aServerNameBuffer[128];
|
|
|
|
char aGameTypeBuffer[128];
|
|
|
|
char aMapNameBuffer[128];
|
|
|
|
|
2017-09-13 20:35:09 +00:00
|
|
|
char aJson[2048];
|
2017-09-12 12:58:44 +00:00
|
|
|
|
|
|
|
#define E(buf, str) EscapeJson(buf, sizeof(buf), str)
|
|
|
|
|
2017-09-24 19:11:04 +00:00
|
|
|
str_format(aJson, sizeof(aJson), "{\"comment\":\"%s\",\"version\":\"%s\",\"game_uuid\":\"%s\",\"server_version\":\"%s\",\"start_time\":\"%s\",\"server_name\":\"%s\",\"server_port\":%d,\"game_type\":\"%s\",\"map_name\":\"%s\",\"map_size\":%d,\"map_crc\":\"%08x\",\"config\":{",
|
|
|
|
E(aCommentBuffer, TEEHISTORIAN_NAME),
|
2017-09-12 12:58:44 +00:00
|
|
|
TEEHISTORIAN_VERSION,
|
|
|
|
aGameUuid,
|
|
|
|
E(aServerVersionBuffer, pGameInfo->m_pServerVersion),
|
|
|
|
E(aStartTimeBuffer, aStartTime),
|
|
|
|
E(aServerNameBuffer, pGameInfo->m_pServerName),
|
|
|
|
pGameInfo->m_ServerPort,
|
|
|
|
E(aGameTypeBuffer, pGameInfo->m_pGameType),
|
|
|
|
E(aMapNameBuffer, pGameInfo->m_pMapName),
|
|
|
|
pGameInfo->m_MapSize,
|
|
|
|
pGameInfo->m_MapCrc);
|
2017-09-13 20:35:09 +00:00
|
|
|
Write(aJson, str_length(aJson));
|
|
|
|
|
|
|
|
char aBuffer1[1024];
|
|
|
|
char aBuffer2[1024];
|
|
|
|
bool First = true;
|
|
|
|
|
|
|
|
#define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \
|
2017-09-24 19:11:04 +00:00
|
|
|
if((Flags)&CFGFLAG_SERVER && !((Flags)&CFGFLAG_NONTEEHISTORIC) && pGameInfo->m_pConfig->m_##Name != (Def)) \
|
2017-09-13 20:35:09 +00:00
|
|
|
{ \
|
|
|
|
str_format(aJson, sizeof(aJson), "%s\"%s\":\"%d\"", \
|
|
|
|
First ? "" : ",", \
|
|
|
|
E(aBuffer1, #ScriptName), \
|
|
|
|
pGameInfo->m_pConfig->m_##Name); \
|
|
|
|
Write(aJson, str_length(aJson)); \
|
|
|
|
First = false; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Flags,Desc) \
|
2017-09-24 19:11:04 +00:00
|
|
|
if((Flags)&CFGFLAG_SERVER && !((Flags)&CFGFLAG_NONTEEHISTORIC) && str_comp(pGameInfo->m_pConfig->m_##Name, (Def)) != 0) \
|
2017-09-13 20:35:09 +00:00
|
|
|
{ \
|
|
|
|
str_format(aJson, sizeof(aJson), "%s\"%s\":\"%s\"", \
|
|
|
|
First ? "" : ",", \
|
|
|
|
E(aBuffer1, #ScriptName), \
|
|
|
|
E(aBuffer2, pGameInfo->m_pConfig->m_##Name)); \
|
|
|
|
Write(aJson, str_length(aJson)); \
|
|
|
|
First = false; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <engine/shared/config_variables.h>
|
|
|
|
|
|
|
|
#undef MACRO_CONFIG_INT
|
|
|
|
#undef MACRO_CONFIG_STR
|
|
|
|
|
|
|
|
str_format(aJson, sizeof(aJson), "},\"tuning\":{");
|
|
|
|
Write(aJson, str_length(aJson));
|
2017-09-12 12:58:44 +00:00
|
|
|
|
2017-09-13 20:35:09 +00:00
|
|
|
First = true;
|
|
|
|
|
2017-09-24 19:11:04 +00:00
|
|
|
static const float TicksPerSecond = 50.0f;
|
2017-09-13 20:35:09 +00:00
|
|
|
#define MACRO_TUNING_PARAM(Name,ScriptName,Value,Description) \
|
2017-09-24 19:11:04 +00:00
|
|
|
if(pGameInfo->m_pTuning->m_##Name.Get() != (int)((Value)*100)) \
|
2017-09-13 20:35:09 +00:00
|
|
|
{ \
|
|
|
|
str_format(aJson, sizeof(aJson), "%s\"%s\":\"%d\"", \
|
|
|
|
First ? "" : ",", \
|
|
|
|
E(aBuffer1, #ScriptName), \
|
|
|
|
pGameInfo->m_pTuning->m_##Name.Get()); \
|
|
|
|
Write(aJson, str_length(aJson)); \
|
|
|
|
First = false; \
|
|
|
|
}
|
|
|
|
#include <game/tuning.h>
|
|
|
|
#undef MACRO_TUNING_PARAM
|
|
|
|
|
|
|
|
str_format(aJson, sizeof(aJson), "}}");
|
|
|
|
Write(aJson, str_length(aJson));
|
|
|
|
Write("", 1); // Null termination.
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 20:35:09 +00:00
|
|
|
|
2017-09-12 12:58:44 +00:00
|
|
|
void CTeeHistorian::BeginTick(int Tick)
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_START || m_State == STATE_BEFORE_TICK, "invalid teehistorian state");
|
|
|
|
|
|
|
|
m_Tick = Tick;
|
|
|
|
m_TickWritten = false;
|
|
|
|
|
2017-09-18 16:26:37 +00:00
|
|
|
if(m_Debug > 1)
|
2017-09-12 12:58:44 +00:00
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "tick %d", Tick);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_State = STATE_BEFORE_PLAYERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::BeginPlayers()
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_BEFORE_PLAYERS, "invalid teehistorian state");
|
|
|
|
|
|
|
|
m_PrevMaxClientID = m_MaxClientID;
|
|
|
|
m_MaxClientID = -1;
|
|
|
|
|
|
|
|
m_State = STATE_PLAYERS;
|
|
|
|
}
|
|
|
|
|
2017-09-18 16:26:37 +00:00
|
|
|
void CTeeHistorian::EnsureTickWrittenPlayerData(int ClientID)
|
2017-09-12 12:58:44 +00:00
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
dbg_assert(ClientID > m_MaxClientID, "invalid player data order");
|
|
|
|
m_MaxClientID = ClientID;
|
|
|
|
|
2017-09-27 18:15:41 +00:00
|
|
|
if(!m_TickWritten && (ClientID > m_PrevMaxClientID || m_LastWrittenTick + 1 != m_Tick))
|
2017-09-12 12:58:44 +00:00
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
WriteTick();
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
else
|
2017-09-12 12:58:44 +00:00
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
// Tick is implicit.
|
|
|
|
m_LastWrittenTick = m_Tick;
|
|
|
|
m_TickWritten = true;
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::RecordPlayer(int ClientID, const CNetObj_CharacterCore *pChar)
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_PLAYERS, "invalid teehistorian state");
|
|
|
|
|
|
|
|
CPlayer *pPrev = &m_aPrevPlayers[ClientID];
|
|
|
|
if(!pPrev->m_Alive || pPrev->m_X != pChar->m_X || pPrev->m_Y != pChar->m_Y)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
EnsureTickWrittenPlayerData(ClientID);
|
|
|
|
|
|
|
|
CPacker Buffer;
|
|
|
|
Buffer.Reset();
|
2017-09-12 12:58:44 +00:00
|
|
|
if(pPrev->m_Alive)
|
|
|
|
{
|
|
|
|
int dx = pChar->m_X - pPrev->m_X;
|
|
|
|
int dy = pChar->m_Y - pPrev->m_Y;
|
2017-09-18 16:26:37 +00:00
|
|
|
Buffer.AddInt(ClientID);
|
|
|
|
Buffer.AddInt(dx);
|
|
|
|
Buffer.AddInt(dy);
|
2017-09-12 12:58:44 +00:00
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "diff cid=%d dx=%d dy=%d", ClientID, dx, dy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int x = pChar->m_X;
|
|
|
|
int y = pChar->m_Y;
|
2017-09-18 16:26:37 +00:00
|
|
|
Buffer.AddInt(-TEEHISTORIAN_PLAYER_NEW);
|
|
|
|
Buffer.AddInt(ClientID);
|
|
|
|
Buffer.AddInt(x);
|
|
|
|
Buffer.AddInt(y);
|
2017-09-12 12:58:44 +00:00
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "new cid=%d x=%d y=%d", ClientID, x, y);
|
|
|
|
}
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
Write(Buffer.Data(), Buffer.Size());
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|
|
|
|
pPrev->m_X = pChar->m_X;
|
|
|
|
pPrev->m_Y = pChar->m_Y;
|
|
|
|
pPrev->m_Alive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::RecordDeadPlayer(int ClientID)
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_PLAYERS, "invalid teehistorian state");
|
|
|
|
|
|
|
|
CPlayer *pPrev = &m_aPrevPlayers[ClientID];
|
|
|
|
if(pPrev->m_Alive)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
EnsureTickWrittenPlayerData(ClientID);
|
|
|
|
|
|
|
|
CPacker Buffer;
|
|
|
|
Buffer.Reset();
|
|
|
|
Buffer.AddInt(-TEEHISTORIAN_PLAYER_OLD);
|
|
|
|
Buffer.AddInt(ClientID);
|
2017-09-12 12:58:44 +00:00
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "old cid=%d", ClientID);
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
Write(Buffer.Data(), Buffer.Size());
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|
|
|
|
pPrev->m_Alive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::Write(const void *pData, int DataSize)
|
|
|
|
{
|
|
|
|
m_pfnWriteCallback(pData, DataSize, m_pWriteCallbackUserdata);
|
|
|
|
}
|
|
|
|
|
2017-09-18 16:26:37 +00:00
|
|
|
void CTeeHistorian::EnsureTickWritten()
|
|
|
|
{
|
|
|
|
if(!m_TickWritten)
|
|
|
|
{
|
|
|
|
WriteTick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-12 12:58:44 +00:00
|
|
|
void CTeeHistorian::WriteTick()
|
|
|
|
{
|
|
|
|
CPacker TickPacker;
|
|
|
|
TickPacker.Reset();
|
|
|
|
|
|
|
|
int dt = m_Tick - m_LastWrittenTick - 1;
|
|
|
|
TickPacker.AddInt(-TEEHISTORIAN_TICK);
|
|
|
|
TickPacker.AddInt(dt);
|
|
|
|
if(m_Debug)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
dbg_msg("teehistorian", "skip_ticks dt=%d", dt);
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|
|
|
|
Write(TickPacker.Data(), TickPacker.Size());
|
|
|
|
|
|
|
|
m_TickWritten = true;
|
|
|
|
m_LastWrittenTick = m_Tick;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::EndPlayers()
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_PLAYERS, "invalid teehistorian state");
|
|
|
|
|
|
|
|
m_State = STATE_BEFORE_INPUTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::BeginInputs()
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_BEFORE_INPUTS, "invalid teehistorian state");
|
2017-09-18 16:26:37 +00:00
|
|
|
|
2017-09-12 12:58:44 +00:00
|
|
|
m_State = STATE_INPUTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::RecordPlayerInput(int ClientID, const CNetObj_PlayerInput *pInput)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
CPacker Buffer;
|
|
|
|
|
2017-09-12 12:58:44 +00:00
|
|
|
CPlayer *pPrev = &m_aPrevPlayers[ClientID];
|
|
|
|
CNetObj_PlayerInput DiffInput;
|
|
|
|
if(pPrev->m_InputExists)
|
|
|
|
{
|
|
|
|
if(mem_comp(&pPrev->m_Input, pInput, sizeof(pPrev->m_Input)) == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
EnsureTickWritten();
|
|
|
|
Buffer.Reset();
|
|
|
|
|
|
|
|
Buffer.AddInt(-TEEHISTORIAN_INPUT_DIFF);
|
2017-09-12 12:58:44 +00:00
|
|
|
CSnapshotDelta::DiffItem((int *)&pPrev->m_Input, (int *)pInput, (int *)&DiffInput, sizeof(DiffInput) / sizeof(int));
|
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
const int *pData = (const int *)&DiffInput;
|
|
|
|
dbg_msg("teehistorian", "diff_input cid=%d %d %d %d %d %d %d %d %d %d %d", ClientID,
|
|
|
|
pData[0], pData[1], pData[2], pData[3], pData[4],
|
|
|
|
pData[5], pData[6], pData[7], pData[8], pData[9]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
EnsureTickWritten();
|
|
|
|
Buffer.Reset();
|
|
|
|
Buffer.AddInt(-TEEHISTORIAN_INPUT_NEW);
|
2017-09-12 12:58:44 +00:00
|
|
|
DiffInput = *pInput;
|
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "new_input cid=%d", ClientID);
|
|
|
|
}
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
Buffer.AddInt(ClientID);
|
2017-09-12 12:58:44 +00:00
|
|
|
for(int i = 0; i < (int)(sizeof(DiffInput) / sizeof(int)); i++)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
Buffer.AddInt(((int *)&DiffInput)[i]);
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|
|
|
|
pPrev->m_InputExists = true;
|
|
|
|
pPrev->m_Input = *pInput;
|
2017-09-18 16:26:37 +00:00
|
|
|
|
|
|
|
Write(Buffer.Data(), Buffer.Size());
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 20:35:09 +00:00
|
|
|
void CTeeHistorian::RecordPlayerMessage(int ClientID, const void *pMsg, int MsgSize)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
EnsureTickWritten();
|
|
|
|
|
|
|
|
CPacker Buffer;
|
|
|
|
Buffer.Reset();
|
|
|
|
Buffer.AddInt(-TEEHISTORIAN_MESSAGE);
|
|
|
|
Buffer.AddInt(ClientID);
|
|
|
|
Buffer.AddInt(MsgSize);
|
|
|
|
Buffer.AddRaw(pMsg, MsgSize);
|
2017-09-13 20:35:09 +00:00
|
|
|
|
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
CUnpacker Unpacker;
|
|
|
|
Unpacker.Reset(pMsg, MsgSize);
|
|
|
|
int MsgID = Unpacker.GetInt();
|
|
|
|
int Sys = MsgID & 1;
|
|
|
|
MsgID >>= 1;
|
|
|
|
dbg_msg("teehistorian", "msg cid=%d sys=%d msgid=%d", ClientID, Sys, MsgID);
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
|
|
|
|
Write(Buffer.Data(), Buffer.Size());
|
2017-09-13 20:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::RecordPlayerJoin(int ClientID)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
EnsureTickWritten();
|
|
|
|
|
|
|
|
CPacker Buffer;
|
|
|
|
Buffer.Reset();
|
|
|
|
Buffer.AddInt(-TEEHISTORIAN_JOIN);
|
|
|
|
Buffer.AddInt(ClientID);
|
2017-09-13 20:35:09 +00:00
|
|
|
|
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "join cid=%d", ClientID);
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
|
|
|
|
Write(Buffer.Data(), Buffer.Size());
|
2017-09-13 20:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::RecordPlayerDrop(int ClientID, const char *pReason)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
EnsureTickWritten();
|
|
|
|
|
|
|
|
CPacker Buffer;
|
|
|
|
Buffer.Reset();
|
|
|
|
Buffer.AddInt(-TEEHISTORIAN_DROP);
|
|
|
|
Buffer.AddInt(ClientID);
|
|
|
|
Buffer.AddString(pReason, 0);
|
2017-09-13 20:35:09 +00:00
|
|
|
|
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "drop cid=%d reason='%s'", ClientID, pReason);
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
|
|
|
|
Write(Buffer.Data(), Buffer.Size());
|
2017-09-13 20:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::RecordConsoleCommand(int ClientID, int FlagMask, const char *pCmd, IConsole::IResult *pResult)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
EnsureTickWritten();
|
|
|
|
|
|
|
|
CPacker Buffer;
|
|
|
|
Buffer.Reset();
|
|
|
|
Buffer.AddInt(-TEEHISTORIAN_CONSOLE_COMMAND);
|
|
|
|
Buffer.AddInt(ClientID);
|
|
|
|
Buffer.AddInt(FlagMask);
|
|
|
|
Buffer.AddString(pCmd, 0);
|
|
|
|
Buffer.AddInt(pResult->NumArguments());
|
2017-09-13 20:35:09 +00:00
|
|
|
for(int i = 0; i < pResult->NumArguments(); i++)
|
|
|
|
{
|
2017-09-18 16:26:37 +00:00
|
|
|
Buffer.AddString(pResult->GetString(i), 0);
|
2017-09-13 20:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "ccmd cid=%d cmd='%s'", ClientID, pCmd);
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
|
|
|
|
Write(Buffer.Data(), Buffer.Size());
|
2017-09-13 20:35:09 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 12:58:44 +00:00
|
|
|
void CTeeHistorian::EndInputs()
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_INPUTS, "invalid teehistorian state");
|
|
|
|
|
|
|
|
m_State = STATE_BEFORE_ENDTICK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::EndTick()
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_BEFORE_ENDTICK, "invalid teehistorian state");
|
|
|
|
m_State = STATE_BEFORE_TICK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTeeHistorian::Finish()
|
|
|
|
{
|
|
|
|
dbg_assert(m_State == STATE_START || m_State == STATE_INPUTS || m_State == STATE_BEFORE_ENDTICK, "invalid teehistorian state");
|
|
|
|
|
|
|
|
if(m_State == STATE_INPUTS)
|
|
|
|
{
|
|
|
|
EndInputs();
|
|
|
|
}
|
|
|
|
if(m_State == STATE_BEFORE_ENDTICK)
|
|
|
|
{
|
|
|
|
EndTick();
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
|
|
|
|
CPacker Buffer;
|
|
|
|
Buffer.Reset();
|
|
|
|
Buffer.AddInt(-TEEHISTORIAN_FINISH);
|
2017-09-13 20:35:09 +00:00
|
|
|
|
|
|
|
if(m_Debug)
|
|
|
|
{
|
|
|
|
dbg_msg("teehistorian", "finish");
|
|
|
|
}
|
2017-09-18 16:26:37 +00:00
|
|
|
|
|
|
|
Write(Buffer.Data(), Buffer.Size());
|
2017-09-12 12:58:44 +00:00
|
|
|
}
|