function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $u =& pfcUserConfig::Instance();
     $nick = $u->nick;
     $ct =& pfcContainer::Instance();
     $text = trim($param);
     // Call parse roll
     require_once dirname(__FILE__) . '/demo27_dice.class.php';
     $dice = new Dice();
     if (!$dice->check($text)) {
         $result = $dice->error_get();
         $cmdp = $p;
         $cmdp["param"] = "Cmd_roll failed: " . $result;
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
     } else {
         $result = $dice->roll();
         $ct->write($recipient, $nick, "send", $result);
     }
 }
Exemple #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();
     $ct =& pfcContainer::Instance();
     if (trim($param) == "") {
         // error
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return;
     }
     // just change the "isadmin" meta flag
     $nicktoop = trim($param);
     $nicktoopid = $ct->getNickId($nicktoop);
     $ct->setUserMeta($nicktoopid, 'isadmin', true);
     $this->forceWhoisReload($nicktoopid);
 }
 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();
     $nicktochange = phpFreeChat::FilterNickname($param);
     if ($c->frozen_nick) {
         // assign a random nick
         $cmdp = $p;
         $cmdp["param"] = $nicktochange . "" . rand(1, 1000);
         $cmd =& pfcCommand::Factory("nick");
         $cmd->run($xml_reponse, $cmdp);
     } else {
         if ($nicktochange == "") {
             $nicktochange = $u->nick;
             $msg = _pfc("Please enter your nickname");
         } else {
             $msg = "'" . $nicktochange . "' is used, please choose another nickname.";
         }
         $xml_reponse->script("var newnick = prompt('" . addslashes($msg) . "', '" . addslashes($nicktochange) . "'); if (newnick) pfc.sendRequest('/nick \"'+newnick+'\"');");
     }
 }
Exemple #4
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();
     // check the user has not been disconnected from the server by timeout
     // if he has been disconnected, then I reconnect him with /connect command
     if ($u->nick != '' && !$u->isOnline()) {
         $cmd =& pfcCommand::Factory("connect");
         $cmdp = $p;
         $cmdp['params'] = array($u->nick);
         $cmdp['getoldmsg'] = false;
         $cmdp['joinoldchan'] = false;
         $cmd->run($xml_reponse, $cmdp);
     }
     // do not update if user isn't active (didn't connect)
     if ($u->isOnline()) {
         $cmdp = $p;
         // update the user nickname timestamp on the server
         $cmd =& pfcCommand::Factory("updatemynick");
         $cmdp["recipient"] = NULL;
         $cmdp["recipientid"] = NULL;
         $cmd->run($xml_reponse, $cmdp);
         // get other online users on each channels
         $cmd =& pfcCommand::Factory("who2");
         foreach ($u->channels as $id => $chan) {
             $cmdp["recipient"] = $chan["recipient"];
             $cmdp["recipientid"] = $id;
             $cmdp["param"] = '';
             // don't forward the parameter because it will be interpreted as a channel name
             $cmd->run($xml_reponse, $cmdp);
         }
         foreach ($u->privmsg as $id => $pv) {
             $cmdp["recipient"] = $pv["recipient"];
             $cmdp["recipientid"] = $id;
             $cmdp["param"] = '';
             // don't forward the parameter because it will be interpreted as a channel name
             $cmd->run($xml_reponse, $cmdp);
         }
         // get new message posted on each channels
         $cmd =& pfcCommand::Factory("getnewmsg");
         foreach ($u->channels as $id => $chan) {
             $cmdp["recipient"] = $chan["recipient"];
             $cmdp["recipientid"] = $id;
             $cmd->run($xml_reponse, $cmdp);
         }
         foreach ($u->privmsg as $id => $pv) {
             $cmdp["recipient"] = $pv["recipient"];
             $cmdp["recipientid"] = $id;
             $cmd->run($xml_reponse, $cmdp);
         }
         $xml_reponse->script("pfc.handleResponse('update', 'ok', '');");
     } else {
         $xml_reponse->script("pfc.handleResponse('update', 'ko', '');");
     }
 }
 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();
     /**
      * fixes some anoying issues with noflood not detecting user flooding the chat
      * those are notice and invite
      */
     $cmdtocheck = array("send", "nick", "me", "notice", "invite");
     // fixes the count of noflood even if the text posted was empty (Neumann Valle (UTAN))
     if (in_array($this->name, $cmdtocheck) && $param != "") {
         $container =& pfcContainer::Instance();
         $nickid = $u->nickid;
         $isadmin = $container->getUserMeta($nickid, 'isadmin');
         $lastfloodtime = $container->getUserMeta($nickid, 'floodtime');
         $flood_nbmsg = $container->getUserMeta($nickid, 'flood_nbmsg');
         $flood_nbchar = $container->getUserMeta($nickid, 'flood_nbchar');
         $floodtime = time();
         if ($floodtime - $lastfloodtime <= $c->proxies_cfg[$this->proxyname]["delay"]) {
             // update the number of posted message indicator
             $flood_nbmsg++;
             // update the number of posted characteres indicator
             $flood_nbchar += utf8_strlen($param);
         } else {
             $flood_nbmsg = 0;
             $flood_nbchar = 0;
         }
         if (!$isadmin && ($flood_nbmsg > $c->proxies_cfg[$this->proxyname]["msglimit"] || $flood_nbchar > $c->proxies_cfg[$this->proxyname]["charlimit"])) {
             // warn the flooder
             $msg = _pfc("Please don't post so many message, flood is not tolerated");
             $xml_reponse->script("alert('" . addslashes($msg) . "');");
             // kick the flooder
             $cmdp = $p;
             $cmdp["param"] = null;
             $cmdp["params"][0] = "ch";
             $cmdp["params"][1] = $u->channels[$recipientid]["name"];
             $cmdp["params"][2] .= _pfc("kicked from %s by %s", $u->channels[$recipientid]["name"], "noflood");
             $cmd =& pfcCommand::Factory("leave");
             $cmd->run($xml_reponse, $cmdp);
             return false;
         }
         if ($flood_nbmsg == 0) {
             $container->setUserMeta($nickid, 'floodtime', $floodtime);
         }
         $container->setUserMeta($nickid, 'flood_nbmsg', $flood_nbmsg);
         $container->setUserMeta($nickid, 'flood_nbchar', $flood_nbchar);
     }
     // 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);
 }
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $msg = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $flag = isset($p["flag"]) ? $p["flag"] : 7;
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     $ct =& pfcContainer::Instance();
     if ($c->shownotice > 0 && ($c->shownotice & $flag) == $flag) {
         $msg = phpFreeChat::FilterSpecialChar($msg);
         $msg = $flag == 7 ? '(' . $sender . ') ' . $msg : $msg;
         $nick = $ct->getNickname($u->nickid);
         $res = $ct->write($recipient, $nick, "notice", $msg);
         if (is_array($res)) {
             $cmdp = $p;
             $cmdp["param"] = implode(",", $res);
             $cmd =& pfcCommand::Factory("error");
             $cmd->run($xml_reponse, $cmdp);
             return;
         }
     }
 }
Exemple #7
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();
     $u =& pfcUserConfig::Instance();
     $nick = isset($params[0]) ? $params[0] : '';
     $reason = isset($params[1]) ? $params[1] : '';
     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;
     }
     $ct =& pfcContainer::Instance();
     $nickidtoban = $ct->getNickId($nick);
     // notify all the channel
     $cmdp = $p;
     $cmdp["param"] = _pfc("%s banished from %s by %s", $nick, $channame, $sender);
     $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
     $banlist = $ct->getChanMeta($recipient, 'banlist_nickid');
     if ($banlist == NULL) {
         $banlist = array();
     } else {
         $banlist = unserialize($banlist);
     }
     $banlist[] = $nickidtoban;
     // append the nickid to the banlist
     $ct->setChanMeta($recipient, 'banlist_nickid', serialize($banlist));
 }
Exemple #8
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();
     $cmd =& pfcCommand::Factory("quit");
     $cmd->run($xml_reponse, $p);
     $u->destroy();
 }
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $owner = isset($p["owner"]) ? $p["owner"] : '';
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     $ct =& pfcContainer::Instance();
     $newnick = phpFreeChat::FilterNickname($param);
     $oldnick = $ct->getNickname($u->nickid);
     if ($this->name == 'nick') {
         // if the user want to change his nickname but the frozen_nick is enable
         // then send him a warning
         if ($this->name == 'nick' && $oldnick != '' && $newnick != $oldnick && $c->frozen_nick == true && $owner != $this->proxyname) {
             $msg = _pfc("You are not allowed to change your nickname");
             $xml_reponse->script("pfc.handleResponse('" . $this->proxyname . "', 'nick', '" . addslashes($msg) . "');");
             return false;
         }
         $newnickid = $ct->getNickId($newnick);
         $oldnickid = $u->nickid;
         if ($newnick == $oldnick && $newnickid == $oldnickid) {
             $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'notchanged', '" . addslashes($newnick) . "');");
             return true;
         }
         // now check the nickname is not yet used (unsensitive case)
         // 'BoB' and 'bob' must be considered same nicknames
         $nick_in_use = $this->_checkNickIsUsed($newnick, $oldnickid);
         if ($nick_in_use) {
             if ($c->frozen_nick) {
                 $xml_reponse->script("pfc.handleResponse('nick', 'notallowed', '" . addslashes($newnick) . "');");
             } else {
                 $xml_reponse->script("pfc.handleResponse('nick', 'isused', '" . addslashes($newnick) . "');");
             }
             return false;
         }
     }
     // allow nick changes only from the parameters array (server side)
     if ($this->name != 'connect' && $c->frozen_nick == true && $oldnick != $c->nick && $c->nick != '' && $owner != $this->proxyname) {
         // change the user nickname
         $cmdp = $p;
         $cmdp["param"] = $c->nick;
         $cmdp["owner"] = $this->proxyname;
         $cmd =& pfcCommand::Factory("nick");
         return $cmd->run($xml_reponse, $cmdp);
     }
     // forward the command to the next proxy or to the final command
     return $this->next->run($xml_reponse, $p);
 }
