AlliedModders Donor
|
08-18-2018
, 10:55
Re: [CS:GO] Help with keyvalue-based ctban plugin
|
#12
|
Considering @mug1wara made more of a full remake and didnt include all features, i used his code as a base and built in the same functions of the original in to his which is using MySQL. Unsure if it works as of now but i've sent it to the server manager; still open for help on the code in both this and previous post, we really need a working CT-Ban system so it's all really appreciated.
This is my rendition of the code from @mug1wara, feel free to correct any of my mistakes in implementing it
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1
ConVar ctban_database_name;
Database ctban_database;
char steamauth[MAXPLAYERS + 1][32];
int ctban[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "CT-Ban",
author = "potatoz & mug1wara",
description = "SQL CT-Ban system for jailbreak servers",
version = "1.1b",
url = ""
};
public void OnPluginStart()
{
ctban_database_name = CreateConVar("sm_ctbans_database_name", "ctbans");
LoadTranslations("common.phrases");
RegAdminCmd("sm_ctban", Command_CTBan, ADMFLAG_BAN);
RegAdminCmd("sm_ctunban", Command_CTUnBan, ADMFLAG_BAN);
RegAdminCmd("sm_isbanned", Command_IsBanned, ADMFLAG_BAN);
HookEvent("player_team", Event_Team);
AddCommandListener(Event_OnJoinTeam, "jointeam");
}
public void OnConfigsExecuted()
{
char s_databasename[256];
GetConVarString(ctban_database_name, s_databasename, sizeof(s_databasename));
Database.Connect(SQL_Connection, s_databasename);
}
public void SQL_Connection(Database hDatabase, const char[] sError, int iData)
{
if (hDatabase == null)
ThrowError(sError);
else
{
ctban_database = hDatabase;
ctban_database.Query(SQL_Error, "CREATE TABLE IF NOT EXISTS ctbans (steam_id VARCHAR(32) NOT NULL, time INT(11) NOT NULL)");
}
}
public void SQL_Error(Database hDatabase, DBResultSet hResults, const char[] sError, int iData)
{
if (hResults == null)
ThrowError(sError);
}
public void OnClientPostAdminCheck(int client)
{
if (IsValidClient(client))
{
GetClientAuthId(client, AuthId_Steam2, steamauth[client], sizeof(steamauth[]));
char query[256];
Format(query, sizeof(query), "SELECT * FROM ctbans WHERE steam_id = \"%s\"", steamauth[client]);
ctban_database.Query(SQL_Authorization, query, GetClientUserId(client));
}
}
public void SQL_Authorization(Database hDatabase, DBResultSet hResults, const char[] sError, int iData)
{
if (hResults == null)
ThrowError(sError);
int client = GetClientOfUserId(client);
if (IsValidClient(client))
{
if (hResults.RowCount != 0)
{
hResults.FetchRow();
ctban[client] = hResults.FetchInt(1);
if (ctban[client] != 0)
CreateTimer(1.0, Timer_CTBanTimer, GetClientUserId(client), TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
else
{
char query[256];
Format(query, sizeof(query), "INSERT INTO ctbans (steam_id, time) VALUES (\"%s\", '%d')", steamauth[client], ctban[client]);
ctban_database.Query(SQL_Error, query);
}
}
}
public Action Event_OnJoinTeam(int client, const char[] command, int args)
{
if (!IsValidClient(client) || IsFakeClient(client))
return Plugin_Continue;
char teamString[2];
GetCmdArg(1, teamString, sizeof(teamString));
int team = StringToInt(teamString);
int minutes = ctban[client] / 60;
minutes++;
if (team == 0)
{
PrintToChat(client, " \x07* You can't auto-assign to select team");
return Plugin_Stop;
}
if (team == 3 && ctban[client] > 0)
{
PrintToChat(client, " \x07* You are banned from the CT team for %.1d more minute(s)", minutes);
return Plugin_Stop;
}
return Plugin_Continue;
}
public Action Event_Team(Handle event, const char[] name, bool dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(IsValidClient(client))
CreateTimer(0.2, CheckTeam, client, TIMER_FLAG_NO_MAPCHANGE);
}
public Action CheckTeam(Handle timer, int client)
{
if(IsValidClient(client) && GetClientTeam(client) == 3 && ctban[client] > 0)
{
int minutes = ctban[client] / 60;
minutes++;
PrintToChat(client, " \x07* You are banned from the CT team for %.1d more minute(s)", minutes);
ChangeClientTeam(client, 2);
}
return Plugin_Handled;
}
public Action Timer_CTBanTimer(Handle timer, int client)
{
if (IsValidClient(client))
{
if (ctban[client] < 1)
{
PrintToChat(client, " \x06*\x01 Your CT-Ban has expired");
return Plugin_Stop;
}
ctban[client]--;
char query[256];
Format(query, sizeof(query), "UPDATE ctbans SET time = '%d' WHERE steam_id = \"%s\"", ctban[client], steamauth[client]);
ctban_database.Query(SQL_Error, query);
}
return Plugin_Continue;
}
public Action Command_CTBan(int client, int args)
{
if (IsValidClient(client))
{
if(args < 3)
{
ReplyToCommand(client, "[SM] Usage: sm_ctban <name|#userid> [minutes] [reason]");
return Plugin_Handled;
}
char target[MAX_NAME_LENGTH], time[32], reason[40];
GetCmdArg(1, target, sizeof(target));
GetCmdArg(2, time, sizeof(time));
GetCmdArg(3, reason, sizeof(reason));
int target2 = FindTarget(client, target);
ctban[target2] = StringToInt(time) * 60;
char query[256];
Format(query, sizeof(query), "UPDATE ctbans SET time = '%d' WHERE steam_id = \"%s\"", ctban[target2], steamauth[target2]);
ctban_database.Query(SQL_Error, query);
if(GetClientTeam(target2) == 3)
{
ChangeClientTeam(target2, 2);
ForcePlayerSuicide(target2);
}
PrintToChatAll(" \x07*\x01 ADMIN: \x07%N\x01 CT-Banned \x07%N \x01for %s minute(s) with reason: \x07%s", client, target2, time, reason);
}
return Plugin_Continue;
}
public Action Command_CTUnBan(int client, int args)
{
if(args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_ctunban <name|#userid>");
return Plugin_Handled;
}
char arg1[32];
GetCmdArg(1, arg1, sizeof(arg1));
int target = FindTarget(client, arg1);
if (target == -1) return Plugin_Handled;
if(ctban[target] < 1)
PrintToChat(client, " \x07* %N is not CT-Banned", target);
ctban[target] = 0;
char query[256];
Format(query, sizeof(query), "UPDATE ctbans SET time = '%d' WHERE steam_id = \"%s\"", ctban[target], steamauth[target]);
ctban_database.Query(SQL_Error, query);
PrintToChatAll(" \x06*\x01 ADMIN: \x06%N\x01 has removed CT-Ban from \x06%N", client, target);
return Plugin_Handled;
}
public Action Command_IsBanned(int client, int args)
{
if(args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_isbanned <name|#userid>");
return Plugin_Handled;
}
char arg1[32];
GetCmdArg(1, arg1, sizeof(arg1));
int target = FindTarget(client, arg1);
if (target == -1) return Plugin_Handled;
int minutes = ctban[client] / 60;
minutes++;
if(ctban[target] < 1)
PrintToChat(client, " \x07* %N is not CT-Banned", target);
else PrintToChat(client, " \x06* %N \x01is CT-Banned for %.1d more minute(s)", target, minutes);
return Plugin_Handled;
}
public void OnClientDisconnect(int client)
{
if (IsValidClient(client))
{
char query[256];
Format(query, sizeof(query), "UPDATE ctbans SET time = '%d' WHERE steam_id = \"%s\"", ctban[client], steamauth[client]);
ctban_database.Query(SQL_Error, query);
}
}
public bool IsValidClient(int client)
{
if (!(0 < client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client))
return false;
return true;
}
__________________
|
|