Пример #1
0
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     if ($param != "") {
         require_once dirname(__FILE__) . "/join.class.php";
         $recipient = pfcCommand_join::GetRecipient($param);
         $recipientid = pfcCommand_join::GetRecipientId($param);
     }
     $chanmeta = $this->_getChanMeta($recipient, $recipientid);
     //if (preg_match("/^pv_/", $recipient))
     //$this->trace($xml_reponse, 'who2', $recipient);
     // check if info didn't change since last call
     $sid = "pfc_who2_" . $c->getId() . "_" . $clientid . "_" . $recipientid;
     if (isset($_SESSION[$sid]) && $chanmeta == $_SESSION[$sid]) {
         // do not send the response to save bandwidth
         //$xml_reponse->script("pfc.handleResponse('".$this->name."', 'unchanged', '');");
     } else {
         $_SESSION[$sid] = $chanmeta;
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', " . $chanmeta . ");");
     }
 }
Пример #2
0
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     if ($param != "") {
         require_once dirname(__FILE__) . "/join.class.php";
         $recipient = pfcCommand_join::GetRecipient($param);
         $recipientid = pfcCommand_join::GetRecipientId($param);
     }
     $chanmeta = $this->_getChanMeta($recipient, $recipientid);
     $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', " . $chanmeta . ");");
 }
Пример #3
0
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     // do not allow someone to run a command if he is not online
     if (!$u->isOnline() && $this->name != 'error' && $this->name != 'connect' && $this->name != 'update') {
         $cmdp = $p;
         $cmdp["param"] = _pfc("Your must be connected to send a message");
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return false;
     }
     // protect admin commands
     $admincmd = array("kick", "ban", "unban", "op", "deop", "debug", "rehash");
     if (in_array($this->name, $admincmd)) {
         $container =& pfcContainer::Instance();
         $nickid = $u->nickid;
         $isadmin = $container->getUserMeta($nickid, 'isadmin');
         $notallowed = $this->name == 'debug' && $c->firstisadmin;
         $notallowed |= $this->name != 'debug' && !$isadmin;
         if ($notallowed) {
             $xml_reponse->script("alert('" . addslashes(_pfc("You are not allowed to run '%s' command", $this->name)) . "');");
             return false;
         }
     }
     // channels protection
     if ($this->name == "join" || $this->name == "join2") {
         $container =& pfcContainer::Instance();
         $channame = $param;
         // check the user is not listed in the banished channel list
         $chan = pfcCommand_join::GetRecipient($channame);
         $chanid = pfcCommand_join::GetRecipientId($channame);
         $banlist = $container->getChanMeta($chan, 'banlist_nickid');
         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;
         }
         if (count($c->frozen_channels) > 0) {
             if (!in_array($channame, $c->frozen_channels)) {
                 // the user is banished, show a message and don't forward the /join command
                 $msg = _pfc("Can't join %s because the channels list is restricted", $param);
                 $xml_reponse->script("pfc.handleResponse('" . $this->proxyname . "', 'frozen', '" . addslashes($msg) . "');");
                 return false;
             }
         }
     }
     // forward the command to the next proxy or to the final command
     $p["clientid"] = $clientid;
     $p["param"] = $param;
     $p["sender"] = $sender;
     $p["recipient"] = $recipient;
     $p["recipientid"] = $recipientid;
     return $this->next->run($xml_reponse, $p);
 }
Пример #4
0
 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();
     // pfcGlobalConfig
     $u =& pfcUserConfig::Instance();
     // pfcUserConfig
     $ct =& pfcContainer::Instance();
     // Connection to the chatbackend
     $nicktoinvite = isset($params[0]) ? $params[0] : '';
     $channeltarget = isset($params[1]) ? $params[1] : $u->channels[$recipientid]["name"];
     // Default: current channel
     if ($nicktoinvite == '' || $channeltarget == '') {
         // Parameters are not ok
         $cmdp = $p;
         $cmdp["params"] = array();
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return;
     }
     // check that the inviter is already in the channeltarget
     if (!$ct->isNickOnline(pfcCommand_join::GetRecipient($channeltarget), $u->nickid)) {
         $cmdp = $p;
         $cmdp["params"] = array();
         $cmdp["param"] = _pfc("You must join %s to invite users in this channel", $channeltarget);
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return;
     }
     // inviting a user: just add a join command to play to the aimed user metadata.
     $nicktoinvite_id = $ct->getNickId($nicktoinvite);
     $cmdstr = 'join2';
     $cmdp = array();
     $cmdp['param'] = $channeltarget;
     // channel target name
     $cmdp['params'][] = $channeltarget;
     // channel target name
     pfcCommand::AppendCmdToPlay($nicktoinvite_id, $cmdstr, $cmdp);
     // notify the aimed channel that a user has been invited
     $cmdp = array();
     $cmdp["param"] = _pfc("%s was invited by %s", $nicktoinvite, $sender);
     $cmdp["flag"] = 1;
     $cmdp["recipient"] = pfcCommand_join::GetRecipient($channeltarget);
     $cmdp["recipientid"] = pfcCommand_join::GetRecipientId($channeltarget);
     $cmd =& pfcCommand::Factory("notice");
     $cmd->run($xml_reponse, $cmdp);
 }
