• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Ban user for a time

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
4 posts • Page 1 of 1

Postby andro » Tue Mar 09, 2010 4:19 pm

This make possible to ban user for example 60 minuts after thet time he can cheat (sorry for my bad English)
Make backup of your chat before start editing source code.

Ban time usage
/bantime {user} {time in minutes} [{reason}]
ex. /bantime user3 60

/bantimelist

/unbantime [user]
ex. /unbantime user3

/unbantime /all

don't forgot /rehash after modification

Finde in pfc/src/proxies/auth.class.php
Code: Select all
      if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist);
      $nickid = $u->nickid;
      if (in_array($nickid,$banlist))
      {
        // the user is banished, show a message and don't forward the /join command
        $msg = _pfc("Can't join %s because you are banished", $param);
        $xml_reponse->script("pfc.handleResponse('".$this->proxyname."', 'ban', '".addslashes($msg)."');");
        return false;
      }

Replace width
Code: Select all
      if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist);
      $nickid = $u->nickid;
      if (in_array($nickid,$banlist))
      {
        // the user is banished, show a message and don't forward the /join command
        $msg = _pfc("Can't join %s because you are banished", $param);
        $xml_reponse->script("pfc.handleResponse('".$this->proxyname."', 'ban', '".addslashes($msg)."');");
        return false;
      }
    
     // ban time list
     $bantimelist = $container->getChanMeta($chan, 'bantimelist_nickid');
     if ($bantimelist == NULL) $bantimelist = array(); else $bantimelist = unserialize($bantimelist);
     $nickid = $u->nickid;
     foreach ($bantimelist as $tempone) {
       if($tempone[0] == $nickid && $tempone[1] > date('c')){
      // the user is banished, show a message and don't forward the /join command
      $wr = "Can't join %s because you are banished to time ".$tempone[1];
        $msg = _pfc($wr, $param);
        $xml_reponse->script("pfc.handleResponse('".$this->proxyname."', 'ban', '".addslashes($msg)."');");
        return false;      
      }
     }

Make file pfc/src/commands/bantime.class.php
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_bantime extends pfcCommand
{
  var $usage = "/bantime {nickname} {time} [ {reason} ]";
 
  function run(&$xml_reponse, $p)
  {
    $clientid    = $p["clientid"];
    $param       = $p["param"];
    $params      = $p["params"];
    $sender      = $p["sender"];
    $recipient   = $p["recipient"];
    $recipientid = $p["recipientid"];
   
    $c =& pfcGlobalConfig::Instance();
    $u =& pfcUserConfig::Instance();

    $nick   = isset($params[0]) ? $params[0] : '';
    $timeban = isset($params[1]) ? $params[1] : '';
   $reason = isset($params[2]) ? $params[2] : '';
   
    if ($reason == '') $reason = _pfc("no reason");

    // to allow unquotted reason
    if (count($params) > 2)
      for ($x=2;$x<count($params);$x++)
        $reason.=" ".$params[$x];
   
    $channame = $u->channels[$recipientid]["name"];
   
    if ($nick == '')
    {
      // error
      $cmdp = $p;
      $cmdp["param"] = _pfc("Missing parameter");
      $cmdp["param"] .= " (".$this->usage.")";
      $cmd =& pfcCommand::Factory("error");
      $cmd->run($xml_reponse, $cmdp);
      return;
    }
   
   if (timeban == '')
    {
      // error
      $cmdp = $p;
      $cmdp["param"] = _pfc("Missing parameter");
      $cmdp["param"] .= " (".$this->usage.")";
      $cmd =& pfcCommand::Factory("error");
      $cmd->run($xml_reponse, $cmdp);
      return;
    }

    $ct =& pfcContainer::Instance();
    $nickidtoban = $ct->getNickId($nick);
   
    // notify all the channel
    $cmdp = $p;
    $cmdp["param"] = _pfc("%s banished from %s by %s for %s minuts" , $nick, $channame, $sender, $timeban);
    $cmdp["flag"]  = 1;
    $cmd =& pfcCommand::Factory("notice");
    $cmd->run($xml_reponse, $cmdp);
   
    // kick the user (maybe in the future, it will be dissociate in a /kickban command)
    $cmdp = $p;
    $cmdp["params"]   = array();
    $cmdp["params"][] = $nick; // nickname to kick
    $cmdp["params"][] = $reason; // reason
    $cmd =& pfcCommand::Factory("kick");
    $cmd->run($xml_reponse, $cmdp);

    // update the recipient banlist
    $bantimelist = $ct->getChanMeta($recipient, 'bantimelist_nickid');
       if ($bantimelist == NULL)
      $bantimelist = array();
    else
       $bantimelist = unserialize($bantimelist);
   
   // searching a removeing old bans
     $updated = false;
     $newban = array();
     foreach ($bantimelist as $tempone) {
       if($tempone[1] > date('c'))
         $newban[]=$tempone;
     }   
     $bantimelist = $newban;
   
   $bantimelist[] = array($nickidtoban, date('c', mktime(date("H"),date("i")+$timeban,date("s"),date("m"),date("d"),date("Y"))));
   // append the nickid to the banlist
    $ct->setChanMeta($recipient, 'bantimelist_nickid', serialize($bantimelist));
  }
}

