[Phpfreechat-svn] SF.net SVN: phpfreechat: [523] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-05-28 15:47:07
|
Revision: 523 Author: kerphi Date: 2006-05-28 08:46:57 -0700 (Sun, 28 May 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=523&view=rev Log Message: ----------- Refactoring on the 'cmdtoplay' command: Now all the command parameters are stored in the user meta. Now a reason is available for the /leave command, it is used by the kick and ban command Modified Paths: -------------- trunk/src/commands/ban.class.php trunk/src/commands/join.class.php trunk/src/commands/kick.class.php trunk/src/commands/leave.class.php trunk/src/commands/unban.class.php trunk/src/commands/update.class.php trunk/src/pfccommand.class.php trunk/src/phpfreechat.class.php Modified: trunk/src/commands/ban.class.php =================================================================== --- trunk/src/commands/ban.class.php 2006-05-28 15:44:30 UTC (rev 522) +++ trunk/src/commands/ban.class.php 2006-05-28 15:46:57 UTC (rev 523) @@ -4,19 +4,39 @@ class pfcCommand_ban extends pfcCommand { + var $usage = "/ban {nickname}"; + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) { $c =& $this->c; $u =& $this->u; + if (trim($param) == "") + { + // error + $msg = _pfc("Missing parameter"); + $msg .= " (".$this->usage.")"; + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $clientid, $msg, $sender, $recipient, $recipientid); + return; + } + $container =& $c->getContainerInstance(); $nickid = $container->getNickId($param); if ($nickid != "undefined") { $cmdtoplay = $container->getMeta("cmdtoplay", "nickname", $nickid); $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - $cmdtoplay[] = array("leave",$recipientid); // ban the user from the current channel //_pfc("banished by %s", $sender); + + $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->setMeta(serialize($cmdtoplay), "cmdtoplay", "nickname", $nickid); } Modified: trunk/src/commands/join.class.php =================================================================== --- trunk/src/commands/join.class.php 2006-05-28 15:44:30 UTC (rev 522) +++ trunk/src/commands/join.class.php 2006-05-28 15:46:57 UTC (rev 523) @@ -4,15 +4,26 @@ class pfcCommand_join extends pfcCommand { + var $usage = "/join {channelname}"; + function run(&$xml_reponse, $clientid, &$param, &$sender, &$recipient, &$recipientid) { $c =& $this->c; $u =& $this->u; - $channame = $param; + $channame = trim($param); $chanrecip = pfcCommand_join::GetRecipient($channame); $chanid = pfcCommand_join::GetRecipientId($channame); + if ($channame == "") + { + $msg = _pfc("Missing parameter"); + $msg .= " (".$this->usage.")"; + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $clientid, $msg, $sender, $recipient, $recipientid); + return; + } + if(!isset($u->channels[$chanid])) { $u->channels[$chanid]["recipient"] = $chanrecip; Modified: trunk/src/commands/kick.class.php =================================================================== --- trunk/src/commands/kick.class.php 2006-05-28 15:44:30 UTC (rev 522) +++ trunk/src/commands/kick.class.php 2006-05-28 15:46:57 UTC (rev 523) @@ -4,11 +4,22 @@ class pfcCommand_kick extends pfcCommand { + var $usage = "/kick {nickname}"; + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) { $c =& $this->c; $u =& $this->u; + if (trim($param) == "") + { + // error + $msg = _pfc("Missing parameter"); + $msg .= " (".$this->usage.")"; + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $clientid, $msg, $sender, $recipient, $recipientid); + return; + } // kicking a user just add a command to play to the aimed user metadata. $container =& $c->getContainerInstance(); @@ -17,7 +28,14 @@ { $cmdtoplay = $container->getMeta("cmdtoplay", "nickname", $nickid); $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - $cmdtoplay[] = array("leave", $recipientid); // kick the user from the current channel //_pfc("kicked by %s", $sender); + $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->setMeta(serialize($cmdtoplay), "cmdtoplay", "nickname", $nickid); } } Modified: trunk/src/commands/leave.class.php =================================================================== --- trunk/src/commands/leave.class.php 2006-05-28 15:44:30 UTC (rev 522) +++ trunk/src/commands/leave.class.php 2006-05-28 15:46:57 UTC (rev 523) @@ -4,13 +4,22 @@ class pfcCommand_leave extends pfcCommand { + var $usage = "/leave [{recipientid} {reason}]"; + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) { $c =& $this->c; $u =& $this->u; // tab to leave can be passed in the parameters - $id = ($param != "") ? $param : $recipientid; + // a reason can also be present (used for kick and ban commands) + $id = ""; $reason = ""; + if (preg_match("/([a-z0-9]*) (.*)/i", $param, $res)) + { + $id = $res[1]; + $reason = $res[2]; + } + 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)."');"); @@ -44,9 +53,11 @@ { if ($leavech) { - // show a leave message + // show a leave message with the showing the reason if present + $msg = _pfc("%s quit",$u->nick); + if ($reason != "") $msg .= " (".$reason.")"; $cmd =& pfcCommand::Factory("notice"); - $cmd->run($xml_reponse, $clientid, _pfc("%s quit",$u->nick), $sender, $leave_recip, $leave_id, 1); + $cmd->run($xml_reponse, $clientid, $msg, $sender, $leave_recip, $leave_id, 1); } // remove the nickname from the channel/pv @@ -60,7 +71,10 @@ else { // error - $xml_reponse->addScript("alert('error leaving ".$id."');"); + $msg = _pfc("Missing parameter"); + $msg .= " (".$this->usage.")"; + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $clientid, $msg, $sender, $recipient, $recipientid); } } } Modified: trunk/src/commands/unban.class.php =================================================================== --- trunk/src/commands/unban.class.php 2006-05-28 15:44:30 UTC (rev 522) +++ trunk/src/commands/unban.class.php 2006-05-28 15:46:57 UTC (rev 523) @@ -4,6 +4,8 @@ class pfcCommand_unban extends pfcCommand { + var $usage = "/unban {id}"; + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) { $c =& $this->c; @@ -11,7 +13,16 @@ $container =& $c->getContainerInstance(); - + if (trim($param) == "") + { + // error + $msg = _pfc("Missing parameter"); + $msg .= " (".$this->usage.")"; + $cmd =& pfcCommand::Factory("error"); + $cmd->run($xml_reponse, $clientid, $msg, $sender, $recipient, $recipientid); + return; + } + $updated = false; $msg = "<p>"._pfc("Nobody has been unbanished")."</p>"; Modified: trunk/src/commands/update.class.php =================================================================== --- trunk/src/commands/update.class.php 2006-05-28 15:44:30 UTC (rev 522) +++ trunk/src/commands/update.class.php 2006-05-28 15:46:57 UTC (rev 523) @@ -23,19 +23,6 @@ // $cmd =& pfcCommand::Factory("notice"); // $cmd->run($xml_reponse, $clientid, _pfc("%s quit (timeout)",$u), $sender, $recipient, $recipientid, 2); // } - - - /* - // --- - // play the other commands - $nickid = $container->getNickId($u->nick); - $cmdtoplay = $container->getMeta("cmdtoplay", "nickname", $nickid); - $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - foreach($cmdtoplay as $cmdtmp) - $xml_reponse->addScript("pfc.handleResponse('update', 'cmdtoplay', Array('".$cmdtmp[0]."','".addslashes($cmdtmp[1])."'));"); - $container->rmMeta("cmdtoplay", "nickname", $nickid); - // --- - */ // update the user nickname timestamp $cmd =& pfcCommand::Factory("updatemynick"); Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2006-05-28 15:44:30 UTC (rev 522) +++ trunk/src/pfccommand.class.php 2006-05-28 15:46:57 UTC (rev 523) @@ -35,6 +35,11 @@ * Command name (lowercase) */ var $name; + + /** + * Contains the command syntaxe (how to use the command) + */ + var $usage; /** * Not used for now Modified: trunk/src/phpfreechat.class.php =================================================================== --- trunk/src/phpfreechat.class.php 2006-05-28 15:44:30 UTC (rev 522) +++ trunk/src/phpfreechat.class.php 2006-05-28 15:46:57 UTC (rev 523) @@ -354,10 +354,15 @@ $container =& $c->getContainerInstance(); $cmdtoplay = $container->getMeta("cmdtoplay", "nickname", $u->privmsg[$recipientid]["pvnickid"]); $cmdtoplay = ($cmdtoplay == NULL) ? array() : unserialize($cmdtoplay); - //if (!isset($cmdtoplay["privmsg2"])) $cmdtoplay["privmsg2"] = array(); - if (!in_array(array("privmsg2", $u->nick), $cmdtoplay)) + $cmdtmp = array("privmsg2", /* cmdname */ + $u->nick, /* param */ + $sender, /* sender */ + $recipient, /* recipient */ + $recipientid,/* recipientid */ + ); + if (!in_array($cmdtmp, $cmdtoplay)) { - $cmdtoplay[] = array("privmsg2", $u->nick); + $cmdtoplay[] = $cmdtmp; $container->setMeta(serialize($cmdtoplay), "cmdtoplay", "nickname", $u->privmsg[$recipientid]["pvnickid"]); //$xml_reponse->addScript("alert('cmdtoplay[]=".serialize($cmdtoplay)."');"); } @@ -385,12 +390,16 @@ // play the command $cmd =& pfcCommand::Factory($cmdtmp[0]); if ($c->debug) - $cmd->run($xml_reponse, $clientid, $cmdtmp[1], $sender, $recipient, $recipientid); + $cmd->run($xml_reponse, $clientid, $cmdtmp[1], $cmdtmp[2], $cmdtmp[3], $cmdtmp[4]); else - @$cmd->run($xml_reponse, $clientid, $cmdtmp[1], $sender, $recipient, $recipientid); + @$cmd->run($xml_reponse, $clientid, $cmdtmp[1], $cmdtmp[2], $cmdtmp[3], $cmdtmp[4]); + // if the cmdtoplay is a 'leave' command, then show an alert to the kicked or banished user if ($cmdtmp[0] == "leave") - $xml_reponse->addScript("alert('KICK');"); + { + 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->getMeta("cmdtoplay", "nickname", $nickid); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |