[Phpfreechat-svn] SF.net SVN: phpfreechat: [517] trunk/src/proxys
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-05-28 11:54:05
|
Revision: 517 Author: kerphi Date: 2006-05-28 04:53:48 -0700 (Sun, 28 May 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=517&view=rev Log Message: ----------- New commands : /ban, /banlist, /unban (with a first basic implementation) Modified Paths: -------------- trunk/src/commands/join.class.php trunk/src/commands/kick.class.php trunk/src/proxys/auth.class.php trunk/themes/default/templates/pfcclient.js.tpl.php trunk/themes/default/templates/style.css.tpl.php Added Paths: ----------- trunk/src/commands/ban.class.php trunk/src/commands/banlist.class.php trunk/src/commands/unban.class.php Added: trunk/src/commands/ban.class.php =================================================================== --- trunk/src/commands/ban.class.php (rev 0) +++ trunk/src/commands/ban.class.php 2006-05-28 11:53:48 UTC (rev 517) @@ -0,0 +1,36 @@ +<?php + +require_once(dirname(__FILE__)."/../pfccommand.class.php"); + +class pfcCommand_ban extends pfcCommand +{ + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) + { + $c =& $this->c; + $u =& $this->u; + + + $container =& $c->getContainerInstance(); + $nickid = $container->getNickId($param); + if ($nickid != "undefined") + { + $cmdtoplay = $container->getMeta("cmdtoplay", "nickname", $nickid); + if (is_string($cmdtoplay)) $cmdtoplay = unserialize($cmdtoplay); + if (!is_array($cmdtoplay)) $cmdtoplay = array(); + if (!isset($cmdtoplay["leave"])) $cmdtoplay["leave"] = array(); + $cmdtoplay["leave"][] = $recipientid; // ban the user from the current channel //_pfc("banished by %s", $sender); + $container->setMeta(serialize($cmdtoplay), "cmdtoplay", "nickname", $nickid); + } + + // update the recipient banlist + $banlist = $container->getMeta("banlist_nickid", "channel", $recipientid); + if ($banlist == NULL) + $banlist = array(); + else + $banlist = unserialize($banlist); + $banlist[] = $nickid; // append the nickid to the banlist + $container->setMeta(serialize($banlist), "banlist_nickid", "channel", $recipientid); + } +} + +?> \ No newline at end of file Added: trunk/src/commands/banlist.class.php =================================================================== --- trunk/src/commands/banlist.class.php (rev 0) +++ trunk/src/commands/banlist.class.php 2006-05-28 11:53:48 UTC (rev 517) @@ -0,0 +1,41 @@ +<?php + +require_once(dirname(__FILE__)."/../pfccommand.class.php"); + +/** + * This command list the banished users on the given channel + * + * @author Stephane Gully <ste...@gm...> + */ +class pfcCommand_banlist extends pfcCommand +{ + var $desc = "This command list the banished users on the given channel"; + + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) + { + $c =& $this->c; + $u =& $this->u; + + $container =& $c->getContainerInstance(); + $banlist = $container->getMeta("banlist_nickid", "channel", $recipientid); + if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist); + $msg = ""; + $msg .= "<p>"._pfc("The banished user's id list is:")."</p>"; + if (count($banlist)>0) + { + $msg .= "<ul>"; + foreach($banlist as $b) $msg .= "<li style=\"margin-left:50px\">".$b."</li>"; + $msg .= "</ul>"; + } + else + { + $msg .= "<p>("._pfc("Empty").")</p>"; + } + $msg .= "<p>"._pfc("'/unban {id}' command will unban the user identified by {id}")."</p>"; + $msg .= "<p>"._pfc("'/unban all' command will unban all the users on this channel")."</p>"; + + $xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'ok', '".addslashes($msg)."');"); + } +} + +?> \ No newline at end of file Modified: trunk/src/commands/join.class.php =================================================================== --- trunk/src/commands/join.class.php 2006-05-28 11:52:22 UTC (rev 516) +++ trunk/src/commands/join.class.php 2006-05-28 11:53:48 UTC (rev 517) @@ -10,8 +10,8 @@ $u =& $this->u; $channame = $param; - $chanrecip = "ch_".$channame; - $chanid = md5($channame); + $chanrecip = pfcCommand_join::GetRecipient($channame); + $chanid = pfcCommand_join::GetRecipientId($channame); if(!isset($u->channels[$chanid])) { @@ -42,6 +42,16 @@ // then the client will create a new tab $xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'ok', Array('".$chanid."','".addslashes($channame)."'));"); } + + function GetRecipient($channame) + { + return "ch_".$channame; + } + + function GetRecipientId($channame) + { + return md5(pfcCommand_join::GetRecipient($channame)); + } } Modified: trunk/src/commands/kick.class.php =================================================================== --- trunk/src/commands/kick.class.php 2006-05-28 11:52:22 UTC (rev 516) +++ trunk/src/commands/kick.class.php 2006-05-28 11:53:48 UTC (rev 517) @@ -18,11 +18,10 @@ $cmdtoplay = $container->getMeta("cmdtoplay", "nickname", $nickid); if (is_string($cmdtoplay)) $cmdtoplay = unserialize($cmdtoplay); if (!is_array($cmdtoplay)) $cmdtoplay = array(); - if (!isset($cmdtoplay["quit"])) $cmdtoplay["quit"] = array(); - $cmdtoplay["quit"][] = _pfc("kicked by %s", $sender); + if (!isset($cmdtoplay["leave"])) $cmdtoplay["leave"] = array(); + $cmdtoplay["leave"][] = $recipientid; // kick the user from the current channel //_pfc("kicked by %s", $sender); $container->setMeta(serialize($cmdtoplay), "cmdtoplay", "nickname", $nickid); } - } } Added: trunk/src/commands/unban.class.php =================================================================== --- trunk/src/commands/unban.class.php (rev 0) +++ trunk/src/commands/unban.class.php 2006-05-28 11:53:48 UTC (rev 517) @@ -0,0 +1,48 @@ +<?php + +require_once(dirname(__FILE__)."/../pfccommand.class.php"); + +class pfcCommand_unban extends pfcCommand +{ + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) + { + $c =& $this->c; + $u =& $this->u; + + $container =& $c->getContainerInstance(); + + + $updated = false; + $msg = "<p>"._pfc("Nobody has been unbanished")."</p>"; + + // update the recipient banlist + $banlist = $container->getMeta("banlist_nickid", "channel", $recipientid); + if ($banlist == NULL) + $banlist = array(); + else + $banlist = unserialize($banlist); + $nb = count($banlist); + + if (in_array($param, $banlist)) + { + $banlist = array_diff($banlist, array($param)); + $container->setMeta(serialize($banlist), "banlist_nickid", "channel", $recipientid); + $updated = true; + $msg = "<p>"._pfc("%s has been unbanished", $param)."</p>"; + } + else if ($param == "all") + { + $banlist = array(); + $container->setMeta(serialize($banlist), "banlist_nickid", "channel", $recipientid); + $updated = true; + $msg = "<p>"._pfc("%s users have been unbanished", $nb)."</p>"; + } + + if ($updated) + $xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'ok', '".$msg."');"); + else + $xml_reponse->addScript("pfc.handleResponse('".$this->name."', 'ko', '".$msg."');"); + } +} + +?> \ No newline at end of file Modified: trunk/src/proxys/auth.class.php =================================================================== --- trunk/src/proxys/auth.class.php 2006-05-28 11:52:22 UTC (rev 516) +++ trunk/src/proxys/auth.class.php 2006-05-28 11:53:48 UTC (rev 517) @@ -47,7 +47,25 @@ $xml_reponse->addScript("alert('not allowed to do /op');"); } } + if ($this->name == "join") + { + // check the user is not listed in the banished channel list + $container =& $c->getContainerInstance(); + $channame = $param; + $chanid = pfcCommand_join::GetRecipientId($channame); + $banlist = $container->getMeta("banlist_nickid", "channel", $chanid); + if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist); + $nickid = $container->getNickId($u->nick); + if (in_array($nickid,$banlist)) + { + + // the user is banished, show a message and don't forward the /join command + $msg = _pfc("Can't join %s because you are banished", $param); + $xml_reponse->addScript("pfc.handleResponse('".$this->proxyname."', 'ban', '".addslashes($msg)."');"); + return; + } + } // on passe la main a au prochain proxy (ou a la command finale) $this->next->run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid); Modified: trunk/themes/default/templates/pfcclient.js.tpl.php =================================================================== --- trunk/themes/default/templates/pfcclient.js.tpl.php 2006-05-28 11:52:22 UTC (rev 516) +++ trunk/themes/default/templates/pfcclient.js.tpl.php 2006-05-28 11:53:48 UTC (rev 517) @@ -336,6 +336,10 @@ this.sendRequest("/"+param[0],param[1]); } } + else if (param[0] == "leave") + { + this.sendRequest("/"+param[0],param[1]); + } else this.sendRequest("/"+param[0],param[1]); } @@ -346,13 +350,47 @@ { if (resp == "ok") { - this.displayMsg( 'rehash', this.i18n._('Configuration has been rehashed') ); + this.displayMsg( cmd, this.i18n._('Configuration has been rehashed') ); } else if (resp == "ko") { - this.displayMsg( 'rehash', this.i18n._('A problem occurs during rehash') ); + this.displayMsg( cmd, this.i18n._('A problem occurs during rehash') ); } } + else if (cmd == "banlist") + { + if (resp == "ok" || resp == "ko") + { + this.displayMsg( cmd, param ); + } + } + else if (cmd == "unban") + { + if (resp == "ok" || resp == "ko") + { + this.displayMsg( cmd, param ); + } + } + else if (cmd == "auth") + { + if (resp == "ban") + { + alert(param); + } + } + else if (cmd == "debug") + { + if (resp == "ok" || resp == "ko") + { + this.displayMsg( cmd, param ); + } + } + else if (cmd == "clear") + { + var tabid = this.gui.getTabId(); + var container = this.gui.getChatContentFromTabId(tabid); + container.innerHTML = ""; + } else alert(cmd + "-"+resp+"-"+param); }, @@ -546,12 +584,20 @@ var tabid = this.gui.getTabId(); var container = this.gui.getChatContentFromTabId(tabid); - // create a dummy div to avoid konqueror bug when setting nickmarkers - var m = document.createElement('div'); - m.innerHTML = '<pre class="<?php echo $prefix; ?>cmd_'+cmd+'">'+msg+'</pre>'; + div = document.createElement('div'); + div.style.padding = "2px 5px 2px 5px"; + + pre = document.createElement('pre'); + Element.addClassName(pre, '<?php echo $prefix; ?>info'); + Element.addClassName(pre, '<?php echo $prefix; ?>info_'+cmd); + pre.style.border = "1px solid #555"; + pre.style.padding = "5px"; + pre.innerHTML = msg; + div.appendChild(pre); + // finaly append this to the message list - container.appendChild(m); - this.gui.scrollDown(tabid, m); + container.appendChild(div); + this.gui.scrollDown(tabid, div); }, handleComingRequest: function( cmds ) Modified: trunk/themes/default/templates/style.css.tpl.php =================================================================== --- trunk/themes/default/templates/style.css.tpl.php 2006-05-28 11:52:22 UTC (rev 516) +++ trunk/themes/default/templates/style.css.tpl.php 2006-05-28 11:53:48 UTC (rev 517) @@ -214,7 +214,7 @@ padding: 2px; height: 18px; - border: black solid 1px; + border: 1px solid #555; color: #FC4A1F; background-color: #FFBA76; text-align: center; @@ -234,11 +234,12 @@ font-style: italic; color: #888; } -pre.<?php echo $prefix; ?>cmd_rehash, -pre.<?php echo $prefix; ?>cmd_help -{ + +/* commands info */ +pre.<?php echo $prefix; ?>info { color: #888; font-style: italic; + background-color: #EEE; } div#<?php echo $prefix; ?>colorlist { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |