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