Exemple #10
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();
     $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 unbanished") . "</p>";
     // update the recipient banlist
     $banlist = $ct->getChanMeta($recipient, 'banlist_nickid');
     if ($banlist == NULL) {
         $banlist = array();
     } else {
         $banlist = unserialize($banlist);
     }
     $nb = count($banlist);
     if (in_array($nickid, $banlist)) {
         $banlist = array_diff($banlist, array($nickid));
         $ct->setChanMeta($recipient, 'banlist_nickid', serialize($banlist));
         $updated = true;
         $msg = "<p>" . _pfc("%s has been unbanished", $nick) . "</p>";
     } else {
         if ($nick == "all") {
             $banlist = array();
             $ct->setChanMeta($recipient, 'banlist_nickid', serialize($banlist));
             $updated = true;
             $msg = "<p>" . _pfc("%s users have been unbanished", $nb) . "</p>";
         }
     }
     if ($updated) {
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', '" . $msg . "');");
     } else {
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ko', '" . $msg . "');");
     }
 }
Exemple #11
0
 /**
  * Virtual method which must be implemented by concrete commands.
  * It is called by the phpFreeChat::HandleRequest function to execute the wanted command.
  */
 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();
     $ct =& pfcContainer::Instance();
     // toggle away-status.
     $is_away = $ct->getUserMeta($u->nickid, 'away');
     // If it's on, turn it off.
     if ($is_away == 'yes') {
         $ct->setUserMeta($u->nickid, 'away', 'no');
         $is_away = 'no';
         $pfc_msg = "{$u->nick} is back";
         $away_img = $c->getFileUrlFromTheme('images/away-off.gif');
     } else {
         $ct->setUserMeta($u->nickid, 'away', 'yes');
         $is_away = 'yes';
         $pfc_msg = "{$u->nick} is away";
         $away_img = $c->getFileUrlFromTheme('images/away-on.gif');
     }
     // refresh the nick list and nick box with away-status.
     $u->saveInCache();
     $this->forceWhoisReload($u->nickid);
     // notify all the joined channels/privmsg.
     $cmdp = $p;
     //	$cmdp["param"] = _pfc($pfc_msg);
     $cmdp["param"] = $pfc_msg;
     $cmdp["flag"] = 1;
     $cmd =& pfcCommand::Factory("notice");
     foreach ($u->channels as $id => $chan) {
         $cmdp["recipient"] = $chan["recipient"];
         $cmdp["recipientid"] = $id;
         $cmd->run($xml_reponse, $cmdp);
     }
     foreach ($u->privmsg as $id => $pv) {
         $cmdp["recipient"] = $pv["recipient"];
         $cmdp["recipientid"] = $id;
         $cmd->run($xml_reponse, $cmdp);
     }
     // refresh the away button.
     $xml_reponse->script("pfc.handleResponse('" . $this->name . "', '" . $is_away . "', '" . $away_img . "');");
     return;
 }
Exemple #12
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();
     $channame = trim($param);
     $chanrecip = pfcCommand_join::GetRecipient($channame);
     $chanid = pfcCommand_join::GetRecipientId($channame);
     if ($channame == "") {
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return;
     }
     if (!isset($u->channels[$chanid])) {
         if ($c->max_channels <= count($u->channels)) {
             // the maximum number of joined channels has been reached
             $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'max_channels', Array());");
             return;
         }
         $u->channels[$chanid]["recipient"] = $chanrecip;
         $u->channels[$chanid]["name"] = $channame;
         $u->saveInCache();
         // show a join message
         $cmdp = $p;
         $cmdp["param"] = _pfc("%s joins %s", $u->getNickname(), $channame);
         $cmdp["recipient"] = $chanrecip;
         $cmdp["recipientid"] = $chanid;
         $cmdp["flag"] = 2;
         $cmd =& pfcCommand::Factory("notice");
         $cmd->run($xml_reponse, $cmdp);
     }
     // register the user (and his metadata) in the channel
     $ct =& pfcContainer::Instance();
     //    $ct->createNick($chanrecip, $u->nick, $u->nickid);
     $ct->joinChan($u->nickid, $chanrecip);
     $this->forceWhoisReload($u->nickid);
     // return ok to the client
     // then the client will create a new tab
     $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', Array('" . $chanid . "','" . addslashes($channame) . "'));");
 }