Пример #5
0
 /**
  * reset the channel identifiers
  */
 function _resetChannelIdentifier($clientid)
 {
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     $ct =& pfcContainer::Instance();
     // reset the channel identifiers
     require_once dirname(__FILE__) . "/join.class.php";
     $channels = array();
     if (count($u->channels) == 0) {
         $channels = $c->channels;
     } else {
         foreach ($u->channels as $chan) {
             $channels[] = $chan["name"];
         }
     }
     foreach ($channels as $channame) {
         $chanrecip = pfcCommand_join::GetRecipient($channame);
         $chanid = pfcCommand_join::GetRecipientId($channame);
         // reset the fromid flag
         $from_id_sid = "pfc_from_id_" . $c->getId() . "_" . $clientid . "_" . $chanid;
         $from_id = $ct->getLastId($chanrecip) - $c->max_msg;
         $_SESSION[$from_id_sid] = $from_id < 0 ? 0 : $from_id;
         // reset the oldmsg flag
         $oldmsg_sid = "pfc_oldmsg_" . $c->getId() . "_" . $clientid . "_" . $chanid;
         $_SESSION[$oldmsg_sid] = true;
     }
     // reset the private messages identifiers
     if (count($u->privmsg) > 0) {
         foreach ($u->privmsg as $recipientid2 => $pv) {
             $recipient2 = $pv['recipient'];
             // reset the fromid flag
             $from_id_sid = "pfc_from_id_" . $c->getId() . "_" . $clientid . "_" . $recipientid2;
             $from_id = $ct->getLastId($recipient2) - $c->max_msg;
             $_SESSION[$from_id_sid] = $from_id < 0 ? 0 : $from_id;
             // reset the oldmsg flag
             $oldmsg_sid = "pfc_oldmsg_" . $c->getId() . "_" . $clientid . "_" . $recipientid2;
             $_SESSION[$oldmsg_sid] = true;
         }
     }
 }
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $params = $p["params"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     $ct =& pfcContainer::Instance();
     $type = isset($params[0]) ? $params[0] : '';
     $name = isset($params[1]) ? $params[1] : '';
     $reason = isset($params[2]) ? $params[2] : '';
     if ($type != 'ch' && $type != 'pv' && $type != '') {
         // error
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return;
     }
     // get the recipientid to close (a pv or a channel)
     $id = '';
     if ($type == 'ch') {
         if ($name == '') {
             $id = $recipientid;
         } else {
             $id = pfcCommand_join::GetRecipientId($name);
         }
     } else {
         if ($type == 'pv') {
             // pv
             $pvnickid = $ct->getNickId($name);
             $nickid = $u->nickid;
             if ($pvnickid != '') {
                 // generate a pvid from the two nicknames ids
                 $a = array($pvnickid, $nickid);
                 sort($a);
                 $pvrecipient = "pv_" . $a[0] . "_" . $a[1];
                 $id = md5($pvrecipient);
             }
         } else {
             $id = $recipientid;
         }
     }
     $leavech = false;
     $leavepv = false;
     $leave_recip = '';
     $leave_id = '';
     // save the new channel list in the session
     if (isset($u->channels[$id])) {
         $leave_recip = $u->channels[$id]["recipient"];
         $leave_id = $id;
         unset($u->channels[$id]);
         $u->saveInCache();
         $leavech = true;
     }
     // save the new private messages list in the session
     if (isset($u->privmsg[$id])) {
         $leave_recip = $u->privmsg[$id]["recipient"];
         $leave_id = $id;
         unset($u->privmsg[$id]);
         $u->saveInCache();
         $leavepv = true;
     }
     if ($leavepv || $leavech) {
         // show a leave message with the showing the reason if present
         $cmdp = $p;
         $cmdp["recipient"] = $leave_recip;
         $cmdp["recipientid"] = $leave_id;
         $cmdp["flag"] = 2;
         $cmdp["param"] = _pfc("%s quit", $u->getNickname());
         if ($reason != "") {
             $cmdp["param"] .= " (" . $reason . ")";
         }
         $cmd =& pfcCommand::Factory("notice");
         $cmd->run($xml_reponse, $cmdp);
         // remove the nickname from the channel/pv
         $ct->removeNick($leave_recip, $u->nickid);
         // reset the sessions indicators
         $chanrecip = $leave_recip;
         $chanid = $leave_id;
         // reset the fromid flag
         $from_id_sid = "pfc_from_id_" . $c->getId() . "_" . $clientid . "_" . $chanid;
         $from_id = $ct->getLastId($chanrecip) - $c->max_msg;
         $_SESSION[$from_id_sid] = $from_id < 0 ? 0 : $from_id;
         // reset the oldmsg flag
         $oldmsg_sid = "pfc_oldmsg_" . $c->getId() . "_" . $clientid . "_" . $chanid;
         $_SESSION[$oldmsg_sid] = true;
         // if the /leave command comes from a cmdtoplay then show the reason to the user (ex: kick or ban reason)
         if ($p['cmdtoplay']) {
             $cmdp = $p;
             $cmdp["param"] = $reason;
             $cmd =& pfcCommand::Factory("error");
             $cmd->run($xml_reponse, $cmdp);
         }
         // return ok to the client
         // then the client will remove the channel' tab
         $xml_reponse->script("pfc.handleResponse('leave', 'ok', '" . $id . "');");
     } else {
         // error
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
     }
 }
Пример #7
0
 /**
  * Return the last $nb message from the $channel room.
  * The messages format is very basic, it's raw data (it will certainly change in future)
  */
 function getLastMsg($channel, $nb)
 {
     if ($this->hasErrors()) {
         return array();
     }
     // to be sure the $nb params is a positive number
     if (!($nb >= 0)) {
         $nb = 10;
     }
     // to get the channel recipient name
     // @todo must use another function to get a private message last messages
     $channel = pfcCommand_join::GetRecipient($channel);
     $ct =& pfcContainer::Instance();
     $lastmsg_id = $ct->getLastId($channel);
     $lastmsg_raw = $ct->read($channel, $lastmsg_id - $nb);
     return $lastmsg_raw;
 }
Пример #8
0
 function GetRecipientId($channame)
 {
     return md5(pfcCommand_join::GetRecipient($channame));
 }