diff --git a/src/engine/shared/storage.cpp b/src/engine/shared/storage.cpp index 491795ad1..1d0e2f781 100644 --- a/src/engine/shared/storage.cpp +++ b/src/engine/shared/storage.cpp @@ -30,6 +30,9 @@ public: str_format(aPath, sizeof(aPath), "%s/maps", m_aApplicationSavePath); fs_makedir(aPath); + str_format(aPath, sizeof(aPath), "%s/dumps", m_aApplicationSavePath); + fs_makedir(aPath); + str_format(aPath, sizeof(aPath), "%s/downloadedmaps", m_aApplicationSavePath); fs_makedir(aPath); diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 5ffe1efdd..433ff4091 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -1,5 +1,6 @@ //#include "gc_console.h" #include +#include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include #include @@ -570,6 +572,41 @@ void CGameConsole::Toggle(int Type) m_ConsoleType = Type; } +void CGameConsole::Dump(int Type) +{ + CInstance *pConsole = Type == 1 ? &m_RemoteConsole : &m_LocalConsole; + char aFilename[128]; + time_t Time; + char aDate[20]; + + time(&Time); + tm* TimeInfo = localtime(&Time); + strftime(aDate, sizeof(aDate), "%Y-%m-%d_%I-%M", TimeInfo); + + for(int i = 0; i < 10; i++) + { + IOHANDLE io; + str_format(aFilename, sizeof(aFilename), "dumps/%s_dump%s-%05d.txt", Type==1?"remote_console":"local_console", aDate, i); + io = Storage()->OpenFile(aFilename, IOFLAG_WRITE); + if(io) + { + #if defined(CONF_FAMILY_WINDOWS) + static const char Newline[] = "\r\n"; + #else + static const char Newline[] = "\n"; + #endif + + for(char *pEntry = pConsole->m_Backlog.First(); pEntry; pEntry = pConsole->m_Backlog.Next(pEntry)) + { + io_write(io, pEntry, str_length(pEntry)); + io_write(io, Newline, sizeof(Newline)-1); + } + io_close(io); + break; + } + } +} + void CGameConsole::ConToggleLocalConsole(IConsole::IResult *pResult, void *pUserData) { ((CGameConsole *)pUserData)->Toggle(0); @@ -590,6 +627,16 @@ void CGameConsole::ConClearRemoteConsole(IConsole::IResult *pResult, void *pUser ((CGameConsole *)pUserData)->m_RemoteConsole.ClearBacklog(); } +void CGameConsole::ConDumpLocalConsole(IConsole::IResult *pResult, void *pUserData) +{ + ((CGameConsole *)pUserData)->Dump(0); +} + +void CGameConsole::ConDumpRemoteConsole(IConsole::IResult *pResult, void *pUserData) +{ + ((CGameConsole *)pUserData)->Dump(1); +} + void CGameConsole::ClientConsolePrintCallback(const char *pStr, void *pUserData) { ((CGameConsole *)pUserData)->m_LocalConsole.PrintLine(pStr); @@ -618,6 +665,8 @@ void CGameConsole::OnConsoleInit() Console()->Register("toggle_remote_console", "", CFGFLAG_CLIENT, ConToggleRemoteConsole, this, "Toggle remote console"); Console()->Register("clear_local_console", "", CFGFLAG_CLIENT, ConClearLocalConsole, this, "Clear local console"); Console()->Register("clear_remote_console", "", CFGFLAG_CLIENT, ConClearRemoteConsole, this, "Clear remote console"); + Console()->Register("dump_local_console", "", CFGFLAG_CLIENT, ConDumpLocalConsole, this, "Dump local console"); + Console()->Register("dump_remote_console", "", CFGFLAG_CLIENT, ConDumpRemoteConsole, this, "Dump remote console"); } /* diff --git a/src/game/client/components/console.h b/src/game/client/components/console.h index 68f3965da..a4d227902 100644 --- a/src/game/client/components/console.h +++ b/src/game/client/components/console.h @@ -56,6 +56,7 @@ class CGameConsole : public CComponent float m_StateChangeDuration; void Toggle(int Type); + void Dump(int Type); static void PossibleCommandsRenderCallback(const char *pStr, void *pUser); static void ClientConsolePrintCallback(const char *pStr, void *pUserData); @@ -63,6 +64,8 @@ class CGameConsole : public CComponent static void ConToggleRemoteConsole(IConsole::IResult *pResult, void *pUserData); static void ConClearLocalConsole(IConsole::IResult *pResult, void *pUserData); static void ConClearRemoteConsole(IConsole::IResult *pResult, void *pUserData); + static void ConDumpLocalConsole(IConsole::IResult *pResult, void *pUserData); + static void ConDumpRemoteConsole(IConsole::IResult *pResult, void *pUserData); public: CGameConsole();