?>

Make file pfc/src/commands/bantimelist.class.php
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

/**
 * This command list the banished users on the given channel
 *
 * @author Stephane Gully <stephane.gully@gmail.com>
 */
class pfcCommand_bantimelist extends pfcCommand
{
  var $desc = "This command list the banished users on the given channel";
 
  function run(&$xml_reponse, $p)
  {
    $c =& pfcGlobalConfig::Instance();
    $u =& pfcUserConfig::Instance();
   
    $ct =& pfcContainer::Instance();
    $bantimelist = $ct->getChanMeta($p["recipient"], 'bantimelist_nickid');
       
    if ($bantimelist == NULL) $bantimelist = array(); else $bantimelist = unserialize($bantimelist);
    $msg  = "";
    $msg .= "<p>"._pfc("The banished user list is:")."</p>";
    if (count($bantimelist)>0)
    {
     $msg .= "<ul>";
     foreach ($bantimelist as $tempone) {
//      foreach ($tempone as $key=>$temptwo) {
//        echo $key.":".$temptwo."n";
//      }
//      echo "</br>";
      $n = $ct->getNickname($tempone[0]);
      $msg .= "<li style="margin-left:50px">".$n." to time: ".$tempone[1]." Time: ".date("c")."</li>";
     }
     $msg .= "</ul>";
    }
    else
    {
      $msg .= "<p>("._pfc("Empty").")</p>";
    }
    $msg .= "<p>"._pfc("'/unban {nickname}' will unban the user identified by {nickname}")."</p>";
    $msg .= "<p>"._pfc("'/unban all'  will unban all the users on this channel")."</p>";
     
    $xml_reponse->script("pfc.handleResponse('banlist', 'ok', '".addslashes($msg)."');");
  }
}

?>

Make file pfc/src/commands/unbantime.class.php
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_unbantime extends pfcCommand
{
  var $usage = "/unbantime {nickname}";
 
  function run(&$xml_reponse, $p)
  {
    $clientid    = $p["clientid"];
    $param       = $p["param"];
    $params      = $p["params"];
    $sender      = $p["sender"];
    $recipient   = $p["recipient"];
    $recipientid = $p["recipientid"];
   
    $c =& pfcGlobalConfig::Instance();
    $u =& pfcUserConfig::Instance();

    $ct =& pfcContainer::Instance();

    $nick = isset($params[0]) ? $params[0] : '';
    $nickid = $ct->getNickId($nick);
     
    if ($nick == "")
    {
      // error
      $cmdp = $p;
      $cmdp["param"] = _pfc("Missing parameter");
      $cmdp["param"] .= " (".$this->usage.")";
      $cmd =& pfcCommand::Factory("error");
      $cmd->run($xml_reponse, $cmdp);
      return;
    }

   
    $updated = false;
    $msg = "<p>"._pfc("Nobody has been unbantimeished")."</p>";
   
    // update the recipient banlist
    $bantimelist = $ct->getChanMeta($recipient, 'bantimelist_nickid');
    if ($bantimelist == NULL)
      $bantimelist = array();
    else
      $bantimelist = unserialize($bantimelist);
    $nb = count($bantimelist);
   $allnickid=array();
   $newban = array();
   foreach ($bantimelist as $tempone) {
       if($tempone[0] != $nickid)
      $newban[]=$tempone;
      else
      $updated = true;
   }
    if ($updated){ 
     $ct->setChanMeta($recipient, 'bantimelist_nickid', serialize($newban));
      $msg = "<p>"._pfc("%s has been unbantimeished", $nick)."</p>";
    }
    else if ($nick == "all") // @todo move the "/unbantime all" command in another command /unbantimeall
    {
      $bantimelist = array();
      $ct->setChanMeta($recipient, 'bantimelist_nickid', serialize($bantimelist));
      $updated = true;
      $msg = "<p>"._pfc("%s users have been unbantimeished", $nb)."</p>";
    }
   
    if ($updated)
      $xml_reponse->script("pfc.handleResponse('unban', 'ok', '".$msg."');");
    else
      $xml_reponse->script("pfc.handleResponse('unban', 'ko', '".$msg."');");
  }
}

?>

When you find a fail write comment.
Last edited by andro on Tue Mar 09, 2010 4:20 pm, edited 1 time in total.
andro
New member
 
Posts: 5
Joined: Tue Mar 09, 2010 2:12 pm
Top

Postby carlis » Thu Jul 08, 2010 6:26 pm

Does it ban IPs or only nicknames?
carlis
New member
 
Posts: 6
Joined: Thu Jul 08, 2010 6:22 pm
Top

Postby Jaybird » Sat Jul 10, 2010 2:15 am

looks like it only bans via nick names..
Jaybird
Member
 
Posts: 65
Joined: Mon Jun 28, 2010 7:59 am
Top

Postby andro » Tue Jul 13, 2010 2:00 pm

I have maid another http://www.phpfreechat.net/forum/viewtopic.php?id=4460 this modul block IP for time.
andro
New member
 
Posts: 5
Joined: Tue Mar 09, 2010 2:12 pm
Top


Post a reply
4 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 5 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub