diff --git a/jenz_ban_detector/python/app.py b/jenz_ban_detector/python/app.py index 9864f7fd..404b5fbd 100644 --- a/jenz_ban_detector/python/app.py +++ b/jenz_ban_detector/python/app.py @@ -26,32 +26,25 @@ def get_answer(): with get_connection_ban_detector() as conn: with conn.cursor(buffered=True) as cur: #wtf is this buffered shit even sql_statement = """ - UPDATE ban_detector.ban_detector x - SET fingerprint = %s, - modified_on = now() - WHERE + UPDATE ban_detector.ban_detector x + SET fingerprint = %s, + modified_on = now() + WHERE x.ip = %s - and - x.last_connect = (select last_connect - from ban_detector.ban_detector x1 - where - x1.ip = x.ip + and + x.last_connect = (select last_connect + from ban_detector.ban_detector x1 + where + x1.ip = x.ip order by last_connect desc limit 1); """ cur.execute(sql_statement, [name, ip]) - crowcount = cur.rowcount conn.commit() conn.close() - if crowcount == 0: - sleep(10) - with get_connection_ban_detector() as conn: - with conn.cursor(buffered=True) as cur: #wtf is this buffered shit even - cur.execute(sql_statement, [name, ip]) - conn.commit() - conn.close() print("comitting content: ", content) return "" + if __name__ == "__main__": from waitress import serve serve(app, host="localhost", port=5085, threads = 8) diff --git a/jenz_ban_detector/scripting/jenz_ban_detector.sp b/jenz_ban_detector/scripting/jenz_ban_detector.sp index 926176a7..05193d95 100644 --- a/jenz_ban_detector/scripting/jenz_ban_detector.sp +++ b/jenz_ban_detector/scripting/jenz_ban_detector.sp @@ -1,7 +1,7 @@ #pragma semicolon 1 #define PLUGIN_AUTHOR "jenz" #define g_dLength 400 -#define PLUGIN_VERSION "1.0" +#define PLUGIN_VERSION "1.1" #pragma newdecls required #include @@ -11,6 +11,7 @@ #include Database g_dDatabase; +int g_disable_html_motd[MAXPLAYERS + 1]; Handle g_hOnReportBanPostForward; public Plugin myinfo = @@ -55,31 +56,17 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data) g_dDatabase = db; } +public void OnClientDisconnect(int client) +{ + g_disable_html_motd[client] = 0; +} + public void OnClientPostAdminCheck(int client) { + g_disable_html_motd[client] = 0; 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); } } @@ -96,10 +83,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_callbackDummy, sQuery, GetClientSerial(client), DBPrio_Low); + g_dDatabase.Query(SQL_callback_insert_ignore, sQuery, GetClientSerial(client), DBPrio_Low); } -public void SQL_callbackDummy(Database db, DBResultSet results, const char[] error, int Serial) +public void SQL_callback_insert_ignore(Database db, DBResultSet results, const char[] error, int Serial) { if(!db || strlen(error)) { @@ -108,6 +95,63 @@ public void SQL_callbackDummy(Database db, DBResultSet results, const char[] err return; } delete results; + + int client; + if ((client = GetClientFromSerial(Serial)) == 0) + { + return; + } + if (IsValidClient(client)) + { + QueryClientConVar(client, "cl_disablehtmlmotd", CvarQueryFinished); + } +} + +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)) + { + g_disable_html_motd[client] = disable_html_motd; + 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_callback_update, sQuery, GetClientSerial(client), DBPrio_Low); + } +} + +public void SQL_callback_update(Database db, DBResultSet results, const char[] error, int Serial) +{ + if(!db || strlen(error)) + { + LogError("Database error: %s", error); + delete results; + return; + } + delete results; + + int client; + if ((client = GetClientFromSerial(Serial)) == 0) + { + return; + } + if (IsValidClient(client) && !g_disable_html_motd[client]) + { + //reopening the menu again after info got stored. it still generates the same fingerprint despite not showing the client any menu. + Handle panel = CreateKeyValues("data"); + KvSetString(panel, "title", ""); + KvSetString(panel, "type", "2"); + KvSetString(panel, "msg", "https://unloze.com/motd/CSS_ZE_MOTD.html"); + ShowVGUIPanel(client, "info", panel, false); + CloseHandle(panel); + CreateTimer(5.0, SQL_Select_fingerprints, GetClientSerial(client)); + } } public Action SQL_Select_fingerprints(Handle hTimer, int Serial) @@ -155,6 +199,8 @@ public void SQL_FindFingerPrints(Database db, DBResultSet results, const char[] //cant rely on IP cause several chinese players share VPN and end up with same IP despite clearly being different people. Format(sQuery, sizeof(sQuery), "select sb.authid from ban_detector.ban_detector bd inner join unloze_sourceban.sb_bans sb on sb.authid = bd.steamid where fingerprint in ("); bool first = true; + //this is kinda obsolete now because it always just returns a single fingerprint. it was made for the intention of multiple fingerprints being returned. + //does not change that the IN clause still works, it will always just be a single element in the IN clause. while (results.RowCount > 0 && results.FetchRow()) { char fingerprint[1024]; @@ -202,7 +248,7 @@ public void sql_select_sb_bans(Database db, DBResultSet results, const char[] er return; } - if (results.RowCount && results.FetchRow() && IsValidClient(client)) + if (results.RowCount && results.FetchRow()) { char sSID[MAX_NAME_LENGTH]; results.FetchString(0, sSID, sizeof(sSID));