tempban

Started by Coolkid, Mar 05, 2016, 01:49 AM

Previous topic - Next topic

Coolkid

hi i am having prb with my ban it gives me this error


Code'
[spoiler]
function onScriptLoad()
{
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 )
{
     NewTimer( "Banned", 3000, 1,  player ); //Check if player is banned.
}
function onPlayerCommand( player, cmd, text )
{
  cmd = cmd.tolower();
     if ( cmd == "tempban" )
     {
       local txt_Split;
          if( !text ) MessagePlayer("[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 MessagePlayer("[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 = GetTok( text, " ", 3, NumTok( text, " " ) );
      if( plr ) AddBan( player, plr, expire, reason );
      else MessagePlayer("[RBAN] No such player.", player );
    }
    else MessagePlayer("[RBAN] /c tempban <player> <day:hour:min> <reason>", player);
    }
     }
  else if( cmd == "untempban" )
  {
    if( !text ) MessagePlayer("[RBAN] /c untempban <Fullname>", player);
    else if( !IsBanned( text ) ) MessagePlayer("[RBAN]Player is not banned.", player);
    else
    {
           QuerySQL( database, "DELETE TABLE FROM Banned WHERE ban_nick='" + text + "' COLLATE NOCASE" );
     Message("Unbanned: [ " + text + " ] by Admin: [ " + player.Name + " ]" );
    }
  }
}
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 );
       MessagePlayer("[RBAN] Your ban has been expired.", player );
    MessagePlayer("[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).";
        MessagePlayer("[RBAN] Your ban has not expired.", player );
     MessagePlayer("[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 );
       MessagePlayer("[RBAN] Your ban has been expired.", player );
    MessagePlayer("[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).";
        MessagePlayer("[RBAN] Your ban has not expired.", player );
     MessagePlayer("[RBAN] Your ban is set to expire in. " + Time_Left , player );
     KickPlayer( player );
   }
   }
   FreeSQLQuery( query );
}

//GeTok function
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;
}

//Check is player is banned.
function IsBanned( fullname )
{
      local query = QuerySQL( database, "SELECT ban_ip FROM Banned WHERE ban_nick='" + fullname + "' COLLATE NOCASE" );
   if( GetSQLColumnData( query, 0 )  ) return true;
   return false;
}

//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;
  ban_Day -= ban_Days;
  ban_Hour -= ban_Hours;
  ban_Minute -= ban_Minutes;
  return ban_Day + " Day(s), " + ban_Hour + " Hour(s), " + ban_Minute + " Minutes.";

[/spoiler]

Stormeus

Have you considered actually reading the error?


.

#2
Quote from: Stormeus on Mar 05, 2016, 02:31 AMHave you considered actually reading the error?

How can they when their eyes are up their a$$. Have you ever seen someone like that read anything?
.

Coolkid

working topic lcoked thanks for help