added an optional time stamp to a demo record by Batchyx

This commit is contained in:
oy 2010-12-08 00:42:32 +01:00
parent 665934ee09
commit db9dd6b8c9
5 changed files with 32 additions and 20 deletions

View file

@ -76,7 +76,7 @@ public:
virtual void Disconnect() = 0; virtual void Disconnect() = 0;
virtual void Quit() = 0; virtual void Quit() = 0;
virtual const char *DemoPlayer_Play(const char *pFilename, int StorageType) = 0; virtual const char *DemoPlayer_Play(const char *pFilename, int StorageType) = 0;
virtual void DemoRecorder_Start(const char *pFilename) = 0; virtual void DemoRecorder_Start(const char *pFilename, bool WithTimestamp) = 0;
virtual void DemoRecorder_Stop() = 0; virtual void DemoRecorder_Stop() = 0;
// networking // networking

View file

@ -1926,13 +1926,20 @@ void CClient::Con_Play(IConsole::IResult *pResult, void *pUserData)
pSelf->DemoPlayer_Play(pResult->GetString(0), IStorage::TYPE_ALL); pSelf->DemoPlayer_Play(pResult->GetString(0), IStorage::TYPE_ALL);
} }
void CClient::DemoRecorder_Start(const char *pFilename) void CClient::DemoRecorder_Start(const char *pFilename, bool WithTimestamp)
{ {
if(State() != IClient::STATE_ONLINE) if(State() != IClient::STATE_ONLINE)
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demorec/record", "client is not online"); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demorec/record", "client is not online");
else else
{ {
char aFilename[512]; char aFilename[128];
if(WithTimestamp)
{
char aDate[20];
str_timestamp(aDate, sizeof(aDate));
str_format(aFilename, sizeof(aFilename), "demos/%s_%s.demo", pFilename, aDate);
}
else
str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pFilename); str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pFilename);
m_DemoRecorder.Start(Storage(), m_pConsole, aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "client"); m_DemoRecorder.Start(Storage(), m_pConsole, aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "client");
} }
@ -1946,7 +1953,10 @@ void CClient::DemoRecorder_Stop()
void CClient::Con_Record(IConsole::IResult *pResult, void *pUserData) void CClient::Con_Record(IConsole::IResult *pResult, void *pUserData)
{ {
CClient *pSelf = (CClient *)pUserData; CClient *pSelf = (CClient *)pUserData;
pSelf->DemoRecorder_Start(pResult->GetString(0)); if(pResult->NumArguments())
pSelf->DemoRecorder_Start(pResult->GetString(0), false);
else
pSelf->DemoRecorder_Start("demo", true);
} }
void CClient::Con_StopRecord(IConsole::IResult *pResult, void *pUserData) void CClient::Con_StopRecord(IConsole::IResult *pResult, void *pUserData)
@ -1965,7 +1975,7 @@ void CClient::RegisterCommands()
m_pConsole->Register("bans", "", CFGFLAG_SERVER, 0, 0, "Show banlist"); m_pConsole->Register("bans", "", CFGFLAG_SERVER, 0, 0, "Show banlist");
m_pConsole->Register("status", "", CFGFLAG_SERVER, 0, 0, "List players"); m_pConsole->Register("status", "", CFGFLAG_SERVER, 0, 0, "List players");
m_pConsole->Register("shutdown", "", CFGFLAG_SERVER, 0, 0, "Shut down"); m_pConsole->Register("shutdown", "", CFGFLAG_SERVER, 0, 0, "Shut down");
m_pConsole->Register("record", "s", CFGFLAG_SERVER, 0, 0, "Record to a file"); m_pConsole->Register("record", "?s", CFGFLAG_SERVER, 0, 0, "Record to a file");
m_pConsole->Register("stoprecord", "", CFGFLAG_SERVER, 0, 0, "Stop recording"); m_pConsole->Register("stoprecord", "", CFGFLAG_SERVER, 0, 0, "Stop recording");
m_pConsole->Register("reload", "", CFGFLAG_SERVER, 0, 0, "Reload the map"); m_pConsole->Register("reload", "", CFGFLAG_SERVER, 0, 0, "Reload the map");
@ -1979,7 +1989,7 @@ void CClient::RegisterCommands()
m_pConsole->Register("rcon", "r", CFGFLAG_CLIENT, Con_Rcon, this, "Send specified command to rcon"); m_pConsole->Register("rcon", "r", CFGFLAG_CLIENT, Con_Rcon, this, "Send specified command to rcon");
m_pConsole->Register("rcon_auth", "s", CFGFLAG_CLIENT, Con_RconAuth, this, "Authenticate to rcon"); m_pConsole->Register("rcon_auth", "s", CFGFLAG_CLIENT, Con_RconAuth, this, "Authenticate to rcon");
m_pConsole->Register("play", "r", CFGFLAG_CLIENT, Con_Play, this, "Play the file specified"); m_pConsole->Register("play", "r", CFGFLAG_CLIENT, Con_Play, this, "Play the file specified");
m_pConsole->Register("record", "s", CFGFLAG_CLIENT, Con_Record, this, "Record to the file"); m_pConsole->Register("record", "?s", CFGFLAG_CLIENT, Con_Record, this, "Record to the file");
m_pConsole->Register("stoprecord", "", CFGFLAG_CLIENT, Con_StopRecord, this, "Stop recording"); m_pConsole->Register("stoprecord", "", CFGFLAG_CLIENT, Con_StopRecord, this, "Stop recording");
m_pConsole->Register("add_favorite", "s", CFGFLAG_CLIENT, Con_AddFavorite, this, "Add a server as a favorite"); m_pConsole->Register("add_favorite", "s", CFGFLAG_CLIENT, Con_AddFavorite, this, "Add a server as a favorite");

