* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* BotLoader/Bot.class.php
*
* bots' parent class.
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;
}
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* BotLoader/BotLoader.class.php
*
* This class loades / rehashs or unloads all Bots.
private $loadedBots = array();
private $botDatabases = array();
private static $botloader;
-
+
public function __construct($uplink) {
$this->uplink = $uplink;
$this->saxdb = new saxdb();
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) {
$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()) {
$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
}
return true;
}
-
+
private function unloadBot($name, $delete = true) {
if(!(array_key_exists(strtolower($name), $this->loadedBots))) return false;
//unload bot
}
return true;
}
-
+
private function rehashBot($name) {
if(!(array_key_exists(strtolower($name), $this->loadedBots))) return false;
$botfile = null;
$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;
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);
}
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* BotLoader/saxdb.class.php
*
* Simple PHP P10 database.
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");
$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];
return array();
}
}
-
+
public function setSection($name, $value) {
$this->database[$name] = $value;
}
-
+
private function parseDB($db) {
$parserflags = 0;
$openblocks = 0;
}
return $output;
}
-
+
private function serializeDB($db) {
$dbstring = "";
foreach($db as $name => $value) {
}
return $dbstring;
}
-
+
}
?>
\ No newline at end of file
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/CGod.class.php
*
* simple C debugger...
class {$_NAME} extends Bot {
private $uplink;
private $c, $ccache = array();
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!$old) {
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]);
$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");
}
$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'])) {
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']) {
$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);
}
$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'], "\ 34".$line."\ 3");
}
} 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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/ExampleBot.class.php
*
* a simple example bot...
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
//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;
$this->uplink->delUser($this->example_bot, "Bye.");
}
}
-
+
public function recive_privmsg($user, $channel, $message) {
//We've got a privmsg...
$exp=explode(" ",$message);
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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/IPv6.class.php
*
* IPv6 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) {
} 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;
$this->uplink->delUser($this->ipv6, "Bye.");
}
}
-
+
public function loop() {
for($i = 0; $i < 2; $i++) {
foreach($this->cache[$i] as $id => $cache) {
}
}
}
-
+
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()) {
$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()) {
$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()) {
$this->cache[1][$user->getNumeric()] = time() + 600;
}
}
-
+
public function recive_quit($user, $reason) {
if($user === $this->ipv6) {
$this->load($this->uplink);
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/JavaGod.class.php
*
* simple Java debugger...
class {$_NAME} extends Bot {
private $uplink;
private $bot, $execcache = array();
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!$old) {
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]);
$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");
}
$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'])) {
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']) {
$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);
}
$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'], "\ 34".$line."\ 3");
}
} 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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/MCBot.class.php
*
* MCBot bot...
class {$_NAME} extends Bot {
private $uplink;
private $mcbot;
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!$old) {
} 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;
$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);
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/ModManager.class.php
*
* module manager bot...
class {$_NAME} extends Bot {
private $uplink;
private $modman;
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!$old) {
} 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;
$this->uplink->delUser($this->modman, "Bye.");
}
}
-
+
public function recive_privmsg($user, $channel, $message) {
if(!$user->getModes()->hasMode('o')) return 0;
$exp=explode(" ",$message);
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) {
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/PHPGod.class.php
*
* simple PHP debugger...
class {$_NAME} extends Bot {
private $uplink;
private $php, $phpcache = array();
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!$old) {
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]);
$this->uplink->delUser($this->php, "Bye.");
}
}
-
+
public function loop() {
foreach($this->phpcache as $id => $php) {
if(!$this->checkstate($php)) {
}
}
}
-
+
function recive_privmsg($user, $channel, $message) {
$opOnPHPChannel = false;
$PHPChannel = P10_Channel::getChannelByName("#PHP");
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']) {
$i++;
if($i>1000) {
$this->uplink->privmsg($this->php, $php['channel'], "too many lines!");
- break;
+ break;
}
$this->uplink->privmsg($this->php, $php['channel'], $line);
}
$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'], "\ 34".$line."\ 3");
}
} 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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/PerlGod.class.php
*
* simple Perl debugger...
class {$_NAME} extends Bot {
private $uplink;
private $bot, $execcache = array();
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!$old) {
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]);
$this->uplink->delUser($this->bot, "Bye.");
}
}
-
+
public function loop() {
foreach($this->execcache as $id => $entry) {
if(!$this->checkstate($entry)) {
}
}
}
-
+
function recive_privmsg($user, $channel, $message) {
$opOnPerlChannel = false;
$entryChannel = P10_Channel::getChannelByName("#Perl");
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']) {
$i++;
if($i>1000) {
$this->uplink->privmsg($this->bot, $entry['channel'], "too many lines!");
- break;
+ break;
}
$this->uplink->privmsg($this->bot, $entry['channel'], $line);
}
$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'], "\ 34".$line."\ 3");
}
} 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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/PulseBot.class.php
*
* WhatPulse bot...
private $pulsebot;
private $cache = array();
private $db = array();
-
+
const TEAM_ID = 19418;
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!$old) {
ModCMD::bind($this, BIND_JOIN, "recive_join");
ModCMD::bind($this, BIND_QUIT, "recive_quit");
}
-
+
public function unload($rehash = false) {
if($rehash) {
return $this->pulsebot;
$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
}
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
}
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);
}
}
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);
$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":
break;
}
}
-
+
public function recive_join($user, $channel, $isBurst) {
if(!$this->botOppedOnChannel($channel)) return false;
if(!($auth = $user->getModes()->hasMode('r'))) return;
$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);
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Bots/Stats.class.php
*
* RRD Stats module...
class {$_NAME} extends Bot {
private $uplink;
private $timer;
-
+
public function load($uplink, $old = false) {
$this->uplink = $uplink;
if(!file_exists("db/network.rrd")) {
"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";
"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";
"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(
"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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* ModCMD/Binding.class.php
*
* a single Binding...
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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* 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++);
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)) {
}
}
}
-
+
public static function unbindBot($bot) {
if(is_a($bot, "Bot")) {
foreach(self::$bindings as $type => $bindings) {
}
}
}
-
+
/********************************************************************************************
* 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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Tools/Table.class.php
*
* IRC Table Class
class Table {
private $table;
-
+
public function Table($colums) {
$this->table = array();
$this->table['set'] = array();
$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();
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();
$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" : "");
}
}
return $output;
}
-
+
}
?>
\ No newline at end of file
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Tools/timer.inc.php
*
* timer functions
$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;
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/Client.class.php
*
* This file contains the basic Client Socket.
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) {
$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);
}
return true;
}
-
+
public function recv() {
$read = array($this->socket);
$write= null;
}
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;
}
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/EventHandler.interface.php
*
* This file contains the Uplink EventHandler interface.
*/
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);
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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/IpAddr.class.php
*
* This class represents an IPv4 or IPv6 address.
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;
$this->parseNumeric($initial_value);
}
}
-
+
public function parseNumeric($numeric) {
if(strlen($numeric) == 6) { //IPv4
$value = Numerics::numToInt($numeric);
$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);
}
$this->addr_is_ipv6 = true;
}
-
+
public function parseIPv4($ipv4) {
$ipv4blocks = explode(".",$ipv4);
$this->ip6[6] = intval($ipv4blocks[0]) << 8;
$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;
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;
return $ipv4[0].$ipv4[1];
}
}
-
+
}
?>
\ No newline at end of file
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/Numerics.class.php
*
* P10 numeric functions
'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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/P10Formatter.class.php
*
* This file contains the command formatter.
*/
class P10Formatter {
-
+
private static $commands = array(
"PASS" => "PASS :%s",
"SERVER" => "SERVER %s 1 %s %s J10 %s]]] +s6 :%s",
"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];
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/P10_Channel.class.php
*
* This class represents a IRC Channel
class P10_Channel {
private static $static_channels = array();
-
+
public static function getChannelByName($name) {
$name = strtolower($name);
if(array_key_exists($name, self::$static_channels)) {
}
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;
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()]);
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()]);
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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/P10_ModeSets.class.php
*
* classes to parse and store channel or user modes
"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
private $modeflags = 0;
private $modeparams = array();
private $channel;
-
+
public function __construct($channel) {
if(self::$modevalues == null) {
//build modevalues array
}
$this->channel = $channel;
}
-
+
public function parseModes($modes) {
$args = explode(" ",$modes);
$c = 1;
}
return $c-1;
}
-
+
public function setModes($modes, $returndiff = false) {
$args = explode(" ",$modes);
$c = 1;
$add = true;
continue;
}
- if($mode == "-") {
+ if($mode == "-") {
$add = false;
continue;
}
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) {
$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 = "";
}
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);
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 {
private static $modevalues = null;
private $modeflags = 0;
private $modeparams = array();
-
+
public function __construct($modes) {
if(self::$modevalues == null) {
//build modevalues array
}
$this->parseModes($modes);
}
-
+
public function parseModes($modes) {
$args = explode(" ",$modes);
$c = 1;
}
}
}
-
+
public function setModes($modes, $returndiff = false) {
$args = explode(" ",$modes);
$c = 1;
$add = true;
continue;
}
- if($mode == "-") {
+ if($mode == "-") {
$add = false;
continue;
}
return $modediff;
}
}
-
+
public function getModeString() {
$modestr = "+";
$paramstr = "";
}
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);
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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/P10_Server.class.php
*
* This class represents a IRC Server
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) {
}
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;
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;
$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);
}
$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()]);
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()]);
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);
}
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/P10_User.class.php
*
* This class represents a IRC User
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) {
}
return NULL;
}
-
+
public static function getAllUsers() {
return self::$static_users;
}
-
-
+
+
private $numeric;
private $server;
private $nick;
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;
$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]);
$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())]);
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);
}
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* Uplink/Uplink.class.php
*
* This file contains the basic P10 Protocol handler.
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
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);
}
$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);
$this->parseLine($line);
}
}
-
+
public function shutdown() {
if($this->client->connected()) {
if(($this->flags & self::FLAG_P10SESSION)) {
$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);
}
$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];
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;
$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;
case "ERROR":
$this->recv_error($from, $arguments);
break;
- //P10 Session
+ //P10 Session
case "S":
$this->recv_server($from, $arguments);
break;
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);
}
$this->client->send($command);
}
-
+
/********************************************************************************************
* INCOMING COMMANDS *
********************************************************************************************/
-
+
private function recv_pass($from, $args) {
$their_pass = $this->getSetting("their_password");
if($their_pass) {
$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
$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);
$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
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
$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();
$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) {
}
$server->disconnectServer($this->eventHandler);
}
-
+
private function recv_quit($from, $args) {
$user = P10_User::getUserByNum($from);
if($user == null) {
}
$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];
}
$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];
}
$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) {
}
$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) {
}
$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) {
}
$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) {
}
$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) {
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]);
//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) {
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]);
//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);
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);
}
$this->send("318", $from, $args[1]);
}
-
+
private function recv_away($from, $args) {
$user = P10_User::getUserByNum($from);
if($user == null) {
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) {
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) {
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) {
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) {
$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) {
$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();
//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++) {
}
$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;
}
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)) {
}
}
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);
}
}
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);
}
}
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
* 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 *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
************************************************************************
- *
+ *
* main.php
*
* initial php file
$botloader->loop();
timer_loop();
if(function_exists("pcntl_signal_dispatch"))
- pcntl_signal_dispatch();
+ pcntl_signal_dispatch();
}
?>
\ No newline at end of file