Guest User

Server ptt pedro

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