February 24, 2018, 04:01:20 am

Author Topic: [RBS] Rocky's Temp-Ban system  (Read 1224 times)

0 Members and 1 Guest are viewing this topic.

[MK]Rocky

  • Newbie
  • *
  • Posts: 8
  • Country: in
    • View Profile
    • Awards
[RBS] Rocky's Temp-Ban system
« on: December 07, 2013, 01:59:27 pm »
Rocky's Temporary Ban System
Some people have been asking me for a Temp-Ban system so here it is, To use it simple log in as admin and type /c tempban <player> <days:hours:mins>
Here's the code:

Code: [Select]
/*
        [RBG] Rocky's Temp-Ban system (v0.1)
This is completly made by me,
You are free to use, modify it for your own use.
Put my name on credits list only if you like my work.
*/
//Events ->
function onScriptLoad()
{
     LoadModule( "sq_lite" );
database <- ConnectSQL( "Data.sqlite" );
     QuerySQL( database, "CREATE TABLE IF NOT EXISTS Banned( ban_nick TEXT, ban_ip TEXT, ban_time TEXT, ban_expire TEXT, ban_expireratio TEXT, ban_admin TEXT, ban_reason TEXT )" );
print("[RBAN] Rocky's Ban system Loaded (v0.1)");
}        

function onPlayerCommand( player, cmd, text )
{
     cmd = cmd.tolower();
     if ( cmd == "tempban" )
     {
      local txt_Split;
          if( !player.IsAdmin ) PrivMessage("[RBAN] You are not a admin.", player );
          else if( !text ) PrivMessage("[RBAN] /c tempban <player> <day:hour:min> <reason>", player);
          else
          {
                if( NumTok( text, " " ) == 2 )
{
     txt_Split = split( text, " " );
local plr = FindPlayer( txt_Split[ 0 ] ), expire = txt_Split[ 1 ];
if( plr ) AddBan( player, plr, expire );
else PrivMessage("[RBAN] No such player.", player );
}
else if( NumTok( text, " " ) >= 3 )
{
     txt_Split = split( text, " " );
                     local plr = FindPlayer( txt_Split[ 0 ] ), expire = txt_Split[ 1 ], reason = txt_Split[ 2 ];
if( plr ) AddBan( player, plr, expire, reason );
else PrivMessage("[RBAN] No such player.", player );
}
else PrivMessage("[RBAN] /c tempban <player> <day:hour:min> <reason>", player);
  }
     }
}

function onPlayerJoin( player )
{
     Banned( player );
}

