further modifications to make it compatible with the entwatch bans website
This commit is contained in:
parent
1cb0905d78
commit
a4e2d541a9
@ -18,6 +18,7 @@
|
|||||||
//2026: add playtime requirements for being unrestricted
|
//2026: add playtime requirements for being unrestricted
|
||||||
#include <unloze_playtime>
|
#include <unloze_playtime>
|
||||||
|
|
||||||
|
Database g_hDatabase;
|
||||||
|
|
||||||
/* FORWARDS */
|
/* FORWARDS */
|
||||||
Handle g_hFwd_OnClientRestricted;
|
Handle g_hFwd_OnClientRestricted;
|
||||||
@ -35,7 +36,8 @@ Handle g_hCookie_RestrictLength_minutes;
|
|||||||
|
|
||||||
/* BOOLEANS */
|
/* BOOLEANS */
|
||||||
bool g_bRestrictedTemp[MAXPLAYERS+1];
|
bool g_bRestrictedTemp[MAXPLAYERS+1];
|
||||||
bool g_bDontSpamMsg[MAXPLAYERS+1]
|
bool g_bDontSpamMsg[MAXPLAYERS+1];
|
||||||
|
bool g_bActiveEban[MAXPLAYERS+1];
|
||||||
|
|
||||||
/* INTERGERS */
|
/* INTERGERS */
|
||||||
int g_iRestrictIssued[MAXPLAYERS+1];
|
int g_iRestrictIssued[MAXPLAYERS+1];
|
||||||
@ -118,15 +120,68 @@ public void OnPluginStart()
|
|||||||
OnClientCookiesCached(client);
|
OnClientCookiesCached(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!g_hDatabase)
|
||||||
|
{
|
||||||
|
Database.Connect(SQL_OnDatabaseConnect, "unloze_entwatch_web");
|
||||||
|
}
|
||||||
|
CreateTimer(5.0, CheckIfEntwatchBanExpired, _, TIMER_REPEAT);
|
||||||
|
|
||||||
g_cvarItemTierRequirement = CreateConVar("sm_entwatch_tier_requirement", "1", "Using the unloze play time plugin to set a tier for allowing players access to items.");
|
g_cvarItemTierRequirement = CreateConVar("sm_entwatch_tier_requirement", "1", "Using the unloze play time plugin to set a tier for allowing players access to items.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//could probably fail at detecting when a client finally gets entwatch unbanned but risk is pretty small as they need the ingame playtime to accomplish it.
|
||||||
|
public Action CheckIfEntwatchBanExpired(Handle timer)
|
||||||
|
{
|
||||||
|
for (int client = 1; client <= MaxClients; client++)
|
||||||
|
{
|
||||||
|
if (Client_IsValid(client) && IsClientInGame(client))
|
||||||
|
{
|
||||||
|
//we only need to check for bans with durations. temporary and permanent bans dont need to be updated as expired obviusly
|
||||||
|
if (g_iRestrictIssued[client] && g_iRestrictExpire[client] >= g_iClientHours[client] && g_iClientHours[client] > 0) //assuring playtime is set for client
|
||||||
|
{
|
||||||
|
//example: client restricted until 1335 hours and currently has 1320
|
||||||
|
if (g_iRestrictExpire[client] > g_iClientHours[client])
|
||||||
|
{
|
||||||
|
g_bActiveEban[client] = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//example client restricted until 1335 hours and 45 minutes. currently has 1335 hours and 20 minutes.
|
||||||
|
if (g_iRestrictExpire_minutes[client] > g_iClientMinutes[client])
|
||||||
|
{
|
||||||
|
g_bActiveEban[client] = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (g_bActiveEban[client])
|
||||||
|
{
|
||||||
|
g_bActiveEban[client] = false;
|
||||||
|
update_entwatchban_mysql_is_expired(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Plugin_Continue;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnMapStart()
|
public void OnMapStart()
|
||||||
{
|
{
|
||||||
g_hTrie_Storage.Clear();
|
g_hTrie_Storage.Clear();
|
||||||
|
if (!g_hDatabase)
|
||||||
|
{
|
||||||
|
Database.Connect(SQL_OnDatabaseConnect, "unloze_entwatch_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -138,6 +193,7 @@ public void OnClientPutInServer(int client)
|
|||||||
GetClientIP(client, sAddress, sizeof(sAddress));
|
GetClientIP(client, sAddress, sizeof(sAddress));
|
||||||
|
|
||||||
g_bDontSpamMsg[client] = false;
|
g_bDontSpamMsg[client] = false;
|
||||||
|
g_bActiveEban[client] = false;
|
||||||
bool bRestrictedTemp;
|
bool bRestrictedTemp;
|
||||||
if (g_hTrie_Storage.GetValue(sAddress, bRestrictedTemp))
|
if (g_hTrie_Storage.GetValue(sAddress, bRestrictedTemp))
|
||||||
{
|
{
|
||||||
@ -175,6 +231,7 @@ public void OnClientDisconnect(int client)
|
|||||||
|
|
||||||
g_bDontSpamMsg[client] = false;
|
g_bDontSpamMsg[client] = false;
|
||||||
g_bRestrictedTemp[client] = false;
|
g_bRestrictedTemp[client] = false;
|
||||||
|
g_bActiveEban[client] = false;
|
||||||
|
|
||||||
g_iRestrictIssued[client] = 0;
|
g_iRestrictIssued[client] = 0;
|
||||||
g_iRestrictIssued_minutes[client] = 0;
|
g_iRestrictIssued_minutes[client] = 0;
|
||||||
@ -232,6 +289,7 @@ public Action Command_ClientRestrict(int client, int args)
|
|||||||
CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s permanently.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767");
|
CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s permanently.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767");
|
||||||
LogAction(client, target, "%L restricted %L permanently.", client, target);
|
LogAction(client, target, "%L restricted %L permanently.", client, target);
|
||||||
}
|
}
|
||||||
|
insert_entwatchban_mysql(client, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -320,7 +378,7 @@ public Action Command_DisplayRestrictions(int client, int args)
|
|||||||
CReplyToCommand(client, "\x07%s[entWatch] \x07%sCurrent clients with not high enough Tier: \x07%s%s", "E01B5D", "F16767", "EDEDED", aBuf_time_requirement);
|
CReplyToCommand(client, "\x07%s[entWatch] \x07%sCurrent clients with not high enough Tier: \x07%s%s", "E01B5D", "F16767", "EDEDED", aBuf_time_requirement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CReplyToCommand(client, "\x07%s[entWatch] \x07%sCurrent clients with not high enoughouh Tier: \x07%snone", "E01B5D", "F16767", "EDEDED");
|
CReplyToCommand(client, "\x07%s[entWatch] \x07%sCurrent clients with not high enough Tier: \x07%snone", "E01B5D", "F16767", "EDEDED");
|
||||||
|
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
@ -474,6 +532,7 @@ stock bool ClientRestrict(int client, int target, int length)
|
|||||||
g_iRestrictIssued[target] = g_iClientHours[target];
|
g_iRestrictIssued[target] = g_iClientHours[target];
|
||||||
g_iRestrictExpire[target] = 0;
|
g_iRestrictExpire[target] = 0;
|
||||||
g_iRestrictLength[target] = 0;
|
g_iRestrictLength[target] = 0;
|
||||||
|
g_iRestrictLength_minutes[target] = 0;
|
||||||
|
|
||||||
SetClientCookieInt(target, g_hCookie_RestrictIssued, GetTime());
|
SetClientCookieInt(target, g_hCookie_RestrictIssued, GetTime());
|
||||||
SetClientCookieInt(target, g_hCookie_RestrictExpire, 0);
|
SetClientCookieInt(target, g_hCookie_RestrictExpire, 0);
|
||||||
@ -560,6 +619,8 @@ stock bool ClientUnrestrict(int client, int target)
|
|||||||
SetClientCookieInt(target, g_hCookie_RestrictLength, 0);
|
SetClientCookieInt(target, g_hCookie_RestrictLength, 0);
|
||||||
SetClientCookieInt(target, g_hCookie_RestrictLength_minutes, 0);
|
SetClientCookieInt(target, g_hCookie_RestrictLength_minutes, 0);
|
||||||
|
|
||||||
|
update_entwatchban_mysql_is_expired(target);
|
||||||
|
|
||||||
Call_StartForward(g_hFwd_OnClientUnrestricted);
|
Call_StartForward(g_hFwd_OnClientUnrestricted);
|
||||||
Call_PushCell(client);
|
Call_PushCell(client);
|
||||||
Call_PushCell(target);
|
Call_PushCell(target);
|
||||||
@ -674,6 +735,53 @@ public void GetPlayerHoursServer(int client, int hours, int minutes)
|
|||||||
g_iClientMinutes[client] = minutes;
|
g_iClientMinutes[client] = minutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update_entwatchban_mysql_is_expired(int entwatch_banned_player)
|
||||||
|
{
|
||||||
|
char sSIDClient[64];
|
||||||
|
GetClientAuthId(entwatch_banned_player, AuthId_Steam2, sSIDClient, sizeof(sSIDClient));
|
||||||
|
|
||||||
|
char sQuery[512];
|
||||||
|
Format(sQuery, sizeof(sQuery), "update `EntWatch_Current_Eban` set is_expired = 1 where client_steamid = '%s' and is_expired = 0", sSIDClient);
|
||||||
|
g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert_entwatchban_mysql(int admin, int entwatch_banned_player)
|
||||||
|
{
|
||||||
|
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(entwatch_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(entwatch_banned_player, AuthId_Steam2, sSIDClient, sizeof(sSIDClient));
|
||||||
|
|
||||||
|
int playtime_start_client = (g_iRestrictIssued[entwatch_banned_player] * 60) + g_iRestrictIssued_minutes[entwatch_banned_player];
|
||||||
|
int playtime_end_client = (g_iRestrictExpire[entwatch_banned_player] * 60) + g_iRestrictExpire_minutes[entwatch_banned_player];
|
||||||
|
|
||||||
|
int length = (g_iRestrictLength[entwatch_banned_player] * 60) + g_iRestrictLength_minutes[entwatch_banned_player];
|
||||||
|
|
||||||
|
char sQuery[512];
|
||||||
|
Format(sQuery, sizeof(sQuery), "INSERT INTO `EntWatch_Current_Eban` (`client_name`, `client_steamid`, `admin_name`, `admin_steamid`, `duration`, `reason`, `time_played_start`, `time_played_end`) VALUES ('%s', '%s', '%s', '%s', '%i', '%s', '%i', '%i')", sEscapedNameClient, sSIDClient, sEscapedNameAdmin, sSIDAdmin, length, "get fucked", 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;
|
||||||
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
38
entWatch4/sql_web/create_tables.sql
Normal file
38
entWatch4/sql_web/create_tables.sql
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
-- entwatchban_web.EntWatch_Current_Eban definition
|
||||||
|
|
||||||
|
CREATE TABLE `EntWatch_Current_Eban` (
|
||||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`client_name` varchar(32) NOT NULL,
|
||||||
|
`client_steamid` varchar(64) NOT NULL,
|
||||||
|
`admin_name` varchar(32) NOT NULL,
|
||||||
|
`admin_steamid` varchar(64) NOT NULL,
|
||||||
|
`duration` int(10) unsigned NOT NULL,
|
||||||
|
`time_stamp_start` datetime DEFAULT current_timestamp(),
|
||||||
|
`reason` varchar(64) DEFAULT NULL,
|
||||||
|
`reason_unban` varchar(64) DEFAULT NULL,
|
||||||
|
`admin_name_unban` varchar(32) DEFAULT NULL,
|
||||||
|
`admin_steamid_unban` varchar(64) DEFAULT NULL,
|
||||||
|
`timestamp_unban` int(11) DEFAULT NULL,
|
||||||
|
`time_played_start` int(11) NOT NULL DEFAULT -1,
|
||||||
|
`time_played_end` int(11) NOT NULL DEFAULT -1,
|
||||||
|
`is_expired` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_steamid_search` (`client_steamid`,`admin_steamid`),
|
||||||
|
KEY `idx_expiry_sort` (`time_stamp_start`,`duration`),
|
||||||
|
KEY `idx_server_expiry` (`duration`,`time_stamp_start`),
|
||||||
|
KEY `idx_is_expired` (`is_expired`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
|
||||||
|
-- entwatchban_web.web_logs definition
|
||||||
|
|
||||||
|
CREATE TABLE `web_logs` (
|
||||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`message` varchar(255) NOT NULL,
|
||||||
|
`admin_name` varchar(32) NOT NULL,
|
||||||
|
`admin_steamid` varchar(64) NOT NULL,
|
||||||
|
`client_name` varchar(32) NOT NULL,
|
||||||
|
`client_steamid` varchar(64) NOT NULL,
|
||||||
|
`time_stamp` int(10) unsigned NOT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
Loading…
Reference in New Issue
Block a user