fixed Client.class.php (block timeouts) and some other bugs
authorpk910 <philipp@zoelle1.de>
Thu, 28 Jul 2011 00:57:25 +0000 (02:57 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 28 Jul 2011 00:57:25 +0000 (02:57 +0200)
BotLoader/BotLoader.class.php
Bots/ModManager.class.php
Bots/PHPGod.class.php
Uplink/Client.class.php

index 0201e4c7f006199488b621ffc3b1b9b6278aae40..9fd0f70bf8599409d6b14142bc812c1e6a0d5cb8 100644 (file)
@@ -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() {
index 61ce790d970bb15335ac406a0f246875a4c85b9f..a83e0a8b1e2ac2837e7e8bac9322ef832c3302b7 100644 (file)
@@ -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();
index 5fc4b873a81436721892bd1afb32a90b7f9d3f15..4b5a6751b925712e639e136e09f2ecad4677c139 100644 (file)
@@ -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) {
index 8a38610dba6870d5fa961f8c9acb6073b5df6da0..1c3f778189cc69ad91f9394fc8e67f0f827b3f5c 100644 (file)
@@ -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;