From 2d3ef46f86e2453d2dfd18d52e0a251992c35b13 Mon Sep 17 00:00:00 2001 From: jenz Date: Fri, 3 Feb 2023 11:38:47 +0100 Subject: [PATCH] added discord integration and updated create table script --- jenz_ban_detector/mysql/create_db.sql | 30 ++++++++++++---- .../scripting/include/jenz_ban_detector.inc | 28 +++++++++++++++ .../scripting/jenz_ban_detector.sp | 36 +++++++++---------- 3 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 jenz_ban_detector/scripting/include/jenz_ban_detector.inc diff --git a/jenz_ban_detector/mysql/create_db.sql b/jenz_ban_detector/mysql/create_db.sql index bc6317a5..907a63b2 100644 --- a/jenz_ban_detector/mysql/create_db.sql +++ b/jenz_ban_detector/mysql/create_db.sql @@ -1,9 +1,25 @@ -CREATE TABLE ban_detector ( +CREATE TABLE `ban_detector` ( `fingerprint` varchar(512) NOT NULL, `ip` varchar(64) NOT NULL, - `steamid` varchar(64), - `name` varchar(128), - `logged_message` boolean default false, - `created_on` datetime DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`fingerprint`, `ip`) -) + `steamid` varchar(64) DEFAULT NULL, + `name` varchar(128) DEFAULT NULL, + `created_on` datetime DEFAULT CURRENT_TIMESTAMP + PRIMARY KEY (`fingerprint`,`ip`) +); + + +--usefull read query +select bd2.* from ban_detector bd2 +inner join +( +SELECT fingerprint, + count(*) AS c +FROM ban_detector bd +GROUP BY fingerprint +HAVING c > 1 +ORDER BY c DESC +) as t +on bd2.fingerprint = t.fingerprint + + + diff --git a/jenz_ban_detector/scripting/include/jenz_ban_detector.inc b/jenz_ban_detector/scripting/include/jenz_ban_detector.inc new file mode 100644 index 00000000..671e37ec --- /dev/null +++ b/jenz_ban_detector/scripting/include/jenz_ban_detector.inc @@ -0,0 +1,28 @@ +#if defined _jenz_ban_detector_Included + #endinput +#endif +#define _jenz_ban_detector_Included + +/** + * Called after a client has been detected for ban avoiding + * + * @param client Client index of the target. + * @param detected_sourceban either steamID or IP of the detected sourceban ban + * @noreturn + */ +forward void BanDetectorPost(int client, const char[] detected_sourceban); + + +/* Do not edit below this line */ +public SharedPlugin __pl_jenz_ban_detector = +{ + name = "jenz_ban_detector", + file = "jenz_ban_detector.smx", +#if defined REQUIRE_PLUGIN + required = 1, +#else + required = 0, +#endif +}; + + diff --git a/jenz_ban_detector/scripting/jenz_ban_detector.sp b/jenz_ban_detector/scripting/jenz_ban_detector.sp index 289ec8b4..8c253f6f 100644 --- a/jenz_ban_detector/scripting/jenz_ban_detector.sp +++ b/jenz_ban_detector/scripting/jenz_ban_detector.sp @@ -12,6 +12,7 @@ int validate_state [MAXPLAYERS + 1]; Database g_dDatabase; Database g_hDatabase_sourceban; +Handle g_hOnReportBanPostForward; public Plugin myinfo = { @@ -22,9 +23,15 @@ public Plugin myinfo = url = "www.unloze.com" }; +public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) +{ + RegPluginLibrary("jenz_ban_detector"); + return APLRes_Success; +} public void OnPluginStart() { + g_hOnReportBanPostForward = CreateGlobalForward("BanDetectorPost", ET_Ignore, Param_Cell, Param_String); if (!g_dDatabase) { Database.Connect(SQL_OnDatabaseConnect, "jenz_ban_detector"); @@ -90,7 +97,7 @@ public void SQL_UpdateEntry(Database db, DBResultSet results, const char[] error char sQuery[g_dLength]; char sSID[MAX_NAME_LENGTH]; GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); - Format(sQuery, sizeof(sQuery), "SELECT fingerprint FROM `ban_detector` where steamid = '%s' and detected_on_sourceban is NULL limit 1", sSID); + Format(sQuery, sizeof(sQuery), "SELECT fingerprint FROM `ban_detector` where steamid = '%s' limit 1", sSID); //PrintToChatAll("sQuery: %s", sQuery); g_dDatabase.Query(SQL_FindFingerPrints, sQuery, client, DBPrio_High); } @@ -157,28 +164,22 @@ public void sql_select_sb_bans(Database db, DBResultSet results, const char[] er if (results.RowCount && results.FetchRow()) { char sSID[MAX_NAME_LENGTH]; - char sSIDClient[MAX_NAME_LENGTH]; - GetClientAuthId(client, AuthId_Steam2, sSIDClient, sizeof(sSIDClient)); char sIP[MAX_NAME_LENGTH]; results.FetchString(0, sSID, sizeof(sSID)); results.FetchString(1, sIP, sizeof(sIP)); - char sql_statement[512]; - Format(sql_statement, sizeof(sql_statement), "UPDATE `ban_detector` SET detected_on_sourceban = '%s' where steamid = '%s'", sSID, sSIDClient); + Call_StartForward(g_hOnReportBanPostForward); + Call_PushCell(client); if (strlen(sSID) == 0) { - Format(sql_statement, sizeof(sql_statement), "UPDATE `ban_detector` SET detected_on_sourceban = '%s' where steamid = '%s'", sIP, sSIDClient); + // use IP instead if no steamID + Call_PushString(sIP); } - g_dDatabase.Query(SQL_UpdateLogged, sql_statement, _, DBPrio_High); - } - delete results; -} - -public void SQL_UpdateLogged(Database db, DBResultSet results, const char[] error, any data) -{ - if (!db || strlen(error)) - { - LogError("Database error: %s", error); - return; + else + { + //found steamID + Call_PushString(sSID); + } + Call_Finish(); } delete results; } @@ -209,7 +210,6 @@ public Action start_checks(Handle hTimer) } } - public void OnClientDisconnect(int client) { validate_state[client] = -1;