예제 #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();
     /**
      * 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"];
     $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);
     }
 }
예제 #3
0
 function run(&$xml_reponse, $p)
 {
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     $ct =& pfcContainer::Instance();
     $banlist = $ct->getChanMeta($p["recipient"], 'banlist_nickid');
     if ($banlist == NULL) {
         $banlist = array();
     } else {
         $banlist = unserialize($banlist);
     }
     $msg = "";
     $msg .= "<p>" . _pfc("The banished user list is:") . "</p>";
     if (count($banlist) > 0) {
         $msg .= "<ul>";
         foreach ($banlist as $b) {
             $n = $ct->getNickname($b);
             $msg .= "<li style=\"margin-left:50px\">" . $n . "</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('" . $this->name . "', 'ok', '" . addslashes($msg) . "');");
 }
예제 #4
0
 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;
         }
     }
 }
예제 #5
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();
     $password = trim($param);
     $isadmin = false;
     //     $xml_reponse->script("alert('sender=".$sender."');");
     //     $xml_reponse->script("alert('password="******"');");
     //     $xml_reponse->script("alert('admins=".var_export($c->admins, true)."');");
     if (isset($c->admins[$sender]) && $c->admins[$sender] == $password) {
         $isadmin = true;
     }
     $msg = "";
     if ($isadmin) {
         // ok the current user is an admin, just save the isadmin flag in the metadata
         $ct =& pfcContainer::Instance();
         $ct->setUserMeta($u->nickid, 'isadmin', $isadmin);
         $this->forceWhoisReload($u->nickid);
         $msg .= _pfc("Succesfully identified");
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', '" . $msg . "');");
     } else {
         $msg .= _pfc("Identification failure");
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ko', '" . $msg . "');");
     }
 }
예제 #6
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);
 }
예제 #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));
 }
예제 #8
0
 function setUp()
 {
     //    echo "setUp<br>";
     require_once dirname(__FILE__) . "/../src/pfcglobalconfig.class.php";
     $params = array();
     $params["title"] = "testcase -> pfccontainer_" . $this->type;
     $params["serverid"] = md5(__FILE__ . time());
     $params["container_type"] = $this->type;
     $this->c = pfcGlobalConfig::Instance($params);
     $this->ct = pfcContainer::Instance();
 }
예제 #9
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);
 }
예제 #10
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();
     $ct->updateNick($u->nickid);
 }
예제 #11
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 . "');");
     }
 }
예제 #12
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();
     //    $xml_reponse->script("trace('".implode(',',$params)."');");
     //    return;
     // get the nickid from the parameters
     // if the run command is whois2 then the parameter is a nickid
     $nickid = '';
     if ($this->name == 'whois2') {
         $nickid = $params[0];
     } else {
         $nickid = $ct->getNickId($params[0]);
     }
     if ($nickid) {
         $usermeta = $ct->getAllUserMeta($nickid);
         $usermeta['nickid'] = $nickid;
         unset($usermeta['cmdtoplay']);
         // used internaly
         // remove private usermeta from the list if the client is not admin
         $isadmin = $ct->getUserMeta($u->nickid, 'isadmin');
         if (!$isadmin) {
             foreach ($c->nickmeta_private as $nmp) {
                 unset($usermeta[$nmp]);
             }
         }
         // sort the list
         $nickmeta_sorted = array();
         $order = array_merge(array_diff(array_keys($usermeta), array_keys($c->nickmeta)), array_keys($c->nickmeta));
         foreach ($order as $o) {
             $nickmeta_sorted[$o] = $usermeta[$o];
         }
         $usermeta = $nickmeta_sorted;
         require_once dirname(__FILE__) . '/../pfcjson.class.php';
         $json = new pfcJSON();
         $js = $json->encode($usermeta);
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', " . $js . ");");
     } else {
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ko','" . $param . "');");
     }
 }
예제 #13
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;
 }
예제 #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();
     $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) . "'));");
 }
예제 #15
0
 function _getChanMeta($recipient, $recipientid)
 {
     $c =& pfcGlobalConfig::Instance();
     $ct =& pfcContainer::Instance();
     $chanmeta = array();
     $chanmeta['chan'] = $recipient;
     $chanmeta['chanid'] = $recipientid;
     $chanmeta['meta'] = $ct->getAllUserMeta($chanmeta['chan']);
     $users = $ct->getOnlineNick($chanmeta['chan']);
     $chanmeta['meta']['users'] = array();
     $chanmeta['meta']['users']['nick'] = $users['nick'];
     $chanmeta['meta']['users']['nickid'] = $users['nickid'];
     require_once dirname(__FILE__) . '/../pfcjson.class.php';
     $json = new pfcJSON();
     $js = $json->encode($chanmeta);
     return $js;
 }
예제 #16
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);
 }
예제 #17
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', '');");
 }
예제 #18
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;
         }
     }
 }
예제 #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();
     $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);
 }
예제 #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();
     $nick = $u->getNickname();
     $text_src = phpFreeChat::PreFilterMsg(trim($param));
     $text_src = str_replace(" ", "", $text_src);
     try {
         $p = new Parser($text_src);
         $p->setDebug($ct, $nick, $recipient);
         $ov = $p->Parse();
         $text = $nick . " : " . $text_src . " >> " . $ov->str . " = " . $ov->val;
     } catch (Exception $e) {
         $text = "Error: " . $e->getMessage();
     }
     $ct->write($recipient, $nick, "send", $text);
 }
예제 #21
0
 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);
 }
예제 #22
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;
 }
예제 #23
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);
 }
 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);
     }
 }
예제 #25
0
 function getNickname()
 {
     if ($this->nick != '') {
         return $this->nick;
     }
     $ct =& pfcContainer::Instance();
     return $ct->getNickname($this->nickid);
 }
예제 #26
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;
 }
 /**
  * Initialize the phpfreechat configuration
  * this initialisation is done once at startup then it is stored into a session cache
  */
 function init()
 {
     $ok = true;
     // check the parameters types
     $array_params = $this->_params_type["array"];
     foreach ($array_params as $ap) {
         if (!is_array($this->{$ap})) {
             $this->errors[] = _pfc("'%s' parameter must be an array", $ap);
         }
     }
     $numerical_positive_params = $this->_params_type["positivenumeric"];
     foreach ($numerical_positive_params as $npp) {
         if (!is_int($this->{$npp}) || $this->{$npp} < 0) {
             $this->errors[] = _pfc("'%s' parameter must be a positive number", $npp);
         }
     }
     $boolean_params = $this->_params_type["bool"];
     foreach ($boolean_params as $bp) {
         if (!is_bool($this->{$bp})) {
             $this->errors[] = _pfc("'%s' parameter must be a boolean", $bp);
         }
     }
     $string_params = $this->_params_type["string"];
     foreach ($string_params as $sp) {
         if (!is_string($this->{$sp})) {
             $this->errors[] = _pfc("'%s' parameter must be a charatere string", $sp);
         }
     }
     if ($this->title == "") {
         $this->title = _pfc("My Chat");
     }
     // first of all, check the used functions
     $f_list["file_get_contents"] = _pfc("You need %s", "PHP 4 >= 4.3.0 or PHP 5");
     $err_session_x = "You need PHP 4 or PHP 5";
     $f_list["session_start"] = $err_session_x;
     $f_list["session_destroy"] = $err_session_x;
     $f_list["session_id"] = $err_session_x;
     $f_list["session_name"] = $err_session_x;
     $err_preg_x = _pfc("You need %s", "PHP 3 >= 3.0.9 or PHP 4 or PHP 5");
     $f_list["preg_match"] = $err_preg_x;
     $f_list["preg_replace"] = $err_preg_x;
     $f_list["preg_split"] = $err_preg_x;
     $err_ob_x = _pfc("You need %s", "PHP 4 or PHP 5");
     $f_list["ob_start"] = $err_ob_x;
     $f_list["ob_get_contents"] = $err_ob_x;
     $f_list["ob_end_clean"] = $err_ob_x;
     $f_list["get_object_vars"] = _pfc("You need %s", "PHP 4 or PHP 5");
     $this->errors = array_merge($this->errors, check_functions_exist($f_list));
     //    $this->errors = array_merge($this->errors, @test_writable_dir($this->data_public_path, "data_public_path"));
     $this->errors = array_merge($this->errors, @test_writable_dir($this->data_private_path, "data_private_path"));
     $this->errors = array_merge($this->errors, @test_writable_dir($this->data_private_path . "/cache", "data_private_path/cache"));
     // install the public directory content
     $dir = dirname(__FILE__) . "/../data/public/js";
     $dh = opendir($dir);
     while (false !== ($file = readdir($dh))) {
         $f_src = $dir . '/' . $file;
         $f_dst = $this->data_public_path . '/js/' . $file;
         if ($file == "." || $file == ".." || !is_file($f_src)) {
             continue;
         }
         // skip . and .. generic files
         // install js files only if the destination doesn't exists or if the destination timestamp is older than the source timestamp
         if (!file_exists($f_dst) || filemtime($f_dst) < filemtime($f_src)) {
             mkdir_r($this->data_public_path . '/js/');
             copy($f_src, $f_dst);
         }
         if (!file_exists($f_dst)) {
             $this->errors[] = _pfc("%s doesn't exist, data_public_path cannot be installed", $f_dst);
         }
     }
     closedir($dh);
     // ---
     // test client script
     // try to find the path into server configuration
     if ($this->client_script_path == '') {
         $this->client_script_path = pfc_GetScriptFilename();
     }
     if ($this->server_script_url == '' && $this->server_script_path == '') {
         $filetotest = $this->client_script_path;
         // do not take into account the url parameters
         if (preg_match("/(.*)\\?(.*)/", $filetotest, $res)) {
             $filetotest = $res[1];
         }
         if (!file_exists($filetotest)) {
             $this->errors[] = _pfc("%s doesn't exist", $filetotest);
         }
         $this->server_script_url = './' . basename($filetotest) . $this->_query_string;
     }
     // calculate datapublic url
     if ($this->data_public_url == "") {
         $this->data_public_url = pfc_RelativePath($this->client_script_path, $this->data_public_path);
     }
     if ($this->server_script_path == '') {
         $this->server_script_path = $this->client_script_path;
     }
     // ---
     // test server script
     if ($this->server_script_url == '') {
         $filetotest = $this->server_script_path;
         // do not take into account the url parameters
         if (preg_match("/(.*)\\?(.*)/", $this->server_script_path, $res)) {
             $filetotest = $res[1];
         }
         if (!file_exists($filetotest)) {
             $this->errors[] = _pfc("%s doesn't exist", $filetotest);
         }
         $this->server_script_url = pfc_RelativePath($this->client_script_path, $this->server_script_path) . '/' . basename($filetotest) . $this->_query_string;
     }
     // check if the theme_path parameter are correctly setup
     if ($this->theme_default_path == '' || !is_dir($this->theme_default_path)) {
         $this->theme_default_path = dirname(__FILE__) . '/../themes';
     }
     if ($this->theme_path == '' || !is_dir($this->theme_path)) {
         $this->theme_path = $this->theme_default_path;
     }
     // If the user didn't give any theme_default_url value,
     // copy the default theme resources in a public directory
     if ($this->theme_default_url == '') {
         mkdir_r($this->data_public_path . '/themes/default');
         if (!is_dir($this->data_public_path . '/themes/default')) {
             $this->errors[] = _pfc("cannot create %s", $this->data_public_path . '/themes/default');
         } else {
             $ret = copy_r(dirname(__FILE__) . '/../themes/default', $this->data_public_path . '/themes/default');
             if (!$ret) {
                 $this->errors[] = _pfc("cannot copy %s in %s", dirname(__FILE__) . '/../themes/default', $this->data_public_path . '/themes/default');
             }
         }
         $this->theme_default_url = $this->data_public_url . '/themes';
     }
     if ($this->theme_url == '') {
         mkdir_r($this->data_public_path . '/themes/' . $this->theme);
         if (!is_dir($this->data_public_path . '/themes/' . $this->theme)) {
             $this->errors[] = _pfc("cannot create %s", $this->data_public_path . '/themes/' . $this->theme);
         } else {
             $ret = copy_r($this->theme_path . '/' . $this->theme, $this->data_public_path . '/themes/' . $this->theme);
             if (!$ret) {
                 $this->errors[] = _pfc("cannot copy %s in %s", $this->theme_path . '/' . $this->theme, $this->data_public_path . '/themes/' . $this->theme);
             }
         }
         $this->theme_url = $this->theme_default_url;
     }
     // if the user do not have an existing prototype.js library, we use the embeded one
     if ($this->prototypejs_url == '') {
         $this->prototypejs_url = $this->data_public_url . '/js/prototype.js';
     }
     // ---
     // run specific container initialisation
     $ct =& pfcContainer::Instance();
     $ct_errors = $ct->init($this);
     $this->errors = array_merge($this->errors, $ct_errors);
     // check the language is known
     $lg_list = pfcI18N::GetAcceptedLanguage();
     if ($this->language != "" && !in_array($this->language, $lg_list)) {
         $this->errors[] = _pfc("'%s' parameter is not valid. Available values are : '%s'", "language", implode(", ", $lg_list));
     }
     // calculate the proxies chaine
     $this->proxies = array();
     foreach ($this->pre_proxies as $px) {
         if (!in_array($px, $this->skip_proxies) && !in_array($px, $this->proxies)) {
             $this->proxies[] = $px;
         }
     }
     foreach ($this->_sys_proxies as $px) {
         if (!in_array($px, $this->skip_proxies) && !in_array($px, $this->proxies)) {
             $this->proxies[] = $px;
         }
     }
     foreach ($this->post_proxies as $px) {
         if (!in_array($px, $this->skip_proxies) && !in_array($px, $this->proxies)) {
             $this->proxies[] = $px;
         }
     }
     // save the proxies path
     $this->proxies_path_default = dirname(__FILE__) . '/proxies';
     // check the customized proxies path
     if ($this->proxies_path != '' && !is_dir($this->proxies_path)) {
         $this->errors[] = _pfc("'%s' directory doesn't exist", $this->proxies_path);
     }
     if ($this->proxies_path == '') {
         $this->proxies_path = $this->proxies_path_default;
     }
     // save the commands path
     $this->cmd_path_default = dirname(__FILE__) . '/commands';
     if ($this->cmd_path == '') {
         $this->cmd_path = $this->cmd_path_default;
     }
     // load smileys from file
     $this->loadSmileyTheme();
     // load version number from file
     $this->version = trim(file_get_contents(dirname(__FILE__) . "/../version.txt"));
     $this->is_init = count($this->errors) == 0;
 }
예제 #28
0
 function _checkNickIsUsed($newnick, $oldnickid)
 {
     $c =& pfcGlobalConfig::Instance();
     $ct =& pfcContainer::Instance();
     $nick_in_use = false;
     $online_users = $ct->getOnlineNick(NULL);
     if (isset($online_users["nickid"])) {
         foreach ($online_users["nickid"] as $nid) {
             if (preg_match("/^" . preg_quote($ct->getNickname($nid)) . "\$/i", $newnick)) {
                 // the nick match
                 // just allow the owner to change his capitalised letters
                 if ($nid != $oldnickid) {
                     return true;
                 }
             }
         }
     }
 }
예제 #29
0
 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;
 }
 /**
  * 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);
     }
 }