Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- error_reporting(1);
- class BasicBot
- {
- public $nome = "(hi)Guest";
- public $avatar = "2";
- public $home = "http://www.google.com/";
- public $admins = Array(
- 42
- );
- public $Wellcome = "xat";
- public $users;
- public $socket;
- public $chatID;
- public $botID = 150;
- public $port;
- public $ip;
- public $k1;
- public function SocketConnect()
- {
- $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- $test = socket_connect($this->socket, '144.217.16.67', 10001);
- }
- public function SocketDesconnect()
- {
- if (isset($this->socket) && $this->socket == True)
- {
- socket_close($this->socket);
- }
- $this->socket = False;
- }
- public function parse($xml, $return = null)
- {
- $conteudo = @simplexml_load_string(trim($xml));
- foreach ($conteudo->Attributes() as $i => $u) $return[$i] = (string)((string)$u);
- return $return;
- }
- public function sendPacket($packet)
- {
- echo "[BOT-LOG]-> {$packet}\n";
- return socket_write($this->socket, $packet, strlen($packet));
- }
- public function login()
- {
- $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- socket_connect($sock, '144.217.16.67', 10001);
- $user = "switch";
- $pass = '34353815';
- socket_write($sock, "<v r=\"8\" p=\"{$pass}\" n=\"{$user}\" />\0");
- $this->loginArray = $this->parse(socket_read($sock, 2048));
- if(isset($this->loginArray["e"])) exit("Login error. [{$this->loginArray["e"]}]");
- socket_close($sock);
- }
- public function EnterRoom()
- {
- $this->SocketConnect();
- $this->login();
- $this->sendPacket('<y r="1" m="1" v="0" u="' . $this->loginArray["i"] . '" />');
- $x = $this->parse(socket_read($this->socket, 2048));
- var_dump($x);
- $y = $x['i'];
- $p = $x['p'];
- $i = $y;
- $disable = array(213);
- $j2 = array();
- $j2 = $this->buildJ2($x, $this->loginArray, $disable);
- $this->write("j2", $j2);
- }
- public function write($tag, $data) {
- $packet = "<".$tag;
- if(!empty($data) && is_array($data)) {
- foreach($data as $k => $v) {
- $packet .= " ".$k."=\"".$v."\"";
- }
- }
- $packet .= " />";
- if($packet{strlen($packet)-1} != chr(0))
- $packet .= chr(0);
- print_r($data);
- socket_write($this->socket, $packet);
- }
- public function verifyPowers($disabled) {
- foreach($disabled as $d) {
- $section = $d >> 5;
- $subid = pow(2, $d % 32);
- $m[$section] += $subid;
- }
- return $m;
- }
- public function buildJ2($handshake, $details, $disabledPowers) {
- $j2 = array();
- $dp = $disabledPowers;
- $stra = explode("_", "100_100_5_100");
- $p_w = $stra[0];
- $p_h = $stra[1];
- $t = ($handshake['i'] % ($p_w * $p_h));
- $p_x = ($t % $p_w);
- $p_y = floor(($t / $p_w));
- $l5 = floor(2 << ($p_x % 94)) % $handshake['c'] + $handshake['i'];
- $l4 = floor(5 << ($handshake['i'] % (integer)$handshake['l3'])) % $p_y + $handshake['i'];
- $disabled = $dp;
- for($di = 0; $di < 300; $di++) {
- if(isset($dp->{$di})) {
- array_push($disabled, $di);
- }
- }
- $m = $this->verifyPowers($disabled);
- $j2["l6"] = 0;
- $j2["l5"] = $l5;
- $j2["l4"] = $l4;
- $j2["l3"] = rand(1000, 5000);
- $j2["l2"] = 0;
- $j2["i"] = $handshake["i"];
- $j2["cb"] = $handshake['c'];
- $j2["y"] = $handshake['i'];
- $j2["q"] = 1;
- $j2["k"] = $details["k1"];
- $j2["k3"] = $details["k3"];
- $j2["p"] = 0;
- if(isset($details['d1']))
- $j2["d1"] = $details["d1"];
- $j2["c"] = 1;
- $j2["r"] = '';
- $j2["u"] = $details["i"];
- for($i = 0; $i <= 25; $i++) {
- if(isset($m[$i])) {
- $j2["m".$i] = $m[$i];
- }
- if(isset($details["d".$i]) && $i != 1) {
- $j2["d".$i] = $details["d".$i];
- }
- }
- if(isset($details['dO']))
- $j2["dO"] = $details["dO"];
- if(isset($details['dx']))
- $j2["dx"] = $details["dx"];
- if(isset($details['dt']))
- $j2["dt"] = $details["dt"];
- $j2["N"] = $details["N"];
- $j2["n"] = $details["n"];
- $j2["a"] = '';
- $j2["h"] = '';
- $j2["a"] = "";
- $j2["h"] = "";
- $j2["v"] = 2;
- return $j2;
- }
- public function Load($ver = True, $variavel = True)
- {
- $x = "";
- try
- {
- $x = rtrim(socket_read($this->socket, 2048));
- $x = str_replace("", "", $x);
- }
- catch(Exception $e)
- {
- return "OFF";
- }
- if (!$x) return "OFF";
- if ($x[strlen($x) - 1] != ">") $x .= $this->Load(True);
- if ($ver) $this->packets($x, $variavel);
- return $x;
- }
- public function packets($packet, $debug = True, $debug1 = False)
- {
- if (substr_count($packet, ">") > 1)
- {
- $packet = explode("/>", $packet);
- $debug1 = True;
- }
- foreach ((Array)$packet as $p)
- {
- if ($debug1) $p .= "/>";
- $p = trim($p);
- if (strlen($p) < 5) return;
- echo "[MAIN-PACKET]-> {$p}\n";
- $TypePacket = trim(strtolower(substr($p, 1, strpos($p . " ", " "))));
- $p = trim(str_replace("<" . $TypePacket, "", str_replace("/>", "", $p)));
- $p = str_replace("\"", "", str_replace("\" ", "&", str_replace("&", "__38", $p)));
- parse_str($p, $this->packet[$TypePacket]);
- foreach ($this->packet[$TypePacket] as $x => $v) $this->packet[$TypePacket][$x] = str_replace("__38", "&", str_replace("pl_", "+", $v));
- if ($debug) $this->Haddle($TypePacket, $this->packet[$TypePacket]);
- }
- }
- public function Haddle($tipo, $packet)
- {
- switch ($tipo)
- {
- case "u":
- $uid = $this->parseU($packet['u']);
- $u = $this->fetchUser($packet['u']);
- $this->users[$this->parseU($packet['u'])] = $packet;
- $this->users[$packet['u']]['cb'] = @$packet['cb'];
- $this->users[$packet['u']]['s'] = @$packet['s'];
- $this->users[$packet['u']]['f'] = (isset($packet['f'])) ? (int) $packet['f'] : 0;
- $this->users[$packet['u']]['id'] = $packet['u'];
- $this->users[$packet['u']]['d0'] = (isset($packet['d0'])) ? (int) $packet['d0'] : 0;
- $this->users[$packet['u']]['d2'] = (isset($packet['d2'])) ? @$packet['d2'] : 0;
- $this->users[$packet['u']]['q'] = (isset($packet['q'])) ? (int) $packet['q'] : 0;
- $this->users[$packet['u']]['registered'] = ((key_exists('N', $packet)) ? $packet['N'] : 'Unregistered');
- $this->users[$packet['u']]['name'] = @$packet['n'];
- $this->users[$packet['u']]['avatar'] = (isset($packet['a'])) ? @$packet['a'] : 'No Avatar';
- $this->users[$packet['u']]['home'] = (isset($packet['h'])) ? @$packet['h'] : 'No Homepage';
- $this->users[$packet['u']]['v'] = (@$packet['v']) ? @$packet['v'] : 0;
- $this->users[$packet['u']]['bride'] = (isset($packet['d2'])) ? @$packet['d2'] : 0;
- $this->users[$packet['u']]['rel'] = (@$packet['d0'] & 1) ? 1 : 2;
- $this->users[$packet['u']]['dx'] = $packet['xats'];
- $this->users[$packet['u']]['sub'] = (isset($packet['p0'])) ? 1 : 0;
- $user = ( $packet['N']) ? $packet['N'] : $packet['u'];
- $userid = $packet['i'];
- $this->member($packet['u']);
- $this->sendPrivateMessage("Bem Vindos", $packet["u"]);
- break;
- case "z":
- $this->sendPrivateMessage("....", $packet["u"]);
- break;
- case "m":
- case "p":
- if (isset($packet["i"]) && $packet["i"] > 0)
- {
- break;
- }
- $msg = $message = explode(" ", $packet["t"]);
- unset($msg[0]);
- $msg = implode(" ", $msg);
- if (isset($message[0]) && $message[0][0] != "@")
- {
- break;
- }
- switch (substr($message[0], 1))
- {
- case "say":
- $this->sendAllChat($msg);
- break;
- case "info":
- $this->sendPrivateMessage("Guest Bot", $packet["u"]);
- break;
- }
- }
- }
- function member($id, $time = null) {
- if (!$time)
- $time = 0;
- $id = $this->parseU($id);
- $this->sendC($id, '/e', $time);
- }
- function sendwelcome($message, $id, $f, $nome) {
- if (!$message) {
- return false;
- }
- $this->sendmsg($message, 'PM', $id);
- }
- public function sendC($id = 0, $com = '') {
- $this->sendPacket('<c u="' . $id . '" t="' . $com . '" />');
- }
- function sendmsg($message, $type = "MSG", $id = 0) {
- if (!$message) {
- return false;
- }
- switch ($type) {
- case "MSG":
- $this->sendPacket("<m t=\"{$message}\" u=\"{$this->botID}\" />");
- break;
- case "PM":
- $this->sendPacket("<p u=\"{$id}\" t=\"{$message}\" d=\"{$id}\" />");
- break;
- case "PC":
- $this->sendPacket("<p u=\"{$id}\" t=\"{$message}\" d=\"{$id}\" s=\"2\" />");
- break;
- }
- }
- public function fetchUser($id) {
- $id = $this->parseU($id);
- if (isset($this->users[$id]))
- return $this->users[$id];
- else
- return false;
- }
- function parseU($id) {
- if (substr_count($id, '_') >= 1)
- $id = substr($id, 0, strpos($id, '_'));
- return $id;
- }
- public function reiniciar()
- {
- $this->SocketConnect();
- $this->EnterRoom();
- }
- function sendPrivateChat($string, $userid)
- {
- $this->sendPacket("<z u=\"{$this->botID}\" t=\"{$string}\" s=\"2\" d=\"{$userid}\" />");
- }
- function sendPrivateMessage($string, $userid)
- {
- $this->sendPacket("<p u=\"{$userid}\" t=\"{$string}\" />");
- }
- function sendAllChat($string)
- {
- $this->sendPacket("<m u=\"{$this->botID}\" t=\"{$string}\" />");
- }
- }
- $BasicBot = new BasicBot();
- while(1)
- {
- if ($BasicBot->Load() == "OFF")
- {
- $BasicBot->SocketDesconnect();
- $BasicBot->EnterRoom();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement