Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- error_reporting(E_ALL);
- date_default_timezone_set(@date_default_timezone_get());
- new bot();
- class bot
- {
- public $username = "Lockie9998"; // Username here
- public $password = ""; // Password here
- public $name = "Bot";
- public $icon = 42;
- public $link = "google.com";
- public $room = "NacroBots";
- public $char = "!";
- public $sock = null; /* DON'T TOUCH THIS IF YOU'RE A SKID. THX. */
- public function __construct()
- {
- $this->login();
- $this->join();
- while(true)
- {
- $packet_glob = explode(chr(0), $this->read());
- foreach($packet_glob as $xml)
- {
- $xml = $this->xmlArray($xml);
- if(!$xml || empty($xml)) continue;
- switch($xml[chr(0)])
- {
- case "m":
- if(isset($xml["s"])) break;
- if(substr($xml["t"], 0, 1) == $this->char)
- {
- $args = explode(" ", $xml["t"], 2);
- switch(substr($args[0], 1))
- {
- case "say":
- $this->sendMessage($args[1]);
- break;
- }
- }
- break;
- }
- }
- }
- }
- public function sendMessage($txt)
- {
- $clean = htmlentities($txt);
- return $this->write("<m t=\"{$clean}\" u=\"{$this->xatID}\" />");
- }
- public function getRoomID($name)
- {
- $load = file_get_contents("http://xat.com/web_gear/chat/roomid.php?d={$name}");
- return (integer) $load;
- }
- public function connect($recon = false)
- {
- if($recon)
- {
- @socket_close($this->sock);
- $this->sock = null;
- }
- $servers = 'fwdelb02-53956973.us-east-1.elb.amazonaws.com' ;
- $port = 10000 + ($this->getRoomID($this->room % 32));
- $serv = $servers;
- print "Connecting to {$serv}:{$port} ...". PHP_EOL;
- $this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- socket_connect($this->sock, $serv, $port);
- return is_resource($this->sock);
- }
- public function write($packet)
- {
- if(substr($packet, -1) != chr(0)) $packet .= chr(0);
- var_dump($packet);
- return socket_write($this->sock, $packet, strlen($packet));
- }
- public function read()
- {
- $data = @socket_read($this->sock, 1204, PHP_BINARY_READ);
- if(strlen($data)) var_dump($data);
- return @trim($data);
- }
- public function join($shake = true)
- {
- $this->connect();
- if($shake)
- {
- $this->write("<y r=\"{$this->getRoomID($this->room)}\" v=\"0\" u=\"{$this->xatID}\" />");
- $this->handshake = $this->xmlArray($this->read());
- }
- $packet = "<j2 ";
- $packet .= "cb=\"{$this->handshake["c"]}\" ";
- $packet .= "y=\"{$this->handshake["i"]}\" ";
- $packet .= "q=\"1\" ";
- $packet .= "k=\"{$this->loginArray["k1"]}\" ";
- $packet .= "k3=\"{$this->loginArray["k3"]}\" ";
- $packet .= "p=\"0\" ";
- if(isset($this->loginArray["d2"]))
- {
- $packet .= "d2=\"{$this->loginArray["d2"]}\" ";
- }
- $packet .= "c=\"{$this->getRoomID($this->room)}\" ";
- $packet .= "r=\"\" ";
- $packet .= "f=\"0\" ";
- $packet .= "e=\"\" ";
- $packet .= "u=\"{$this->xatID}\" ";
- for($i = 0; $i < 25; $i++)
- {
- $d_index = "d".$i;
- if(isset($this->loginArray[$d_index]))
- {
- $packet .= $d_index ."=\"{$this->loginArray[$d_index]}\" ";
- }
- }
- $pvars = array("dO", "dx", "dt");
- foreach($pvars as $pv)
- {
- if(isset($this->loginArray[$pv]))
- {
- $packet .= $pv ."=\"{$this->loginArray[$pv]}\" ";
- }
- }
- $packet .= "N=\"{$this->username}\" ";
- $packet .= "n=\"{$this->name}\" ";
- $packet .= "a=\"{$this->icon}\" ";
- $packet .= "h=\"{$this->link}\" ";
- $packet .= "v=\"0\" ";
- $packet .= "/>";
- return $this->write($packet);
- }
- public function xmlArray($xs)
- {
- $xss = @simplexml_load_string(trim($xs));
- $rss = array();
- if(!method_exists($xss, "getName")) return $rss;
- $rss[chr(0)] = $xss->getName();
- foreach($xss->attributes() as $x => $y) $rss[@(string) $x] = @(string) $y;
- return $rss;
- }
- public function login()
- {
- $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- socket_connect($sock, "fwdelb02-53956973.us-east-1.elb.amazonaws.com", 10000);
- socket_write($sock, "<y r=\"8\" />\0");
- socket_read($sock, 1204);
- $user = $this->username;
- $pass = "$". crc32($this->password);
- socket_write($sock, "<v r=\"8\" p=\"{$pass}\" n=\"{$user}\" />\0");
- $this->loginArray = $this->xmlArray(socket_read($sock, 1204));
- if(isset($this->loginArray["e"])) exit("Login error. [{$this->loginArray["e"]}]");
- $this->xatID = (integer) $this->loginArray["i"];
- socket_close($sock);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement