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