Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <?php
  2. set_time_limit(0);
  3. error_reporting(E_ALL);
  4. date_default_timezone_set(@date_default_timezone_get());
  5.  
  6. new bot();
  7.  
  8. class bot
  9. {
  10. public $username = "Lockie9998"; // Username here
  11. public $password = ""; // Password here
  12.  
  13. public $name = "Bot";
  14. public $icon = 42;
  15. public $link = "google.com";
  16. public $room = "NacroBots";
  17. public $char = "!";
  18. public $sock = null; /* DON'T TOUCH THIS IF YOU'RE A SKID. THX. */
  19.  
  20. public function __construct()
  21. {
  22. $this->login();
  23. $this->join();
  24. while(true)
  25. {
  26. $packet_glob = explode(chr(0), $this->read());
  27. foreach($packet_glob as $xml)
  28. {
  29. $xml = $this->xmlArray($xml);
  30. if(!$xml || empty($xml)) continue;
  31. switch($xml[chr(0)])
  32. {
  33. case "m":
  34. if(isset($xml["s"])) break;
  35.  
  36. if(substr($xml["t"], 0, 1) == $this->char)
  37. {
  38. $args = explode(" ", $xml["t"], 2);
  39. switch(substr($args[0], 1))
  40. {
  41. case "say":
  42. $this->sendMessage($args[1]);
  43. break;
  44. }
  45. }
  46. break;
  47. }
  48. }
  49. }
  50. }
  51.  
  52. public function sendMessage($txt)
  53. {
  54. $clean = htmlentities($txt);
  55. return $this->write("<m t=\"{$clean}\" u=\"{$this->xatID}\" />");
  56. }
  57.  
  58. public function getRoomID($name)
  59. {
  60. $load = file_get_contents("http://xat.com/web_gear/chat/roomid.php?d={$name}");
  61. return (integer) $load;
  62. }
  63.  
  64. public function connect($recon = false)
  65. {
  66. if($recon)
  67. {
  68. @socket_close($this->sock);
  69. $this->sock = null;
  70. }
  71. $servers = 'fwdelb02-53956973.us-east-1.elb.amazonaws.com' ;
  72. $port = 10000 + ($this->getRoomID($this->room % 32));
  73. $serv = $servers;
  74. print "Connecting to {$serv}:{$port} ...". PHP_EOL;
  75. $this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  76. socket_connect($this->sock, $serv, $port);
  77. return is_resource($this->sock);
  78. }
  79.  
  80. public function write($packet)
  81. {
  82. if(substr($packet, -1) != chr(0)) $packet .= chr(0);
  83. var_dump($packet);
  84. return socket_write($this->sock, $packet, strlen($packet));
  85. }
  86.  
  87. public function read()
  88. {
  89. $data = @socket_read($this->sock, 1204, PHP_BINARY_READ);
  90. if(strlen($data)) var_dump($data);
  91. return @trim($data);
  92. }
  93.  
  94. public function join($shake = true)
  95. {
  96. $this->connect();
  97. if($shake)
  98. {
  99. $this->write("<y r=\"{$this->getRoomID($this->room)}\" v=\"0\" u=\"{$this->xatID}\" />");
  100. $this->handshake = $this->xmlArray($this->read());
  101. }
  102.  
  103. $packet = "<j2 ";
  104. $packet .= "cb=\"{$this->handshake["c"]}\" ";
  105. $packet .= "y=\"{$this->handshake["i"]}\" ";
  106. $packet .= "q=\"1\" ";
  107. $packet .= "k=\"{$this->loginArray["k1"]}\" ";
  108. $packet .= "k3=\"{$this->loginArray["k3"]}\" ";
  109. $packet .= "p=\"0\" ";
  110.  
  111. if(isset($this->loginArray["d2"]))
  112. {
  113. $packet .= "d2=\"{$this->loginArray["d2"]}\" ";
  114. }
  115.  
  116. $packet .= "c=\"{$this->getRoomID($this->room)}\" ";
  117. $packet .= "r=\"\" ";
  118. $packet .= "f=\"0\" ";
  119. $packet .= "e=\"\" ";
  120. $packet .= "u=\"{$this->xatID}\" ";
  121.  
  122. for($i = 0; $i < 25; $i++)
  123. {
  124. $d_index = "d".$i;
  125. if(isset($this->loginArray[$d_index]))
  126. {
  127. $packet .= $d_index ."=\"{$this->loginArray[$d_index]}\" ";
  128. }
  129. }
  130.  
  131. $pvars = array("dO", "dx", "dt");
  132. foreach($pvars as $pv)
  133. {
  134. if(isset($this->loginArray[$pv]))
  135. {
  136. $packet .= $pv ."=\"{$this->loginArray[$pv]}\" ";
  137. }
  138. }
  139.  
  140. $packet .= "N=\"{$this->username}\" ";
  141. $packet .= "n=\"{$this->name}\" ";
  142. $packet .= "a=\"{$this->icon}\" ";
  143. $packet .= "h=\"{$this->link}\" ";
  144. $packet .= "v=\"0\" ";
  145. $packet .= "/>";
  146. return $this->write($packet);
  147. }
  148.  
  149. public function xmlArray($xs)
  150. {
  151. $xss = @simplexml_load_string(trim($xs));
  152. $rss = array();
  153.  
  154. if(!method_exists($xss, "getName")) return $rss;
  155.  
  156. $rss[chr(0)] = $xss->getName();
  157.  
  158. foreach($xss->attributes() as $x => $y) $rss[@(string) $x] = @(string) $y;
  159.  
  160. return $rss;
  161. }
  162.  
  163. public function login()
  164. {
  165. $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  166. socket_connect($sock, "fwdelb02-53956973.us-east-1.elb.amazonaws.com", 10000);
  167. socket_write($sock, "<y r=\"8\" />\0");
  168. socket_read($sock, 1204);
  169.  
  170. $user = $this->username;
  171. $pass = "$". crc32($this->password);
  172.  
  173. socket_write($sock, "<v r=\"8\" p=\"{$pass}\" n=\"{$user}\" />\0");
  174. $this->loginArray = $this->xmlArray(socket_read($sock, 1204));
  175.  
  176. if(isset($this->loginArray["e"])) exit("Login error. [{$this->loginArray["e"]}]");
  177.  
  178. $this->xatID = (integer) $this->loginArray["i"];
  179. socket_close($sock);
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement