[Phpfreechat-svn] SF.net SVN: phpfreechat: [895] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-12-08 17:58:33
|
Revision: 895 http://svn.sourceforge.net/phpfreechat/?rev=895&view=rev Author: kerphi Date: 2006-12-08 09:58:25 -0800 (Fri, 08 Dec 2006) Log Message: ----------- work in progress : multi parameters in commands Modified Paths: -------------- trunk/src/client/pfcclient.js trunk/src/client/pfcgui.js trunk/src/commands/ban.class.php trunk/src/commands/invite.class.php trunk/src/commands/kick.class.php trunk/src/commands/leave.class.php trunk/src/pfccommand.class.php trunk/src/phpfreechat.class.php Modified: trunk/src/client/pfcclient.js =================================================================== --- trunk/src/client/pfcclient.js 2006-12-08 13:55:33 UTC (rev 894) +++ trunk/src/client/pfcclient.js 2006-12-08 17:58:25 UTC (rev 895) @@ -888,12 +888,27 @@ sendRequest: function(cmd, param) { var recipientid = this.gui.getTabId(); + + var req = cmd+" "+this.clientid+" "+(recipientid==''?'0':recipientid)+(param?" "+param : ""); if (pfc_debug) if (cmd != "/update") trace('sendRequest: '+req); return eval('pfc_handleRequest(req);'); }, + // @todo remplacer sendRequest par cette fonction (cf /leave dans pfcgui.js) + sendRequest2: function(cmd) + { + var rx = new RegExp('(^\/[^ ]+) *(.*)','ig'); + var ttt = cmd.split(rx); + + var recipientid = this.gui.getTabId(); + var req = ttt[1]+" "+this.clientid+" "+(recipientid==''?'0':recipientid)+' '+ttt[2]; + if (pfc_debug) + if (cmd != "/update") trace('sendRequest: '+req); + return eval('pfc_handleRequest(req);'); + }, + /** * update function to poll the server each 'refresh_delay' time */ Modified: trunk/src/client/pfcgui.js =================================================================== --- trunk/src/client/pfcgui.js 2006-12-08 13:55:33 UTC (rev 894) +++ trunk/src/client/pfcgui.js 2006-12-08 17:58:25 UTC (rev 895) @@ -256,9 +256,10 @@ { var a2 = document.createElement('a'); a2.pfc_tabid = tabid; + a2.pfc_tabname = name; a2.onclick = function(){ var res = confirm(pfc.res.getLabel('Do you really want to leave this room ?')); - if (res == true) pfc.sendRequest('/leave', this.pfc_tabid); return false; + if (res == true) pfc.sendRequest2('/leave "'+this.pfc_tabname+'"'); return false; } a2.alt = pfc.res.getLabel('Close this tab'); a2.title = a2.alt; Modified: trunk/src/commands/ban.class.php =================================================================== --- trunk/src/commands/ban.class.php 2006-12-08 13:55:33 UTC (rev 894) +++ trunk/src/commands/ban.class.php 2006-12-08 17:58:25 UTC (rev 895) @@ -4,12 +4,13 @@ class pfcCommand_ban extends pfcCommand { - var $usage = "/ban {nickname}"; + var $usage = "/ban {nickname} [ {reason} ]"; function run(&$xml_reponse, $p) { $clientid = $p["clientid"]; $param = $p["param"]; + $params = $p["params"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; @@ -17,7 +18,7 @@ $c =& $this->c; $u =& $this->u; - if (trim($param) == "") + if (trim($params[0]) == '') { // error $cmdp = $p; @@ -28,33 +29,33 @@ return; } + $ct =& $c->getContainerInstance(); + $nickidtoban = $ct->getNickId($params[0]); + + // notify all the channel + $cmdp = $p; + $cmdp["param"] = _pfc("banished from %s by %s", $recipient, $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"][] = $params[0]; // nickname to kick + $cmdp["params"][] = $params[1]; // reason + $cmd =& pfcCommand::Factory("kick"); + $cmd->run($xml_reponse, $cmdp); - $container =& $c->getContainerInstance(); - $nickid = $container->getNickId($param); - if ($nickid != "") - { - $cmdtoplay = $container->getUserMeta($nickid, 'cmdtoplay'); - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - $cmdtmp = array("leave", /* cmdname */ - $recipientid,/* param */ - $sender, /* sender */ - $recipient, /* recipient */ - $recipientid,/* recipientid */ - ); - //_pfc("banished from %s by %s", $recipient, $sender); - $cmdtoplay[] = $cmdtmp; // ban the user from the current channel - $container->setUserMeta($nickid, 'cmdtoplay', serialize($cmdtoplay)); - } - // update the recipient banlist - $banlist = $container->getChanMeta($recipient, 'banlist_nickid'); + $banlist = $ct->getChanMeta($recipient, 'banlist_nickid'); if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist); - $banlist[] = $nickid; // append the nickid to the banlist - $container->setChanMeta($recipient, 'banlist_nickid', serialize($banlist)); + $banlist[] = $nickidtoban; // append the nickid to the banlist + $ct->setChanMeta($recipient, 'banlist_nickid', serialize($banlist)); } } Modified: trunk/src/commands/invite.class.php =================================================================== --- trunk/src/commands/invite.class.php 2006-12-08 13:55:33 UTC (rev 894) +++ trunk/src/commands/invite.class.php 2006-12-08 17:58:25 UTC (rev 895) @@ -1,5 +1,4 @@ <?php - /** * invite.class.php * @@ -20,7 +19,10 @@ * Free Software Foundation, 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ - + +require_once(dirname(__FILE__)."/../pfccommand.class.php"); +require_once(dirname(__FILE__)."/../commands/join.class.php"); + /** * /invite command * @@ -29,54 +31,56 @@ * The parameter "target channel" is optional, if not set it defaults to the current channel * * @author Benedikt Hallinger <be...@ph...> + * @author Stephane Gully <ste...@gm...> */ class pfcCommand_invite extends pfcCommand { - var $usage = "/invite {nickname to invite} [{target channel}]"; + var $usage = "/invite {nickname to invite} [ {target channel} ]"; - function run(&$xml_reponse, $p) - { - $clientid = $p["clientid"]; - $param = $p["param"]; - $sender = $p["sender"]; - $recipient = $p["recipient"]; - $recipientid = $p["recipientid"]; + function run(&$xml_reponse, $p) + { + $clientid = $p["clientid"]; + $param = $p["param"]; + $params = $p["params"]; + $sender = $p["sender"]; + $recipient = $p["recipient"]; + $recipientid = $p["recipientid"]; + + $c =& $this->c; // pfcGlobalConfig + $u =& $this->u; // pfcUserConfig + $ct =& $c->getContainerInstance(); // 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; + } - $c =& $this->c; // pfcGlobalConfig - $u =& $this->u; // pfcUserConfig - $container =& $c->getContainerInstance(); // Connection to the chatbackend - - $p_array = split(' ', $param); // Split the parameters: [0]= targetnick, [1]=targetchannel - if (!isset($p_array[1])) $p_array[1] = $u->channels[$recipientid]["name"]; // Default: current channel - if (!isset($p_array[0]) || !isset($p_array[1])) - { - // Parameters not ok! - $cmdp = $p; - $cmdp["param"] = _pfc("Missing parameter"); - $cmdp["param"] .= " (".$this->usage.")"; - $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. - $nickid = $container->getNickId($p_array[0]); // get the internal ID of that chatter - if ($nickid != "") - { - $cmdtoplay = $container->getUserMeta($nickid, 'cmdtoplay'); // get the users command queue - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - $cmdtmp = array("join", /* cmdname */ - $p_array[1], /* param */ - $sender, /* sender */ - $recipient, /* recipient */ - $recipientid,/* recipientid */ - ); - $cmdtoplay[] = $cmdtmp; // store the command in the queue - $container->setUserMeta($nickid, 'cmdtoplay', serialize($cmdtoplay)); // close and store the queue + // inviting a user: just add a join command to play to the aimed user metadata. + $nickidtoinvite = $ct->getNickId($nicktoinvite); + $cmdstr = 'join2'; + $cmdp = array(); + $cmdp['param'] = $channeltarget; // channel target name + $cmdp['params'][] = $channeltarget; // channel target name + pfcCommand::AppendCmdToPlay($nickidtoinvite, $cmdstr, $cmdp); - // Ok, the user is invited, now write something into the chat, so his tab opens - $container->write($recipient, 'SYSTEM', "notice", $p_array[0].' was invited by '.$sender); - } - } + // notify the aimed channel that a user has been invited + $cmdp = array(); + $cmdp["param"] = $nicktoinvite.' was invited by '.$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); + } } ?> \ No newline at end of file Modified: trunk/src/commands/kick.class.php =================================================================== --- trunk/src/commands/kick.class.php 2006-12-08 13:55:33 UTC (rev 894) +++ trunk/src/commands/kick.class.php 2006-12-08 17:58:25 UTC (rev 895) @@ -4,12 +4,13 @@ class pfcCommand_kick extends pfcCommand { - var $usage = "/kick {nickname}"; + var $usage = "/kick {nickname} [ {reason} ]"; function run(&$xml_reponse, $p) { $clientid = $p["clientid"]; $param = $p["param"]; + $params = $p["params"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; @@ -17,7 +18,7 @@ $c =& $this->c; $u =& $this->u; - if (trim($param) == "") + if (trim($params[0]) == '') { // error $cmdp = $p; @@ -27,24 +28,16 @@ $cmd->run($xml_reponse, $cmdp); return; } - + // kicking a user just add a command to play to the aimed user metadata. - $container =& $c->getContainerInstance(); - $nickid = $container->getNickId($param); - if ($nickid != "") - { - $cmdtoplay = $container->getUserMeta($nickid, 'cmdtoplay'); - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - $reason = _pfc("kicked from %s by %s", $u->channels[$recipientid]["name"], $sender); - $cmdtmp = array("leave", /* cmdname */ - $recipientid." ".$reason, /* param */ - $sender, /* sender */ - $recipient, /* recipient */ - $recipientid,/* recipientid */ - ); - $cmdtoplay[] = $cmdtmp; // kick the user from the current channel - $container->setUserMeta($nickid, 'cmdtoplay', serialize($cmdtoplay)); - } + $ct =& $c->getContainerInstance(); + $otherid = $ct->getNickId($params[0]); + $channame = $u->channels[$recipientid]["name"]; + $cmdstr = 'leave'; + $cmdp = array(); + $cmdp['params'][] = $channame; // channel name + $cmdp['params'][] = _pfc("kicked from %s by %s - reason: %s", $channame, $sender, $params[1]); // reason + pfcCommand::AppendCmdToPlay($otherid, $cmdstr, $cmdp); } } Modified: trunk/src/commands/leave.class.php =================================================================== --- trunk/src/commands/leave.class.php 2006-12-08 13:55:33 UTC (rev 894) +++ trunk/src/commands/leave.class.php 2006-12-08 17:58:25 UTC (rev 895) @@ -1,15 +1,16 @@ <?php require_once(dirname(__FILE__)."/../pfccommand.class.php"); +require_once(dirname(__FILE__)."/../commands/join.class.php"); class pfcCommand_leave extends pfcCommand { - var $usage = "/leave [{recipientid} {reason}]"; + var $usage = "/leave [{channel} {reason}]"; function run(&$xml_reponse, $p) { $clientid = $p["clientid"]; - $param = $p["param"]; + $params = $p["params"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; @@ -19,13 +20,13 @@ // tab to leave can be passed in the parameters // a reason can also be present (used for kick and ban commands) - $id = ""; $reason = ""; - if (preg_match("/([a-z0-9]*)( (.*)|)/i", $param, $res)) + $id = ''; $reason = ''; + if (count($params)>0) { - $id = $res[1]; - $reason = trim($res[2]); + $id = pfcCommand_join::GetRecipientId($params[0]); + $reason = implode(" ",array_slice($params,1)); } - if ($id == "") $id = $recipientid; // be default this is the current tab to leave + if ($id == '') $id = $recipientid; // be default this is the current tab to leave // $xml_reponse->addScript("alert('sender=".addslashes($sender)."');"); // $xml_reponse->addScript("alert('recipientid=".addslashes($id)."');"); @@ -84,6 +85,15 @@ // 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 Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2006-12-08 13:55:33 UTC (rev 894) +++ trunk/src/pfccommand.class.php 2006-12-08 17:58:25 UTC (rev 895) @@ -161,22 +161,88 @@ // alert them that $nicktorewhois user info just changed foreach($otherids as $otherid) { + $cmdstr = 'whois2'; + $cmdp = array(); + $cmdp['param'] = $nicktorewhois; + 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 */ + $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)); } + */ } } + function AppendCmdToPlay($nickid, $cmdstr, $cmdp) + { + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + + $ct =& $c->getContainerInstance(); + if ($nickid != "") + { + $cmdtoplay = $ct->getUserMeta($nickid, 'cmdtoplay'); + $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); + $cmdtmp = array(); + $cmdtmp['cmdstr'] = $cmdstr; + $cmdtmp['params'] = $cmdp; + $cmdtoplay[] = $cmdtmp; + $ct->setUserMeta($nickid, 'cmdtoplay', serialize($cmdtoplay)); + return true; + } + else + return false; + } + + function RunPendingCmdToPlay($nickid,$clientid,$xml_reponse) + { + $c =& pfcGlobalConfig::Instance(); + $u =& pfcUserConfig::Instance(); + $ct =& $c->getContainerInstance(); + + $morecmd = true; + while($morecmd) + { + // take a command from the list + $cmdtoplay = $ct->getUserMeta($nickid, 'cmdtoplay'); + $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); + if (count($cmdtoplay) == 0) { $morecmd = false; continue; } + // take the last posted command + $cmdtmp = array_pop($cmdtoplay); + // store the new cmdtoplay list (-1 item) + $ct->setUserMeta($nickid, 'cmdtoplay', serialize($cmdtoplay)); + + // play the command + // print_r($cmdtmp); + $cmd =& pfcCommand::Factory($cmdtmp['cmdstr']); + $cmdp = $cmdtmp['params']; + $cmdp['clientid'] = $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); + + // check if there is other command to play + $cmdtoplay = $ct->getUserMeta($nickid, 'cmdtoplay'); + $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); + + $morecmd = (count($cmdtoplay) > 0); + } + } + + function trace(&$xml_reponse, $msg, $data = NULL) { if ($data != NULL) Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2006-12-08 13:55:33 UTC (rev 894) +++ trunk/src/phpfreechat.class.php 2006-12-08 17:58:25 UTC (rev 895) @@ -361,70 +361,21 @@ { // alert the other from the new pv // (warn other user that someone talk to him) - $container =& $c->getContainerInstance(); - $cmdtoplay = $container->getUserMeta($u->privmsg[$recipientid]["pvnickid"], 'cmdtoplay'); - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - $cmdtmp = array("privmsg2", /* cmdname */ - $u->nick, /* param */ - $sender, /* sender */ - $recipient, /* recipient */ - $recipientid,/* recipientid */ - ); - if (!in_array($cmdtmp, $cmdtoplay)) - { - $cmdtoplay[] = $cmdtmp; - $container->setUserMeta($u->privmsg[$recipientid]["pvnickid"], 'cmdtoplay', serialize($cmdtoplay)); - //$xml_reponse->addScript("alert('cmdtoplay[]=".serialize($cmdtoplay)."');"); - } + + $ct =& $c->getContainerInstance(); + $nickidtopv = $u->privmsg[$recipientid]["pvnickid"]; + $cmdstr = 'privmsg2'; + $cmdp = array(); + $cmdp['param'] = $u->nick; + $cmdp['params'][] = $u->nick; + pfcCommand::AppendCmdToPlay($nickidtopv, $cmdstr, $cmdp); } } - // before playing the wanted command // play the found commands into the meta 'cmdtoplay' - $container =& $c->getContainerInstance(); - $nickid = $u->nickid; - $morecmd = true; - while($morecmd) - { - // take a command from the list - $cmdtoplay = $container->getUserMeta($nickid, 'cmdtoplay'); - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - $cmdtmp = array_pop($cmdtoplay); - if ($cmdtmp != NULL) - { - // store the new cmdtoplay list (-1 item) - $container->setUserMeta($nickid, 'cmdtoplay', serialize($cmdtoplay)); - - // play the command - $cmd =& pfcCommand::Factory($cmdtmp[0]); - $cmdp = array(); - $cmdp["clientid"] = $clientid; - $cmdp["param"] = $cmdtmp[1]; - $cmdp["sender"] = $cmdtmp[2]; - $cmdp["recipient"] = $cmdtmp[3]; - $cmdp["recipientid"] = $cmdtmp[4]; - if ($c->debug) - $cmd->run($xml_reponse, $cmdp); - else - @$cmd->run($xml_reponse, $cmdp); - - // if the cmdtoplay is a 'leave' command, then show an alert to the kicked or banished user - if ($cmdtmp[0] == "leave") - { - if (preg_match("/([a-z0-9]*) (.*)/i", $cmdtmp[1], $res)) - $xml_reponse->addScript("alert('".$res[2]."');"); - } - - // check if there is other command to play - $cmdtoplay = $container->getUserMeta($nickid, 'cmdtoplay'); - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - } - - $morecmd = (count($cmdtoplay) > 0); - } - + pfcCommand::RunPendingCmdToPlay($u->nickid, $clientid, $xml_reponse); $cmd =& pfcCommand::Factory($cmdname); $cmdp = array(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |