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); }
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); }
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; }
/** * Force whois reloading */ function forceWhoisReload($nickid) { $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); $ct =& pfcContainer::Instance(); // list the users in the same channel as $nickid $channels = $ct->getMeta("nickid-to-channelid", $nickid); $channels = $channels['value']; $channels = array_diff($channels, array('SERVER')); $otherids = array(); foreach ($channels as $chan) { $ret = $ct->getOnlineNick($ct->decode($chan)); $otherids = array_merge($otherids, $ret['nickid']); } // alert them that $nickid user info just changed foreach ($otherids as $otherid) { $cmdstr = 'whois2'; $cmdp = array(); $cmdp['params'] = array($nickid); pfcCommand::AppendCmdToPlay($otherid, $cmdstr, $cmdp); /* $cmdtoplay = $ct->getUserMeta($otherid, 'cmdtoplay'); $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); $cmdtmp = array("whois2", // cmdname $nicktorewhois, // param NULL, // sender NULL, // recipient NULL, // recipientid ); if (!in_array($cmdtmp, $cmdtoplay)) { $cmdtoplay[] = $cmdtmp; $ct->setUserMeta($otherid, 'cmdtoplay', serialize($cmdtoplay)); } */ } }