Raised This Month: $51 Target: $400
 12% 

Solved [CS:GO] Help with keyvalue-based ctban plugin


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
potatoz
AlliedModders Donor
Join Date: Nov 2016
Old 08-16-2018 , 14:37   [CS:GO] Help with keyvalue-based ctban plugin
Reply With Quote #1

Hi,

A server i used to develop and administrate for, which i still help out with plugins and such in a few cases, has recently been having major problems finding a CT-Ban plugin that works, trying CT-Ban by databomb, the edit by Addicted, Teambans by Bara and more to no success. I went to work on a simple ct-ban plugin based on keyvalues partly considering knowledge of coding with SQL is limited but also since i know more about how to work with keyvalues having used it before.

Now, whilst the plugin works in ct-banning players and such, players also seem to get invalid ct-bans in a way which seems to give the player someone elses ct-ban on the postadmincheck where it gets a clients ct-ban info from the local file. The file is formatted sort of like the example below, considering i don't have an actual example myself this may not be exact but it should be about right;

PHP Code:
"ctban_database"
{
   
"STEAM_0:1:57886172"
   
{
       
"ctban_time"    "582"
   
}

Any help to as of why this could be happening and how to fix it is really appreciated, i will leave the source-code here as well, keep in mind that the code might not be perfect in syntax rules and does contain a lot of possibly unnecessary code partly in desperate hope to fix the issue; feel free to point these things out or even just rewrite parts of code

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1 
 
int ctban[MAXPLAYERS+1];
Handle ctbantimer[MAXPLAYERS+1];
 
KeyValues kv

public 
Plugin myinfo =
{
    
name "Simple CT-Ban",
    
author "Potatoz",
    
description "Simple CT-Ban system for jailbreak servers",
    
version "1.0",
    
url "http://www.sourcemod.net/"
};


public 
void OnPluginStart()
{
    
LoadTranslations("common.phrases");
    
RegAdminCmd("sm_ctban"Command_CTBanADMFLAG_BAN);
    
RegAdminCmd("sm_ctunban"Command_CTUnBanADMFLAG_BAN);
    
RegAdminCmd("sm_isbanned"Command_IsBannedADMFLAG_BAN);
    
    
HookEvent("player_team"Event_PlayerTeam);
    
AddCommandListener(Event_OnJoinTeam"jointeam");
    
    
char buffer[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMbuffersizeof(buffer), "configs/ctban_database.cfg");
    
kv = new KeyValues("ctban_database");
    
kv.ImportFromFile(buffer);
}

public 
Action Event_PlayerTeam(Handle event, const char[] namebool dontBroadcast)
{
    new 
client  GetClientOfUserId(GetEventInt(event"userid"));
    if(
IsValidClient(client))
        
CreateTimer(0.2CheckTeamclientTIMER_FLAG_NO_MAPCHANGE);
}

public 
Action CheckTeam(Handle timerint client)
{
    if(
IsValidClient(client) && GetClientTeam(client) == && 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(client2);
    }
    
    return 
Plugin_Handled;
}

public 
Action Event_OnJoinTeam(int client, const char[] commandint args
{
    if (!
IsValidClient(client) || IsFakeClient(client))
        return 
Plugin_Continue;

    
char teamString[2];
    
GetCmdArg(1teamStringsizeof(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 == && 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 
OnClientPostAdminCheck(int client
{
    
CreateTimer(1.0Timer_GetCTBanDataTIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Timer_GetCTBanData(Handle timerint client)
{
    
GetCTBanData(client);
    
    if(
ctban[client] > 0)
        
ctbantimer[client] = CreateTimer(1.0Timer_CTBanclientTIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
        
    return 
Plugin_Handled;
}

public 
Action Command_CTBan(int clientint args)
{
    if(
args 3
    {
        
ReplyToCommand(client"[SM] Usage: sm_ctban <name|#userid> [minutes] [reason]");
        return 
Plugin_Handled;
    }
    
    
char arg1[32], arg2[32], arg3[40];

    
GetCmdArg(1arg1sizeof(arg1));
    
GetCmdArg(2arg2sizeof(arg2));
    
GetCmdArg(3arg3sizeof(arg3));
    
    
int minutes StringToInt(arg2);
    
int target FindTarget(clientarg1);
    if (
target == -1) return Plugin_Handled;
    
    if(
ctban[target] > 0)
    {
        
PrintToChat(client" \x07* %N is already CT-Banned"target);
        return 
Plugin_Handled;
    }
    
    
ctban[target] = minutes 60;
    
ctbantimer[target] = CreateTimer(1.0Timer_CTBantargetTIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
    
    
UpdateCTBanData(target);
    
    if(
GetClientTeam(target) == 3)
    {
        
ChangeClientTeam(target2);
        
ForcePlayerSuicide(target);
    }
    
    
PrintToChatAll(" \x07*\x01 ADMIN: \x07%N\x01 CT-Banned \x07%N \x01for %s minute(s) with reason: \x07%s"clienttargetarg2arg3);
    
    return 
Plugin_Handled;
}

public 
Action Command_CTUnBan(int clientint args)
{
    if(
args 1
    {
        
ReplyToCommand(client"[SM] Usage: sm_ctunban <name|#userid>");
        return 
Plugin_Handled;
    }
    
    
char arg1[32];

    
GetCmdArg(1arg1sizeof(arg1));
    
int target FindTarget(clientarg1);
    if (
target == -1) return Plugin_Handled;
    
    if(
ctban[target] < 1)
        
PrintToChat(client" \x07* %N is not CT-Banned"target);
        
    
ctbantimer[target] = null;
    
KillTimer(ctbantimer[target]);
    
    
ctban[target] = 0;
    
PrintToChatAll(" \x06*\x01 ADMIN: \x06%N\x01 has removed CT-Ban from \x06%N"clienttarget);
    
UpdateCTBanData(target);
    
    return 
Plugin_Handled;
}

public 
Action Timer_CTBan(Handle timerint client)
{
    if(
ctban[client] < 1)
    {
        
ctban[client] = 0;
        
        
ctbantimer[client] = null;
        
KillTimer(ctbantimer[client]);
        
        return 
Plugin_Stop;
    }
    
    
ctban[client]--;
    
UpdateCTBanData(client);
    
    if(
ctban[client] < 1)
    {
        
PrintToChat(client" \x06*\x01 Your CT-Ban has expired");
        
ctban[client] = 0;
        
        
ctbantimer[client] = null;
        
KillTimer(ctbantimer[client]);
        
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;
}

public 
void OnClientDisconnect(int client)
{
    if (
ctbantimer[client] != null)
    {
        
KillTimer(ctbantimer[client]);
        
ctbantimer[client] = null;
    }
}

public 
Action Command_IsBanned(int clientint args)
{
    if(
args 1
    {
        
ReplyToCommand(client"[SM] Usage: sm_isbanned <name|#userid>");
        return 
Plugin_Handled;
    }
    
    
char arg1[32];
    
GetCmdArg(1arg1sizeof(arg1));
    
int target FindTarget(clientarg1);
    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)"targetminutes);
    
    return 
Plugin_Handled;
}

UpdateCTBanData(int client)
{
    
char buffer[PLATFORM_MAX_PATH], steamauth[50];
    
GetClientAuthId(clientAuthId_Steam2steamauthsizeof(steamauth));
    
Format(buffersizeof(buffer), "%d"ctban[client]);
    
kv.JumpToKey(steamauthtrue);
    
kv.SetString("ctban_time"buffer);
    
    
int length StringToInt(buffer);
    if (
length == 0)
        
kv.DeleteThis();
    
    
kv.Rewind();
    
BuildPath(Path_SMbuffersizeof(buffer), "configs/ctban_database.cfg");
    
kv.ExportToFile(buffer);
}

GetCTBanData(int client)
{
    
char sConfig[PLATFORM_MAX_PATH], sUserID[50];
    
GetClientAuthId(clientAuthId_Steam2sUserIDsizeof(sUserID));
    
BuildPath(Path_SMsConfigsizeof(sConfig), "configs/ctban_database.cfg");

    
KeyValues hConfig = new KeyValues("ctban_database");
    
    if (
FileToKeyValues(hConfigsConfig))
    {
        if (
KvJumpToKey(hConfigsUserIDfalse))
        {
            
char sUserID2[50];
            
GetClientAuthId(clientAuthId_Steam2sUserID2sizeof(sUserID2));
            if(
StrEqual(sUserIDsUserID2))
            {
                
char sTimeLeft[20];
                
KvGetString(hConfig"ctban_time"sTimeLeftsizeof(sTimeLeft));
                
                if (!
sTimeLeft[0])
                    
ctban[client] = StringToInt(sTimeLeft);
                else
                    
ctban[client] = 0;
                
                if(
ctban[client] > 0)
                {
                    if(
ctbantimer[client] == null)
                        
ctbantimer[client] = CreateTimer(1.0Timer_CTBanclientTIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
                }
                else
                {
                    
ctban[client] = 0;
                    
KillTimer(ctbantimer[client]);
                    
ctbantimer[client] = null;
                }
            }
            else
            {
                
ctban[client] = 0;
                
KillTimer(ctbantimer[client]);
                
ctbantimer[client] = null;
            }
        }
        else
        {
            
ctban[client] = 0;
            
KillTimer(ctbantimer[client]);
            
ctbantimer[client] = null;
        }
    }
    
    
CloseHandle(hConfig);
}

bool IsValidClient(int client
{
    if (!( 
<= client <= MaxClients ) || !IsClientInGame(client)) 
        return 
false
     
    return 
true

__________________

Last edited by potatoz; 08-19-2018 at 06:05.
potatoz is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode