From 28bb26e89776df7ef898d42a9bf4145f89a5b3b5 Mon Sep 17 00:00:00 2001 From: jenz Date: Tue, 1 Aug 2023 23:49:29 +0200 Subject: [PATCH] simply adding check for the convar disablehtml motd to check if webapp misses the updates sometimes --- jenz_ban_detector/mysql/create_db.sql | 11 +++-- .../scripting/jenz_ban_detector.sp | 48 ++++++++----------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/jenz_ban_detector/mysql/create_db.sql b/jenz_ban_detector/mysql/create_db.sql index b4213814..c21a7d56 100644 --- a/jenz_ban_detector/mysql/create_db.sql +++ b/jenz_ban_detector/mysql/create_db.sql @@ -1,10 +1,11 @@ -CREATE TABLE ban_detector.ban_detector ( +CREATE TABLE `ban_detector` ( `fingerprint` varchar(512) DEFAULT NULL, `ip` varchar(64) NOT NULL, `steamid` varchar(64) NOT NULL, `name` varchar(128) DEFAULT NULL, - `created_on` datetime DEFAULT CURRENT_TIMESTAMP, - `modified_on` datetime default null, - `last_connect` datetime default null, + `created_on` datetime DEFAULT current_timestamp(), + `modified_on` datetime DEFAULT NULL, + `last_connect` datetime DEFAULT NULL, + `disable_html_motd` int(11) DEFAULT 0, PRIMARY KEY (`steamid`) -) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/jenz_ban_detector/scripting/jenz_ban_detector.sp b/jenz_ban_detector/scripting/jenz_ban_detector.sp index ec1d8619..926176a7 100644 --- a/jenz_ban_detector/scripting/jenz_ban_detector.sp +++ b/jenz_ban_detector/scripting/jenz_ban_detector.sp @@ -60,10 +60,29 @@ public void OnClientPostAdminCheck(int client) if (!IsFakeClient(client) && !IsClientSourceTV(client)) { SQL_addEntry(client); + QueryClientConVar(client, "cl_disablehtmlmotd", CvarQueryFinished); CreateTimer(15.0, SQL_Select_fingerprints, GetClientSerial(client)); } } +public void CvarQueryFinished(QueryCookie cookie, int client, ConVarQueryResult res, const char[] sCvarName, const char[] sCvarVal) +{ + if (res != ConVarQuery_Okay) + { + return; + } + + int disable_html_motd = StringToInt(sCvarVal); + if (IsValidClient(client)) + { + char sQuery[g_dLength]; + char sSID[MAX_NAME_LENGTH]; + GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); + Format(sQuery, sizeof(sQuery), "UPDATE ban_detector SET last_connect = now(), disable_html_motd = '%i' where steamid = '%s'", disable_html_motd, sSID); + g_dDatabase.Query(SQL_callbackDummy, sQuery, GetClientSerial(client), DBPrio_Low); + } +} + public void SQL_addEntry(int client) { char sQuery[g_dLength]; @@ -77,35 +96,10 @@ public void SQL_addEntry(int client) g_dDatabase.Escape(sName, sEscapedName, size2 + 1); GetClientIP(client, sIP, sizeof(sIP)); Format(sQuery, sizeof(sQuery), "insert ignore into `ban_detector` (`steamid`, `ip`, `name`) SELECT '%s', '%s','%s'", sSID, sIP,sEscapedName); - g_dDatabase.Query(SQL_UpdateEntry, sQuery, GetClientSerial(client), DBPrio_Low); + g_dDatabase.Query(SQL_callbackDummy, sQuery, GetClientSerial(client), DBPrio_Low); } -public void SQL_UpdateEntry(Database db, DBResultSet results, const char[] error, int Serial) -{ - if(!db || strlen(error)) - { - LogError("Database error: %s", error); - delete results; - return; - } - int client; - if ((client = GetClientFromSerial(Serial)) == 0) - { - delete results; - return; - } - if (IsValidClient(client)) - { - char sQuery[g_dLength]; - char sSID[MAX_NAME_LENGTH]; - GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); - Format(sQuery, sizeof(sQuery), "UPDATE ban_detector SET last_connect = now() where steamid = '%s'", sSID); - g_dDatabase.Query(SQL_update_last_connect, sQuery, GetClientSerial(client), DBPrio_Low); - } - delete results; -} - -public void SQL_update_last_connect(Database db, DBResultSet results, const char[] error, int Serial) +public void SQL_callbackDummy(Database db, DBResultSet results, const char[] error, int Serial) { if(!db || strlen(error)) {