From: pk910 Date: Thu, 28 Jul 2011 00:20:18 +0000 (+0200) Subject: finished first "alpha" version of PHP-P10 v2 X-Git-Url: http://git.pk910.de/?p=PHP-P10.git;a=commitdiff_plain;h=316aa700bd3e2e0019b8e3f10b543b49b0f77f02 finished first "alpha" version of PHP-P10 v2 --- diff --git a/BotLoader/BotLoader.class.php b/BotLoader/BotLoader.class.php index b5dc87b..0201e4c 100644 --- a/BotLoader/BotLoader.class.php +++ b/BotLoader/BotLoader.class.php @@ -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)) { diff --git a/BotLoader/saxdb.class.php b/BotLoader/saxdb.class.php index 15b36c2..e3e5413 100644 --- a/BotLoader/saxdb.class.php +++ b/BotLoader/saxdb.class.php @@ -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 index f60d65e..0000000 --- a/BotLoader/saxdb.php +++ /dev/null @@ -1,160 +0,0 @@ -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 diff --git a/Bots/ModManager.class.php b/Bots/ModManager.class.php index 4eac48c..61ce790 100644 --- a/Bots/ModManager.class.php +++ b/Bots/ModManager.class.php @@ -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"); } diff --git a/ModCMD/ModCMD.class.php b/ModCMD/ModCMD.class.php index 6c735a6..026b8ae 100644 --- a/ModCMD/ModCMD.class.php +++ b/ModCMD/ModCMD.class.php @@ -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); } } diff --git a/Uplink/Uplink.class.php b/Uplink/Uplink.class.php index 867cb85..14585f6 100644 --- a/Uplink/Uplink.class.php +++ b/Uplink/Uplink.class.php @@ -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]); diff --git a/main.php b/main.php index 57ec862..af8810c 100644 --- 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();