Skip to content

Commit

Permalink
Fix SourceSlouth not functioning for perm.bans
Browse files Browse the repository at this point in the history
  • Loading branch information
shavitush committed Apr 19, 2016
1 parent 3608cfe commit 2453503
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 46 deletions.
90 changes: 48 additions & 42 deletions game_upload/addons/sourcemod/scripting/SourceSleuth.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// This file is part of SourceBans++.
//
// Copyright (C) 2014-2016 Sarabveer Singh <me@sarabveer.me>
//
//
// SourceBans++ is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, per version 3 of the License.
//
//
// SourceBans++ is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with SourceBans++. If not, see <http://www.gnu.org/licenses/>.
//
// This file is based off work covered by the following copyright(s):
// This file is based off work covered by the following copyright(s):
//
// SourceSleuth 1.3 fix
// Copyright (C) 2013-2015 ecca
Expand Down Expand Up @@ -53,36 +53,36 @@ ConVar g_cVar_bypass;
//- Bools -//
new bool:CanUseSourcebans = false;

public Plugin:myinfo =
public Plugin:myinfo =
{
name = "SourceSleuth",
author = "ecca, Sarabveer(VEER™)",
description = "Useful for TF2 servers. Plugin will check for banned ips and ban the player.",
version = PLUGIN_VERSION,
name = "SourceSleuth",
author = "ecca, Sarabveer(VEER™)",
description = "Useful for TF2 servers. Plugin will check for banned ips and ban the player.",
version = PLUGIN_VERSION,
url = "https://sarabveer.github.io/SourceBans-Fork/"
};

public OnPluginStart()
{
LoadTranslations("sourcesleuth.phrases");

CreateConVar("sm_sourcesleuth_version", PLUGIN_VERSION, "SourceSleuth plugin version", FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY | FCVAR_DONTRECORD);

g_cVar_actions = CreateConVar("sm_sleuth_actions", "3", "Sleuth Ban Type: 1 - Original Length, 2 - Custom Length, 3 - Double Length, 4 - Notify Admins Only", FCVAR_PLUGIN, true, 1.0, true, 4.0);
g_cVar_banduration = CreateConVar("sm_sleuth_duration", "0", "Required: sm_sleuth_actions 1: Bantime to ban player if we got a match (0 = permanent (defined in minutes) )", FCVAR_PLUGIN);
g_cVar_sbprefix = CreateConVar("sm_sleuth_prefix", "sb", "Prexfix for sourcebans tables: Default sb", FCVAR_PLUGIN);
g_cVar_bansAllowed = CreateConVar("sm_sleuth_bansallowed", "0", "How many active bans are allowed before we act", FCVAR_PLUGIN);
g_cVar_bantype = CreateConVar("sm_sleuth_bantype", "0", "0 - ban all type of lengths, 1 - ban only permanent bans", FCVAR_PLUGIN, true, 0.0, true, 1.0);
g_cVar_bypass = CreateConVar("sm_sleuth_adminbypass", "0", "0 - Inactivated, 1 - Allow all admins with ban flag to pass the check", FCVAR_PLUGIN, true, 0.0, true, 1.0);

g_hAllowedArray = CreateArray(256);

AutoExecConfig(true, "Sm_SourceSleuth");

SQL_TConnect(SQL_OnConnect, "sourcebans");

RegAdminCmd("sm_sleuth_reloadlist", ReloadListCallBack, ADMFLAG_ROOT);

LoadWhiteList();
}

Expand Down Expand Up @@ -122,16 +122,16 @@ public SQL_OnConnect(Handle:owner, Handle:hndl, const String:error[], any:data)
public Action:ReloadListCallBack(client, args)
{
ClearArray(g_hAllowedArray);

LoadWhiteList();

LogMessage("%L reloaded the whitelist", client);

if (client != 0)
{
PrintToChat(client, "[SourceSleuth] WhiteList has been reloaded!");
}

return Plugin_Continue;
}

Expand All @@ -141,30 +141,30 @@ public OnClientPostAdminCheck(client)
{
new String:steamid[32];
GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));

if (g_cVar_bypass.BoolValue && CheckCommandAccess(client, "sleuth_admin", ADMFLAG_BAN, false))
{
return;
}

if (FindStringInArray(g_hAllowedArray, steamid) == -1)
{
new String:IP[32], String:Prefix[64];
GetClientIP(client, IP, sizeof(IP));

g_cVar_sbprefix.GetString(Prefix, sizeof(Prefix));

new String:query[1024];

FormatEx(query, sizeof(query), "SELECT * FROM %s_bans WHERE ip='%s' AND RemoveType IS NULL AND ends > %d", Prefix, IP, g_cVar_bantype.IntValue == 0 ? GetTime() : 0);

new Handle:datapack = CreateDataPack();

WritePackCell(datapack, GetClientUserId(client));
WritePackString(datapack, steamid);
WritePackString(datapack, IP);
ResetPack(datapack);

SQL_TQuery(hDatabase, SQL_CheckHim, query, datapack);
}
}
Expand All @@ -174,25 +174,25 @@ public SQL_CheckHim(Handle:owner, Handle:hndl, const String:error[], any:datapac
{
new client;
decl String:steamid[32], String:IP[32];

if (datapack != INVALID_HANDLE)
{
client = GetClientOfUserId(ReadPackCell(datapack));
ReadPackString(datapack, steamid, sizeof(steamid));
ReadPackString(datapack, IP, sizeof(IP));
CloseHandle(datapack);
}

if (hndl == INVALID_HANDLE)
{
LogError("SourceSleuth: Database query error: %s", error);
return;
}

if (SQL_FetchRow(hndl))
{
new TotalBans = SQL_GetRowCount(hndl);

if (TotalBans > g_cVar_bansAllowed.IntValue)
{
switch (g_cVar_actions.IntValue)
Expand All @@ -201,7 +201,7 @@ public SQL_CheckHim(Handle:owner, Handle:hndl, const String:error[], any:datapac
{
new length = SQL_FetchInt(hndl, 6);
new time = length * 60;

BanPlayer(client, time);
}
case LENGTH_CUSTOM:
Expand All @@ -212,8 +212,14 @@ public SQL_CheckHim(Handle:owner, Handle:hndl, const String:error[], any:datapac
case LENGTH_DOUBLE:
{
new length = SQL_FetchInt(hndl, 6);
new time = length / 60 * 2;


new time = 0;

if(length != 0)
{
time = length / 60 * 2;
}

BanPlayer(client, time);
}
case LENGTH_NOTIFY:
Expand All @@ -236,13 +242,13 @@ stock BanPlayer(client, time)
PrintToAdmins(const String:format[], any:...)
{
new String:g_Buffer[256];

for (new i = 1; i <= MaxClients; i++)
{
if (CheckCommandAccess(i, "sm_sourcesleuth_printtoadmins", ADMFLAG_BAN) && IsClientInGame(i))
{
VFormat(g_Buffer, sizeof(g_Buffer), format, 2);

PrintToChat(i, "%s", g_Buffer);
}
}
Expand All @@ -251,17 +257,17 @@ PrintToAdmins(const String:format[], any:...)
public LoadWhiteList()
{
decl String:path[PLATFORM_MAX_PATH], String:line[256];

BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "configs/sourcesleuth_whitelist.cfg");

new Handle:fileHandle = OpenFile(path, "r");

while (!IsEndOfFile(fileHandle) && ReadFileLine(fileHandle, line, sizeof(line)))
{
ReplaceString(line, sizeof(line), "\n", "", false);

PushArrayString(g_hAllowedArray, line);
}

CloseHandle(fileHandle);
}
8 changes: 4 additions & 4 deletions game_upload/addons/sourcemod/scripting/include/sourcebans.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
#endif
#define _sourcebans_included

public SharedPlugin:__pl_sourcebans =
public SharedPlugin:__pl_sourcebans =
{
name = "SourceBans",
file = "sourcebans.smx",
name = "sourcebans",
file = "sourcebans.smx",
#if defined REQUIRE_PLUGIN
required = 1
#else
Expand All @@ -59,4 +59,4 @@ public __pl_sourcebans_SetNTVOptional()
*********************************************************/
native SBBanPlayer(client, target, time, String:reason[]);

//Yarr!
//Yarr!

0 comments on commit 2453503

Please sign in to comment.