//Functions ->
//Everyone is familiar with this function. :P
function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}
//This basically stores the ban info into database reason for ban is optional.
function AddBan( admin, player, expire, reason = "Not Specified" )
{
     //Equation = (DAYS*24*60*60) + (HOUR*60*60) + (MIN*60)
     local ban_Expire = split( expire, ":" ); //days:hours:minutes
if( NumTok( expire, ":" ) == 3 )
{
if( IsNum( ban_Expire[ 0 ] ) &&  IsNum( ban_Expire[ 1 ] ) && IsNum( ban_Expire[ 2 ] ) )
{
         if( ban_Expire[ 0 ].tointeger() <= 31 && ban_Expire[ 1 ].tointeger() <= 24 && ban_Expire[ 2 ].tointeger() <= 60 )
{
        local ban_Expires = ( (ban_Expire[ 0 ].tointeger()*24*60*60) + (ban_Expire[ 1 ].tointeger()*60*60) + (ban_Expire[ 2 ].tointeger()*60) ), 
                    Calc = ban_Expire[ 0 ] + " Day(s), " + ban_Expire[ 1 ] + " Hour(s), " + ban_Expire[ 2 ] + " Minute(s).",
                    query = QuerySQL( database, "INSERT INTO Banned( ban_nick, ban_ip, ban_time, ban_expire, ban_expireratio, ban_admin, ban_reason ) VALUES ( '"+ player.Name.tostring() +"','"+ player.IP.tostring() +"','"+ time().tostring() +"', '"+ ban_Expires.tostring() +"', '" + expire.tostring() + "', '"+ admin.Name.tostring() +"', '"+ reason.tostring() +"')");
FreeSQLQuery( query );
PrivMessage("[RBAN] You have been temporarily banned by " + admin.Name, player);
PrivMessage("[RBAN] Your ban is set to expire in: " + Calc, player);
KickPlayer( player );
}
}
else PrivMessage("[RBAN] Time should be numeric (day:hour:min)", admin );
}
else PrivMessage("[RBAN] Wrong format, day:hour:min (Numeric)", admin );
}
//Check if player is banned and Kick him/her.
function Banned( player )
{
      local query = QuerySQL( database, "SELECT * FROM Banned WHERE ban_nick='" + player.Name + "' COLLATE NOCASE" ), Ip = player.IP.tostring();
  if( GetSQLColumnData( query, 0 )  )
  {
        if( ( time() - GetSQLColumnData( query, 2 ).tointeger() ) >= GetSQLColumnData( query, 3 ).tointeger() )
{
    local query2 = QuerySQL( database, "DELETE FROM Banned WHERE ban_nick='" + player.Name.tostring() + "'" );
FreeSQLQuery( query2 );
    PrivMessage("[RBAN] Your ban has been expired.", player );
PrivMessage("[RBAN] Stick to the rules or you will get permanently banned.", player );
}
else
{
     local Time_Left = TimeRem( GetSQLColumnData( query, 2 ).tointeger(), GetSQLColumnData( query, 4 ) );
     //local splitban = split(  GetSQLColumnData( query, 4 ), ":"  ), Calc = splitban[ 0 ] + " Day(s), " + splitban[ 1 ] + " Hour(s), " + splitban[ 2 ] + " Minute(s).";
     PrivMessage("[RBAN] Your ban has not expired.", player );
PrivMessage("[RBAN] Your ban is set to expire in. " + Time_Left, player );
KickPlayer( player );
}
  }
  else if( GetSQLColumnData( QuerySQL( database, "SELECT * FROM Banned WHERE ban_ip='" + Ip + "'" ), 0 ) )
  {
        local query = QuerySQL( database, "SELECT * FROM Banned WHERE ban_ip='" + Ip + "'" );
        if( ( time() - GetSQLColumnData( query, 2 ).tointeger() ) >= GetSQLColumnData( query, 3 ).tointeger() )
{
    local query2 = QuerySQL( database, "DELETE FROM Banned WHERE ban_ip='" + player.IP.tostring() + "'" );
FreeSQLQuery( query2 );
    PrivMessage("[RBAN] Your ban has been expired.", player );
PrivMessage("[RBAN] Stick to the rules or you will get permanently banned.", player );
}
else
{
     local Time_Left = TimeRem( GetSQLColumnData( query, 2 ).tointeger(), GetSQLColumnData( query, 4 ).tostring() );
     //local splitban = split(  GetSQLColumnData( query, 4 ), ":"  ), Calc = splitban[ 0 ] + " Day(s), " + splitban[ 1 ] + " Hour(s), " + splitban[ 2 ] + " Minute(s).";
     PrivMessage("[RBAN] Your ban has not expired.", player );
PrivMessage("[RBAN] Your ban is set to expire in. " + Time_Left , player );
KickPlayer( player );
}
  }
  FreeSQLQuery( query );
}

//This returns the time left for ban in Day:hour:minute format.
function TimeRem( bantime,  banratio )
{
        local ban_current = time()-bantime, sp = split(banratio,":"), ban_Days, ban_Hours, ban_Minutes,
ban_Day = sp[ 0 ].tointeger(),
ban_Hour = sp[ 1 ].tointeger(),
ban_Minute = sp[ 2 ].tointeger();
ban_Days = ban_current/86400;
ban_current = ban_current%86400;
ban_Hours = ban_current/3600;
ban_current = ban_current%3600;
ban_Minutes = ban_current/60;
ban_current = ban_current%60;
print( ban_Days + ":" + ban_Hours + ":" + ban_Minutes );
ban_Day -= ban_Days;
ban_Hour -= ban_Hours;
ban_Minute -= ban_Minutes;
return ban_Day + " Day(s), " + ban_Hour + " Hour(s), " + ban_Minute + " Minutes.";
}

/*
  ~End of the code~
*/

Version: 0.1
Edits made: 0

If you find any help or if you find any bugs in the code, Post here.

Direct copy-paste from here
Disagree Disagree x 1 Useful Useful x 2 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


kennedy

  • Fanatic
  • ****
  • Posts: 140
  • Country: ve
  • American Roleplay
    • View Profile
    • Awards
Re: [RBS] Rocky's Temp-Ban system
« Reply #1 on: April 11, 2017, 04:40:22 am »
Updated use This

Place this on the top of the main.nut

Code: [Select]
const blue  = "[#4682B4]";
const blank = "[#ffffff]";

Code: [Select]
function onScriptLoad()
{
     LoadModule( "sq_lite" );
database <- ConnectSQL( "Data.sqlite" );
     QuerySQL( database, "CREATE TABLE IF NOT EXISTS Banned( ban_nick TEXT, ban_ip TEXT, ban_time TEXT, ban_expire TEXT, ban_expireratio TEXT, ban_admin TEXT, ban_reason TEXT )" );
print("[RBAN] Rocky's Ban system Loaded (v0.1)");
}

function onPlayerJoin( player )
{
Banned( player );
}

function onPlayerCommand( player, cmd, text )
{
     cmd = cmd.tolower();
     if ( cmd == "tempban" )
     {
      local txt_Split;
          if( !text ) MessagePlayer(""+blue+"[RBAN] "+blank+"tempban <player> <day:hour:min> <reason>", player);
          else
          {
                if( NumTok( text, " " ) == 2 )
{
     txt_Split = split( text, " " );
local plr = FindPlayer( txt_Split[ 0 ] ), expire = txt_Split[ 1 ];
if( plr ) AddBan( player, plr, expire );
else MessagePlayer(""+blue+"[RBAN] "+blank+"No such player.", player );
}
else if( NumTok( text, " " ) >= 3 )
{
     txt_Split = split( text, " " );
                     local plr = FindPlayer( txt_Split[ 0 ] ), expire = txt_Split[ 1 ], reason = txt_Split[ 2 ];
if( plr ) AddBan( player, plr, expire, reason );
else MessagePlayer(""+blue+"[RBAN] "+blank+" No such player.", player );
}
else MessagePlayer(""+blue+"[RBAN] "+blank+"tempban <player> <day:hour:min> <reason>", player);
  }
     }

else MessagePlayer(""+blue+"[CMD] "+blank+"Invalid command",player)
if ( text == null ) text = "NOTHING";
return 1;
}

function AddBan( admin, player, expire, reason = "Not Specified" )
{
     //Equation = (DAYS*24*60*60) + (HOUR*60*60) + (MIN*60)
     local ban_Expire = split( expire, ":" ); //days:hours:minutes
if( NumTok( expire, ":" ) == 3 )
{
if( IsNum( ban_Expire[ 0 ] ) &&  IsNum( ban_Expire[ 1 ] ) && IsNum( ban_Expire[ 2 ] ) )
{
         if( ban_Expire[ 0 ].tointeger() <= 31 && ban_Expire[ 1 ].tointeger() <= 24 && ban_Expire[ 2 ].tointeger() <= 60 )
{
        local ban_Expires = ( (ban_Expire[ 0 ].tointeger()*24*60*60) + (ban_Expire[ 1 ].tointeger()*60*60) + (ban_Expire[ 2 ].tointeger()*60) ), 
                    Calc = ban_Expire[ 0 ] + " Day(s), " + ban_Expire[ 1 ] + " Hour(s), " + ban_Expire[ 2 ] + " Minute(s).",
                    query = QuerySQL( database, "INSERT INTO Banned( ban_nick, ban_ip, ban_time, ban_expire, ban_expireratio, ban_admin, ban_reason ) VALUES ( '"+ player.Name.tostring() +"','"+ player.IP.tostring() +"','"+ time().tostring() +"', '"+ ban_Expires.tostring() +"', '" + expire.tostring() + "', '"+ admin.Name.tostring() +"', '"+ reason.tostring() +"')");
                    Message("[#FF1111][BANNED] "+blank+"Admin "+blue+""+admin.Name+" "+blank+" Banned [#FF1111]"+player.Name+" "+blue+" "+blank+"Time: [#ac6000]"+Calc+"")
MessagePlayer(""+blue+"[RBAN] "+blank+"You have been temporarily banned by " + admin.Name, player);
MessagePlayer(""+blue+"[RBAN] "+blank+"Your ban is set to expire in: " + Calc, player);
KickPlayer( player );
}
}
else MessagePlayer(""+blue+"[RBAN] "+blank+"Time should be numeric (day:hour:min)", admin );
}
else MessagePlayer(""+blue+"[RBAN] "+blank+" Wrong format, day:hour:min (Numeric)", admin );
}

function Banned( player )
{
      local query = QuerySQL( database, "SELECT * FROM Banned WHERE ban_nick='" + player.Name + "' COLLATE NOCASE" ), Ip = player.IP.tostring();
  if( query == null ) return print("player no banned");
  else if( GetSQLColumnData( query, 0 )  )
  {
        if( ( time() - GetSQLColumnData( query, 2 ).tointeger() ) >= GetSQLColumnData( query, 3 ).tointeger() )
{
    local query2 = QuerySQL( database, "DELETE FROM Banned WHERE ban_nick='" + player.Name.tostring() + "'" );
    MessagePlayer(""+blue+"[RBAN] "+blank+"Your ban has been expired.", player );
MessagePlayer(""+blue+"[RBAN] "+blank+"Stick to the rules or you will get permanently banned.", player );
}
else
{
     local Time_Left = TimeRem( GetSQLColumnData( query, 2 ).tointeger(), GetSQLColumnData( query, 4 ) );
     //local splitban = split(  GetSQLColumnData( query, 4 ), ":"  ), Calc = splitban[ 0 ] + " Day(s), " + splitban[ 1 ] + " Hour(s), " + splitban[ 2 ] + " Minute(s).";
Message("[#FF1111][BANNED] "+blue+""+player.Name+" "+blank+"Is Banned. Time: [#FF1111]"+Time_Left)
     MessagePlayer(""+blue+"[RBAN] "+blank+"Your ban has not expired.", player );
MessagePlayer(""+blue+"[RBAN] "+blank+" Your ban is set to expire in. " + Time_Left, player );
KickPlayer( player );
}
  }
  else if( GetSQLColumnData( QuerySQL( database, "SELECT * FROM Banned WHERE ban_ip='" + Ip + "'" ), 0 ) )
  {
        local query = QuerySQL( database, "SELECT * FROM Banned WHERE ban_ip='" + Ip + "'" );
        if( ( time() - GetSQLColumnData( query, 2 ).tointeger() ) >= GetSQLColumnData( query, 3 ).tointeger() )
{
    local query2 = QuerySQL( database, "DELETE FROM Banned WHERE ban_ip='" + player.IP.tostring() + "'" );
FreeSQLQuery( query2 );
    MessagePlayer(""+blue+"[RBAN] "+blank+"Your ban has been expired.", player );
MessagePlayer(""+blue+"[RBAN] "+blank+"Stick to the rules or you will get permanently banned.", player );
}
else
{
     local Time_Left = TimeRem( GetSQLColumnData( query, 2 ).tointeger(), GetSQLColumnData( query, 4 ).tostring() );
     //local splitban = split(  GetSQLColumnData( query, 4 ), ":"  ), Calc = splitban[ 0 ] + " Day(s), " + splitban[ 1 ] + " Hour(s), " + splitban[ 2 ] + " Minute(s).";
Message("[#FF1111][BANNED] "+blue+""+player.Name+" "+blank+"Is Banned. Time: [#FF1111]"+Time_Left)
     MessagePlayer(""+blue+"[RBAN] "+blank+"Your ban has not expired.", player );
MessagePlayer(""+blue+"[RBAN] "+blank+"Your ban is set to expire in. " + Time_Left , player );
KickPlayer( player );
}
  }
  FreeSQLQuery( query );
}

function TimeRem( bantime,  banratio )
{
        local ban_current = time()-bantime, sp = split(banratio,":"), ban_Days, ban_Hours, ban_Minutes,
ban_Day = sp[ 0 ].tointeger(),
ban_Hour = sp[ 1 ].tointeger(),
ban_Minute = sp[ 2 ].tointeger();
ban_Days = ban_current/86400;
ban_current = ban_current%86400;
ban_Hours = ban_current/3600;
ban_current = ban_current%3600;
ban_Minutes = ban_current/60;
ban_current = ban_current%60;
print( ban_Days + ":" + ban_Hours + ":" + ban_Minutes );
ban_Day -= ban_Days;
ban_Hour -= ban_Hours;
ban_Minute -= ban_Minutes;
return ban_Day + " Day(s), " + ban_Hour + " Hour(s), " + ban_Minute + " Minutes.";
}


