added discord integration and updated create table script

This commit is contained in:
jenz 2023-02-03 11:38:47 +01:00
parent 532c3212ce
commit 2d3ef46f86
3 changed files with 69 additions and 25 deletions

View File

@ -1,9 +1,25 @@
CREATE TABLE ban_detector ( CREATE TABLE `ban_detector` (
`fingerprint` varchar(512) NOT NULL, `fingerprint` varchar(512) NOT NULL,
`ip` varchar(64) NOT NULL, `ip` varchar(64) NOT NULL,
`steamid` varchar(64), `steamid` varchar(64) DEFAULT NULL,
`name` varchar(128), `name` varchar(128) DEFAULT NULL,
`logged_message` boolean default false, `created_on` datetime DEFAULT CURRENT_TIMESTAMP
`created_on` datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`fingerprint`,`ip`)
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

View File

@ -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
};

View File

@ -12,6 +12,7 @@
int validate_state [MAXPLAYERS + 1]; int validate_state [MAXPLAYERS + 1];
Database g_dDatabase; Database g_dDatabase;
Database g_hDatabase_sourceban; Database g_hDatabase_sourceban;
Handle g_hOnReportBanPostForward;
public Plugin myinfo = public Plugin myinfo =
{ {
@ -22,9 +23,15 @@ public Plugin myinfo =
url = "www.unloze.com" 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() public void OnPluginStart()
{ {
g_hOnReportBanPostForward = CreateGlobalForward("BanDetectorPost", ET_Ignore, Param_Cell, Param_String);
if (!g_dDatabase) if (!g_dDatabase)
{ {
Database.Connect(SQL_OnDatabaseConnect, "jenz_ban_detector"); 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 sQuery[g_dLength];
char sSID[MAX_NAME_LENGTH]; char sSID[MAX_NAME_LENGTH];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); 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); //PrintToChatAll("sQuery: %s", sQuery);
g_dDatabase.Query(SQL_FindFingerPrints, sQuery, client, DBPrio_High); 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()) if (results.RowCount && results.FetchRow())
{ {
char sSID[MAX_NAME_LENGTH]; char sSID[MAX_NAME_LENGTH];
char sSIDClient[MAX_NAME_LENGTH];
GetClientAuthId(client, AuthId_Steam2, sSIDClient, sizeof(sSIDClient));
char sIP[MAX_NAME_LENGTH]; char sIP[MAX_NAME_LENGTH];
results.FetchString(0, sSID, sizeof(sSID)); results.FetchString(0, sSID, sizeof(sSID));
results.FetchString(1, sIP, sizeof(sIP)); results.FetchString(1, sIP, sizeof(sIP));
char sql_statement[512]; Call_StartForward(g_hOnReportBanPostForward);
Format(sql_statement, sizeof(sql_statement), "UPDATE `ban_detector` SET detected_on_sourceban = '%s' where steamid = '%s'", sSID, sSIDClient); Call_PushCell(client);
if (strlen(sSID) == 0) 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); else
} {
delete results; //found steamID
} Call_PushString(sSID);
}
public void SQL_UpdateLogged(Database db, DBResultSet results, const char[] error, any data) Call_Finish();
{
if (!db || strlen(error))
{
LogError("Database error: %s", error);
return;
} }
delete results; delete results;
} }
@ -209,7 +210,6 @@ public Action start_checks(Handle hTimer)
} }
} }
public void OnClientDisconnect(int client) public void OnClientDisconnect(int client)
{ {
validate_state[client] = -1; validate_state[client] = -1;