Exemple #13
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();
     $u =& pfcUserConfig::Instance();
     $nick = isset($params[0]) ? $params[0] : '';
     $reason = isset($params[1]) ? $params[1] : '';
     if ($reason == '') {
         $reason = _pfc("no reason");
     }
     // to allow unquotted reason
     if (count($params) > 2) {
         for ($x = 2; $x < count($params); $x++) {
             $reason .= " " . $params[$x];
         }
     }
     if ($nick == '') {
         // error
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return;
     }
     // kicking a user just add a command to play to the aimed user metadata.
     $ct =& pfcContainer::Instance();
     $otherid = $ct->getNickId($nick);
     $channame = $u->channels[$recipientid]["name"];
     $cmdstr = 'leave';
     $cmdp = array();
     $cmdp['flag'] = 4;
     $cmdp['params'][] = 'ch';
     $cmdp['params'][] = $channame;
     // channel name
     $cmdp['params'][] = _pfc("kicked from %s by %s - reason: %s", $channame, $sender, $reason);
     // reason
     pfcCommand::AppendCmdToPlay($otherid, $cmdstr, $cmdp);
 }
Exemple #14
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();
     $ct =& pfcContainer::Instance();
     $nick = $ct->getNickname($u->nickid);
     // leave the channels
     foreach ($u->channels as $id => $chandetail) {
         if ($ct->removeNick($chandetail["recipient"], $u->nickid)) {
             $cmdp = $p;
             $cmdp["param"] = $id;
             $cmdp["recipient"] = $chandetail["recipient"];
             $cmdp["recipientid"] = $id;
             $cmd =& pfcCommand::Factory("leave");
             $cmd->run($xml_reponse, $cmdp);
         }
     }
     // leave the private messages
     foreach ($u->privmsg as $id => $pvdetail) {
         if ($ct->removeNick($pvdetail["recipient"], $u->nickid)) {
             $cmdp = $p;
             $cmdp["param"] = $id;
             $cmdp["recipient"] = $pvdetail["recipient"];
             $cmdp["recipientid"] = $id;
             $cmd =& pfcCommand::Factory("leave");
             $cmd->run($xml_reponse, $cmdp);
         }
     }
     // leave the server
     $ct->removeNick(NULL, $u->nickid);
     /*
     // then set the chat inactive
     $u->active = false;
     $u->saveInCache();
     */
     $xml_reponse->script("pfc.handleResponse('quit', 'ok', '');");
 }
 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 (trim($param) == '') {
         // error
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return;
     }
     $xml_reponse->redirect($param);
 }
Exemple #16
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();
     $ct =& pfcContainer::Instance();
     if (trim($param) == "") {
         // error
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return;
     }
     $msg = phpFreeChat::PreFilterMsg($param);
     $ct->write($recipient, "*me*", $this->name, $u->getNickname() . " " . $msg);
 }
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     if ($this->name == 'update' || $this->name == 'connect') {
         $c =& pfcGlobalConfig::Instance();
         $u =& pfcUserConfig::Instance();
         $ct =& pfcContainer::Instance();
         // disconnect users from channels when they timeout
         $disconnected_users = $ct->removeObsoleteNick($c->timeout);
         for ($i = 0; $i < count($disconnected_users["nick"]); $i++) {
             $nick = $disconnected_users["nick"][$i];
             for ($j = 0; $j < count($disconnected_users["channels"][$i]); $j++) {
                 $chan = $disconnected_users["channels"][$i][$j];
                 if ($chan != 'SERVER') {
                     $online_users = $ct->getOnlineNick($chan);
                     if (count($online_users['nickid']) > 0) {
                         $cmdp = $p;
                         $cmdp["param"] = _pfc("%s quit (timeout)", $nick);
                         $cmdp["flag"] = 2;
                         $cmdp["recipient"] = $chan;
                         $cmdp["recipientid"] = md5($chan);
                         // @todo: clean the recipient/recipientid notion
                         $cmd =& pfcCommand::Factory("notice");
                         $cmd->run($xml_reponse, $cmdp);
                     }
                 }
             }
         }
     }
     // forward the command to the next proxy or to the final command
     return $this->next->run($xml_reponse, $p);
 }
