diff --git a/amxmodx/binlog.cpp b/amxmodx/binlog.cpp index 7c393997..ec342a06 100644 --- a/amxmodx/binlog.cpp +++ b/amxmodx/binlog.cpp @@ -45,8 +45,27 @@ bool BinLog::Open() } build_pathname_r(file, sizeof(file)-1, "%s/binlogs/binlog%04d.blg", data, lastcntr); m_logfile.assign(file); - build_pathname_r(file, sizeof(file)-1, "%s/binlogs/bindb%04d.bdb", data, lastcntr); - m_dbfile.assign(file); + + /** + * it's now safe to create the binary log + */ + FILE *fp = fopen(m_logfile.c_str(), "wb"); + if (!fp) + return false; + + int magic = BINLOG_MAGIC; + short vers = BINLOG_VERSION; + char c = sizeof(time_t); + fwrite(&magic, sizeof(int), 1, fp); + fwrite(&vers, sizeof(short), 1, fp); + fwrite(&c, sizeof(char), 1, fp); + + WritePluginDB(fp); + fclose(fp); + + m_state = true; + + WriteOp(BinLog_Start, -1); return true; } @@ -54,10 +73,14 @@ bool BinLog::Open() void BinLog::Close() { WriteOp(BinLog_End, -1); + m_state = false; } void BinLog::WriteOp(BinLogOp op, int plug, ...) { + if (!m_state) + return; + FILE *fp = fopen(m_logfile.c_str(), "ab"); if (!fp) return; @@ -70,7 +93,6 @@ void BinLog::WriteOp(BinLogOp op, int plug, ...) fclose(fp); Close(); Open(); - CacheAllPlugins(); fp = fopen(m_logfile.c_str(), "ab"); if (!fp) return; @@ -187,18 +209,8 @@ void BinLog::WriteOp(BinLogOp op, int plug, ...) fclose(fp); } -void BinLog::CacheAllPlugins() +void BinLog::WritePluginDB(FILE *fp) { - FILE *fp = fopen(m_dbfile.c_str(), "wb"); - if (!fp) - return; - - unsigned int magic = BINDB_MAGIC; - unsigned short vers = BINDB_VERSION; - - fwrite(&magic, sizeof(unsigned int), 1, fp); - fwrite(&vers, sizeof(unsigned short), 1, fp); - int num = g_plugins.getPluginsNum(); fwrite(&num, sizeof(int), 1, fp); @@ -243,24 +255,6 @@ void BinLog::CacheAllPlugins() fwrite(name, sizeof(char), len, fp); } } - fclose(fp); - - /** - * it's now safe to create the binary log - */ - fp = fopen(m_logfile.c_str(), "wb"); - if (!fp) - return; - - magic = BINLOG_MAGIC; - vers = BINLOG_VERSION; - c = sizeof(time_t); - fwrite(&magic, sizeof(int), 1, fp); - fwrite(&vers, sizeof(short), 1, fp); - fwrite(&c, sizeof(char), 1, fp); - fclose(fp); - - WriteOp(BinLog_Start, -1); } #endif //BINLOG_ENABLED diff --git a/amxmodx/binlog.h b/amxmodx/binlog.h index cf417011..0b1a1c29 100644 --- a/amxmodx/binlog.h +++ b/amxmodx/binlog.h @@ -6,25 +6,13 @@ #include "CString.h" #define BINLOG_MAGIC 0x414D424C -#define BINLOG_VERSION 0x0100 -#define BINDB_MAGIC 0x414D4244 -#define BINDB_VERSION 0x0100 +#define BINLOG_VERSION 0x0200 /** * Format of binlog: * uint32 magic * uint16 version * uint8 sizeof(time_t) - * [ - * uint8 operation code - * time_t realtime - * float gametime - * int32 plugin id - * - * ] - * Format of bindb: - * uint32 magic - * uint16 version * uint32 num plugins * [ * uint8 status codes @@ -37,6 +25,14 @@ * [ * str[uint8] public name * ] + * ] + * [ + * uint8 operation code + * time_t realtime + * float gametime + * int32 plugin id + * + * ] */ enum BinLogOp @@ -57,14 +53,19 @@ enum BinLogOp class BinLog { +public: + BinLog() : m_state(false) + { + }; public: bool Open(); void Close(); - void CacheAllPlugins(); void WriteOp(BinLogOp op, int plug, ...); private: - String m_dbfile; + void WritePluginDB(FILE *fp); +private: String m_logfile; + bool m_state; }; extern BinLog g_BinLog; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 7e047530..97c1977c 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -292,15 +292,6 @@ int C_Spawn(edict_t *pent) // Set server flags memset(g_players[0].flags, -1, sizeof(g_players[0].flags)); -#if defined BINLOG_ENABLED - if (!g_BinLog.Open()) - { - LOG_ERROR(PLID, "Binary log failed to open."); - } - g_binlog_level = atoi(get_localinfo("bin_logging", "17")); - g_binlog_maxsize = atoi(get_localinfo("g_binlog_maxsize", "20")); -#endif - g_opt_level = atoi(get_localinfo("optimizer", "7")); if (!g_opt_level) g_opt_level = 7; @@ -325,7 +316,12 @@ int C_Spawn(edict_t *pent) FF_ChangeLevel = registerForward("server_changelevel", ET_STOP, FP_STRING, FP_DONE); #if defined BINLOG_ENABLED - g_BinLog.CacheAllPlugins(); + if (!g_BinLog.Open()) + { + LOG_ERROR(PLID, "Binary log failed to open."); + } + g_binlog_level = atoi(get_localinfo("bin_logging", "17")); + g_binlog_maxsize = atoi(get_localinfo("binlog_maxsize", "20")); #endif modules_callPluginsLoaded(); diff --git a/amxmodx/msvc/amxmodx_mm.vcproj b/amxmodx/msvc/amxmodx_mm.vcproj index 6ffb3720..8b4882fe 100755 --- a/amxmodx/msvc/amxmodx_mm.vcproj +++ b/amxmodx/msvc/amxmodx_mm.vcproj @@ -614,7 +614,7 @@ AdditionalDependencies="..\zlib\zlib.lib ..\JIT\amxjitsn.obj ..\JIT\amxexecn.obj ..\JIT\natives-x86.obj" OutputFile="jitdebugbinlog/amxmodx_mm.dll" Version="0.1" - LinkIncremental="1" + LinkIncremental="2" SuppressStartupBanner="TRUE" AdditionalLibraryDirectories="..\extra\lib_win32" IgnoreDefaultLibraryNames="MSVCRT"