From: NurPech Date: Mon, 9 Apr 2012 22:56:59 +0000 (+0200) Subject: format X-Git-Url: http://git.pk910.de/?p=PHP-P10.git;a=commitdiff_plain;h=7f51193ddac01b0540000c756c50167ff015e02a format --- diff --git a/BotLoader/Bot.class.php b/BotLoader/Bot.class.php index d954648..c24e51e 100644 --- a/BotLoader/Bot.class.php +++ b/BotLoader/Bot.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * BotLoader/Bot.class.php * * bots' parent class. @@ -25,31 +25,31 @@ class Bot { private $db_section = NULL; - + public function load($uplink, $oldDatas = null) { - + } - + public function unload($rehash = false) { - + } - + public function loop() { - + } - + public function writeDB() { - + } - + public function readDB($value) { - + } - + public function getDBSection() { return $this->db_section; } - + public function setDBSection($section) { $this->db_section = $section; } diff --git a/BotLoader/BotLoader.class.php b/BotLoader/BotLoader.class.php index 0ad3dd4..f7903d4 100644 --- a/BotLoader/BotLoader.class.php +++ b/BotLoader/BotLoader.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * BotLoader/BotLoader.class.php * * This class loades / rehashs or unloads all Bots. @@ -34,7 +34,7 @@ class BotLoader { private $loadedBots = array(); private $botDatabases = array(); private static $botloader; - + public function __construct($uplink) { $this->uplink = $uplink; $this->saxdb = new saxdb(); @@ -43,7 +43,7 @@ class BotLoader { self::$botloader = $this; timer(60*10, array($this, "autosave"), array()); } - + public function loadBots() { if(array_key_exists("bots", $this->botdb) && is_array($this->botdb["bots"])) { foreach($this->botdb["bots"] as $name => $botfile) { @@ -53,18 +53,18 @@ class BotLoader { $this->botdb["bots"] = array(); } } - + public function unloadBots() { foreach($this->loadedBots as $name => $bot) { $this->unloadBot($name, false); } } - + public function save() { $this->saxdb->setSection("BotLoader", $this->botdb); $this->saxdb->writeDB("php_p10.db"); } - + public function autosave() { foreach($this->loadedBots as $name => $bot) { if($bot->getDBSection()) { @@ -75,13 +75,13 @@ class BotLoader { $this->save(); timer(60*10, array($this, "autosave"), array()); } - + public function loop() { foreach($this->loadedBots as $name => $bot) { $bot->loop(); } } - + private function loadBot($name, $botfile) { if(array_key_exists(strtolower($name), $this->loadedBots)) return false; //load bot @@ -94,7 +94,7 @@ class BotLoader { } return true; } - + private function unloadBot($name, $delete = true) { if(!(array_key_exists(strtolower($name), $this->loadedBots))) return false; //unload bot @@ -111,7 +111,7 @@ class BotLoader { } return true; } - + private function rehashBot($name) { if(!(array_key_exists(strtolower($name), $this->loadedBots))) return false; $botfile = null; @@ -138,17 +138,17 @@ class BotLoader { $this->loadedBots[strtolower($name)] = $bot; return true; } - + private function listLoadedBots() { return $this->loadedBots; } - + private function addDBsection($bot, $section) { if(!is_a($bot, "Bot")) return false; $bot->setDBSection($section); $bot->readDB($this->saxdb->getSection($section)); } - + private function loadClass($file, $classprefix) { $dir = self::BOT_DIR; $tmp = self::TMP_DIR; @@ -168,23 +168,23 @@ class BotLoader { unlink($tmp."/modules_".$classprefix."_".$class.".tmp.php"); return $newclass; } - + public static function load($name, $botfile) { return self::$botloader->loadBot($name, $botfile); } - + public static function unload($name) { return self::$botloader->unloadBot($name); } - + public static function rehash($name) { return self::$botloader->rehashBot($name); } - + public static function listBots() { return self::$botloader->listLoadedBots(); } - + public static function registerDB($bot, $name) { return self::$botloader->addDBsection($bot, $name); } diff --git a/BotLoader/saxdb.class.php b/BotLoader/saxdb.class.php index f4d0e55..f6885a8 100644 --- a/BotLoader/saxdb.class.php +++ b/BotLoader/saxdb.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * BotLoader/saxdb.class.php * * Simple PHP P10 database. @@ -30,7 +30,7 @@ class saxdb { 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"); @@ -39,14 +39,14 @@ class saxdb { $this->database = $this->parseDB($db); } } - + public function writeDB($name) { $fp = fopen($name, "w"); $db = $this->serializeDB($this->database); fwrite($fp, $db); fclose($fp); } - + public function getSection($name) { if(array_key_exists($name, $this->database)) { return $this->database[$name]; @@ -54,11 +54,11 @@ class saxdb { return array(); } } - + public function setSection($name, $value) { $this->database[$name] = $value; } - + private function parseDB($db) { $parserflags = 0; $openblocks = 0; @@ -148,7 +148,7 @@ class saxdb { } return $output; } - + private function serializeDB($db) { $dbstring = ""; foreach($db as $name => $value) { @@ -167,7 +167,7 @@ class saxdb { } return $dbstring; } - + } ?> \ No newline at end of file diff --git a/Bots/CGod.class.php b/Bots/CGod.class.php index f6f8d71..0910599 100644 --- a/Bots/CGod.class.php +++ b/Bots/CGod.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/CGod.class.php * * simple C debugger... @@ -26,7 +26,7 @@ class {$_NAME} extends Bot { private $uplink; private $c, $ccache = array(); - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -40,16 +40,16 @@ class {$_NAME} extends Bot { if(is_a($this->c, "P10_User")) { $this->uplink->join($this->c, "#c", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE)); $this->uplink->join($this->c, "#dev", P10_Channel::USERPRIV_VOICE); - $this->uplink->join($this->c, "#CoderCom", P10_Channel::USERPRIV_VOICE); + $this->uplink->join($this->c, "#CoderCom", P10_Channel::USERPRIV_VOICE); } } else { $this->c = $old; } - + ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function unload($rehash = false) { foreach($this->ccache as $id => $c) { fclose($c['pipes'][1]); @@ -63,17 +63,17 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->c, "Bye."); } } - + public function loop() { foreach($this->ccache as $id => $c) { if(!$this->checkstate($c)) { - unlink("tmp/debug_".$c['id'].".c"); - unlink("tmp/debug_".$c['id']); + unlink("tmp/debug_".$c['id'].".c"); + unlink("tmp/debug_".$c['id']); unset($this->ccache[$id]); } } } - + function recive_privmsg($user, $channel, $message) { $opOnCChannel = false; $CChannel = P10_Channel::getChannelByName("#C"); @@ -91,43 +91,43 @@ class {$_NAME} extends Bot { } $entry=array(); $entry['channel'] = $channel; - $entry['id'] = rand(1, 999999); - if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { - $pasteid = explode("/", $exp[1]); - $pasteid = $pasteid[count($pasteid)-1]; - $codecontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); - if(preg_match("#Unknown Paste ID!#i", $codecontent)) { - $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); - return; - } - $code = "#include \"includes.h\" + $entry['id'] = rand(1, 999999); + if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { + $pasteid = explode("/", $exp[1]); + $pasteid = $pasteid[count($pasteid)-1]; + $codecontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); + if(preg_match("#Unknown Paste ID!#i", $codecontent)) { + $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); + return; + } + $code = "#include \"includes.h\" ".$codecontent; - } else { - $code = "#include \"includes.h\" + } else { + $code = "#include \"includes.h\" ".$exp[1]; - }; - $fp = fopen("tmp/debug_".$entry['id'].".c", "w"); - fwrite($fp, $code); - fclose($fp); - $err = shell_exec("gcc -o tmp/debug_".$entry['id']." tmp/debug_".$entry['id'].".c 2>&1"); - if($err) { - $err=str_replace("\r","",$err); - $lines=explode("\n",$err); - $i=0; - foreach($lines as $line) { - if($line == "") continue; - $i++; - if($i>100) { - $this->uplink->privmsg($this->c, $entry['channel'], "too many lines!"); - break; - } - $this->uplink->privmsg($this->c, $entry['channel'], $line); - } - } - if(!file_exists("tmp/debug_".$entry['id'])) { - unlink("tmp/debug_".$entry['id'].".c"); - break; - } + }; + $fp = fopen("tmp/debug_".$entry['id'].".c", "w"); + fwrite($fp, $code); + fclose($fp); + $err = shell_exec("gcc -o tmp/debug_".$entry['id']." tmp/debug_".$entry['id'].".c 2>&1"); + if($err) { + $err=str_replace("\r","",$err); + $lines=explode("\n",$err); + $i=0; + foreach($lines as $line) { + if($line == "") continue; + $i++; + if($i>100) { + $this->uplink->privmsg($this->c, $entry['channel'], "too many lines!"); + break; + } + $this->uplink->privmsg($this->c, $entry['channel'], $line); + } + } + if(!file_exists("tmp/debug_".$entry['id'])) { + unlink("tmp/debug_".$entry['id'].".c"); + break; + } $descriptor = array(0 => array("pipe", "r"),1 => array("pipe", "w"),2 => array("pipe", "w")); $entry['proc'] = proc_open('tmp/debug_'.$entry['id'], $descriptor, $entry['pipes']); if(!is_resource($entry['proc'])) { @@ -140,13 +140,13 @@ class {$_NAME} extends Bot { break; } } - + function recive_quit($user, $reason) { if($user === $this->c) { $this->load($this->uplink); } } - + function checkstate($c) { $data = proc_get_status($c['proc']); if(!$data['running']) { @@ -163,11 +163,11 @@ class {$_NAME} extends Bot { $lines=explode("\n",$out); $i=0; foreach($lines as $line) { - if($line == "") continue; + if($line == "") continue; $i++; if($i>1000) { $this->uplink->privmsg($this->c, $c['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->c, $c['channel'], $line); } @@ -177,11 +177,11 @@ class {$_NAME} extends Bot { $lines=explode("\n",$eout); $i=0; foreach($lines as $line) { - if($line == "") continue; + if($line == "") continue; $i++; - if($i>1000) { + if($i>1000) { $this->uplink->privmsg($this->c, $c['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->c, $c['channel'], "4".$line.""); } @@ -204,13 +204,13 @@ class {$_NAME} extends Bot { } else { proc_terminate($c['proc']); $c['term']=true; - $this->uplink->privmsg($this->c, $c['channel'], "c timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); + $this->uplink->privmsg($this->c, $c['channel'], "c timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); return true; } } } } - + } ?> \ No newline at end of file diff --git a/Bots/ExampleBot.class.php b/Bots/ExampleBot.class.php index 1994e8e..90ebc5e 100644 --- a/Bots/ExampleBot.class.php +++ b/Bots/ExampleBot.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/ExampleBot.class.php * * a simple example bot... @@ -26,26 +26,26 @@ class {$_NAME} extends Bot { // {$_NAME} will be replaced by our script later ;) private $uplink; private $example_bot; - + public function load($uplink, $old = false) { //load is called when the module gets included $this->uplink = $uplink; //Reference to the P10 Uplink - + //$old is only set, if the module is rehashed. It contains the return value of unload(); - + if(!$old) { - + //Here you can define startup actions //We'll add an user to the Server // newuser($localid,$nick,$ident,$host,$realname,$uptime,$modes) returns an array with the result // $localid is just an id you can set (whatever you want) - maybe you'll use it to identify the bot/user later? - + $nick = "ExampleBot"; // Please note: If this user already exists on another Server it will be killed! $ident = "Example"; $host = "Example.Bot"; $ip = "::1"; $realname = "Thats an example Bot :)"; $modes = "i"; //we don't need a leading + (that will be added automatically) - + $this->example_bot = $this->uplink->addUser($nick, $ident, $host, $ip, $modes, $realname); //addUser($nick, $ident, $host, $ip, $modes, $realname) if(is_a($this->example_bot, "P10_User")) { // A new user was created :) //ok let's join a channel @@ -53,23 +53,23 @@ class {$_NAME} extends Bot { // {$_NAME} will be replaced by our script later ; //now we want to say something... //but note: thats the startup procedure! the p10 server is not connected to an uplink, yet - so noone would recive our message (only the other bots on this server) } - + } else { $this->example_bot = $old; //We've saved out Bot reference in $old so we can simply use it again... } - + //OK send something to the Server is easy... //How to recive something from the IRC Server? - + //I've copied the eggdrop way to do that - bind ModCMD::bind($this, BIND_PRIVMSG, "recive_privmsg"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function loop() { //this function is triggered as often as possible (at least one time per second!). Maybe you need it to do timed events //please don't trigger any blocking functions here... that would cause an extreme lagg! } - + public function unload($rehash = false) { //this function is triggered, when the Bot is unloaded... If it's just a rehash the return value of this method is passed to $old in the load method. if($rehash) { return $this->example_bot; @@ -77,7 +77,7 @@ class {$_NAME} extends Bot { // {$_NAME} will be replaced by our script later ; $this->uplink->delUser($this->example_bot, "Bye."); } } - + public function recive_privmsg($user, $channel, $message) { //We've got a privmsg... $exp=explode(" ",$message); @@ -89,20 +89,20 @@ class {$_NAME} extends Bot { // {$_NAME} will be replaced by our script later ; foreach($channel->getUsers() as $chan_user) { $extra=""; $privs = $channel->getUserPrivs($chan_user); - if(($privs & P10_Channel::USERPRIV_VOICE)) $extra= '+'; - if(($privs & P10_Channel::USERPRIV_OPED)) $extra= '@'; + if(($privs & P10_Channel::USERPRIV_VOICE)) $extra= '+'; + if(($privs & P10_Channel::USERPRIV_OPED)) $extra= '@'; $user_str .= " " . $extra . $chan_user->getNick(); } $this->uplink->notice($this->example_bot, $user, "User in ".$channel->getName().":".$user_str); } } - + function recive_quit($user, $reason) { if($user === $this->example_bot) { //maybe we got killed??? $this->load($this->uplink); } } - + } ?> \ No newline at end of file diff --git a/Bots/IPv6.class.php b/Bots/IPv6.class.php index d30ee53..d5c4a1e 100644 --- a/Bots/IPv6.class.php +++ b/Bots/IPv6.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/IPv6.class.php * * IPv6 bot... @@ -27,10 +27,10 @@ class {$_NAME} extends Bot { private $uplink; private $ipv6; private $cache = array( - 0 => array(), - 1 => array() - ); - + 0 => array(), + 1 => array() + ); + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -48,13 +48,13 @@ class {$_NAME} extends Bot { } else { $this->ipv6 = $old; } - + ModCMD::bind($this, BIND_JOIN, "recive_join"); ModCMD::bind($this, BIND_CHANMODE, "recive_mode"); ModCMD::bind($this, BIND_KICK, "recive_kick"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function unload($rehash = false) { if($rehash) { return $this->ipv6; @@ -62,7 +62,7 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->ipv6, "Bye."); } } - + public function loop() { for($i = 0; $i < 2; $i++) { foreach($this->cache[$i] as $id => $cache) { @@ -70,12 +70,12 @@ class {$_NAME} extends Bot { } } } - + private function botOppedOnChannel($channel) { $privs = $channel->getUserPrivs($this->ipv6); return ($privs & P10_Channel::USERPRIV_OPED); } - + public function recive_join($user, $channel, $isBurst) { if(!$this->botOppedOnChannel($channel)) return false; if($user->getIP()->isIPv6()) { @@ -84,7 +84,7 @@ class {$_NAME} extends Bot { $this->uplink->mode($this->ipv6, $channel, "+v ".$user->getNumeric()); } } - + public function recive_mode($user, $channel, $modes) { if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false; if(array_key_exists($user->getNumeric(), $this->cache[0]) && $this->cache[0][$user->getNumeric()]['time'] > time()) { @@ -110,7 +110,7 @@ class {$_NAME} extends Bot { $modes = implode(" ",$mode); $this->uplink->mode($this->ipv6, $channel, $modes); } - + public function recive_kick($user, $target, $channel, $modes) { if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false; if(array_key_exists($user->getNumeric(), $this->cache[1]) && $this->cache[1][$user->getNumeric()]['time'] > time()) { @@ -120,7 +120,7 @@ class {$_NAME} extends Bot { $this->cache[1][$user->getNumeric()] = time() + 600; } } - + public function recive_quit($user, $reason) { if($user === $this->ipv6) { $this->load($this->uplink); diff --git a/Bots/JavaGod.class.php b/Bots/JavaGod.class.php index e41ef02..364abf5 100644 --- a/Bots/JavaGod.class.php +++ b/Bots/JavaGod.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/JavaGod.class.php * * simple Java debugger... @@ -26,7 +26,7 @@ class {$_NAME} extends Bot { private $uplink; private $bot, $execcache = array(); - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -40,16 +40,16 @@ class {$_NAME} extends Bot { if(is_a($this->bot, "P10_User")) { $this->uplink->join($this->bot, "#java", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE)); $this->uplink->join($this->bot, "#dev", P10_Channel::USERPRIV_VOICE); - $this->uplink->join($this->bot, "#CoderCom", P10_Channel::USERPRIV_VOICE); + $this->uplink->join($this->bot, "#CoderCom", P10_Channel::USERPRIV_VOICE); } } else { $this->bot = $old; } - + ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function unload($rehash = false) { foreach($this->execcache as $id => $entry) { fclose($entry['pipes'][1]); @@ -63,17 +63,17 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->bot, "Bye."); } } - + public function loop() { foreach($this->execcache as $id => $entry) { if(!$this->checkstate($entry)) { - unlink("tmp/Debug_".$entry['id'].".java"); - unlink("tmp/Debug_".$entry['id'].".class"); + unlink("tmp/Debug_".$entry['id'].".java"); + unlink("tmp/Debug_".$entry['id'].".class"); unset($this->execcache[$id]); } } } - + function recive_privmsg($user, $channel, $message) { $opOnJavaChannel = false; $JavaChannel = P10_Channel::getChannelByName("#Java"); @@ -91,51 +91,51 @@ class {$_NAME} extends Bot { } $entry=array(); $entry['channel'] = $channel; - $entry['id'] = rand(1, 999999); - if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { - $pasteid = explode("/", $exp[1]); - $pasteid = $pasteid[count($pasteid)-1]; - $javacontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); - if(preg_match("#Unknown Paste ID!#i", $javacontent)) { - $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); - return; - } - $javacode = "import java.*; + $entry['id'] = rand(1, 999999); + if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { + $pasteid = explode("/", $exp[1]); + $pasteid = $pasteid[count($pasteid)-1]; + $javacontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); + if(preg_match("#Unknown Paste ID!#i", $javacontent)) { + $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); + return; + } + $javacode = "import java.*; @SuppressWarnings(\"unused\") public class Debug_".$entry['id']." { ".$javacontent." } "; - } else { - $javacode = "import java.*; + } else { + $javacode = "import java.*; @SuppressWarnings(\"unused\") public class Debug_".$entry['id']." { ".$exp[1]." } "; - }; - $fp = fopen("tmp/Debug_".$entry['id'].".java", "w"); - fwrite($fp, $javacode); - fclose($fp); - $err = shell_exec("javac tmp/Debug_".$entry['id'].".java 2>&1"); - if($err) { - $err=str_replace("\r","",$err); - $lines=explode("\n",$err); - $i=0; - foreach($lines as $line) { - if($line == "") continue; - $i++; - if($i>100) { - $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); - break; - } - $this->uplink->privmsg($this->bot, $entry['channel'], $line); - } - } - if(!file_exists("tmp/Debug_".$entry['id'].".class")) { - unlink("tmp/Debug_".$entry['id'].".java"); - break; - } + }; + $fp = fopen("tmp/Debug_".$entry['id'].".java", "w"); + fwrite($fp, $javacode); + fclose($fp); + $err = shell_exec("javac tmp/Debug_".$entry['id'].".java 2>&1"); + if($err) { + $err=str_replace("\r","",$err); + $lines=explode("\n",$err); + $i=0; + foreach($lines as $line) { + if($line == "") continue; + $i++; + if($i>100) { + $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); + break; + } + $this->uplink->privmsg($this->bot, $entry['channel'], $line); + } + } + if(!file_exists("tmp/Debug_".$entry['id'].".class")) { + unlink("tmp/Debug_".$entry['id'].".java"); + break; + } $descriptor = array(0 => array("pipe", "r"),1 => array("pipe", "w"),2 => array("pipe", "w")); $entry['proc'] = proc_open('java -classpath tmp Debug_'.$entry['id'], $descriptor, $entry['pipes']); if(!is_resource($entry['proc'])) { @@ -148,13 +148,13 @@ class {$_NAME} extends Bot { break; } } - + function recive_quit($user, $reason) { if($user === $this->bot) { $this->load($this->uplink); } } - + function checkstate($entry) { $data = proc_get_status($entry['proc']); if(!$data['running']) { @@ -171,11 +171,11 @@ class {$_NAME} extends Bot { $lines=explode("\n",$out); $i=0; foreach($lines as $line) { - if($line == "") continue; + if($line == "") continue; $i++; if($i>1000) { $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->bot, $entry['channel'], $line); } @@ -185,11 +185,11 @@ class {$_NAME} extends Bot { $lines=explode("\n",$eout); $i=0; foreach($lines as $line) { - if($line == "") continue; + if($line == "") continue; $i++; - if($i>1000) { + if($i>1000) { $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->bot, $entry['channel'], "4".$line.""); } @@ -212,13 +212,13 @@ class {$_NAME} extends Bot { } else { proc_terminate($entry['proc']); $entry['term']=true; - $this->uplink->privmsg($this->bot, $entry['channel'], "Java timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); + $this->uplink->privmsg($this->bot, $entry['channel'], "Java timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); return true; } } } } - + } ?> \ No newline at end of file diff --git a/Bots/MCBot.class.php b/Bots/MCBot.class.php index 6d88ed3..8b50280 100644 --- a/Bots/MCBot.class.php +++ b/Bots/MCBot.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/MCBot.class.php * * MCBot bot... @@ -26,7 +26,7 @@ class {$_NAME} extends Bot { private $uplink; private $mcbot; - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -44,11 +44,11 @@ class {$_NAME} extends Bot { } else { $this->mcbot = $old; } - + ModCMD::bind($this, BIND_JOIN, "recive_join"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function unload($rehash = false) { if($rehash) { return $this->mcbot; @@ -56,19 +56,19 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->mcbot, "Bye."); } } - + private function botOppedOnChannel($channel) { $privs = $channel->getUserPrivs($this->mcbot); return ($privs & P10_Channel::USERPRIV_OPED); } - + public function recive_join($user, $channel, $isBurst) { if(!$this->botOppedOnChannel($channel)) return false; if(preg_match("#(.*).spoof.minecraft.WebGamesNet#i",$user->getHost())) { $this->uplink->mode($this->mcbot, $channel, "+v ".$user->getNumeric()); } } - + public function recive_quit($user, $reason) { if($user === $this->mcbot) { $this->load($this->uplink); diff --git a/Bots/ModManager.class.php b/Bots/ModManager.class.php index 0077f1c..38281f4 100644 --- a/Bots/ModManager.class.php +++ b/Bots/ModManager.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/ModManager.class.php * * module manager bot... @@ -26,7 +26,7 @@ class {$_NAME} extends Bot { private $uplink; private $modman; - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -44,12 +44,12 @@ class {$_NAME} extends Bot { } else { $this->modman = $old; } - + ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); ModCMD::bind($this, BIND_CTCP, "recive_ctcp"); } - + public function unload($rehash = false) { if($rehash) { return $this->modman; @@ -57,7 +57,7 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->modman, "Bye."); } } - + public function recive_privmsg($user, $channel, $message) { if(!$user->getModes()->hasMode('o')) return 0; $exp=explode(" ",$message); @@ -109,13 +109,13 @@ class {$_NAME} extends Bot { break; } } - + public function recive_quit($user, $reason) { if($user === $this->modman) { $this->load($this->uplink); } } - + public function recive_ctcp($user, $target, $command, $text, $publicCtcp) { if(!$publicCtcp) { switch($command) { diff --git a/Bots/PHPGod.class.php b/Bots/PHPGod.class.php index 355eb39..e0ee13e 100644 --- a/Bots/PHPGod.class.php +++ b/Bots/PHPGod.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/PHPGod.class.php * * simple PHP debugger... @@ -26,7 +26,7 @@ class {$_NAME} extends Bot { private $uplink; private $php, $phpcache = array(); - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -40,16 +40,16 @@ class {$_NAME} extends Bot { if(is_a($this->php, "P10_User")) { $this->uplink->join($this->php, "#php", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE)); $this->uplink->join($this->php, "#dev", P10_Channel::USERPRIV_VOICE); - $this->uplink->join($this->php, "#CoderCom", P10_Channel::USERPRIV_VOICE); + $this->uplink->join($this->php, "#CoderCom", P10_Channel::USERPRIV_VOICE); } } else { $this->php = $old; } - + ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function unload($rehash = false) { foreach($this->phpcache as $id => $php) { fclose($php['pipes'][1]); @@ -63,7 +63,7 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->php, "Bye."); } } - + public function loop() { foreach($this->phpcache as $id => $php) { if(!$this->checkstate($php)) { @@ -71,7 +71,7 @@ class {$_NAME} extends Bot { } } } - + function recive_privmsg($user, $channel, $message) { $opOnPHPChannel = false; $PHPChannel = P10_Channel::getChannelByName("#PHP"); @@ -96,31 +96,31 @@ class {$_NAME} extends Bot { return; } $entry['time'] = time(); - if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { - $pasteid = explode("/", $exp[1]); - $pasteid = $pasteid[count($pasteid)-1]; - $codecontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); - if(preg_match("#Unknown Paste ID!#i", $codecontent)) { - $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); - return; - } - $code = $codecontent; - } else { - $code = "<"."?php " . $exp[1] . " ?".">"; - }; + if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { + $pasteid = explode("/", $exp[1]); + $pasteid = $pasteid[count($pasteid)-1]; + $codecontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); + if(preg_match("#Unknown Paste ID!#i", $codecontent)) { + $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); + return; + } + $code = $codecontent; + } else { + $code = "<"."?php " . $exp[1] . " ?".">"; + }; fwrite($entry['pipes'][0], $code); fclose($entry['pipes'][0]); $this->phpcache[] = $entry; break; } } - + function recive_quit($user, $reason) { if($user === $this->php) { $this->load($this->uplink); } } - + function checkstate($php) { $data = proc_get_status($php['proc']); if(!$data['running']) { @@ -140,7 +140,7 @@ class {$_NAME} extends Bot { $i++; if($i>1000) { $this->uplink->privmsg($this->php, $php['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->php, $php['channel'], $line); } @@ -151,9 +151,9 @@ class {$_NAME} extends Bot { $i=0; foreach($lines as $line) { $i++; - if($i>1000) { + if($i>1000) { $this->uplink->privmsg($this->php, $php['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->php, $php['channel'], "4".$line.""); } @@ -176,13 +176,13 @@ class {$_NAME} extends Bot { } else { proc_terminate($php['proc']); $php['term']=true; - $this->uplink->privmsg($this->php, $php['channel'], "php timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); + $this->uplink->privmsg($this->php, $php['channel'], "php timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); return true; } } } } - + } ?> \ No newline at end of file diff --git a/Bots/PerlGod.class.php b/Bots/PerlGod.class.php index 0eb0a63..189a7f6 100644 --- a/Bots/PerlGod.class.php +++ b/Bots/PerlGod.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/PerlGod.class.php * * simple Perl debugger... @@ -26,7 +26,7 @@ class {$_NAME} extends Bot { private $uplink; private $bot, $execcache = array(); - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -40,16 +40,16 @@ class {$_NAME} extends Bot { if(is_a($this->bot, "P10_User")) { $this->uplink->join($this->bot, "#perl", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE)); $this->uplink->join($this->bot, "#dev", P10_Channel::USERPRIV_VOICE); - $this->uplink->join($this->bot, "#CoderCom", P10_Channel::USERPRIV_VOICE); + $this->uplink->join($this->bot, "#CoderCom", P10_Channel::USERPRIV_VOICE); } } else { $this->bot = $old; } - + ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function unload($rehash = false) { foreach($this->execcache as $id => $entry) { fclose($entry['pipes'][1]); @@ -63,7 +63,7 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->bot, "Bye."); } } - + public function loop() { foreach($this->execcache as $id => $entry) { if(!$this->checkstate($entry)) { @@ -71,7 +71,7 @@ class {$_NAME} extends Bot { } } } - + function recive_privmsg($user, $channel, $message) { $opOnPerlChannel = false; $entryChannel = P10_Channel::getChannelByName("#Perl"); @@ -96,31 +96,31 @@ class {$_NAME} extends Bot { return; } $entry['time'] = time(); - if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { - $pasteid = explode("/", $exp[1]); - $pasteid = $pasteid[count($pasteid)-1]; - $codecontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); - if(preg_match("#Unknown Paste ID!#i", $codecontent)) { - $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); - return; - } - $code = $codecontent; - } else { - $code = $exp[1]; - } + if(preg_match("#pastebin\.com/([a-zA-Z0-9]*)$#i", $exp[1])) { + $pasteid = explode("/", $exp[1]); + $pasteid = $pasteid[count($pasteid)-1]; + $codecontent = file_get_contents("http://pastebin.com/download.php?i=".$pasteid); + if(preg_match("#Unknown Paste ID!#i", $codecontent)) { + $this->uplink->notice($this->bot, $user, "Unknown Paste ID!"); + return; + } + $code = $codecontent; + } else { + $code = $exp[1]; + } fwrite($entry['pipes'][0], $code); fclose($entry['pipes'][0]); $this->execcache[] = $entry; break; } } - + function recive_quit($user, $reason) { if($user === $this->bot) { $this->load($this->uplink); } } - + function checkstate($entry) { $data = proc_get_status($entry['proc']); if(!$data['running']) { @@ -140,7 +140,7 @@ class {$_NAME} extends Bot { $i++; if($i>1000) { $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->bot, $entry['channel'], $line); } @@ -151,9 +151,9 @@ class {$_NAME} extends Bot { $i=0; foreach($lines as $line) { $i++; - if($i>1000) { + if($i>1000) { $this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!"); - break; + break; } $this->uplink->privmsg($this->bot, $entry['channel'], "4".$line.""); } @@ -176,13 +176,13 @@ class {$_NAME} extends Bot { } else { proc_terminate($entry['proc']); $entry['term']=true; - $this->uplink->privmsg($this->bot, $entry['channel'], "perl timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); + $this->uplink->privmsg($this->bot, $entry['channel'], "perl timeout. (maximum of 10 seconds exceeded) sending SIGTERM"); return true; } } } } - + } ?> \ No newline at end of file diff --git a/Bots/PulseBot.class.php b/Bots/PulseBot.class.php index b9a5e6a..961d974 100644 --- a/Bots/PulseBot.class.php +++ b/Bots/PulseBot.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/PulseBot.class.php * * WhatPulse bot... @@ -28,9 +28,9 @@ class {$_NAME} extends Bot { private $pulsebot; private $cache = array(); private $db = array(); - + const TEAM_ID = 19418; - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!$old) { @@ -53,7 +53,7 @@ class {$_NAME} extends Bot { ModCMD::bind($this, BIND_JOIN, "recive_join"); ModCMD::bind($this, BIND_QUIT, "recive_quit"); } - + public function unload($rehash = false) { if($rehash) { return $this->pulsebot; @@ -61,15 +61,15 @@ class {$_NAME} extends Bot { $this->uplink->delUser($this->pulsebot, "Bye."); } } - + public function readDB($db) { $this->db = $db; } - + public function writeDB() { return $this->db; } - + private function getStats() { if(array_key_exists("stats", $this->cache) && time() - $this->cache['stats_time'] < 300) { //use cached stats @@ -82,7 +82,7 @@ class {$_NAME} extends Bot { } return $stats; } - + private function getUserStats($name) { if(array_key_exists("ustats_".strtolower($name), $this->cache) && time() - $this->cache['ustats_'.strtolower($name).'_time'] < 300) { //use cached stats @@ -102,12 +102,12 @@ class {$_NAME} extends Bot { } return null; } - + private function botOppedOnChannel($channel) { $privs = $channel->getUserPrivs($this->pulsebot); return ($privs & P10_Channel::USERPRIV_OPED); } - + function recive_privmsg($user, $channel, $message) { if(!$this->botOppedOnChannel($channel)) return; $privs = $channel->getUserPrivs($user); @@ -164,7 +164,7 @@ class {$_NAME} extends Bot { } } if(!$f) - $this->uplink->notice($this->pulsebot, $user, "WhatPulse user '".$exp[1]."' is not added."); + $this->uplink->notice($this->pulsebot, $user, "WhatPulse user '".$exp[1]."' is not added."); break; case ".users": $table = new Table(5); @@ -187,9 +187,9 @@ class {$_NAME} extends Bot { $lines = $table->end(); foreach($lines as $line) { if(count($exp) > 1) - $this->uplink->privmsg($this->pulsebot, $channel, $line); + $this->uplink->privmsg($this->pulsebot, $channel, $line); else - $this->uplink->notice($this->pulsebot, $user, $line); + $this->uplink->notice($this->pulsebot, $user, $line); } break; case ".mypulse": @@ -235,7 +235,7 @@ class {$_NAME} extends Bot { break; } } - + public function recive_join($user, $channel, $isBurst) { if(!$this->botOppedOnChannel($channel)) return false; if(!($auth = $user->getModes()->hasMode('r'))) return; @@ -262,7 +262,7 @@ class {$_NAME} extends Bot { $this->uplink->privmsg($this->pulsebot, $channel, "WhatPulse User \002".$pulseUser->MemberName."\002 (\002".number_format(floatval($pulseUser->MemberKeys),0,',','.')."\002 keys and \002".number_format(floatval($pulseUser->MemberClicks),0,',','.')."\002 clicks) has joined the channel."); } } - + public function recive_quit($user, $reason) { if($user === $this->pulsebot) { $this->load($this->uplink); diff --git a/Bots/Stats.class.php b/Bots/Stats.class.php index 3288d85..ec4e2fb 100644 --- a/Bots/Stats.class.php +++ b/Bots/Stats.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Bots/Stats.class.php * * RRD Stats module... @@ -26,7 +26,7 @@ class {$_NAME} extends Bot { private $uplink; private $timer; - + public function load($uplink, $old = false) { $this->uplink = $uplink; if(!file_exists("db/network.rrd")) { @@ -45,13 +45,13 @@ class {$_NAME} extends Bot { "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:288:797" - ); - $ret = rrd_create($fname, $opts, count($opts)); - if(!$ret) { - $err = rrd_error(); - echo "Create error: $err\n"; - die(); - } + ); + $ret = rrd_create($fname, $opts, count($opts)); + if(!$ret) { + $err = rrd_error(); + echo "Create error: $err\n"; + die(); + } } if(!file_exists("db/network-away.rrd")) { $fname = "db/network-away.rrd"; @@ -67,13 +67,13 @@ class {$_NAME} extends Bot { "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:288:797" - ); - $ret = rrd_create($fname, $opts, count($opts)); - if(!$ret) { - $err = rrd_error(); - echo "Create error: $err\n"; - die(); - } + ); + $ret = rrd_create($fname, $opts, count($opts)); + if(!$ret) { + $err = rrd_error(); + echo "Create error: $err\n"; + die(); + } } if(!file_exists("db/network-peruser.rrd")) { $fname = "db/network-peruser.rrd"; @@ -89,21 +89,21 @@ class {$_NAME} extends Bot { "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:288:797" - ); - $ret = rrd_create($fname, $opts, count($opts)); - if(!$ret) { - $err = rrd_error(); - echo "Create error: $err\n"; - die(); - } + ); + $ret = rrd_create($fname, $opts, count($opts)); + if(!$ret) { + $err = rrd_error(); + echo "Create error: $err\n"; + die(); + } } $this->timer = timer(5,array(&$this,"create_stats"),array()); } - + public function unload($rehash = false) { kill_timer($this->timer); } - + function create_stats() { $this->timer = timer(5*60,array(&$this,"create_stats"),array()); $stats = array( @@ -146,13 +146,13 @@ class {$_NAME} extends Bot { "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:288:797" - ); - $ret = rrd_create($fname, $opts, count($opts)); + ); + $ret = rrd_create($fname, $opts, count($opts)); } rrd_update($fname, time().":".$count); } } - + } ?> \ No newline at end of file diff --git a/ModCMD/Binding.class.php b/ModCMD/Binding.class.php index cd735d8..e7619b4 100644 --- a/ModCMD/Binding.class.php +++ b/ModCMD/Binding.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * ModCMD/Binding.class.php * * a single Binding... @@ -26,31 +26,31 @@ class Binding { private $bot; private $method; - private $filter; - + private $filter; + public function __construct($bot, $method, $filter) { $this->bot = $bot; $this->method = $method; - $this->filter = $filter; + $this->filter = $filter; } - + public function trigger($params) { call_user_func_array(array($this->bot, $this->method), $params); } - + public function match($bot, $method, $filter) { return ($bot === $this->bot && (!$method || strtolower($this->method) == strtolower($method)) && (!$filter || $this->match_filter($filter, false))); } - - public function match_filter($filter, $preg = true) { - if(!$this->filter) return true; - if(is_object($filter) || is_object($this->filter)) { - return $filter === $this->filter; - } else if($preg && is_string($filter && is_string($this->filter))) { - return preg_match($this->filter, $filter); - } else - return $filter == $this->filter; - } + + public function match_filter($filter, $preg = true) { + if(!$this->filter) return true; + if(is_object($filter) || is_object($this->filter)) { + return $filter === $this->filter; + } else if($preg && is_string($filter && is_string($this->filter))) { + return preg_match($this->filter, $filter); + } else + return $filter == $this->filter; + } } ?> \ No newline at end of file diff --git a/ModCMD/ModCMD.class.php b/ModCMD/ModCMD.class.php index c613eca..83106b4 100644 --- a/ModCMD/ModCMD.class.php +++ b/ModCMD/ModCMD.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,14 +16,14 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * ModCMD/ModCMD.class.php * * shares the incoming events to all bot's that request them. * */ require_once("Binding.class.php"); - + $bindid = 1; define("BIND_NEWSERVER", $bindid++); define("BIND_SQUIT", $bindid++); @@ -45,31 +45,31 @@ define("BIND_CTCPREPLY", $bindid++); define("BIND_PREPARSE", $bindid++); define("BIND_UNKNOWNCMD", $bindid++); - + class ModCMD implements EventHandler { private static $eventHandler = null; private static $bindings = array(); - + public static function getEventHandler() { if(self::$eventHandler == null) { self::$eventHandler = new ModCMD(); } return self::$eventHandler; } - + public static function bind($bot, $type, $method, $filter = NULL) { if(is_a($bot, "Bot") && method_exists($bot, $method)) { if(array_key_exists($type, self::$bindings)) { foreach(self::$bindings[$type] as $binding) { if($binding->match($bot, $method, $filter)) - return; + return; } - } else - self::$bindings[$type] = array(); + } else + self::$bindings[$type] = array(); self::$bindings[$type][] = new Binding($bot, $method, $filter); } } - + public static function unbind($bot, $type, $method, $filter = NULL) { if(is_a($bot, "Bot")) { if(array_key_exists($type, self::$bindings)) { @@ -82,7 +82,7 @@ class ModCMD implements EventHandler { } } } - + public static function unbindBot($bot) { if(is_a($bot, "Bot")) { foreach(self::$bindings as $type => $bindings) { @@ -94,108 +94,108 @@ class ModCMD implements EventHandler { } } } - + /******************************************************************************************** * EVENT HANDLER * ********************************************************************************************/ - + private function event($type, $parameters, $matchings = array(null)) { if(array_key_exists($type, self::$bindings)) { foreach(self::$bindings[$type] as $binding) { - $match = false; - foreach($matchings as $matching) { - if(($match = $binding->match_filter($matching))) break; - } - if($match) - $binding->trigger($parameters); + $match = false; + foreach($matchings as $matching) { + if(($match = $binding->match_filter($matching))) break; + } + if($match) + $binding->trigger($parameters); } } } - + public function event_newserver($server, $isBurst) { $this->event(BIND_NEWSERVER, array($server, $isBurst)); } - + public function event_squit($server){ $this->event(BIND_SQUIT, array($server)); } - + public function event_connect($user, $isBurst) { $this->event(BIND_CONNECT, array($user, $isBurst)); } - + public function event_nick($user, $newNick) { $this->event(BIND_NICK, array($user, $newNick)); } - + public function event_usermode($user, $modes) { $this->event(BIND_USERMODE, array($user, $modes)); } - + public function event_quit($user, $reason) { $this->event(BIND_QUIT, array($user, $reason)); } - + public function event_join($user, $channel, $isBurst) { $this->event(BIND_JOIN, array($user, $channel, $isBurst), array($user, $channel)); } - + public function event_part($user, $channel, $reason) { $this->event(BIND_PART, array($user, $channel, $reason), array($user, $channel)); } - + public function event_kick($user, $target, $channel, $reason) { $this->event(BIND_KICK, array($user, $target, $channel, $reason), array($user, $channel, $target)); } - + public function event_chanmode($user, $channel, $modes) { $this->event(BIND_CHANMODE, array($user, $channel, $modes), array($user, $channel)); } - + public function event_chanmessage($user, $channel, $message) { $this->event(BIND_CHANMSG, array($user, $channel, $message), array($user, $channel)); } - + public function event_channotice($user, $channel, $message) { $this->event(BIND_CHANNOTICE, array($user, $channel, $message), array($user, $channel)); } - + public function event_privmessage($user, $target, $message) { $this->event(BIND_PRIVMSG, array($user, $target, $message), array($user, $target)); } - + public function event_privnotice($user, $target, $message) { $this->event(BIND_PRIVNOTICE, array($user, $target, $message), array($user, $target)); } - + public function event_preparse($from, $command, $arguments) { $this->event(BIND_PREPARSE, array($from, $command, $arguments), array($command)); } - + public function event_unknown_cmd($from, $command, $arguments) { $this->event(BIND_UNKNOWNCMD, array($from, $command, $arguments), array($command)); } - + public function event_chanctcp($user, $channel, $command, $text) { $this->event(BIND_CTCP, array($user, $channel, $command, $text, true)); } - + public function event_chanctcpreply($user, $channel, $command, $text) { $this->event(BIND_CTCPREPLY, array($user, $channel, $command, $text, true)); } - + public function event_privctcp($user, $target, $command, $text) { $this->event(BIND_CTCP, array($user, $target, $command, $text, false)); } - + public function event_privctcpreply($user, $target, $command, $text) { $this->event(BIND_CTCPREPLY, array($user, $target, $command, $text, false)); } - + public function event_away($user, $away) { $this->event(BIND_AWAY, array($user, $away)); } - + } ?> \ No newline at end of file diff --git a/Tools/Table.class.php b/Tools/Table.class.php index 239de46..761c59c 100644 --- a/Tools/Table.class.php +++ b/Tools/Table.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Tools/Table.class.php * * IRC Table Class @@ -24,7 +24,7 @@ class Table { private $table; - + public function Table($colums) { $this->table = array(); $this->table['set'] = array(); @@ -36,11 +36,11 @@ class Table { $this->table['set']['bold'][$i] = false; } } - + public function setBold($colum) { $this->table['set']['bold'][$colum] = true; } - + public function add() { $args = func_get_args(); $row = array(); @@ -48,12 +48,12 @@ class Table { if(count($args) <= $i) $args[$i]= ""; $row[] = $args[$i]; if(count($args) >= $i) - if(strlen($args[$i]) > $this->table['set']['max'.$i]) $this->table['set']['max'.$i] = strlen($args[$i]); + if(strlen($args[$i]) > $this->table['set']['max'.$i]) $this->table['set']['max'.$i] = strlen($args[$i]); } $this->table['data'][] = $row; return true; } - + public function end() { $space = " "; $output = array(); @@ -61,7 +61,7 @@ class Table { $out = ""; for($i = 0; $i < $this->table['set']['col']; $i++) { if($i < $this->table['set']['col'] - 1) - $this->table['data'][$row][$i] .= substr($space,0,$this->table['set']['max'.$i] - strlen($this->table['data'][$row][$i]) + 1); + $this->table['data'][$row][$i] .= substr($space,0,$this->table['set']['max'.$i] - strlen($this->table['data'][$row][$i]) + 1); $bold = $this->table['set']['bold'][$i]; $out .= ($bold ? "\002" : "").$this->table['data'][$row][$i].($bold ? "\002" : ""); } @@ -69,7 +69,7 @@ class Table { } return $output; } - + } ?> \ No newline at end of file diff --git a/Tools/timer.inc.php b/Tools/timer.inc.php index 445ab67..1ba5cd7 100644 --- a/Tools/timer.inc.php +++ b/Tools/timer.inc.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Tools/timer.inc.php * * timer functions @@ -24,50 +24,53 @@ $timers['id']=0; function timer_loop() { - global $timers; - $mtime = microtime(true); - $ret = false; - foreach ($timers as $id => $timer) { - if(($timer['expire'] - 0.00019) <= $mtime) { //we expire a timer 0,19 ms before (to reduce timer desyncs) - if((is_array($timer['function']) && method_exists($timer['function'][0],$timer['function'][1])) || (!is_array($timer['function']) && function_exists($timer['function']))) { - call_user_func_array($timer['function'],$timer['params']); - } - $ret = true; - unset($timers[$id]); - } - } - return $ret; + global $timers; + $mtime = microtime(true); + $ret = false; + foreach ($timers as $id => $timer) { + if(($timer['expire'] - 0.00019) <= $mtime) { //we expire a timer 0,19 ms before (to reduce timer desyncs) + if((is_array($timer['function']) && method_exists($timer['function'][0],$timer['function'][1])) || (!is_array($timer['function']) && function_exists($timer['function']))) { + call_user_func_array($timer['function'],$timer['params']); + } + $ret = true; + unset($timers[$id]); + } + } + return $ret; } function timer($seconds,$command,$parameter) { - global $timers; - $new['expire'] = microtime(true) + $seconds; - $new['function'] = $command; - $new['params'] = $parameter; - while(isset($timers[$timers['id']])|| !isset($timers['id'])) { - $timers['id']++; - if($timers['id'] > 9999999) $timers['id'] = 0; - } - $timers[$timers['id']] = $new; - return $timers['id']; + global $timers; + $new['expire'] = microtime(true) + $seconds; + $new['function'] = $command; + $new['params'] = $parameter; + if(!array_key_exists('id', $timers)) { + $timers['id'] = 0; + } + while(isset($timers[$timers['id']])|| !isset($timers['id'])) { + $timers['id']++; + if($timers['id'] > 9999999) $timers['id'] = 0; + } + $timers[$timers['id']] = $new; + return $timers['id']; } function utimer($seconds,$command,$parameter) { - global $timers; - $new['expire'] = microtime(true) + ($seconds / 1000); - $new['function'] = $command; - $new['params'] = $parameter; - while($timers[$timers['id']] || !$timers['id']) { - $timers['id']++; - if($timers['id'] > 9999999) $timers['id'] = 0; - } - $timers[$timers['id']] = $new; - return $timers['id']; + global $timers; + $new['expire'] = microtime(true) + ($seconds / 1000); + $new['function'] = $command; + $new['params'] = $parameter; + while($timers[$timers['id']] || !$timers['id']) { + $timers['id']++; + if($timers['id'] > 9999999) $timers['id'] = 0; + } + $timers[$timers['id']] = $new; + return $timers['id']; } function kill_timer($id) { - global $timers; - unset($timers[$id]); + global $timers; + unset($timers[$id]); } $timers['id']=0; diff --git a/Uplink/Client.class.php b/Uplink/Client.class.php index a8d946e..02567fe 100644 --- a/Uplink/Client.class.php +++ b/Uplink/Client.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/Client.class.php * * This file contains the basic Client Socket. @@ -25,16 +25,16 @@ class Client { const CLIENT_RECV_MAX_LINES = 20; //maximum Lines to receive within one recv() call - + private $socket; private $traffic = array("in" => 0, "out" => 0); private $timeout; - + public function connect($host, $port, $bind = null, $ssl = false, $blocking = 0) { if($bind) - $options = array('socket' => array('bindto' => $bind.":0")); + $options = array('socket' => array('bindto' => $bind.":0")); else - $options = array(); + $options = array(); $context = stream_context_create($options); $sock = stream_socket_client(($ssl ? 'ssl://' : '').$host.':'.$port, $errno, $errstr, 3, STREAM_CLIENT_CONNECT, $context); if($sock) { @@ -43,15 +43,15 @@ class Client { $this->socket = $sock; return true; } else - return false; + return false; } - + public function disconnect() { if($this->socket == null) return; fclose($this->socket); $this->socket = null; } - + public function connected() { if($this->socket == null) return false; $read = array($this->socket); @@ -64,7 +64,7 @@ class Client { } return true; } - + public function recv() { $read = array($this->socket); $write= null; @@ -88,14 +88,14 @@ class Client { } return null; } - + public function send($line, $newline = "\r\n") { if($this->socket == null) return; echo"[send] ".utf8_decode($line)."\n"; $this->traffic['out'] += strlen($line); fwrite($this->socket,$line.$newline); } - + public function getTraffic() { return $this->traffic; } diff --git a/Uplink/EventHandler.interface.php b/Uplink/EventHandler.interface.php index e5b1ab5..c33ce38 100644 --- a/Uplink/EventHandler.interface.php +++ b/Uplink/EventHandler.interface.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/EventHandler.interface.php * * This file contains the Uplink EventHandler interface. @@ -24,21 +24,21 @@ */ interface EventHandler { - + public function event_newserver($server, $isBurst); public function event_squit($server); - + public function event_connect($user, $isBurst); public function event_nick($user, $newNick); public function event_usermode($user, $modes); public function event_quit($user, $reason); public function event_away($user, $away); - + public function event_join($user, $channel, $isBurst); public function event_part($user, $channel, $reason); public function event_kick($user, $target, $channel, $reason); public function event_chanmode($user, $channel, $modes); - + public function event_chanmessage($user, $channel, $message); public function event_channotice($user, $channel, $message); public function event_chanctcp($user, $channel, $command, $text); @@ -47,11 +47,11 @@ interface EventHandler { public function event_privnotice($user, $target, $message); public function event_privctcp($user, $target, $command, $text); public function event_privctcpreply($user, $target, $command, $text); - - + + public function event_preparse($from, $command, $arguments); public function event_unknown_cmd($from, $command, $arguments); - + } ?> \ No newline at end of file diff --git a/Uplink/IPAddr.class.php b/Uplink/IPAddr.class.php index 266e4b6..1eddcbe 100644 --- a/Uplink/IPAddr.class.php +++ b/Uplink/IPAddr.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/IpAddr.class.php * * This class represents an IPv4 or IPv6 address. @@ -28,7 +28,7 @@ class IPAddr { private static $pattern_IPv4 = '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(|\/[0-9]{1,2})$/'; private $ip6 = array(); private $addr_is_ipv6 = false; - + public function __construct($initial_value) { for($i = 0; $i < 8; $i++) { $this->ip6[$i] = 0; @@ -43,7 +43,7 @@ class IPAddr { $this->parseNumeric($initial_value); } } - + public function parseNumeric($numeric) { if(strlen($numeric) == 6) { //IPv4 $value = Numerics::numToInt($numeric); @@ -67,7 +67,7 @@ class IPAddr { $this->addr_is_ipv6 = true; } } - + public function parseIPv6($ipv6) { if(substr($ipv6,0,2) == "::") $ipv6 = substr($ipv6, 1); if(substr($ipv6,-2) == "::") $ipv6 = substr($ipv6, 0, -1); @@ -83,7 +83,7 @@ class IPAddr { } $this->addr_is_ipv6 = true; } - + public function parseIPv4($ipv4) { $ipv4blocks = explode(".",$ipv4); $this->ip6[6] = intval($ipv4blocks[0]) << 8; @@ -92,19 +92,19 @@ class IPAddr { $this->ip6[7] |= intval($ipv4blocks[3]); $this->addr_is_ipv6 = false; } - + public function isIPv6() { return $this->addr_is_ipv6; } - + public function getAddress() { - if($this->isIPv6()) { + if($this->isIPv6()) { $max_start = 0; $max_zeros = 0; $curr_zeros = 0; for ($i = 0; $i < 8; $i++) { if ($this->ip6[$i] == 0) - $curr_zeros++; + $curr_zeros++; else if ($curr_zeros > $max_zeros) { $max_start = $i - $curr_zeros; $max_zeros = $curr_zeros; @@ -135,15 +135,15 @@ class IPAddr { return implode(".", $ipv4); } } - + public function getNumeric() { - if($this->isIPv6()) { + if($this->isIPv6()) { $max_start = 0; $max_zeros = 0; $curr_zeros = 0; for ($i = 0; $i < 8; $i++) { if ($this->ip6[$i] == 0) - $curr_zeros++; + $curr_zeros++; else if ($curr_zeros > $max_zeros) { $max_start = $i - $curr_zeros; $max_zeros = $curr_zeros; @@ -171,7 +171,7 @@ class IPAddr { return $ipv4[0].$ipv4[1]; } } - + } ?> \ No newline at end of file diff --git a/Uplink/Numerics.class.php b/Uplink/Numerics.class.php index 3de23e1..0a979e1 100644 --- a/Uplink/Numerics.class.php +++ b/Uplink/Numerics.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/Numerics.class.php * * P10 numeric functions @@ -29,38 +29,38 @@ class Numerics { 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','[',']' - ); - private static $base64charsLength = 64; - - public static function intToNum($int, $length) { - $numeric = ""; - for($pos = $length-1; $pos >= 0; $pos--) { - //current position represents floor($int / ($base64charsLength ^ $pos)) - $base = 1; - for($i = 0; $i < $pos; $i++) { - $base = $base * self::$base64charsLength; - } - $posValue = floor($int / $base); - $int -= $posValue * $base; - //get the char representing $posValue - $posChar = self::$base64chars[$posValue]; - $numeric .= $posChar; - } - - return $numeric; - } - - public static function numToInt($numeric) { - $base = 1; - $int = 0; - for($pos = strlen($numeric)-1; $pos >= 0; $pos--) { - $posValue = array_search($numeric[$pos], self::$base64chars); - $int = ($posValue * $base); - $base = $base * self::$base64charsLength; - } - return $int; - } - + ); + private static $base64charsLength = 64; + + public static function intToNum($int, $length) { + $numeric = ""; + for($pos = $length-1; $pos >= 0; $pos--) { + //current position represents floor($int / ($base64charsLength ^ $pos)) + $base = 1; + for($i = 0; $i < $pos; $i++) { + $base = $base * self::$base64charsLength; + } + $posValue = floor($int / $base); + $int -= $posValue * $base; + //get the char representing $posValue + $posChar = self::$base64chars[$posValue]; + $numeric .= $posChar; + } + + return $numeric; + } + + public static function numToInt($numeric) { + $base = 1; + $int = 0; + for($pos = strlen($numeric)-1; $pos >= 0; $pos--) { + $posValue = array_search($numeric[$pos], self::$base64chars); + $int = ($posValue * $base); + $base = $base * self::$base64charsLength; + } + return $int; + } + } ?> \ No newline at end of file diff --git a/Uplink/P10Formatter.class.php b/Uplink/P10Formatter.class.php index c01b651..44b1c28 100644 --- a/Uplink/P10Formatter.class.php +++ b/Uplink/P10Formatter.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/P10Formatter.class.php * * This file contains the command formatter. @@ -24,7 +24,7 @@ */ class P10Formatter { - + private static $commands = array( "PASS" => "PASS :%s", "SERVER" => "SERVER %s 1 %s %s J10 %s]]] +s6 :%s", @@ -52,9 +52,9 @@ class P10Formatter { "318" => "{num} 318 %s %s :End of /WHOIS list.", "401" => "{num} 401 %s %s :No such nick", "SQ" => "{num} SQ :%s", - null => null + null => null ); - + public static function formatCMD($numeric, $command, $args) { if(array_key_exists($command, self::$commands)) { $command = self::$commands[$command]; diff --git a/Uplink/P10_Channel.class.php b/Uplink/P10_Channel.class.php index 0022b62..b194b82 100644 --- a/Uplink/P10_Channel.class.php +++ b/Uplink/P10_Channel.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/P10_Channel.class.php * * This class represents a IRC Channel @@ -25,7 +25,7 @@ class P10_Channel { private static $static_channels = array(); - + public static function getChannelByName($name) { $name = strtolower($name); if(array_key_exists($name, self::$static_channels)) { @@ -33,21 +33,21 @@ class P10_Channel { } return NULL; } - + public static function getChannels() { return self::$static_channels; } - + public static function getChannelCount() { return count(self::$static_channels); } - + public static function recheckAllChannels() { foreach(self::$static_channels as $channel) { $channel->checkChannel(); } - } - + } + private $name; private $topic; private $modes; @@ -55,58 +55,58 @@ class P10_Channel { private $users = array(); const USERPRIV_OPED = 0x0001; const USERPRIV_HALFOP = 0x0002; - const USERPRIV_VOICE = 0x0004; + const USERPRIV_VOICE = 0x0004; private $userPrivs = array(); - + public function __construct($name) { $this->name = $name; $this->modes = new P10_ChannelModeSet($this); $this->create_time = time(); self::$static_channels[strtolower($name)] = $this; } - + public function getName() { return $this->name; } - + public function getModes() { return $this->modes; } - + public function setTopic($topic) { $this->topic = $topic; } - + public function getTopic() { return $this->topic; } - + public function setCreateTime($time) { $this->create_time = $time; } - + public function getCreateTime() { return $this->create_time; } - + public function joinUser($user) { $this->users[$user->getNumeric()] = $user; $this->userPrivs[$user->getNumeric()] = 0; $user->addChannel($this); } - + public function burstUser($user, $opped, $halfopped, $voiced) { $this->users[$user->getNumeric()] = $user; $this->userPrivs[$user->getNumeric()] = ($opped ? self::USERPRIV_OPED : 0) | ($halfopped ? self::USERPRIV_HALFOP : 0) | ($voiced ? self::USERPRIV_VOICE : 0); $user->addChannel($this); } - + private function checkChannel() { if(count($this->users) == 0 && !$this->modes->hasMode('z')) { unset(self::$static_channels[strtolower($this->name)]); //drop empty channel } } - + public function quitUser($user) { if(array_key_exists($user->getNumeric(), $this->users)) { unset($this->users[$user->getNumeric()]); @@ -117,7 +117,7 @@ class P10_Channel { trigger_error("Tried to quit a User from a Channel it is not joined.", E_USER_WARNING); } } - + public function partUser($user) { if(array_key_exists($user->getNumeric(), $this->users)) { unset($this->users[$user->getNumeric()]); @@ -128,28 +128,28 @@ class P10_Channel { trigger_error("Tried to part a User from a Channel it is not joined.", E_USER_WARNING); } } - + public function getUserPrivs($user) { if(array_key_exists($user->getNumeric(), $this->users)) { return $this->userPrivs[$user->getNumeric()]; - } else - return 0; + } else + return 0; } - + public function setUserPrivs($user, $privs) { if(array_key_exists($user->getNumeric(), $this->users)) { $this->userPrivs[$user->getNumeric()] = $privs; } } - + public function getUserCount() { return count($this->users); } - + public function getUsers() { return $this->users; } - + } ?> \ No newline at end of file diff --git a/Uplink/P10_ModeSets.class.php b/Uplink/P10_ModeSets.class.php index 2515984..aaaf8e7 100644 --- a/Uplink/P10_ModeSets.class.php +++ b/Uplink/P10_ModeSets.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/P10_ModeSets.class.php * * classes to parse and store channel or user modes @@ -68,8 +68,8 @@ class P10_ChannelModeSet { "R" => self::MODE_TYPE_D, "z" => self::MODE_TYPE_D, "S" => self::MODE_TYPE_D, - - //special behavior + + //special behavior "o" => self::MODE_TYPE_B, "h" => self::MODE_TYPE_B, "v" => self::MODE_TYPE_B @@ -78,7 +78,7 @@ class P10_ChannelModeSet { private $modeflags = 0; private $modeparams = array(); private $channel; - + public function __construct($channel) { if(self::$modevalues == null) { //build modevalues array @@ -91,7 +91,7 @@ class P10_ChannelModeSet { } $this->channel = $channel; } - + public function parseModes($modes) { $args = explode(" ",$modes); $c = 1; @@ -115,7 +115,7 @@ class P10_ChannelModeSet { } return $c-1; } - + public function setModes($modes, $returndiff = false) { $args = explode(" ",$modes); $c = 1; @@ -130,7 +130,7 @@ class P10_ChannelModeSet { $add = true; continue; } - if($mode == "-") { + if($mode == "-") { $add = false; continue; } @@ -194,12 +194,12 @@ class P10_ChannelModeSet { return $modediff; } } - + private function handleBan($add, $mode, $mask) { //no ban management right now... return true; } - + private function setPrivs($add, $mode, $user) { $user = P10_User::getUserByNum($user); if($user == null) { @@ -209,17 +209,17 @@ class P10_ChannelModeSet { $privs = $this->channel->getUserPrivs($user); $privFlag = 0; if($mode == "o") $privFlag = P10_Channel::USERPRIV_OPED; - if($mode == "h") $privFlag = P10_Channel::USERPRIV_HALFOP; + if($mode == "h") $privFlag = P10_Channel::USERPRIV_HALFOP; if($mode == "v") $privFlag = P10_Channel::USERPRIV_VOICE; if(!($add xor ($privs & $privFlag))) - return false; + return false; if($add) $privs |= $privFlag; else $privs &= ~$privFlag; $this->channel->setUserPrivs($user, $privs); return true; - + } - + public function getModeString() { $modestr = "+"; $paramstr = ""; @@ -233,7 +233,7 @@ class P10_ChannelModeSet { } return $modestr.$paramstr; } - + public function hasMode($mode) { if(!array_key_exists($mode, self::$modevalues)) { trigger_error("unknown mode (".$mode.") on setModes (".$modes.").", E_USER_WARNING); @@ -243,9 +243,9 @@ class P10_ChannelModeSet { if(self::$modes[$mode] == self::MODE_TYPE_B || self::$modes[$mode] == self::MODE_TYPE_C) { return (($this->modeflags & $flag) ? $this->modeparams[$mode] : false); } else - return ($this->modeflags & $flag); + return ($this->modeflags & $flag); } - + } class P10_UserModeSet { @@ -275,7 +275,7 @@ class P10_UserModeSet { private static $modevalues = null; private $modeflags = 0; private $modeparams = array(); - + public function __construct($modes) { if(self::$modevalues == null) { //build modevalues array @@ -288,7 +288,7 @@ class P10_UserModeSet { } $this->parseModes($modes); } - + public function parseModes($modes) { $args = explode(" ",$modes); $c = 1; @@ -310,7 +310,7 @@ class P10_UserModeSet { } } } - + public function setModes($modes, $returndiff = false) { $args = explode(" ",$modes); $c = 1; @@ -324,7 +324,7 @@ class P10_UserModeSet { $add = true; continue; } - if($mode == "-") { + if($mode == "-") { $add = false; continue; } @@ -358,7 +358,7 @@ class P10_UserModeSet { return $modediff; } } - + public function getModeString() { $modestr = "+"; $paramstr = ""; @@ -372,7 +372,7 @@ class P10_UserModeSet { } return $modestr.$paramstr; } - + public function hasMode($mode) { if(!array_key_exists($mode, self::$modevalues)) { trigger_error("unknown mode (".$mode.") on setModes (".$modes.").", E_USER_WARNING); @@ -382,9 +382,9 @@ class P10_UserModeSet { if(self::$modes[$mode] == self::MODE_WITH_PARAMETER) { return (($this->modeflags & $flag) ? $this->modeparams[$mode] : false); } else - return ($this->modeflags & $flag); + return ($this->modeflags & $flag); } - + } ?> \ No newline at end of file diff --git a/Uplink/P10_Server.class.php b/Uplink/P10_Server.class.php index fb1ce9c..a111a6e 100644 --- a/Uplink/P10_Server.class.php +++ b/Uplink/P10_Server.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/P10_Server.class.php * * This class represents a IRC Server @@ -25,14 +25,14 @@ class P10_Server { private static $static_servers = array(); - + public static function getServerByNum($numeric) { if(array_key_exists($numeric, self::$static_servers)) { return self::$static_servers[$numeric]; } return NULL; } - + public static function getServerByName($name) { $name = strtolower($name); foreach(self::$static_servers as $server) { @@ -42,16 +42,16 @@ class P10_Server { } return NULL; } - + public static function getServerCount() { return count(self::$static_servers); } - + public static function getServers() { return self::$static_servers; } - - + + private $name; private $numeric; private $parent_server; @@ -60,7 +60,7 @@ class P10_Server { private $description; private $servers = array(); //all Servers connected to this Server private $users = array(); //all Users connected to this Server - + public function __construct($name, $numeric, $parent_server, $start_time, $link_time, $description) { $this->name = $name; $this->numeric = $numeric; @@ -68,14 +68,14 @@ class P10_Server { $this->start_time = $start_time; $this->link_time = $link_time; $this->description = $description; - + self::$static_servers[$numeric] = $this; } - + public function disconnectServer($eventHandler, $linked_only = false) { if(!$linked_only) { if($eventHandler) - $eventHandler->event_squit($this); + $eventHandler->event_squit($this); if($this->parent_server) { $this->parent_server->delServer($this); } @@ -86,38 +86,38 @@ class P10_Server { $server->disconnectServer($eventHandler); } } - + public function disconnectUsers() { //disconnect all Users connected to the actual Server foreach($this->users as $user) { $user->quit("*.net *.split"); } } - + public function getNumeric() { return $this->numeric; } - + public function getName() { return $this->name; } - + public function getStartTime() { return $this->start_time; } - + public function getLinkTime() { return $this->link_time; } - + public function getDescription() { return $this->description; } - + public function addServer($server) { $this->servers[$server->getNumeric()] = $server; } - + public function delServer($server) { if(array_key_exists($server->getNumeric(), $this->servers)) { unset($this->servers[$server->getNumeric()]); @@ -125,11 +125,11 @@ class P10_Server { trigger_error("Tried to remove a Server, that does NOT exist.", E_USER_WARNING); } } - + public function addUser($user) { $this->users[$user->getNumeric()] = $user; } - + public function delUser($user) { if(array_key_exists($user->getNumeric(), $this->users)) { unset($this->users[$user->getNumeric()]); @@ -137,11 +137,11 @@ class P10_Server { trigger_error("Tried to remove a User, that does NOT exist.", E_USER_WARNING); } } - + public function getUsers() { return $this->users; } - + public function getUserCount() { return count($this->users); } diff --git a/Uplink/P10_User.class.php b/Uplink/P10_User.class.php index 752e8be..4da7c43 100644 --- a/Uplink/P10_User.class.php +++ b/Uplink/P10_User.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/P10_User.class.php * * This class represents a IRC User @@ -25,14 +25,14 @@ class P10_User { private static $static_users = array(); - + public static function getUserByNum($numeric) { if(array_key_exists($numeric, self::$static_users)) { return self::$static_users[$numeric]; } return NULL; } - + public static function getUserByNick($nick) { $nick = strtolower($nick); foreach(self::$static_users as $user) { @@ -42,12 +42,12 @@ class P10_User { } return NULL; } - + public static function getAllUsers() { return self::$static_users; } - - + + private $numeric; private $server; private $nick; @@ -59,7 +59,7 @@ class P10_User { private $realname; private $channels = array(); private $away = null; - + public function __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) { $this->nick = $nick; $this->numeric = $numeric; @@ -73,63 +73,63 @@ class P10_User { $server->addUser($this); self::$static_users[$numeric] = $this; } - + public function getNumeric() { return $this->numeric; } - + public function getServer() { return $this->server; } - + public function setNick($nick) { $this->nick = $nick; } - + public function getNick() { return $this->nick; } - + public function setIdent($ident) { $this->ident = $ident; } - + public function getIdent() { return $this->ident; } - + public function getHost() { return $this->host; } - + public function getIP() { return $this->ip; } - + public function getConnectTime() { return $this->connect_time; } - + public function getModes() { return $this->modes; } - + public function getRealname() { return $this->realname; } - + public function setAway($away) { $this->away = $away; } - + public function getAway() { return $this->away; } - + public function isAway() { return ($this->away != null); } - + public function quit($reason) { $this->server->delUser($this); unset(self::$static_users[$this->numeric]); @@ -137,11 +137,11 @@ class P10_User { $channel->quitUser($this); } } - + public function addChannel($channel) { $this->channels[strtolower($channel->getName())] = $channel; } - + public function delChannel($channel) { if(array_key_exists(strtolower($channel->getName()), $this->channels)) { unset($this->channels[strtolower($channel->getName())]); @@ -149,15 +149,15 @@ class P10_User { trigger_error("Tried to remove a Channel, that does NOT exist.", E_USER_WARNING); } } - + public function getChannels() { return $this->channels; } - + public function getChannelCount() { return count($this->channels); } - + public function isOnChannel($channel) { return array_key_exists(strtolower($channel->getName()),$this->channels); } diff --git a/Uplink/Uplink.class.php b/Uplink/Uplink.class.php index 18468e7..6465a98 100644 --- a/Uplink/Uplink.class.php +++ b/Uplink/Uplink.class.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * Uplink/Uplink.class.php * * This file contains the basic P10 Protocol handler. @@ -45,7 +45,7 @@ class Uplink { private $server; private $eventHandler = null; private $last_local_numeric = 0; - + const FLAG_P10SESSION = 0x0001; //connection is in P10 mode (server is connected) const FLAG_SECURITY_QUIT = 0x0002; //local connection abort because of security issues const FLAG_NOT_CONNECTABLE = 0x0004; //remote server is not connectable @@ -53,13 +53,13 @@ class Uplink { const FLAG_CONNECTED = 0x0010; //connected and synced (ready) const FLAG_GOT_PASS = 0x0020; //got PASS from the remote Server private $flags = 0; - + public function __construct() { $this->client = new Client(); $this->setSetting("recv_timeout", 1000); $this->setSetting("his_usermask", "user.NoMask"); } - + public function initialize() { if($this->server) { trigger_error("Uplink already initialized.", E_USER_ERROR); @@ -74,7 +74,7 @@ class Uplink { } $this->server = new P10_Server($self_name, $self_numeric, null, time(), time(), $self_description); } - + public function loop() { if($this->server == null) { trigger_error("Uplink not initialized.", E_USER_ERROR); @@ -111,7 +111,7 @@ class Uplink { $this->parseLine($line); } } - + public function shutdown() { if($this->client->connected()) { if(($this->flags & self::FLAG_P10SESSION)) { @@ -120,36 +120,36 @@ class Uplink { $this->client->disconnect(); } } - + public function setUplinkHost($host, $port, $ssl = false, $bind = null) { $this->setSetting("host", $host); $this->setSetting("port", $port); $this->setSetting("ssl", $ssl); $this->setSetting("bind", $bind); } - + public function setLoopTimeout($timeout) { $this->setSetting("recv_timeout", $timeout); } - + public function setUplinkServer($numeric, $name, $password, $description) { $this->setSetting("numeric", Numerics::intToNum($numeric, 2)); $this->setSetting("name", $name); $this->setSetting("password", $password); $this->setSetting("description", $description); } - + public function setValidateServer($name, $password) { $this->setSetting("their_name", $name); $this->setSetting("their_password", $password); } - + public function setHISOptions($servername, $serverdesc, $usermask) { $this->setSetting("his_name", $servername); $this->setSetting("his_desc", $serverdesc); $this->setSetting("his_usermask", $usermask); } - + public function setEventHandler($event_handler) { if(!is_a($event_handler, "EventHandler")) { trigger_error((is_object($event_handler) ? get_class($event_handler) : gettype($event_handler))." is NOT a valid EventHandler.", E_USER_ERROR); @@ -157,11 +157,11 @@ class Uplink { } $this->eventHandler = $event_handler; } - + private function setSetting($setting, $value) { $this->settings[$setting] = $value; } - + private function getSetting($setting) { if(array_key_exists($setting, $this->settings)) { return $this->settings[$setting]; @@ -169,18 +169,18 @@ class Uplink { return null; } } - + private function loginServer() { $password = $this->getSetting("password"); $this->send("PASS", $password); $this->send("SERVER", $this->server->getName(), $this->server->getStartTime(), $this->server->getLinkTime(), $this->server->getNumeric(), $this->server->getDescription()); } - + private function parseLine($line) { $highExplode = explode(" :", $line, 2); $tokens = explode(" ", $highExplode[0]); if(count($highExplode) > 1) - $tokens[] = $highExplode[1]; + $tokens[] = $highExplode[1]; $cmdPos = (($this->flags & self::FLAG_P10SESSION) ? 1 : 0); if($cmdPos == 1) $from = $tokens[0]; else $from = null; @@ -189,7 +189,7 @@ class Uplink { $this->eventHandler->event_preparse($from, strtoupper($tokens[$cmdPos]), $arguments); } switch(strtoupper($tokens[$cmdPos])) { - //pre P10 Session + //pre P10 Session case "PASS": $this->recv_pass($from, $arguments); break; @@ -199,7 +199,7 @@ class Uplink { case "ERROR": $this->recv_error($from, $arguments); break; - //P10 Session + //P10 Session case "S": $this->recv_server($from, $arguments); break; @@ -262,15 +262,15 @@ class Uplink { case "NFH": $this->recv_newfakehost($from, $arguments); break; - //default + //default default: //unknown cmd if($this->eventHandler) - $this->eventHandler->event_unknown_cmd($from, strtoupper($tokens[$cmdPos]), $arguments); + $this->eventHandler->event_unknown_cmd($from, strtoupper($tokens[$cmdPos]), $arguments); break; } } - + private function send($command) { if(func_num_args() > 1) { $args = array_slice(func_get_args(), 1); @@ -280,11 +280,11 @@ class Uplink { } $this->client->send($command); } - + /******************************************************************************************** * INCOMING COMMANDS * ********************************************************************************************/ - + private function recv_pass($from, $args) { $their_pass = $this->getSetting("their_password"); if($their_pass) { @@ -298,13 +298,13 @@ class Uplink { $this->flags |= self::FLAG_GOT_PASS; } } - + private function recv_error($from, $args) { //we received an error - the socket is dead for us, now //maybe we want to log this, later $this->client->disconnect(); } - + private function recv_server($from, $args) { if($from == null) { //our uplink Server @@ -325,7 +325,7 @@ class Uplink { $this->server->addServer($new_server); $this->flags |= self::FLAG_P10SESSION | self::FLAG_BURST_PENDING; if($this->eventHandler) - $this->eventHandler->event_newserver($new_server, !($this->flags & self::FLAG_CONNECTED)); + $this->eventHandler->event_newserver($new_server, !($this->flags & self::FLAG_CONNECTED)); } else { //another server got a new slave server ^^ $server = P10_Server::getServerByNum($from); @@ -336,15 +336,15 @@ class Uplink { $new_server = new P10_Server($args[0], substr($args[5],0,2), $server, $args[2], $args[3], $args[7]); $server->addServer($new_server); if($this->eventHandler) - $this->eventHandler->event_newserver($new_server, !($this->flags & self::FLAG_CONNECTED)); + $this->eventHandler->event_newserver($new_server, !($this->flags & self::FLAG_CONNECTED)); } } - + private function recv_ping($from, $args) { $this->send("Z", $args[0]); //simply PONG P10_Channel::recheckAllChannels(); } - + private function recv_nick($from, $args) { if(count($args) <= 2) { //Nick change @@ -354,7 +354,7 @@ class Uplink { return; } if($this->eventHandler) - $this->eventHandler->event_nick($user, $args[0]); + $this->eventHandler->event_nick($user, $args[0]); $user->setNick($args[0]); } else { //New User @@ -377,10 +377,10 @@ class Uplink { $realname = $args[count($args)-1]; $user = new P10_User($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes); if($this->eventHandler) - $this->eventHandler->event_connect($user, !($this->flags & self::FLAG_CONNECTED)); + $this->eventHandler->event_connect($user, !($this->flags & self::FLAG_CONNECTED)); } } - + private function recv_end_of_burst($from, $args) { if(($this->flags & self::FLAG_BURST_PENDING)) { $this->burst(); @@ -388,11 +388,11 @@ class Uplink { $this->flags &= ~self::FLAG_BURST_PENDING; } } - + private function recv_end_of_burst_ack($from, $args) { $this->flags |= self::FLAG_CONNECTED; } - + private function recv_server_quit($from, $args) { $server = P10_Server::getServerByName($args[0]); if($server == null) { @@ -401,7 +401,7 @@ class Uplink { } $server->disconnectServer($this->eventHandler); } - + private function recv_quit($from, $args) { $user = P10_User::getUserByNum($from); if($user == null) { @@ -410,9 +410,9 @@ class Uplink { } $user->quit($args[0]); if($this->eventHandler) - $this->eventHandler->event_quit($user, $args[0]); + $this->eventHandler->event_quit($user, $args[0]); } - + private function recv_burst($from, $args) { $name = $args[0]; $create_time = $args[1]; @@ -422,7 +422,7 @@ class Uplink { } $channel = P10_Channel::getChannelByName($name); if($channel == null) - $channel = new P10_Channel($name); + $channel = new P10_Channel($name); $channel->setCreateTime($create_time); $modes = $channel->getModes(); $userstr = $args[count($args)-1]; @@ -463,13 +463,13 @@ class Uplink { } $channel->burstUser($user, $isop, $ishalfop, $isvoice); if($this->eventHandler) - $this->eventHandler->event_join($user, $channel, true); + $this->eventHandler->event_join($user, $channel, true); } $modestr = array_slice($args, 2); if($modestr[0] == "+") - $modes->parseModes(implode(" ", $modestr)); + $modes->parseModes(implode(" ", $modestr)); } - + private function recv_join($from, $args) { $user = P10_User::getUserByNum($from); if($user == null) { @@ -478,12 +478,12 @@ class Uplink { } $channel = P10_Channel::getChannelByName($args[0]); if($channel == null) - $channel = new P10_Channel($args[0]); + $channel = new P10_Channel($args[0]); $channel->joinUser($user); if($this->eventHandler) - $this->eventHandler->event_join($user, $channel, false); + $this->eventHandler->event_join($user, $channel, false); } - + private function recv_part($from, $args) { $user = P10_User::getUserByNum($from); if($user == null) { @@ -492,12 +492,12 @@ class Uplink { } $channel = P10_Channel::getChannelByName($args[0]); if($channel == null) - $channel = new P10_Channel($args[0]); + $channel = new P10_Channel($args[0]); if($this->eventHandler) - $this->eventHandler->event_part($user, $channel, $args[1]); + $this->eventHandler->event_part($user, $channel, $args[1]); $channel->partUser($user); } - + private function recv_kick($from, $args) { $user = P10_User::getUserByNum($from); if($user == null) { @@ -506,17 +506,17 @@ class Uplink { } $channel = P10_Channel::getChannelByName($args[0]); if($channel == null) - $channel = new P10_Channel($args[0]); + $channel = new P10_Channel($args[0]); $target = P10_User::getUserByNum($args[1]); if($target == null) { trigger_error("Someone tries to kick an user that does not exist or was not found on recv_kick.", E_USER_ERROR); return; } if($this->eventHandler) - $this->eventHandler->event_kick($user, $target, $channel, $args[1]); + $this->eventHandler->event_kick($user, $target, $channel, $args[1]); $channel->partUser($user); } - + private function recv_kill($from, $args) { $user = P10_User::getUserByNum($args[0]); if($user == null) { @@ -525,9 +525,9 @@ class Uplink { } $user->quit($args[1]); if($this->eventHandler) - $this->eventHandler->event_quit($user, "Killed (".$args[1].")"); + $this->eventHandler->event_quit($user, "Killed (".$args[1].")"); } - + private function recv_privmsg($from, $args) { $user = P10_User::getUserByNum($from); if($user == null) { @@ -538,16 +538,16 @@ class Uplink { if($args[0][0] == "#") { $channel = P10_Channel::getChannelByName($args[0]); if($channel == null) - $channel = new P10_Channel($args[0]); + $channel = new P10_Channel($args[0]); if(strlen($args[1]) > 0 && $args[1][0] == "\001") { //ctcp $args[1] = substr($args[1],1); if($args[1][strlen($args[1])-1] == "\001") - $args[1] = substr($args[1],0,-1); + $args[1] = substr($args[1],0,-1); $ctcpexp = explode(" ",$args[1],2); $this->eventHandler->event_chanctcp($user, $channel, strtoupper($ctcpexp[0]), (count($ctcpexp) > 1 ? $ctcpexp[1] : null)); } else - $this->eventHandler->event_chanmessage($user, $channel, $args[1]); + $this->eventHandler->event_chanmessage($user, $channel, $args[1]); } else if($args[0][0] == "$") { //"multicast" $this->eventHandler->event_privmessage($user, NULL, $args[1]); @@ -561,15 +561,15 @@ class Uplink { //ctcp $args[1] = substr($args[1],1); if($args[1][strlen($args[1])-1] == "\001") - $args[1] = substr($args[1],0,-1); + $args[1] = substr($args[1],0,-1); $ctcpexp = explode(" ",$args[1],2); $this->eventHandler->event_privctcp($user, $targetUser, strtoupper($ctcpexp[0]), (count($ctcpexp) > 1 ? $ctcpexp[1] : null)); } else - $this->eventHandler->event_privmessage($user, $targetUser, $args[1]); + $this->eventHandler->event_privmessage($user, $targetUser, $args[1]); } } } - + private function recv_notice($from, $args) { $user = P10_User::getUserByNum($from); if($user == null) { @@ -580,16 +580,16 @@ class Uplink { if($args[0][0] == "#") { $channel = P10_Channel::getChannelByName($args[0]); if($channel == null) - $channel = new P10_Channel($args[0]); + $channel = new P10_Channel($args[0]); if(strlen($args[1]) > 0 && $args[1][0] == "\001") { //ctcp $args[1] = substr($args[1],1); if($args[1][strlen($args[1])-1] == "\001") - $args[1] = substr($args[1],0,-1); + $args[1] = substr($args[1],0,-1); $ctcpexp = explode(" ",$args[1],2); $this->eventHandler->event_chanctcpreply($user, $channel, strtoupper($ctcpexp[0]), (count($ctcpexp) > 1 ? $ctcpexp[1] : null)); } else - $this->eventHandler->event_channotice($user, $channel, $args[1]); + $this->eventHandler->event_channotice($user, $channel, $args[1]); } else if($args[0][0] == "$") { //"multicast" $this->eventHandler->event_privnotice($user, NULL, $args[1]); @@ -603,15 +603,15 @@ class Uplink { //ctcp $args[1] = substr($args[1],1); if($args[1][strlen($args[1])-1] == "\001") - $args[1] = substr($args[1],0,-1); + $args[1] = substr($args[1],0,-1); $ctcpexp = explode(" ",$args[1],2); $this->eventHandler->event_privctcpreply($user, $targetUser, strtoupper($ctcpexp[0]), (count($ctcpexp) > 1 ? $ctcpexp[1] : null)); } else - $this->eventHandler->event_privnotice($user, $targetUser, $args[1]); + $this->eventHandler->event_privnotice($user, $targetUser, $args[1]); } } } - + private function recv_whois($from, $args) { /* [get] ACAAF W AX :NetworkServ */ $fromUser = P10_User::getUserByNum($from); @@ -671,11 +671,11 @@ class Uplink { if($modes->hasMode("o") && (!$modes->hasMode("H") || $fromUser->getModes()->hasMode("o"))) { if($modes->hasMode("S")) { if($modes->hasMode("D")) - $this->send("313", $from, $nick, "is a Network Service"); + $this->send("313", $from, $nick, "is a Network Service"); else - $this->send("313", $from, $nick, "is an illegal Network Service - HACKER!"); + $this->send("313", $from, $nick, "is an illegal Network Service - HACKER!"); } else - $this->send("313", $from, $nick, "is an IRC Operator"); + $this->send("313", $from, $nick, "is an IRC Operator"); } if(($auth = $modes->hasMode("r"))) { $this->send("330", $from, $nick, $auth); @@ -683,7 +683,7 @@ class Uplink { } $this->send("318", $from, $args[1]); } - + private function recv_away($from, $args) { $user = P10_User::getUserByNum($from); if($user == null) { @@ -693,14 +693,14 @@ class Uplink { if(count($args) > 0) { $user->setAway($args[0]); if($this->eventHandler) - $this->eventHandler->event_away($user, $args[0]); + $this->eventHandler->event_away($user, $args[0]); } else { $user->setAway(null); if($this->eventHandler) - $this->eventHandler->event_away($user, null); + $this->eventHandler->event_away($user, null); } } - + private function recv_mode($from, $args) { $user = P10_User::getUserByNum($from); if($user == null && strlen($from) != 2) { @@ -711,10 +711,10 @@ class Uplink { if($args[0][0] == "#") { $channel = P10_Channel::getChannelByName($args[0]); if($channel == null) - $channel = new P10_Channel($args[0]); + $channel = new P10_Channel($args[0]); $channel->getModes()->setModes($modes); if($this->eventHandler && strlen($from) != 2) - $this->eventHandler->event_chanmode($user, $channel, $modes); + $this->eventHandler->event_chanmode($user, $channel, $modes); } else { $targetUser = P10_User::getUserByNick($args[0]); if($targetUser == null) { @@ -731,11 +731,11 @@ class Uplink { if($this->eventHandler) { $this->eventHandler->event_usermode($targetUser, $modes); if($fakemodes) - $this->eventHandler->event_usermode($targetUser, $fakemodes); + $this->eventHandler->event_usermode($targetUser, $fakemodes); } } } - + private function recv_account($from, $args) { $user = P10_User::getUserByNum($args[0]); if($user == null) { @@ -753,10 +753,10 @@ class Uplink { if($this->eventHandler) { $this->eventHandler->event_usermode($user, "+r ".$auth); if($fakemodes) - $this->eventHandler->event_usermode($user, $fakemodes); + $this->eventHandler->event_usermode($user, $fakemodes); } } - + private function recv_fakehost($from, $args) { $user = P10_User::getUserByNum($args[0]); if($user == null) { @@ -766,9 +766,9 @@ class Uplink { $fakehost = $args[1]; $user->getModes()->setModes("+f ".$fakehost); if($this->eventHandler) - $this->eventHandler->event_usermode($user, "+f ".$fakehost); + $this->eventHandler->event_usermode($user, "+f ".$fakehost); } - + private function recv_newfakehost($from, $args) { $user = P10_User::getUserByNum($args[0]); if($user == null) { @@ -780,13 +780,13 @@ class Uplink { $user->setIdent($fakeident); $user->getModes()->setModes("+f ".$fakehost); if($this->eventHandler) - $this->eventHandler->event_usermode($user, "+f ".$fakehost); + $this->eventHandler->event_usermode($user, "+f ".$fakehost); } - + /******************************************************************************************** * SERVER FUNCTIONS * ********************************************************************************************/ - + private function burst() { foreach($this->server->getUsers() as $user) { $nick = $user->getNick(); @@ -809,7 +809,7 @@ class Uplink { //make a binary number out of $i $binary = decbin($i); while(strlen($binary) < count($privs_to_burst)) - $binary = '0'.$binary; + $binary = '0'.$binary; $combination_name = ''; $combination_value = 0; for($j = 0; $j < count($privs_to_burst); $j++) { @@ -859,11 +859,11 @@ class Uplink { } $this->send("EB"); } - + /******************************************************************************************** * LOCAL USER FUNCTIONS * ********************************************************************************************/ - + public function addUser($nick, $ident, $host, $ip, $modes, $realname) { $user = P10_User::getUserByNick($nick); if($user != null) return ERR_NICK_IN_USE; @@ -882,38 +882,38 @@ class Uplink { } return $user; } - + public function delUser($user, $reason) { if(!is_a($user, "P10_User")) return ERR_INVALID_USER; if($user->getServer() === $this->server) { //local user (QUIT) $user->quit($reason); - if(($this->flags & self::FLAG_CONNECTED)) - $this->send("Q", $user->getNumeric(), $reason); + if(($this->flags & self::FLAG_CONNECTED)) + $this->send("Q", $user->getNumeric(), $reason); } else { //remote user (KILL) - if(!($this->flags & self::FLAG_CONNECTED)) - return ERR_NOT_CONNECTED; + if(!($this->flags & self::FLAG_CONNECTED)) + return ERR_NOT_CONNECTED; if($this->eventHandler) - $this->eventHandler->event_quit($user, "Killed (".$reason.")"); + $this->eventHandler->event_quit($user, "Killed (".$reason.")"); $user->quit("Killed (".$reason.")"); $name = ($this->getSetting('his_name') ? $this->getSetting('his_name') : $this->getSetting('name')); $this->send("D", $user->getNumeric(), $name, $reason); } } - + public function join($user, $chanName, $privs = 0) { if(!is_a($user, "P10_User") || !($user->getServer() === $this->server)) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if($chanName[0] != "#") - return ERR_INVALID_CHANNAME; + return ERR_INVALID_CHANNAME; $channel = P10_Channel::getChannelByName($chanName); if($channel == null) - $channel = new P10_Channel($chanName); + $channel = new P10_Channel($chanName); $channel->joinUser($user); if(($this->flags & self::FLAG_CONNECTED)) - $this->send("J", $user->getNumeric(), $chanName, time(), 0); + $this->send("J", $user->getNumeric(), $chanName, time(), 0); if($privs != 0) { $channel->setUserPrivs($user, $privs); if(($this->flags & self::FLAG_CONNECTED)) { @@ -925,70 +925,70 @@ class Uplink { } } if($this->eventHandler) - $this->eventHandler->event_join($user, $channel, false); + $this->eventHandler->event_join($user, $channel, false); } - + public function part($user, $chanName, $reason) { if(!is_a($user, "P10_User") || !($user->getServer() === $this->server)) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(!((is_string($chanName) && $chanName[0] == "#") || is_a($chanName, "P10_Channel"))) - return ERR_INVALID_CHANNAME; + return ERR_INVALID_CHANNAME; if(is_a($chanName, "P10_Channel")) - $channel = $chanName; + $channel = $chanName; else - $channel = P10_Channel::getChannelByName($chanName); + $channel = P10_Channel::getChannelByName($chanName); if($channel == null) - $channel = new P10_Channel($chanName); - if(!$user->isOnChannel($channel)) - return ERR_NOT_ON_CHANNEL; + $channel = new P10_Channel($chanName); + if(!$user->isOnChannel($channel)) + return ERR_NOT_ON_CHANNEL; if($this->eventHandler) - $this->eventHandler->event_part($user, $channel, $reason); + $this->eventHandler->event_part($user, $channel, $reason); $channel->partUser($user, $reason); if(($this->flags & self::FLAG_CONNECTED)) - $this->send("L", $user->getNumeric(), $chanName, $reason); + $this->send("L", $user->getNumeric(), $chanName, $reason); } - + public function kick($user, $target, $chanName, $reason) { if(!is_a($user, "P10_User") || !($user->getServer() === $this->server)) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(!is_a($target, "P10_User")) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(!((is_string($chanName) && $chanName[0] == "#") || is_a($chanName, "P10_Channel"))) - return ERR_INVALID_CHANNAME; + return ERR_INVALID_CHANNAME; if(is_a($chanName, "P10_Channel")) - $channel = $chanName; + $channel = $chanName; else - $channel = P10_Channel::getChannelByName($chanName); + $channel = P10_Channel::getChannelByName($chanName); if($channel == null) - $channel = new P10_Channel($chanName); - if(!$target->isOnChannel($channel)) - return ERR_NOT_ON_CHANNEL; + $channel = new P10_Channel($chanName); + if(!$target->isOnChannel($channel)) + return ERR_NOT_ON_CHANNEL; if($this->eventHandler) - $this->eventHandler->event_kick($user, $target, $channel, $reason); + $this->eventHandler->event_kick($user, $target, $channel, $reason); $channel->partUser($target, $reason); if(($this->flags & self::FLAG_CONNECTED)) - $this->send("K", $user->getNumeric(), $channel->getName(), $target->getNumeric(), $reason); + $this->send("K", $user->getNumeric(), $channel->getName(), $target->getNumeric(), $reason); } - + public function privmsg($user, $target, $message) { if(!is_a($user, "P10_User") || !($user->getServer() === $this->server)) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(!is_a($target, "P10_User") && !is_a($target, "P10_Channel") && !(is_string($target) && ($target[0] == "#" || P10_User::getUserByNick($target)))) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(is_a($target, "P10_Channel")) - $targetStr = $target->getName(); + $targetStr = $target->getName(); else if(is_a($target, "P10_User")) - $targetStr = $target->getNumeric(); + $targetStr = $target->getNumeric(); else if($target[0] == "#") - $targetStr = $target; + $targetStr = $target; else - $targetStr = P10_User::getUserByNick($target)->getNumeric(); - + $targetStr = P10_User::getUserByNick($target)->getNumeric(); + if($this->eventHandler) { if($targetStr[0] == "#") { $channel = P10_Channel::getChannelByName($targetStr); if($channel == null) - $channel = new P10_Channel($targetStr); + $channel = new P10_Channel($targetStr); $this->eventHandler->event_chanmessage($user, $channel, $message); } else { $targetUser = P10_User::getUserByNum($targetStr); @@ -996,28 +996,28 @@ class Uplink { } } if(($this->flags & self::FLAG_CONNECTED)) - $this->send("P", $user->getNumeric(), $targetStr, $message); + $this->send("P", $user->getNumeric(), $targetStr, $message); } - + public function notice($user, $target, $message) { if(!is_a($user, "P10_User") || !($user->getServer() === $this->server)) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(!is_a($target, "P10_User") && !is_a($target, "P10_Channel") && !(is_string($target) && ($target[0] == "#" || P10_User::getUserByNick($target)))) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(is_a($target, "P10_Channel")) - $targetStr = $target->getName(); + $targetStr = $target->getName(); else if(is_a($target, "P10_User")) - $targetStr = $target->getNumeric(); + $targetStr = $target->getNumeric(); else if($target[0] == "#") - $targetStr = $target; + $targetStr = $target; else - $targetStr = P10_User::getUserByNick($target)->getNumeric(); - + $targetStr = P10_User::getUserByNick($target)->getNumeric(); + if($this->eventHandler) { if($targetStr[0] == "#") { $channel = P10_Channel::getChannelByName($targetStr); if($channel == null) - $channel = new P10_Channel($targetStr); + $channel = new P10_Channel($targetStr); $this->eventHandler->event_channotice($user, $channel, $message); } else { $targetUser = P10_User::getUserByNum($targetStr); @@ -1025,57 +1025,57 @@ class Uplink { } } if(($this->flags & self::FLAG_CONNECTED)) - $this->send("O", $user->getNumeric(), $targetStr, $message); + $this->send("O", $user->getNumeric(), $targetStr, $message); } - + public function mode($user, $target, $modes, $force = false) { if(!is_a($user, "P10_User") || !($user->getServer() === $this->server)) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(!is_a($target, "P10_User") && !is_a($target, "P10_Channel") && !(is_string($target) && ($target[0] == "#" || P10_User::getUserByNick($target)))) - return ERR_INVALID_USER; + return ERR_INVALID_USER; if(is_a($target, "P10_Channel")) - $targetStr = $target->getName(); + $targetStr = $target->getName(); else if(is_a($target, "P10_User")) - $targetStr = $target->getNumeric(); + $targetStr = $target->getNumeric(); else if($target[0] == "#") - $targetStr = $target; + $targetStr = $target; else - $targetStr = P10_User::getUserByNick($target)->getNumeric(); - + $targetStr = P10_User::getUserByNick($target)->getNumeric(); + if($targetStr[0] == "#") { $channel = P10_Channel::getChannelByName($targetStr); if($channel == null) - $channel = new P10_Channel($targetStr); + $channel = new P10_Channel($targetStr); $modes = $channel->getModes()->setModes($modes, true); if(($this->flags & self::FLAG_CONNECTED)) - $this->send(($force ? "OM" : "M"), $user->getNumeric(), $targetStr, $modes); + $this->send(($force ? "OM" : "M"), $user->getNumeric(), $targetStr, $modes); if($this->eventHandler) - $this->eventHandler->event_chanmode(($force ? $this->server : $user), $channel, $modes); + $this->eventHandler->event_chanmode(($force ? $this->server : $user), $channel, $modes); } else { $targetUser = P10_User::getUserByNum($targetStr); if($targetUser->getServer() === $this->server) { //just do it :D $modes = $targetUser->getModes()->setModes($modes, true); if(($this->flags & self::FLAG_CONNECTED)) - $this->send("M", $targetUser->getNumeric(), $targetUser->getNick(), $modes); + $this->send("M", $targetUser->getNumeric(), $targetUser->getNick(), $modes); if($this->eventHandler) - $this->eventHandler->event_usermode($targetUser, $modes); + $this->eventHandler->event_usermode($targetUser, $modes); } else { //SVSMODE if(($this->flags & self::FLAG_CONNECTED)) - $this->send("SM", $user->getNumeric(), $targetUser->getNumeric(), $modes); + $this->send("SM", $user->getNumeric(), $targetUser->getNumeric(), $modes); } } } - + public function ctcp($user, $target, $command, $text) { return $this->privmsg($user, $target, "\001".strtoupper($command)." ".$text."\001"); } - + public function ctcp_reply($user, $target, $command, $text) { return $this->notice($user, $target, "\001".strtoupper($command)." ".$text."\001"); } - + } ?> \ No newline at end of file diff --git a/main.php b/main.php index 8361b28..a6b615a 100644 --- a/main.php +++ b/main.php @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 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 * @@ -16,7 +16,7 @@ * along with this program. If not, see . * * * ************************************************************************ - * + * * main.php * * initial php file @@ -63,7 +63,7 @@ while(true) { $botloader->loop(); timer_loop(); if(function_exists("pcntl_signal_dispatch")) - pcntl_signal_dispatch(); + pcntl_signal_dispatch(); } ?> \ No newline at end of file