Guest User

Untitled

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