finished first "alpha" version of PHP-P10 v2
authorpk910 <philipp@zoelle1.de>
Thu, 28 Jul 2011 00:20:18 +0000 (02:20 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 28 Jul 2011 00:20:18 +0000 (02:20 +0200)
BotLoader/BotLoader.class.php
BotLoader/saxdb.class.php
BotLoader/saxdb.php [deleted file]
Bots/ModManager.class.php
ModCMD/ModCMD.class.php
Uplink/Uplink.class.php
main.php

index b5dc87b252cd482c934e5cf7581a0f91dc1d8e66..0201e4c7f006199488b621ffc3b1b9b6278aae40 100644 (file)
@@ -64,6 +64,7 @@ class BotLoader {
        }
        
        public function save() {
+               $this->saxdb->setSection("BotLoader", $this->botdb);
                $this->saxdb->writeDB("php_p10.db");
        }
        
@@ -115,6 +116,14 @@ class BotLoader {
        
        private function rehashBot($name) {
                if(!(array_key_exists(strtolower($name), $this->loadedBots))) return false;
+               $botfile = null;
+               foreach($this->botdb["bots"] as $botname => $file) {
+                       if(strtolower($botname) == strtolower($name)) {
+                               $botfile = $file;
+                               break;
+                       }
+               }
+               if(!$botfile) break;
                //rehash bot
                $bot = $this->loadedBots[strtolower($name)];
                if(array_key_exists(strtolower($name), $this->botDatabases)) {
index 15b36c2669a4a97f40021705c6e2e021d7ad5b4a..e3e5413dd634fa114c483492fe216f2aea2502b2 100644 (file)
@@ -152,13 +152,14 @@ class saxdb {
                return $output;
        }
        
-       private function serializeDB($db, $dbstring = "") {
+       private function serializeDB($db) {
+               $dbstring = "";
                foreach($db as $name => $value) {
                        if(!is_array($value) && !is_string($value) && !is_numeric($value)) continue;
                        $dbstring .= "\"".str_replace("\"","\\\"", $name)."\"";
                        if(is_array($value)) {
                                $dbstring .= "{";
-                               $dbstring .= $this->serializeDB($value, $dbstring);
+                               $dbstring .= $this->serializeDB($value);
                                $dbstring .= "}";
                        } else {
                                $dbstring .= "\"".str_replace("\"","\\\"", $value)."\"";
diff --git a/BotLoader/saxdb.php b/BotLoader/saxdb.php
deleted file mode 100644 (file)
index f60d65e..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-<?php
-/********************************* PHP-P10 ******************************
- *    P10 uplink class by pk910   (c)2011 pk910                         *
- ************************************************************************
- *                          Version 2 (OOP)                             *
- *                                                                      *
- * PHP-P10 is free software; you can redistribute it and/or modify      *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or    *
- * (at your option) any later version.                                  *
- *                                                                      *
- * This program 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 General Public License for more details.                         *
- *                                                                      *
- * You should have received a copy of the GNU General Public License    *
- * along with PHP-P10; if not, write to the Free Software Foundation,   *
- * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.       *
- *                                                                      *
- ************************************************************************
- * 
- *  BotLoader/saxdb.class.php
- *
- * Simple PHP P10 database.
- *
- */
-
-class saxdb {
-       const PARSER_ISSTRING  = 0x0001;
-       const PARSER_ISESCAPED = 0x0002;
-       const PARSER_ISBLOCK   = 0x0004;
-       const PARSER_EXPECT_VALUE = 0x0008;
-       const PARSER_STRING_LIST  = 0x0010;
-       private $database = array();
-       
-       public function loadDB($name) {
-               if(file_exists($name)) {
-                       $fp = fopen($name, "r");
-                       $db = fread($fp, filesize($name));
-                       fclose($fp);
-                       $this->database = $this->parseDB($db);
-               }
-       }
-       
-       public function writeDB($name) {
-               $fp = fopen($name, "w");
-               $db = $this->serializeDB($this->database);
-               fwrite($fp, $db);
-               fclose($fp);
-       }
-       
-       private function parseDB($db) {
-               $parserflags = 0;
-               $openblocks = 0;
-               $buffer = "";
-               $cache = array();
-               $output = array();
-               for($i = 0; $i < strlen($db); $i++) {
-                       if(($parserflags & self::PARSER_ISBLOCK) && $db[$i] != "{" && $db[$i] != "}") {
-                               $buffer .= $db[$i];
-                               continue;
-                       }
-                       if(($parserflags & self::PARSER_ISSTRING) && $db[$i] != "\"") {
-                               $buffer .= $db[$i];
-                               continue;
-                       }
-                       if($parserflags & self::PARSER_ISESCAPED) {
-                               $buffer .= $db[$i];
-                               $parserflags &= ~self::PARSER_ISESCAPED;
-                               continue;
-                       }
-                       switch($db[$i]) {
-                               case "\\":
-                                       $parserflags |= self::PARSER_ISESCAPED;
-                                       break;
-                               case "\"":
-                                       if($parserflags & self::PARSER_ISSTRING) {
-                                               $parserflags &= ~self::PARSER_ISSTRING;
-                                               if($parserflags & self::PARSER_STRING_LIST) {
-                                                       $cache['list'][] = $buffer;
-                                               } else if($parserflags & self::PARSER_EXPECT_VALUE) {
-                                                       //we've got a full entry
-                                                       $output[$cache['name']] = $buffer;
-                                                       $parserflags &= ~self::PARSER_EXPECT_VALUE;
-                                               } else {
-                                                       //we've only got the name of the next entry
-                                                       $cache['name'] = $buffer;
-                                                       $parserflags |= self::PARSER_EXPECT_VALUE;
-                                               }
-                                       } else {
-                                               $buffer = ""; //clear the buffer
-                                               $parserflags |= self::PARSER_ISSTRING;
-                                       }
-                                       break;
-                               case "{":
-                                       //block (it must be a value)
-                                       if($parserflags & self::PARSER_ISBLOCK) {
-                                               $openblocks++;
-                                               $buffer .= $db[$i];
-                                       } else {
-                                               $parserflags |= self::PARSER_ISBLOCK;
-                                               $buffer = "";
-                                       }
-                                       break;
-                               case "}":
-                                       if($parserflags & self::PARSER_ISBLOCK) {
-                                               $openblocks--;
-                                               if($openblocks == -1) {
-                                                       $parserflags &= ~self::PARSER_ISBLOCK;
-                                                       if($parserflags & self::PARSER_EXPECT_VALUE) {
-                                                               $output[$cache['name']] = $this->parseDB($buffer);
-                                                               $parserflags &= ~self::PARSER_EXPECT_VALUE;
-                                                       }
-                                               } else {
-                                                       $buffer .= $db[$i];
-                                               }
-                                       }
-                                       break;
-                               case "(":
-                                       if(!($parserflags & self::PARSER_STRING_LIST)) {
-                                               $cache['list'] = array();
-                                               $parserflags |= self::PARSER_STRING_LIST;
-                                       }
-                                       break;
-                               case ")":
-                                       if(($parserflags & self::PARSER_STRING_LIST)) {
-                                               $parserflags &= ~self::PARSER_STRING_LIST;
-                                               if($parserflags & self::PARSER_EXPECT_VALUE) {
-                                                       $output[$cache['name']] = $cache['list'];
-                                                       $parserflags &= ~self::PARSER_EXPECT_VALUE;
-                                               }
-                                       }
-                                       break;
-                               default:
-                                       $buffer .= $db[$i];
-                                       break;
-                       }
-               }
-               return $output;
-       }
-       
-       private function serializeDB($db, $dbstring = "") {
-               foreach($db as $name => $value) {
-                       if(!is_array($value) && !is_string($value) && !is_numeric($value)) continue;
-                       $dbstring .= "\"".str_replace("\"","\\\"", $name)."\"";
-                       if(is_array($value)) {
-                               $dbstring .= "{";
-                               $dbstring .= $this->serializeDB($value, $dbstring);
-                               $dbstring .= "}";
-                       } else {
-                               $dbstring .= "\"".str_replace("\"","\\\"", $value)."\"";
-                       }
-               }
-               return $dbstring;
-       }
-       
-}
-
-?>
\ No newline at end of file
index 4eac48c06bbd78ba379e40b624f3a0b773ff86f9..61ce790d970bb15335ac406a0f246875a4c85b9f 100644 (file)
@@ -48,7 +48,7 @@ class {$_NAME} extends Bot {
                        $this->modman = $old;
                }
                
-               ModCMD::bind($this, BIND_PRIVMSG, "recive_privmsg");
+               ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg");
                ModCMD::bind($this, BIND_QUIT, "recive_quit");
        }
        
index 6c735a6bb28fcd90063559897bfcdf2f5d95c669..026b8ae5deea020ab6ffc8c5ed1a56ba38ee64f8 100644 (file)
@@ -122,7 +122,7 @@ class ModCMD implements EventHandler {
        
        private function event($type, $parameters) {
                if(array_key_exists($type, self::$bindings)) {
-                       foreach(self::$bindings as $binding) {
+                       foreach(self::$bindings[$type] as $binding) {
                                $binding->trigger($parameters);
                        }
                }
index 867cb8587da7e40752c344a007e31276685a717d..14585f6901fc5a7b11b253ad7a97b299c1143358 100644 (file)
@@ -543,7 +543,7 @@ class Uplink {
                        return;
                }
                if($this->eventHandler) {
-                       if($args[0] == "#") {
+                       if($args[0][0] == "#") {
                                $channel = P10_Channel::getChannelByName($args[0]);
                                if($channel == null)
                                        $channel = new P10_Channel($args[0]);
@@ -566,7 +566,7 @@ class Uplink {
                        return;
                }
                if($this->eventHandler) {
-                       if($args[0] == "#") {
+                       if($args[0][0] == "#") {
                                $channel = P10_Channel::getChannelByName($args[0]);
                                if($channel == null)
                                        $channel = new P10_Channel($args[0]);
index 57ec8624e912e340e931b5294dcc6f4db7956dd0..af8810c05517d0b4a212a6785a0bc972e893819d 100644 (file)
--- a/main.php
+++ b/main.php
@@ -52,13 +52,10 @@ $botloader = new BotLoader($uplink);
 $botloader->loadBots();
 BotLoader::load("ModManager", "ModManager.class.php");
 
-function shutdown($signal) {
+function shutdown($signal = 0) {
        global $botloader;
        global $uplink;
-       if($signal == SIGINT) $type="SIGINT";
-       else if($signal == SIGTERM) $type="SIGTERM";
-       else $type = $signal;
-       echo "\n\nrecived shutdown instruction... ".$type."\n";
+       echo "\n\nrecived shutdown instruction...\n";
        $botloader->unloadBots();
        $botloader->save();
        $uplink->shutdown();