[Phpfreechat-svn] SF.net SVN: phpfreechat: [782] trunk
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-09-22 09:29:04
|
Revision: 782 http://svn.sourceforge.net/phpfreechat/?rev=782&view=rev Author: kerphi Date: 2006-09-22 02:28:51 -0700 (Fri, 22 Sep 2006) Log Message: ----------- [en] Improve noflood proxy algorithme: now it takes into account the number of posted characteres and the number of posted messages. [fr] Ammelioration du proxy noflood : maintenant il prend en compte le nombre de caracteres postes ainsi que le nombre de messsages postes. Modified Paths: -------------- trunk/src/pfcglobalconfig.class.php trunk/src/proxies/noflood.class.php Added Paths: ----------- trunk/lib/utf8/utf8_strlen.php Added: trunk/lib/utf8/utf8_strlen.php =================================================================== --- trunk/lib/utf8/utf8_strlen.php (rev 0) +++ trunk/lib/utf8/utf8_strlen.php 2006-09-22 09:28:51 UTC (rev 782) @@ -0,0 +1,24 @@ +<?php + +/** + * Counts the number of characters of a string in UTF-8. + * Unit-tested by Kasper and works 100% like strlen() / mb_strlen() + * + * @param string UTF-8 multibyte character string + * @return integer The number of characters + * @see strlen() + * @author Martin Kutschker <mar...@bl...> + */ +function utf8_strlen($str) { + $n=0; + for($i=0; strlen($str{$i}); $i++) { + $c = ord($str{$i}); + if (!($c & 0x80)) // single-byte (0xxxxxx) + $n++; + elseif (($c & 0xC0) == 0xC0) // multi-byte starting byte (11xxxxxx) + $n++; + } + return $n; +} + +?> \ No newline at end of file Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-09-22 08:12:22 UTC (rev 781) +++ trunk/src/pfcglobalconfig.class.php 2006-09-22 09:28:51 UTC (rev 782) @@ -45,7 +45,7 @@ var $post_proxies = array(); // these proxies will be handled just before to process commands and just after system proxies var $pre_proxies = array(); // these proxies will be handled before system proxies (at begining) var $proxies_cfg = array("auth" => array(), - "noflood" => array("limit"=>10,"delay"=>5), + "noflood" => array("charlimit"=>450,"msglimit"=>10,"delay"=>5), "censor" => array("words"=>array("fuck","sex","bitch"),"replaceby"=>"*"), "log" => array("path"=>"")); var $proxies_path = ""; // a custom proxies path Modified: trunk/src/proxies/noflood.class.php =================================================================== --- trunk/src/proxies/noflood.class.php 2006-09-22 08:12:22 UTC (rev 781) +++ trunk/src/proxies/noflood.class.php 2006-09-22 09:28:51 UTC (rev 782) @@ -22,6 +22,7 @@ require_once dirname(__FILE__)."/../pfci18n.class.php"; require_once dirname(__FILE__)."/../pfcuserconfig.class.php"; require_once dirname(__FILE__)."/../pfcproxycommand.class.php"; +require_once dirname(__FILE__)."/../../lib/utf8/utf8_strlen.php"; /** * pfcProxyCommand_noflood @@ -48,15 +49,26 @@ $nickid = $u->nickid; $isadmin = $container->getUserMeta($nickid, 'isadmin'); $lastfloodtime = $container->getUserMeta($nickid, 'floodtime'); - $nbflood = $container->getUserMeta($nickid, 'nbflood'); + $flood_nbmsg = $container->getUserMeta($nickid, 'flood_nbmsg'); + $flood_nbchar = $container->getUserMeta($nickid, 'flood_nbchar'); $floodtime = time(); - + + // update the number of posted message indicator if ($floodtime - $lastfloodtime <= $c->proxies_cfg[$this->proxyname]["delay"]) - $nbflood++; + $flood_nbmsg++; else - $nbflood = 0; + $flood_nbmsg = 0; + + // update the number of posted characteres indicator + if ($floodtime - $lastfloodtime <= $c->proxies_cfg[$this->proxyname]["delay"]) + $flood_nbchar += utf8_strlen($param); + else + $flood_nbchar = 0; - if ($nbflood>$c->proxies_cfg[$this->proxyname]["limit"]) + if (!$isadmin && + ($flood_nbmsg>$c->proxies_cfg[$this->proxyname]["msglimit"] || + $flood_nbchar>$c->proxies_cfg[$this->proxyname]["charlimit"]) + ) { // warn the flooder $msg = _pfc("Please don't post so many message, flood is not tolerated"); @@ -71,9 +83,10 @@ return; } - if ($nbflood == 0) + if ($flood_nbmsg == 0) $container->setUserMeta($nickid, 'floodtime', $floodtime); - $container->setUserMeta($nickid, 'nbflood', $nbflood); + $container->setUserMeta($nickid, 'flood_nbmsg', $flood_nbmsg); + $container->setUserMeta($nickid, 'flood_nbchar', $flood_nbchar); } // forward the command to the next proxy or to the final command This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |