Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set("display_errors", "on");
- set_time_limit(0);
- date_default_timezone_set('Europe/Warsaw');
- gc_enable();
- $start = time();
- if(!isset($argv[1]) || !is_numeric($argv[1]))
- {
- exit();
- }
- while(true)
- {
- $core = null;
- $core = new bot($argv, $start);
- do
- {
- gc_collect_cycles();
- } while($core->listen() !== false);
- foreach($core as $i => $u)
- {
- unset($core->{$i}, $i, $u);
- }
- }
- class bot
- {
- public $root, $class, $socket, $xatC, $login, $j2, $e = array();
- public $fh = false;
- public $sock = array();
- public $pools = array();
- public $noload = array();
- public $commands = array();
- public $users = array();
- public $loaded = array();
- public $ipc = array();
- public $kicks = array();
- public $special_bot = false;
- public $Ranks = array(
- "faggots" => -1000000000000,
- "banned" => -1,
- "guest" => 0,
- "member" => 1,
- "moderator" => 2,
- "owner" => 3,
- "mainowner" => 4,
- "trusted" => 5,
- "botowner" => 6,
- "support" => 7,
- "admin" => 8
- );
- public function __construct($argv, $start)
- {
- $dd = "Lobby";
- $GLOBALS["core"] = &$this;
- list($this->debug, $this->botID) = array(isset($argv[2]) ? true : false, $argv[1]);
- list($this->ds, $this->root, $this->class, $this->lib) = array(
- DIRECTORY_SEPARATOR,
- __DIR__ . DIRECTORY_SEPARATOR,
- __DIR__ . DIRECTORY_SEPARATOR . "_class" . DIRECTORY_SEPARATOR,
- __DIR__ . DIRECTORY_SEPARATOR . "_lib" . DIRECTORY_SEPARATOR
- );
- $this->load("functions");
- $this->load("powers");
- $this->load("userClass");
- $this->mysql = new Database("localhost", "neobots", "fPt9r05$", "admin_andbots"); // phpMyAdmin
- if($argv[1] == 1)
- {
- $this->mysql->debug = true;
- }
- /* Load the bot info */
- $bot = $this->mysql->fetch_array("select * from `bots` where `ID`={$argv[1]};");
- $user = $this->mysql->fetch_array("select `id`, `subscription` from `users` where `botid`={$this->botID};");
- if(empty($bot) || empty($user))
- {
- exit;
- }
- $this->mysql->query("update `bots` set `pid`=" . getmypid() . " where `ID`={$this->botID};");
- list($this->userID, $bot) = array($user[0]['id'], $bot[0]);
- /* Set user information */
- $this->info = (object) array(
- 'cmd_char' => $bot['comchar'],
- 'user' => (object) array(
- 'id' => 0,
- 'user' => $bot['botUser'],
- 'pass' => base64_decode($bot['botPass']),
- 'nick' => $bot['nick'],
- 'avatar' => $bot['avatar'],
- 'home' => $bot['home'],
- 'status' => $bot['status'],
- 'statusglow' => $bot['statusglow'],
- 'statuscolor' => $bot['statuscolor'],
- 'statusgrad' => $bot['statusgrad'],
- 'namecolor' => $bot['namecolor'],
- 'nameglow' => $bot['nameglow'],
- 'namegrad' => $bot['namegrad'],
- 'textglow' => $bot['textglow'],
- 'textcolor' => $bot['textcolor'],
- 'hat' => $bot['hat'],
- 'hatcolor' => $bot['hatcolor'],
- 'pcback' => $bot['pcback'],
- 'stealth' => false
- ),
- 'owner' => $bot['ownerID'],
- 'language' => $bot['lang'],
- 'autowelcome' => $bot['autowelcome'],
- 'automember' => $bot['automember'],
- 'room' => $bot['room'],
- 'responses' => @(array) unserialize($bot['responses'] == '' ? 'a:0:{}' : $bot['responses']),
- 'minrank' => @(array) unserialize($bot['minrank'] == '' ? 'a:0:{}' : $bot['minrank']),
- 'alias' => @(array) unserialize($bot['alias'] == '' ? 'a:0:{}' : $bot['alias']),
- 'mod' => $bot['mod'],
- 'mod_max_consecutive' => $bot['mod_max_consec'],
- 'mod_flood' => unserialize($bot['mod_flood']),
- 'mod_max_kicks' => $bot['mod_max_kicks'],
- 'mod_max_caps' => $bot['maxCaps'],
- 'detectLink' => $bot['linkDetect'],
- 'detectCaps' => $bot['capsDetect'],
- 'detectInapp' => $bot['inappDetect'],
- 'banTime' => $bot['banTime'],
- 'dice' => $bot['dice'],
- 'start' => $start,
- 'sub' => $user[0]['subscription'],
- 'private_commands' => true,
- 'stfu' => $bot['stfu'] == '1' ? true : false,
- /* Disabled Powers ( Disable invisible by default ) */
- 'dpowers' => @(array) unserialize($bot['dpowers'] == '' ? 'a:1:{i:0;s:2:"29";}' : $bot['dpowers'])
- );
- /* If special chat, give unlimited time */
- $file = file_get_contents($this->lib . "special_chats.txt");
- preg_match_all("/http:\/\/polskixat\.pl\/([^\/\"]*)\"/", $file, $chats);
- $chats = array_map('strtolower', $chats[1]);
- if(in_array(strtolower($bot['room']), $chats))
- {
- $this->special_bot = true;
- $this->mysql->query("update `bots` set `type`=1 where `id`={$this->botID};");
- }
- unset($file);
- $this->mysql->query("update `bots` set `uptime`={$start} where `id`={$this->botID};");
- $this->info->badwords = explode(chr(10), file_get_contents($this->lib . 'badwords.txt'));
- $this->info->badwords = array_map('trim', $this->info->badwords);
- /* Parse teh nickname info */
- $this->info->user->nick = explode("##", $this->info->user->nick, 2);
- $this->info->user->nick = $this->info->user->nick[0];
- $this->info->abl = @(array) unserialize($bot['abl'] == "" ? "a:0:{}" : $bot['abl']);
- $this->info->snitch = @(array) unserialize($bot['snitch'] == "" ? "a:0:{}" : $bot['snitch']);
- $this->info->user->stealth = substr($this->info->user->nick, 0, 1) == '$' ? true : false;
- if($this->info->user->stealth == true)
- {
- $this->info->user->nick = substr($this->info->user->nick, 1);
- }
- /* End */
- $this->ranks = @(array) unserialize($bot["ranks"] == "" ? "a:0:{}" : $bot["ranks"]);
- $this->ranks[$this->info->owner] = 6;
- unset($this->ranks[1]);
- $forcerank = $this->mysql->fetch_array("select `admins`, `support` from `config` limit 0, 1;");
- foreach(explode('|', implode('|', $forcerank[0])) as $u)
- {
- if(!empty($u))
- {
- $rank = explode(',', $u);
- $this->ranks[$rank[0]] = $rank[1];
- if($rank[1] != 8)
- {
- $this->support[] = $rank[0];
- }
- }
- }
- /* Configure Room Info */
- if(empty($this->info->room))
- {
- if($this->info->language == 'en')
- $this->error("Your need to setup chat link, neo-bots.tk.pl/panel");
- if($this->info->language == 'pl')
- $this->error("Musisz skonfigurować link bota, neo-bots.tk.pl/panel");
- if($this->info->language == 'pt')
- $this->error("Você precisa configurar o link do chat, neo-bots.tk.pl/panel");
- if($this->info->language == 'es')
- $this->error("Es necesario configurar el enlace de chat, neo-bots.tk.pl/panel");
- }
- do
- {
- if($bot["_room"] != "")
- {
- $this->info->room = json_decode($bot["_room"]);
- if(time() - $this->info->room->last_update < 86400 && strtolower($bot["room"]) == strtolower($this->info->room->name))
- {
- break;
- }
- }
- $this->info->room = $this->parseRoom($bot["room"]);
- if(!is_object($this->info->room))
- {
- if($this->info->language == 'en')
- $this->error("The chat you provided doesn't exist.");
- if($this->info->language == 'pl')
- $this->error("Czat który dodajesz nie istnieje.");
- if($this->info->language == 'pt')
- $this->error("O chat que você adicionou não existe.");
- if($this->info->language == 'es')
- $this->error("El chat que agregó no existe.");
- }
- if($bot["chatpass"] != "")
- {
- $this->info->room->pass = $bot["chatpass"];
- }
- $this->info->room->last_update = time();
- $this->mysql->query("update `bots` set `_room`=:a where `ID`={$this->botID};", array("a" => json_encode($this->info->room)));
- } while(false);
- /* End */
- $this->autokick = @(array) unserialize($bot["autokick"] == "" ? "a:0:{}" : $bot["autokick"]);
- $this->load("commands");
- $this->load("responses", $bot);
- /* Join room */
- $i = 1;
- while(!$this->joinRoom(null, $i--));
- /* Cause we love to save memory even though variables are unset when a function returns */
- unset($bot, $forcerank, $u, $rank);
- }
- public function playing($ip, $port)
- {
- $open = @fsockopen($ip, $port, $errno, $errstr, 1);
- if($open) {
- fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
- $read = fread($open, 200);
- $text = preg_split('/^((?:[^,]+,){5}[^,]+),/', $this->split($read, '<body>', '</body>'));
- return implode('', $text);
- }
- return false;
- fclose($open);
- }
- public function load($what, $extras = null)
- {
- if(array_key_exists($what, $this->loaded))
- {
- return false;
- } else {
- $this->loaded[$what] = true;
- }
- switch($what)
- {
- case "responses":
- require_once $this->class . "responses.php";
- $this->response = new response($this, $extras["_responses_"]);
- return true;
- case "functions":
- require_once $this->class . "pdo.php";
- require_once $this->class . "function.php";
- $this->function = new functions($this);
- return true;
- case "commands":
- $commands = glob($this->root . "commands{$this->ds}*.php");
- foreach($commands as $cmd)
- {
- list($name, $alias) = array(substr($cmd, strrpos($cmd, $this->ds) + 1, -4), array());
- if(!in_array(strtolower($name), $this->noload))
- {
- if(array_key_exists($name, $this->commands))
- {
- continue;
- }
- include $cmd;
- $alias = array_merge(array_key_exists($name, $this->info->alias) ? $this->info->alias[$name] : array(), $alias);
- foreach($alias as $u)
- {
- $this->commands[strtolower($u)] = &$this->commands[$name];
- $this->alias[strtolower($u)] = $name;
- }
- }
- }
- unset($commands, $cmd, $name, $this->noload, $alias, $u);
- return true;
- case "powers":
- $this->function->getPowers();
- return true;
- case "userClass":
- require_once $this->class . "user.php";
- return true;
- default: return false;
- }
- }
- public function update($what)
- {
- $query = "update `bots` set `%s`=:a where `ID`={$this->botID};";
- switch($what)
- {
- case "ranks":
- $this->mysql->query(sprintf($query, 'ranks'), array('a' => serialize($this->ranks)));
- return true;
- case "nick":
- $nick = ($this->info->user->stealth ? '$' : '') . $this->info->user->nick . '##' . $this->info->user->status;
- $this->mysql->query(sprintf($query, 'nick'), array('a' => $nick));
- return true;
- case "status":
- $this->mysql->query(sprintf($query, 'status'), array('a' => $this->info->user->status));
- return true;
- case "statusglow":
- $this->mysql->query(sprintf($query, 'statusglow'), array('a' => $this->info->user->statusglow));
- return true;
- case "statuscolor":
- $this->mysql->query(sprintf($query, 'statuscolor'), array('a' => $this->info->user->statuscolor));
- return true;
- case "nameglow":
- $this->mysql->query(sprintf($query, 'nameglow'), array('a' => $this->info->user->nameglow));
- return true;
- case "namecolor":
- $this->mysql->query(sprintf($query, 'namecolor'), array('a' => $this->info->user->namecolor));
- return true;
- case "hat":
- $this->mysql->query(sprintf($query, 'hat'), array('a' => $this->info->user->hat));
- return true;
- case "hatcolor":
- $this->mysql->query(sprintf($query, 'hatcolor'), array('a' => $this->info->user->hatcolor));
- return true;
- case "pcback":
- $this->mysql->query(sprintf($query, 'pcback'), array('a' => $this->info->user->pcback));
- return true;
- case "avatar":
- $this->mysql->query(sprintf($query, 'avatar'), array('a' => $this->info->user->avatar));
- return true;
- case "home":
- $this->mysql->query(sprintf($query, 'home'), array('a' => $this->info->user->home));
- return true;
- case "autowelcome":
- $this->mysql->query(sprintf($query, 'autowelcome'), array('a' => $this->info->autowelcome));
- return true;
- case "automember":
- $this->mysql->query(sprintf($query, 'automember'), array('a' => $this->info->automember));
- return true;
- case "responses":
- $this->mysql->query(sprintf($query, 'responses'), array('a' => serialize($this->info->responses)));
- return true;
- case "disabled_powers":
- $this->mysql->query(sprintf($query, 'dpowers'), array('a' => serialize($this->info->dpowers)));
- return true;
- }
- }
- /* public function login($force = false)
- {
- if(!empty($this->login) && !$force)
- {
- return true;
- }
- $ports = array(10000, 10001, 10004);
- $this->connect(8, $ports[rand(0, 2)]);
- $this->write(0, "<v p=\"{$this->function->sanatize($this->info->user->pass)}\" n=\"{$this->function->sanatize($this->info->user->user)}\" />");
- $login_array = $this->xmlArray($this->listen(true));
- $login_array['cb'] = time();
- $this->login = (object) $login_array;
- if(property_exists($this->login, 'i') == false || !isset($this->login->n))
- {
- if(isset($this->login->e))
- {
- switch((string) $this->login->e)
- {
- case "E6": $this->error("Bad credentials were provided, did you change them after you setup the bot account in your panel?");
- case "F13": $this->forcedom = true; unset($this->login); return false;
- case "E21": $this->error("Xat isn't letting us login to your bot account. (Try again in a few seconds)");
- case "E37": $this->error("Locking or Protection seems to be enabled on your bot's xat account, please disable them both, or use our bot account.");
- }
- }
- if($this->info->language == 'en')
- $this->error("We couldn't login to your bot account [{$this->info->user->user}]");
- if($this->info->language == 'pt')
- $this->error("Falha ao conectar sua conta [{$this->info->user->user}]");
- if($this->info->language == 'es')
- $this->error("No hemos podido bot entra a tu cuenta [{$this->info->user->user}]");
- }
- if($this->info->room->bot != $this->login->i)
- {
- if($this->info->language == 'en')
- $this->error("It would seem bot power was configured incorrectly, you must set the ID to {$this->login->i}");
- if($this->info->language == 'pt')
- $this->error("Você não configurou a id do bot no chat, configure usando a id {$this->login->i}");
- if($this->info->language == 'es')
- $this->error("Usted no ha configurado la ID de la bot de chat, configurar el uso de la ID {$this->login->i}");
- }
- $this->info->user->id = $this->login->i;
- $this->info->user->user = $this->login->n;
- $this->info->user->bank = (object) array(
- "xats" => isset($this->login->dx) ? $this->login->dx : 0,
- "days" => @floor(($this->login->d1 - time()) / 60 / 60 / 24)
- );
- if($this->info->user->bank->days < 1)
- {
- $this->info->user->bank->days = 0;
- }
- //Get Bot Powers
- $this->info->powers = array();
- foreach($this->powers as $power)
- {
- $sect = isset($this->login->{'d' . ($power['section'] + 4)}) ? $this->login->{'d' . ($power['section'] + 4)} : false;
- if($sect & $power['subid'])
- {
- array_push($this->info->powers, strtolower($power['name']));
- }
- }
- return true;
- }*/
- public function joinRoom($orr = false, $fl = false)
- {
- $bot = $this->mysql->fetch_array("select * from `bots` where `ID`={$this->botID};");
- if($fl != false)
- {
- return false;
- }
- $curl = curl_init('http://neoxat.tk/mobile?'.time());
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, "username=NXBot&password=kamisama&room={$bot[0]['room']}");
- $url = curl_exec($curl);
- $parte1 = explode("\"id\":\"", $url);
- $id = explode("\"", $parte1[1]);
- $this_botID = $id[0];
- $parte2 = explode("\"k\":\"", $url);
- $k = explode("\"", $parte2[1]);
- $this_k = $k[0];
- $k3_data = explode("\"k3\":\"", $url);
- $k3 = explode("\"", $k3_data[1]);
- $this_k3 = $k3[0];
- $chat_data = explode('c="', $url);
- $chatID = explode('"', $chat_data[1]);
- $this_chatID = $chatID[0];
- $parte4 = explode("WebSocket('ws://", $url);
- $ip = explode(":", $parte4[1]);
- $this_ip = $ip[0];
- $dx_data = explode("\"xats\":\"", $url);
- $dx = explode("\"", $dx_data[1]);
- $this_dx = $dx[0];
- $d1_data = explode("\"days\":\"", $url);
- $d1 = explode("\"", $d1_data[1]);
- $this_d1 = $d1[0];
- $mypowers = explode("var mypowers = JSON.parse('", $url);
- $mypowers_data = explode("');", $mypowers[1]);
- $this_mypowers = json_decode($mypowers_data[0], true);
- $this->mysql->query("update `bots` set `powers`='" . json_encode($this_mypowers) . "' where `ID`={$this->botID};");
- $parte5 = explode($this_ip.':', $url);
- $port = explode("/", $parte5[1]);
- $this_port = $port[0];
- $this->connect($this->info->room->id);
- $hat = $this->info->user->hat == 'off' ? "" : "(hat#{$this->info->user->hat}#{$this->info->user->hatcolor})";
- if(empty($this->info->user->namegrad) || $this->info->user->namegrad == 'off'){
- $namec = $this->info->user->namecolor;
- }else{
- $namec = $this->info->user->namegrad;
- }
- if(empty($this->info->user->statusgrad) || $this->info->user->statusgrad == 'off'){
- $statusg = $this->info->user->statuscolor;
- }else{
- $statusg = $this->info->user->statusgrad;
- }
- $glow = $this->info->user->nameglow == '' ? "" : "(glow#{$this->info->user->nameglow}#{$namec})";
- $text = $this->info->user->textglow == '' ? "" : "(text#{$this->info->user->textglow}#{$this->info->user->textcolor})";
- $status = $this->info->user->status == '' ? "" : "##{$this->info->user->status}#{$this->info->user->statusglow}#{$statusg}";
- $j2 = $this->function->build("j2", array(
- 'cb' => time(),
- 'q' => '1',
- 'y' => $this->y['yi'],
- 'k' => $this_k,
- "k3" => $this_k3,
- "d1" => $this_d1,
- 'c' => $this_chatID,
- 'r' => isset($this->info->room->pass) ? $this->info->room->pass : false,
- 'f' => '8192',
- 'u' => $this_botID,
- "disabled" => "", /* m{section}='0' */
- "d0" => isset($this->login->d0) ? $this->login->d0 : false,
- "powers" => "", /* p{section}='0' */
- "dO" => isset($this->login->dO) ? $this->login->dO : false,
- "dx" => isset($this->login->dx) ? $this->login->dx : false,
- "dt" => isset($this->login->dt) ? $this->login->dt : false,
- 'N' => $this->info->user->user,
- 'n' => ($this->info->user->stealth ? '$' : "") . str_replace(' ', ' ', $this->function->sanatize(($this->info->user->nick . $hat . $glow . $text . $status))),
- 'a' => $this->function->sanatize($this->info->user->avatar .'#'. $this->info->user->pcback),
- 'h' => $this->function->sanatize($this->info->user->home),
- 'v' => '0'
- ));
- $powers = array(array(), array());
- /* Bot Powers */
- /*for($i = 2; $i <= $this->sections + 4; $i++)
- {
- if(isset($this->login->{"d{$i}"}))
- {
- $powers[0][] = "d{$i}=\"{$this->login->{"d{$i}"}}\"";
- }
- }*/
- foreach($this_mypowers as $i => $u){
- $powers[0][] = "d".substr($i, 1)."=\"{$u}\" ";
- }
- /* Disabled Powers */
- $disabled = array();
- foreach($this->info->dpowers as $i => $u)
- {
- $power = $this->function->powerinfo($u);
- $disabled['m' . $power["section"]] = isset($disabled['m' . $power["section"]]) ?
- $disabled['m' . $power["section"]] + $power["subid"] : $power["subid"];
- }
- foreach($disabled as $i => $u)
- {
- $powers[1][] = $i . "=\"{$u}\"";
- }
- /* Set Power Options */
- $j2 = str_replace(
- array("disabled=\"\"", "powers=\"\"", ' '),
- array(implode(' ', $powers[1]), implode(' ', $powers[0]), ' '),
- $j2);
- $this->write(0, $j2);
- if($this->fh)
- {
- sleep(1);
- @flock($this->fh, LOCK_UN);
- @fclose($this->fh);
- }
- return true;
- }
- public function write($socket, $data, $nonull = false)
- {
- if($socket === 0)
- {
- $this->debug($data, false);
- }
- if(substr($data, -1) != chr(0) && !$nonull)
- {
- $data .= chr(0);
- }
- return @socket_write($this->socket[$socket], $data) ? true : false;
- }
- public function listen($return = false, $data = "", $to = 1800, $timeout = Null)
- {
- $sockets = $this->socket;
- if(!isset($this->restart))
- {
- $this->restart = time() + $to;
- }
- $timeout = $this->info->sub - time() < 300 && $this->special_bot === false ? $this->info->sub - time() : $this->restart - time();
- if(@socket_select($sockets, $null, $null, $timeout) < 1)
- {
- if($this->info->sub <= time() && $this->special_bot === false)
- {
- if($this->info->language == 'en'){
- $this->function->respond("The time your bot over, buy more time for your signature!");
- $this->error("The time your bot over, buy more time for your signature!");
- }
- if($this->info->language == 'pl'){
- $this->function->respond("Czas dla Twojego bota kończy się, musisz kupić więcej czasu dla Twojej Sygnatury!");
- $this->error("Czas dla Twojego bota kończy się, musisz kupić więcej czasu dla Twojej Sygnatury!");
- }
- if($this->info->language == 'pt'){
- $this->function->respond("O tempo do seu bot acabou, compre mais tempo para sua assinatura!");
- $this->error("O tempo do seu bot acabou, compre mais tempo para sua assinatura!");
- }
- if($this->info->language == 'es'){
- $this->function->respond("El tiempo de tu bot más, comprar más tiempo para su firma!");
- $this->error("El tiempo de tu bot más, comprar más tiempo para su firma!");
- }
- } elseif($this->restart >= (time() - 2)) {
- $this->restart = time() + $to;
- $this->function->restart();
- }
- } else {
- foreach($this->socket as $i=>$u)
- {
- if(in_array($u, $sockets))
- {
- switch($i)
- {
- case 0:
- $data = "";
- do
- {
- $data .= @socket_read($u, 10075);
- } while( substr($data, -1) != chr(0) && $data !== "");
- if($data === "")
- {
- return $this->function->restart();
- }
- if($return !== false)
- {
- return $data;
- }
- $this->debug($data, true);
- foreach(explode(chr(0), $data) as $xml)
- {
- $packet = $this->xmlArray($xml);
- if($packet === false || $packet === chr(0))
- {
- continue;
- }
- if($this->parse($packet) === false)
- {
- break 3;
- }
- }
- break;
- case 1:
- $this->socket[] = socket_accept($this->socket[1]);
- socket_getsockname(end($this->socket), $ip);
- if(!in_array($ip, array(
- '127.0.0.1',
- )))
- {
- socket_close(end($this->socket));
- unset($this->socket[count($this->socket) - 1]);
- }
- break;
- case 2:
- $data = trim(strip_tags(socket_read($u, 65535)));
- if(strlen($data) < 7)
- {
- socket_close($u);
- $this->socket[2] = null;
- break;
- }
- $data = explode(',', $data, 7);
- if(count($data) != 7)
- {
- $this->function->respond("Radio error [Invalid stream?]");
- break;
- }
- $this->function->respond("Current Song: {$data[6]}");
- break;
- default:
- $input = @trim(socket_read($u, 10075));
- if($input == "")
- {
- @socket_close($this->socket[$i]);
- unset($this->socket[$i]);
- } else {
- $input = $this->xmlArray($input);
- if(!$input)
- {
- return;
- }
- switch(strtoupper($input[chr(0)]))
- {
- case "RESPONSE_RL";
- foreach($this->response as $i => $u)
- {
- unset($this->response->{$i});
- }
- unset($this->response);
- $bot = $this->mysql->fetch_array("select * from `bots` where `ID`={$this->botID};");
- unset($this->loaded["responses"]);
- $this->load("responses", $bot[0]);
- $this->function->respond("My response list has been updated.");
- unset($bot);
- break;
- case "USER_COUNT":
- $this->write($i, count($this->users));
- break;
- case "ANNOUNCE":
- $this->function->respond("Announcement: {$input['t']}");
- break;
- case "USERS":
- $users = "";
- foreach($this->users as &$u)
- {
- $users .= $u->reg ? $u->reg . ", " : $u->userid . ", ";
- }
- $this->write($i, substr($users, 0, -2));
- break;
- case "RANK":
- $this->write($i, $this->info->rank[1]);
- break;
- case "WALLET":
- $this->write($i, json_encode($this->info->user->bank));
- break;
- case "MOD":
- $this->info->mod = isset($input["enabled"]) ? true : false;
- $this->function->respond("Moderation has been " . (isset($input["enabled"]) ? "enabled" : "disabled") . " from the bot panel.");
- break;
- case "MSETTINGS":
- if(isset($input["avatar"]))
- {
- $this->info->user->avatar = $input["avatar"];
- }
- if(isset($input["nick"]))
- {
- $this->info->user->nick = $input["nick"];
- }
- if(isset($input["home"]))
- {
- $this->info->user->home = $input["home"];
- }
- if(isset($input["ownerID"]))
- {
- $this->info->info->owner = $input["ownerID"];
- }
- if(isset($input["comchar"]))
- {
- $this->info->info->cmd_char = $input["comchar"];
- }
- $this -> write ( $i , chr(0) ) ; /* C a u s e I c o u l d : p */
- $this -> function -> restart () ; /* C a u s e I c o u l d : p */
- break;
- case "REFRESH":
- $this->write(0, "<l u=\"{$this->info->user->id}\" />");
- socket_close($this->socket[0]);
- exec("nohup php /var/www/html/classes/bot_script/bot.php \"{$this->botID}\" > /dev/null 2>&1 &");
- die();
- break;
- case "MOD_UPDATE":
- if(isset($input["mod_kicks"]))
- {
- $this->info->mod_max_kicks = $input["mod_kicks"];
- }
- if(isset($input["mod_caps"]))
- {
- $this->info->mod_max_caps = $input["mod_caps"];
- }
- if(isset($input["detectLink"]))
- {
- $this->info->detectLink = $input["detectLink"];
- }
- if(isset($input["detectCaps"]))
- {
- $this->info->detectCaps = $input["detectCaps"];
- }
- if(isset($input["detectInapp"]))
- {
- $this->info->detectInapp = $input["detectInapp"];
- }
- if(isset($input["banTime"]))
- {
- $this->info->banTime = $input["banTime"];
- }
- if(isset($input["mod_consec"]))
- {
- $this->info->mod_max_consecutive = $input["mod_consec"];
- }
- if(isset($input["mod_flood"]))
- {
- $this->info->mod_flood = unserialize(base64_decode($input["mod_flood"]));
- }
- $this->write($i, chr(0));
- $this->function->respond("Mod settings have been changed from bot panel");
- break;
- case "COMMAND":
- if(isset($input['t']))
- {
- $xml = $this->xmlArray("<u u=\"{$this->info->user->id}\" a=\"{$this->info->user->avatar}\" n=\"{$this->info->user->nick}\" />");
- $user = new user($xml, $this); /* $this->commands[$args[0]](&$this, &$args, &$xml, &$user); */
- $user->botRank = $this->Ranks["botowner"];
- if(substr($input['t'], 0, 1) == $this->info->cmd_char)
- {
- $input[chr(0)] = 'm';
- $args = explode(' ', $input['t'], 2);
- $args = array_map('trim', $args);
- $args[0] = substr(strtolower($args[0]), 1);
- if(isset($this->commands[$args[0]]))
- {
- $this->commands[$args[0]]($this, $args, $input, $user, $args[0]);
- }
- $this->write($i, "Command executed.");
- $executed = 1;
- }
- }
- if(!isset($executed))
- {
- $this->write($i, chr(0));
- }
- unset($xml, $user, $args);
- break;
- default: $this->write($i, chr(0)); break;
- }
- }
- break;
- }
- }
- }
- }
- return true;
- }
- public function parse($xml)
- {
- switch($xml[chr(0)])
- {
- case 'a':
- switch($xml['k'])
- {
- case 'T':
- if(strtolower($this->info->room->name) == "NeoBots" && $xml['b'] == $this->info->user->id)
- {
- list($user, $xats) = array($this->function->getuserbyid($xml['u']), (int) $xml['x'] + ($xml['s'] * 13));
- $value = ($xats % 300 == 0 ? strtotime("+ " . ($xats / 300) . " months") : strtotime("+ " . ($xats * 2) . " hours")) - time();
- if(!isset($xml['t']) && !ctype_alnum($xml['t']))
- {
- $this->mysql->query("insert into `redeem` values('NULL', " . time() . ", '{$key}', {$value}, 0);");
- $user->pc("Link to put your code: http://neo-bots.tk/panel?redeem");
- usleep(400000);
- $user->pc("Your redemption code is: {$key}");
- $this->function->respond("{$userfm->reg}({$xml['u']}) transfer {$xats} xats and purchased " . ($xats % 300 == 0 ? (($xats / 300) . " months") : (round($value / 60 / 60, 2) . " hours")) . ".");
- $this->mysql->insert('payments_xats', array('NULL', $user->userid, time(), $xml['x'], $xml['s'], '0'), true);
- $this->function->restart(true);
- }
- else if(isset($xml['t']) && ctype_alnum($xml['t']))
- {
- $bot = $this->mysql->fetch_array('select * from `bots` where `ID`=:a;', array('a' => $xml['t']));
- if(empty($bot))
- {
- do
- {
- $key = $this->mysql->rand(64);
- } while($r = $this->mysql->fetch_array("select `id` from `redeem` where `code`='{$key}';") && !empty($r));
- $this->mysql->query("insert into `redeem` values('NULL', " . time() . ", '{$key}', {$value}, 0);");
- $user->pc("You did not provide a valid BotID, redeem the following code at http://neo-bots.tk/panel?redeem");
- usleep(400000);
- $user->pc("Your redemption code is: {$key}");
- $this->function->respond("{$userfm->reg}({$xml['u']}) transfer {$xats} xats and purchased " . ($xats % 300 == 0 ? (($xats / 300) . " months") : (round($value / 60 / 60, 2) . " hours")) . ".");
- $this->mysql->insert('payments_xats', array('NULL', $user->userid, time(), $xml['x'], $xml['s'], $xml['t']), true);
- } else {
- $_user = $this->mysql->fetch_array("select * from `users` where `botid`='{$bot[0]['ID']}';");
- if($_user[0]["subscription"] < time())
- {
- $_user[0]["subscription"] = time();
- }
- $_user[0]["subscription"] += $value;
- $this->mysql->query("update `users` set `subscription`={$_user[0]["subscription"]} where `id`={$_user[0]["id"]};");
- $user->pc("Your have purchased " . ($xats % 300 == 0 ? (($xats / 300) . " months") : (round($value / 60 / 60, 2) . " hours")) . " for \"{$_user[0]["user"]}\".");
- $this->function->respond("{$userfm->reg}({$xml['u']}) transfer {$xats} xats and purchased " . ($xats % 300 == 0 ? (($xats / 300) . " months") : (round($value / 60 / 60, 2) . " hours")) . ".");
- $this->mysql->insert('payments_xats', array('NULL', $user->userid, time(), $xml['x'], $xml['s'], $xml['t']), true);
- }
- $this->function->restart(true);
- } elseif($this->info->user->id == $xml['b']) {
- $this->function->restart(true);
- }
- break; }
- return true;
- }
- case 'p':
- if(!in_array('off', $this->info->snitch))
- {
- foreach($this->info->snitch as $u)
- {
- if($u == "on")
- {
- continue;
- }
- if($u != $this->function->runder($xml['u']) && substr($xml['t'], 0, 1) != '/')
- {
- list($lamingtons, $user) = array($this->function->getuserbyid($u), $this->function->getuserbyid($xml['u']));
- if($lamingtons !== false)
- {
- $lamingtons->pc('[' . ( $user->reg ? $user->reg : $user->userid ) . "][" . (isset($xml['s']) ? "PC" : "PM") . "]: {$xml['t']}");
- }
- }
- sleep(1);
- }
- }
- if(substr($xml['t'], 0, strlen($this->info->cmd_char)) != $this->info->cmd_char || $this->info->private_commands == false)
- {
- if(substr($xml['t'], 0, strlen($this->info->cmd_char)) == $this->info->cmd_char)
- {
- $this->function->respond("Private commands are disabled", 2, $this->function->runder($xml['u']));
- }
- break;
- }
- case 'm':
- if(isset($xml['s']) && $xml[chr(0)] != 'p' || !isset($xml['u']))
- {
- break;
- }
- if(!isset($user))
- {
- $user = $this->function->getuserbyid($xml['u']);
- }
- if(!is_object($user) || $this->function->mod($user, $xml) === true)
- {
- break;
- }
- $xml['t'] = str_replace(array(' (', ') '), array('(', ')'), $xml['t']);
- if(substr($xml['t'], 0, 1) === $this->info->cmd_char)
- {
- if(!empty($this->info->abl) && in_array('on', $this->info->abl) && !in_array($user->userid, $this->info->abl) && !$user->rank('botowner'))
- {
- return $user->pm("Only users on the access list!");
- }
- $args = explode(chr(32), trim($xml['t']), 2);
- $args = array_map("trim", $args);
- $args[0] = substr(strtolower($args[0]), 1);
- if(isset($this->commands[$args[0]]))
- {
- if(isset($user->last[$args[0]]) && time() - $user->last[$args[0]] <= 2)
- {
- return $user->pm("Don't use my commands for flood...");
- }
- $alias = isset($this->alias[$args[0]]) ? $this->alias[$args[0]] : $args[0];
- $this->commands [$args[0]] ($this, $args, $xml, $user, $alias);
- $user->last[$args[0]] = time();
- } else {
- $user->pm("Command not found, see more here: http://neo-bots.tk/commands");
- }
- } elseif($xml[chr(0)] == 'm') {
- $respond = false;
- foreach($this->info->responses as $i => $u)
- {
- if( ($u[1] == true && strtolower($xml['t']) == $i) ||
- ($u[1] != true && is_numeric(stripos($xml['t'], $i))))
- {
- $response = str_replace(
- array("{nick}"),
- array($user->nick),
- $u[0]
- );
- $this->function->respond($response);
- return true;
- }
- }
- }
- return true;
- case 'u':
- $xml['u'] = $this->function->runder($xml['u']);
- if(!isset($this->users[$xml['u']]))
- {
- $this->users[$xml['u']] = new user($xml, $this);
- if(isset($this->users[$xml['u']]->selfDestruct))
- {
- unset($this->users[$xml['u']]);
- }
- $this->write(0, "<z d=\"{$xml['u']}\" u=\"{$this->info->user->id}\" t=\"/l\" />");
- } else {
- $this->users[$xml['u']]->reset($xml);
- }
- return true;
- case 'l':
- if(isset($this->users[$xml['u']]))
- {
- unset($this->users[$xml['u']]);
- }
- return true;
- case 'z':
- $user = $this->function->getuserbyid($xml['u']);
- if(!is_object($user))
- {
- break;
- }
- switch(substr($xml['t'], 1, 1))
- {
- case 'l':
- if(isset($user->last['z']))
- {
- if($user->last['z'] > time())
- {
- break;
- }
- }
- $user->last['z'] = time() + 2;
- $this->write(0, "<z d=\"{$xml['u']}\" u=\"{$this->info->user->id}\" t=\"/ayewpk\" />");
- $this->function->respond($this->response->_return(51), 1, $user->userid);
- break;
- case 'a':
- $user->reset($xml, true, isset($xml["po"]) ? $xml["po"] : "");
- break;
- }
- return true;
- case 'i':
- $this->e25 = 0;
- $info = explode(";=", $xml['b']);
- $this->info->room = (object) array_merge((array)$this->info->room, array(
- "bg" => $info[0],
- "tabbed" => array(
- "name" => $info[1],
- "id" => $info[2]
- ),
- "lang" => $info[3],
- "radio" => str_replace(array("http://", "https://"), "", $info[4]),
- ));
- $this->info->room->storemessages = $xml['f'] & 256 ? false : true;
- $this->info->room->deleted = $xml['f'] & 33554432 ? true : false;
- $this->info->room->membersonly = $xml['f'] & 128 ? true : false;
- $this->info->room->radio = (array) explode(':', $this->info->room->radio);
- $this->info->rank = array(isset($xml['r']) ? $xml['r'] : 0);
- $this->info->rank[0] = $this->function->relrank($this->info->rank[0]);
- $this->info->rank[1] = $this->function->wordrank($this->info->rank[0]);
- $this->mysql->query("update `bots` set `chatdsc`=:a, `chatrdo`=:b, `chatbg`=:c where `ID`={$this->botID};", array(
- 'a' => $this->info->room->desc,
- 'b' => $info[4],
- 'c' => $info[0]
- ));
- return true;
- case 'v':
- case "dup":
- if($xml[chr(0)] == "dup")
- {
- exit;
- }
- if(isset($xml['n']))
- {
- break;
- }
- if(!empty($xml['e'])) switch(substr($xml['e'], 1))
- {
- case '8': $this->error("Bad Xat-Credentials (bot login information)"); exit;
- case "36": $this->error("We had trouble logging into your bot account!"); exit;
- case "37": $this->error("Locking and Protection must be off to be able to login to your bot!"); exit;
- case "25": $this->error("Bot Power was not configured correctly, make sure it is using the Xat ID \"{$this->info->user->id}\"<br /> <center> <a href=\"http://img849.imageshack.us/img849/1448/2mi0.png\"> Click Here for help with setting up bot power :) </a>"); exit;
- default: $this->function->restart(); break 2; /* break 2 to avoid the exit; ( break out of the current switch, then break out of the parent switch ) */
- }
- sleep(5);
- $this->function->restart();
- break;
- case 'q':
- case "logout":
- case "idle":
- if($xml['e'] == "E25")
- {
- if(!isset($this->e25))
- {
- $this->e25 = 0;
- }
- if(++$this->e25 < 10)
- {
- sleep(1);
- break;
- }
- }
- if(in_array($xml['e'], array("E35", "E21", "E25")))
- {
- $this->error("Xat's telling us that bot power wasn't setup correctly, try reassigning it, then setting the ID to 1000, and then back to your bot's ID");
- }
- sleep(3); /* To stop it "spamming" xat servers */
- $this->function->restart();
- return true;
- case 'done':
- $this->e = array();
- break;
- case 'w':
- $pools = explode(' ', $xml['v']);
- array_shift($pools);
- $this->pools = $pools;
- break;
- }
- return true;
- }
- public function xmlArray($packet, $expected='*', $return=array())
- {
- $xml = @simplexml_load_string($packet);
- if(!method_exists($xml, 'attributes'))
- {
- return false;
- }
- $return[chr(0)] = $xml->getName();
- if(is_array($expected))
- {
- foreach($expected as $i=>$u)
- {
- $return[$i] = false;
- }
- }
- foreach($xml->Attributes() as $i=>$u)
- {
- if(!is_array($expected) || in_array($i, $return))
- {
- $return[$i] = mb_convert_encoding((string) $u, "");
- }
- }
- return $return;
- }
- public function connect($room = 0, $fpt = false, $fail = 0, $force = false)
- {
- if(!empty($this->socket))
- {
- @array_map('socket_close', $this->socket);
- }
- $this->socket = array( socket_create(AF_INET, SOCK_STREAM, SOL_TCP) );
- if(isset($this->forcedom))
- {
- unset($this->forcedom);
- list($fail, $force) = array($fail + 1, true);
- }
- while(true)
- {
- $server = isset($this->serv) && $force === false ? $this->serv : $this->function->connections($this->info->room->id, $fail % 2 == 0 ? false : true);
- switch(@socket_connect($this->socket[0], $server[0], $fpt ? $fpt : $server[1]))
- {
- case false:
- unset($this->serv);
- if(++$fail >= 5)
- {
- $this->error('We are having trouble connecting to xats server.<br />Updates maybe?');
- }
- sleep(60);
- break;
- default:
- $this->write(0, '<y u="' . $this->info->user->id . '" m="1" r="' . $room . '" />');
- print $room;
- $response = $this->xmlArray($this->listen(true));
- if($response[chr(0)] != 'y')
- {
- if(!isset($this->e[$response[chr(0)]]))
- {
- $this->e[$response[chr(0)]] = 0;
- }
- if(++$this->e[$response[chr(0)]] >= 100)
- {
- $this->error('Xat is not allowing us to connect.');
- }
- if($this->e[$response[chr(0)]] % 10 == 0)
- {
- sleep(floor($this->e[$response[chr(0)]] / 10));
- }
- break;
- }
- $this->e = array();
- $this->y = $response;
- list($this->socket[1], $this->socket[2]) = array(
- socket_create_listen(0), /* API Socket */
- Null /* Radio */
- );
- socket_getsockname($this->socket[1], $this->ipc[0], $this->ipc[1]);
- $this->mysql->query('update `bots` set `ipc`=:a where `ID`=' . $this->botID . ';', array('a' => serialize($this->ipc)));
- $this->serv = $server;
- break 2;
- }
- }
- }
- public function single_connect($socket, $ip, $port)
- {
- $this->socket[$socket] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- socket_connect($this->socket[$socket], $ip, $port);
- }
- function error($text, $noquit = false)
- {
- print $text . chr(10); /* Print the error to CLI */
- /* Below - Insert the error into the users "messages" */
- $this->mysql->insert('messages', array('NULL', $this->userID, 1, $text), true);
- if(!$noquit)
- {
- exit;
- }
- }
- public function parseRoom($room)
- {
- $source = file_get_contents('http://neoxat.tk/' . (is_numeric($room) ? "xat{$room}?x" : $room."?x"));
- $info = array(
- //"id" => $this->split($source, 'roomid=', '&'),
- "id" => "1",
- "name" => substr($this->split($source, '<h1>', '<'),6),
- //"bot" => trim($this->split($source, "xat:bot\" content=\"", '"')),
- "bot" => "8895",
- "desc" => $this->split($source, "<h2>", '<')
- );
- return $info["id"] == false ? false : (object) $info;
- }
- public function split($content, $start, $end, $i=false)
- {
- $engine = $i ? "stripos" : "strpos";
- if(!is_numeric($engine($content, $start)))
- {
- return false;
- }
- $content = substr($content, $engine($content, $start) + strlen($start));
- if(!is_numeric($engine($content, $end)))
- {
- return false;
- }
- $content = substr($content, 0, $engine($content, $end));
- return strlen($content) >= 1 ? $content : false;
- }
- public function debug($packet, $x)
- {
- if($this->debug == true)
- {
- print '[' . time() . "] BOT " . ($x == true ? "<--" : "-->") . " XAT: " . trim($packet) . str_repeat(PHP_EOL, 2);
- }
- }
- }
Add Comment
Please, Sign In to add comment