Author Topic: Subnet Functions  (Read 3842 times)

Rifle168

  • Newbie
  • *
  • Posts: 12
  • Karma: +2/-1
    • View Profile
Subnet Functions
« on: March 21, 2012, 11:07:47 am »
Functions List

  • BanSubnet(player,admin,reason) : Ban a players Subnet
  • IsSubban(player) : Check if the player's Subnet is banned
  • GetSubnet(player)  : Get the players Subnet from IP


OnScriptLoad
Code: [Select]
LoadModule("lu_sqlite");Load the Module.
Code: [Select]
database <- sqlite_open( "LU/data/Subnet.subnetz" );
Code: [Select]
sqlite_query( database, "CREATE TABLE IF NOT EXISTS Subnet (Subnet FLOAT, Time TEXT, Admin TEXT, Reason TEXT )" );Create a database to store the subnet bans data

Functions

BanSubnet(player,admin,reason)
Code: [Select]
function BanSubnet(player,admin,reason)
{
   local sub = GetSubnet(player);
   sqlite_query( database,"INSERT INTO Subnet ( Subnet, Time, Admin, Reason ) VALUES ( '"+sub+"',  '"+GetFullTime()+"', '"+admin+"', '"+reason+"' )" );
   Message( "Banning Subnet:[ "+ sub +" ] by [ " + admin + " ] Reason:[ " + reason + " ]");
   KickPlayer(player);
}

IsSubban(player)
Code: [Select]
function IsSubban(player)
{
    local sub = GetSubnet(player);
    local User = sqlite_column_data( sqlite_query(database, "SELECT Admin FROM Subnet WHERE Subnet='" + sub + "'" ), 0 );
if ( User ) return User;
    else return 0;
}

GetSubnet(player)
Code: [Select]
function GetSubnet(player)
{
   local ip = player.IP.tostring();
   local sliceip = split( ip, ".");
   local ip1 = sliceip[ 0 ], ip2 = sliceip[ 1 ];
   local subnet = format(ip1 + "." + ip2 );
   return subnet;
}

USAGE: Command

Code: [Select]
if( cmd == "subban" )
{
else if ( !text ) MessagePlayer( "Error: /" +cmd+ " [Nick/ID] [Reason]", player );
else
                 {
    local plr = FindPlayer(GetTok( text, " ", 1 ));
if(!plr) MessagePlayer( "Error: No such player is online!", player );
else {
       local Reason = GetTok( text, " ", 2, NumTok( text, " " ) );
       if(!Reason)  BanSubnet(plr,player, "none");
       else BanSubnet(plr,player,Reason);
     }
}
else MessagePlayer( "You don't have access to use this command!", player );
    }

USAGE: Checking
Code: [Select]
function onPlayerJoin( player )
{
  if( IsSubban(player) )
{
    Message("Kicking:[ " + player.Name + " ] for:[ Subnet banned ] Subnet:[ " + GetSubnet(player).tostring()+ " ]");
KickPlayer(player);
}
     return 1;
}

  • If you want to view: the date of the ban, by which admin, reason or if you want to manually add subnet bans or manually delete subnet Download
  • You will also need lu_sqlite Module which can be found within the server package.
  • Thanks you and if you find any bugs please inform me :)

Scripted by: [FS]Rocky and Rifle
« Last Edit: March 21, 2012, 11:12:21 am by Rifle168 »

 

© Liberty Unleashed Team.