modified to play along with the webpannel for knifebans as well
This commit is contained in:
parent
a72b0d9a8d
commit
14e83ec9a3
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
char g_sBanListFilePath[256];
|
char g_sBanListFilePath[256];
|
||||||
|
|
||||||
|
Database g_hDatabase;
|
||||||
|
|
||||||
bool g_bKnifeBanned[MAXPLAYERS + 1];
|
bool g_bKnifeBanned[MAXPLAYERS + 1];
|
||||||
bool g_bKnifeBan;
|
bool g_bKnifeBan;
|
||||||
|
|
||||||
@ -53,6 +55,7 @@ public void OnPluginStart()
|
|||||||
SetFailState("Couldnt find CBaseCombatCharacter::m_hActiveWeapon");
|
SetFailState("Couldnt find CBaseCombatCharacter::m_hActiveWeapon");
|
||||||
|
|
||||||
CreateTimer(5.0, CheckKnifeBans, _, TIMER_REPEAT);
|
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();
|
g_TempBanned = new ArrayList();
|
||||||
|
|
||||||
@ -68,6 +71,29 @@ public void OnPluginStart()
|
|||||||
if(IsClientInGame(i))
|
if(IsClientInGame(i))
|
||||||
OnClientPostAdminCheck(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()
|
public void OnPluginEnd()
|
||||||
@ -99,9 +125,6 @@ public void OnClientPostAdminCheck(int client)
|
|||||||
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
|
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_iClientHours[client] = 0;
|
|
||||||
g_iClientMinutes[client] = 0;
|
|
||||||
|
|
||||||
char sAuth[32];
|
char sAuth[32];
|
||||||
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
|
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
|
||||||
|
|
||||||
@ -141,6 +164,134 @@ public void OnMapEnd()
|
|||||||
g_TempBanned.Clear();
|
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)
|
public Action CheckKnifeBans(Handle timer)
|
||||||
{
|
{
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
@ -208,6 +359,7 @@ public void CheckIfClientIsStillKnifeBanned(char sAuth[32], int client, int time
|
|||||||
Banlist.SetString("admin", "");
|
Banlist.SetString("admin", "");
|
||||||
Banlist.Rewind();
|
Banlist.Rewind();
|
||||||
Banlist.ExportToFile(g_sBanListFilePath);
|
Banlist.ExportToFile(g_sBanListFilePath);
|
||||||
|
update_knife_unban_mysql(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,6 +473,8 @@ public Action Command_Knifeban(int client, int args)
|
|||||||
Banlist.SetString("admin", sAdmin);
|
Banlist.SetString("admin", sAdmin);
|
||||||
Banlist.Rewind();
|
Banlist.Rewind();
|
||||||
Banlist.ExportToFile(g_sBanListFilePath);
|
Banlist.ExportToFile(g_sBanListFilePath);
|
||||||
|
|
||||||
|
insert_knifeban_mysql(client, target, length_hours, length_minutes, time, time_minutes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -338,6 +492,8 @@ public Action Command_Knifeban(int client, int args)
|
|||||||
Banlist.SetString("admin", sAdmin);
|
Banlist.SetString("admin", sAdmin);
|
||||||
Banlist.Rewind();
|
Banlist.Rewind();
|
||||||
Banlist.ExportToFile(g_sBanListFilePath);
|
Banlist.ExportToFile(g_sBanListFilePath);
|
||||||
|
|
||||||
|
insert_knifeban_mysql(client, target, -1, -1, time, time_minutes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,6 +518,60 @@ public Action Command_Knifeban(int client, int args)
|
|||||||
return Plugin_Handled;
|
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, ' ')", sNameClient, sSIDClient, sIP, sNameAdmin, 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)
|
public Action Command_Knifeunban(int client, int args)
|
||||||
{
|
{
|
||||||
if(!GetCmdArgs())
|
if(!GetCmdArgs())
|
||||||
@ -400,6 +610,7 @@ public Action Command_Knifeunban(int client, int args)
|
|||||||
Banlist.SetString("admin", "");
|
Banlist.SetString("admin", "");
|
||||||
Banlist.Rewind();
|
Banlist.Rewind();
|
||||||
Banlist.ExportToFile(g_sBanListFilePath);
|
Banlist.ExportToFile(g_sBanListFilePath);
|
||||||
|
update_knife_unban_mysql(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
int accountid = GetSteamAccountID(target);
|
int accountid = GetSteamAccountID(target);
|
||||||
@ -416,6 +627,16 @@ public Action Command_Knifeunban(int client, int args)
|
|||||||
return Plugin_Handled;
|
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)
|
public Action Command_Knifestatus(int client, int args)
|
||||||
{
|
{
|
||||||
if(CheckCommandAccess(client, "", ADMFLAG_BAN) && GetCmdArgs())
|
if(CheckCommandAccess(client, "", ADMFLAG_BAN) && GetCmdArgs())
|
||||||
|
|||||||
46
KnifeBan/sql/create_table.sql
Normal file
46
KnifeBan/sql/create_table.sql
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
-- knifeban_web.KbRestrict_CurrentBans definition
|
||||||
|
|
||||||
|
CREATE TABLE `KbRestrict_CurrentBans` (
|
||||||
|
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`client_name` varchar(64) NOT NULL,
|
||||||
|
`client_steamid` varchar(64) NOT NULL,
|
||||||
|
`client_ip` varchar(64) NOT NULL,
|
||||||
|
`admin_name` varchar(64) NOT NULL,
|
||||||
|
`admin_steamid` varchar(64) NOT NULL,
|
||||||
|
`reason` varchar(255) NOT NULL,
|
||||||
|
`map` varchar(64) NOT NULL,
|
||||||
|
`length` int(11) NOT NULL,
|
||||||
|
`time_stamp_start` datetime DEFAULT current_timestamp(),
|
||||||
|
`time_played_start` int(11) NOT NULL,
|
||||||
|
`time_played_end` int(11) NOT NULL,
|
||||||
|
`is_expired` int(11) NOT NULL,
|
||||||
|
`is_removed` int(11) NOT NULL,
|
||||||
|
`time_stamp_removed` int(20) NOT NULL,
|
||||||
|
`admin_name_removed` varchar(255) NOT NULL,
|
||||||
|
`admin_steamid_removed` varchar(255) NOT NULL,
|
||||||
|
`reason_removed` varchar(255) NOT NULL,
|
||||||
|
`web_unban_required` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
|
`web_addban_required` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
|
`web_ban_delete` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
|
`web_edit_required` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_steamid_search` (`client_steamid`),
|
||||||
|
KEY `idx_ip_search` (`client_ip`),
|
||||||
|
KEY `idx_admin_steamid` (`admin_steamid`),
|
||||||
|
KEY `idx_status` (`is_expired`,`is_removed`),
|
||||||
|
KEY `idx_steamid_ip_status` (`client_steamid`,`client_ip`,`is_expired`,`is_removed`),
|
||||||
|
KEY `idx_web_unban_required` (`web_unban_required`),
|
||||||
|
KEY `idx_web_addban_required` (`web_addban_required`),
|
||||||
|
KEY `idx_web_ban_delete` (`web_ban_delete`),
|
||||||
|
KEY `idx_web_edit_required` (`web_edit_required`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS knifeban_web.KbRestrict_weblogs (
|
||||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`message` varchar(200) NOT NULL,
|
||||||
|
`admin_name` varchar(255) NOT NULL,
|
||||||
|
`admin_steamid` varchar(64) NOT NULL,
|
||||||
|
`client_name` varchar(255) NOT NULL,
|
||||||
|
`client_steamid` varchar(64) NOT NULL,
|
||||||
|
`time_stamp` int(20) NOT NULL,
|
||||||
|
PRIMARY KEY(`id`));
|
||||||
Loading…
Reference in New Issue
Block a user