From: pk910 Date: Thu, 28 Jul 2011 00:57:25 +0000 (+0200) Subject: fixed Client.class.php (block timeouts) and some other bugs X-Git-Url: http://git.pk910.de/?p=PHP-P10.git;a=commitdiff_plain;h=3927f0cb5827f9da038702bb0f7a8efd69b34aa7 fixed Client.class.php (block timeouts) and some other bugs --- diff --git a/BotLoader/BotLoader.class.php b/BotLoader/BotLoader.class.php index 0201e4c..9fd0f70 100644 --- a/BotLoader/BotLoader.class.php +++ b/BotLoader/BotLoader.class.php @@ -95,6 +95,7 @@ class BotLoader { if(!array_key_exists($name, $this->botdb["bots"])) { $this->botdb["bots"][$name] = $botfile; } + return true; } private function unloadBot($name, $delete = true) { @@ -112,6 +113,7 @@ class BotLoader { if(array_key_exists($name, $this->botdb["bots"]) && $delete) { unset($this->botdb["bots"][$name]); } + return true; } private function rehashBot($name) { @@ -139,6 +141,7 @@ class BotLoader { if(!$bot) return false; $bot->load($this->uplink, $data); $this->loadedBots[strtolower($name)] = $bot; + return true; } private function listLoadedBots() { diff --git a/Bots/ModManager.class.php b/Bots/ModManager.class.php index 61ce790..a83e0a8 100644 --- a/Bots/ModManager.class.php +++ b/Bots/ModManager.class.php @@ -85,6 +85,11 @@ class {$_NAME} extends Bot { $this->uplink->privmsg($this->modman, $channel, "error."); } break; + case "~list": + foreach(BotLoader::listBots() as $name => $bot) { + $this->uplink->privmsg($this->modman, $channel, $name); + } + break; case "~debug": $exp=explode(" ",$message,2); ob_start(); diff --git a/Bots/PHPGod.class.php b/Bots/PHPGod.class.php index 5fc4b87..4b5a675 100644 --- a/Bots/PHPGod.class.php +++ b/Bots/PHPGod.class.php @@ -28,7 +28,7 @@ class {$_NAME} extends Bot { private $uplink; - private $php, $phpcache; + private $php, $phpcache = array(); public function load($uplink, $old = false) { $this->uplink = $uplink; @@ -53,7 +53,7 @@ class {$_NAME} extends Bot { } public function unload($rehash = false) { - foreach($this->phpcache as $id => &$php) { + foreach($this->phpcache as $id => $php) { fclose($php['pipes'][1]); fclose($php['pipes'][2]); proc_terminate($php['proc'],9); @@ -67,8 +67,8 @@ class {$_NAME} extends Bot { } public function loop() { - foreach($this->phpcache as $id => &$php) { - if(!$this->checkstate(&$php)) { + foreach($this->phpcache as $id => $php) { + if(!$this->checkstate($php)) { unset($this->phpcache[$id]); } } @@ -82,7 +82,7 @@ class {$_NAME} extends Bot { $opOnPHPChannel = ($privs & P10_Channel::USERPRIV_OPED); } if(!$user->getModes()->hasMode('o') && !$opOnPHPChannel) return 0; - $exp=explode(" ",$message); + $exp=explode(" ", $message, 2); switch (strtolower($exp[0])) { case "~php": if(count($this->phpcache) > 5) { diff --git a/Uplink/Client.class.php b/Uplink/Client.class.php index 8a38610..1c3f778 100644 --- a/Uplink/Client.class.php +++ b/Uplink/Client.class.php @@ -54,6 +54,7 @@ class Client { private $socket; private $traffic = array("in" => 0, "out" => 0); + private $timeout; public function connect($host, $port, $bind = null, $ssl = false, $blocking = 0) { if($bind) @@ -63,12 +64,8 @@ class Client { $context = stream_context_create($options); $sock = stream_socket_client(($ssl ? 'ssl://' : '').$host.':'.$port, $errno, $errstr, 3, STREAM_CLIENT_CONNECT, $context); if($sock) { - if($blocking) { - stream_set_blocking($sock, true); - stream_set_timeout($sock, 0, ($blocking / 1000)); - } else { - stream_set_blocking($sock, false); - } + $this->timeout = $blocking * 1000; + stream_set_blocking($sock, false); $this->socket = $sock; return true; } else @@ -98,7 +95,7 @@ class Client { $read = array($this->socket); $write= null; $except=null; - $n=@stream_select($read, $write, $except, 0); + $n=@stream_select($read, $write, $except, 0, $this->timeout); if($n === FALSE || feof($this->socket)) { $this->socket = false; return null;