Exemple #18
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();
     $ct =& pfcContainer::Instance();
     $nick = $ct->getNickname($u->nickid);
     //phpFreeChat::FilterSpecialChar($sender);
     $text = phpFreeChat::PreFilterMsg($param);
     //        $offline = $container->getMeta("offline", "nickname", $u->privmsg[$recipientid]["name"]);
     // if this channel is a pv (one to one channel),
     // first of all, check if the other user is connected
     // if he is not connected anymore, display an error
     $can_send = true;
     if (isset($u->privmsg[$recipientid])) {
         $pvnickid = $u->privmsg[$recipientid]["pvnickid"];
         $pvnick = $ct->getNickname($pvnickid);
         //$u->privmsg[$recipientid]["name"];
         //      $pvnickid = $ct->getNickId($pvnick);
         // now check if this user is currently online
         $onlineusers = $ct->getOnlineNick(NULL);
         if (!in_array($pvnickid, $onlineusers["nickid"])) {
             // send an error because the user is not online
             $cmdp = $p;
             $cmdp["param"] = _pfc("Can't send the message, %s is offline", $pvnick);
             $cmd =& pfcCommand::Factory("error");
             $cmd->run($xml_reponse, $cmdp);
             $can_send = false;
         }
     }
     // check the sent text is not empty and the user has a none empty nickname
     $errors = array();
     if ($text == "") {
         $errors["pfc_words"] = _pfc("Text cannot be empty");
     }
     if ($nick == "") {
         $errors["pfc_handle"] = _pfc("Please enter your nickname");
     }
     if (count($errors) > 0) {
         // an error occured, just ignore the message and display errors
         $cmdp = $p;
         $cmdp["param"] = $errors;
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         if (isset($errors["pfc_handle"])) {
             // the nick is empty so give it focus
             $xml_reponse->script("\$('pfc_handle').focus();");
         }
         $can_send = false;
     }
     // Now send the message if there is no errors
     if ($can_send) {
         $msgid = $ct->write($recipient, $nick, "send", $text);
         if (is_array($msgid)) {
             $cmdp = $p;
             $cmdp["param"] = implode(",", $msgid);
             $cmd =& pfcCommand::Factory("error");
             $cmd->run($xml_reponse, $cmdp);
             return;
         }
         // a message has been posted so :
         // - clear errors
         // - give focus to "words" field
         // @todo move this code in the handleResponse function
         $xml_reponse->script("pfc.clearError(Array('pfc_words" . "','pfc_handle" . "'));");
         $xml_reponse->script("\$('pfc_words').focus();");
     }
     $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', '');");
 }
Exemple #19
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);
 }
Exemple #20
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();
     $ct =& pfcContainer::Instance();
     if (trim($param) == '') {
         // error
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return false;
     }
     $newnick = phpFreeChat::FilterNickname($param);
     $oldnick = $ct->getNickname($u->nickid);
     $newnickid = $ct->getNickId($newnick);
     $oldnickid = $u->nickid;
     // new nickname is undefined (not used) and
     // current nickname (oldnick) is mine and
     // oldnick is different from new nick
     // -> this is a nickname change
     if ($oldnick != $newnick && $oldnick != '') {
         // really change the nick (rename it)
         $ct->changeNick($newnick, $oldnick);
         $u->nick = $newnick;
         $u->saveInCache();
         $this->forceWhoisReload($u->nickid);
         // notify all the joined channels/privmsg
         $cmdp = $p;
         $cmdp["param"] = _pfc("%s changes his nickname to %s", $oldnick, $newnick);
         $cmdp["flag"] = 1;
         $cmd =& pfcCommand::Factory("notice");
         foreach ($u->channels as $id => $chan) {
             $cmdp["recipient"] = $chan["recipient"];
             $cmdp["recipientid"] = $id;
             $cmd->run($xml_reponse, $cmdp);
         }
         foreach ($u->privmsg as $id => $pv) {
             $cmdp["recipient"] = $pv["recipient"];
             $cmdp["recipientid"] = $id;
             $cmd->run($xml_reponse, $cmdp);
         }
         $xml_reponse->script("pfc.handleResponse('nick', 'changed', '" . addslashes($newnick) . "');");
         return true;
     }
     // new nickname is undefined (not used)
     // -> this is a first connection (this piece of code is called by /connect command)
     if ($newnickid == '') {
         // this is a first connection : create the nickname on the server
         $ct->createNick($u->nickid, $newnick);
         $u->nick = $newnick;
         $u->saveInCache();
         $this->forceWhoisReload($u->nickid);
         $xml_reponse->script("pfc.handleResponse('nick', 'connected', '" . addslashes($newnick) . "');");
         return true;
     }
     return false;
 }
Exemple #21
0
 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();
     if (count($params) == 0) {
         // error
         $cmdp = $p;
         $cmdp["param"] = _pfc("Missing parameter");
         $cmdp["param"] .= " (" . $this->usage . ")";
         $cmd =& pfcCommand::Factory("error");
         $cmd->run($xml_reponse, $cmdp);
         return false;
     }
     // check the pvname exists on the server
     $pvname = '';
     $pvnickid = '';
     if ($this->name == 'privmsg2') {
         $pvnickid = $params[0];
         $pvname = $ct->getNickname($pvnickid);
     } else {
         $pvname = $params[0];
         $pvnickid = $ct->getNickId($pvname);
     }
     $nickid = $u->nickid;
     $nick = $ct->getNickname($u->nickid);
     // error: can't speak to myself
     if ($pvnickid == $nickid) {
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "','speak_to_myself');");
         return;
     }
     //$this->trace($xml_reponse, $this->name, $sender);
     // error: can't speak to unknown
     if ($pvnickid == '') {
         // remove this old pv from the privmsg list
         $pvid_to_remove = "";
         foreach ($u->privmsg as $pv_k => $pv_v) {
             if ($pv_v["name"] == $pvname) {
                 $pvid_to_remove = $pv_k;
             }
         }
         if ($pvid_to_remove != "") {
             unset($u->privmsg[$pvid_to_remove]);
             $u->saveInCache();
         }
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'unknown', Array('" . addslashes($pvname) . "','speak to unknown'));");
         return;
     }
     // generate a pvid from the two nicknames ids
     $a = array($pvnickid, $nickid);
     sort($a);
     $pvrecipient = "pv_" . $a[0] . "_" . $a[1];
     $pvrecipientid = md5($pvrecipient);
     //    $xml_reponse->script("alert('privmsg: pvnickid=".$pvnickid."');");
     //    $xml_reponse->script("alert('privmsg: pvname=".$pvname." pvrecipient=".$pvrecipient."');");
     // update the private message list
     // in the sessions
     if (!isset($u->privmsg[$pvrecipientid])) {
         if ($c->max_privmsg <= count($u->privmsg)) {
             // the maximum number of private messages has been reached
             $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'max_privmsg', Array());");
             return;
         }
         $u->privmsg[$pvrecipientid]["recipient"] = $pvrecipient;
         $u->privmsg[$pvrecipientid]["name"] = $pvname;
         $u->privmsg[$pvrecipientid]["pvnickid"] = $pvnickid;
         $u->saveInCache();
         // reset the message id indicator
         // i.e. be ready to re-get all last posted messages
         $from_id_sid = "pfc_from_id_" . $c->getId() . "_" . $clientid . "_" . $pvrecipientid;
         $from_id = $ct->getLastId($pvrecipient) - $c->max_msg - 1;
         $_SESSION[$from_id_sid] = $from_id < 0 ? 0 : $from_id;
     }
     // register the user (and his metadata) in this pv
     //    $ct->createNick($pvrecipient, $u->nick, $u->nickid);
     $ct->joinChan($nickid, $pvrecipient);
     $this->forceWhoisReload($nickid);
     // return ok to the client
     // then the client will create a new tab
     $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', Array('" . $pvrecipientid . "','" . addslashes($pvname) . "'));");
 }
 function &handleRequest($request)
 {
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     if ($c->debug) {
         ob_start();
     }
     // capture output
     $xml_reponse =& new pfcResponse();
     // check the command
     $cmdstr = "";
     $cmdname = "";
     $clientid = "";
     $recipient = "";
     $recipientid = "";
     $param = "";
     $sender = "";
     $res = pfcCommand::ParseCommand($request);
     $cmdstr = isset($res['cmdstr']) ? $res['cmdstr'] : $request;
     $cmdname = strtolower(isset($res['cmdname']) ? $res['cmdname'] : '');
     $clientid = isset($res['params'][0]) ? $res['params'][0] : '';
     $recipientid = isset($res['params'][1]) ? $res['params'][1] : "";
     $params = array_slice(is_array($res['params']) ? $res['params'] : array(), 2);
     $param = implode(" ", $params);
     // to keep compatibility (will be removed)
     $sender = $u->getNickname();
     // translate the recipientid to the channel name
     if (isset($u->channels[$recipientid])) {
         $recipient = $u->channels[$recipientid]["recipient"];
     }
     if (isset($u->privmsg[$recipientid])) {
         $recipient = $u->privmsg[$recipientid]["recipient"];
         // @todo: move this code in a proxy
         if ($cmdname != "update" && $cmdname != "leave" && $cmdname != "quit" && $cmdname != "privmsg2") {
             // alert the other from the new pv
             // (warn other user that someone talk to him)
             $ct =& pfcContainer::Instance();
             $nickidtopv = $u->privmsg[$recipientid]["pvnickid"];
             $cmdstr = 'privmsg2';
             $cmdp = array();
             $cmdp['param'] = $u->nickid;
             //$sender;
             $cmdp['params'][] = $u->nickid;
             //$sender;
             pfcCommand::AppendCmdToPlay($nickidtopv, $cmdstr, $cmdp);
         }
     }
     $cmdp = array();
     $cmdp["clientid"] = $clientid;
     $cmdp["sender"] = $sender;
     $cmdp["recipient"] = $recipient;
     $cmdp["recipientid"] = $recipientid;
     // before playing the wanted command
     // play the found commands into the meta 'cmdtoplay'
     pfcCommand::RunPendingCmdToPlay($u->nickid, $cmdp, $xml_reponse);
     // play the wanted command
     $cmd =& pfcCommand::Factory($cmdname);
     $cmdp["param"] = $param;
     $cmdp["params"] = $params;
     if ($cmd != NULL) {
         // call the command
         if ($c->debug) {
             $cmd->run($xml_reponse, $cmdp);
         } else {
             @$cmd->run($xml_reponse, $cmdp);
         }
     } else {
         $cmd =& pfcCommand::Factory("error");
         $cmdp = array();
         $cmdp["clientid"] = $clientid;
         $cmdp["param"] = _pfc("Unknown command [%s]", stripslashes("/" . $cmdname . " " . $param));
         $cmdp["sender"] = $sender;
         $cmdp["recipient"] = $recipient;
         $cmdp["recipientid"] = $recipientid;
         if ($c->debug) {
             $cmd->run($xml_reponse, $cmdp);
         } else {
             @$cmd->run($xml_reponse, $cmdp);
         }
     }
     // do not update twice
     // do not update when the user just quit
     if ($cmdname != "update" && $cmdname != "quit" && $u->nickid != '') {
         // force an update just after a command is sent
         // thus the message user just poster is really fastly displayed
         $cmd =& pfcCommand::Factory("update");
         $cmdp = array();
         $cmdp["clientid"] = $clientid;
         $cmdp["param"] = $param;
         $cmdp["sender"] = $sender;
         $cmdp["recipient"] = $recipient;
         $cmdp["recipientid"] = $recipientid;
         if ($c->debug) {
             $cmd->run($xml_reponse, $cmdp);
         } else {
             @$cmd->run($xml_reponse, $cmdp);
         }
     }
     if ($c->debug) {
         // capture echoed content
         // if a content not empty is captured it is a php error in the code
         $data = ob_get_contents();
         if ($data != "") {
             // todo : display the $data somewhere to warn the user
         }
         ob_end_clean();
     }
     // do nothing else if the xml response is empty in order to save bandwidth
     if ($xml_reponse->getCommandCount() == 0) {
         die;
     }
     return $xml_reponse;
 }
