update sourcebanpp to 1.6.3

This commit is contained in:
Riwan Mattei
2019-04-15 22:12:43 +02:00
parent 98377e82be
commit 1252828d2f

View File

@@ -26,15 +26,14 @@
#pragma semicolon 1 #pragma semicolon 1
#include <sourcemod> #include <sourcemod>
#include <sourcebans> #include <sourcebanspp>
#undef REQUIRE_PLUGIN #undef REQUIRE_PLUGIN
#include <adminmenu> #include <adminmenu>
#tryinclude <updater> #tryinclude <updater>
#include <sm_limit_ban_duration>
#define SB_VERSION "1.6.2++" #define SB_VERSION "1.6.3"
#define SBR_VERSION "1.6.2" #define SBR_VERSION "1.6.3"
#if defined _updater_included #if defined _updater_included
#define UPDATE_URL "https://sbpp.github.io/updater/updatefile.txt" #define UPDATE_URL "https://sbpp.github.io/updater/updatefile.txt"
@@ -58,101 +57,95 @@ enum State/* ConfigState */
ConfigStateNone = 0, ConfigStateNone = 0,
ConfigStateConfig, ConfigStateConfig,
ConfigStateReasons, ConfigStateReasons,
ConfigStateHacking ConfigStateHacking,
ConfigStateTime
} }
new g_BanTarget[MAXPLAYERS + 1] = { -1, ... }; State ConfigState;
new g_BanTime[MAXPLAYERS + 1] = { -1, ... };
new State:ConfigState; #define Prefix "[SourceBans++] "
new Handle:ConfigParser;
new Handle:hTopMenu = INVALID_HANDLE;
bool g_bLimitBan;
new const String:Prefix[] = "[SourceBans++] ";
new String:ServerIp[24];
new String:ServerPort[7];
new String:DatabasePrefix[10] = "sb";
new String:WebsiteAddress[128];
/* Admin Stuff*/ /* Admin Stuff*/
new AdminCachePart:loadPart; AdminCachePart loadPart;
new bool:loadAdmins;
new bool:loadGroups;
new bool:loadOverrides;
new curLoading = 0;
new AdminFlag:g_FlagLetters[FLAG_LETTERS_SIZE];
/* Admin KeyValues */ AdminFlag g_FlagLetters[FLAG_LETTERS_SIZE];
new String:groupsLoc[128];
new String:adminsLoc[128];
new String:overridesLoc[128];
/* Cvar handle*/ /* Cvar handle*/
new Handle:CvarHostIp; ConVar
new Handle:CvarPort; CvarHostIp
, CvarPort;
/* Database handle */ /* Database handle */
new Handle:DB; Database DB;
new Handle:SQLiteDB; Database SQLiteDB;
/* Menu file globals */ char
new Handle:ReasonMenuHandle; ServerIp[24]
new Handle:HackingMenuHandle; , ServerPort[7]
, DatabasePrefix[10] = "sb"
, WebsiteAddress[128]
, groupsLoc[128] /* Admin KeyValues */
, adminsLoc[128]
, overridesLoc[128]
, logFile[256]; /* Log Stuff */
/* Datapack and Timer handles */ float RetryTime = 15.0;
new Handle:PlayerRecheck[MAXPLAYERS + 1] = { INVALID_HANDLE, ... };
new Handle:PlayerDataPack[MAXPLAYERS + 1] = { INVALID_HANDLE, ... };
/* Player ban check status */ bool
new bool:PlayerStatus[MAXPLAYERS + 1]; loadAdmins /* Admin Stuff*/
, loadGroups
, loadOverrides
, LateLoaded
, AutoAdd
, g_bConnecting = false
, requireSiteLogin = false /* Require a lastvisited from SB site */
, backupConfig = true
, enableAdmins = true
, PlayerStatus[MAXPLAYERS + 1]; /* Player ban check status */
/* Disable of addban and unban */ int
new CommandDisable; g_BanTarget[MAXPLAYERS + 1] = { -1, ... }
new bool:backupConfig = true; , g_BanTime[MAXPLAYERS + 1] = { -1, ... }
new bool:enableAdmins = true; , curLoading
, serverID = -1
, ProcessQueueTime = 5
, g_ownReasons[MAXPLAYERS + 1] = { false, ... } /* Own Chat Reason */
, CommandDisable; /* Disable of addban and unban */
/* Require a lastvisited from SB site */ Handle
new bool:requireSiteLogin = false; ConfigParser
, hTopMenu = INVALID_HANDLE
, TimeMenuHandle /* Menu file globals */
, ReasonMenuHandle
, HackingMenuHandle
, g_hFwd_OnBanAdded
, g_hFwd_OnReportAdded
, PlayerRecheck[MAXPLAYERS + 1] = { INVALID_HANDLE, ... } /* Datapack and Timer handles */
, PlayerDataPack[MAXPLAYERS + 1] = { INVALID_HANDLE, ... };
/* Log Stuff */ public Plugin myinfo =
new String:logFile[256];
/* Own Chat Reason */
new g_ownReasons[MAXPLAYERS + 1] = { false, ... };
new Float:RetryTime = 15.0;
new ProcessQueueTime = 5;
new bool:LateLoaded;
new bool:AutoAdd;
new bool:g_bConnecting = false;
new serverID = -1;
new Handle:g_hFwd_OnBanAdded;
public Plugin:myinfo =
{ {
name = "(LBD) SourceBans++: Main Plugin", name = "SourceBans++: Main Plugin",
author = "SourceBans Development Team, SourceBans++ Dev Team, with optional Limit Ban Duration support.", author = "SourceBans Development Team, SourceBans++ Dev Team",
description = "Advanced ban management for the Source engine", description = "Advanced ban management for the Source engine",
version = SBR_VERSION, version = SBR_VERSION,
url = "https://sbpp.github.io" url = "https://sbpp.github.io"
}; };
#if SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR >= 3 #if SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR >= 3
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
#else #else
public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max) public bool AskPluginLoad(Handle myself, bool late, char[] error, int err_max)
#endif #endif
{ {
RegPluginLibrary("sourcebans"); RegPluginLibrary("sourcebans++");
CreateNative("SBBanPlayer", Native_SBBanPlayer);
CreateNative("SourceBans_BanPlayer", Native_SBBanPlayer);
g_hFwd_OnBanAdded = CreateGlobalForward("SourceBans_OnBanPlayer", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_String); CreateNative("SBBanPlayer", Native_SBBanPlayer);
CreateNative("SBPP_BanPlayer", Native_SBBanPlayer);
CreateNative("SBPP_ReportPlayer", Native_SBReportPlayer);
g_hFwd_OnBanAdded = CreateGlobalForward("SBPP_OnBanPlayer", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_String);
g_hFwd_OnReportAdded = CreateGlobalForward("SBPP_OnReportPlayer", ET_Ignore, Param_Cell, Param_Cell, Param_String);
LateLoaded = late; LateLoaded = late;
@@ -189,6 +182,12 @@ public OnPluginStart()
RegConsoleCmd("say", ChatHook); RegConsoleCmd("say", ChatHook);
RegConsoleCmd("say_team", ChatHook); RegConsoleCmd("say_team", ChatHook);
if ((TimeMenuHandle = CreateMenu(MenuHandler_BanTimeList, MenuAction_Select|MenuAction_Cancel|MenuAction_DrawItem)) != INVALID_HANDLE)
{
SetMenuPagination(TimeMenuHandle, 8);
SetMenuExitBackButton(TimeMenuHandle, true);
}
if ((ReasonMenuHandle = CreateMenu(ReasonSelected)) != INVALID_HANDLE) if ((ReasonMenuHandle = CreateMenu(ReasonSelected)) != INVALID_HANDLE)
{ {
SetMenuPagination(ReasonMenuHandle, 8); SetMenuPagination(ReasonMenuHandle, 8);
@@ -213,11 +212,12 @@ public OnPluginStart()
CloseHandle(ReasonMenuHandle); CloseHandle(ReasonMenuHandle);
if (HackingMenuHandle != INVALID_HANDLE) if (HackingMenuHandle != INVALID_HANDLE)
CloseHandle(HackingMenuHandle); CloseHandle(HackingMenuHandle);
LogToFile(logFile, "Database failure: Could not find Database conf \"sourcebans\". See FAQ: https://sbpp.sarabveer.me/faq/"); LogToFile(logFile, "Database failure: Could not find Database conf \"sourcebans\". See Docs: https://sbpp.github.io/docs/");
SetFailState("Database failure: Could not find Database conf \"sourcebans\""); SetFailState("Database failure: Could not find Database conf \"sourcebans\"");
return; return;
} }
SQL_TConnect(GotDatabase, "sourcebans");
Database.Connect(GotDatabase, "sourcebans");
BuildPath(Path_SM, groupsLoc, sizeof(groupsLoc), "configs/sourcebans/sb_admin_groups.cfg"); BuildPath(Path_SM, groupsLoc, sizeof(groupsLoc), "configs/sourcebans/sb_admin_groups.cfg");
@@ -243,31 +243,19 @@ public OnPluginStart()
#endif #endif
} }
#if defined _updater_included
public void OnLibraryAdded(const char[] name) public void OnLibraryAdded(const char[] name)
{ {
#if defined _updater_included
if (StrEqual(name, "updater")) if (StrEqual(name, "updater"))
{ {
Updater_AddPlugin(UPDATE_URL); Updater_AddPlugin(UPDATE_URL);
} }
}
#endif #endif
if(StrEqual(name, "sm_limit_ban_duration")){
g_bLimitBan = true;
}
}
public void OnLibraryRemoved(const char[] name) public void OnAllPluginsLoaded()
{ {
if(StrEqual(name, "sm_limit_ban_duration")){ Handle topmenu;
g_bLimitBan = false;
}
}
public OnAllPluginsLoaded()
{
g_bLimitBan = LibraryExists("sm_limit_ban_duration");
new Handle:topmenu;
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "OnAllPluginsLoaded()"); LogToFile(logFile, "OnAllPluginsLoaded()");
#endif #endif
@@ -278,13 +266,13 @@ public OnAllPluginsLoaded()
} }
} }
public OnConfigsExecuted() public void OnConfigsExecuted()
{ {
decl String:filename[200]; char filename[200];
BuildPath(Path_SM, filename, sizeof(filename), "plugins/basebans.smx"); BuildPath(Path_SM, filename, sizeof(filename), "plugins/basebans.smx");
if (FileExists(filename)) if (FileExists(filename))
{ {
decl String:newfilename[200]; char newfilename[200];
BuildPath(Path_SM, newfilename, sizeof(newfilename), "plugins/disabled/basebans.smx"); BuildPath(Path_SM, newfilename, sizeof(newfilename), "plugins/disabled/basebans.smx");
ServerCommand("sm plugins unload basebans"); ServerCommand("sm plugins unload basebans");
if (FileExists(newfilename)) if (FileExists(newfilename))
@@ -292,28 +280,16 @@ public OnConfigsExecuted()
RenameFile(newfilename, filename); RenameFile(newfilename, filename);
LogToFile(logFile, "plugins/basebans.smx was unloaded and moved to plugins/disabled/basebans.smx"); LogToFile(logFile, "plugins/basebans.smx was unloaded and moved to plugins/disabled/basebans.smx");
} }
BuildPath(Path_SM, filename, sizeof(filename), "plugins/sbpp_main.smx");
if(FileExists(filename))
{
char newfilename[PLATFORM_MAX_PATH];
BuildPath(Path_SM, newfilename, sizeof(newfilename), "plugins/disabled/sbpp_main.smx");
ServerCommand("sm plugins unload sbpp_main");
if(FileExists(newfilename))
DeleteFile(newfilename);
RenameFile(newfilename, filename);
LogToFile(logFile, "plugins/sbpp_main.smx was unloaded and moved to plugins/disabled/sbpp_main.smx");
}
} }
public OnMapStart() public void OnMapStart()
{ {
ResetSettings(); ResetSettings();
} }
public OnMapEnd() public OnMapEnd()
{ {
for (new i = 0; i <= MaxClients; i++) for (int i = 0; i <= MaxClients; i++)
{ {
if (PlayerDataPack[i] != INVALID_HANDLE) if (PlayerDataPack[i] != INVALID_HANDLE)
{ {
@@ -326,7 +302,7 @@ public OnMapEnd()
// CLIENT CONNECTION FUNCTIONS // // CLIENT CONNECTION FUNCTIONS //
public Action:OnClientPreAdminCheck(client) public Action OnClientPreAdminCheck(int client)
{ {
if (!DB || GetUserAdmin(client) != INVALID_ADMIN_ID) if (!DB || GetUserAdmin(client) != INVALID_ADMIN_ID)
return Plugin_Continue; return Plugin_Continue;
@@ -334,7 +310,7 @@ public Action:OnClientPreAdminCheck(client)
return curLoading > 0 ? Plugin_Handled : Plugin_Continue; return curLoading > 0 ? Plugin_Handled : Plugin_Continue;
} }
public OnClientDisconnect(client) public OnClientDisconnect(int client)
{ {
if (PlayerRecheck[client] != INVALID_HANDLE) if (PlayerRecheck[client] != INVALID_HANDLE)
{ {
@@ -344,13 +320,13 @@ public OnClientDisconnect(client)
g_ownReasons[client] = false; g_ownReasons[client] = false;
} }
public bool:OnClientConnect(client, String:rejectmsg[], maxlen) public bool OnClientConnect(int client, char[] rejectmsg, int maxlen)
{ {
PlayerStatus[client] = false; PlayerStatus[client] = false;
return true; return true;
} }
public OnClientAuthorized(client, const String:auth[]) public void OnClientAuthorized(int client, const char[] auth)
{ {
/* Do not check bots nor check player with lan steamid. */ /* Do not check bots nor check player with lan steamid. */
if (auth[0] == 'B' || auth[9] == 'L' || DB == INVALID_HANDLE) if (auth[0] == 'B' || auth[9] == 'L' || DB == INVALID_HANDLE)
@@ -359,17 +335,20 @@ public OnClientAuthorized(client, const String:auth[])
return; return;
} }
decl String:Query[256], String:ip[30]; char Query[256], ip[30];
GetClientIP(client, ip, sizeof(ip)); GetClientIP(client, ip, sizeof(ip));
FormatEx(Query, sizeof(Query), "SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, auth[8], ip);
FormatEx(Query, sizeof(Query), "SELECT bid, ip FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, auth[8], ip);
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "Checking ban for: %s", auth); LogToFile(logFile, "Checking ban for: %s", auth);
#endif #endif
SQL_TQuery(DB, VerifyBan, Query, GetClientUserId(client), DBPrio_High); DB.Query(VerifyBan, Query, GetClientUserId(client), DBPrio_High);
} }
public OnRebuildAdminCache(AdminCachePart:part) public void OnRebuildAdminCache(AdminCachePart part)
{ {
loadPart = part; loadPart = part;
switch (loadPart) switch (loadPart)
@@ -384,23 +363,23 @@ public OnRebuildAdminCache(AdminCachePart:part)
if (DB == INVALID_HANDLE) { if (DB == INVALID_HANDLE) {
if (!g_bConnecting) { if (!g_bConnecting) {
g_bConnecting = true; g_bConnecting = true;
SQL_TConnect(GotDatabase, "sourcebans"); Database.Connect(GotDatabase, "sourcebans");
} }
} }
else { else {
GotDatabase(DB, DB, "", 0); GotDatabase(DB, "", 0);
} }
} }
// COMMAND CODE // // COMMAND CODE //
public Action:ChatHook(client, args) public Action ChatHook(int client, int args)
{ {
// is this player preparing to ban someone // is this player preparing to ban someone
if (g_ownReasons[client]) if (g_ownReasons[client])
{ {
// get the reason // get the reason
new String:reason[512]; char reason[512];
GetCmdArgString(reason, sizeof(reason)); GetCmdArgString(reason, sizeof(reason));
StripQuotes(reason); StripQuotes(reason);
@@ -421,13 +400,13 @@ public Action:ChatHook(client, args)
return Plugin_Continue; return Plugin_Continue;
} }
public Action:_CmdReload(client, args) public Action _CmdReload(int client, int args)
{ {
ResetSettings(); ResetSettings();
return Plugin_Handled; return Plugin_Handled;
} }
public Action:CommandBan(client, args) public Action CommandBan(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@@ -436,12 +415,15 @@ public Action:CommandBan(client, args)
} }
// This is mainly for me sanity since client used to be called admin and target used to be called client // This is mainly for me sanity since client used to be called admin and target used to be called client
new admin = client; int admin = client;
// Get the target, find target returns a message on failure so we do not // Get the target, find target returns a message on failure so we do not
decl String:buffer[100]; char buffer[100];
GetCmdArg(1, buffer, sizeof(buffer)); GetCmdArg(1, buffer, sizeof(buffer));
new target = FindTarget(client, buffer, true);
int target = FindTarget(client, buffer, true);
if (target == -1) if (target == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
@@ -449,7 +431,9 @@ public Action:CommandBan(client, args)
// Get the ban time // Get the ban time
GetCmdArg(2, buffer, sizeof(buffer)); GetCmdArg(2, buffer, sizeof(buffer));
new time = StringToInt(buffer);
int time = StringToInt(buffer);
if (!time && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT))) if (!time && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)))
{ {
ReplyToCommand(client, "You do not have Perm Ban Permission"); ReplyToCommand(client, "You do not have Perm Ban Permission");
@@ -457,7 +441,8 @@ public Action:CommandBan(client, args)
} }
// Get the reason // Get the reason
new String:reason[128]; char reason[128];
if (args >= 3) if (args >= 3)
{ {
GetCmdArg(3, reason, sizeof(reason)); GetCmdArg(3, reason, sizeof(reason));
@@ -487,7 +472,7 @@ public Action:CommandBan(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
public Action:CommandBanIp(client, args) public Action CommandBanIp(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@@ -495,9 +480,8 @@ public Action:CommandBanIp(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
decl len, next_len; int len, next_len;
decl String:Arguments[256]; char Arguments[256], arg[50], time[20];
decl String:arg[50], String:time[20];
GetCmdArgString(Arguments, sizeof(Arguments)); GetCmdArgString(Arguments, sizeof(Arguments));
len = BreakString(Arguments, arg, sizeof(arg)); len = BreakString(Arguments, arg, sizeof(arg));
@@ -512,9 +496,11 @@ public Action:CommandBanIp(client, args)
Arguments[0] = '\0'; Arguments[0] = '\0';
} }
decl String:target_name[MAX_TARGET_LENGTH]; char target_name[MAX_TARGET_LENGTH];
decl target_list[1], bool:tn_is_ml; int target_list[1];
new target = -1; bool tn_is_ml;
int target = -1;
if (ProcessTargetString( if (ProcessTargetString(
arg, arg,
@@ -532,8 +518,10 @@ public Action:CommandBanIp(client, args)
GetClientIP(target, arg, sizeof(arg)); GetClientIP(target, arg, sizeof(arg));
} }
decl String:adminIp[24], String:adminAuth[64]; char adminIp[24], adminAuth[64];
new minutes = StringToInt(time);
int minutes = StringToInt(time);
if (!minutes && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT))) if (!minutes && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)))
{ {
ReplyToCommand(client, "You do not have Perm Ban Permission"); ReplyToCommand(client, "You do not have Perm Ban Permission");
@@ -550,23 +538,25 @@ public Action:CommandBanIp(client, args)
} }
// Pack everything into a data pack so we can retain it // Pack everything into a data pack so we can retain it
new Handle:dataPack = CreateDataPack(); DataPack dataPack = new DataPack();
WritePackCell(dataPack, client); dataPack.WriteCell(client);
WritePackCell(dataPack, minutes); dataPack.WriteCell(minutes);
WritePackString(dataPack, Arguments[len]); dataPack.WriteString(Arguments[len]);
WritePackString(dataPack, arg); dataPack.WriteString(arg);
WritePackString(dataPack, adminAuth); dataPack.WriteString(adminAuth);
WritePackString(dataPack, adminIp); dataPack.WriteString(adminIp);
decl String:Query[256]; char sQuery[256];
FormatEx(Query, sizeof(Query), "SELECT bid FROM %s_bans WHERE type = 1 AND ip = '%s' AND (length = 0 OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL",
FormatEx(sQuery, sizeof(sQuery), "SELECT bid FROM %s_bans WHERE type = 1 AND ip = '%s' AND (length = 0 OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL",
DatabasePrefix, arg); DatabasePrefix, arg);
SQL_TQuery(DB, SelectBanIpCallback, Query, dataPack, DBPrio_High); SQL_TQuery(DB, SelectBanIpCallback, sQuery, dataPack, DBPrio_High);
return Plugin_Handled; return Plugin_Handled;
} }
public Action:CommandUnban(client, args) public Action CommandUnban(int client, int args)
{ {
if (args < 1) if (args < 1)
{ {
@@ -581,7 +571,9 @@ public Action:CommandUnban(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
decl len, String:Arguments[256], String:arg[50], String:adminAuth[64]; int len;
char Arguments[256], arg[50], adminAuth[64];
GetCmdArgString(Arguments, sizeof(Arguments)); GetCmdArgString(Arguments, sizeof(Arguments));
if ((len = BreakString(Arguments, arg, sizeof(arg))) == -1) if ((len = BreakString(Arguments, arg, sizeof(arg))) == -1)
@@ -598,24 +590,27 @@ public Action:CommandUnban(client, args)
} }
// Pack everything into a data pack so we can retain it // Pack everything into a data pack so we can retain it
new Handle:dataPack = CreateDataPack(); DataPack dataPack = new DataPack();
WritePackCell(dataPack, client); dataPack.WriteCell(client);
WritePackString(dataPack, Arguments[len]); dataPack.WriteString(Arguments[len]);
WritePackString(dataPack, arg); dataPack.WriteString(arg);
WritePackString(dataPack, adminAuth); dataPack.WriteString(adminAuth);
char query[200];
decl String:query[200];
if (strncmp(arg, "STEAM_", 6) == 0) if (strncmp(arg, "STEAM_", 6) == 0)
{ {
Format(query, sizeof(query), "SELECT bid FROM %s_bans WHERE (type = 0 AND authid = '%s') AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, arg); Format(query, sizeof(query), "SELECT bid FROM %s_bans WHERE (type = 0 AND authid = '%s') AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, arg);
} else { } else {
Format(query, sizeof(query), "SELECT bid FROM %s_bans WHERE (type = 1 AND ip = '%s') AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, arg); Format(query, sizeof(query), "SELECT bid FROM %s_bans WHERE (type = 1 AND ip = '%s') AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, arg);
} }
SQL_TQuery(DB, SelectUnbanCallback, query, dataPack); SQL_TQuery(DB, SelectUnbanCallback, query, dataPack);
return Plugin_Handled; return Plugin_Handled;
} }
public Action:CommandAddBan(client, args) public Action CommandAddBan(int client, int args)
{ {
if (args < 2) if (args < 2)
{ {
@@ -630,10 +625,11 @@ public Action:CommandAddBan(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
decl String:arg_string[256], String:time[50], String:authid[50]; char arg_string[256], time[50], authid[50];
GetCmdArgString(arg_string, sizeof(arg_string)); GetCmdArgString(arg_string, sizeof(arg_string));
new len, total_len; int len, total_len;
/* Get time */ /* Get time */
if ((len = BreakString(arg_string, time, sizeof(time))) == -1) if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
@@ -654,8 +650,10 @@ public Action:CommandAddBan(client, args)
arg_string[0] = '\0'; arg_string[0] = '\0';
} }
decl String:adminIp[24], String:adminAuth[64]; char adminIp[24], adminAuth[64];
new minutes = StringToInt(time);
int minutes = StringToInt(time);
if (!minutes && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT))) if (!minutes && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)))
{ {
ReplyToCommand(client, "You do not have Perm Ban Permission"); ReplyToCommand(client, "You do not have Perm Ban Permission");
@@ -672,23 +670,25 @@ public Action:CommandAddBan(client, args)
} }
// Pack everything into a data pack so we can retain it // Pack everything into a data pack so we can retain it
new Handle:dataPack = CreateDataPack(); DataPack dataPack = new DataPack();
WritePackCell(dataPack, client); dataPack.WriteCell(client);
WritePackCell(dataPack, minutes); dataPack.WriteCell(minutes);
WritePackString(dataPack, arg_string[total_len]); dataPack.WriteString(arg_string[total_len]);
WritePackString(dataPack, authid); dataPack.WriteString(authid);
WritePackString(dataPack, adminAuth); dataPack.WriteString(adminAuth);
WritePackString(dataPack, adminIp); dataPack.WriteString(adminIp);
decl String:Query[256]; char sQuery[256];
FormatEx(Query, sizeof(Query), "SELECT bid FROM %s_bans WHERE type = 0 AND authid = '%s' AND (length = 0 OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL",
FormatEx(sQuery, sizeof sQuery, "SELECT bid FROM %s_bans WHERE type = 0 AND authid = '%s' AND (length = 0 OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL",
DatabasePrefix, authid); DatabasePrefix, authid);
SQL_TQuery(DB, SelectAddbanCallback, Query, dataPack, DBPrio_High); SQL_TQuery(DB, SelectAddbanCallback, sQuery, dataPack, DBPrio_High);
return Plugin_Handled; return Plugin_Handled;
} }
public Action:sm_rehash(args) public Action sm_rehash(int args)
{ {
if (enableAdmins) if (enableAdmins)
DumpAdminCache(AdminCache_Groups, true); DumpAdminCache(AdminCache_Groups, true);
@@ -700,7 +700,7 @@ public Action:sm_rehash(args)
// MENU CODE // // MENU CODE //
public OnAdminMenuReady(Handle:topmenu) public void OnAdminMenuReady(Handle topmenu)
{ {
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "OnAdminMenuReady()"); LogToFile(logFile, "OnAdminMenuReady()");
@@ -716,20 +716,20 @@ public OnAdminMenuReady(Handle:topmenu)
hTopMenu = topmenu; hTopMenu = topmenu;
/* Find the "Player Commands" category */ /* Find the "Player Commands" category */
new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS); TopMenuObject player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
if (player_commands != INVALID_TOPMENUOBJECT) if (player_commands != INVALID_TOPMENUOBJECT)
{ {
// just to avoid "unused variable 'res'" warning // just to avoid "unused variable 'res'" warning
#if defined DEBUG #if defined DEBUG
new TopMenuObject:res = AddToTopMenu(hTopMenu, TopMenuObject res = AddToTopMenu(hTopMenu,
"sm_ban", // Name "sm_ban", // Name
TopMenuObject_Item, // We are a submenu TopMenuObject_Item, // We are a submenu
AdminMenu_Ban, // Handler function AdminMenu_Ban, // Handler function
player_commands, // We are a submenu of Player Commands player_commands, // We are a submenu of Player Commands
"sm_ban", // The command to be finally called (Override checks) "sm_ban", // The command to be finally called (Override checks)
ADMFLAG_BAN); // What flag do we need to see the menu option ADMFLAG_BAN); // What flag do we need to see the menu option
decl String:temp[125]; char temp[125];
Format(temp, 125, "Result of AddToTopMenu: %d", res); Format(temp, 125, "Result of AddToTopMenu: %d", res);
LogToFile(logFile, temp); LogToFile(logFile, temp);
LogToFile(logFile, "Added Ban option to admin menu"); LogToFile(logFile, "Added Ban option to admin menu");
@@ -745,12 +745,12 @@ public OnAdminMenuReady(Handle:topmenu)
} }
} }
public AdminMenu_Ban(Handle:topmenu, public void AdminMenu_Ban(Handle topmenu,
TopMenuAction:action, // Action being performed TopMenuAction action, // Action being performed
TopMenuObject:object_id, // The object ID (if used) TopMenuObject object_id, // The object ID (if used)
param, // client idx of admin who chose the option (if used) int param, // client idx of admin who chose the option (if used)
String:buffer[], // Output buffer (if used) char[] buffer, // Output buffer (if used)
maxlength) // Output buffer (if used) int maxlength) // Output buffer (if used)
{ {
/* Clear the Ownreason bool, so he is able to chat again;) */ /* Clear the Ownreason bool, so he is able to chat again;) */
g_ownReasons[param] = false; g_ownReasons[param] = false;
@@ -764,7 +764,7 @@ public AdminMenu_Ban(Handle:topmenu,
// We are only being displayed, We only need to show the option name // We are only being displayed, We only need to show the option name
case TopMenuAction_DisplayOption: case TopMenuAction_DisplayOption:
{ {
Format(buffer, maxlength, "%T", "Ban player", param); FormatEx(buffer, maxlength, "%T", "Ban player", param);
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "AdminMenu_Ban() -> Formatted the Ban option text"); LogToFile(logFile, "AdminMenu_Ban() -> Formatted the Ban option text");
@@ -782,13 +782,14 @@ public AdminMenu_Ban(Handle:topmenu,
} }
} }
public ReasonSelected(Handle:menu, MenuAction:action, param1, param2) public int ReasonSelected(Handle menu, MenuAction action, int param1, int param2)
{ {
switch (action) switch (action)
{ {
case MenuAction_Select: case MenuAction_Select:
{ {
decl String:info[128], String:key[128]; char info[128], key[128];
GetMenuItem(menu, param2, key, sizeof(key), _, info, sizeof(info)); GetMenuItem(menu, param2, key, sizeof(key), _, info, sizeof(info));
if (StrEqual("Hacking", key)) if (StrEqual("Hacking", key))
@@ -827,13 +828,14 @@ public ReasonSelected(Handle:menu, MenuAction:action, param1, param2)
} }
} }
public HackingSelected(Handle:menu, MenuAction:action, param1, param2) public int HackingSelected(Handle menu, MenuAction action, int param1, int param2)
{ {
switch (action) switch (action)
{ {
case MenuAction_Select: case MenuAction_Select:
{ {
decl String:info[128], String:key[128]; char info[128], key[128];
GetMenuItem(menu, param2, key, sizeof(key), _, info, sizeof(info)); GetMenuItem(menu, param2, key, sizeof(key), _, info, sizeof(info));
if (g_BanTarget[param1] != -1 && g_BanTime[param1] != -1) if (g_BanTarget[param1] != -1 && g_BanTime[param1] != -1)
@@ -844,16 +846,17 @@ public HackingSelected(Handle:menu, MenuAction:action, param1, param2)
{ {
if (param2 == MenuCancel_Disconnected) if (param2 == MenuCancel_Disconnected)
{ {
new Handle:Pack = PlayerDataPack[param1]; DataPack Pack = view_as<DataPack>(PlayerDataPack[param1]);
if (Pack != INVALID_HANDLE) if (Pack != INVALID_HANDLE)
{ {
ReadPackCell(Pack); // admin index Pack.ReadCell(); // admin index
ReadPackCell(Pack); // target index Pack.ReadCell(); // target index
ReadPackCell(Pack); // admin userid Pack.ReadCell(); // admin userid
ReadPackCell(Pack); // target userid Pack.ReadCell(); // target userid
ReadPackCell(Pack); // time Pack.ReadCell(); // time
new Handle:ReasonPack = Handle:ReadPackCell(Pack);
DataPack ReasonPack = Pack.ReadCell();
if (ReasonPack != INVALID_HANDLE) if (ReasonPack != INVALID_HANDLE)
{ {
@@ -873,7 +876,7 @@ public HackingSelected(Handle:menu, MenuAction:action, param1, param2)
} }
} }
public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2) public int MenuHandler_BanPlayerList(Handle menu, MenuAction action, int param1, int param2)
{ {
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "MenuHandler_BanPlayerList()"); LogToFile(logFile, "MenuHandler_BanPlayerList()");
@@ -896,8 +899,8 @@ public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
case MenuAction_Select: case MenuAction_Select:
{ {
decl String:info[32], String:name[32]; char info[32], name[32];
new userid, target; int userid, target;
GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name)); GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
userid = StringToInt(info); userid = StringToInt(info);
@@ -919,7 +922,7 @@ public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
} }
} }
public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2) public int MenuHandler_BanTimeList(Handle menu, MenuAction action, int param1, int param2)
{ {
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "MenuHandler_BanTimeList()"); LogToFile(logFile, "MenuHandler_BanTimeList()");
@@ -927,11 +930,6 @@ public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
switch (action) switch (action)
{ {
case MenuAction_End:
{
CloseHandle(menu);
}
case MenuAction_Cancel: case MenuAction_Cancel:
{ {
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE) if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
@@ -942,7 +940,7 @@ public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
case MenuAction_Select: case MenuAction_Select:
{ {
decl String:info[32]; char info[32];
GetMenuItem(menu, param2, info, sizeof(info)); GetMenuItem(menu, param2, info, sizeof(info));
g_BanTime[param1] = StringToInt(info); g_BanTime[param1] = StringToInt(info);
@@ -950,20 +948,32 @@ public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
//DisplayBanReasonMenu(param1); //DisplayBanReasonMenu(param1);
DisplayMenu(ReasonMenuHandle, param1, MENU_TIME_FOREVER); DisplayMenu(ReasonMenuHandle, param1, MENU_TIME_FOREVER);
} }
case MenuAction_DrawItem:
{
char time[16];
GetMenuItem(menu, param2, time, sizeof(time));
return (StringToInt(time) > 0 || CheckCommandAccess(param1, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
}
} }
return 0;
} }
stock DisplayBanTargetMenu(client) stock void DisplayBanTargetMenu(int client)
{ {
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "DisplayBanTargetMenu()"); LogToFile(logFile, "DisplayBanTargetMenu()");
#endif #endif
new Handle:menu = CreateMenu(MenuHandler_BanPlayerList); // Create a new menu, pass it the handler.
decl String:title[100]; Handle menu = CreateMenu(MenuHandler_BanPlayerList); // Create a new menu, pass it the handler.
Format(title, sizeof(title), "%T:", "Ban player", client);
char title[100];
FormatEx(title, sizeof(title), "%T:", "Ban player", client);
//Format(title, sizeof(title), "Ban player", client); // Create the title of the menu
SetMenuTitle(menu, title); // Set the title SetMenuTitle(menu, title); // Set the title
SetMenuExitBackButton(menu, true); // Yes we want back/exit SetMenuExitBackButton(menu, true); // Yes we want back/exit
@@ -975,75 +985,44 @@ stock DisplayBanTargetMenu(client)
DisplayMenu(menu, client, MENU_TIME_FOREVER); // Show the menu to the client FOREVER! DisplayMenu(menu, client, MENU_TIME_FOREVER); // Show the menu to the client FOREVER!
} }
stock DisplayBanTimeMenu(client) stock void DisplayBanTimeMenu(int client)
{ {
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "DisplayBanTimeMenu()"); LogToFile(logFile, "DisplayBanTimeMenu()");
#endif #endif
new Handle:menu; char title[100];
if(g_bLimitBan && LimitBan_GetSize() > 0){ FormatEx(title, sizeof(title), "%T:", "Ban player", client);
menu = CreateMenu(MenuHandler_BanTimeList, MenuAction_Select | MenuAction_Cancel | MenuAction_DrawItem); SetMenuTitle(TimeMenuHandle, title);
} else {
menu = CreateMenu(MenuHandler_BanTimeList, MenuAction_Select | MenuAction_Cancel | MenuAction_DrawItem);
}
decl String:title[100]; DisplayMenu(TimeMenuHandle, client, MENU_TIME_FOREVER);
Format(title, sizeof(title), "%T:", "Ban player", client);
//Format(title, sizeof(title), "Ban player", client);
SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true);
if(g_bLimitBan && LimitBan_GetSize() > 0)
{
char _sDisplay[64];
char _sLength[32];
for(int i = 0; i <= LimitBan_GetSize(); i++)
{
if(LimitBan_GetAccess(i, client))
{
int _iLength = LimitBan_GetLength(i);
IntToString(_iLength, _sLength, sizeof(_sLength));
LimitBan_GetDisplay(i, _sDisplay);
AddMenuItem(menu, _sLength, _sDisplay);
}
}
if(LimitBan_GetAccess(-1, client) && CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN|ADMFLAG_ROOT))
{
LimitBan_GetDisplay(-1, _sDisplay);
AddMenuItem(menu, "0", _sDisplay);
}
} else {
if (CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)){
AddMenuItem(menu, "0", "Permanent");
AddMenuItem(menu, "10", "10 Minutes");
AddMenuItem(menu, "30", "30 Minutes");
AddMenuItem(menu, "60", "1 Hour");
AddMenuItem(menu, "240", "4 Hours");
AddMenuItem(menu, "1440", "1 Day");
AddMenuItem(menu, "10080", "1 Week");
}
}
DisplayMenu(menu, client, MENU_TIME_FOREVER);
} }
stock ResetMenu() stock void ResetMenu()
{ {
if (TimeMenuHandle != INVALID_HANDLE)
{
RemoveAllMenuItems(TimeMenuHandle);
}
if (ReasonMenuHandle != INVALID_HANDLE) if (ReasonMenuHandle != INVALID_HANDLE)
{ {
RemoveAllMenuItems(ReasonMenuHandle); RemoveAllMenuItems(ReasonMenuHandle);
} }
if (HackingMenuHandle != INVALID_HANDLE)
{
RemoveAllMenuItems(HackingMenuHandle);
}
} }
// QUERY CALL BACKS // // QUERY CALL BACKS //
public GotDatabase(Handle:owner, Handle:hndl, const String:error[], any:data) public void GotDatabase(Database db, const char[] error, any data)
{ {
if (hndl == INVALID_HANDLE) if (db == INVALID_HANDLE)
{ {
LogToFile(logFile, "Database failure: %s. See FAQ: https://sbpp.sarabveer.me/faq/", error); LogToFile(logFile, "Database failure: %s. See Docs: https://sbpp.github.io/docs/", error);
g_bConnecting = false; g_bConnecting = false;
// Parse the overrides backup! // Parse the overrides backup!
@@ -1051,9 +1030,10 @@ public GotDatabase(Handle:owner, Handle:hndl, const String:error[], any:data)
return; return;
} }
DB = hndl; DB = db;
char query[1024];
decl String:query[1024];
SQL_SetCharset(DB, "utf8"); SQL_SetCharset(DB, "utf8");
InsertServerInfo(); InsertServerInfo();
@@ -1082,7 +1062,7 @@ public GotDatabase(Handle:owner, Handle:hndl, const String:error[], any:data)
if (loadAdmins && enableAdmins) if (loadAdmins && enableAdmins)
{ {
new String:queryLastLogin[50] = ""; char queryLastLogin[50] = "";
if (requireSiteLogin) if (requireSiteLogin)
queryLastLogin = "lastvisit IS NOT NULL AND lastvisit != '' AND"; queryLastLogin = "lastvisit IS NOT NULL AND lastvisit != '' AND";
@@ -1117,7 +1097,7 @@ public GotDatabase(Handle:owner, Handle:hndl, const String:error[], any:data)
g_bConnecting = false; g_bConnecting = false;
} }
public VerifyInsert(Handle:owner, Handle:hndl, const String:error[], any:dataPack) public VerifyInsert(Handle:owner, Handle:hndl, const String:error[], DataPack dataPack)
{ {
if (dataPack == INVALID_HANDLE) if (dataPack == INVALID_HANDLE)
{ {
@@ -1128,48 +1108,50 @@ public VerifyInsert(Handle:owner, Handle:hndl, const String:error[], any:dataPac
if (hndl == INVALID_HANDLE || error[0]) if (hndl == INVALID_HANDLE || error[0])
{ {
LogToFile(logFile, "Verify Insert Query Failed: %s", error); LogToFile(logFile, "Verify Insert Query Failed: %s", error);
new admin = ReadPackCell(dataPack);
ReadPackCell(dataPack); // target int admin = dataPack.ReadCell();
ReadPackCell(dataPack); // admin userid dataPack.ReadCell(); // target
ReadPackCell(dataPack); // target userid dataPack.ReadCell(); // admin userid
new time = ReadPackCell(dataPack); dataPack.ReadCell(); // target userid
new Handle:reasonPack = Handle:ReadPackCell(dataPack); int time = dataPack.ReadCell();
new String:reason[128];
ReadPackString(reasonPack, reason, sizeof(reason)); DataPack reasonPack = dataPack.ReadCell();
decl String:name[50];
ReadPackString(dataPack, name, sizeof(name)); char reason[128], name[50], auth[30], ip[20], adminAuth[30], adminIp[20];
decl String:auth[30];
ReadPackString(dataPack, auth, sizeof(auth)); reasonPack.ReadString(reason, sizeof reason);
decl String:ip[20];
ReadPackString(dataPack, ip, sizeof(ip)); dataPack.ReadString(name, sizeof name);
decl String:adminAuth[30]; dataPack.ReadString(auth, sizeof auth);
ReadPackString(dataPack, adminAuth, sizeof(adminAuth)); dataPack.ReadString(ip, sizeof ip);
decl String:adminIp[20]; dataPack.ReadString(adminAuth, sizeof adminAuth);
ReadPackString(dataPack, adminIp, sizeof(adminIp)); dataPack.ReadString(adminIp, sizeof adminIp);
ResetPack(dataPack);
ResetPack(reasonPack); dataPack.Reset();
reasonPack.Reset();
PlayerDataPack[admin] = INVALID_HANDLE; PlayerDataPack[admin] = INVALID_HANDLE;
UTIL_InsertTempBan(time, name, auth, ip, reason, adminAuth, adminIp, Handle:dataPack); UTIL_InsertTempBan(time, name, auth, ip, reason, adminAuth, adminIp, dataPack);
return; return;
} }
new admin = ReadPackCell(dataPack); int admin = dataPack.ReadCell();
new client = ReadPackCell(dataPack); int client = dataPack.ReadCell();
if (!IsClientConnected(client) || IsFakeClient(client)) if (!IsClientConnected(client) || IsFakeClient(client))
return; return;
ReadPackCell(dataPack); // admin userid dataPack.ReadCell(); // admin userid
new UserId = ReadPackCell(dataPack);
new time = ReadPackCell(dataPack);
new Handle:ReasonPack = Handle:ReadPackCell(dataPack);
decl String:Name[64]; int UserId = dataPack.ReadCell();
new String:Reason[128]; int time = dataPack.ReadCell();
ReadPackString(dataPack, Name, sizeof(Name)); DataPack ReasonPack = dataPack.ReadCell();
ReadPackString(ReasonPack, Reason, sizeof(Reason));
char Name[64], Reason[128];
dataPack.ReadString(Name, sizeof(Name));
ReasonPack.ReadString(Reason, sizeof(Reason));
if (!time) if (!time)
{ {
@@ -1575,33 +1557,51 @@ public ErrorCheckCallback(Handle:owner, Handle:hndle, const String:error[], any:
} }
} }
public VerifyBan(Handle:owner, Handle:hndl, const String:error[], any:userid) public void VerifyBan(Database db, DBResultSet results, const char[] error, int userid)
{ {
decl String:clientName[64]; char clientName[64], clientAuth[64], clientIp[64];
decl String:clientAuth[64];
decl String:clientIp[64]; int client = GetClientOfUserId(userid);
new client = GetClientOfUserId(userid);
if (!client) if (!client)
return; return;
/* Failure happen. Do retry with delay */ /* Failure happen. Do retry with delay */
if (hndl == INVALID_HANDLE) if (results == null)
{ {
LogToFile(logFile, "Verify Ban Query Failed: %s", error); LogToFile(logFile, "Verify Ban Query Failed: %s", error);
PlayerRecheck[client] = CreateTimer(RetryTime, ClientRecheck, client); PlayerRecheck[client] = CreateTimer(RetryTime, ClientRecheck, client);
return; return;
} }
GetClientIP(client, clientIp, sizeof(clientIp)); GetClientIP(client, clientIp, sizeof(clientIp));
GetClientAuthId(client, AuthId_Steam2, clientAuth, sizeof(clientAuth)); GetClientAuthId(client, AuthId_Steam2, clientAuth, sizeof(clientAuth));
GetClientName(client, clientName, sizeof(clientName)); GetClientName(client, clientName, sizeof(clientName));
if (SQL_GetRowCount(hndl) > 0)
{
decl String:buffer[40];
decl String:Name[128];
decl String:Query[512];
SQL_EscapeString(DB, clientName, Name, sizeof(Name)); if (results.RowCount > 0)
{
char buffer[40], Name[128], Query[512];
// Amending to ban record's IP field
if (results.FetchRow())
{
char sIP[32];
int iBid = results.FetchInt(0);
results.FetchString(1, sIP, sizeof sIP);
if (StrEqual(sIP, ""))
{
char sQuery[256];
FormatEx(sQuery, sizeof sQuery, "UPDATE %s_bans SET `ip` = '%s' WHERE `bid` = '%d'", DatabasePrefix, clientIp, iBid);
DB.Query(SQL_OnIPMend, sQuery, client);
}
}
DB.Escape(clientName, Name, sizeof Name);
if (serverID == -1) if (serverID == -1)
{ {
FormatEx(Query, sizeof(Query), "INSERT INTO %s_banlog (sid ,time ,name ,bid) VALUES \ FormatEx(Query, sizeof(Query), "INSERT INTO %s_banlog (sid ,time ,name ,bid) VALUES \
@@ -1618,11 +1618,14 @@ public VerifyBan(Handle:owner, Handle:hndl, const String:error[], any:userid)
} }
SQL_TQuery(DB, ErrorCheckCallback, Query, client, DBPrio_High); SQL_TQuery(DB, ErrorCheckCallback, Query, client, DBPrio_High);
FormatEx(buffer, sizeof(buffer), "banid 5 %s", clientAuth); FormatEx(buffer, sizeof(buffer), "banid 5 %s", clientAuth);
ServerCommand(buffer); ServerCommand(buffer);
KickClient(client, "%t", "Banned Check Site", WebsiteAddress); KickClient(client, "%t", "Banned Check Site", WebsiteAddress);
return; return;
} }
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "%s is NOT banned.", clientAuth); LogToFile(logFile, "%s is NOT banned.", clientAuth);
#endif #endif
@@ -1630,6 +1633,19 @@ public VerifyBan(Handle:owner, Handle:hndl, const String:error[], any:userid)
PlayerStatus[client] = true; PlayerStatus[client] = true;
} }
public void SQL_OnIPMend(Database db, DBResultSet results, const char[] error, int iClient)
{
if (results == null)
{
char sIP[32], sSteamID[32];
GetClientAuthId(iClient, AuthId_Steam3, sSteamID, sizeof sSteamID);
GetClientIP(iClient, sIP, sizeof sIP);
LogToFile(logFile, "Failed to mend IP address for %s (%s): %s", sSteamID, sIP, error);
}
}
public AdminsDone(Handle:owner, Handle:hndl, const String:error[], any:data) public AdminsDone(Handle:owner, Handle:hndl, const String:error[], any:data)
{ {
//SELECT authid, srv_password , srv_group, srv_flags, user //SELECT authid, srv_password , srv_group, srv_flags, user
@@ -2142,13 +2158,14 @@ public SMCResult:ReadConfig_NewSection(Handle:smc, const String:name[], bool:opt
{ {
if (name[0]) if (name[0])
{ {
if (strcmp("Config", name, false) == 0) if (strcmp("Config", name, false) == 0) {
{
ConfigState = ConfigStateConfig; ConfigState = ConfigStateConfig;
} else if (strcmp("BanReasons", name, false) == 0) { } else if (strcmp("BanReasons", name, false) == 0) {
ConfigState = ConfigStateReasons; ConfigState = ConfigStateReasons;
} else if (strcmp("HackingReasons", name, false) == 0) { } else if (strcmp("HackingReasons", name, false) == 0) {
ConfigState = ConfigStateHacking; ConfigState = ConfigStateHacking;
} else if (strcmp("BanTime", name, false) == 0) {
ConfigState = ConfigStateTime;
} }
} }
return SMCParse_Continue; return SMCParse_Continue;
@@ -2240,6 +2257,13 @@ public SMCResult:ReadConfig_KeyValue(Handle:smc, const String:key[], const Strin
AddMenuItem(HackingMenuHandle, key, value); AddMenuItem(HackingMenuHandle, key, value);
} }
} }
case ConfigStateTime:
{
if (StringToInt(key) > -1 && TimeMenuHandle != INVALID_HANDLE)
{
AddMenuItem(TimeMenuHandle, key, value);
}
}
} }
return SMCParse_Continue; return SMCParse_Continue;
} }
@@ -2258,12 +2282,12 @@ public SMCResult:ReadConfig_EndSection(Handle:smc)
* @param reason The reason to ban the player from the server * @param reason The reason to ban the player from the server
* @noreturn * @noreturn
*********************************************************/ *********************************************************/
public Native_SBBanPlayer(Handle:plugin, numParams) public Native_SBBanPlayer(Handle plugin, int numParams)
{ {
new client = GetNativeCell(1); int client = GetNativeCell(1);
new target = GetNativeCell(2); int target = GetNativeCell(2);
new time = GetNativeCell(3); int time = GetNativeCell(3);
new String:reason[128]; char reason[128];
GetNativeString(4, reason, 128); GetNativeString(4, reason, 128);
if (reason[0] == '\0') if (reason[0] == '\0')
@@ -2271,7 +2295,7 @@ public Native_SBBanPlayer(Handle:plugin, numParams)
if (client && IsClientInGame(client)) if (client && IsClientInGame(client))
{ {
new AdminId:aid = GetUserAdmin(client); AdminId aid = GetUserAdmin(client);
if (aid == INVALID_ADMIN_ID) if (aid == INVALID_ADMIN_ID)
{ {
ThrowNativeError(SP_ERROR_NATIVE, "Ban Error: Player is not an admin."); ThrowNativeError(SP_ERROR_NATIVE, "Ban Error: Player is not an admin.");
@@ -2289,12 +2313,91 @@ public Native_SBBanPlayer(Handle:plugin, numParams)
return true; return true;
} }
public int Native_SBReportPlayer(Handle plugin, int numParams)
{
if (numParams < 3)
{
ThrowNativeError(SP_ERROR_NATIVE, "Invalid amount of arguments. Received %d arguments", numParams);
return;
}
int iReporter = GetNativeCell(1)
, iTarget = GetNativeCell(2)
, iReasonLen;
int iTime = GetTime();
GetNativeStringLength(3, iReasonLen);
iReasonLen++;
char[] sReason = new char[iReasonLen];
GetNativeString(3, sReason, iReasonLen);
char sRAuth[32], sTAuth[32], sRName[MAX_NAME_LENGTH + 1], sTName[MAX_NAME_LENGTH + 1],
sRIP[16], sTIP[16], sREscapedName[MAX_NAME_LENGTH * 2 + 1], sTEscapedName[MAX_NAME_LENGTH * 2 + 1];
char[] sEscapedReason = new char[iReasonLen * 2 + 1];
GetClientAuthId(iReporter, AuthId_Steam2, sRAuth, sizeof sRAuth);
GetClientAuthId(iTarget, AuthId_Steam2, sTAuth, sizeof sTAuth);
GetClientName(iReporter, sRName, sizeof sRName);
GetClientName(iTarget, sTName, sizeof sTName);
GetClientIP(iReporter, sRIP, sizeof sRIP);
GetClientIP(iTarget, sTIP, sizeof sTIP);
DB.Escape(sRName, sREscapedName, sizeof sREscapedName);
DB.Escape(sTName, sTEscapedName, sizeof sTEscapedName);
DB.Escape(sReason, sEscapedReason, iReasonLen * 2 + 1);
char[] sQuery = new char[512 + (iReasonLen * 2 + 1)];
Format(sQuery, 512 + (iReasonLen * 2 + 1), "INSERT INTO %s_submissions (`submitted`, `modid`, `SteamId`, `name`, `email`, `reason`, `ip`, `subname`, `sip`, `archiv`, `server`)"
... "VALUES ('%d', 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0, 0)", DatabasePrefix, iTime, sTAuth, sTEscapedName, sRAuth, sEscapedReason, sRIP, sREscapedName, sTIP);
DataPack ForwardPack = new DataPack();
ForwardPack.WriteCell(iReporter);
ForwardPack.WriteCell(iTarget);
ForwardPack.WriteCell(iReasonLen);
ForwardPack.WriteString(sReason);
DB.Query(SQL_OnReportPlayer, sQuery, ForwardPack);
}
public void SQL_OnReportPlayer(Database db, DBResultSet results, const char[] error, DataPack ForwardPack)
{
if (results == null)
LogToFile(logFile, "Failed to submit report: %s", error);
else
{
ForwardPack.Reset();
int iReporter = ForwardPack.ReadCell();
int iTarget = ForwardPack.ReadCell();
int iReasonLen = ForwardPack.ReadCell();
char[] sReason = new char[iReasonLen];
ForwardPack.ReadString(sReason, iReasonLen);
Call_StartForward(g_hFwd_OnReportAdded);
Call_PushCell(iReporter);
Call_PushCell(iTarget);
Call_PushString(sReason);
Call_Finish();
}
}
// STOCK FUNCTIONS // // STOCK FUNCTIONS //
public InitializeBackupDB() public InitializeBackupDB()
{ {
decl String:error[255]; char error[255];
SQLiteDB = SQLite_UseDatabase("sourcebans-queue", error, sizeof(error)); SQLiteDB = SQLite_UseDatabase("sourcebans-queue", error, sizeof(error));
if (SQLiteDB == INVALID_HANDLE) if (SQLiteDB == INVALID_HANDLE)
SetFailState(error); SetFailState(error);
@@ -2304,10 +2407,10 @@ public InitializeBackupDB()
SQL_UnlockDatabase(SQLiteDB); SQL_UnlockDatabase(SQLiteDB);
} }
public bool:CreateBan(client, target, time, String:reason[]) public bool CreateBan(int client, int target, int time, const char[] reason)
{ {
decl String:adminIp[24], String:adminAuth[64]; char adminIp[24], adminAuth[64];
new admin = client; int admin = client;
// The server is the one calling the ban // The server is the one calling the ban
if (!admin) if (!admin)
@@ -2328,34 +2431,35 @@ public bool:CreateBan(client, target, time, String:reason[])
} }
// target information // target information
decl String:ip[24], String:auth[64], String:name[64]; char ip[24], auth[64], name[64];
GetClientName(target, name, sizeof(name)); GetClientName(target, name, sizeof(name));
GetClientIP(target, ip, sizeof(ip)); GetClientIP(target, ip, sizeof(ip));
if (!GetClientAuthId(target, AuthId_Steam2, auth, sizeof(auth))) if (!GetClientAuthId(target, AuthId_Steam2, auth, sizeof(auth)))
return false; return false;
new userid = admin ? GetClientUserId(admin) : 0; int userid = admin ? GetClientUserId(admin) : 0;
// Pack everything into a data pack so we can retain it // Pack everything into a data pack so we can retain it
new Handle:dataPack = CreateDataPack(); DataPack dataPack = new DataPack();
new Handle:reasonPack = CreateDataPack(); DataPack reasonPack = new DataPack();
WritePackString(reasonPack, reason); WritePackString(reasonPack, reason);
WritePackCell(dataPack, admin); dataPack.WriteCell(admin);
WritePackCell(dataPack, target); dataPack.WriteCell(target);
WritePackCell(dataPack, userid); dataPack.WriteCell(userid);
WritePackCell(dataPack, GetClientUserId(target)); dataPack.WriteCell(GetClientUserId(target));
WritePackCell(dataPack, time); dataPack.WriteCell(time);
WritePackCell(dataPack, _:reasonPack); dataPack.WriteCell( _:reasonPack);
WritePackString(dataPack, name); dataPack.WriteString(name);
WritePackString(dataPack, auth); dataPack.WriteString(auth);
WritePackString(dataPack, ip); dataPack.WriteString(ip);
WritePackString(dataPack, adminAuth); dataPack.WriteString(adminAuth);
WritePackString(dataPack, adminIp); dataPack.WriteString(adminIp);
ResetPack(dataPack); dataPack.Reset();
ResetPack(reasonPack); reasonPack.Reset();
if (reason[0] != '\0') if (reason[0] != '\0')
{ {
@@ -2408,34 +2512,40 @@ stock UTIL_InsertBan(time, const String:Name[], const String:Authid[], const Str
SQL_TQuery(DB, VerifyInsert, Query, Pack, DBPrio_High); SQL_TQuery(DB, VerifyInsert, Query, Pack, DBPrio_High);
} }
stock UTIL_InsertTempBan(time, const String:name[], const String:auth[], const String:ip[], const String:reason[], const String:adminAuth[], const String:adminIp[], Handle:dataPack) stock UTIL_InsertTempBan(int time, const char[] name, const char[] auth, const char[] ip, const char[] reason, const char[] adminAuth, const char[] adminIp, DataPack dataPack)
{ {
ReadPackCell(dataPack); // admin index dataPack.ReadCell(); // admin index
new client = ReadPackCell(dataPack);
ReadPackCell(dataPack); // admin userid int client = ReadPackCell(dataPack);
ReadPackCell(dataPack); // target userid
ReadPackCell(dataPack); // time dataPack.ReadCell(); // admin userid
new Handle:reasonPack = Handle:ReadPackCell(dataPack); dataPack.ReadCell(); // target userid
dataPack.ReadCell(); // time
DataPack reasonPack = view_as<DataPack>(dataPack.ReadCell());
if (reasonPack != INVALID_HANDLE) if (reasonPack != INVALID_HANDLE)
{
CloseHandle(reasonPack); CloseHandle(reasonPack);
}
CloseHandle(dataPack); CloseHandle(dataPack);
// we add a temporary ban and then add the record into the queue to be processed when the database is available // we add a temporary ban and then add the record into the queue to be processed when the database is available
decl String:buffer[50]; char buffer[50];
Format(buffer, sizeof(buffer), "banid %d %s", ProcessQueueTime, auth); Format(buffer, sizeof(buffer), "banid %d %s", ProcessQueueTime, auth);
ServerCommand(buffer); ServerCommand(buffer);
if (IsClientInGame(client)) if (IsClientInGame(client))
KickClient(client, "%t", "Banned Check Site", WebsiteAddress); KickClient(client, "%t", "Banned Check Site", WebsiteAddress);
decl String:banName[128]; char banName[128], banReason[256], query[512];
decl String:banReason[256];
decl String:query[512];
SQL_EscapeString(SQLiteDB, name, banName, sizeof(banName)); SQL_EscapeString(SQLiteDB, name, banName, sizeof(banName));
SQL_EscapeString(SQLiteDB, reason, banReason, sizeof(banReason)); SQL_EscapeString(SQLiteDB, reason, banReason, sizeof(banReason));
FormatEx(query, sizeof(query), "INSERT INTO queue VALUES ('%s', %i, %i, '%s', '%s', '%s', '%s', '%s')", FormatEx(query, sizeof(query), "INSERT INTO queue VALUES ('%s', %i, %i, '%s', '%s', '%s', '%s', '%s')",
auth, time, GetTime(), banReason, banName, ip, adminAuth, adminIp); auth, time, GetTime(), banReason, banName, ip, adminAuth, adminIp);
SQL_TQuery(SQLiteDB, ErrorCheckCallback, query); SQL_TQuery(SQLiteDB, ErrorCheckCallback, query);
} }
@@ -2453,35 +2563,36 @@ stock CheckLoadAdmins()
stock InsertServerInfo() stock InsertServerInfo()
{ {
if (DB == INVALID_HANDLE) if (DB == INVALID_HANDLE) {
{ return;
return; }
}
char query[100];
int pieces[4];
int longip = GetConVarInt(CvarHostIp);
decl String:query[100], pieces[4]; pieces[0] = (longip >> 24) & 0x000000FF;
new longip = GetConVarInt(CvarHostIp); pieces[1] = (longip >> 16) & 0x000000FF;
pieces[0] = (longip >> 24) & 0x000000FF; pieces[2] = (longip >> 8) & 0x000000FF;
pieces[1] = (longip >> 16) & 0x000000FF; pieces[3] = longip & 0x000000FF;
pieces[2] = (longip >> 8) & 0x000000FF;
pieces[3] = longip & 0x000000FF;
FormatEx(ServerIp, sizeof(ServerIp), "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
GetConVarString(CvarPort, ServerPort, sizeof(ServerPort));
if (AutoAdd != false) FormatEx(ServerIp, sizeof(ServerIp), "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
{ GetConVarString(CvarPort, ServerPort, sizeof(ServerPort));
FormatEx(query, sizeof(query), "SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s'", DatabasePrefix, ServerIp, ServerPort);
SQL_TQuery(DB, ServerInfoCallback, query); if (AutoAdd != false) {
} FormatEx(query, sizeof(query), "SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s'", DatabasePrefix, ServerIp, ServerPort);
SQL_TQuery(DB, ServerInfoCallback, query);
}
} }
stock PrepareBan(client, target, time, String:reason[], size) stock void PrepareBan(int client, int target, int time, char[] reason, int size)
{ {
#if defined DEBUG #if defined DEBUG
LogToFile(logFile, "PrepareBan()"); LogToFile(logFile, "PrepareBan()");
#endif #endif
if (!target || !IsClientInGame(target)) if (!target || !IsClientInGame(target))
return; return;
decl String:authid[64], String:name[32], String:bannedSite[512]; char authid[64], name[32], bannedSite[512];
if (!GetClientAuthId(target, AuthId_Steam2, authid, sizeof(authid))) if (!GetClientAuthId(target, AuthId_Steam2, authid, sizeof(authid)))
return; return;
GetClientName(target, name, sizeof(name)); GetClientName(target, name, sizeof(name));
@@ -2517,7 +2628,7 @@ stock PrepareBan(client, target, time, String:reason[], size)
g_BanTime[client] = -1; g_BanTime[client] = -1;
} }
stock ReadConfig() stock void ReadConfig()
{ {
InitializeConfigParser(); InitializeConfigParser();
@@ -2526,7 +2637,7 @@ stock ReadConfig()
return; return;
} }
decl String:ConfigFile[PLATFORM_MAX_PATH]; char ConfigFile[PLATFORM_MAX_PATH];
BuildPath(Path_SM, ConfigFile, sizeof(ConfigFile), "configs/sourcebans/sourcebans.cfg"); BuildPath(Path_SM, ConfigFile, sizeof(ConfigFile), "configs/sourcebans/sourcebans.cfg");
if (FileExists(ConfigFile)) if (FileExists(ConfigFile))
@@ -2534,14 +2645,14 @@ stock ReadConfig()
InternalReadConfig(ConfigFile); InternalReadConfig(ConfigFile);
PrintToServer("%sLoading configs/sourcebans.cfg config file", Prefix); PrintToServer("%sLoading configs/sourcebans.cfg config file", Prefix);
} else { } else {
decl String:Error[PLATFORM_MAX_PATH + 64]; char Error[PLATFORM_MAX_PATH + 64];
FormatEx(Error, sizeof(Error), "%sFATAL *** ERROR *** can not find %s", Prefix, ConfigFile); FormatEx(Error, sizeof(Error), "%sFATAL *** ERROR *** can not find %s", Prefix, ConfigFile);
LogToFile(logFile, "FATAL *** ERROR *** can not find %s", ConfigFile); LogToFile(logFile, "FATAL *** ERROR *** can not find %s", ConfigFile);
SetFailState(Error); SetFailState(Error);
} }
} }
stock ResetSettings() stock void ResetSettings()
{ {
CommandDisable = 0; CommandDisable = 0;
@@ -2549,17 +2660,19 @@ stock ResetSettings()
ReadConfig(); ReadConfig();
} }
stock ParseBackupConfig_Overrides() stock void ParseBackupConfig_Overrides()
{ {
new Handle:hKV = CreateKeyValues("SB_Overrides"); Handle hKV = CreateKeyValues("SB_Overrides");
if (!FileToKeyValues(hKV, overridesLoc)) if (!FileToKeyValues(hKV, overridesLoc))
return; return;
if (!KvGotoFirstSubKey(hKV)) if (!KvGotoFirstSubKey(hKV))
return; return;
decl String:sSection[16], String:sFlags[32], String:sName[64]; char sSection[16], sFlags[32], sName[64];
decl OverrideType:type; OverrideType type;
do do
{ {
KvGetSectionName(hKV, sSection, sizeof(sSection)); KvGetSectionName(hKV, sSection, sizeof(sSection));
@@ -2588,9 +2701,9 @@ stock ParseBackupConfig_Overrides()
CloseHandle(hKV); CloseHandle(hKV);
} }
stock AdminFlag:CreateFlagLetters() stock AdminFlag CreateFlagLetters()
{ {
new AdminFlag:FlagLetters[FLAG_LETTERS_SIZE]; AdminFlag FlagLetters[FLAG_LETTERS_SIZE];
FlagLetters['a'-'a'] = Admin_Reservation; FlagLetters['a'-'a'] = Admin_Reservation;
FlagLetters['b'-'a'] = Admin_Generic; FlagLetters['b'-'a'] = Admin_Generic;
@@ -2619,7 +2732,8 @@ stock AdminFlag:CreateFlagLetters()
stock AccountForLateLoading() stock AccountForLateLoading()
{ {
decl String:auth[30]; char auth[30];
for (new i = 1; i <= GetMaxClients(); i++) for (new i = 1; i <= GetMaxClients(); i++)
{ {
if (IsClientConnected(i) && !IsFakeClient(i)) if (IsClientConnected(i) && !IsFakeClient(i))