[Phpfreechat-svn] SF.net SVN: phpfreechat: [878] trunk/src/commands/invite.class.php
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-11-27 17:36:53
|
Revision: 878 http://svn.sourceforge.net/phpfreechat/?rev=878&view=rev Author: kerphi Date: 2006-11-27 09:36:52 -0800 (Mon, 27 Nov 2006) Log Message: ----------- [en] New /invite command. Syntax is: /invite {nickname to invite} [{target channel}] (thanks to Benedikt Hallinger) [20min] [fr] Nouvelle commande /invite permettant d'inviter une personne dans un salon. La syntaxe de la commande est : /invite {pseudo a inviter} [{salon de destination}] (merci ?\195?\160 Benedikt Hallinger) [20min] Added Paths: ----------- trunk/src/commands/invite.class.php Added: trunk/src/commands/invite.class.php =================================================================== --- trunk/src/commands/invite.class.php (rev 0) +++ trunk/src/commands/invite.class.php 2006-11-27 17:36:52 UTC (rev 878) @@ -0,0 +1,82 @@ +<?php + +/** + * invite.class.php + * + * Copyright \xA9 2006 Stephane Gully <ste...@gm...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +/** + * /invite command + * + * Invites other users into a channel + * Currently this is implemented as a "autojoin", so the invited user joins automatically. + * The parameter "target channel" is optional, if not set it defaults to the current channel + * + * @author Benedikt Hallinger <be...@ph...> + */ +class pfcCommand_invite extends pfcCommand +{ + 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"]; + + $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 + + // 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); + } + } +} +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |