•  
Welcome, Guest. Please login or register.

News:


Author Topic: [SQUIRREL] Rocky's Ban System  (Read 6455 times)

Offline Rocky

  • [MK]
  • Godfather
  • *
  • Posts: 359
  • Karma: +0/-0
    • View Profile
[SQUIRREL] Rocky's Ban System
« on: September 23, 2012, 05:47:44 am »
Rocky's Ban System

I made this ban system for PsyShell owned by Thomas, this script uses a new array method which is useful storing data, i have to thank X_94 for showing me this wonderful method. these functions also free query after use so no need to be afraid of memory leaks. Also date and reason will be stored on database you can take a look with SQL database browzer.

Code: [Select]
BannedIPs <- [];  //Banned IPs will be stored here
BannedNicks <- []; //Banned Nicks will be stored here

//Load up ban data into array.
function onScriptLoad( )
{
         LoadModule("sq_lite");
database <- ConnectSQL("Banlist.db");
LoadBansInMemory(); //Load ban files into array.
print( "Banlist loaded!" );
}

//Disconnect database.
function onScriptUnload( )
{
DisconnectSQL( database );
}

Ban data loading function

Code: [Select]
function LoadBansInMemory()
{
    local query = QuerySQL(database, "CREATE TABLE IF NOT EXISTS Banlist ( Nick TEXT, Reason TEXT, Date TEXT, IP TEXT)" );
FreeSQLQuery( query );

//Store data into array.
    local q = QuerySQL( database, "SELECT Nick, Reason, Date, IP FROM Banlist" );
    while ( GetSQLColumnData ( q, 0 ) )
{
BannedIPs.push( GetSQLColumnData( q, 3 ).tostring() );
BannedNicks.push( GetSQLColumnData( q, 0 ).tostring() );

GetSQLNextRow( q );
}
     FreeSQLQuery( q );
}

Ban player function

Code: [Select]
//Function to ban a player.
function BanPlayer( admin, player, reason )
{
      if( BannedIPs.find( player.IP.tostring() ) == null )
  {
             BannedIPs.push( player.IP.tostring() );
         BannedNicks.push( player.Name.tolower() );
                 local q = QuerySQL( database,"INSERT INTO Banlist ( Nick, Reason, Date, IP) VALUES ( '"+player.Name+"', '"+reason+"',  '"+GetFullTime()+"', '"+player.IP+"')" );
                 FreeSQLQuery( q );
                 Message( "[BAN] Banned: " + player + " by: " + admin + " for: " + reason);
                 KickPlayer( player );

  }
}

Unban functions

Code: [Select]

//Function to unban a player using IP.
function UnbanFromIP( ip )
{
          if( BannedIPs.find( ip.tostring() ) != null )
          {
                local query = QuerySQL( database, "SELECT Nick FROM Banlist WHERE IP='" + ip + "' COLLATE NOCASE" );
local nickname = GetSQLColumnData( query, 0 );
FreeSQLQuery( query );
query = QuerySQL( database,"DELETE FROM Banlist WHERE Nick='" +nickname+ "' COLLATE NOCASE" );
FreeSQLQuery( query );
                    BannedNicks.remove( BannedNicks.find( nickname.tostring() ) );
BannedIPs.remove( BannedIPs.find( ip.tostring() ) );
  }
}

//Function to unban a player from their nickname.
function UnbanFromNick( nickname )
{
          if( BannedNicks.find( nickname.tostring() ) != null )
          {
                local query = QuerySQL( database, "SELECT IP FROM Banlist WHERE Nick='" + nickname + "' COLLATE NOCASE" );
                    local ip = GetSQLColumnData( query, 0 );
FreeSQLQuery( query );
query = QuerySQL( database,"DELETE FROM Banlist WHERE Nick='" +nickname+ "' COLLATE NOCASE" );
FreeSQLQuery( query );
                    BannedNicks.remove( BannedNicks.find( nickname ) );
BannedIPs.remove( BannedIPs.find( ip.tostring() ) );
  }
}

Checking

Code: [Select]
function onPlayerJoin( player )
{
// Check if the name is banned
    if( ( BannedNicks.find( player.Name.tolower() ) != null ) || ( BannedIPs.find( player.IP.tostring() ) != null ) )
{
        Message("[BAN] Auto-Kicking: " + player.Name + " for Ban Evading.");
KickPlayer( player );
return;
}
}

function useful to find a string is in IP format or not, used for /c unbanip command.

Code: [Select]
function IsStringIP( string )
{
        local Format = split(string, ".");
        if( Format != 4 ) return false;
return true;
}

Version v1.0
Coded by Rocky

I have tested it and it works, if you have found any bugs for suggestions either pm me or post here.
BBC Copypaste from Squirrel forum

Offline Moric

  • Global Moderator
  • Godfather
  • *
  • Posts: 625
  • Karma: +0/-0
  • Nothing Personal!!!!
    • View Profile
Re: [SQUIRREL] Rocky's Ban System
« Reply #1 on: September 23, 2012, 08:13:34 am »
gj  ;)
https://mk.vc-mp.net/forum/gallery/?sa=view;pic=24

"Never argue with an idiot because he/she will drag you down to his level and then beat you with experience."

Offline Rocky

  • [MK]
  • Godfather
  • *
  • Posts: 359
  • Karma: +0/-0
    • View Profile
Re: [SQUIRREL] Rocky's Ban System
« Reply #2 on: September 24, 2012, 03:55:20 pm »

Offline Pegasus

  • Bully
  • *
  • Posts: 68
  • Karma: +0/-0
  • Pro Kill3r
    • View Profile
Re: [SQUIRREL] Rocky's Ban System
« Reply #3 on: October 23, 2012, 07:00:20 pm »
Nice 1  ;)