View file

@ -284,7 +284,7 @@ public:
void RegisterCommands(); void RegisterCommands();
const char *DemoPlayer_Play(const char *pFilename, int StorageType); const char *DemoPlayer_Play(const char *pFilename, int StorageType);
void DemoRecorder_Start(const char *pFilename); void DemoRecorder_Start(const char *pFilename, bool WithTimestamp);
void DemoRecorder_Stop(); void DemoRecorder_Stop();
virtual class CEngine *Engine() { return &m_Engine; } virtual class CEngine *Engine() { return &m_Engine; }

View file

@ -1405,9 +1405,18 @@ void CServer::ConShutdown(IConsole::IResult *pResult, void *pUser)
void CServer::ConRecord(IConsole::IResult *pResult, void *pUser) void CServer::ConRecord(IConsole::IResult *pResult, void *pUser)
{ {
char aFilename[512]; CServer* pServer = (CServer *)pUser;
char aFilename[128];
if(pResult->NumArguments())
str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pResult->GetString(0)); str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pResult->GetString(0));
((CServer *)pUser)->m_DemoRecorder.Start(((CServer *)pUser)->Storage(), ((CServer *)pUser)->Console(), aFilename, ((CServer *)pUser)->GameServer()->NetVersion(), ((CServer *)pUser)->m_aCurrentMap, ((CServer *)pUser)->m_CurrentMapCrc, "server"); else
{
char aDate[20];
str_timestamp(aDate, sizeof(aDate));
str_format(aFilename, sizeof(aFilename), "demos/demo_%s.demo", aDate);
}
pServer->m_DemoRecorder.Start(pServer->Storage(), pServer->Console(), aFilename, pServer->GameServer()->NetVersion(), pServer->m_aCurrentMap, pServer->m_CurrentMapCrc, "server");
} }
void CServer::ConStopRecord(IConsole::IResult *pResult, void *pUser) void CServer::ConStopRecord(IConsole::IResult *pResult, void *pUser)
@ -1445,7 +1454,7 @@ void CServer::RegisterCommands()
Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, ""); Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, "");
Console()->Register("shutdown", "", CFGFLAG_SERVER, ConShutdown, this, ""); Console()->Register("shutdown", "", CFGFLAG_SERVER, ConShutdown, this, "");
Console()->Register("record", "s", CFGFLAG_SERVER|CFGFLAG_STORE, ConRecord, this, ""); Console()->Register("record", "?s", CFGFLAG_SERVER|CFGFLAG_STORE, ConRecord, this, "");
Console()->Register("stoprecord", "", CFGFLAG_SERVER, ConStopRecord, this, ""); Console()->Register("stoprecord", "", CFGFLAG_SERVER, ConStopRecord, this, "");
Console()->Register("reload", "", CFGFLAG_SERVER, ConMapReload, this, ""); Console()->Register("reload", "", CFGFLAG_SERVER, ConMapReload, this, "");

View file

@ -99,14 +99,7 @@ void CMenus::RenderGame(CUIRect MainView)
if(DoButton_Menu(&s_DemoButton, Localize(Recording ? "Stop record" : "Record demo"), 0, &Button)) // Localize("Stop record");Localize("Record demo"); if(DoButton_Menu(&s_DemoButton, Localize(Recording ? "Stop record" : "Record demo"), 0, &Button)) // Localize("Stop record");Localize("Record demo");
{ {
if(!Recording) if(!Recording)
{ Client()->DemoRecorder_Start("demo", true);
char aFilename[128];
char aDate[20];
str_timestamp(aDate, sizeof(aDate));
str_format(aFilename, sizeof(aFilename), "demo_%s.png", aDate);
Client()->DemoRecorder_Start(aFilename);
}
else else
Client()->DemoRecorder_Stop(); Client()->DemoRecorder_Stop();
} }