956 lines
31 KiB
SourcePawn
956 lines
31 KiB
SourcePawn
#pragma semicolon 1
|
|
|
|
#include <sourcemod>
|
|
#include <sdktools>
|
|
#include <sdkhooks>
|
|
#include <cstrike>
|
|
#include <multicolors>
|
|
#include <zombiereloaded>
|
|
|
|
//2026: add playtime requirements for being unrestricted
|
|
#include <unloze_playtime>
|
|
|
|
char g_sBanListFilePath[256];
|
|
|
|
Database g_hDatabase;
|
|
|
|
bool g_bKnifeBanned[MAXPLAYERS + 1];
|
|
bool g_bKnifeBan;
|
|
|
|
ArrayList g_TempBanned;
|
|
|
|
KeyValues Banlist;
|
|
|
|
int g_hActiveWeapon;
|
|
int g_iClientHours[MAXPLAYERS + 1];
|
|
int g_iClientMinutes[MAXPLAYERS + 1];
|
|
|
|
public Plugin myinfo =
|
|
{
|
|
name = "KnifeBan",
|
|
author = "Dogan",
|
|
description = "Tools to handle Zombie Knifers in ZE",
|
|
version = "2.0.0",
|
|
url = ""
|
|
}
|
|
|
|
public void OnPluginStart()
|
|
{
|
|
LoadTranslations("common.phrases");
|
|
|
|
ConVar cvar;
|
|
HookConVarChange((cvar = CreateConVar("sm_knifeban_block", "1", "1 = Knifebanned clients are blocked, 0 = Knifebanned clients are not blocked", FCVAR_NONE, true, 0.0, true, 1.0)), g_cvKnifeBan);
|
|
g_bKnifeBan = cvar.BoolValue;
|
|
delete cvar;
|
|
|
|
AutoExecConfig(true, "plugin.KnifeBan");
|
|
|
|
RegAdminCmd("sm_knifeban", Command_Knifeban, ADMFLAG_BAN, "Knifebans a client");
|
|
RegAdminCmd("sm_knifeunban", Command_Knifeunban, ADMFLAG_BAN, "Knifeunbans a client");
|
|
RegConsoleCmd("sm_knifestatus", Command_Knifestatus, "Returns the knifestatus of a client");
|
|
RegConsoleCmd("sm_knifebanlist", Command_Knifebanlist, "Returns the knifebanlist of all clients currently on the server");
|
|
|
|
g_hActiveWeapon = FindSendPropInfo("CBaseCombatCharacter", "m_hActiveWeapon");
|
|
if(g_hActiveWeapon == -1)
|
|
SetFailState("Couldnt find CBaseCombatCharacter::m_hActiveWeapon");
|
|
|
|
CreateTimer(5.0, CheckKnifeBans, _, TIMER_REPEAT);
|
|
CreateTimer(300.0, CheckKnifeBansFromWeb, _, TIMER_REPEAT); //check every 5 minutes if something new was done on webpannel
|
|
|
|
g_TempBanned = new ArrayList();
|
|
|
|
Banlist = new KeyValues("banlist");
|
|
BuildPath(Path_SM, g_sBanListFilePath, sizeof(g_sBanListFilePath), "configs/knifeban/banlist.cfg");
|
|
Banlist.ImportFromFile(g_sBanListFilePath);
|
|
if(!FileExists(g_sBanListFilePath))
|
|
SetFailState("[KnifeBan] Config file missing!");
|
|
|
|
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(IsClientInGame(i))
|
|
OnClientPostAdminCheck(i);
|
|
}
|
|
|
|
if (!g_hDatabase)
|
|
{
|
|
Database.Connect(SQL_OnDatabaseConnect, "unloze_knifeban_web");
|
|
}
|
|
}
|
|
|
|
public void OnMapStart()
|
|
{
|
|
if (!g_hDatabase)
|
|
{
|
|
Database.Connect(SQL_OnDatabaseConnect, "unloze_knifeban_web");
|
|
}
|
|
}
|
|
|
|
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
|
{
|
|
if(!db || strlen(error))
|
|
{
|
|
LogError("Database error: %s", error);
|
|
return;
|
|
}
|
|
g_hDatabase = db;
|
|
}
|
|
|
|
public void OnPluginEnd()
|
|
{
|
|
Banlist.Rewind();
|
|
if(!Banlist.ExportToFile(g_sBanListFilePath))
|
|
SetFailState("[KnifeBan] Config file missing!");
|
|
}
|
|
|
|
public void g_cvKnifeBan(ConVar convar, const char[] oldValue, const char[] newValue)
|
|
{
|
|
g_bKnifeBan = convar.BoolValue;
|
|
}
|
|
|
|
public void OnClientPutInServer(int client)
|
|
{
|
|
//now knifebanned people cant knife fakeclients forward.
|
|
if (IsFakeClient(client))
|
|
{
|
|
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
|
|
}
|
|
}
|
|
|
|
public void OnClientPostAdminCheck(int client)
|
|
{
|
|
//autism check
|
|
if (!IsFakeClient(client))
|
|
{
|
|
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
|
|
}
|
|
|
|
char sAuth[32];
|
|
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
|
|
|
|
Banlist.Rewind();
|
|
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
int length = Banlist.GetNum("duration");
|
|
int length_minutes = Banlist.GetNum("duration_minutes");
|
|
int time = Banlist.GetNum("time");
|
|
int time_minutes = Banlist.GetNum("time_minutes", 0);
|
|
|
|
if(length == -1)
|
|
g_bKnifeBanned[client] = true;
|
|
else if(length > 0 || length_minutes > 0)
|
|
CheckIfClientIsStillKnifeBanned(sAuth, client, time, time_minutes, length, length_minutes);
|
|
}
|
|
|
|
int accountid = GetSteamAccountID(client);
|
|
if(accountid != 0)
|
|
{
|
|
int index = g_TempBanned.FindValue(accountid);
|
|
if(index != -1)
|
|
g_bKnifeBanned[client] = true;
|
|
}
|
|
}
|
|
|
|
public void OnClientDisconnect(int client)
|
|
{
|
|
g_iClientHours[client] = 0;
|
|
g_iClientMinutes[client] = 0;
|
|
g_bKnifeBanned[client] = false;
|
|
}
|
|
|
|
public void OnMapEnd()
|
|
{
|
|
g_TempBanned.Clear();
|
|
}
|
|
|
|
public Action CheckKnifeBansFromWeb(Handle timer)
|
|
{
|
|
char sQuery[512];
|
|
Format(sQuery, sizeof(sQuery), "select client_steamid, web_addban_required, web_unban_required, web_ban_delete, web_edit_required, time_played_start, length, krcb.admin_name from `KbRestrict_CurrentBans` krcb where krcb.web_addban_required = 1 or krcb.web_unban_required = 1 or krcb.web_ban_delete = 1 or krcb.web_edit_required = 1");
|
|
g_hDatabase.Query(SQL_OnQueryCompletedWebKbans, sQuery);
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public void SQL_OnQueryCompletedWebKbans(Database db, DBResultSet results, const char[] error, int iSerial)
|
|
{
|
|
if (!db || strlen(error))
|
|
{
|
|
delete results;
|
|
LogError("Query error 3: %s", error);
|
|
return;
|
|
}
|
|
while (results.RowCount && results.FetchRow())
|
|
{
|
|
char sSID[64];
|
|
results.FetchString(0, sSID, sizeof(sSID));
|
|
int web_addban_required = results.FetchInt(1);
|
|
int web_unban_required = results.FetchInt(2);
|
|
int web_ban_delete = results.FetchInt(3);
|
|
int web_edit_required = results.FetchInt(4);
|
|
int time_played_start = results.FetchInt(5);
|
|
int length = results.FetchInt(6);
|
|
char admin_name[255];
|
|
results.FetchString(7, admin_name, sizeof(admin_name));
|
|
|
|
char sQuery[512];
|
|
if (web_addban_required)
|
|
{
|
|
file_addban(sSID, time_played_start, length, admin_name);
|
|
Format(sQuery, sizeof(sQuery), "update `KbRestrict_CurrentBans` set web_addban_required = 0 where client_steamid = '%s' and web_addban_required = 1", sSID);
|
|
g_hDatabase.Query(SQL_FinishedQuery, sQuery);
|
|
}
|
|
else if (web_unban_required)
|
|
{
|
|
file_unban(sSID);
|
|
Format(sQuery, sizeof(sQuery), "update `KbRestrict_CurrentBans` set web_unban_required = 0 where client_steamid = '%s' and web_unban_required = 1", sSID);
|
|
g_hDatabase.Query(SQL_FinishedQuery, sQuery);
|
|
}
|
|
else if (web_ban_delete)
|
|
{
|
|
file_unban(sSID);
|
|
Format(sQuery, sizeof(sQuery), "delete from `KbRestrict_CurrentBans` where client_steamid = '%s' and web_ban_delete = 1", sSID);
|
|
g_hDatabase.Query(SQL_FinishedQuery, sQuery);
|
|
}
|
|
else if (web_edit_required)
|
|
{
|
|
file_edit_ban(sSID, length);
|
|
Format(sQuery, sizeof(sQuery), "update `KbRestrict_CurrentBans` set web_edit_required = 0 where client_steamid = '%s' and web_edit_required = 1", sSID);
|
|
g_hDatabase.Query(SQL_FinishedQuery, sQuery);
|
|
}
|
|
}
|
|
delete results;
|
|
}
|
|
|
|
public void file_edit_ban(char sAuth[64], int length)
|
|
{
|
|
int length_hours = length / 60;
|
|
int length_minutes = length % 60;
|
|
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
Banlist.SetNum("duration", length_hours);
|
|
Banlist.SetNum("duration_minutes", length_minutes);
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
}
|
|
}
|
|
|
|
public void file_unban(char sAuth[64])
|
|
{
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
int history = Banlist.GetNum("history");
|
|
Banlist.SetNum("history", history - 1);
|
|
Banlist.SetNum("time", 0);
|
|
Banlist.SetNum("time_minutes", 0);
|
|
Banlist.SetNum("duration", 0);
|
|
Banlist.SetNum("duration_minutes", 0);
|
|
Banlist.SetString("admin", "");
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
}
|
|
}
|
|
|
|
public void file_addban(char sAuth[64], int time_played_start, int length, char sAdmin[255])
|
|
{
|
|
int time = time_played_start / 60;
|
|
int time_minutes = time_played_start & 60;
|
|
|
|
int length_hours = length / 60;
|
|
int length_minutes = length % 60;
|
|
|
|
if( length_hours || length_minutes)
|
|
{
|
|
if(Banlist.JumpToKey(sAuth, true))
|
|
{
|
|
int history = Banlist.GetNum("history");
|
|
Banlist.SetNum("history", history + 1);
|
|
Banlist.SetNum("time", time);
|
|
Banlist.SetNum("time_minutes", time_minutes);
|
|
Banlist.SetNum("duration", length_hours);
|
|
Banlist.SetNum("duration_minutes", length_minutes);
|
|
Banlist.SetString("admin", sAdmin);
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(Banlist.JumpToKey(sAuth, true))
|
|
{
|
|
int history = Banlist.GetNum("history");
|
|
Banlist.SetNum("history", history + 1);
|
|
Banlist.SetNum("time", time);
|
|
Banlist.SetNum("time_minutes", time_minutes);
|
|
Banlist.SetNum("duration", -1);
|
|
Banlist.SetNum("duration_minutes", -1);
|
|
Banlist.SetString("admin", sAdmin);
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Action CheckKnifeBans(Handle timer)
|
|
{
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(!IsClientInGame(i))
|
|
continue;
|
|
|
|
if(g_bKnifeBanned[i])
|
|
{
|
|
char sAuth[32];
|
|
GetClientAuthId(i, AuthId_Steam2, sAuth, sizeof(sAuth));
|
|
|
|
Banlist.Rewind();
|
|
|
|
int length;
|
|
int length_minutes;
|
|
int time;
|
|
int time_minutes;
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
length = Banlist.GetNum("duration");
|
|
length_minutes = Banlist.GetNum("duration_minutes");
|
|
time = Banlist.GetNum("time");
|
|
time_minutes = Banlist.GetNum("time_minutes", 0);
|
|
}
|
|
|
|
if(length > 0 || length_minutes > 0)
|
|
CheckIfClientIsStillKnifeBanned(sAuth, i, time, time_minutes, length, length_minutes);
|
|
}
|
|
}
|
|
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public void CheckIfClientIsStillKnifeBanned(char sAuth[32], int client, int time, int time_minutes, int length, int length_minutes)
|
|
{
|
|
int timesinceknifeban = g_iClientHours[client] - time;
|
|
int timesinceknifeban_minutes = g_iClientMinutes[client] - time_minutes;
|
|
|
|
if (timesinceknifeban_minutes < 0)
|
|
{
|
|
timesinceknifeban_minutes += 60;
|
|
timesinceknifeban--;
|
|
}
|
|
//PrintToChatAll("timesinceknifeban: %i. length: %i. timesinceknifeban_minutes: %i. length_minutes: %i", timesinceknifeban, length, timesinceknifeban_minutes, length_minutes);
|
|
if (timesinceknifeban < length)
|
|
{
|
|
g_bKnifeBanned[client] = true;
|
|
}
|
|
else if (timesinceknifeban <= length && timesinceknifeban_minutes < length_minutes)
|
|
{
|
|
g_bKnifeBanned[client] = true;
|
|
}
|
|
else
|
|
{
|
|
g_bKnifeBanned[client] = false;
|
|
Banlist.Rewind();
|
|
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
Banlist.SetNum("time", 0);
|
|
Banlist.SetNum("time_minutes", 0);
|
|
Banlist.SetNum("duration", 0);
|
|
Banlist.SetNum("duration_minutes", 0);
|
|
Banlist.SetString("admin", "");
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
update_knife_unban_mysql(client);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom)
|
|
{
|
|
if(attacker < 1 || attacker > MaxClients)
|
|
return Plugin_Continue;
|
|
|
|
if(!IsPlayerAlive(victim))
|
|
return Plugin_Continue;
|
|
|
|
if(!IsPlayerAlive(attacker))
|
|
return Plugin_Continue;
|
|
|
|
if(!g_bKnifeBan)
|
|
return Plugin_Continue;
|
|
|
|
if(!g_bKnifeBanned[attacker])
|
|
return Plugin_Continue;
|
|
|
|
if(!ZR_IsClientZombie(victim))
|
|
return Plugin_Continue;
|
|
|
|
if(!ZR_IsClientHuman(attacker))
|
|
return Plugin_Continue;
|
|
|
|
char sWeapon[32];
|
|
int iWeapon = GetEntDataEnt2(attacker, g_hActiveWeapon);
|
|
if(iWeapon != INVALID_ENT_REFERENCE)
|
|
GetEdictClassname(iWeapon, sWeapon, sizeof(sWeapon));
|
|
else
|
|
return Plugin_Continue;
|
|
|
|
if(!StrEqual(sWeapon, "weapon_knife") || damagetype & DMG_BLAST)
|
|
return Plugin_Continue;
|
|
|
|
CPrintToChat(attacker, "\x07%s[KnifeBan] \x07%sYou are currently knifebanned.", "E01B5D", "F16767");
|
|
damage = 0.0;
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public Action Command_Knifeban(int client, int args)
|
|
{
|
|
if(!GetCmdArgs())
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sUsage: sm_knifeban <#userid/name> [duration]", "E01B5D", "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
char sArguments[2][32];
|
|
GetCmdArg(1, sArguments[0], sizeof(sArguments[]));
|
|
GetCmdArg(2, sArguments[1], sizeof(sArguments[]));
|
|
|
|
int target;
|
|
if((target = FindTarget(client, sArguments[0], true)) == -1)
|
|
return Plugin_Handled;
|
|
|
|
int length;
|
|
int length_hours;
|
|
int length_minutes;
|
|
|
|
if(GetCmdArgs() >= 2)
|
|
{
|
|
length = StringToInt(sArguments[1]);
|
|
|
|
if(length < 0)
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sThe given knifeban duration is invalid.", "E01B5D", "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
length_hours = length / 60;
|
|
length_minutes = length % 60;
|
|
}
|
|
|
|
if(g_bKnifeBanned[target])
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sThe given client is already knifebanned.", "E01B5D", "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
g_bKnifeBanned[target] = true;
|
|
int time = g_iClientHours[target];
|
|
int time_minutes = g_iClientMinutes[target];
|
|
|
|
char sAdmin[32];
|
|
GetClientName(client, sAdmin, sizeof(sAdmin));
|
|
if(client == 0)
|
|
sAdmin = "Console";
|
|
|
|
char sAuth[32];
|
|
GetClientAuthId(target, AuthId_Steam2, sAuth, sizeof(sAuth));
|
|
|
|
Banlist.Rewind();
|
|
|
|
if(GetCmdArgs() >= 2)
|
|
{
|
|
if(length_hours || length_minutes)
|
|
{
|
|
CPrintToChatAll("\x07%s[KnifeBan] \x07%s%N\x07%s knifebanned \x07%s%N\x07%s for \x07%s%d\x07%s hours and \x07%s%d\x07%s minutes Playtime.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767", "EDEDED", length_hours, "F16767", "EDEDED", length_minutes, "F16767");
|
|
LogAction(client, target, "%L knifebanned %L for %d hours and %d minutes.", client, target, length_hours, length_minutes);
|
|
if(Banlist.JumpToKey(sAuth, true))
|
|
{
|
|
int history = Banlist.GetNum("history");
|
|
Banlist.SetNum("history", history + 1);
|
|
Banlist.SetNum("time", time);
|
|
Banlist.SetNum("time_minutes", time_minutes);
|
|
Banlist.SetNum("duration", length_hours);
|
|
Banlist.SetNum("duration_minutes", length_minutes);
|
|
Banlist.SetString("admin", sAdmin);
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
|
|
insert_knifeban_mysql(client, target, length_hours, length_minutes, time, time_minutes);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CPrintToChatAll("\x07%s[KnifeBan] \x07%s%N\x07%s knifebanned \x07%s%N\x07%s permanently.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767");
|
|
LogAction(client, target, "%L knifebanned %L permanently.", client, target);
|
|
if(Banlist.JumpToKey(sAuth, true))
|
|
{
|
|
int history = Banlist.GetNum("history");
|
|
Banlist.SetNum("history", history + 1);
|
|
Banlist.SetNum("time", time);
|
|
Banlist.SetNum("time_minutes", time_minutes);
|
|
Banlist.SetNum("duration", -1);
|
|
Banlist.SetNum("duration_minutes", -1);
|
|
Banlist.SetString("admin", sAdmin);
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
|
|
insert_knifeban_mysql(client, target, -1, -1, time, time_minutes);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CPrintToChatAll("\x07%s[KnifeBan] \x07%s%N\x07%s knifebanned \x07%s%N\x07%s temporarily.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767");
|
|
LogAction(client, target, "%L knifebanned %L temporarily.", client, target);
|
|
if(Banlist.JumpToKey(sAuth, true))
|
|
{
|
|
int history = Banlist.GetNum("history");
|
|
Banlist.SetNum("history", history + 1);
|
|
Banlist.SetNum("time", time);
|
|
Banlist.SetNum("time_minutes", time_minutes);
|
|
Banlist.SetString("admin", sAdmin);
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
int accountid = GetSteamAccountID(target);
|
|
g_TempBanned.Push(accountid);
|
|
}
|
|
}
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public void insert_knifeban_mysql(int admin, int knife_banned_player, int length_hours, int length_minutes, int time_start_playertime_hours, int time_start_playertime_minutes)
|
|
{
|
|
char sNameAdmin[MAX_NAME_LENGTH];
|
|
GetClientName(admin, sNameAdmin, sizeof(sNameAdmin));
|
|
int size2 = 2 * strlen(sNameAdmin) + 1;
|
|
char[] sEscapedNameAdmin = new char[size2 + 1];
|
|
g_hDatabase.Escape(sNameAdmin, sEscapedNameAdmin, size2 + 1);
|
|
char sSIDAdmin[64];
|
|
GetClientAuthId(admin, AuthId_Steam2, sSIDAdmin, sizeof(sSIDAdmin));
|
|
|
|
|
|
char sNameClient[MAX_NAME_LENGTH];
|
|
GetClientName(knife_banned_player, sNameClient, sizeof(sNameClient));
|
|
size2 = 2 * strlen(sNameClient) + 1;
|
|
char[] sEscapedNameClient = new char[size2 + 1];
|
|
g_hDatabase.Escape(sNameClient, sEscapedNameClient, size2 + 1);
|
|
char sSIDClient[64];
|
|
GetClientAuthId(knife_banned_player, AuthId_Steam2, sSIDClient, sizeof(sSIDClient));
|
|
char sIP[32];
|
|
GetClientIP(knife_banned_player, sIP, sizeof(sIP));
|
|
|
|
char currentMap[64];
|
|
GetCurrentMap(currentMap, sizeof(currentMap));
|
|
|
|
char sQuery[512];
|
|
//length is assumed to be minutes.
|
|
int length = (length_hours * 60) + length_minutes;
|
|
if (length_hours == -1)
|
|
{
|
|
length = 0;
|
|
}
|
|
|
|
int playtime_start_client = (time_start_playertime_hours * 60) + time_start_playertime_minutes;
|
|
int playtime_end_client = playtime_start_client + length;
|
|
|
|
if (length_hours == -1)
|
|
{
|
|
playtime_end_client = -1;
|
|
playtime_start_client = -1;
|
|
}
|
|
|
|
Format(sQuery, sizeof(sQuery), "INSERT INTO `KbRestrict_CurrentBans` (`client_name`, `client_steamid`, `client_ip`, `admin_name`, `admin_steamid`, `reason`, `map`, `length`, `time_played_start`, `time_played_end`, `is_expired`, `is_removed`, `admin_name_removed`, `admin_steamid_removed`, `time_stamp_removed`, `reason_removed`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%i', '%i', '%i', 0, 0, ' ', ' ', 0, ' ')", sEscapedNameClient, sSIDClient, sIP, sEscapedNameAdmin, sSIDAdmin, "get fucked", currentMap, length, playtime_start_client, playtime_end_client);
|
|
g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Normal);
|
|
}
|
|
|
|
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, any data)
|
|
{
|
|
if (!db || strlen(error))
|
|
{
|
|
LogError("Query error 3: %s", error);
|
|
}
|
|
delete results;
|
|
}
|
|
|
|
public Action Command_Knifeunban(int client, int args)
|
|
{
|
|
if(!GetCmdArgs())
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sUsage: sm_knifeunban <#userid/name>", "E01B5D", "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
char sArguments[1][32];
|
|
GetCmdArg(1, sArguments[0], sizeof(sArguments[]));
|
|
|
|
int target;
|
|
if((target = FindTarget(client, sArguments[0], true)) == -1)
|
|
return Plugin_Handled;
|
|
|
|
if(!g_bKnifeBanned[target])
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sThe given client is not knifebanned.", "E01B5D", "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
g_bKnifeBanned[target] = false;
|
|
Banlist.Rewind();
|
|
|
|
char sAuth[32];
|
|
GetClientAuthId(target, AuthId_Steam2, sAuth, sizeof(sAuth));
|
|
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
int history = Banlist.GetNum("history");
|
|
Banlist.SetNum("history", history - 1);
|
|
Banlist.SetNum("time", 0);
|
|
Banlist.SetNum("time_minutes", 0);
|
|
Banlist.SetNum("duration", 0);
|
|
Banlist.SetNum("duration_minutes", 0);
|
|
Banlist.SetString("admin", "");
|
|
Banlist.Rewind();
|
|
Banlist.ExportToFile(g_sBanListFilePath);
|
|
update_knife_unban_mysql(target);
|
|
}
|
|
|
|
int accountid = GetSteamAccountID(target);
|
|
if(accountid != 0)
|
|
{
|
|
int index = g_TempBanned.FindValue(accountid);
|
|
if(index != -1)
|
|
g_TempBanned.Erase(index);
|
|
}
|
|
|
|
CPrintToChatAll("\x07%s[KnifeBan] \x07%s%N\x07%s knifeunbanned \x07%s%N\x07%s.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767");
|
|
LogAction(client, target, "%L knifeunbanned %L.", client, target);
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public void update_knife_unban_mysql(int knife_unbanned_client)
|
|
{
|
|
char sSIDClient[64];
|
|
GetClientAuthId(knife_unbanned_client, AuthId_Steam2, sSIDClient, sizeof(sSIDClient));
|
|
|
|
char sQuery[512];
|
|
Format(sQuery, sizeof(sQuery), "update `KbRestrict_CurrentBans` set is_expired = 1 where client_steamid = '%s' and is_expired = 0", sSIDClient);
|
|
g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Normal);
|
|
}
|
|
|
|
public Action Command_Knifestatus(int client, int args)
|
|
{
|
|
if(CheckCommandAccess(client, "", ADMFLAG_BAN) && GetCmdArgs())
|
|
{
|
|
char sArguments[1][32];
|
|
GetCmdArg(1, sArguments[0], sizeof(sArguments[]));
|
|
|
|
int target;
|
|
if((target = FindTarget(client, sArguments[0], true)) == -1)
|
|
return Plugin_Handled;
|
|
|
|
char sAuth[32];
|
|
GetClientAuthId(target, AuthId_Steam2, sAuth, sizeof(sAuth));
|
|
int accountid = GetSteamAccountID(target);
|
|
int index = g_TempBanned.FindValue(accountid);
|
|
|
|
Banlist.Rewind();
|
|
int length_hours;
|
|
int length_minutes;
|
|
|
|
int time;
|
|
int time_minutes;
|
|
|
|
int history;
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
length_hours = Banlist.GetNum("duration");
|
|
length_minutes = Banlist.GetNum("duration_minutes");
|
|
|
|
time = Banlist.GetNum("time");
|
|
time_minutes = Banlist.GetNum("time_minutes");
|
|
|
|
history = Banlist.GetNum("history");
|
|
}
|
|
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%s%N\x07%s has been knifebanned \x07%s%d\x07%s times before.", "E01B5D", "EDEDED", target, "F16767", "EDEDED", history, "F16767");
|
|
|
|
if(g_bKnifeBanned[target] && index != -1)
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%s%N\x07%s is currently temporarily knifebanned.", "E01B5D", "EDEDED", target, "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
else if(g_bKnifeBanned[target] && length_hours == -1)
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%s%N\x07%s is currently permanently knifebanned.", "E01B5D", "EDEDED", target, "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
else if(g_bKnifeBanned[target] && (length_hours > 0 || length_minutes > 0))
|
|
{
|
|
char sTimeRemaining[64];
|
|
int timesinceknifeban = g_iClientHours[target] - time;
|
|
int timesinceknifeban_minutes = g_iClientMinutes[target] - time_minutes;
|
|
|
|
if (timesinceknifeban_minutes < 0)
|
|
{
|
|
timesinceknifeban_minutes += 60;
|
|
timesinceknifeban--;
|
|
}
|
|
|
|
int iTimeRemaining = length_hours - timesinceknifeban;
|
|
int iTimeRemaining_minutes = length_minutes - timesinceknifeban_minutes;
|
|
if (iTimeRemaining_minutes < 0)
|
|
{
|
|
iTimeRemaining_minutes += 60;
|
|
iTimeRemaining--;
|
|
}
|
|
|
|
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours and %d minutes playtime", iTimeRemaining, iTimeRemaining_minutes);
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%s%N\x07%s is currently knifebanned for another \x07%s%s\x07%s.", "E01B5D", "EDEDED", target, "F16767", "EDEDED", sTimeRemaining, "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
else
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%s%N\x07%s is currently not knifebanned.", "E01B5D", "EDEDED", target, "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
char sAuth[32];
|
|
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
|
|
int accountid = GetSteamAccountID(client);
|
|
int index = g_TempBanned.FindValue(accountid);
|
|
|
|
Banlist.Rewind();
|
|
int length_hours;
|
|
int length_minutes;
|
|
|
|
int time;
|
|
int time_minutes;
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
length_hours = Banlist.GetNum("duration");
|
|
length_minutes = Banlist.GetNum("duration_minutes");
|
|
|
|
time = Banlist.GetNum("time");
|
|
time_minutes = Banlist.GetNum("time_minutes");
|
|
}
|
|
|
|
if(g_bKnifeBanned[client] && index != -1)
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sYou are currently temporarily knifebanned.", "E01B5D", "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
else if(g_bKnifeBanned[client] && length_hours == -1)
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sYou are currently permanently knifebanned.", "E01B5D", "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
else if(g_bKnifeBanned[client] && (length_hours > 0 || length_minutes > 0))
|
|
{
|
|
char sTimeRemaining[64];
|
|
int timesinceknifeban = g_iClientHours[client] - time;
|
|
int timesinceknifeban_minutes = g_iClientMinutes[client] - time_minutes;
|
|
|
|
if (timesinceknifeban_minutes < 0)
|
|
{
|
|
timesinceknifeban_minutes += 60;
|
|
timesinceknifeban--;
|
|
}
|
|
|
|
int iTimeRemaining = length_hours - timesinceknifeban;
|
|
int iTimeRemaining_minutes = length_minutes - timesinceknifeban_minutes;
|
|
if (iTimeRemaining_minutes < 0)
|
|
{
|
|
iTimeRemaining_minutes += 60;
|
|
iTimeRemaining--;
|
|
}
|
|
|
|
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours and %d minutes playtime", iTimeRemaining, iTimeRemaining_minutes);
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sYou are currently knifebanned for another \x07%s%s\x07%s.", "E01B5D", "F16767", "EDEDED", sTimeRemaining, "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
else
|
|
{
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sYou are currently not knifebanned.", "E01B5D", "F16767");
|
|
return Plugin_Handled;
|
|
}
|
|
}
|
|
}
|
|
|
|
public Action Command_Knifebanlist(int client, int args)
|
|
{
|
|
char aBuf[1024];
|
|
char aBuf2[MAX_NAME_LENGTH];
|
|
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(IsClientInGame(i) && !IsFakeClient(i))
|
|
{
|
|
if(g_bKnifeBanned[i])
|
|
{
|
|
GetClientName(i, aBuf2, sizeof(aBuf2));
|
|
StrCat(aBuf, sizeof(aBuf), aBuf2);
|
|
StrCat(aBuf, sizeof(aBuf), ", ");
|
|
}
|
|
}
|
|
}
|
|
|
|
if(strlen(aBuf))
|
|
{
|
|
aBuf[strlen(aBuf) - 2] = 0;
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sCurrently knifebanned clients: \x07%s%s", "E01B5D", "F16767", "EDEDED", aBuf);
|
|
}
|
|
else
|
|
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sCurrently knifebanned clients: \x07%snone", "E01B5D", "F16767", "EDEDED");
|
|
|
|
if(CheckCommandAccess(client, "", ADMFLAG_BAN))
|
|
OpenKnifebanlistMenu(client);
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public void OpenKnifebanlistMenu(int client)
|
|
{
|
|
if(client == 0)
|
|
return;
|
|
|
|
Menu menu = new Menu(MenuHandler_MainMenu);
|
|
|
|
menu.SetTitle("Currently knifebanned clients:", client);
|
|
|
|
char sBuffer[32];
|
|
int iMenuItem;
|
|
char sMenuItem[8];
|
|
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(IsClientInGame(i) && !IsFakeClient(i))
|
|
{
|
|
if(g_bKnifeBanned[i])
|
|
{
|
|
GetClientName(i, sBuffer, sizeof(sBuffer));
|
|
IntToString(iMenuItem, sMenuItem, sizeof(sMenuItem));
|
|
menu.AddItem(sMenuItem, sBuffer);
|
|
iMenuItem++;
|
|
}
|
|
}
|
|
}
|
|
|
|
menu.Display(client, MENU_TIME_FOREVER);
|
|
}
|
|
|
|
public void MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection)
|
|
{
|
|
switch(action)
|
|
{
|
|
case(MenuAction_Select):
|
|
{
|
|
char sMenuItem[8];
|
|
char sBuffer[32];
|
|
int flag;
|
|
menu.GetItem(selection, sMenuItem, sizeof(sMenuItem), flag, sBuffer, sizeof(sBuffer));
|
|
OpenKnifebanlistOfTheClient(client, sBuffer);
|
|
}
|
|
case(MenuAction_End):
|
|
{
|
|
delete menu;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OpenKnifebanlistOfTheClient(int client, char sBuffer[32])
|
|
{
|
|
Menu menuclient = new Menu(MenuHandler_ClientMenu);
|
|
|
|
char sTitle[64] = "Knifebanned client: ";
|
|
|
|
StrCat(sTitle, sizeof(sTitle), sBuffer);
|
|
|
|
int target;
|
|
char sName[32];
|
|
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(IsClientInGame(i) && !IsFakeClient(i) && g_bKnifeBanned[i])
|
|
{
|
|
GetClientName(i, sName, sizeof(sName));
|
|
|
|
if(StrEqual(sName, sBuffer))
|
|
{
|
|
target = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
char sAuth[32];
|
|
GetClientAuthId(target, AuthId_Steam2, sAuth, sizeof(sAuth));
|
|
|
|
Banlist.Rewind();
|
|
|
|
int length;
|
|
int length_minutes;
|
|
|
|
int history;
|
|
char sAdmin[32];
|
|
if(Banlist.JumpToKey(sAuth))
|
|
{
|
|
length = Banlist.GetNum("duration");
|
|
length_minutes = Banlist.GetNum("duration_minutes");
|
|
|
|
history = Banlist.GetNum("history");
|
|
Banlist.GetString("admin", sAdmin, sizeof(sAdmin));
|
|
}
|
|
|
|
menuclient.SetTitle(sTitle, client);
|
|
|
|
char sInfo[256];
|
|
Format(sInfo, sizeof(sInfo), "Banned by: %s", sAdmin);
|
|
|
|
menuclient.AddItem("0", sInfo);
|
|
|
|
if(length > 0)
|
|
Format(sInfo, sizeof(sInfo), "Duration: %d Hours and %d minutes playtime", length, length_minutes);
|
|
else if(length == -1)
|
|
Format(sInfo, sizeof(sInfo), "Duration: Permanently");
|
|
else
|
|
Format(sInfo, sizeof(sInfo), "Duration: Temporarly");
|
|
|
|
menuclient.AddItem("1", sInfo);
|
|
Format(sInfo, sizeof(sInfo), "Ban History: %d times", history);
|
|
|
|
menuclient.AddItem("2", sInfo);
|
|
|
|
menuclient.AddItem("3", "Back to List");
|
|
|
|
menuclient.Display(client, MENU_TIME_FOREVER);
|
|
}
|
|
|
|
public void MenuHandler_ClientMenu(Menu menuclient, MenuAction action, int client, int selection)
|
|
{
|
|
switch(action)
|
|
{
|
|
case(MenuAction_Select):
|
|
{
|
|
switch(selection)
|
|
{
|
|
case(4): OpenKnifebanlistMenu(client);
|
|
}
|
|
}
|
|
case(MenuAction_End):
|
|
{
|
|
delete menuclient;
|
|
}
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------
|
|
// Purpose: 2026 getting the ingame play time of the players. called with OnClientPostAdminCheck() forward and timer every 10 minutes
|
|
//----------------------------------------------------------------------------------------------------
|
|
public void GetPlayerHoursServer(int client, int hours, int minutes)
|
|
{
|
|
g_iClientHours[client] = hours;
|
|
g_iClientMinutes[client] = minutes;
|
|
}
|