Esempio n. 1
0
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     if ($param != "") {
         require_once dirname(__FILE__) . "/join.class.php";
         $recipient = pfcCommand_join::GetRecipient($param);
         $recipientid = pfcCommand_join::GetRecipientId($param);
     }
     $chanmeta = $this->_getChanMeta($recipient, $recipientid);
     //if (preg_match("/^pv_/", $recipient))
     //$this->trace($xml_reponse, 'who2', $recipient);
     // check if info didn't change since last call
     $sid = "pfc_who2_" . $c->getId() . "_" . $clientid . "_" . $recipientid;
     if (isset($_SESSION[$sid]) && $chanmeta == $_SESSION[$sid]) {
         // do not send the response to save bandwidth
         //$xml_reponse->script("pfc.handleResponse('".$this->name."', 'unchanged', '');");
     } else {
         $_SESSION[$sid] = $chanmeta;
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', " . $chanmeta . ");");
     }
 }
Esempio n. 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);
 }
Esempio n. 3
0
 function run(&$xml_reponse, $p)
 {
     $cmdtocheck = array("send", "me", "notice");
     if (in_array($this->name, $cmdtocheck)) {
         $clientid = $p["clientid"];
         $param = $p["param"];
         $sender = $p["sender"];
         $recipient = $p["recipient"];
         $recipientid = $p["recipientid"];
         $c =& pfcGlobalConfig::Instance();
         $u =& pfcUserConfig::Instance();
         $logpath = $c->proxies_cfg[$this->proxyname]["path"] == "" ? $c->data_private_path . "/logs" : $c->proxies_cfg[$this->proxyname]["path"];
         $logpath .= "/" . $c->getId();
         if (!file_exists($logpath)) {
             @mkdir_r($logpath);
         }
         if (file_exists($logpath) && is_writable($logpath)) {
             $logfile = $logpath . "/chat.log";
             if (is_writable($logpath)) {
                 // @todo write logs in a cleaner structured language (xml, html ... ?)
                 $log = $recipient . "\t";
                 $log .= date("d/m/Y") . "\t";
                 $log .= date("H:i:s") . "\t";
                 $log .= $sender . "\t";
                 $log .= $param . "\n";
                 file_put_contents($logfile, $log, FILE_APPEND | LOCK_EX);
             }
         }
     }
     // forward the command to the next proxy or to the final command
     return $this->next->run($xml_reponse, $p);
 }
Esempio n. 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();
     /**
      * 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);
 }
Esempio n. 5
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;
         }
     }
 }
Esempio n. 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();
     $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+'\"');");
     }
 }
Esempio n. 7
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', '');");
     }
 }
Esempio n. 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();
     $ignore = array("updatemynick", "getnewmsg", "notice", "getonlinenick", "error", "update", "asknick");
     $cmdlist = array();
     $dh = opendir(dirname(__FILE__));
     while (false !== ($file = readdir($dh))) {
         if (!preg_match("/^([a-z]+).class.php\$/i", $file, $res)) {
             continue;
         }
         if (!in_array($res[1], $ignore)) {
             $cmdlist[] = $res[1];
         }
     }
     closedir($dh);
     sort($cmdlist);
     $str = _pfc("Here is the command list:") . "<br/>";
     $str .= implode("<br/>", $cmdlist);
     $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', '" . $str . "');");
 }
Esempio n. 9
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) . "');");
 }
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $c =& pfcGlobalConfig::Instance();
     $nick = $c->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", $c);
         $cmd->run($xml_reponse, $cmdp);
     } else {
         $result = $dice->roll();
         $ct->write($recipient, $nick, "send", $result);
     }
 }
Esempio n. 11
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 . "');");
     }
 }
Esempio n. 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();
     $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));
 }
Esempio n. 13
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();
     $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', '" . $c->version . "');");
 }
Esempio n. 14
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);
 }
Esempio n. 15
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();
 }
Esempio n. 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();
     $ct->updateNick($u->nickid);
 }
Esempio n. 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();
     $cmd =& pfcCommand::Factory("quit");
     $cmd->run($xml_reponse, $p);
     $u->destroy();
 }
Esempio n. 18
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 . "');");
     }
 }
Esempio n. 19
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 . "');");
     }
 }
Esempio n. 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();
     $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) . "'));");
 }
Esempio n. 21
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;
 }
Esempio n. 22
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;
 }
Esempio n. 23
0
 function run(&$xml_reponse, $p)
 {
     $c =& pfcGlobalConfig::Instance();
     $errors = $p["param"];
     if (is_array($errors)) {
         $error_ids = "";
         $error_str = "";
         foreach ($errors as $k => $e) {
             $error_ids .= ",'" . $k . "'";
             $error_str .= $e . " ";
         }
         $error_ids = substr($error_ids, 1);
         $xml_reponse->script("pfc.setError('" . addslashes(stripslashes($error_str)) . "', Array(" . $error_ids . "));");
     } else {
         $xml_reponse->script("pfc.setError('" . addslashes(stripslashes($errors)) . "', Array());");
     }
 }
 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;
                 }
             }
         }
     }
 }
Esempio n. 25
0
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $c =& pfcGlobalConfig::Instance();
     // just destroy the cache
     // do not synchronizeWithCache() because it will reload the same parameters as the current one
     // the right way is to wait for the next page reload and the new parameters will be taken into account
     $destroyed = $c->destroyCache();
     if ($destroyed) {
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ok', '');");
     } else {
         $xml_reponse->script("pfc.handleResponse('" . $this->name . "', 'ko', '');");
     }
 }
Esempio n. 26
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);
 }
Esempio n. 27
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', '');");
 }
Esempio n. 28
0
 function run(&$xml_reponse, $p)
 {
     $clientid = $p["clientid"];
     $param = $p["param"];
     $sender = $p["sender"];
     $recipient = $p["recipient"];
     $recipientid = $p["recipientid"];
     $c =& pfcGlobalConfig::Instance();
     $u =& pfcUserConfig::Instance();
     if (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);
 }
Esempio n. 29
0
function pfc_shorten_url($url)
{
    $c =& pfcGlobalConfig::Instance();
    if (!$c->short_url) {
        return $url;
    }
    // Short URL Width
    $shurl_w = $c->short_url_width;
    $shurl_end_w = floor($shurl_w * 0.25) - 3;
    if ($shurl_end_w < 3) {
        $shurl_end_w = 3;
    }
    $shurl_begin_w = $shurl_w - $shurl_end_w - 3;
    if ($shurl_begin_w < 3) {
        $shurl_begin_w = 3;
    }
    $decodedurl = html_entity_decode($url, ENT_QUOTES);
    $len = strlen($decodedurl);
    $short_url = $len > $shurl_w ? substr($decodedurl, 0, $shurl_begin_w) . "..." . substr($decodedurl, -$shurl_end_w) : $decodedurl;
    return htmlentities($short_url, ENT_QUOTES);
}
Esempio n. 30
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;
         }
     }
 }