Exemple #23
0
<?php

require_once dirname(__FILE__) . '/../src/pfccommand.class.php';
$results = array();
$results[] = array('cmdstr' => '/cmdname clientid recipientid', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid param1   param2', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid param1 param2 param3', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2', 'param3'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid "param1" "param2"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid "param1" "param2" "param3"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2', 'param3'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid "param1 with spaces" "param2 with spaces"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1 with spaces', 'param2 with spaces'));
$results[] = array('cmdstr' => '/cmdname000 clientid recipientid "param1" "param2"', 'cmdname' => 'cmdname000', 'params' => array('clientid', 'recipientid', 'param1', 'param2'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid param1  param2', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid "param1 with spaces" param2 param3', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1 with spaces', 'param2', 'param3'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid "param1" param2 "param3 with spaces" param4', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2', 'param3 with spaces', 'param4'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid "param1""param2"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2'));
$results[] = array('cmdstr' => '/cmdname clientid recipientid "param1withoutspace"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1withoutspace'));
$results[] = array('cmdstr' => '/send clientid recipientid my sentance " with double " quotes', 'cmdname' => 'send', 'params' => array('clientid', 'recipientid', 'my sentance " with double " quotes'));
echo '<pre>';
for ($i = 0; $i < count($results); $i++) {
    $command = $results[$i]['cmdstr'];
    $result = pfcCommand::ParseCommand($command);
    if ($result == $results[$i]) {
        echo "OK => {$command}\n";
    } else {
        print_r($result);
        echo "KO => {$command}\n";
    }
}
echo '</pre>';
 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);
 }
 /**
  * Constructor
  */
 function pfcProxyCommand()
 {
     pfcCommand::pfcCommand();
 }
 /**
  * Run all commands to be played for a user
  * @param $nickid is the user that entered the command
  * @param $context
  * @param $xml_reponse
  */
 function RunPendingCmdToPlay($nickid, $context, &$xml_reponse)
 {
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     $ct =& pfcContainer::Instance();
     // Get all queued commands to be played
     $cmdtoplay_ids = $ct->getCmdMeta($nickid);
     // process each command and parse content
     foreach ($cmdtoplay_ids as $cid) {
         // take a command from the list
         $cmdtoplay = $ct->getCmdMeta($nickid, $cid);
         $cmdtoplay = $cmdtoplay == NULL || count($cmdtoplay) == 0 ? array() : unserialize($cmdtoplay[0]);
         // play the command
         $cmd =& pfcCommand::Factory($cmdtoplay['cmdstr']);
         $cmdp = $cmdtoplay['params'];
         if (!isset($cmdp['param'])) {
             $cmdp['param'] = '';
         }
         if (!isset($cmdp['sender'])) {
             $cmdp['sender'] = $context['sender'];
         }
         if (!isset($cmdp['recipient'])) {
             $cmdp['recipient'] = $context['recipient'];
         }
         if (!isset($cmdp['recipientid'])) {
             $cmdp['recipientid'] = $context['recipientid'];
         }
         $cmdp['clientid'] = $context['clientid'];
         // the clientid must be the current user one
         $cmdp['cmdtoplay'] = true;
         // used to run some specials actions in the command (ex:  if the cmdtoplay is a 'leave' command, then show an alert to the kicked or banished user)
         if ($c->debug) {
             $cmd->run($xml_reponse, $cmdp);
         } else {
             @$cmd->run($xml_reponse, $cmdp);
         }
         // delete command when complete
         $ct->rmMeta("nickid-to-cmdtoplay", $nickid, $cid);
     }
 }
 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);
     }
 }
