From c1c85d36b80db39c2aef034ab71456f5c512191a Mon Sep 17 00:00:00 2001 From: neon Date: Mon, 23 Jul 2018 22:40:46 +0200 Subject: [PATCH] initial commit --- .../scripting/unloze_BanDetector.sp | 189 ++++++++++++++++++ unloze_Clantag/scripting/unloze_Clantag.sp | 69 +++++++ 2 files changed, 258 insertions(+) create mode 100644 unloze_BanDetector/scripting/unloze_BanDetector.sp create mode 100644 unloze_Clantag/scripting/unloze_Clantag.sp diff --git a/unloze_BanDetector/scripting/unloze_BanDetector.sp b/unloze_BanDetector/scripting/unloze_BanDetector.sp new file mode 100644 index 00000000..01659f4d --- /dev/null +++ b/unloze_BanDetector/scripting/unloze_BanDetector.sp @@ -0,0 +1,189 @@ +//==================================================================================================== +// +// Name: i3D.net Ban Detector. +// Author: zaCade +// Description: Detect potential ban evasions. +// +//==================================================================================================== +#undef REQUIRE_PLUGIN +#include +#include +#include + +new G_iParentAuthID[MAXPLAYERS+1]; +new G_iClientAuthID[MAXPLAYERS+1]; + +new bool:G_bSourcebansAvailable; +new Handle:G_hDatabase; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Plugin:myinfo = +{ + name = "UNLOZE Ban Detector", + author = "zaCade", + description = "Detect potential ban evasions", + version = "1.0", +}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public OnPluginStart() +{ + SQL_TConnect(SQL_OnConnected, "sourcebans"); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public OnAllPluginsLoaded() +{ + if (LibraryExists("sourcebans")) + G_bSourcebansAvailable = true; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public OnLibraryAdded(const String:name[]) +{ + if (StrEqual("sourcebans", name)) + G_bSourcebansAvailable = true; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public OnLibraryRemoved(const String:name[]) +{ + if (StrEqual("sourcebans", name)) + G_bSourcebansAvailable = false; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public OnClientConnected(client) +{ + G_iParentAuthID[client] = -1; + G_iClientAuthID[client] = -1; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public OnClientDisconnect(client) +{ + G_iParentAuthID[client] = -1; + G_iClientAuthID[client] = -1; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public OnClientPostAdminCheck(client) +{ + if (G_bSourcebansAvailable && !IsFakeClient(client)) + { + if (G_iParentAuthID[client] != -1 && G_iClientAuthID[client] != -1) + CheckBans_SteamID(client, G_iParentAuthID[client], G_iClientAuthID[client]); + + CheckBans_IPAdress(client); + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public SteamWorks_OnValidateClient(parentAuthID, clientAuthID) +{ + if (G_bSourcebansAvailable && parentAuthID != clientAuthID) + { + for (new client = 1; client <= MaxClients; client++) + { + if (IsClientConnected(client) && GetSteamAccountID(client) == clientAuthID) + { + if (!IsClientInGame(client)) + { + G_iParentAuthID[client] = parentAuthID; + G_iClientAuthID[client] = clientAuthID; + break; + } + else + { + CheckBans_SteamID(client, parentAuthID, clientAuthID); + break; + } + } + } + } +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public CheckBans_SteamID(client, parentAuthID, clientAuthID) +{ + new String:authid[32]; + Format(authid, sizeof(authid), "STEAM_0:%d:%d", (parentAuthID & 1), (parentAuthID >> 1)); + + new String:query[512]; + Format(query, sizeof(query), "SELECT * FROM sb_bans WHERE authid = '%s' AND ((length = 0 OR ends > UNIX_TIMESTAMP()) AND removetype IS NULL)", authid); +// Format(query, sizeof(query), "SELECT * FROM sb_bans WHERE authid = '%s' AND ((ends > '%d' AND length != '0') OR length = '0')", authid, GetTime()); + + LogMessage("[BanDetector] Checking family sharing user %L (AUTH: %s, PAUTH: %d, CAUTH: %d)", client, authid, parentAuthID, clientAuthID); + + if (G_hDatabase != INVALID_HANDLE) + SQL_TQuery(G_hDatabase, SQL_OnCheckClientSteamID, query, client); + else + LogMessage("[BanDetector] Unable to check user %L (No database)", client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public CheckBans_IPAdress(client) +{ + new String:adress[32]; + GetClientIP(client, adress, sizeof(adress)); + + new String:query[512]; + Format(query, sizeof(query), "SELECT * FROM sb_bans WHERE ip = '%s' AND ((length = 0 OR ends > UNIX_TIMESTAMP()) AND removetype IS NULL AND (aid != 0 OR reason != 'Ban evasion (IP)')", adress); +// Format(query, sizeof(query), "SELECT * FROM sb_bans WHERE ip = '%s' AND ((ends > '%d' AND length != '0') OR length = '0') AND ((reason != 'Ban evasion (IP)' AND aid = '0') OR aid != '0')", adress, GetTime()); + + LogMessage("[BanDetector] Checking user %L (IP: %s)", client, adress); + + if (G_hDatabase != INVALID_HANDLE) + SQL_TQuery(G_hDatabase, SQL_OnCheckClientIP, query, client); + else + LogMessage("[BanDetector] Unable to check user %L (No database)", client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public SQL_OnConnected(Handle:owner, Handle:handle, const String:error[], any:data) +{ + if (handle != INVALID_HANDLE) + G_hDatabase = handle; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public SQL_OnCheckClientSteamID(Handle:owner, Handle:handle, const String:error[], any:client) +{ + if (handle != INVALID_HANDLE && SQL_FetchRow(handle)) + SBBanPlayer(0, client, 0, "Ban evasion (FS)"); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public SQL_OnCheckClientIP(Handle:owner, Handle:handle, const String:error[], any:client) +{ + if (handle != INVALID_HANDLE && SQL_FetchRow(handle)) + SBBanPlayer(0, client, 0, "Ban evasion (IP)"); +} \ No newline at end of file diff --git a/unloze_Clantag/scripting/unloze_Clantag.sp b/unloze_Clantag/scripting/unloze_Clantag.sp new file mode 100644 index 00000000..d4f05a98 --- /dev/null +++ b/unloze_Clantag/scripting/unloze_Clantag.sp @@ -0,0 +1,69 @@ +#include +#include + +#define CLANID "9110211" +#define GROUP "Game-Member" + +public Plugin myinfo = +{ + name = "UNLOZE Clantag", + author = "BotoX", + description = "Assign group to people wearing the UNLOZE clantag", + version = "1.0", + url = "" +}; + +public void OnPluginStart() +{ + /* Handle late load */ + for(int client = 1; client <= MaxClients; client++) + { + if(IsClientInGame(client) && IsClientAuthorized(client)) + { + OnClientPostAdminFilter(client); + } + } +} + +public void OnClientPostAdminFilter(int client) +{ + CheckClantag(client); +} + +public void OnClientSettingsChanged(int client) +{ + CheckClantag(client); +} + +void CheckClantag(int client) +{ + if(!IsClientAuthorized(client)) + return; + + char sClanID[32]; + GetClientInfo(client, "cl_clanid", sClanID, sizeof(sClanID)); + + if(!StrEqual(sClanID, CLANID)) + return; + + AdminId AdmID; + GroupId GrpID; + + if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID) + { + LogMessage("Creating new admin for %L", client); + + AdmID = CreateAdmin(""); + SetUserAdmin(client, AdmID, true); + } + + if ((GrpID = FindAdmGroup(GROUP)) != INVALID_GROUP_ID) + { + if (AdminInheritGroup(AdmID, GrpID)) + LogMessage("%L added to group %s", client, GROUP); + } + else + { + LogMessage("%L group not found %s", client, GROUP); + } +}