Guest User

Untitled

a guest
Feb 4th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 142.14 KB | None | 0 0
  1. <?php
  2.  
  3. set_time_limit(0);
  4. date_default_timezone_set("Australia/Melbourne");
  5. libxml_use_internal_errors(true);
  6. ini_set('display_errors', 'on');
  7. error_reporting(E_ALL);
  8.  
  9. do {
  10. $server = new MSERVER();
  11. unset($server);
  12. } while (true);
  13.  
  14. class MSERVER {
  15.  
  16. private $info = array();
  17. public $socket = array(null, null);
  18. public $users = array();
  19. public $ipbans = array();
  20. public $protected = array();
  21. public $rfilter = array();
  22. public $debug = false;
  23. public $hasGroupPowers = array("Lobby", "Help","DeviazMu");
  24.  
  25. public function __construct() {
  26. //require __DIR__ . "/../_class/config.php";
  27. $config = (object) array( 'db' => array( 0 => 'localhost', 1 => 'root', 2 => '', 3 => 'ixat' ) ); //Configuracao
  28. $this->mysql = new Database($config->db[0], $config->db[1], $config->db[2], $config->db[3]);
  29.  
  30. $this->resetConfig();
  31. $this->bind();
  32.  
  33. while (true) {
  34. $this->bind();
  35.  
  36. while ($this->socket[0]) {
  37. $this->listen();
  38. }
  39.  
  40. array_map('socket_close', $this->socket);
  41. }
  42. }
  43.  
  44. public function resetConfig() {
  45. $this->config = $this->mysql->fetch_array("select * from `server` limit 0, 1;");
  46. $this->config = (object) $this->config[0];
  47.  
  48. $this->config->spam_wait = 800;
  49. $this->config->staff = (array) json_decode($this->config->staff);
  50. $this->config->pawns = (array) json_decode($this->config->pawns);
  51.  
  52. $this->config->pcount = $this->mysql->fetch_array('select count(distinct `section`) as `count` from `powers`;');
  53. $this->config->pcount = $this->config->pcount[0]['count'];
  54.  
  55. $this->hash = $this->mysql->rand(25); /* For API Laterz */
  56. $this->ipbans = $this->mysql->fetch_array("select `ipbans` from `server`;");
  57. $this->ipbans = (array) json_decode($this->ipbans[0]['ipbans']);
  58. $this->mysql->query("update `server` set `pid`='" . getmypid() . "';");
  59. }
  60.  
  61. public function bind() {
  62. try {
  63. global $argv;
  64. $this->socket = array(
  65. socket_create(AF_INET, SOCK_STREAM, SOL_TCP),
  66. socket_create_listen(0)
  67. );
  68.  
  69. socket_getsockname(end($this->socket), $ip, $port);
  70. $this->mysql->query("update `server` set `ipc`={$port};");
  71. socket_set_option($this->socket[0], SOL_SOCKET, SO_REUSEADDR, true);
  72.  
  73. if (!isset($argv[1]) || $argv[1] != 'debug') {
  74. socket_bind($this->socket[0], $this->config->server_ip, $this->config->server_pt) or exit('line:' . __LINE__);
  75. } else {
  76. $this->debug = true;
  77. print 'binding on debug port' . chr(10);
  78. socket_bind($this->socket[0], $this->config->server_ip, $this->config->backup_pt) or exit('line:' . __LINE__);
  79. }
  80.  
  81. socket_listen($this->socket[0]);
  82. socket_set_block($this->socket[0]);
  83. } catch (Exception $e) {
  84. print $e->getMessage();
  85. exit('line:' . __LINE__);
  86. }
  87. }
  88.  
  89. public function listen($null = null, $ipc = 0) {
  90. /* Create Read Array */
  91. $read = $this->socket;
  92. foreach ($this->users as $user) {
  93. $read[] = $user->sock;
  94. }
  95. $except = $read;
  96. /* Accept / Filter New Connections */
  97. if (@socket_select($read, $null, $except, null) < 1) {
  98. continue;
  99. }
  100.  
  101. foreach ($this->socket as $i => $psock) {
  102. if (in_array($psock, $read)) {
  103. switch ((int) $i) {
  104. case 0:
  105. $socket = socket_accept($psock);
  106. socket_set_nonblock($socket);
  107.  
  108. if (!is_resource($socket) || count($this->users) >= $this->config->max_total) {
  109. @socket_close($socket);
  110. break;
  111. }
  112.  
  113. socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 3, 'usec' => 0));
  114.  
  115. @socket_getpeername($socket, $ip);
  116. foreach ($this->users as $user) {
  117. if ($user->ipaddr == $ip) {
  118. $ipc++;
  119. }
  120. }
  121.  
  122. if ($ipc > $this->config->max_per_ip || in_array($ip, $this->ipbans)) {
  123. foreach ($this->users as $user) {
  124. if ($user->ipaddr == $ip) {
  125. $this->disconnect($user->index);
  126. }
  127. }
  128. break;
  129. }
  130.  
  131. do {
  132. $index = $this->mysql->rand();
  133. } while (isset($this->users[$index]));
  134.  
  135. $this->users[$index] = new client($socket, $this, $index, $ip);
  136. break;
  137.  
  138. case 1:
  139. $this->socket[] = socket_accept($psock);
  140. break;
  141.  
  142. default: /* For API if I feel like making it later */
  143. $data = trim(socket_read($psock, 1205));
  144.  
  145. if (strlen($data) <= 1) {
  146. socket_close($psock);
  147. unset($this->socket[$i]);
  148. break;
  149. }
  150.  
  151. $packet = simplexml_load_string($data);
  152. $data = $this->GetMultiAttr($packet);
  153.  
  154. if (!method_exists($packet, 'getName')) {
  155. break;
  156. }
  157.  
  158. switch ($packet->getName()) {
  159. case 'usercount':
  160. socket_write($psock, count($this->users));
  161. break;
  162. case 'globalMessage':
  163. foreach ($this->users as $i => $user) {
  164. if ($user->online == true) {
  165. $user->sendPacket('<fuckoff/>');
  166. }
  167. }
  168. break;
  169. }
  170. break;
  171. }
  172. }
  173. }
  174. /* Read From Waiting Sockets, kill exceptions */
  175. if (!is_array($except)) {
  176. $except = array(); /* To avoid a possibility of an error below */
  177. }
  178.  
  179. foreach ($this->users as $index => $user) {
  180. if (in_array($user->sock, $except) || !$user->sock) {
  181. unset($this->users[$index]);
  182. } elseif (in_array($user->sock, $read)) {
  183. $input = @socket_read($user->sock, 1205);
  184. if (trim($input) == '' || ord(substr($input, 0, 1)) == 136) {
  185. unset($this->users[$index]);
  186. continue;
  187. } elseif (substr_count($input, chr(0)) <= 1) {
  188. $this->handle($input, $user);
  189. }
  190. }
  191. }
  192. }
  193.  
  194. private function handle($packet, &$user) {
  195. $packet = str_replace('', '', $packet); //RIP Chrome
  196.  
  197. try {
  198. if ($this->debug) {
  199. var_dump($packet);
  200. }
  201.  
  202.  
  203. if ($user->mobile == false && substr($packet, 0, 1) !== '<') {
  204. $user->mobile = true;
  205. }
  206.  
  207. if (substr($packet, 0, 2) == '<x') {
  208. $user->sendRoom($packet);
  209. }
  210.  
  211. if ($user->mobile == true) {
  212. if ($user->mobready == false) {
  213. $user->buffer .= $packet;
  214. if (strlen($user->buffer) >= 2048) {
  215. throw new Exception();
  216. }
  217.  
  218. if (is_numeric(strpos($user->buffer, "\r\n\r\n"))) {
  219. $headers = array();
  220. $lines = explode("\r\n", $user->buffer);
  221. foreach ($lines as $line) {
  222. $line = explode(': ', $line, 2);
  223. if (count($line) < 2)
  224. continue;
  225. $headers[strtolower($line[0])] = $line[1];
  226. }
  227.  
  228. if (!isset($headers['sec-websocket-key'])) {
  229. throw new Exception();
  230. }
  231.  
  232. $secAccept = base64_encode(pack('H*', sha1($headers['sec-websocket-key'] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
  233. $response = array();
  234. array_push($response, "HTTP/1.1 101 Pulse");
  235. array_push($response, "Upgrade: websocket");
  236. array_push($response, "Connection: Upgrade");
  237. array_push($response, "Sec-WebSocket-Accept: " . $secAccept);
  238. @socket_write($user->sock, implode("\r\n", $response) . "\r\n\r\n");
  239.  
  240. $user->mobready = true;
  241. }
  242.  
  243. return;
  244. } else {
  245. $packet = $this->unmask($packet);
  246. if ($packet == false) {
  247. throw new Exception(1);
  248. }
  249. }
  250. }
  251.  
  252. if (strpos($packet, '<', 1) !== false) {
  253. throw new Exception(2);
  254. }
  255. $packet2 = $packet;
  256. $packet = simplexml_load_string(trim($packet));
  257.  
  258. if (!method_exists($packet, 'getName')) {
  259. libxml_clear_errors(true);
  260. throw new Exception(3);
  261. }
  262.  
  263. $tag = strtolower($packet->getName());
  264. $lPackets = array('policy-file-request', 'ls2', 'y', 'login');
  265.  
  266. if (strlen($tag) > 25 || $tag == '') {
  267. throw new Exception(4);
  268. }
  269.  
  270. if (!isset($user->loginKey) || $user->loginKey == null) {
  271. if (!in_array($tag, $lPackets)) {
  272. throw new Exception(5);
  273. }
  274. } elseif ($user->authenticated == null && $tag != 'ls2') {
  275. throw new Exception(6);
  276. } elseif (isset($user->id) && in_array($user->id, array(0, 2))) {
  277. throw new Exception(7);
  278. } elseif ($user->hidden == true && $user->online) {
  279. $user->hidden = false;
  280. $user->joinRoom($user->chat, false, true, $user->pool);
  281. };
  282. } catch (Exception $e) {
  283. //print $e->getMessage() . "\n";
  284. return $this->disconnect($user->index);
  285. }
  286.  
  287.  
  288. if (!$user->authenticated && !in_array($tag, $lPackets)) {
  289. return $this->disconnect($user->index, true);
  290. }
  291.  
  292. switch ($tag) {
  293. //For bots
  294. case 'login':
  295. //$key = $this->getAttribute($packet, 'key');//lol later
  296. $user2 = $this->getAttribute($packet, 'user');
  297. $password = $this->getAttribute($packet, 'pass');
  298. $userLogin = $this->mysql->fetch_array('select * from `users` where `username`=\'' . $this->mysql->sanatize($user2) . '\';');
  299. if (!$this->mysql->validate($password, $userLogin[0]['password']) || empty($userLogin)) {
  300. $user->sendPacket('<login t="Bad Username/Password." e="1" />');
  301. } else {
  302. $loginKey = md5(json_encode(array(time(), $userLogin[0]['username'], $userLogin[0]['password'])));
  303. $this->mysql->query('update `users` set `loginKey`=\'' . $loginKey . '\' where `username`=\'' . $this->mysql->sanatize($userLogin[0]['username']) . '\';');
  304.  
  305. if ((floor(($userLogin[0]['days'] - time()) / (24 * 3600) + 0.3) >= 1 ? floor(($userLogin[0]['days'] - time()) / (24 * 3600) + 0.3) : 0) >= 1)
  306. {
  307. $upowers = $this->mysql->fetch_array("select * from `userpowers` where `userid`={$userLogin[0]['id']};");
  308. $spowers = $this->mysql->fetch_array("select * from `powers` where `name` not like '%(Undefined)%';");
  309. list($vals, $p, $dO, $powerO, $pp) = array(array(), array(), '', '', '');
  310. foreach ($spowers as $i => $u)
  311. {
  312. $vals[$u["id"]] = array($u["section"], $u["subid"]);
  313. if (!isset($p[$u["section"]]))
  314. {
  315. $p[$u["section"]] = 0;
  316. }
  317. }
  318.  
  319. foreach ($upowers as $i => $u)
  320. {
  321. if ($u["count"] >= 1 && isset($vals[$u["powerid"]]) && isset($p[$vals[$u["powerid"]][0]]))
  322. {
  323. $str = $u['powerid'] . '=' . ($u['count'] > 1 ? ($u['count'] - 1) : 1) . '|';
  324. $dO .= $str;
  325.  
  326. if ($u['count'] > 1)
  327. {
  328. $powerO .= $str;
  329. }
  330.  
  331. $p[$vals[$u["powerid"]][0]] += $vals[$u["powerid"]][1];
  332. }
  333. }
  334. }
  335.  
  336. $nickname = explode('##', $userLogin[0]['nickname'], 2);
  337. if (count($nickname) != 2) {
  338. $nickname[1] = "";
  339. }
  340. $vars = "";
  341. $vars .= 'userno="' . $userLogin[0]["id"] . '" ';
  342. $vars .= 'avatar="' . $userLogin[0]["avatar"] . '" ';
  343. $vars .= 'k1="' . $userLogin[0]["k"] . '" ';
  344. $vars .= 'd0="' . $userLogin[0]["d0"] . '" ';
  345. $vars .= 'd1="' . $userLogin[0]["days"] . '" ';
  346. $vars .= 'd2="' . $userLogin[0]["d2"] . '" ';
  347. $vars .= 'd3="" ';
  348.  
  349. foreach ($p as $i => $u)
  350. $vars .= 'd' . (substr($i, 1) + 4) . '="' . $u . '" ';
  351.  
  352. $vars .= 'dt=0" ';
  353. $vars .= 'homepage="' . $userLogin[0]["url"] . '" ';
  354. $vars .= 'Powers="' . implode(",", $p) . '" ';
  355. $vars .= 'PowerO="' . $powerO . '" ';
  356. $vars .= 'status="' . $nickname[1] . '" ';
  357. $vars .= 'dO="'.$dO.'" ';
  358. $vars .= 'dx="' . $userLogin[0]["xats"] . '" ';
  359. $vars .= 'registered="' . $userLogin[0]["username"] . '" ';
  360. $vars .= 'k2="' . $userLogin[0]["k2"] . '" ';
  361. $vars .= 'k3="' . $userLogin[0]["k3"] . '" ';
  362. $vars .= 'name="' . $nickname[0] . '" ';
  363. $vars .= 'loginKey="' . $loginKey . '"';
  364. $user->sendPacket('<v ' . $vars . ' e="0" />');
  365. }
  366. break;
  367.  
  368. case substr($tag, 0, 1) == 'w': /* Pools, leave it here nigga, maybe later just use joinRoom() for faster change :] */
  369. $pool = substr($tag, 1, 2);
  370. $user->sendRoom("<l u=\"{$user->id}\" />");
  371. $user->switchingPools = true;
  372. $user->joinRoom($user->chat, true, true, $pool);
  373. break;
  374.  
  375.  
  376.  
  377. case 'f':
  378. $users = $this->getAttribute($packet, 'o');
  379. if ($users === false || $this->spamfilter($tag, $user, 200)) {
  380. $this->disconnect($user->index);
  381. } else {
  382. $friends = (array) explode(' ', $users);
  383. $online = array();
  384. foreach ($this->users as $i => $_user) {
  385. if ($_user->id != $user->id && in_array($_user->id, $friends) && $_user->hidden === false && !in_array($_user->id, $online)) {
  386. array_push($online, $_user->id);
  387. }
  388. }
  389. $user->sendPacket('<f v="' . implode(',', $online) . '" />');
  390. }
  391. break;
  392.  
  393. case 'policy-file-request':
  394. if (isset($user->policy)) {
  395. return $this->ipban($user->ipaddr);
  396. }
  397.  
  398. $user->sendPacket('<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>');
  399. $user->policy = 1;
  400. break;
  401.  
  402. case 'y':
  403. if (isset($user->loginKey) && $user->loginKey != null) {
  404. return $this->ipban($user->ipaddr);
  405. }
  406.  
  407. $user->loginKey = rand(10000000, 99999999);
  408. $user->loginShift = rand(2, 5);
  409. $user->loginTime = time();
  410.  
  411. $user->sendPacket('<y yi="' . $user->loginKey . '" yc="' . $user->loginTime . '" ys="' . $user->loginShift . '" />');
  412. break;
  413.  
  414. case 'ls2':
  415.  
  416. if ($user->authenticated == true) {
  417. $user->sendPacket('<logout />');
  418. return $this->disconnect($user->index);
  419. }
  420.  
  421. if ($user->authenticate($packet) == false) {
  422. $user->sendPacket('<n t="Voce deve registrar/fazer login!." />');
  423. $user->sendPacket('<logout />');
  424. $this->disconnect($user->index);
  425. }
  426.  
  427.  
  428.  
  429. break;
  430.  
  431. case 'l':
  432. $this->disconnect($user->index);
  433. break;
  434.  
  435.  
  436. case 'm':
  437. if ($user->banned > time()) {
  438. return false;
  439. }
  440.  
  441. if (isset($this->protected[$user->chat])) {
  442. if ($this->protected[$user->chat]['end'] < time()) {
  443. unset($this->protected[$user->chat]);
  444. $user->sendRoom("<m t=\"A protecao do chat foi desativa
  445. pois ja se passarao 60 minutos.\" u=\"0\" />");
  446. } elseif ($this->protected[$user->chat]['type'] == 'noguest') {
  447. if ($user->rank == 5 || $user->rank == 40) {
  448. return false;
  449. }
  450. } elseif ($this->protected[$user->chat]['type'] == 'unreg') {
  451. if ($user->guest == true && in_array($user->rank, array(5, 40))) {
  452. return false;
  453. }
  454. }
  455. }
  456.  
  457. if (in_array($user->rank, array(5, 40)) && $user->guest == true) {
  458. if (!isset($this->rfilter[$user->chat])) {
  459. $this->rfilter[$user->chat] = array();
  460. }
  461.  
  462. $ctime = time() - 5;
  463. $count = 1;
  464. foreach ($this->rfilter[$user->chat] as $i => $time) {
  465. if ($ctime > $time) {
  466. unset($this->rfilter[$user->chat][$i]);
  467. continue;
  468. }
  469.  
  470. $count++;
  471. }
  472.  
  473. array_push($this->rfilter[$user->chat], time());
  474. if ($count >= 12) {
  475. $this->protected[$user->chat] = array('end' => time() + 3600, 'type' => 'unreg');
  476. $user->sendRoom("<m u=\"0\" t=\"Protecao do chat foi ativada!(Raid Detected)\" />");
  477. foreach ($this->users as $i => $u) {
  478. if ($u->chat == $user->chat && in_array($u->rank, array(5, 40)) && $u->guest == true) {
  479. $u->sendPacket('<n t="Protection ativada, chutando null users." />');
  480. $this->disconnect($u->index);
  481. }
  482. }
  483.  
  484. unset($this->rfilter[$user->chat]);
  485. }
  486. }
  487.  
  488. $message = $this->getAttribute($packet, 't');
  489.  
  490. if (empty($message)) {
  491. return false;
  492. } elseif (substr($message, 0, 1) == '!') { // COMANDO <-- That's there so I can ctrl+f to here quickly <:
  493. $owner = in_array($user->id, $this->config->staff) ? true : false;
  494.  
  495. $args = explode(' ', substr($message, 1));
  496. switch (strtolower($args[0])) {
  497.  
  498.  
  499. case 'resetconfig':
  500. if ($owner) {
  501. $this->resetConfig();
  502. $user->sendPacket('<m u="0" t="Configuration has been reloaded" />');
  503. }
  504. break;
  505.  
  506. case 'setrank':
  507. if (!$owner) {
  508. break;
  509. }
  510.  
  511. switch ($s) {
  512. case "mod":
  513. case "moderator":
  514. $return = 2;
  515. break;
  516.  
  517. case "guest":
  518. $return = 5;
  519. break;
  520.  
  521. case "member":
  522. $return = 3;
  523. break;
  524.  
  525. case "owner":
  526. $return = 4;
  527. break;
  528. }
  529. $this->mysql->query('delete from `ranks` where `chatid`=' . $user->chat . ' and `userid`=' . $user->id . ';');
  530. $this->mysql->query('insert into `ranks`(`userid`, `chatid`, `f`) values(' . $user->id . ', ' . $user->chat . ', ' . $return . ');');
  531. $this->disconnect($user->index);
  532. break;
  533.  
  534.  
  535. case 'setxats':
  536. if (count($args) != 3 || !$owner) {
  537. break;
  538. }
  539. $uRow = $this->mysql->fetch_array('select `id`, `username`, `password` from `users` where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  540. if (count($uRow) == 1 && is_numeric($args[2])) {
  541. $this->mysql->query('update `users` set `xats`=' . $args[2] . ' where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  542. $_user = $this->getuserbyid($uRow[0]['id'], $user->chat);
  543. if ($_user != false) {
  544. $_user->sendPacket($this->doLogin($uRow[0]['username'], $uRow[0]['password']));
  545. }
  546. }
  547. break;
  548.  
  549.  
  550. case 'setdays':
  551. if (count($args) != 3 || !$owner) { break; }
  552. $uRow = $this->mysql->fetch_array('select `id`, `username`, `password` from `users` where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  553. if (count($uRow) == 1 && is_numeric($args[2]))
  554. {
  555. $this->mysql->query('update `users` set `days`=' . strtotime("+ " . $args[2] . " days") . ' where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  556. $_user = $this->getuserbyid($uRow[0]['id'], $user->chat);
  557. if ($_user != false)
  558. {
  559. $_user->sendPacket($this->doLogin($uRow[0]['username'], $uRow[0]['password']));
  560. }
  561. }
  562. break;
  563.  
  564.  
  565.  
  566. case "clear":
  567. if($rank > 3) {$user->sendPacket('<n t="You don\'t have a high enough rank!" />'); break;}
  568. $this->mysql->query("delete from `messages` where `id` = '{$user->chat}';");
  569.  
  570. $this->disconnect($user->index);
  571. $user->sendRoom("<l u=\"{$u->id}\" />");
  572. break;
  573.  
  574. case 'roulette':
  575. $num = floor(36 * (rand(0, 36) * rand(0, 36)));
  576. $user->sendAll("<n t=\"$num IS Your Number!\" />");
  577. return;
  578.  
  579. case 'release':
  580. if (!$owner) {
  581. break;
  582. }
  583. $power = $args[1];
  584. $amount = $args[2];
  585. $this->mysql->query("UPDATE `powers` SET `amount`='" . $amount . "' WHERE `name`='" . $power . "'");
  586. $Mais = $amount == 1 ? "" : "s";
  587. $user->sendAll("<n t=\"{$amount} {$power}{$Mais} Foi Liberado!\" />");
  588. return;
  589. break;
  590.  
  591. case 'unrelease':
  592. if (!$owner) {
  593. break;
  594. }
  595. $power = $args[1];
  596. $amount = $args[2];
  597. $this->mysql->query("UPDATE `powers` SET `amount`='" . $amount . "' WHERE `name`='" . $power . "'");
  598. $Mais = $amount == 0 ? "" : "s";
  599. $user->sendAll("<n t=\"{$amount} {$power}{$Mais} foi travado!\" />");
  600. return;
  601. break;
  602.  
  603. case "zua":
  604. if (!$owner) {
  605. break;
  606. }
  607. $args = explode(' ', substr($message, 1), 2);
  608. $args2 = explode(' ', substr($message, 2), 2);
  609. $sum = "<m t=\"{$args[1]}\" u=\"{$args2[2]}\" />";
  610. $user->sendAll($sum);
  611. return;
  612. break;
  613.  
  614. case "global":
  615. if (!$owner) {
  616. break;
  617. }
  618. $args = explode(' ', substr($message, 1), 2);
  619. $sum = "<n t=\"{$args[1]}\" />";
  620. $user->sendAll($sum);
  621. return;
  622. break;
  623.  
  624. case 'relog':
  625. if (count($args) == 2 && $owner) {
  626. $_user = $this->mysql->fetch_array('select * from `users` where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  627. if (empty($_user)) {
  628. break;
  629. }
  630. $online = $this->getuserbyid($_user[0]['id']);
  631. if (is_object($online)) {
  632. $online->sendPacket($this->doLogin($_user[0]['username'], $_user[0]['password']));
  633. }
  634. return;
  635. }
  636.  
  637. break;
  638.  
  639. case 'limited':
  640. if (!$owner) {
  641. break;
  642. }
  643. $power = $args[1];
  644. $this->mysql->query("UPDATE `powers` SET `limited`='1' WHERE `name`='" . $power . "'");
  645. $user->sendRoom('<n t="0" t="o power [' . $power . '] agora e limitado!" i="0" />');
  646. break;
  647. case 'unlimited':
  648. if (!$owner) {
  649. break;
  650. }
  651. $power = $args[1];
  652. $this->mysql->query("UPDATE `powers` SET `limited`='0' WHERE `name`='" . $power . "'");
  653. $user->sendRoom('<n t="0" t="o power [' . $power . '] agora nao e mais limitado!" i="0" />');
  654. break;
  655.  
  656. case 'every':
  657. case 'nopowers':
  658. if (count($args) != 2 || !$owner) {
  659. break;
  660. }
  661. $uRow = $this->mysql->fetch_array('select * from `users` where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  662. if (count($uRow) == 1) {
  663. $this->mysql->query('delete from `userpowers` where `userid`=' . $uRow[0]['id'] . ';');
  664. if (strtolower($args[0]) == 'every') {
  665. $powers = $this->mysql->fetch_array('select `id`, `name` from `powers` where `name` not like \'%(Undefined)%\' and `subid`<2147483647;');
  666. $inputs = '';
  667. foreach ($powers as $power) {
  668. if (!is_numeric($power['name'])) {
  669. $inputs .= '(' . $uRow[0]['id'] . ', ' . $power['id'] . ', 1),';
  670. }
  671. }
  672. $this->mysql->query('insert into `userpowers` (`userid`, `powerid`, `count`) values ' . substr($inputs, 0, -1) . ';');
  673. }
  674.  
  675. $_user = $this->getuserbyid($uRow[0]['id'], $user->chat);
  676. if ($_user != false) {
  677. $_user->sendPacket($this->doLogin($uRow[0]['username'], $uRow[0]['password']));
  678. }
  679. }
  680. break;
  681. case 'gback':
  682. if (!$owner) {
  683. break;
  684. }
  685. $arg1 = $args[1];
  686. $this->mysql->query("UPDATE `chats` SET `gback`='" . $arg1 . "' WHERE `id`='" . $user->chat . "'");
  687. $user->sendPacket('<m u="0" t="gback has been updated [' . $arg1 . ']" i="0" />');
  688. break;
  689. case 'addpower':
  690. case 'delpower':
  691. if (count($args) == 3 && $owner) { /* Just cause I felt like doing it this way this time */
  692. $_user = $this->mysql->fetch_array('select * from `users` where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  693. $power = $this->mysql->fetch_array('select * from `powers` where `name`=\'' . $this->mysql->sanatize($args[2]) . '\';');
  694. if (empty($_user) || empty($power)) {
  695. break;
  696. }
  697. $this->mysql->query('delete from `userpowers` where `userid`=' . $_user[0]['id'] . ' and `powerid`=' . $power[0]['id'] . ';');
  698. if (strtolower($args[0]) == 'addpower') {
  699. $this->mysql->query('insert into `userpowers`(`userid`, `powerid`, `count`) values(' . $_user[0]['id'] . ', ' . $power[0]['id'] . ', 1);');
  700. }
  701.  
  702. $online = $this->getuserbyid($_user[0]['id']);
  703. if (is_object($online)) {
  704. $online->sendPacket($this->doLogin($_user[0]['username'], $_user[0]['password']));
  705. }
  706. }
  707. break;
  708.  
  709.  
  710.  
  711.  
  712.  
  713. case 'subst':
  714. if(!$owner)
  715. {
  716. break;
  717. }
  718. $uRowPower = $this->mysql->fetch_array('select * from `powers` where `name`=\'' . $this->mysql->sanatize($args[2]) . '\';');
  719. $uRow = $this->mysql->fetch_array('select * from `users` where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  720. $curXats = $uRow[0]['xats'];
  721. $price = $uRowPower[0]['cost'];
  722. $total = $curXats - $price;
  723. $user->sendRoom("<n t=\"0\" t=\"O USUARIO ".$args[1]." TEM O TOTAL DE ".$curXats." XATS PARA COMPRAR O POWER ".$args[2].", FALTAM Somente ".$total." xats.\" />");
  724. break;
  725.  
  726. case 'setcost':
  727. if(!$owner)
  728. {
  729. break;
  730. }
  731. $power = $args[1];
  732. $this->mysql->query("UPDATE `powers` SET `cost`='".$args[2]."' WHERE `name`='".$power."'");
  733. $user->sendRoom('<n t="0" t="Power ['.$power.'] Foi mudado o preco para ['.$args[2].']" i="0" />');
  734. break;
  735.  
  736. case 'bot':
  737. if(!$owner)
  738. {
  739. exec("c:\windows\system32\cmd.exe /c C:\xampp\htdocs\bot.bat");
  740. }break;
  741.  
  742.  
  743.  
  744.  
  745. case 'reset': // Torching
  746. if(!$owner)
  747. {
  748. break;
  749. }
  750. $target = $args[1];
  751. $t = $this->mysql->fetch_array("SELECT * FROM `users` WHERE `username`='".$target."';");
  752. $i = $t[0]['id'];
  753. $ray = floor(floor($id)) * 100 / 2;
  754. $inf = base64_encode(serialize(base64_encode($ray)));
  755. $this->mysql->query("DELETE FROM `userpowers` WHERE `userid`='".$i."';");
  756. $this->mysql->query("DELETE FROM `ranks` WHERE `userid`='".$i."';");
  757. if($user->id == '1' OR '-1')
  758. {
  759. $this->mysql->query("INSERT INTO torches(id, torchedBy, reason, ray_id) VALUES ('".$i."', '".$user->username."', 'Torched by an Administrator for unlisted reasons.', '".$inf."');");
  760. } else {
  761. $this->mysql->query("INSERT INTO torches(id, torchedBy, reason, ray_id) VALUES ('".$i."', '".$user->username."', 'Reason Unlistd.', '".$inf."');");
  762. }
  763. $user->sendPacket('<n t="USUARIO '.$target.' FOI RESETADO." />');
  764. break;
  765.  
  766.  
  767.  
  768. case 'value':
  769. if(!$owner) {
  770. break;
  771. }
  772. $uRow = $this->mysql->fetch_array('select * from `users` where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  773. $user->sendRoom("<n t=\"0\" t=\" [".$args[1]."]: days-[".$uRow[0]['xats']."] days-[".$uRow[0]['days']."]\" />");
  774. break;
  775.  
  776. case 'setid':
  777. if (count($args) == 3 && is_numeric($args[2]) && $owner) {
  778. $_user = $this->mysql->fetch_array('select * from `users` where `username`=\'' . $this->mysql->sanatize($args[1]) . '\';');
  779. $_test = $this->mysql->fetch_array('select * from `users` where `id`=\'' . $this->mysql->sanatize($args[2]) . '\';');
  780.  
  781. if (!empty($_test)) {
  782. $user->sendPacket('<m t="Dude that ID is taken by ' . $_test[0]['username'] . '" u="0" />');
  783. break;
  784. }
  785.  
  786. if (empty($_user)) {
  787. $user->sendPacket('<m t="That username doesn\'t exist" u="0" />');
  788. break;
  789. }
  790.  
  791. $this->mysql->query('update `users` set `id`=' . $this->mysql->sanatize($args[2]) . ' where `id`=' . $_user[0]['id'] . ';');
  792. $this->mysql->query('update `ranks` set `userid`=' . $this->mysql->sanatize($args[2]) . ' where `userid`=' . $_user[0]['id'] . ';');
  793. $this->mysql->query('update `userpowers` set `userid`=' . $this->mysql->sanatize($args[2]) . ' where `userid`=' . $_user[0]['id'] . ';');
  794.  
  795. $online = $this->getuserbyid($_user[0]['id']);
  796. if (is_object($online)) {
  797. $online->sendPacket($this->doLogin($_user[0]['username'], $_user[0]['password']));
  798. }
  799. }
  800. break;
  801.  
  802.  
  803. case 'main':
  804. case 'delrank':
  805. if ($owner) {
  806. $this->mysql->query('delete from `ranks` where `chatid`=' . $user->chat . ' and `userid`=' . $user->id . ';');
  807. if (strtolower($args[0]) == 'main') {
  808.  
  809.  
  810. $this->mysql->query('insert into `ranks`(`userid`, `chatid`, `f`) values(' . $user->id . ', ' . $user->chat . ', 1);');
  811. }
  812. $this->disconnect($user->index);
  813. }
  814. break;
  815. }
  816.  
  817. } elseif (substr($message, 0, 1) == "/") {
  818. if ($message == '/away' && $user->hasPower(144)) {
  819. $user->f |= 0x4000;
  820. $user->joinRoom($user->chat, false, true, $user->pool);
  821. return;
  822. } elseif ($message == '/back') {
  823. if ($user->f & 0x4000 && $user->hasPower(144)) {
  824. $user->f -= 0x4000;
  825. $user->joinRoom($user->chat, false, true, $user->pool);
  826. }
  827.  
  828. return;
  829. } else {
  830. switch (strtolower(substr($message, 1, 1))) {
  831. case 'd':
  832. if (in_array($user->rank, array(1, 2, 4))) {
  833. $mid = substr($message, 2);
  834.  
  835. if (is_numeric($mid)) {
  836. $res = $this->mysql->query('update `messages` set `visible`=0 where `id`=' . $user->chat . ' and `mid`=' . $mid . ';');
  837. if ($res) {
  838. $user->sendRoom('<m t="/' . $mid . '" u="0" />');
  839. unset($user->last['m']);
  840. }
  841. } elseif ($mid == 'clear') {
  842. $res = $this->mysql->query('update `messages` set `visible`=0 where `id`=' . $user->chat . ';');
  843. }
  844. }
  845. return;
  846. case 'p':
  847. if ($user->rank == 1 || $user->rank == 4) {
  848. if (!isset($this->protected[$user->chat])) {
  849. $user->sendRoom("<m u=\"0\" t=\"Protecao ativada pelos proximos 60 minutos!({$user->id})\" />");
  850. $this->protected[$user->chat] = array("end" => (time() + 3600), "type" => 'noguest');
  851. return false;
  852. } else {
  853. unset($this->protected[$user->chat]);
  854. $user->sendRoom("<m u=\"0\" t=\"Protecao desativada!({$user->id})\" />");
  855. return false;
  856. }
  857. }
  858. break;
  859. case 's':
  860. if ($user->rank != 1) {
  861. return false;
  862. }
  863. $scroll = $this->mysql->sanatize(htmlspecialchars(substr($message, 2), ENT_QUOTES));
  864. $this->mysql->query("update `chats` set `sc` = '{$scroll}' where `name` = '{$user->group}';");
  865. $user->sendRoom("<m u=\"{$user->id}\" t=\"/s" . str_replace('"', '', htmlspecialchars_decode(stripslashes($scroll))) . "\" />");
  866. break;
  867. case 'g':
  868. if ($user->hasPower(32)) {
  869. $this->mysql->query('delete from `ranks` where `chatid`=' . $user->chat . ' and `userid`=' . $user->id . ';');
  870. $user->joinRoom($user->chat, 0, true);
  871. }
  872. break;
  873. default:
  874. $user->message($message);
  875. return false;
  876. }
  877. }
  878. }
  879.  
  880. if ($this->spamfilter($tag, $user, 700))
  881. break;
  882. $this->mysql->query("insert into `messages` (`id`, `uid`, `message`, `name`, `registered`, `avatar`, `time`, `pool`) values ('{$this->mysql->sanatize($user->chat)}', '{$this->mysql->sanatize($user->id)}', '{$this->mysql->sanatize($message)}', '{$this->mysql->sanatize($user->nickname)}', '{$this->mysql->sanatize($user->username)}', '{$this->mysql->sanatize($user->avatar)}', '" . time() . "', '{$this->mysql->sanatize($user->pool)}');");
  883. $user->message($message);
  884. $user->last = array();
  885. break;
  886.  
  887. case 'x':
  888. $attr = $this->getMultiAttr($packet, array('x', 's', 'b', 'm', 'p', 'k', 'f', 'i', 'u', 'd', 't'));
  889.  
  890. if($attr['i'] == '30008' && $attr['u'] && $attr['d'] && $attr['t'])
  891. {
  892. $tradee = $this->getUserByID($attr['d'], $user->chat);
  893.  
  894. if(is_object($tradee))
  895. { // [Client -> Server]: <x i="30008" u="1142540256" d="14200143" t="T,0;0;1=1|4=1|5=1|,0;0;,FFTJaooL4jQZK8L" />
  896. // T,myxats;mydays;mypowers,yourxats;yourdays;yourpowers,mypass
  897. if(substr($attr['t'], 0, 1) == 'T')
  898. {
  899. if(isset($tradee->trade[$user->id]))
  900. {
  901. $trade = explode(',', $attr['t']);
  902. if(count($trade) == 4)
  903. { // gotta do stuff here
  904. $tdata = explode(';', $trade[1]);
  905. $tusr2 = explode(';', $trade[2]);
  906.  
  907. if(count($tdata) == 3 && count($tusr2) == 3)
  908. {
  909. if(!is_numeric($tdata[0]) || !is_numeric($tdata[1]))
  910. {
  911. break;
  912. }
  913.  
  914. elseif(!$this->mysql->checkPass($trade[3], $user->password))
  915. {
  916. $user->sendPacket('<n t="Senha errada" />');
  917. $tradee->sendPacket('<n t="(' . $user->id . ') Senha errada" />');
  918. }
  919.  
  920. elseif($tdata[0] > $user->xats || $tdata[0] < 0)
  921. {
  922. $user->sendPacket('<n t="Voce nao tem xats" />');
  923. $tradee->sendPacket('<n t="(' . $user->id . ') Voce nao tem xats" />');
  924. }
  925.  
  926. elseif($tdata[1] > $user->days || $tdata[1] < 0)
  927. {
  928. $user->sendPacket('<n t="voce nao tem days" />');
  929. $tradee->sendPacket('<n t="(' . $user->id . ') voce nao tem days" />');
  930. }
  931.  
  932. else
  933. {
  934. if($tusr2 != $tradee->trade[$user->id][1] || $tdata != $tradee->trade[$user->id][2])
  935. {
  936. $user->sendPacket('<n t="Ocorreu um erro na Transferencia Tente novamente" />');
  937. $tradee->sendPacket('<n t="Ocorreu um erro na Transferencia Tente novamente" />');
  938. }
  939. else
  940. {
  941. $reset0 = $this->mysql->fetch_array('select `xats`, `days`, `password` from `users` where `id`=' . $user->id . ';');
  942. $reset1 = $this->mysql->fetch_array('select `xats`, `days`, `password` from `users` where `id`=' . $tradee->id . ';');
  943. $u1powers = $this->mysql->fetch_array('select * from `userpowers` where `userid`=' . $user->id);
  944. $u2powers = $this->mysql->fetch_array('select * from `userpowers` where `userid`=' . $tradee->id);
  945. $u1p = $u2p = $u1p0 = $u2p0 = array();
  946. $u1t = $u2t = array(array(), array());
  947. $user->xats = $reset0[0]['xats'];
  948. $tradee->xats = $reset1[0]['xats'];
  949. $user->days = floor(($reset0[0]['days'] - time()) / 86400);
  950. $tradee->days = floor(($reset1[0]['days'] - time()) / 86400);
  951.  
  952. foreach($u1powers as $i => $u) $u1p[$u['powerid']] = $u['count'];
  953. foreach($u2powers as $i => $u) $u2p[$u['powerid']] = $u['count'];
  954. $u1trade = explode('|', $tdata[2]);
  955. $u2trade = explode('|', $tradee->trade[$user->id][1][2]);
  956. $u1p0 = $u1p; $u2p0 = $u2p;
  957.  
  958. foreach($u1trade as $i => $u)
  959. {
  960. $power = explode('=', $u);
  961. if(count($power) == 2)
  962. {
  963. if(isset($u1p[$power[0]]) && $u1p[$power[0]] >= $power[1])
  964. {
  965. $u1p[$power[0]] = $u1p[$power[0]] - $power[1];
  966. $u2p[$power[0]] = isset($u2p[$power[0]]) ? ($u2p[$power[0]] + $power[1]) : $power[1];
  967. }
  968. else
  969. {
  970. $user->sendPacket('<n t="voce nao tem powers" />');
  971. $tradee->sendPacket('<n t="(' . $user->id . ') Voce nao tem powers" />');
  972. break;
  973. }
  974. }
  975. }
  976.  
  977. foreach($u2trade as $i => $u)
  978. {
  979. $power = explode('=', $u);
  980. if(count($power) == 2)
  981. {
  982. if(isset($u2p[$power[0]]) && $u2p[$power[0]] >= $power[1])
  983. {
  984. $u2p[$power[0]] = $u2p[$power[0]] - $power[1];
  985. $u1p[$power[0]] = isset($u1p[$power[0]]) ? ($u1p[$power[0]] + $power[1]) : $power[1];
  986. }
  987. else
  988. {
  989. $tradee->sendPacket('<n t="voce nao tem powers" />');
  990. $user->sendPacket('<n t="(' . $user->id . ') Voce nao tem powers" />');
  991. break;
  992. }
  993. }
  994. }
  995.  
  996. $user->xats += $tradee->trade[$user->id][1][0];
  997. $tradee->xats -= $tradee->trade[$user->id][1][0];
  998.  
  999. $user->xats -= $tdata[0];
  1000. $tradee->xats += $tdata[0];
  1001.  
  1002. $user->days -= $tdata[1];
  1003. $tradee->days += $tdata[1];
  1004.  
  1005. $tradee->days -= $tradee->trade[$user->id][1][1];
  1006. $user->days += $tradee->trade[$user->id][1][1];
  1007.  
  1008. $u1d = time() + ($user->days * 86400);
  1009. $u2d = time() + ($user->days * 86400);
  1010.  
  1011. $this->mysql->query('update `users` set `xats`=' . $user->xats . ', `days`=' . $u1d . ' where `id`=' . $user->id . ';');
  1012. $this->mysql->query('update `users` set `xats`=' . $tradee->xats . ', `days`=' . $u2d . ' where `id`=' . $tradee->id . ';');
  1013.  
  1014. foreach($u1p as $id => $count)
  1015. {
  1016. if($count < 1)
  1017. {
  1018. $this->mysql->query('delete from `userpowers` where `userid`=' . $user->id . ' and `powerid`=' . $id . ';');
  1019. }
  1020. elseif(isset($u1p0[$id]))
  1021. {
  1022. $this->mysql->query('update `userpowers` set `count`=' . $count . ' where `userid`=' . $user->id . ' and `powerid`=' . $id . ';');
  1023. }
  1024. else
  1025. {
  1026. $this->mysql->query('insert into `userpowers`(`userid`, `powerid`, `count`) values(' . $user->id . ', ' . $id . ', ' . $count . ');');
  1027. }
  1028. }
  1029.  
  1030. foreach($u2p as $id => $count)
  1031. {
  1032. if($count < 1)
  1033. {
  1034. $this->mysql->query('delete from `userpowers` where `userid`=' . $tradee->id . ' and `powerid`=' . $id . ';');
  1035. }
  1036. elseif(isset($u2p0[$id]))
  1037. {
  1038. $this->mysql->query('update `userpowers` set `count`=' . $count . ' where `userid`=' . $tradee->id . ' and `powerid`=' . $id . ';');
  1039. }
  1040. else
  1041. {
  1042. $this->mysql->query('insert into `userpowers`(`userid`, `powerid`, `count`) values(' . $tradee->id . ', ' . $id . ', ' . $count . ');');
  1043. }
  1044. }
  1045. }
  1046. $tradee->sendPacket('<n t="Trade Completado Com Sucesso" />');
  1047. $user->sendPacket('<n t="(' . $user->id . ') Trade Completado Com Sucesso" />');
  1048. $data1 = $this->doLogin($user->username, $user->password);
  1049. $data2 = $this->doLogin($tradee->username, $tradee->password);
  1050. $user->sendPacket($data1);
  1051. $tradee->sendPacket($data2);
  1052.  
  1053. }
  1054. }
  1055. }
  1056. }
  1057. else
  1058. {
  1059. $trade = explode(',', $attr['t']);
  1060. if(count($trade) == 4)
  1061. {
  1062. $tdata = explode(';', $trade[1]);
  1063. $tdu2 = explode(';', $trade[2]);
  1064. if(count($tdata) == 3 && count($tdu2) == 3)
  1065. {
  1066. if(!is_numeric($tdata[0]) || !is_numeric($tdata[1]))
  1067. {
  1068. break;
  1069. }
  1070.  
  1071. elseif(!$this->mysql->checkPass($trade[3], $user->password))
  1072. {
  1073. $user->sendPacket('<n t="Senha Errada" />');
  1074. $tradee->sendPacket('<n t="(' . $user->id . ') Senha Errada" />');
  1075. }
  1076.  
  1077. elseif($tdata[0] > $user->xats || $tdata[0] < 0)
  1078. {
  1079. $user->sendPacket('<n t="Voce nao tem xats" />');
  1080. $tradee->sendPacket('<n t="(' . $user->id . ') Voce nao tem xats" />');
  1081. }
  1082.  
  1083. elseif($tdata[1] > $user->days || $tdata[1] < 0)
  1084. {
  1085. $user->sendPacket('<n t="Voce nao tem days" />');
  1086. $user->sendPacket('<n t="(' . $user->id . ') Voce nao tem Days" />');
  1087. }
  1088.  
  1089. else
  1090. {
  1091. $user->trade[$tradee->id] = array($trade, $tdata, $tdu2);
  1092. }
  1093. }
  1094. }
  1095. }
  1096. }
  1097.  
  1098. $tradee->sendPacket($rawXML);
  1099. }
  1100.  
  1101.  
  1102. break;
  1103. }
  1104. else
  1105. {
  1106.  
  1107. $x = $attr['x'];
  1108. $s = $attr['s'];
  1109. $b = $attr['b'];
  1110. $m = $attr['m'];
  1111. $p = $attr['p'];
  1112. $k = $attr['k'];
  1113. $f = $attr['f'];
  1114. $i = $attr['i'];
  1115. $user->sendPacket("<x i=\"{$i}\" u=\"{$user->id}\" b=\"{$b}\" x=\"{$x}\" t=\"{$m}\" />");
  1116.  
  1117. }
  1118. break;
  1119.  
  1120.  
  1121. case 'ap':
  1122. $attributes = Array(
  1123. 'a',
  1124. 'p'
  1125. );
  1126. $attributes = $this->getMultiAttr( $packet, $attributes );
  1127. $a = $attributes[ 'a' ];
  1128. $p = $attributes[ 'p' ];
  1129. $power = $this->mysql->fetch_array( "SELECT * FROM `powers` WHERE `id`='{$this->mysql->sanatize($p)}';" );
  1130. $existe = $this->mysql->fetch_array( "SELECT * FROM `chat_powers` WHERE `power`='{$this->mysql->sanatize($p)}' AND `chat`='{$user->group}';" );
  1131. $double = $this->mysql->fetch_array( "SELECT * FROM `userpowers` WHERE `powerid`='{$this->mysql->sanatize($p)}' AND `userid`='{$user->id}';" );
  1132. $count = $this->mysql->fetch_array( "SELECT * FROM `chat_powers` WHERE `power`='{$this->mysql->sanatize($p)}' AND `usuario`='{$user->id}';" );
  1133. switch ( $a )
  1134. {
  1135. case 1:
  1136. If ( !$user->hasPower( $p ) )
  1137. return $user->sendPacket( '<n t="Voce nao tem este power!" />' );
  1138. If ( Isset( $existe[ 0 ][ 'id' ] ) )
  1139. return $user->sendPacket( '<n t="Ja tem este power ativado neste chat!" />' );
  1140. if ( $double[ 0 ][ 'count' ] < count( $count ) + 1 )
  1141. return $user->sendPacket( '<n t="Voce precisa de mais um power deste compre mais uma unidade!" />' );
  1142. $this->mysql->query( "INSERT INTO chat_powers(`chat`,`usuario`,`power`) VALUES ('{$user->group}','{$user->id}','{$this->mysql->sanatize($p)}');" );
  1143. $user->sendPacket( '<n t="' . $power[ 0 ][ 'name' ] . ' foi assinado!" />' );
  1144. break;
  1145.  
  1146. case 0:
  1147. If ( !$user->hasPower( $p ) )
  1148. return $user->sendPacket( '<n t="Voce nao tem este power!" />' );
  1149. If ( !Isset( $existe[ 0 ][ 'id' ] ) )
  1150. return $user->sendPacket( '<n t="Voce nao tem este power ativado aqui!" />' );
  1151. $this->mysql->query( "DELETE FROM chat_powers WHERE `usuario`='{$user->id}' AND `power`='{$this->mysql->sanatize($p)}' AND `chat`='{$user->group}';" );
  1152. $user->sendPacket( '<n t="' . $power[ 0 ][ 'name' ] . ' foi des-assinado!" />' );
  1153. break;
  1154. } //$a
  1155. break;
  1156. case 'a':
  1157. if ($this->spamfilter($tag, $user, $this->config->spam_wait) || $user->banned > time())
  1158. break;
  1159. if ($user->guest == true) {
  1160. return false;
  1161. }
  1162.  
  1163. $attributes = array('x', 's', 'b', 'm', 'p', 'k', 'f');
  1164. $attributes = $this->getMultiAttr($packet, $attributes);
  1165. $x = $attributes['x'];
  1166. $s = $attributes['s'];
  1167. $b = $attributes['b'];
  1168. $m = $attributes['m'];
  1169. $p = $attributes['p'];
  1170. $k = $attributes['k'];
  1171. $f = $attributes['f'];
  1172.  
  1173. if (!$b && !$f) {
  1174. if ($user->xats < 25) {
  1175. return $user->sendPacket('<m t="/wVoce nao\'Tem xats o suficientes!" u="0" />');
  1176. }
  1177.  
  1178. $usr = $this->mysql->fetch_array("select * from `users` where `id`='{$user->id}';");
  1179. $usr = $usr[0];
  1180. if (!$this->mysql->checkPass($p, $usr['password'])) {
  1181. return $user->sendPacket('<v e="8" />');
  1182. }
  1183.  
  1184. $user->xats = ($usr['xats'] - 25);
  1185. $this->mysql->query("update `users` set `xats` = '{$user->xats}', `reserve`=`reserve`-25 where `id` = '{$user->id}';");
  1186. $user->sendRoom("<a u=\"{$user->id}\" k=\"{$k}\" t=\"{$m}\" />", true);
  1187. $user->sendPacket("<a u=\"{$user->id}\" k=\"{$k}\" t=\"{$m}\" c=\"{$user->xats}\" />");
  1188. } else {
  1189. switch ($k) {
  1190. case 'Confetti':
  1191. case 'Hearts':
  1192. case 'Sunset':
  1193. case 'Marry':
  1194. case 'Marriage':
  1195. case 'Rings':
  1196. if ($user->d2 != 0) {
  1197. $user->sendPacket('<n t="/wEste usuario ja tem BFF/Married." u="0" />');
  1198. break;
  1199. }
  1200. if ($user->id == $b) {
  1201. $user->sendPacket( '<n t="/wVoce nao pode casar com si propio!" u="0" />' );
  1202. break;
  1203. }
  1204. $usr = $this->mysql->fetch_array("select * from `users` where `id`='{$user->id}';");
  1205. $usr = $usr[0];
  1206. if (!$this->mysql->checkPass($p, $usr['password'])) {
  1207. return $user->sendPacket('<v e="8" />');
  1208. }
  1209. if ($user->xats < 200) {
  1210. $user->sendPacket('<v e="11" />');
  1211. break;
  1212. }
  1213. $u = $this->getUserByID($b, $user->chat);
  1214. if (!is_object($u)) {
  1215. break;
  1216. }
  1217. if ($u->hasPower(99)) {
  1218. return $user->sendPacket('<n t="' . $u->id . ' tem o power single." />');
  1219. }
  1220. $user->xats = ($usr['xats'] - 200);
  1221. if ($u->d2 != 0) {
  1222. $user->sendPacket('<m t="/wste usuario ja tem BFF/Married." u="0" />');
  1223. break;
  1224. }
  1225. $this->mysql->query("update `users` set `bride` = '{$u->id}', `d2` = '{$u->id}', `xats` = '{$user->xats}', `reserve`=`reserve`-200 where `id` = '{$user->id}';");
  1226. $this->mysql->query("update `users` set `bride` = '{$user->id}', `d2` = '{$user->id}' where `id` = '{$u->id}';");
  1227. $data1 = $this->doLogin($user->username, $user->password);
  1228. $data2 = $this->doLogin($u->username, $u->password);
  1229. $user->sendPacket( '<n t="Agora voce esta casado(a) com ' . $u->id . '" />' );
  1230. $user->sendPacket($data1);
  1231. $u->sendPacket( '<n t="Agora voce esta casado(a) com ' . $user->id . '" />' );
  1232. $u->sendPacket($data2);
  1233. break;
  1234.  
  1235. case 'Argue':
  1236. case 'Divorced':
  1237. case 'Hippod':
  1238. case 'Divorce':
  1239. case 'Botd':
  1240. $this->mysql->query("update `users` set `d0` = '0', `d2` = '0', `bride` = '' where `id` = '{$user->id}';");
  1241. $user->sendPacket( '<n t="Voce Divorciou-se!" />' );
  1242. $data1 = $this->doLogin($user->username, $user->password);
  1243. $user->sendPacket($data1);
  1244. break;
  1245.  
  1246.  
  1247. case 'Champagne':
  1248. If ( $user->d2 != 0 )
  1249. {
  1250. $user->sendPacket( '<m t="/wVoce ja tem BFF/Married!" u="0" />' );
  1251. break;
  1252. } //$user->d2 != 0
  1253. If ( $user->id == $b )
  1254. {
  1255. $user->sendPacket( '<m t="/wVoce nao pode fazer BFF/Married com si propio!" u="0" />' );
  1256. break;
  1257. } //$user->id == $b
  1258. $usr = $this->mysql->fetch_Array( "select * from `users` where `id`='{$user->id}';" );
  1259. $usr = $usr[ 0 ];
  1260. If ( !$this->mysql->checkPass( $p, $usr[ 'password' ] ) )
  1261. {
  1262. return $user->sendPacket( '<v e="8" />' );
  1263. } //!$this->mysql->checkPass( $p, $usr[ 'password' ] )
  1264. If ( $user->xats < 200 )
  1265. {
  1266. $user->sendPacket( '<v e="11" />' );
  1267. break;
  1268. } //$user->xats < 200
  1269. $u = $this->getUserByID( $f, $user->chat );
  1270. If ( !is_object( $u ) )
  1271. {
  1272. break;
  1273. } //!is_object( $u )
  1274. If ( $u->hasPower( 82 ) )
  1275. {
  1276. return $user->sendPacket( '<n t="' . $u->id . ' tem o power single." />' );
  1277. } //$u->hasPower( 82 )
  1278. $user->xats = ( $usr[ 'xats' ] - 25 );
  1279. If ( $u->d2 != 0 )
  1280. {
  1281. $user->sendPacket( '<m t="/wEste usuario ja esta BFF/Married!" u="0" />' );
  1282. break;
  1283. } //$u->d2 != 0
  1284. $this->mysql->query( "update `users` set `d0` = '1', `d2` = '{$u->id}', `xats` = '{$user->xats}', `reserve`=`reserve`-25 where `id` = '{$user->id}';" );
  1285. $this->mysql->query( "update `users` set `d0` = '1', `d2` = '{$user->id}' where `id` = '{$u->id}';" );
  1286. $data1 = $this->doLogin( $user->username, $user->password );
  1287. $data2 = $this->doLogin( $u->username, $u->password );
  1288. $user->sendPacket( '<n t="Agora voce esta BFF com ' . $u->id . '" />' );
  1289. $user->sendPacket( $data1 );
  1290. $u->sendPacket( '<n t="Agora voce esta BFF com ' . $user->id . '" />' );
  1291. $u->sendPacket( $data2 );
  1292. break;
  1293.  
  1294. case 'Champagne':
  1295. If ( $user->d2 != 0 )
  1296. {
  1297. $user->sendPacket( '<m t="/wVoce ja tem BFF/Married!" u="0" />' );
  1298. break;
  1299. } //$user->d2 != 0
  1300. If ( $user->id == $b )
  1301. {
  1302. $user->sendPacket( '<m t="/wVoce nao pode fazer BFF/Married com si propio!" u="0" />' );
  1303. break;
  1304. } //$user->id == $b
  1305. $usr = $this->mysql->fetch_Array( "select * from `users` where `id`='{$user->id}';" );
  1306. $usr = $usr[ 0 ];
  1307. If ( !$this->mysql->checkPass( $p, $usr[ 'password' ] ) )
  1308. {
  1309. return $user->sendPacket( '<v e="8" />' );
  1310. } //!$this->mysql->checkPass( $p, $usr[ 'password' ] )
  1311. If ( $user->xats < 200 )
  1312. {
  1313. $user->sendPacket( '<v e="11" />' );
  1314. break;
  1315. } //$user->xats < 200
  1316. $u = $this->getUserByID( $f, $user->chat );
  1317. If ( !is_object( $u ) )
  1318. {
  1319. break;
  1320. } //!is_object( $u )
  1321. If ( $u->hasPower( 82 ) )
  1322. {
  1323. return $user->sendPacket( '<n t="' . $u->id . ' tem o power single." />' );
  1324. } //$u->hasPower( 82 )
  1325. $user->xats = ( $usr[ 'xats' ] - 25 );
  1326. If ( $u->d2 != 0 )
  1327. {
  1328. $user->sendPacket( '<m t="/wEste usuario ja esta BFF/Married!" u="0" />' );
  1329. break;
  1330. } //$u->d2 != 0
  1331. $this->mysql->query( "update `users` set `d0` = '1', `d2` = '{$u->id}', `xats` = '{$user->xats}', `reserve`=`reserve`-25 where `id` = '{$user->id}';" );
  1332. $this->mysql->query( "update `users` set `d0` = '1', `d2` = '{$user->id}' where `id` = '{$u->id}';" );
  1333. $data1 = $this->doLogin( $user->username, $user->password );
  1334. $data2 = $this->doLogin( $u->username, $u->password );
  1335. $user->sendPacket( '<n t="Agora voce esta BFF com ' . $u->id . '" />' );
  1336. $user->sendPacket( $data1 );
  1337. $u->sendPacket( '<n t="Agora voce esta BFF com ' . $user->id . '" />' );
  1338. $u->sendPacket( $data2 );
  1339. break;
  1340.  
  1341. case 'T':
  1342. If ( $x < 0 || !is_numeric( $x ) )
  1343. {
  1344. return $this->disconnect( $user->index );
  1345. } //$x < 0 || !is_numeric( $x )
  1346. $usr = $this->mysql->fetch_Array( "select * from `users` where `id`='{$user->id}';" );
  1347. $usr = $usr[ 0 ];
  1348. If ( $usr[ 'transferblock' ] > time() )
  1349. {
  1350. return $user->sendPacket( '<v e="10" />' );
  1351. } //$usr[ 'transferblock' ] > time()
  1352. If ( !$this->mysql->checkPass( $p, $usr[ 'password' ] ) )
  1353. {
  1354. return $user->sendPacket( '<v e="8" />' );
  1355. } //!$this->mysql->checkPass( $p, $usr[ 'password' ] )
  1356. If ( $x > $usr[ 'xats' ] )
  1357. {
  1358. return $user->sendPacket( '<v e="11" />' );
  1359. } //$x > $usr[ 'xats' ]
  1360. If ( $x > $usr[ 'xats' ] - $usr[ 'reserve' ] )
  1361. {
  1362. return $user->sendPacket( "<n t=\"Voce nao pode usar todos seus xats (Voce so podera usar " . ( $usr[ 'xats' ] - $usr[ 'reserve' ] ) . " xats).\" />" );
  1363. } //$x > $usr[ 'xats' ] - $usr[ 'reserve' ]
  1364. If ( strtotime( "+ $s days" ) > $usr[ 'days' ] )
  1365. {
  1366. return $user->sendPacket( '<v e="18" />' );
  1367. } //strtotime( "+ $s days" ) > $usr[ 'days' ]
  1368. $u = $this->getUserByID( $b, $user->chat );
  1369. If ( !is_object( $u ) )
  1370. {
  1371. return $user->sendPacket( '<v e="0" m="a" t="" />' );
  1372. } //!is_object( $u )
  1373.  
  1374. If ( $user->ipaddr == $u->ipaddr )
  1375. {
  1376. return $user->sendPacket( '<n t="Voce nao pode fazer transfer com si propio .-." />' );
  1377. } //$user->ipaddr == $u->ipaddr
  1378.  
  1379. $u->xats += $x;
  1380. If ( $u->days <= 0 )
  1381. {
  1382. $u->days = $s;
  1383. } //$u->days <= 0
  1384. Else
  1385. {
  1386. $u->days += $s;
  1387. }
  1388. $user->xats -= $x;
  1389. $user->days -= $s;
  1390. $uDAYS = strtotime( "+ " . $u->days . " days" );
  1391. $UDAYS = strtotime( "+ " . $user->days . " days" );
  1392. $this->mysql->query( "update `users` set `xats`='{$u->xats}', `days`='{$uDAYS}' where `id` = '{$u->id}';" );
  1393. $this->mysql->query( "update `users` set `xats`='{$user->xats}', `days`='{$UDAYS}' where `id` = '{$user->id}';" );
  1394. $this->mysql->query( "insert into `transfers` (`to`, `from`, `xats`, `days`, `timestamp`) values ('{$u->id}', '{$user->id}', '{$x}', '{$s}', '" . time() . "');" );
  1395.  
  1396. $user->sendPacket( "<a c=\"{$user->xats}\" u=\"{$user->id}\" b=\"{$b}\" s=\"{$s}\" x=\"{$x}\" k=\"T\" t=\"{$m}\" />" );
  1397. $u->sendPacket( "<a c=\"{$u->xats}\" u=\"{$user->id}\" b=\"{$b}\" s=\"{$s}\" x=\"{$x}\" k=\"T\" t=\"{$m}\" />" );
  1398.  
  1399. $user->joinRoom( $user->chat, 1 );
  1400. $u->joinRoom( $user->chat, 1 );
  1401. break;
  1402. } //$k
  1403. }
  1404. break;
  1405.  
  1406. case 'p':
  1407. $u = $this->getuserbyid($this->getAttribute($packet, 'u', true), $user->chat);
  1408. if (!is_object($u)) {
  1409. break;
  1410. }
  1411.  
  1412. $attr = $this->getMultiAttr($packet, array('t', 's'));
  1413.  
  1414. if (substr($attr['t'], 0, 1) == "/") {
  1415. switch (1) {
  1416. case substr( $attr[ 't' ], 1, 2 ) == 'ls':
  1417. $verIficar = $this->mysql->fetch_Array( "SELECT * FROM `bans` WHERE userid = {$u->id} AND `chatid` = {$user->chat} AND type = 'f262144';" );
  1418. If ( !@$verIficar[ 0 ][ 'index' ] )
  1419. {
  1420. $time = strtotime( "+ 20 years" );
  1421. $this->mysql->query( "insert into `bans` (`chatid`, `userid`, `unbandate`, `ip`, `type`) values ('{$user->chat}', '{$u->id}', '{$time}', '{$u->ipaddr}', 'f262144');" );
  1422. $u->joinRoom( $user->chat, False, True, 0 );
  1423. $user->sendRoom( '<m p="' . substr( $attr[ 't' ], 3 ) . '" t="/ls' . substr( $attr[ 't' ], 3 ) . '" u="' . $user->id . '" d="' . $u->id . '" />', False, $u->id );
  1424. } //!$verIficar[ 0 ][ 'index' ]
  1425. Else
  1426. {
  1427. $this->mysql->query( "delete from `bans` where `chatid`='{$user->chat}' and `userid`='{$u->id}' and type='f262144';" );
  1428. $u->f -= 262144;
  1429. $u->joinRoom( $user->chat, 0, True );
  1430. }
  1431. break;
  1432.  
  1433.  
  1434. case substr($attr['t'], 1, 2) == 'mo':
  1435. if (!in_array($user->rank, array(1)) || !$this->higherRank($user->rank, $u->rank, true)) {
  1436. break;
  1437. }
  1438. $time = round(substr($attr['t'], 3), 1);
  1439. if (!is_numeric($time) || $time > 24 || $time < 1) {
  1440. return $user->sendPacket("<n t=\"Please use the following format\n/mo2.5 for 2.5 hours.\nMax:24\nMin:1\" />");
  1441. }
  1442. $this->mysql->query("delete from `ranks` where `userid`='{$u->id}' and `chatid`='{$user->chat}';");
  1443. $this->mysql->query("insert into `ranks`(`userid`, `chatid`, `f`, `tempend`) values('{$u->id}', '{$u->chatid}', 4, " . (time() + ($time * 60 * 60)) . ");");
  1444. $x = "<i>";
  1445. $x = htmlspecialchars($x);
  1446. $user->sendRoom("<m u=\"{$user->id}\" t=\"{$x} I have made {$u->username} an owner for {$time} hours!\" />");
  1447. $u->joinRoom($user->chat, 0, true);
  1448. break;
  1449.  
  1450. case substr($attr['t'], 1, 2) == 'mb':
  1451. if (!in_array($user->rank, array(1)) || !$this->higherRank($user->rank, $u->rank, true)) {
  1452. break;
  1453. }
  1454. $time = round(substr($attr['t'], 3), 1);
  1455. if (!is_numeric($time) || $time > 24 || $time < 1) {
  1456. return $user->sendPacket("<n t=\"Please use the following format\n/mo2.5 for 2.5 hours.\nMax:24\nMin:1\" />");
  1457. }
  1458. $this->mysql->query("delete from `ranks` where `userid`='{$u->id}' and `chatid`='{$user->chat}';");
  1459. $this->mysql->query("insert into `ranks`(`userid`, `chatid`, `f`, `tempend`) values('{$u->id}', '{$u->chatid}', 3, " . (time() + ($time * 60 * 60)) . ");");
  1460. $x = "<i>";
  1461. $x = htmlspecialchars($x);
  1462. $user->sendRoom("<m u=\"{$user->id}\" t=\"{$x} I have made {$u->username} a Member for {$time} hours!\" />");
  1463. $u->joinRoom($user->chat, 0, true);
  1464. break;
  1465.  
  1466.  
  1467.  
  1468. case substr($attr['t'], 1, 1) == 'm':
  1469. if (!in_array($user->rank, array(1, 4)) || !$this->higherRank($user->rank, $u->rank, true)) {
  1470. break;
  1471. }
  1472. $time = round(substr($attr['t'], 2), 1);
  1473. if (!is_numeric($time) || $time > 24 || $time < 1) {
  1474. return $user->sendPacket("<n t=\"Please use the following format\n/m2.5 for 2.5 hours.\nMax:24\nMin:1\" />");
  1475. }
  1476. $this->mysql->query("delete from `ranks` where `userid`='{$u->id}' and `chatid`='{$user->chat}';");
  1477. $this->mysql->query("insert into `ranks`(`userid`, `chatid`, `f`, `tempend`) values('{$u->id}', '{$u->chatid}', 2, " . (time() + ($time * 60 * 60)) . ");");
  1478. $user->sendRoom("<m u=\"{$user->id}\" t=\"&lt;i&gt; I have made {$u->username} a moderator for {$time} hours!\" />");
  1479. $u->joinRoom($user->chat, 0, true);
  1480. break;
  1481. default:
  1482. $attr['t'] = htmlspecialchars($attr['t']);
  1483. $attr['s'] = htmlspecialchars($attr['s']);
  1484. $u->sendPacket("<p u=\"{$user->id}\" t=\"{$attr['t']}\" s=\"{$attr['s']}\" />");
  1485. return;
  1486. }
  1487. } else {
  1488. $attr['t'] = htmlspecialchars($attr['t']);
  1489. $attr['s'] = htmlspecialchars($attr['s']);
  1490. $u->sendPacket("<p u=\"{$user->id}\" t=\"{$attr['t']}\" s=\"{$attr['s']}\" />");
  1491. if ($this->spamfilter($tag, $user, 700))
  1492. break;
  1493. }
  1494. break;
  1495.  
  1496. case 'z':
  1497. if ($user->switchingPools == true) {
  1498. $user->switchingPools = false;
  1499. break;
  1500. }
  1501. if ($this->spamfilter($tag, $user, 1))
  1502. break;
  1503. $d = $this->getAttribute($packet, 'd');
  1504. $u = $this->getUserByID($d);
  1505. if (!is_object($u)) {
  1506. break;
  1507. }
  1508. if (!is_object($user)) {
  1509. break;
  1510. }
  1511. $t2 = $this->getAttribute($packet, 't');
  1512. $t = substr($t2, 0, 2);
  1513. $t3 = substr($t2, 0, 3);
  1514. $param = substr($t2, 2);
  1515. switch ($t) {
  1516. case '/l':
  1517.  
  1518. if ($u->hidden == true) {
  1519. return false;
  1520. }
  1521.  
  1522. $str = ((($u->p0 & 32) && ($u->chat != $user->chat)) || !isset($u->group)) ? " t=\"/a_Nofollow\"" : " t=\"/a_on {$u->group}\""; //Nofollow
  1523. $user->sendPacket('<z b="1" d="' . $user->id . '" u="' . $u->id . '"' . ( $str ) . ' po="' . $u->dO . '" ' . $u->pStr . 'x="' . $u->xats . '" y="' . $u->days . '" q="3"' . ($u->username == '' ? '' : ' N="' . $u->username . '"') . ' n="' . html_entity_decode(htmlspecialchars_decode(($u->nickname))) . '" a="' . $this->mysql->sanatize($u->avatar) . '" h="' . $this->mysql->sanatize($u->url) . '" v="2" />');
  1524. $u->sendPacket('<z b="1" d="' . $u->id . '" u="' . $user->id . '" t="/l" po="' . $user->dO . '" ' . $user->pStr . 'x="' . $user->xats . '" y="' . $user->days . '" q="3"' . ($user->username == '' ? '' : ' N="' . $user->username . '"') . ' n="' . html_entity_decode(htmlspecialchars_decode(($user->nickname))) . '" a="' . $this->mysql->sanatize($user->avatar) . '" h="' . $this->mysql->sanatize($user->url) . '" v="2" />');
  1525.  
  1526. break;
  1527. case '/a':
  1528. break;
  1529.  
  1530. default:
  1531. $t = $this->getAttribute($packet, 't');
  1532. $s = $this->getAttribute($packet, 's');
  1533. $u->sendPacket("<z u=\"" . $user->id . "\" t=\"" . $t . "\" s=\"" . $s . "\" d=\"" . $u->id . "\" />");
  1534. break;
  1535. }
  1536. break;
  1537.  
  1538. case 'c':
  1539. if ($this->spamfilter($tag, $user, 800))
  1540. break;
  1541. if ($user->banned > time()) {
  1542. return false;
  1543. }
  1544.  
  1545. if ($user->rExpire != 0 && $user->rExpire < time()) {
  1546. $this->mysql->query("delete from `ranks` where `userid`={$user->id} and `chatid`='{$user->chat}';");
  1547. $this->mysql->query("insert into `ranks`(`userid`, `chatid`, `f`) values({$user->id}, {$user->chat}, 3);");
  1548. return $user->joinRoom($user->chat, 0, true);
  1549. }
  1550.  
  1551. $attr = $this->getAttribute($packet, 'u', true);
  1552. $t2 = $this->getAttribute($packet, 't');
  1553. $uid = $this->getAttribute($packet, 'u');
  1554. $game = $this->getAttribute($packet, 'w');
  1555. $p = $this->getAttribute($packet, 'p');
  1556. $u = $this->getUserByID($attr, $user->chat);
  1557. $bchat = $this->mysql->fetch_array("select * from `chats` where `id`='{$user->chat}';");
  1558. $blastban = $bchat[0]["blastban"];
  1559. $blastkick = $bchat[0]["blastkick"];
  1560. $blastpro = $bchat[0]["blastpro"];
  1561. $blastde = $bchat[0]["blastde"];
  1562. $param3 = substr($t2, 3);
  1563. $param = substr($t2, 2);
  1564.  
  1565. if (!is_object($u)) {
  1566. break;
  1567. }
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576. switch (substr($t2, 0, 3)) {
  1577. case '/gm':
  1578. If ( $this->higherRank( $user->rank, $u->rank, True ) && in_Array( $user->rank, Array(
  1579. 1,
  1580. 2,
  1581. 4
  1582. ) ) )
  1583. // Mute
  1584. {
  1585. $verIficar = $this->mysql->fetch_Array( "SELECT * FROM `bans` WHERE userid = {$u->id} AND `chatid` = {$user->chat} AND type = 'f256';" );
  1586. If ( !$verIficar[ 0 ][ 'index' ] )
  1587. {
  1588. $time = $param3 == 0 ? strtotime( "+ 20 years" ) : strtotime( "+ {$param3} seconds" );
  1589. $this->mysql->query( "insert into `bans` (`chatid`, `userid`, `unbandate`, `ip`, `type`) values ('{$user->chat}', '{$u->id}', '{$time}', '{$u->ipaddr}', 'f256');" );
  1590. $u->joinRoom( $user->chat, False, True, 0 );
  1591. $user->sendRoom( '<m p="' . $this->getAttribute( $packet, 'p' ) . '" t="/gm' . $param3 . '" u="' . $user->id . '" d="' . $u->id . '" />', False, $u->id );
  1592. $u->banned = $time;
  1593. } //!$verIficar[ 0 ][ 'index' ]
  1594. Else
  1595. {
  1596. $this->mysql->query( "delete from `bans` where `chatid`='{$user->chat}' and `userid`='{$u->id}' and type='f256';" );
  1597. $u->f -= 256;
  1598. $u->joinRoom( $user->chat, 0, True );
  1599. }
  1600. } //$this->higherRank( $user->rank, $u->rank, True ) && in_Array( $user->rank, Array( 1, 2, 4 ) )
  1601. return;
  1602.  
  1603. case '/gn':
  1604. If ( $this->higherRank( $user->rank, $u->rank, True ) && in_Array( $user->rank, Array(
  1605. 1,
  1606. 2,
  1607. 4
  1608. ) ) )
  1609. // Naughty
  1610. {
  1611. $verIficar = $this->mysql->fetch_Array( "SELECT * FROM `bans` WHERE userid = {$u->id} AND `chatid` = {$user->chat} AND type = 'f524288';" );
  1612. If ( !$verIficar[ 0 ][ 'index' ] )
  1613. {
  1614. $time = $param3 == 0 ? strtotime( "+ 20 years" ) : strtotime( "+ {$param3} seconds" );
  1615. $this->mysql->query( "insert into `bans` (`chatid`, `userid`, `unbandate`, `ip`, `type`) values ('{$user->chat}', '{$u->id}', '{$time}', '{$u->ipaddr}', 'f524288');" );
  1616. $u->joinRoom( $user->chat, False, True, 0 );
  1617. $user->sendRoom( '<m p="' . $this->getAttribute( $packet, 'p' ) . '" t="/gn' . $param3 . '" u="' . $user->id . '" d="' . $u->id . '" />', False, $u->id );
  1618. //$user->sendRoom("<m p=\"{$pee}\" t=\"/k\" u=\"{$user->id}\" d=\"{$u->id}\" />", false);
  1619. $this->disconnect($u->index);
  1620. $user->sendRoom("<l u=\"{$u->id}\" />");
  1621. $u->banned = $time;
  1622. } //!$verIficar[ 0 ][ 'index' ]
  1623. Else
  1624. {
  1625. $this->mysql->query( "delete from `bans` where `chatid`='{$user->chat}' and `userid`='{$u->id}' and type='f524288';" );
  1626. $u->f -= 524288;
  1627. $u->joinRoom( $user->chat, 0, True );
  1628. }
  1629. } //$this->higherRank( $user->rank, $u->rank, True ) && in_Array( $user->rank, Array( 1, 2, 4 ) )
  1630. return;
  1631.  
  1632. case '/gy':
  1633. If ( $this->higherRank( $user->rank, $u->rank, True ) && in_Array( $user->rank, Array(
  1634. 1,
  1635. 2,
  1636. 4
  1637. ) ) )
  1638. // Yellowcard
  1639. {
  1640. $verIficar = $this->mysql->fetch_Array( "SELECT * FROM `bans` WHERE userid = {$u->id} AND `chatid` = {$user->chat} AND type = 'f1048576';" );
  1641. If ( !$verIficar[ 0 ][ 'index' ] )
  1642. {
  1643. $time = $param3 == 0 ? strtotime( "+ 20 years" ) : strtotime( "+ {$param3} seconds" );
  1644. $this->mysql->query( "insert into `bans` (`chatid`, `userid`, `unbandate`, `ip`, `type`) values ('{$user->chat}', '{$u->id}', '{$time}', '{$u->ipaddr}', 'f1048576');" );
  1645. $u->joinRoom( $user->chat, False, True, 0 );
  1646. $user->sendRoom( '<m p="' . $this->getAttribute( $packet, 'p' ) . '" t="/gy' . $param3 . '" u="' . $user->id . '" d="' . $u->id . '" />', False, $u->id );
  1647. //$user->sendRoom("<m p=\"{$pee}\" t=\"/k\" u=\"{$user->id}\" d=\"{$u->id}\" />", false);
  1648. $this->disconnect($u->index);
  1649. $user->sendRoom("<l u=\"{$u->id}\" />");
  1650. } //!$verIficar[ 0 ][ 'index' ]
  1651. Else
  1652. {
  1653. $this->mysql->query( "delete from `bans` where `chatid`='{$user->chat}' and `userid`='{$u->id}' and type='f1048576';" );
  1654. $u->f -= 1048576;
  1655. $u->joinRoom( $user->chat, 0, True );
  1656. }
  1657. } //$this->higherRank( $user->rank, $u->rank, True ) && in_Array( $user->rank, Array( 1, 2, 4 ) )
  1658. return;
  1659.  
  1660. case '/gg':
  1661. If ( $this->higherRank( $user->rank, $u->rank, True ) && in_Array( $user->rank, Array(
  1662. 1,
  1663. 2,
  1664. 4
  1665. ) ) )
  1666. // Gag
  1667. {
  1668. $verIficar = $this->mysql->fetch_Array( "SELECT * FROM `bans` WHERE userid = {$u->id} AND `chatid` = {$user->chat} AND type = 'f256';" );
  1669. If ( !$verIficar[ 0 ][ 'index' ] )
  1670. {
  1671. $time = $param3 == 0 ? strtotime( "+ 20 years" ) : strtotime( "+ {$param3} seconds" );
  1672. $this->mysql->query( "insert into `bans` (`chatid`, `userid`, `unbandate`, `ip`, `type`) values ('{$user->chat}', '{$u->id}', '{$time}', '{$u->ipaddr}', 'f256');" );
  1673. $u->joinRoom( $user->chat, False, True, 1 );
  1674. $user->sendRoom( '<m p="' . $this->getAttribute( $packet, 'p' ) . '" t="/gg' . $param3 . '" u="' . $user->id . '" d="' . $u->id . '" />', False, $u->id );
  1675. //$user->sendRoom("<m p=\"{$pee}\" t=\"/k\" u=\"{$user->id}\" d=\"{$u->id}\" />", false);
  1676. $this->disconnect($u->index);
  1677. $user->sendRoom("<l u=\"{$u->id}\" />");
  1678. $u->banned = $time;
  1679. } //!$verIficar[ 0 ][ 'index' ]
  1680. Else
  1681. {
  1682. $this->mysql->query( "delete from `bans` where `chatid`='{$user->chat}' and `userid`='{$u->id}' and type='f256';" );
  1683. $u->f -= 256;
  1684. $u->joinRoom( $user->chat, 0, True );
  1685. }
  1686. } //$this->higherRank( $user->rank, $u->rank, True ) && in_Array( $user->rank, Array( 1, 2, 4 ) )
  1687. return;
  1688.  
  1689. case '/gd':
  1690. if($this->higherRank($user->rank,$u->rank,true) && in_array($user->rank, array(1, 2, 4)))
  1691. { // Dunce
  1692. if($u->f & 0x8000)
  1693. {
  1694. $this->mysql->query("delete from `bans` where `chatid`='{$user->chat}' and `userid`='{$u->id}' or `chatid`='{$user->chat}' and `ip`='{$u->ipaddr}';");
  1695. $user->sendRoom('<m t="/u" u="' . $user->id . '" d="' . $u->id . '" />');
  1696. $u->sendPacket('<c u="0" d="' . $u->id . '" t="/u" />');
  1697. $u->f -= 0x8000;
  1698. $u->joinRoom($user->chat, false, true, 0);
  1699. }
  1700. else
  1701. {
  1702. $time = $param3 == 0 ? strtotime("+ 20 years") : strtotime("+ {$param3} seconds");
  1703. $this->mysql->query("insert into `bans` (`chatid`, `userid`, `unbandate`, `ip`, `type`) values ('{$user->chat}', '{$u->id}', '{$time}', '{$u->ipaddr}', 'f32768');");
  1704. if($u->group && $user->hasPower(296))
  1705. {
  1706. $user->sendRoom('<bl u="'.$user->id.'" d="'.$u->id.'" t="blastdunce" v="1" r="'.$this->BlastCor($u->rank).'" o="'.$this->BlastCargo($u->rank).'" /> ', false);
  1707. }
  1708. $u->joinRoom($user->chat, false, true, 0);
  1709. $user->sendRoom('<m p=\"{$pee}\" t=\"/k\" u=\"{$user->id}\" d=\"{$u->id}\" />', false, $u->id);
  1710. //$user->sendRoom("<m p=\"{$pee}\" t=\"/k\" u=\"{$user->id}\" d=\"{$u->id}\" />", false);
  1711.  
  1712. }
  1713. }
  1714. return;
  1715. }
  1716.  
  1717. switch (substr($t2, 0, 2)) {
  1718. case '/r': // Guest
  1719. case '/e': // Member
  1720. case '/m': // Mod
  1721. case '/M': // Owner
  1722. $ranks = array(
  1723. 'r' => array(array(1, 2, 4), 5),
  1724. 'e' => array(array(1, 2, 4), 3),
  1725. 'm' => array(array(1, 4), 2),
  1726. 'M' => array(array(1), 4)
  1727. );
  1728.  
  1729. $rank = $ranks[substr($t2, 1, 1)];
  1730.  
  1731. if (in_array($user->rank, $rank[0]) && $this->higherRank($user->rank, $u->rank, true)) {
  1732. $this->mysql->query('delete from `ranks` where `userid`=' . $u->id . ' and `chatid`=' . $user->chat . ';');
  1733. $this->mysql->query('insert into `ranks`(`userid`, `chatid`, `f`) values(' . $u->id . ', ' . $user->chat . ', ' . $rank[1] . ');');
  1734. $p = $this->getAttribute($packet, 'p');
  1735. $silent = 'm'; //$user->hasPower(72) && in_array($user->rank, array(1, 4)) && $rank == $ranks['e'] ? 'c' : 'm';
  1736. $u->sendPacket('<c p="' . $p . '" t="' . substr($t2, 0, 2) . '" u="' . $user->id . '" d="' . $u->id . '" />');
  1737. //$user->sendRoom('<' . $silent . ' p="' . $p . '" t="' . substr($t2, 0, 2) . '" u="' . $user->id . '" d="' . $u->id . '" />');
  1738. $user->sendRoom('<m u="' . $user->id . '" d="' . $u->id . '" t="/m" p="' . substr($t2, 1, 1) . '" />');
  1739. /*
  1740. * Guest: 0x009900
  1741. * Member: 0x3366FF
  1742. * Moderator: 0xFFFFFF
  1743. * Owner: 0xFF9900
  1744. */
  1745. $cols = array(
  1746. "/r" => "0x009900",
  1747. "/e" => "0x3366FF",
  1748. "/m" => "0xFFFFFF",
  1749. "/M" => "0xFF9900"
  1750. );
  1751. $colIndex = substr($t2, 0, 2);
  1752. $blaster = $cols[$colIndex];
  1753. $oAttr = array(
  1754. "/r" => "r",
  1755. "/e" => "e",
  1756. "/m" => "m",
  1757. "/M" => "M"
  1758. );
  1759. $oIndex = substr($t2, 0, 2);
  1760. $useO = $oAttr[$oIndex];
  1761. if (in_array($user->group, $this->hasGroupPowers)) {
  1762. $user->sendRoom('<bl u="' . $user->id . '" d="' . $u->id . '" t="blastpro" v="' . $blastpro . '" r="' . $blaster . '" o="' . $useO . '" />', false);
  1763. }
  1764. $u->joinRoom($user->chat, 0, true);
  1765. }
  1766. break;
  1767.  
  1768. case '/g': // Ban
  1769. if (in_array($user->rank, array(1, 2, 4)) && $this->higherRank($user->rank, $u->rank, true)) {
  1770. if ($user->rank == 2) { // Mod8
  1771. $hours = round((($param3 / 60) / 60), 1);
  1772. $mod8 = $user->haspower(3);
  1773. if ($hours > 6 && !$mod8 || $mod8 && $hours > 8) {
  1774. return;
  1775. }
  1776. }
  1777.  
  1778. $time = $param3 == 0 ? strtotime("+ 20 years") : strtotime("+ {$param3} seconds");
  1779.  
  1780. if ($game !== false && is_numeric($game) && $game > 0) {
  1781. if ($user->hasPower($game)) {
  1782. $this->mysql->query("insert into `bans` (`chatid`, `userid`, `unbandate`, `ip`, `type`) values ('{$user->chat}', '{$u->id}', '{$time}', '{$u->ipaddr}', 'w{$game}');");
  1783. $user->sendRoom('<m p="' . $p . '" t="/g' . $param . '" w="' . $game . '" u="' . $user->id . '" d="' . $u->id . '" />');
  1784. $u->sendPacket('<c p="' . $p . '" w="' . $game . '" t="/g' . $time . '" u="' . $user->id . '" d="' . $u->id . '" />');
  1785. if (in_array($user->group, $this->hasGroupPowers)) {
  1786. $user->sendRoom('<bl u="' . $user->id . '" d="' . $u->id . '" t="blastban" v="1" r="' . $this->BlastCor($u->rank) . '" o="' . $this->BlastCargo($u->rank) . '" />', false);
  1787. }
  1788. $u->joinRoom($user->chat, false, true, 0);
  1789. } else {
  1790. $user->sendPacket('<n t="You don\'t have that power!" />');
  1791. }
  1792. } else {
  1793. $this->mysql->query("insert into `bans` (`chatid`, `userid`, `unbandate`, `ip`) values ('{$user->chat}', '{$u->id}', '{$time}', '{$u->ipaddr}');");
  1794. $user->sendRoom('<m p="' . $this->getAttribute($packet, 'p') . '" t="/g' . $param . '" u="' . $user->id . '" d="' . $u->id . '" />');
  1795. $u->sendPacket('<c p="' . $this->getAttribute($packet, 'p') . '" t="/g' . $time . '" u="' . $this->getAttribute($packet, 'u') . '" d="' . $this->getAttribute($packet, 'd') . '" />');
  1796. $u->sendRoom("<l u=\"{$u->id}\" />");
  1797. if (in_array($user->group, $this->hasGroupPowers)) {
  1798. $user->sendRoom('<bl u="' . $user->id . '" d="' . $u->id . '" t="blastban" v="1" r="' . $this->BlastCor($u->rank) . '" o="' . $this->BlastCargo($u->rank) . '" />', false);
  1799. }
  1800. $u->sendRoom("<l u=\"{$u->id}\" />"); // Left off here [Blasts]
  1801. $u->joinRoom($user->chat, false, true, 2);
  1802. }
  1803. }
  1804. break;
  1805.  
  1806. case "/k": // Kick/Boot
  1807. If ( in_Array( $user->rank, Array(
  1808. 1,
  1809. 2,
  1810. 4
  1811. ) ) && $this->higherRank( $user->rank, $u->rank, True ) )
  1812. {
  1813. $args = explode( "#", $pee = $this->getAttribute( $packet, 'p' ) );
  1814. If ( count( $args ) == 2 )
  1815. {
  1816. $chat = $this->mysql->fetch_Array( "select * from `chats` where `id`='{$this->mysql->sanatize($args[1])}' or `name`='{$this->mysql->sanatize($args[1])}';" );
  1817. If ( empty( $chat ) )
  1818. {
  1819. $user->sendPacket( "<n t=\"Este chat nao existe!\" />" );
  1820. } //empty( $chat )
  1821. Else
  1822. {
  1823. $user->sendRoom( "<m p=\"{$pee}\" t=\"/k\" u=\"{$user->id}\" d=\"{$u->id}\" />", False );
  1824. $u->sendPacket( "<q p2=\"{$pee}\" u=\"{$u->id}\" d2=\"{$user->id}\" r=\"{$chat[0]['id']}\" />" );
  1825. $u->joinRoom( $chat[ 0 ][ 'id' ], True );
  1826. $user->sendRoom( "<l u=\"{$u->id}\" />" );
  1827. }
  1828. } //count( $args ) == 2
  1829. Else
  1830. {
  1831. If ( count( $args ) == 3 && !$user->hasPower( 121 ) )
  1832. {
  1833. $user->sendPacket( "<n t=\"Voce nao tem o power ZAP!\" />" );
  1834. } //count( $args ) == 3 && !$user->hasPower( 121 )
  1835. Else
  1836. {
  1837. $user->sendRoom( "<m p=\"{$pee}\" t=\"/k\" u=\"{$user->id}\" d=\"{$u->id}\" />", False );
  1838. $u->sendPacket( "<c p=\"{$pee}\" t=\"/k\" u=\"{$user->id}\" d=\"{$u->id}\" />" );
  1839. $user->sendRoom( '<bl u="' . $user->id . '" d="' . $u->id . '" t="blastkick" v="' . $blastkick . '" r="' . $this->BlastCor( $u->rank ) . '" o="' . $this->BlastCargo( $u->rank ) . '" />', False );
  1840. $this->disconnect( $u->index );
  1841. $user->sendRoom( "<l u=\"{$u->id}\" />" );
  1842. }
  1843. }
  1844. } //in_Array( $user->rank, Array( 1, 2, 4 ) ) && $this->higherRank( $user->rank, $u->rank, True )
  1845. Else
  1846. {
  1847. $this->disconnect( $user->index );
  1848. }
  1849. break;
  1850.  
  1851. case '/u':
  1852. if (in_array($user->rank, array(1, 2, 4)) && ($u->rank == 16 && $this->higherRank($user->rank, $u->rank, true))) {
  1853. $this->mysql->query("delete from `bans` where `chatid`='{$user->chat}' and `userid`='{$u->id}' or `chatid`='{$user->chat}' and `ip`='{$u->ipaddr}';");
  1854. $user->sendRoom('<m t="/u" u="' . $user->id . '" d="' . $u->id . '" />');
  1855. $u->sendPacket('<c u="0" d="' . $u->id . '" t="/u" />');
  1856. $u->joinRoom($user->chat, 0, true);
  1857. }
  1858. break;
  1859. }
  1860. break;
  1861. default:
  1862. $this->disconnect($user->index);
  1863. break;
  1864. }
  1865. }
  1866.  
  1867. public function BlastCor($rank) {
  1868. $ranks = array(1, 2, 3, 4, 5);
  1869. $cor = "0x009900";
  1870. if ($rank == 5)
  1871. $cor = "0x009900";
  1872. if ($rank == 4)
  1873. $cor = "0xFF9900";
  1874. if ($rank == 3)
  1875. $cor = "0x3366FF";
  1876. if ($rank == 2)
  1877. $cor = "0xFFFFFF";
  1878. if ($rank == 1)
  1879. $cor = "X";
  1880. return $cor;
  1881. }
  1882.  
  1883. public function BlastCargo($rank) {
  1884. $ranks = array(1, 2, 3, 4, 5);
  1885. $cargo = "0x009900";
  1886. if ($rank == 5)
  1887. $cargo = "r"; // Guest
  1888. if ($rank == 4)
  1889. $cargo = "M"; // Owner
  1890. if ($rank == 3)
  1891. $cargo = "e"; // Member
  1892. if ($rank == 2)
  1893. $cargo = "m"; // Mod
  1894. if ($rank == 1)
  1895. $cargo = "X"; // Main Owner
  1896. return $cargo;
  1897. }
  1898.  
  1899. public function mask($packet) {
  1900. $length = strlen($packet);
  1901.  
  1902. if ($length < 126) {
  1903. return pack('CC', 0x80 | (0x1 & 0x0f), $length) . $packet;
  1904. } elseif ($length < 65536) {
  1905. return pack('CCn', 0x80 | (0x1 & 0x0f), 126, $length) . $packet;
  1906. } else {
  1907. return pack('CCNN', 0x80 | (0x1 & 0x0f), 127, $length) . $packet;
  1908. }
  1909. }
  1910.  
  1911. public function unmask($packet) {
  1912. try {
  1913. $length = ord($packet[1]) & 127;
  1914. if ($length == 126) {
  1915. $masks = substr($packet, 4, 4);
  1916. $data = substr($packet, 8);
  1917. } elseif ($length == 127) {
  1918. $masks = substr($packet, 10, 4);
  1919. $data = substr($packet, 14);
  1920. } else {
  1921. $masks = substr($packet, 2, 4);
  1922. $data = substr($packet, 6);
  1923. }
  1924.  
  1925. $response = '';
  1926. $dlength = strlen($data);
  1927. for ($i = 0; $i < $dlength; ++$i) {
  1928. $response .= $data[$i] ^ $masks[$i % 4];
  1929. }
  1930.  
  1931. return $response == '' ? false : $response;
  1932. } catch (Exception $e) {
  1933. return false;
  1934. }
  1935. }
  1936.  
  1937. public function doLogin($user, $pass) {
  1938. /* Variables */
  1939. $vals = array();
  1940. $p = array();
  1941. $pp = '';
  1942. $dO = '';
  1943. $powerO = '';
  1944.  
  1945. $user = $this->mysql->fetch_array('select * from `users` where `username`=\'' . $this->mysql->sanatize($user) . '\';');
  1946. if (isset($user[0])) {
  1947. $bride = $user[0]['d2'] == 0 ? false : $user[0]['bride'];
  1948.  
  1949. if ((floor(($user[0]['days'] - time()) / (24 * 3600) + 0.3) >= 1 ? floor(($user[0]['days'] - time()) / (24 * 3600) + 0.3) : 0) >= 1) {
  1950. $upowers = $this->mysql->fetch_array('select * from `userpowers` where `userid`=' . $user[0]['id'] . ';');
  1951. $spowers = $this->mysql->fetch_array('select * from `powers` where `name` not like \'%(Undefined)%\';');
  1952.  
  1953. foreach ($spowers as $power) {
  1954. $vals[$power['id']] = array($power['section'], $power['subid']);
  1955. $p[$power['section']] = 0;
  1956. }
  1957.  
  1958. foreach ($upowers as $power) {
  1959. if ($power['count'] >= 1 && isset($vals[$power['powerid']]) && isset($p[$vals[$power['powerid']][0]])) {
  1960. $str = $power['powerid'] . '=' . ($power['count'] > 1 ? ($power['count'] - 1) : 1) . '|';
  1961. $p[$vals[$power['powerid']][0]] += $vals[$power['powerid']][1];
  1962. $dO .= $str;
  1963. if ($power['count'] > 1) {
  1964. $powerO .= $str;
  1965. }
  1966. }
  1967. }
  1968.  
  1969. foreach ($p as $i => $u) {
  1970. $pp .= " d" . (substr($i, 1) + 4) . "=\"{$u}\"";
  1971. }
  1972. }
  1973.  
  1974. $this->mysql->query("update `users` set `dO`='{$this->mysql->sanatize($powerO)}' where `username`='{$this->mysql->sanatize($user[0]['username'])}';");
  1975.  
  1976. return "<v RL=\"1\" i=\"{$user[0]['id']}\" c=\"{$user[0]['xats']}\" dt=\"0\" n=\"{$user[0]['username']}\" k1=\"{$user[0]['k']}\" k2=\"{$user[0]['k2']}\" k3=\"{$user[0]['k3']}\" bride=\"{$bride}\" d0=\"{$user[0]['d0']}\" d1=\"{$user[0]['days']}\" d2=\"{$user[0]['d2']}\" d3=\"\"{$pp} dx=\"{$user[0]['xats']}\" dO=\"{$powerO}\" PowerO=\"{$powerO}\" />";
  1977. }
  1978. return false;
  1979. }
  1980.  
  1981. public function getUserByID($id, $chat = null) {
  1982. if ($id == 2 || $id == 0) {
  1983. return false;
  1984. }
  1985. foreach ($this->users as $user) {
  1986. if ($user->id == $id && ($chat == null || $user->chat == $chat)) {
  1987. return $user->online ? $user : false;
  1988. }
  1989. }
  1990. return false;
  1991. }
  1992.  
  1993. function higherRank($rank1, $rank2, $minMod = false) {
  1994. if ($rank1 == $rank2) {
  1995. return false;
  1996. }
  1997. $order = array(1, 2, 3, 4);
  1998. if (in_array($rank1, $order) && !in_array($rank2, $order)) {
  1999. return true;
  2000. }
  2001. if ($rank1 == 1) {
  2002. return true;
  2003. }
  2004. if ($rank1 == 4 && $rank2 != 1) {
  2005. return true;
  2006. }
  2007. if ($rank1 == 2 && $rank2 != 1 && $rank2 != 4) {
  2008. return true;
  2009. }
  2010. if ($minMod == true) {
  2011. return false;
  2012. }
  2013. if ($rank1 == 3 && $rank2 != 1 && $rank2 != 4 && $rank2 != 2) {
  2014. return true;
  2015. }
  2016. return false;
  2017. }
  2018.  
  2019. function objectToArray($object) {
  2020. $array = array();
  2021. foreach ($object as $member => $data) {
  2022. $array[$member] = $data;
  2023. }
  2024. return $array;
  2025. }
  2026.  
  2027. public function getAttribute($xml, $attName, $reverse = false) {
  2028. $att = $this->objectToArray($xml->attributes());
  2029. if ($reverse == true) {
  2030. array_reverse($att);
  2031. }
  2032.  
  2033. foreach ($att as $a => $b) {
  2034. if ($a == $attName) {
  2035. $b = htmlspecialchars($b);
  2036. return $b;
  2037. }
  2038. }
  2039. return false;
  2040. }
  2041.  
  2042. public function getMultiAttr($xml, $names = array(), $values = array()) {
  2043. setType($names, 'array');
  2044. if (!method_exists($xml, 'attributes')) {
  2045. return array();
  2046. }
  2047.  
  2048. foreach ($names as $u) {
  2049. $values[$u] = false;
  2050. }
  2051.  
  2052. foreach ($xml->attributes() as $i => $u) {
  2053. if (in_array($i, $names) || empty($names)) {
  2054. $values[$i] = ((string) ((string) $u));
  2055. }
  2056. }
  2057.  
  2058. return $values;
  2059. }
  2060.  
  2061. public function disconnect($userID, $logout = null, $num = null, $chatid = null) {
  2062. if (isset($this->users[$userID]) && $user = $this->users[$userID]) {
  2063. if (!is_null($logout) && $user->online) {
  2064. $user->sendPacket("<logout />");
  2065. }
  2066.  
  2067. if (is_resource($user->sock)) {
  2068. socket_close($user->sock);
  2069. $user->sock = null;
  2070. }
  2071. $user->online = false;
  2072.  
  2073. return true;
  2074. }
  2075. return false;
  2076. }
  2077.  
  2078. public function ipban($ip, $dcall = true) {
  2079. if (!filter_var($ip, FILTER_VALIDATE_IP)) {
  2080. return false;
  2081. }
  2082.  
  2083. $this->ipbans[] = $ip;
  2084. if ($dcall == true) {
  2085. foreach ($this->users as $u) {
  2086. if ($u->ipaddr == $ip) {
  2087. $this->disconnect($u->index);
  2088. }
  2089. }
  2090. }
  2091. $bans = json_encode($this->ipbans);
  2092. $this->mysql->query("update `server` set `ipbans`='{$this->mysql->sanatize($bans)}';");
  2093. return true;
  2094. }
  2095.  
  2096. public function ipUnban($ip) {
  2097. if (!filter_var($ip, FILTER_VALIDATE_IP)) {
  2098. return false;
  2099. }
  2100. foreach ($this->ipbans as $index => $addr) {
  2101. if ($ip == $addr) {
  2102. unset($this->ipbans[$index]);
  2103. $bans = json_encode($this->ipbans);
  2104. $this->mysql->query("update `server` set `ipbans`='{$this->mysql->sanatize($bans)}';");
  2105. return true;
  2106. } else {
  2107. continue;
  2108. }
  2109. }
  2110. return false;
  2111. }
  2112.  
  2113.  
  2114.  
  2115. public function spamfilter($element, $user, $ms = 800, $time = null, $dc = true) {
  2116. if (is_null($time)) {
  2117. $time = round(microtime(true) * 1000);
  2118. }
  2119. if (isset($user->last[$element]) && ($user->last[$element] + $ms) >= $time) {
  2120. return (is_null($dc) ? true : $this->disconnect($user->index));
  2121. }
  2122. $user->last[$element] = $time;
  2123. return false;
  2124. }
  2125.  
  2126. }
  2127.  
  2128. class client {
  2129.  
  2130. public $sock, $parent;
  2131. public $bride, $rank, $id, $username, $nickname, $k, $k2, $k3, $password, $avatar, $url, $powers, $room, $xats, $days, $chat, $banned, $hidden = false, $pool = 0, $switchingPools = false;
  2132. public $d0, $d1, $d2, $d3, $d4, $d5, $d6, $dt, $dx, $dO, $p0, $p1, $p2, $p4, $PowerO, $d7, $p3, $homepage, $h, $group, $away = false, $pStr;
  2133. public $loginKey = null, $last = array(), $authenticated = null, $online = false, $disconnect = false, $rExpire = 0, $chatPass = false, $pawn = '';
  2134. public $mobready = false, $buffer = '';
  2135.  
  2136. public function __construct(&$socket, &$parent, $index, $ipaddr, $mobile = false) {
  2137. list($this->index, $this->sock, $this->parent, $this->ipaddr, $this->mobile) = array(
  2138. $index, $socket, $parent, $ipaddr, $mobile
  2139. );
  2140. }
  2141. public function listen( $null = null, $ipc = 0 )
  2142. {
  2143. $read = $this->socket;
  2144. Foreach ( $this->users as $user )
  2145. {
  2146. $read[ ] = $user->sock;
  2147. } //$this->users as $user
  2148. $except = $read;
  2149. If ( @socket_select( $read, $null, $except, null ) < 1 )
  2150. {
  2151. continue;
  2152. } //@socket_select( $read, $null, $except, null ) < 1
  2153.  
  2154. Foreach ( $this->socket as $i => $psock )
  2155. {
  2156. If ( in_Array( $psock, $read ) )
  2157. {
  2158. switch ( (int) $i )
  2159. {
  2160. case 0:
  2161. $socket = socket_accept( $psock );
  2162. socket_set_nonblock($socket);
  2163. If ( !is_resource( $socket ) || count( $this->users ) >= $this->config->max_total )
  2164. {
  2165. @socket_close( $socket );
  2166. break;
  2167. } //!is_resource( $socket ) || count( $this->users ) >= $this->config->max_total
  2168.  
  2169. socket_getpeername( $socket, $ip );
  2170. Foreach ( $this->users as $user )
  2171. {
  2172. If ( $user->ipaddr == $ip )
  2173. {
  2174. $ipc++;
  2175. } //$user->ipaddr == $ip
  2176. } //$this->users as $user
  2177.  
  2178. If ( $ipc > $this->config->max_per_ip || in_Array( $ip, $this->ipbans ) )
  2179. {
  2180. Foreach ( $this->users as $user )
  2181. {
  2182. If ( $user->ipaddr == $ip )
  2183. {
  2184. $this->disconnect( $user->index );
  2185. } //$user->ipaddr == $ip
  2186. } //$this->users as $user
  2187. break;
  2188. } //$ipc > $this->config->max_per_ip || in_Array( $ip, $this->ipbans )
  2189.  
  2190. do
  2191. {
  2192. $index = $this->mysql->rand();
  2193. } while ( Isset( $this->users[ $index ] ) );
  2194.  
  2195. $this->users[ $index ] = new client( $socket, $this, $index, $ip );
  2196. break;
  2197.  
  2198. case 1:
  2199. $this->socket[ ] = socket_accept( $psock );
  2200. break;
  2201.  
  2202. } //(int) $i
  2203. } //in_Array( $psock, $read )
  2204. } //$this->socket as $i => $psock
  2205. If ( !is_Array( $except ) )
  2206. {
  2207. $except = Array( );
  2208. } //!is_Array( $except )
  2209.  
  2210. Foreach ( $this->users as $index => $user )
  2211. {
  2212. If ( in_Array( $user->sock, $except ) || !$user->sock )
  2213. {
  2214. unset( $this->users[ $index ] );
  2215. } //in_Array( $user->sock, $except ) || !$user->sock
  2216. ElseIf ( in_Array( $user->sock, $read ) )
  2217. {
  2218. $input = '';
  2219. while(@socket_recv($user->sock, $buf, (2048 * 2048), 0) >= 1)
  2220. {
  2221. $input .= $buf;
  2222. }
  2223. If ( trim( $input ) == '' || ord( substr( $input, 0, 1 ) ) == 136 )
  2224. {
  2225. unset( $this->users[ $index ] );
  2226. continue;
  2227. } //trim( $input ) == '' || ord( substr( $input, 0, 1 ) ) == 136
  2228. ElseIf ( substr_count( $input, chr( 0 ) ) <= 1 )
  2229. {
  2230. $this->handle( $input, $user );
  2231. } //substr_count( $input, chr( 0 ) ) <= 1
  2232. } //in_Array( $user->sock, $read )
  2233. } //$this->users as $index => $user
  2234. }
  2235. public function resetDetails($id, $bans = null) {
  2236. $user = $this->parent->mysql->fetch_array("select * from `users` where `id`='{$this->parent->mysql->sanatize($id)}' and `id` not in(0, 2);");
  2237. if (empty($user)) {
  2238. $this->guest = true;
  2239. } else {
  2240. if ($user[0]['username'] == '') {
  2241. list($this->guest, $this->k, $this->k2, $this->k3) = array(
  2242. true, $user[0]['k'], $user[0]['k2'], $user[0]['k3']
  2243. );
  2244. } else {
  2245. $this->xats = $user[0]['xats'];
  2246. $this->days = floor(($user[0]['days'] - time()) / (24 * 3600) + 0.3) >= 1 ? floor(($user[0]['days'] - time()) / (24 * 3600) + 0.3) : 0;
  2247. $this->username = $user[0]['username'];
  2248. $this->password = $user[0]['password'];
  2249. $this->enabled = $user[0]['enabled'];
  2250. $this->k = $user[0]['k'];
  2251. $this->k2 = $user[0]['k2'];
  2252. $this->k3 = $user[0]['k3'];
  2253. $this->PowerO = $user[0]['dO'];
  2254. $this->powers = $user[0]['powers'];
  2255. $this->avatar = $user[0]['avatar'];
  2256. $this->url = $user[0]['url'];
  2257. $this->d1 = 0;
  2258. $this->d2 = $user[0]['d2'];
  2259. $this->bride = $user[0]['bride'];
  2260. $this->d3 = null;
  2261. $this->pawn = $user[0]['custpawn'] == 'off' ? '' : $user[0]['custpawn'];
  2262.  
  2263. if ($this->mobile) {
  2264. $this->nickname = $this->username == '' ? 'Unregistered' : $this->username;
  2265. } else {
  2266. $this->nickname = explode("##", $user[0]['nickname'], 2);
  2267. $this->nickname[0] = htmlspecialchars_decode($this->nickname[0]);
  2268. $this->nickname = count($this->nickname) > 1 ? implode("##", $this->nickname) : $this->nickname[0];
  2269. }
  2270.  
  2271. if (true || $user[0]['torched'] != 1) { // Torching - Add Later
  2272. if (!$this->getPowers()) {
  2273. return false;
  2274. }
  2275.  
  2276. $this->dO = $user[0]['dO'];
  2277. }
  2278. $this->dt = null;
  2279. $this->guest = false;
  2280. }
  2281.  
  2282. $trolls = json_decode($user[0]['trolls'], true);
  2283. if (is_array($trolls)) {
  2284. foreach ($trolls as $i => $u) {
  2285. $this->{$i} = $u;
  2286. }
  2287. }
  2288. }
  2289.  
  2290. if ($this->guest === true) {
  2291. $this->username = '';
  2292. }
  2293. return true;
  2294. }
  2295.  
  2296. public function getPowers($pV = array()) {
  2297. if ($this->days < 1)
  2298. {
  2299. for ($i = 0; $i <= $this->parent->config->pcount; $this->{'p' . $i++} = 0);
  2300. return true;
  2301. }
  2302.  
  2303. $powers = $this->parent->mysql->fetch_array('select * from `userpowers` where `userid`=' . $this->id . ';');
  2304. $powerv = $this->parent->mysql->fetch_array('select `id`, `section`, `subid` from `powers` where `name` not like \'%(Undefined)%\';');
  2305. $pv = $test = $final = array();
  2306. foreach ($powerv as $power) {
  2307. $pv[$power['id']] = array('sect' => $power['section'], 'sub' => (int) $power['subid']);
  2308. $test[$power['section']] = 0;
  2309. $last[$power['section']] = 0;
  2310. }
  2311.  
  2312. foreach ($powers as $power) {
  2313. $test[$pv[$power['powerid']]['sect']] += $pv[$power['powerid']]['sub'];
  2314. }
  2315.  
  2316. foreach ($test as $sect => $val) {
  2317. if ((int) $val != (int) $this->{$sect . 'v'}) {
  2318. return false;
  2319. }
  2320. }
  2321.  
  2322. foreach ($powers as $power) {
  2323. if (isset($pv[$power['powerid']])) {
  2324. $power = $pv[$power['powerid']];
  2325. if ((int) $this->{$power['sect'] . 'v'} & $test[$power['sect']]) {
  2326. if (!((int) $power['sub'] & $test[$power['sect']])) {
  2327. return false;
  2328. }
  2329.  
  2330. if (!($this->{'m' . substr($power['sect'], 1)} & (int) $power['sub'])) {
  2331. $last[$power['sect']] += (int) $power['sub'];
  2332. }
  2333. }
  2334. }
  2335. }
  2336.  
  2337. $this->pStr = '';
  2338. foreach ($test as $sect => $u) {
  2339. $this->{$sect} = $last[$sect];
  2340. $this->pStr .= $sect . '="' . $this->{$sect} . '" ';
  2341. }
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.  
  2350. return true;
  2351. }
  2352.  
  2353.  
  2354. public function updateDetails() {
  2355. $upowers = $this->parent->mysql->fetch_array('select * from `userpowers` where `userid`=' . $this->id . ';');
  2356. $spowers = $this->parent->mysql->fetch_array('select * from `powers` where `name` not like \'%(Undefined)%\';');
  2357.  
  2358. $vals = array();
  2359. $p = array();
  2360. $powerO = '';
  2361.  
  2362. foreach ($spowers as $power)
  2363. {
  2364. $vals[$power['id']] = array($power['section'], $power['subid']);
  2365. $p[$power['section']] = 0;
  2366. }
  2367.  
  2368. foreach ($upowers as $power)
  2369. {
  2370. if ($power['count'] >= 1 && isset($vals[$power['powerid']]) && isset($p[$vals[$power['powerid']][0]]))
  2371. {
  2372. $str = $power['powerid'] . '=' . ($power['count'] > 1 ? ($power['count'] - 1) : 1) . '|';
  2373. $p[$vals[$power['powerid']][0]] += $vals[$power['powerid']][1];
  2374. if ($power['count'] > 1) {
  2375. $powerO .= $str;
  2376. }
  2377. }
  2378. }
  2379. if ($this->id != 0 && $this->id != 2 && $this->mobile == false) {
  2380. $this->parent->mysql->query(
  2381. "update `users` set
  2382. `nickname`='{$this->parent->mysql->sanatize($this->nickname)}',
  2383. `avatar`='{$this->parent->mysql->sanatize($this->avatar)}',
  2384. `url`='{$this->parent->mysql->sanatize($this->url)}',
  2385. `dO`='{$this->parent->mysql->sanatize($powerO)}',
  2386. `connectedlast`='{$this->ipaddr}'
  2387. where `id`='{$this->parent->mysql->sanatize($this->id)}';"
  2388. );
  2389. }
  2390. return ($this->id != 0 && $this->id != 2) ? true : false;
  2391. }
  2392.  
  2393. public function hasPower($power) {
  2394. list($subid, $section) = array(
  2395. pow(2, $power % 32),
  2396. $power >> 5
  2397. );
  2398.  
  2399. return $this->{'p' . $section} & $subid ? true : false;
  2400. ;
  2401. }
  2402.  
  2403. public function authenticate($packet) {
  2404. //print_r($packet->Attributes());
  2405. /* Load Packet Information */
  2406. /* Load Packet / Values */
  2407. $attributes = array('u', 'N', 'k', 'pool', 'f', 'auth1', 'auth2', 'h', 'd0', 'a', 'c', 'banned', 'r');
  2408. for ($i = 0; $i <= $this->parent->config->pcount; $i++) {
  2409. array_push($attributes, 'd' . ($i + 4));
  2410. array_push($attributes, 'm' . $i);
  2411. }
  2412.  
  2413. $info = $this->getMultiAttr($packet, $attributes);
  2414.  
  2415. for ($i = 0; $i <= $this->parent->config->pcount; $i++) {
  2416. $this->{'p' . $i . 'v'} = (int) $info['d' . ($i + 4)];
  2417. $this->{'m' . $i} = (int) $info['m' . $i];
  2418. }
  2419. /* End */
  2420. $this->id = (string) $info['u'];
  2421. $this->d0 = (integer) $info['d0'];
  2422. $this->f = (integer) $info['f'];
  2423. $n = (string) $info['N'];
  2424. $k = (integer) $info['k'];
  2425. $pool = $this->pool;
  2426.  
  2427.  
  2428. if ($this->mobile) {
  2429. $this->f |= 0x0200;
  2430. }
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437. $this->b = $this->f & 8 ? true : false;
  2438. $chat = (int) $info['c'];
  2439.  
  2440. if ($this->days < 1)
  2441. {
  2442.  
  2443. for ($i = 0; $i <= $this->parent->config->pcount; $i++)
  2444. {
  2445. $this->pStr .= 'p' . $i . '="0" ';
  2446. }
  2447. } else {
  2448. for ($i = 0; $i <= $this->parent->config->pcount; $i++)
  2449. {
  2450. $this->{'p' . $i . 'v'} = isset($info['d' . ($i + 4)]) ? $info['d' . ($i + 4)] : 0;
  2451. $this->{'m' . $i} = isset($info['m' . $i]) ? $info['m' . $i] : 0;
  2452. $this->pStr .= 'p' . $i . '="' . $this->{'p' . $i . 'v'} . '" ';
  2453. }
  2454. }
  2455. /* End */
  2456. /* Reset details, Check powers */
  2457. if (!$this->resetDetails($this->id)) {
  2458. return false;
  2459. }
  2460. $this->url = (string) $info['h'];
  2461. $this->avatar = (string) $info['a'];
  2462. $xInfo = $this->parent->mysql->fetch_Array( "select * from `chats` where `id`='{$this->parent->mysql->sanatize($chat)}';" );
  2463. if(isset($xInfo)){
  2464. $pBot = $this->parent->mysql->fetch_Array( "select * from `chat_powers` where `chat`='{$this->parent->mysql->sanatize($xInfo[0]['name'])}' and power=150;" );
  2465. }
  2466. /* End */
  2467. /* Bot Protection */
  2468. if (!$this->mobile) {
  2469. $this->bot1 = (int) $info['auth1'];
  2470. $this->bot2 = (int) $info['auth2'];
  2471.  
  2472.  
  2473.  
  2474.  
  2475.  
  2476.  
  2477. $bot2 = floor(pow(2, $this->loginShift % 27));
  2478. $bot1 = floor(2 << ($this->loginKey % 94)) % $this->loginTime + $this->loginKey;
  2479.  
  2480. if ($bot1 != $this->bot1 || $bot2 != $this->bot2) {
  2481. return false;
  2482. }
  2483. }
  2484. /* End */
  2485. /* Chat Password [get main] */
  2486. if ($info['r'] !== false) {
  2487. $this->chatPass = $info['r'];
  2488. }
  2489. /* Sanatize Name / Explode Status */
  2490. $this->nickname = $this->getAttribute($packet, 'n');
  2491. $this->nickname = explode('##', $this->nickname, 2);
  2492. if (count($this->nickname) > 1) {
  2493. $this->nickname[1] = htmlspecialchars(str_replace("", "", $this->nickname[1]));
  2494. $this->nickname = implode('##', $this->nickname);
  2495. } else {
  2496. $this->nickname = $this->nickname[0];
  2497. }
  2498. if (strlen($this->nickname) > 255) {
  2499. //return false;
  2500. }
  2501. /* End */
  2502. /* Just some information checking for guest system, + user exists */
  2503. if ($this->guest == true && isset($this->enabled) && $this->id != 2) {
  2504. return false;
  2505. } elseif ($this->id != 2 && is_numeric($k)) {
  2506. $user = $this->parent->mysql->fetch_array("select * from `users` where `id`='{$this->parent->mysql->sanatize($this->id)}' and `k`='{$this->parent->mysql->sanatize($k)}' and `id`!='' and `k`!='';");
  2507. if (empty($user)) {
  2508. return false;
  2509. } elseif ($user[0]['username'] == 'Unregistered') {
  2510. $this->guest = true;
  2511. } else {
  2512. $this->guest = false;
  2513. }
  2514. } else {
  2515. $this->guest = true;
  2516. }
  2517. /* End */
  2518. $this->updateDetails();
  2519. $this->authenticated = true;
  2520. return $this->joinRoom($chat, 1, false, $pool);
  2521. }
  2522.  
  2523. public function getAttribute($xml, $name) {
  2524. if (method_exists($xml, 'attributes')) {
  2525. foreach ($xml->attributes() as $a => $b) {
  2526. if ($a == $name)
  2527. return (string) $b;
  2528. }
  2529. }
  2530. return false;
  2531. }
  2532.  
  2533. public function getMultiAttr($xml, $names = array(), $values = array()) {
  2534. setType($names, 'array');
  2535. if (!method_exists($xml, 'attributes')) {
  2536. return array();
  2537. }
  2538. foreach ($names as $u) {
  2539. $values[$u] = false;
  2540. }
  2541. foreach ($xml->attributes() as $i => $u) {
  2542. if (in_array($i, $names)) {
  2543. $values[$i] = mb_convert_encoding((string) $u, "utf-8");
  2544. }
  2545. }
  2546. return $values;
  2547. }
  2548.  
  2549. public function message($t, $ex = true) {
  2550. $this->sendMessage($t, $this->id, 0, false, $ex);
  2551. }
  2552.  
  2553. public function sendMessage($t, $u = '[C]', $i = 0, $s = false, $ex = false) {
  2554. if ($u == '[C]')
  2555. $u = $this->id;
  2556. $packet = "<m t=\"{$t}\" u=\"{$u}\" i=\"{$i}\" />";
  2557. $ex != false ? $this->sendRoom($packet, $ex) : $this->sendPacket($packet);
  2558. }
  2559.  
  2560. public function sendPacket($packet) {
  2561. if ($this->sock) {
  2562. if ($this->mobile == true) {
  2563. $packet = simplexml_load_string($packet);
  2564. if (!method_exists($packet, 'getName')) {
  2565. $this->parent->disconnect($this->sock);
  2566. return false;
  2567. }
  2568.  
  2569. $json = new stdClass();
  2570. $json->tag = $packet->getName();
  2571. foreach ($packet->Attributes() as $i => $u) {
  2572. $json->{$i} = (string) $u;
  2573. }
  2574.  
  2575. $packet = json_encode($json);
  2576. $packet = $this->parent->mask($packet);
  2577. } elseif (substr($packet, -1) != chr(0)) {
  2578. $packet .= chr(0);
  2579. }
  2580.  
  2581. // socket_set_nonblock($this->sock);
  2582. if (!@socket_write($this->sock, $packet, strlen($packet))) {
  2583. $this->parent->disconnect($this->sock);
  2584. return false;
  2585. }
  2586.  
  2587. // socket_set_block($this->sock);
  2588. return true;
  2589. }
  2590. }
  2591.  
  2592. public function sendAll($packet) {
  2593. if (stristr($packet, strlen($packet) - 1, 1) != chr(0)) {
  2594. $packet = $packet . chr(0);
  2595. }
  2596. foreach ($this->parent->users as &$user) {
  2597. if (!@socket_write($user->sock, $packet, strlen($packet))) {
  2598. $this->parent->disconnect($user->index);
  2599. }
  2600. }
  2601. return true;
  2602. }
  2603.  
  2604. public function parseRank($rank) {
  2605. $ranks = array(1, 2, 3, 4, 5);
  2606. if (!is_numeric($rank)) {
  2607. switch (strtolower($rank)) {
  2608. case 'guest': return 5;
  2609. case 'owner': return 4;
  2610. case 'member': return 3;
  2611. case 'moderator': return 2;
  2612. case 'mainowner': return 1;
  2613. default: return 0;
  2614. }
  2615. } elseif (!in_array($rank, $ranks)) {
  2616. return 0;
  2617. }
  2618. return $rank;
  2619. }
  2620.  
  2621. public function rank($numrank, $word = null, $compare = null) { // Made this for the hell of it
  2622. $ranks = array(
  2623. 5 => array(5, 'guest'),
  2624. 3 => array(4, 'member'),
  2625. 2 => array(3, 'moderator'),
  2626. 4 => array(2, 'owner'),
  2627. 1 => array(1, 'mainOwner')
  2628. );
  2629. if (!in_array($numrank, $ranks)) {
  2630. $rank = $ranks[5];
  2631. } else {
  2632. $rank = $ranks[$numrank];
  2633. }
  2634. return is_null($compare) ? (is_null($word) ? $rank[0] : $rank[1]) : ($rank[0] < $ranks[$compare][0] ? true : false);
  2635. }
  2636.  
  2637. public function __destruct() {
  2638. /* It's done like this to avoid a bitch of a memory leak */
  2639. if (isset($this->id) && !isset($this->noLogout)) {
  2640. $this->sendRoom('<l u="' . $this->id . '" />', true);
  2641. }
  2642. }
  2643.  
  2644. public function joinRoom($chat, $reload = true, $nodup = false, $pool = 0, $banTick = 0) {
  2645. /* Initial Information */
  2646.  
  2647. list($this->pool, $this->hidden) = array($pool, false);
  2648.  
  2649. if (!$this->authenticated || !is_numeric($chat) || $chat < 1) {
  2650. return false;
  2651. }
  2652.  
  2653. $chat = $this->parent->mysql->fetch_array("select * from `chats` where `id`='{$this->parent->mysql->sanatize($chat)}';");
  2654. if (empty($chat)) {
  2655. return false;
  2656. }
  2657.  
  2658.  
  2659. list($this->chatid, $this->group) = array($chat[0]['id'], $chat[0]['name']);
  2660. /* Do Ranks */
  2661. $ranks = $this->parent->mysql->fetch_array("select * from `ranks` where `chatid`='{$chat[0]['id']}' and `userid`='{$this->parent->mysql->sanatize($this->id)}';");
  2662. if ($this->chatPass !== false) {
  2663. if ($this->parent->mysql->validate($this->chatPass, $chat[0]['pass']) === true) {
  2664. if (empty($ranks)) {
  2665. $this->parent->mysql->query("insert into `ranks`(`userid`, `chatid`, `f`) values({$this->id}, {$this->chatid}, 1);");
  2666. } else {
  2667. $this->parent->mysql->query("update `ranks` set `f`=1 where `userid`={$this->id} and `chatid`={$this->chatid};");
  2668. }
  2669. $ranks[0] = array(
  2670. 'userid' => $this->id,
  2671. 'chatid' => $this->chatid,
  2672. 'f' => 1,
  2673. 'tempend' => 0
  2674. );
  2675. }
  2676. }
  2677. if (!isset($ranks[0]['f'])) {
  2678. $ranks[0] = array('f' => 5);
  2679. $this->parent->mysql->query("insert into `ranks` (`userid`, `chatid`, `f`) values ('{$this->parent->mysql->sanatize($this->id)}', '{$chat[0]['id']}', '5');");
  2680. } elseif ($ranks[0]['tempend'] > 0 && $ranks[0]['tempend'] < time()) {
  2681. $ranks[0] = array("f" => 3);
  2682. $this->parent->mysql->query("update `ranks` set `f`=3, `tempend`=0 where `userid`={$this->id} and `chatid`={$this->chatid};");
  2683. } else {
  2684. $userRank = $ranks[0]['f'];
  2685. $this->rExpire = $ranks[0]['tempend'] > time() ? $ranks[0]['tempend'] : 0;
  2686. }
  2687.  
  2688. $this->rank = $ranks[0]['f'];
  2689.  
  2690. if ($this->hasPower(29) && !$this->online && in_array($this->rank & 7, array(1, 4))) {
  2691. $this->hidden = true;
  2692.  
  2693. if (!($this->f & 0x0400)) {
  2694. $this->f += 0x0400;
  2695. }
  2696. } elseif ($this->f & 0x0400) {
  2697. $this->f -= 0x0400;
  2698. }
  2699.  
  2700. $this->updateDetails();
  2701. $this->resetDetails($this->id, true);
  2702. /* End */
  2703. /* Update / Check Bans */
  2704. $game = '';
  2705. $this->banned = 0;
  2706. $this->unban = false;
  2707. $ban = $this->parent->mysql->fetch_array("select * from `bans` where `userid`='{$this->parent->mysql->sanatize($this->id)}' and `chatid`='{$this->parent->mysql->sanatize($chat[0]['id'])}' or `ip`='{$this->ipaddr}' and `chatid`='{$this->parent->mysql->sanatize($this->chatid)}' order by `unbandate` desc limit 0,1;");
  2708. if (!empty($ban) && ($this->id == $ban[0]['userid'] || $this->ipaddr == $ban[0]['ip'])) {
  2709. $ban = $ban[0];
  2710. if ($ban['unbandate'] >= $this->loginTime) {
  2711. if (substr($ban['type'], 0, 1) == 'w') {
  2712. $this->rank = 16;
  2713. $game = ' w="' . substr($ban['type'], 1) . '"';
  2714. } elseif (substr($ban['type'], 0, 1) == 'r') {
  2715. $this->rank |= (int) substr($ban['type'], 1);
  2716. } elseif (substr($ban['type'], 0, 1) == 'f') {
  2717. $this->f |= (int) substr($ban['type'], 1);
  2718. } else {
  2719. $this->rank = 16;
  2720. }
  2721.  
  2722. if (!($this->f & 0x8000)) { // desban do dunced
  2723. $this->banned = $ban['unbandate'];
  2724. }
  2725.  
  2726. if (!($this->f & 0xFF)) { // desban do gag
  2727. $this->banned = $ban['unbandate'];
  2728. }
  2729. } elseif ($this->id == $ban['userid']) {
  2730. $this->unban = true;
  2731. $this->parent->mysql->query("delete from `bans` where `userid`='{$this->parent->mysql->sanatize($this->id)}' and `chatid`='{$this->parent->mysql->sanatize($chat[0]['id'])}' and `unbandate`<={$this->loginTime};");
  2732. }
  2733. } elseif (empty($ban) && $this->b == true) {
  2734. $this->unban = true;
  2735. } elseif (isset($ban['unbandate'])) {
  2736. $this->sendPacket("<n t=\"You are banned for " . round(($ban['unbandate'] - time()) / 60, 1) . " more minutes.\" />");
  2737. }
  2738. /* End */
  2739. /* Chat Information */
  2740. if (empty($chat[0]['attached'])) {
  2741. $chat[0]['attached'] = array('Lobby', '1');
  2742. } else {
  2743. $info = $this->parent->mysql->fetch_array("select * from `chats` where `name`='{$this->parent->mysql->sanatize($chat[0]['attached'])}';");
  2744. if (empty($info) || $info[0]['id'] == $chat[0]['id']) {
  2745. $chat[0]['attached'] = array('Lobby', '1');
  2746. } else {
  2747. $chat[0]['attached'] = array(
  2748. 0 => $info[0]['name'],
  2749. 1 => $info[0]['id']
  2750. );
  2751. }
  2752. }
  2753. if ($chat[0]['attached'][1] == $this->chatid) {
  2754. $chat[0]['attached'] = array('0', '0');
  2755. }
  2756.  
  2757.  
  2758. if ($this->unban == true) {
  2759. $this->sendPacket('<c u="0" d="' . $this->id . '" t="/u" />');
  2760. $this->unban = false;
  2761. }
  2762. $pawn = strlen($this->pawn) == 6 ? ' pawn="' . $this->pawn . '"' : '';
  2763.  
  2764. $this->sendPacket("<i{$pawn}{$game} b=\"{$chat[0]['bg']};={$chat[0]['attached'][0]};={$chat[0]['attached'][1]};=;={$chat[0]['radio']};={$chat[0]['button']}\" f=\"{$this->f}\" ".($this->days >= 1 ? 'v="3"' : 'v="1"')." r=\"{$this->rank}\" cb=\"10\" />");
  2765. $pRankpool = $this->parent->mysql->fetch_Array( "SELECT * FROM `chat_powers` WHERE `chat`='" . $this->group . "' AND `power`=114;" );
  2766. $pBanpool = $this->parent->mysql->fetch_Array( "SELECT * FROM `chat_powers` WHERE `chat`='" . $this->group . "' AND `power`=126;" );
  2767. If ( !count( $pRankpool ) == 0 )
  2768. $this->sendPacket( '<w v="'.$pool.' 0 1" />' );
  2769. If ( !count( $pRankpool ) == 0 && !count( $pBanpool ) == 0 )
  2770. $this->sendPacket( '<w v="'.$pool.' 0 2 1" />' );
  2771. // $this->sendPacket('<w v="'.$pool.' ' . $chat[0]['pool'] . '" />');
  2772. $this->sendPacket($this->buildGp());
  2773.  
  2774. // $this->sendPacket('<gp p="0|0|1431372864|1074025493|273678340|268435456|16384|1|0|0|0|0|0|" g80="{\'mg\':\'0\',\'mb\':\'11\',\'kk\':\'0\',\'bn\':\'0\',\'ubn\':\'0\',\'prm\':\'0\',\'bge\':\'0\',\'mxt\':50,\'sme\':\'11\',\'dnc\':\'8\'}" g114="{\'m\':\'' . $chat[0]['chat'] . '\',\'t\':\'' . $chat[0]['mods'] . '\',\'rnk\':\'7\',\'b\':\'' . $chat[0]['banned'] . '\',\'v\':1}" g90="' . $chat[0]['badword'] . '" g74="' . $chat[0]['smiles'] . '" g106="' . $chat[0]['gback'] . '" g188="a91" g100="' . $chat[0]['link'] . '" u="1" />');
  2775. //@$this->sendPacket('<gp g80="{\'mg\':\'0\',\'mb\':\'11\',\'kk\':\'0\',\'bn\':\'0\',\'ubn\':\'0\',\'prm\':\'0\',\'bge\':\'0\',\'mxt\':50,\'sme\':\'11\',\'dnc\':\'8\'}" g114="{\'m\':\'' . $chat[0]['chat'] . '\',\'t\':\'' . $chat[0]['mods'] . '\',\'rnk\':\'7\',\'b\':\'' . $chat[0]['banned'] . '\',\'v\':1}" g90="' . $chat[0]['badword'] . '" g74="' . $chat[0]['gline'] . '" g106="' . $chat[0]['gback'] . '" g188="a91" g100="' . $chat[0]['link'] . '" p="0|0|1431372864|1074025493|273678340|268435456|16384|1|0|0|0|0|0|" />'); /* End */
  2776. /* Check if user is already on chat */
  2777. if ($nodup == false) {
  2778. while ($r = $this->parent->getUserByID((int) $this->id, (int) $chat[0]['id'])) {
  2779. if (is_object($r) && $r->online === true) {
  2780. $r->sendPacket("<dup />");
  2781. $r->noLogout = true;
  2782. $this->parent->disconnect($r->index, true);
  2783. }
  2784. }
  2785. }
  2786. /* End */
  2787. /* Compile, and send user list */
  2788. $this->chat = $chat[0]['id'];
  2789. $myNick = explode("##", $this->nickname, 2);
  2790. $myNick[0] = htmlspecialchars(html_entity_decode(htmlspecialchars_decode($myNick[0])));
  2791. $myNick = count($myNick) > 1 ? implode("##", $myNick) : $myNick[0];
  2792.  
  2793. $myPack = "<u{$pawn} so=\"1\" f=\"{$this->f}\" flag=\"{$this->f}\" rank=\"{$this->rank}\" u=\"{$this->id}\" ".($this->days >= 1 ? ' q="3"' : ' q="1"') . ($this->username == '' ? '' : " N=\"{$this->username}\"") . " n=\"{$myNick}\" a=\"{$this->avatar}\" h=\"{$this->url}\" d0=\"{$this->d0}\" d2=\"{$this->d2}\" bride=\"{$this->bride}\" {$this->pStr}v=\"1\" />";
  2794. $valid = simplexml_load_string($myPack);
  2795. if (!method_exists($valid, 'getName')) {
  2796. return false;
  2797. } else {
  2798. foreach ($this->parent->users as $user) {
  2799. if ($this->mobile == true && $user->mobile == true && $user->ipaddr == $this->ipaddr && $user->username != $this->username) {
  2800. $this->parent->disconnect($user->index);
  2801. }
  2802.  
  2803. if ($user->chat == $chat[0]['id'] && $user->id != $this->id && $user->pool == $this->pool) {
  2804. if (!in_array($user->id, array(0, 2)) && $user->hidden == false) {
  2805. $user->bride = $user->d2 == 0 ? null : $user->d2;
  2806. $nick = explode('##', $user->nickname, 2);
  2807. $nick[0] = htmlspecialchars(html_entity_decode(htmlspecialchars_decode($nick[0])));
  2808. $nick = count($nick) > 1 ? implode('##', $nick) : $nick[0];
  2809. $pawn = strlen($user->pawn) == 6 ? ' pawn="' . $user->pawn . '"' : '';
  2810.  
  2811. $packet = "<u{$pawn} flag=\"{$user->f}\" s=\"1\" f=\"{$user->f}\" rank=\"{$user->rank}\" u=\"{$user->id}\" ".($user->days >= 1 ? ' q="3"' : ' q="1"') . ($user->username == '' ? '' : " N=\"{$user->username}\"") . " n=\"{$nick}\" a=\"{$user->avatar}\" h=\"{$user->url}\" d0=\"{$user->d0}\" d2=\"{$user->d2}\" bride=\"{$user->bride}\" {$user->pStr}v=\"1\" />";
  2812. $valid = simplexml_load_string($packet);
  2813.  
  2814. if (method_exists($valid, 'getName')) {
  2815. $this->sendPacket($packet);
  2816. } else {
  2817. $this->parent->disconnect($user->index);
  2818. continue;
  2819. }
  2820. }
  2821.  
  2822. if (!in_array($this->id, array(0, 2)) && $this->hidden == false) {
  2823. $user->sendPacket($myPack);
  2824. }
  2825. }
  2826. }
  2827. }
  2828. /* End */
  2829. /* Send Previous Messages (15) */
  2830. if ($reload == true) {
  2831. $messages = $this->parent->mysql->fetch_array("select * from `messages` where `id`='{$chat[0]['id']}' and `pool`={$this->pool} order by time desc limit 0,15;");
  2832. for ($i = 0; $i < count($messages); $i++) {
  2833. $message = $messages[count($messages) - $i - 1];
  2834. if ($message['visible'] == '1') {
  2835. $this->sendPacket("<m u=\"{$message['uid']}\" n=\"{$message['name']}\" N=\"{$message['registered']}\" a=\"{$message['avatar']}\" i=\"{$message['mid']}\" t=\"{$message['message']}\" s=\"1\" />");
  2836. }
  2837. }
  2838. unset($messages);
  2839. unset($message);
  2840. }
  2841. /* End */
  2842. $this->sendPacket("<done />");
  2843. /* Other info, scrollies, protection meh */
  2844. $this->sendPacket("<m u=\"{$chat[0]['ch']}\" t=\"/s{$chat[0]['sc']}\" />");
  2845.  
  2846. if (isset($this->parent->protected[$this->chat])) {
  2847. $time = floor(($this->parent->protected[$this->chat]['end'] - time()) / 60);
  2848. switch ($this->parent->protected[$this->chat]['type']) {
  2849. case 'noguest':
  2850. $this->sendPacket("<z d=\"0\" u=\"0\" t=\"This chat is protected for another {$time} minutes. Guests cannot chat until given a higher rank.\" />");
  2851. break;
  2852. case 'unreg':
  2853. $this->sendPacket("<z d=\"0\" u=\"0\" t=\"This chat is protected for another {$time} minutes. Unregistered users cannot chat until given a higher rank.\" />");
  2854. break;
  2855. }
  2856. } elseif ($this->f & 1 && 1 == 2) {
  2857. $this->sendPacket("<logout e=\"E12\" />");
  2858. }
  2859.  
  2860. $this->online = true;
  2861. /* End */
  2862. return true;
  2863. }
  2864.  
  2865. public function buildGp( )
  2866. {
  2867. $gdata = $this->parent->mysql->fetch_Array( "SELECT * FROM `chats` WHERE `name`='" . $this->group . "';" );
  2868. $pBad = $this->parent->mysql->fetch_Array( "SELECT * FROM `chat_powers` WHERE `chat`='" . $this->group . "' AND `power`=90;" );
  2869. $pAnnounce = $this->parent->mysql->fetch_Array( "SELECT * FROM `chat_powers` WHERE `chat`='" . $this->group . "' AND `power`=112;" );
  2870. $pGback = $this->parent->mysql->fetch_Array( "SELECT * FROM `chat_powers` WHERE `chat`='" . $this->group . "' AND `power`=130;" );
  2871. $pGline = $this->parent->mysql->fetch_Array( "SELECT * FROM `chat_powers` WHERE `chat`='" . $this->group . "' AND `power`=74;" );
  2872. $gp = "<gp ";
  2873. $gp .= "p=\"0|0|1431655744|1079334229|290459972|269549572|16645|272646145|4194305|0|0|0|0|\" ";
  2874. $gp .= "g80=\"{'mm':'14','mbt':48,'ss':'14','prm':'14','dnc':'14','bdg':'8'}\" ";
  2875. $gp .= "g148=\"{'ef':'0','bk':'0','col':'','v':'32'}\" ";
  2876. If ( !count( $pBad ) == 0 )
  2877. $gp .= "g90=\"{$gdata[0]['bad']}\" ";
  2878. If ( !count( $pAnnounce ) == 0 )
  2879. {
  2880. $gp .= "g112=\"{$gdata[0]['announce']}\" ";
  2881. } //!count( $pAnnounce ) == 0
  2882. $gp .= "g246=\"{'dt':70,'v':1}\" ";
  2883. $gp .= "g256=\"{'rnk':'2','dt':65,'rt':15,'rc':'1','tg':200,'v':1}\" ";
  2884. //$gp .= "g278=\"{'ef':'0','bk':'0','v':1}\" ";
  2885. If ( $gdata[ 0 ][ 'pools' ] != null )
  2886. {
  2887. $gp .= "g114=\"{'m':'{$gdata[0]['rankpool']}','t':'{$gdata[0]['staffpool']}','rnk':'7','b':'{$gdata[0]['banned']}','v':2}\" ";
  2888. } //$gdata[ 0 ][ 'pools' ] != null
  2889. $gp .= "g100=\"{$gdata[0]['link']}\" ";
  2890. If ( !count( $pGline ) == 0 )
  2891. $gp .= "g74=\"{$gdata[0]['gline']}\" ";
  2892. If ( !count( $pGback ) == 0 )
  2893. $gp .= "g106=\"{$gdata[0]['gback']}\" ";
  2894. $gp .= "/>";
  2895. return $gp;
  2896. }
  2897.  
  2898. public function sendRoom($packet, $passme = false, $exclude = 0) {
  2899. foreach ($this->parent->users as $user) {
  2900. if (
  2901. $user->chat == $this->chat &&
  2902. $user->id != $exclude &&
  2903. (
  2904. isset($user->pool) &&
  2905. isset($this->pool) &&
  2906. $user->pool == $this->pool
  2907. )
  2908. ) {
  2909. if ($user->id != $this->id || $passme == false) {
  2910. $user->sendPacket($packet);
  2911. }
  2912. }
  2913. }
  2914. }
  2915.  
  2916. }
  2917.  
  2918. class database {
  2919.  
  2920. public $link, $host, $user, $pass, $name;
  2921. public $doe = true;
  2922.  
  2923. public function __construct($host = null, $user = null, $pass = null, $name = null) {
  2924. if ($name != null) {
  2925. $this->host = $host;
  2926. $this->user = $user;
  2927. $this->pass = $pass;
  2928. $this->name = $name;
  2929. }
  2930.  
  2931. if (!$this->connected()) {
  2932. $this->link = @mysqli_connect($this->host, $this->user, $this->pass, $this->name);
  2933. if (!$this->connected()) {
  2934. $this->error("Failed to connect to `{$this->host}`.`{$this->name}` using password [" . (empty($this->pass) ? "NO" : 'YES') . "]");
  2935. }
  2936. } return true; // Cause I can put it there if I want to
  2937. }
  2938.  
  2939. public function connected() {
  2940. return @mysqli_ping($this->link) ? true : false;
  2941. }
  2942.  
  2943. public function error($error) {
  2944. print $error . chr(10);
  2945. if ($this->doe == true) {
  2946. exit('line:' . __LINE__);
  2947. }
  2948. }
  2949.  
  2950. public function query($query = "") {
  2951. if (!is_string($query)) {
  2952. return false;
  2953. }
  2954. $this->__construct();
  2955. $return = mysqli_query($this->link, $query);
  2956. return $return ? $return : false;
  2957. }
  2958.  
  2959. public function fetch_array($query, $return = array()) {
  2960. $this->__construct();
  2961. if (!is_string($query) || !($res = $this->query($query))) {
  2962. return array();
  2963. }
  2964. while ($data = mysqli_fetch_assoc($res)) {
  2965. $return[] = $data;
  2966. }
  2967. return !empty($return) ? $return : array();
  2968. }
  2969.  
  2970. public function sanatize($data) {
  2971. if (is_array($data)) {
  2972. return array_map(array($this, 'sanatize'), $data);
  2973. }
  2974. if (function_exists("mb_convert_encoding")) {
  2975. $data = mb_convert_encoding($data, "UTF-8", 'auto');
  2976. }
  2977. return $this->link->real_escape_string($data);
  2978. }
  2979.  
  2980. public function rand($length = 32, $low = true, $upp = true, $num = true, $indent = false) {
  2981. $chars = array_merge(
  2982. $low ? range('a', 'z') : array(), $upp ? range('A', 'Z') : array(), $num ? range('0', '9') : array()
  2983. );
  2984. for ($rand = ""; strlen($rand) < $length; $rand .= $chars[array_rand($chars)])
  2985. ;
  2986. if ($indent != false) {
  2987. $rand = implode('-', str_split($rand, $indent));
  2988. }
  2989. return $rand;
  2990. }
  2991.  
  2992. static function urs($x, $y) {
  2993. return ($x >> $y) & (2147483647 >> ($y - 1));
  2994. }
  2995.  
  2996. public function hash($str, $rawsalt = '', $hash = 'sha512') {
  2997. if ($rawsalt == '') {
  2998. $rawsalt = $this->rand(((strlen($str) % 3) + 1) * 5);
  2999. }
  3000.  
  3001. $loc = array(hash('sha1', $rawsalt), hash('sha1', $str), '');
  3002. foreach (str_split($loc[0], 1) as $index => $character) {
  3003. $loc[2] .= $character . $loc[1][$index];
  3004. }
  3005.  
  3006. $hash = hash($hash, $loc[2]);
  3007. return substr_replace($hash, $rawsalt, (strlen($str) << 2) % strlen($hash), 0);
  3008. }
  3009.  
  3010. public function validate($str, $hash, $engine = 'sha512') {
  3011. $salt = substr($hash, (strlen($str) << 2) % strlen(hash($engine, 1)), ((strlen($str) % 3) + 1) * 5);
  3012. return $this->hash($str, $salt, $engine) === $hash ? true : false;
  3013. }
  3014.  
  3015. public function hashPass($pass, $salt = null, $hashtype = 'sha512', $hash = "") {
  3016. return $this->hash($pass, $salt, $hashtype);
  3017. }
  3018.  
  3019. public function checkPass($input, $real, $hash = 'sha512') {
  3020. return $this->validate($input, $real, $hash);
  3021. }
  3022.  
  3023. }
Add Comment
Please, Sign In to add comment