Guest User

Untitled

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