And I'm where I want

Code: [Select]
function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}
« Last Edit: April 11, 2017, 12:09:30 pm by kennedy »
Useful Useful x 1 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


Dr.Shawn

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • *
  • Posts: 2138
  • Country: in
    • View Profile
    • Awards
Re: [RBS] Rocky's Temp-Ban system
« Reply #2 on: April 11, 2017, 07:06:10 am »
2013 +1 = 2014
2013 +2 = 2015
2013 +3 = 2016
2013 +4 = 2017
So you bump a 4 years old topic because u feel like updating the work of that fella ?
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


kennedy

  • Fanatic
  • ****
  • Posts: 140
  • Country: ve
  • American Roleplay
    • View Profile
    • Awards
Re: [RBS] Rocky's Temp-Ban system
« Reply #3 on: April 11, 2017, 12:10:05 pm »
2013 +1 = 2014
2013 +2 = 2015
2013 +3 = 2016
2013 +4 = 2017
So you bump a 4 years old topic because u feel like updating the work of that fella ?

I'm sorry, but is there something wrong with that?
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


Dr.Shawn

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • *
  • Posts: 2138
  • Country: in
    • View Profile
    • Awards
Re: [RBS] Rocky's Temp-Ban system
« Reply #4 on: April 11, 2017, 01:22:24 pm »
2013 +1 = 2014
2013 +2 = 2015
2013 +3 = 2016
2013 +4 = 2017
So you bump a 4 years old topic because u feel like updating the work of that fella ?

I'm sorry, but is there something wrong with that?
yes bumping is not allowed, make new post
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


kennedy

  • Fanatic
  • ****
  • Posts: 140
  • Country: ve
  • American Roleplay
    • View Profile
    • Awards
Re: [RBS] Rocky's Temp-Ban system
« Reply #5 on: April 11, 2017, 01:32:21 pm »
2013 +1 = 2014
2013 +2 = 2015
2013 +3 = 2016
2013 +4 = 2017
So you bump a 4 years old topic because u feel like updating the work of that fella ?

I'm sorry, but is there something wrong with that?
yes bumping is not allowed, make new post

But the function is not mine

Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


klein.

  • VW7 - The Triumvirate
  • Crazy Man
  • *
  • Posts: 415
  • Country: 00
  • hi
    • View Profile
    • Awards
Re: [RBS] Rocky's Temp-Ban system
« Reply #6 on: April 11, 2017, 02:20:08 pm »
nice work

Thijn

  • Forum Administrator
  • Crazy Man
  • *
  • *
  • *
  • Posts: 2801
  • Country: nl
    • View Profile
    • Awards
Re: [RBS] Rocky's Temp-Ban system
« Reply #7 on: April 11, 2017, 09:25:39 pm »
2013 +1 = 2014
2013 +2 = 2015
2013 +3 = 2016
2013 +4 = 2017
So you bump a 4 years old topic because u feel like updating the work of that fella ?

I'm sorry, but is there something wrong with that?
yes bumping is not allowed, make new post

But the function is not mine


Then link to the original post...
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

I'm not totally useless,
I can be used as an bad example ;)

"Never do Today, What you can do Tomorrow"



RobinX

  • Vice Underdog
  • Crazy Man
  • *
  • Posts: 663
  • Country: sa
  • No looking here! - Personal
    • View Profile
    • Awards
Re: [RBS] Rocky's Temp-Ban system
« Reply #8 on: May 02, 2017, 01:05:34 pm »
2013 +1 = 2014
2013 +2 = 2015
2013 +3 = 2016
2013 +4 = 2017
So you bump a 4 years old topic because u feel like updating the work of that fella ?

I'm sorry, but is there something wrong with that?
yes bumping is not allowed, make new post

But the function is not mine


Then link to the original post...
I don't find any problem here. Its going to be the same thing anyways.
Useless-bumping can be avoided but that's not the case here.

Anyways, good work(i didn't look at the code).
« Last Edit: May 02, 2017, 01:08:45 pm by RobinX »
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

-TomZ^ Creationz