Sonmez

  • Newbie
  • Yo! It's time to play the fair game!
  • Posts: 15
Ban System
«  »Last edited
Code: [Select]
function onScriptLoad()
{
  Bans <- ConnectSQL( "Bans.db" );
QuerySQL( Bans, "CREATE TABLE IF NOT EXISTS Reason ( Name TEXT, Admin TEXT, Reason TEXT)" );
 QuerySQL( Bans, "CREATE TABLE IF NOT EXISTS Bans ( Name TEXT, IP VARCHAR(25), UID1 VARCHAR(25), UID2 VARCHAR(25), Time VARCHAR(255) DEFAULT CURRENT_TIMESTAMP, Trys NUMERIC DEFAULT 0)" );
  print("Ban system by Sonmez loaded.");
}
function onPlayerJoin(player)
{
BanControl(player);
}
function BanInf( p )
 {
    local q = QuerySQL( Bans, "SELECT * FROM Bans WHERE Name='" + p + "'" );
    local name = GetSQLColumnData( q, 0 );
    if ( name ) return 1;
    else return 0;
  }
 function BanControl( player )
 {
 local q = QuerySQL(Bans, format( "SELECT * FROM Bans WHERE Name = '%s' OR IP = '%s' OR UID1 = '%s' OR UID2 = '%s'", player.Name, player.IP, player.UniqueID, player.UniqueID2 ) );
 if (q)
 {
 KickPlayerR(player , player.Name);
 }
 }
 function KickPlayerR(player, name)
{
local q = QuerySQL(Bans, "SELECT * FROM Bans WHERE Name = '" + escapeSQLString(name) + "'");
 if (q)
 {
 local Trys = GetSQLColumnData(q, 5);
 if (Trys == 4)
 {
 KickPlayer(player);
 return false;
 }
 else
 {
 Message("[#ffffff]" + name + " [#e0e0e0] AutoKicked (Banned).");
 local Tryss = GetSQLColumnData(q, 5);
 Tryss += 1;
QuerySQL( Bans, "UPDATE Bans SET Trys='"+Tryss+"' WHERE Name LIKE '" + name + "'" );
 }
 }
KickPlayer(player);
}

  function onPlayerCommand( player, cmd, text )
{
  if ( cmd == "ban" )
       {
  if ( !text ) MessagePlayer( "[#ffffff]/" + cmd + " <nick or id> <reason>", player );
  else
  {
  local plr = GetPlayer( GetTok( text, " ", 1 ) );
  if ( !plr ) MessagePlayer( "[#ffffff]**Unknown Player '"+plr+"' **", player );
  else
  {
  local reason = GetTok( text, " ", 2 );
  local now = date();
  if ( reason == null ) {MessagePlayer( "[#ffffff]/" + cmd + " <nick or id> <reason>", player ); return false;}
  {
  QuerySQL( Bans, "INSERT INTO Reason ( Name, Admin, Reason) VALUES ( '" + plr.Name + "', '" + player.Name + "', '" + reason + "' )" );
  QuerySQL( Bans, "INSERT INTO Bans ( Name, IP, UID1, UID2, Time, Trys ) VALUES ( '" + plr.Name + "', '" + plr.IP + "', '" + plr.UniqueID + "', '" + plr.UniqueID2 + "', '"+ now.year +"/"+now.month+"/"+now.day+"/"+now.hour+":"+ now.min + "', '" + 0 + "' )" );
 Message( "[#ffffff]Admin " + player.Name + " banned " + plr.Name + " Reason: " + reason + "");
  KickPlayer( plr );
  }
  }
  }
  }
  else if ( cmd == "unban" )
  {
  if ( !text ) MessagePlayer( "[#ffffff]/" + cmd + " <Full Nick>", player );
  else if ( BanInf( text ) == 0 ) MessagePlayer( "[#ffffff]" + text + " isn't banned.", player );
  else
  {
    QuerySQL( Bans, "DELETE FROM Bans WHERE Name='" + text + "'" );
  Message( "[#ffffff]Admin " + player.Name + " UnBanned " +  text + ".");
  }
  }
}


function GetPlayer( plr )
{
if ( plr )
{
if ( IsNum( plr ) )
{
plr = FindPlayer( plr.tointeger() );
if ( plr ) return plr;
else return false;
}
else
{
plr = FindPlayer( plr );
if ( plr ) return plr;
else return false;
}
}
else return false;
}
function GetTok(string, separator, n, ...)
{
    local m = vargv.len() > 0 ? vargv[0] : n,
    tokenized = split(string, separator),
    text = "";
    if (n > tokenized.len() || n < 1) return null;
    for (; n <= m; n++)
    {
        text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
    }
    return text;
}

function NumTok(string, separator)
{
    local tokenized = split(string, separator);
    return tokenized.len();
}



Good Luck...
if (!perfect) createAgain();

AroliS^

  • Newbie
  • Learning of Mike Tyson K.O
  • Posts: 45
Re: Ban System
« Reply #1,  »Last edited
You can make it better you did too much code for a simple script!

Code: [Select]

 function BanControl( player )
 {
 local q = QuerySQL(Bans, format( "SELECT * FROM Bans WHERE Name = '%s' OR IP = '%s' OR UID1 = '%s' OR UID2 = '%s'", player.Name, player.IP, player.UniqueID, player.UniqueID2 ) );
 if (q) {
 #<!-- your stuffs here --!>
 }
 }

KrooB

  • Full Member
  • BEN TÜRKÜM
  • Posts: 117
Re: Ban System
« Reply #2,  »
I think the system also saving mum's number ;D
We are his people !
Who can challange us ?

Sonmez

  • Newbie
  • Yo! It's time to play the fair game!
  • Posts: 15
Re: Ban System
« Reply #3,  »
Quote from AroliS^ on June 5th, 12:41 AM
You can make it better you did too much code for a simple script!

Code: [Select]

 function BanControl( player )
 {
 local q = QuerySQL(Bans, format( "SELECT * FROM Bans WHERE Name = '%s' OR IP = '%s' OR UID1 = '%s' OR UID2 = '%s'", player.Name, player.IP, player.UniqueID, player.UniqueID2 ) );
 if (q)
 {
 #<!-- your stuffs here --!>
 }
 }
Thanks. I changed now.
if (!perfect) createAgain();