login
April 27, 2024, 10:49:51 pm

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

0 Members and 1 Guest are viewing this topic.

GiTo

  • Regular
  • ***
  • Posts: 78
  • Country: pk
    • View Profile
( Simple ) Ban System.
« on: July 11, 2021, 06:41:06 am »
Ban System (DURATION)


Creating Database
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)");

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

OnPlayer Command
Code: [Select]
else if (cmd == "ban")
{
if (!stats[player.ID].Registered) return MessagePlayer("[#ff0000]Error: [#ffffff]You should be registered 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;
}

Functions
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." );
}
« Last Edit: July 18, 2021, 08:31:01 am by GiTo »
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

What happens when the poison expires?

Mody

  • Vice Underdog Rookie
  • Regular
  • *
  • Posts: 90
  • Country: eg
    • View Profile
Re: Ban System With Duration.
« Reply #1 on: July 11, 2021, 09:22:18 am »
Code: [Select]
if (!stats[player.ID].Registered) return MessagePlayer("[#ff0000]Error: [#ffffff]You don't have permission to use this command.",player);
If player isn't registered return "you don't have permission"? Shouldn't it be "You're not registered"? 🤨
« Last Edit: July 11, 2021, 09:24:01 am by Mody »
Agree Agree x 1 Funny Funny x 2 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

Vice Underdog Trainee | Mortal Bot - Developer | VFS - Manager | VCDM - Administrator

GiTo

  • Regular
  • ***
  • Posts: 78
  • Country: pk
    • View Profile
Re: Ban System With Duration.
« Reply #2 on: July 11, 2021, 04:36:06 pm »
Code: [Select]
if (!stats[player.ID].Registered) return MessagePlayer("[#ff0000]Error: [#ffffff]You don't have permission to use this command.",player);
If player isn't registered return "you don't have permission"? Shouldn't it be "You're not registered"? 🤨

haha bro it just a lil mistake btw thanks fixed  8)
Useful Useful x 1 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

What happens when the poison expires?