diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 9ad6f04f..fb0ea5a0 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -44,6 +44,8 @@ #define HUD_NOSOUNDS (1 << 11) // disables sounds on personal best, world record etc #define HUD_NOPRACALERT (1 << 12) // hides practice mode chat alert +#define SHAVIT_LOG_QUERIES 0 + // status enum TimerStatus { @@ -250,6 +252,56 @@ enum struct frame_cache_t float fTickrate; } +stock void Shavit_LogQuery(const char[] query) +{ +#if SHAVIT_LOG_QUERIES + static File hLogFile; + + if (hLogFile == null) + { + char sPlugin[PLATFORM_MAX_PATH]; + GetPluginFilename(INVALID_HANDLE, sPlugin, sizeof(sPlugin)); + ReplaceString(sPlugin, PLATFORM_MAX_PATH, ".smx", ""); + ReplaceString(sPlugin, PLATFORM_MAX_PATH, "\\", "/"); + + int start = FindCharInString(sPlugin, '/', true); + + char sFilename[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, sFilename, sizeof(sFilename), "logs/%s_sql.log", sPlugin[start+1]); + + hLogFile = OpenFile(sFilename, "a"); + } + + if (hLogFile) + { + LogToOpenFileEx(hLogFile, "%s", query); + } +#endif +} + +methodmap Database2 < Database +{ + public void Query(SQLQueryCallback callback, const char[] query, any data = 0, DBPriority prio = DBPrio_Normal) + { + Shavit_LogQuery(query); + this.Query(callback, query, data, prio); + } +} + +methodmap Transaction2 < Transaction +{ + public Transaction2() + { + return view_as(new Transaction()); + } + + public int AddQuery(const char[] query, any data = 0) + { + Shavit_LogQuery(query); + return this.AddQuery(query, data); + } +} + #if defined USES_CHAT_COLORS // hardcoded colors char gS_GlobalColorNames[][] = @@ -323,6 +375,11 @@ stock Database GetTimerDatabaseHandle() return db; } +stock Database2 GetTimerDatabaseHandle2() +{ + return view_as(GetTimerDatabaseHandle()); +} + // figures out if the database is a mysql database stock bool IsMySQLDatabase(Database db) { diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index 85ef6a79..304888c9 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -81,7 +81,7 @@ DynamicHook gH_AcceptInput; // used for hooking player_speedmod's AcceptInput Handle gH_PhysicsCheckForEntityUntouch; // database handle -Database gH_SQL = null; +Database2 gH_SQL = null; bool gB_MySQL = false; int gI_MigrationsRequired; int gI_MigrationsFinished; @@ -2995,7 +2995,7 @@ bool LoadMessages() void SQL_DBConnect() { GetTimerSQLPrefix(gS_MySQLPrefix, 32); - gH_SQL = GetTimerDatabaseHandle(); + gH_SQL = GetTimerDatabaseHandle2(); gB_MySQL = IsMySQLDatabase(gH_SQL); // support unicode names @@ -3193,7 +3193,7 @@ public void SQL_TableMigrationIPAddresses_Callback(Database db, DBResultSet resu return; } - Transaction hTransaction = new Transaction(); + Transaction2 hTransaction = new Transaction2(); int iQueries = 0; while(results.FetchRow()) diff --git a/addons/sourcemod/scripting/shavit-rankings.sp b/addons/sourcemod/scripting/shavit-rankings.sp index 8fc5fcc4..598e8fd2 100644 --- a/addons/sourcemod/scripting/shavit-rankings.sp +++ b/addons/sourcemod/scripting/shavit-rankings.sp @@ -66,7 +66,7 @@ enum struct ranking_t } char gS_MySQLPrefix[32]; -Database gH_SQL = null; +Database2 gH_SQL = null; bool gB_HasSQLRANK = false; // whether the sql driver supports RANK() bool gB_Stats = false; @@ -218,7 +218,7 @@ public void OnLibraryRemoved(const char[] name) public void Shavit_OnDatabaseLoaded() { GetTimerSQLPrefix(gS_MySQLPrefix, 32); - gH_SQL = GetTimerDatabaseHandle(); + gH_SQL = GetTimerDatabaseHandle2(); if(!IsMySQLDatabase(gH_SQL)) { @@ -743,7 +743,7 @@ public Action Command_RecalcAll(int client, int args) { ReplyToCommand(client, "- Started recalculating points for all maps. Check console for output."); - Transaction trans = new Transaction(); + Transaction2 trans = new Transaction2(); char sQuery[1024]; FormatEx(sQuery, sizeof(sQuery), "UPDATE %splayertimes SET points = 0;", gS_MySQLPrefix); diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index 8e2d4bfd..5d8b1881 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -286,7 +286,7 @@ TopMenu gH_AdminMenu = null; TopMenuObject gH_TimerCommands = INVALID_TOPMENUOBJECT; // database related things -Database gH_SQL = null; +Database2 gH_SQL = null; char gS_MySQLPrefix[32]; bool gB_ClosestPos; @@ -488,7 +488,7 @@ public void OnPluginStart() // database GetTimerSQLPrefix(gS_MySQLPrefix, 32); - gH_SQL = GetTimerDatabaseHandle(); + gH_SQL = GetTimerDatabaseHandle2(); LoadDHooks(); diff --git a/addons/sourcemod/scripting/shavit-stats.sp b/addons/sourcemod/scripting/shavit-stats.sp index c16d6dc4..d04c5c92 100644 --- a/addons/sourcemod/scripting/shavit-stats.sp +++ b/addons/sourcemod/scripting/shavit-stats.sp @@ -40,7 +40,7 @@ bool gB_Rankings = false; // database handle -Database gH_SQL = null; +Database2 gH_SQL = null; char gS_MySQLPrefix[32]; // cache @@ -109,7 +109,7 @@ public void OnPluginStart() // database GetTimerSQLPrefix(gS_MySQLPrefix, 32); - gH_SQL = GetTimerDatabaseHandle(); + gH_SQL = GetTimerDatabaseHandle2(); if(gB_Late) { diff --git a/addons/sourcemod/scripting/shavit-timelimit.sp b/addons/sourcemod/scripting/shavit-timelimit.sp index de9b1a7c..2c0847b7 100644 --- a/addons/sourcemod/scripting/shavit-timelimit.sp +++ b/addons/sourcemod/scripting/shavit-timelimit.sp @@ -36,7 +36,7 @@ // #define DEBUG // database handle -Database gH_SQL = null; +Database2 gH_SQL = null; // base cvars ConVar mp_do_warmup_period = null; @@ -113,7 +113,7 @@ public void OnPluginStart() Convar.AutoExecConfig(); GetTimerSQLPrefix(gS_MySQLPrefix, 32); - gH_SQL = GetTimerDatabaseHandle(); + gH_SQL = GetTimerDatabaseHandle2(); } public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) diff --git a/addons/sourcemod/scripting/shavit-wr.sp b/addons/sourcemod/scripting/shavit-wr.sp index b059f5be..1bbe3e80 100644 --- a/addons/sourcemod/scripting/shavit-wr.sp +++ b/addons/sourcemod/scripting/shavit-wr.sp @@ -58,7 +58,7 @@ Handle gH_OnWorstRecord = null; Handle gH_OnFinishMessage = null; // database handle -Database gH_SQL = null; +Database2 gH_SQL = null; bool gB_Connected = false; bool gB_MySQL = false; @@ -2144,11 +2144,11 @@ public int SubMenu_Handler(Menu menu, MenuAction action, int param1, int param2) public void Shavit_OnDatabaseLoaded() { GetTimerSQLPrefix(gS_MySQLPrefix, 32); - gH_SQL = GetTimerDatabaseHandle(); + gH_SQL = GetTimerDatabaseHandle2(); gB_MySQL = IsMySQLDatabase(gH_SQL); char sQuery[1024]; - Transaction hTransaction = new Transaction(); + Transaction2 hTransaction = new Transaction2(); if(gB_MySQL) { diff --git a/addons/sourcemod/scripting/shavit-zones.sp b/addons/sourcemod/scripting/shavit-zones.sp index 05e90d58..4ab92fab 100644 --- a/addons/sourcemod/scripting/shavit-zones.sp +++ b/addons/sourcemod/scripting/shavit-zones.sp @@ -40,7 +40,7 @@ EngineVersion gEV_Type = Engine_Unknown; -Database gH_SQL = null; +Database2 gH_SQL = null; bool gB_Connected = false; bool gB_MySQL = false; bool gB_InsertedPrebuiltZones = false; @@ -3240,10 +3240,10 @@ void CreateZonePoints(float point[8][3], float offset = 0.0) public void Shavit_OnDatabaseLoaded() { GetTimerSQLPrefix(gS_MySQLPrefix, 32); - gH_SQL = GetTimerDatabaseHandle(); + gH_SQL = GetTimerDatabaseHandle2(); gB_MySQL = IsMySQLDatabase(gH_SQL); - Transaction hTransaction = new Transaction(); + Transaction2 hTransaction = new Transaction2(); char sQuery[1024]; FormatEx(sQuery, 1024,