•  
Welcome, Guest. Please login or register.

News:


Author Topic: ( Simple ) Ban System.  (Read 5685 times)

Offline gito baloch

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
( Simple ) Ban System.
« on: July 11, 2021, 07:41:46 am »
Ban System (DURATION)


Creating Database
[noae]
Code: [Select]
DataBase <- ConnectSQL("Databases/BanSys.db");   
QuerySQL(DataBase, "create table if not exists Bans ( Name TEXT, UID TEXT, UID2 TEXT, Admin TEXT, Reason TEXT, Time INTEGER, IP REAL)");
[/noae]

onPlayer Join
[noae]
Code: [Select]
CheckBan( player );
[/noae]

OnPlayer Command
[noae]
Code: [Select]
else if (cmd == "ban")
{
if (!stats[player.ID].Registered) return MessagePlayer("[#ff0000]Error: [#ffffff]You don't have permission to use this command.",player);
else if (!stats[player.ID].Logged) return MessagePlayer("[#FF0000]You're Not Logged in.", player);
else if ( stats[ player.ID ].Level < 3 ) return MessagePlayer("[#FF0000]You don't have Authorization to to use this command.", player);
else if ( !text ) PrivMessage( player, format( "Error: Use /%s <player> Days Hours Reason", cmd ) );
else
{
local plr = GetPlayer( GetTok( text, " ", 1 ) );
if ( plr )
{
local d = GetTok( text, " ", 2 ), h = GetTok( text, " ", 3 );
local reason = GetTok( text, " ", 4 NumTok( text, " " ) );
if (!IsNum(d)) return MessagePlayer("[#FF0000]Error: Days Must be in integers.",player);
else if (!IsNum(h)) return MessagePlayer("[#FF0000]Error: Hours Must be in integers.",player);
else if (!reason) return MessagePlayer("[#FF0000]ERROR: Reason is Missing.",player);
else if ( reason && d && h && IsNum( d ) && IsNum( h ) ) Ban( plr, player.Name, reason, d.tointeger(), h.tointeger() );
}
else MessagePlayer("Invalid Player.",player);
}
        return 0;
}


else if (cmd == "unban")
{
        if(stats[player.ID].Level < 3) MessagePlayer("[#ff0000]Error: [#ffffff]You don't have permission to use this command.",player);
        else if (!text) MessagePlayer("Correct syntax - /"+cmd+" Full player name",player);
else
{
DelBan( player.Name, text );
Message("[#ffffff]"+player.Name + "[#25A5F9] has unbanned[#ffffff] ( " + text + " ) ");
}
        return 0;
}
[/noae]

Functions
[noae]
Code: [Select]
function Ban( player, admin, reason, d, h )
{
local name = player.Name.tolower(), Time = time() + d * 86400 + h * 3600;
QuerySQL( DataBase, "INSERT INTO Bans ( Name, UID, UID2, Admin, Reason, Time, IP ) VALUES ( '" + name + "', '" + player.UniqueID + "', '" + player.UniqueID2 + "', '" + admin + "', '" + reason + "', '" + Time.tointeger() + "', '" + player.IP + "')" );
Message( admin + " banned " + name + ", reason:[ " + reason + " ] time: [ " + d + " days, " + h + " hours ]." );
KickPlayer( player );
}
function GetLastDay( t1, t2 )
{
    local time = t2 - t1, min = ( time / 60 ).tointeger(), week = 0, hour = 0, day = 0;
while( min >= 60 ) { hour += 1; min -= 60; }
while( hour >= 24 ) { day += 1; hour -= 24; }
while( day >= 7 ) { week += 1; day -= 7; }
return ( week == 0 ? day + " days " + hour + " hours " + min + " minutes" : week + " weeks " + day + " days" );
}
function CheckBan( plr )
{
local q = QuerySQL( DataBase, "SELECT * FROM Bans WHERE UID='" + plr.UniqueID + "'" ), q2, q3;
if ( q )
{
local time1 = GetSQLColumnData( q, 5 ).tointeger();
if ( time1 && time() >= time1 )
{
QuerySQL( DataBase, "DELETE FROM Bans WHERE UID='" + plr.UniqueID + "'" );
FreeSQLQuery(q);
return false;
}
    local admin = GetSQLColumnData( q, 3 ), reason = GetSQLColumnData( q, 4 ), relname = GetSQLColumnData( q, 0 );

Message( "Player-Banned [ " + plr.Name + " ], Admin:[ " + admin + " ], Reason:[ " + reason + " ], Time Left:[ " + GetLastDay( time(), time1 ) + " ]." );
    KickPlayer( plr );
FreeSQLQuery( q );
return true;
}
else
{
q2 = QuerySQL( DataBase, "SELECT * FROM Bans WHERE IP='" + plr.IP + "'" );
if ( q2 )
{
local time1 = GetSQLColumnData( q2, 5 ).tointeger();
if ( time1 && time() >= time1 )
{
QuerySQL( DataBase, "DELETE FROM Bans WHERE IP='" + plr.IP + "'" );
FreeSQLQuery(q2);
return false;
}
      local admin = GetSQLColumnData( q2, 3 ), reason = GetSQLColumnData( q2, 4 ), relname = GetSQLColumnData( q2, 0 );

Message( "Player-Banned [ " + plr.Name + " ], Admin:[ " + admin + " ], Reason:[ " + reason + " ], Time Left:[ " + GetLastDay( time(), time1 ) + " ]." );
    KickPlayer( plr );
FreeSQLQuery( q2 );
return true;
}
else
{
q3 = QuerySQL( DataBase, "SELECT * FROM Bans WHERE LOWER(Name)='" + plr.Name.tolower() + "'" );
if ( q3 )
{
local time1 = GetSQLColumnData( q3, 5 ).tointeger();
if ( time1 && time() >= time1 )
{
QuerySQL( DataBase, "DELETE FROM Bans WHERE LOWER(Name)='" + plr.Name + "'" );
FreeSQLQuery(q3);
return false;
}
      local admin = GetSQLColumnData( q3, 3 ), reason = GetSQLColumnData( q3, 4 ), relname = GetSQLColumnData( q3, 0 );

Message( "Player-Banned [ " + plr.Name + " ], Admin:[ " + admin + " ], Reason:[ " + reason + " ], Time Left:[ " + GetLastDay( time(), time1 ) + " ]." );
    KickPlayer( plr );
FreeSQLQuery( q3 );
return true;
}
}
}
try
{
FreeSQLQuery( q );
if ( q2 ) FreeSQLQuery( q2 );
if ( q3 ) FreeSQLQuery( q3 );
}
catch(e)
return false;
}

function DelBan( admin, banned )
{
QuerySQL( DataBase, "DELETE FROM Bans WHERE Name='" + banned.tolower() + "'" );
Message( "done." );
}
[/noae]
« Last Edit: July 18, 2021, 09:34:40 am by gito baloch »