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; }
<?php require_once dirname(__FILE__) . '/../src/pfccommand.class.php'; $results = array(); $results[] = array('cmdstr' => '/cmdname clientid recipientid', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid')); $results[] = array('cmdstr' => '/cmdname clientid recipientid param1 param2', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2')); $results[] = array('cmdstr' => '/cmdname clientid recipientid param1 param2 param3', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2', 'param3')); $results[] = array('cmdstr' => '/cmdname clientid recipientid "param1" "param2"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2')); $results[] = array('cmdstr' => '/cmdname clientid recipientid "param1" "param2" "param3"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2', 'param3')); $results[] = array('cmdstr' => '/cmdname clientid recipientid "param1 with spaces" "param2 with spaces"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1 with spaces', 'param2 with spaces')); $results[] = array('cmdstr' => '/cmdname000 clientid recipientid "param1" "param2"', 'cmdname' => 'cmdname000', 'params' => array('clientid', 'recipientid', 'param1', 'param2')); $results[] = array('cmdstr' => '/cmdname clientid recipientid param1 param2', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2')); $results[] = array('cmdstr' => '/cmdname clientid recipientid "param1 with spaces" param2 param3', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1 with spaces', 'param2', 'param3')); $results[] = array('cmdstr' => '/cmdname clientid recipientid "param1" param2 "param3 with spaces" param4', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2', 'param3 with spaces', 'param4')); $results[] = array('cmdstr' => '/cmdname clientid recipientid "param1""param2"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1', 'param2')); $results[] = array('cmdstr' => '/cmdname clientid recipientid "param1withoutspace"', 'cmdname' => 'cmdname', 'params' => array('clientid', 'recipientid', 'param1withoutspace')); $results[] = array('cmdstr' => '/send clientid recipientid my sentance " with double " quotes', 'cmdname' => 'send', 'params' => array('clientid', 'recipientid', 'my sentance " with double " quotes')); echo '<pre>'; for ($i = 0; $i < count($results); $i++) { $command = $results[$i]['cmdstr']; $result = pfcCommand::ParseCommand($command); if ($result == $results[$i]) { echo "OK => {$command}\n"; } else { print_r($result); echo "KO => {$command}\n"; } } echo '</pre>';