(Ban) System!

Started by Jutt, Jun 12, 2022, 09:39 AM

Previous topic - Next topic

Jutt

function onPlayerJoin( player )
{
NewTimer( "CheckBan", 1000, 1, player.ID );
}


function onScriptLoad(){
{
db <- ConnectSQL( "DataBase.db" );
QuerySQL( db, "CREATE TABLE IF NOT EXISTS SubBans ( Name VARCHAR(32), IP VARCHAR(25), Admin TEXT, Reason TEXT )" );
print(" === Simple Ban System Loaded === ");
}


function CheckBan( user )
{
local player = FindPlayer( user );
 if ( player )
 {
local ip = player.IP;
local sub = split( ip, "." );
local q = QuerySQL( db,  "SELECT * FROM SubBans WHERE IP='" + sub[0].tofloat() + "." + sub[1].tofloat() + "'" );
if ( GetSQLColumnData( q, 0 ) )
 {
Message( ">>> " + player + " Banned From Server <<<");
KickPlayer( player );
return 1;
}
}
}


if ( cmd == "ban" )
        {
     if ( !text ) MessagePlayer( "[Syntax] - /" + cmd + " <Nick/ID> <Reason>", player );
else {
 local plr = GetPlayer( GetTok( text, " ", 1 ) );
    if ( !plr ) MessagePlayer( "[Error] - Unknown Player..", player );
    else {
            local reason = GetTok( text, " ", 2 NumTok( text, " " ) );
            local ip = plr.IP;
            local sub = split( ip, "." );
             if ( reason == null ) reason = "None";
             QuerySQL( db, "INSERT INTO SubBans ( Name, IP, Admin, Reason ) VALUES ( '" + plr.Name + "', '" + sub[0].tofloat() + "." + sub[1].tofloat() + "', '" + player.Name + "', '" + reason + "' )" );
            Message( "[#EE82EE]** Admin " + player.Name + " Banned " + plr.Name + " Reason: " + reason );
    KickPlayer( plr );
    }
    }
 }

else if ( cmd == "unban" )
 {
 local q = QuerySQL( db,  "SELECT * FROM SubBans WHERE Name='" + text + "'" );
     if ( !text ) MessagePlayer( "[Syntax] - /" + cmd + " <Nick Full>", player );
    else if ( GetSQLColumnData( q, 0 ) != text ) MessagePlayer( "[Error] - " + text + " is not Banned.", player );
    else {
    QuerySQL( db, "DELETE FROM SubBans WHERE Name='" + text + "'" );
    Message( "[#EE82EE]** Admin " + player.Name + " UnBanned Player [ [#FFA500]" + text + " [#EE82EE]]." );
 }
 }
}
Jutt