Exemple #28
0
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $params = $p["params"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $getoldmsg = isset($p["getoldmsg"]) ? $p["getoldmsg"] : true;
     $joinoldchan = isset($p["joinoldchan"]) ? $p["joinoldchan"] : true;
     // nickname must be given to be able to connect to the chat
     $nick = $params[0];
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     $ct =& pfcContainer::Instance();
     // reset the message id indicator (see getnewmsg.class.php)
     // i.e. be ready to re-get all last posted messages
     if ($getoldmsg) {
         $this->_resetChannelIdentifier($clientid);
     }
     // check if the user is alone on the server, and give it the admin status if yes
     $isadmin = $ct->getUserMeta($u->nickid, 'isadmin');
     if ($isadmin == NULL) {
         $isadmin = $c->isadmin;
     }
     if ($c->firstisadmin && !$isadmin) {
         $users = $ct->getOnlineNick(NULL);
         if (isset($users["nickid"]) && (count($users["nickid"]) == 0 || count($users["nickid"]) == 1 && $users["nickid"][0] == $u->nickid)) {
             $isadmin = true;
         }
     }
     // create the nickid and setup some user meta
     $nickid = $u->nickid;
     $ct->joinChan($nickid, NULL);
     // join the server
     // store the user ip
     $ip = $c->get_ip_from_xforwardedfor && isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
     if ($ip == "::1") {
         $ip = "127.0.0.1";
     }
     // fix for konqueror & localhost
     $ct->setUserMeta($nickid, 'ip', $ip);
     // store the admin flag
     $ct->setUserMeta($nickid, 'isadmin', $isadmin);
     // store the customized nick metadata
     foreach ($c->nickmeta as $k => $v) {
         $ct->setUserMeta($nickid, $k, $v);
     }
     // run the /nick command to assign the user nick
     $cmdp = array();
     $cmdp["param"] = $nick;
     $cmd =& pfcCommand::Factory('nick');
     $ret = $cmd->run($xml_reponse, $cmdp);
     if ($ret) {
         $chanlist = count($u->channels) == 0 ? $c->channels : $u->getChannelNames();
         for ($i = 0; $i < count($chanlist); $i++) {
             $cmdp = array();
             $cmdp["param"] = $chanlist[$i];
             $cmd =& pfcCommand::Factory($i < count($chanlist) - 1 || !$joinoldchan ? 'join2' : 'join');
             $cmd->run($xml_reponse, $cmdp);
         }
         $pvlist = count($u->privmsg) == 0 ? $c->privmsg : $u->getPrivMsgNames();
         for ($i = 0; $i < count($pvlist); $i++) {
             $cmdp = array();
             $cmdp["param"] = $pvlist[$i];
             $cmd =& pfcCommand::Factory($i < count($pvlist) - 1 || !$joinoldchan ? 'privmsg2' : 'privmsg');
             $cmd->run($xml_reponse, $cmdp);
         }
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', Array('" . addslashes($nick) . "'));");
     } else {
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ko', Array('" . addslashes($nick) . "'));");
     }
 }