Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit( 0 ); // Definir tempo limite
- error_reporting( 0 ); // Caso o script de algum erro, nao mostrar ele
- class zBot
- {
- /* Bot Config */
- public $sala = 'Failures'; // Sala em que sera ativado o bot [necessario ter o power BOT]
- public $usuario = 'Login do bot'; // Login da conta que sera usada para o bot
- public $senha = 'Senha do bot'; // Senha da conta que sera usada para o bot
- /* Sample Config */
- public $botID = 1314323233; // O id do bot
- public $botNome = 'Bot'; // O nome do bot
- public $botAvatar = '1'; // O avatar do bot
- public $botHome = 'http://xat.com/Failures'; // A homepage do bot [casinha]
- public $admins = array( 97868863 ); // IDs com acesso exemplo array(42,100,96218942); etc...
- public $automember = True; // True = ativado, False = desativado
- public $autowelcome = 'Bem-vindo ao {chat} - {usuario}, seu cargo atual é: {rank}!'; //Mensagem de boas vindas, extra:{usuario},{online},{rank} e {chat}
- /* Uso extra */
- public $socket;
- public $packet;
- public $logado;
- public $IDSala;
- public $usuarios;
- public $passKey;
- public $ip;
- public $porta;
- public $xatIP = '107.182.224.236' // Os IPs podem mudar, para isso contacte o iZerang!
- public $botInfo = array( );
- /* Funcao de conectar bot ao xat.com */
- public function conectar( )
- {
- if ( empty( $this->usuario ) || empty( $this->senha ) )
- die( "--> Voce deve digitar login/senha.\n" );
- if ( !is_numeric( $this->sala ) )
- {
- $url = file_get_contents( 'http://xat.com/' . $this->sala );
- $parte1 = explode( 'name="chat" FlashVars="id=', $url );
- $final = explode( '&', $parte1[ 1 ] );
- $this->IDSala = $final[ 0 ];
- } //!is_numeric( $this->sala )
- else
- $this->IDSala = $this->sala;
- if ( !is_numeric( $this->IDSala ) )
- die( "--> Este chat grupo nao existe.\n" );
- if ( $this->IDSala < 8 )
- {
- $porta2 = 10000 - 1 + $this->IDSala;
- } //$this->IDSala < 8
- else
- {
- $porta2 = 10000 + 7 + ( $this->IDSala % 32 );
- }
- $this->ip = $this->xatIP;
- $this->porta = $porta2;
- $this->socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
- socket_set_option( $this->socket, SOL_SOCKET, SO_RCVTIMEO, array(
- 'sec' => 1000,
- 'usec' => 0
- ) );
- if ( !socket_connect( $this->socket, $this->ip, $this->porta ) )
- {
- die( "--> Falha ao conectar.\n" );
- } //!socket_connect( $this->socket, $this->ip, $this->porta )
- echo "<-- Conectando em {$this->ip}:{$this->porta}\n";
- }
- /* Desconectar bot, usado apenas para simples comandos tipo reiniciar etc... */
- public function desconectar( )
- {
- if ( isset( $this->socket ) && $this->socket == True )
- socket_close( $this->socket );
- $this->socket = False;
- }
- /* Fazer login no xat.com e pegar informacoes sobre o bot */
- public function logar()
- {
- $p = fsockopen( $this->ip, 10001, $e, $e, 1 );
- stream_set_timeout( $p, 2 );
- $packet = '<y u="' . $this->botID . '" r="' . $this->IDSala . '" m="1" />';
- fwrite( $p, $packet . chr( 0 ) );
- $x = trim( fread( $p, 1024 ) );
- $packet = '<v r="' . $this->IDSala . '" p="' . $this->passKey . '" n="' . $this->usuario . '" />';
- fwrite( $p, $packet . chr( 0 ) );
- $x = trim( fread( $p, 1024 ) );
- $this->packets( $x );
- $this->botInfo = $this->packet[ 'v' ];
- if ( count( $this->botInfo ) <= 4 )
- return False;
- return $this->botInfo;
- }
- /* A parte principal, conectar o bot ate a sala */
- public function entrar( $sala = False )
- {
- if ( $this->socket == FALSE ) {
- $this->conectar();
- $ch = curl_init("http://xat.com/web_gear/chat/register.php");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, "Locked=NC&Login=Login&NameEmail={$this->usuario}&Pin=0&Protected=NO&UserId=0&cp=&k2=0&mode=0&password=".$this->senha);
- $exec = curl_exec($ch);
- curl_close($ch);
- $part1 = explode('&pw=', $exec);
- $passKey = explode( '"', $part1[1]);
- if(!$ch) {die("<-- Tente novamente!");}
- if(!$passKey[0]) {die("<-- Login ou senha invalidos!");}
- $this->passKey = $passKey[0];
- $this->logado = $this->logar();
- } //$this->soc == FALSE
- unset( $this->packet[ 'y' ] );
- $this->enviar( '<y u="' . $this->botID . '" r="' . $this->IDSala . '" m="1" />' );
- while ( !is_array( $this->packet[ 'y' ] ) )
- $this->carregar();
- if ( $this->logado != False )
- {
- $j2 = '';
- $j2 .= 'cb="' . $this->packet[ 'y' ][ 'c' ] . '" ';
- $j2 .= 'q="1" ';
- $j2 .= 'y="' . $this->packet[ 'y' ][ 'i' ] . '" ';
- $j2 .= 'k="' . $this->botInfo[ 'k1' ] . '" ';
- $j2 .= 'k3="' . $this->botInfo[ 'k3' ] . '" ';
- if ( isset( $this->botInfo[ 'd1' ] ) )
- $j2 .= 'd1="' . $this->botInfo[ 'd1' ] . '" ';
- $j2 .= 'p="0" ';
- $j2 .= 'c="' . $this->IDSala . '" ';
- $j2 .= 'u="' . $this->botID . '" ';
- $j2 .= 'f="0" ';
- for ( $x = 0; $x < 15; $x++ )
- if ( $x == 1 )
- continue;
- elseif ( isset( $this->botInfo[ 'd' . $x ] ) )
- $j2 .= 'd' . $x . '="' . $this->botInfo[ 'd' . $x ] . '" ';
- if ( isset( $this->botInfo[ 'sn' ] ) )
- $j2 .= 'sn="' . $this->botInfo[ 'sn' ] . '" ';
- if ( isset( $this->botInfo[ 'dx' ] ) )
- $j2 .= 'dx="' . $this->botInfo[ 'dx' ] . '" ';
- if ( isset( $this->botInfo[ 'z' ] ) )
- $j2 .= 'z="' . $this->botInfo[ 'z' ] . '" ';
- else
- $this->botInfo[ 'dx' ] = '';
- $j2 .= 'dt="' . $this->botInfo[ 'dt' ] . '" ';
- $j2 .= 'N="' . $this->botInfo[ 'n' ] . '" ';
- $j2 .= 'n="' . $this->botNome . '" ';
- $j2 .= 'a="' . $this->botAvatar . '" ';
- $j2 .= 'h="' . $this->botHome . '" ';
- $j2 .= 'v="0" ';
- $j2 = trim( $j2 );
- $j2 = '<j2 ' . $j2 . ' />';
- $this->enviar( $j2 );
- } //$this->logado != False
- else
- die( "--> Erro, Captcha/J2 Incorreto ou falha de conexao.\n" );
- }
- /* Verificar os packets se estao corretos, etc... */
- public function packets( $packet, $teste = True, $teste2 = False )
- {
- if ( substr_count( $packet, '>' ) > 1 )
- {
- $packet = explode( '/>', $packet );
- $teste2 = True;
- } //substr_count( $packet, '>' ) > 1
- foreach ( (Array) $packet as $p )
- {
- if ( $teste2 )
- $p .= '/>';
- $p = trim( $p );
- if ( strlen( $p ) < 5 )
- return;
- echo "[XAT]-> {$p}\n";
- $tipo = trim( strtolower( substr( $p, 1, strpos( $p . ' ', ' ' ) ) ) );
- $p = trim( str_replace( '<' . $tipo, '', str_replace( '/>', '', $p ) ) );
- $p = str_replace( '"', "", str_replace( '" ', "&", str_replace( "&", "__38", $p ) ) );
- parse_str( $p, $this->packet[ $tipo ] );
- foreach ( $this->packet[ $tipo ] as $x => $v )
- $this->packet[ $tipo ][ $x ] = str_replace( "__38", "&", str_replace( "pl_", "+", $v ) );
- if ( $teste )
- $this->tipos( $tipo, $this->packet[ $tipo ] );
- } //(Array) $packet as $p
- }
- /* Verificar os ranks */
- public function ranks( $x )
- {
- $f = $this->passarU( $x );
- if ( $f == -1 ) // Guest
- return 'Guest';
- if ( ( 16 & $f ) ) // Banido
- return 'Banido';
- if ( ( 1 & $f ) && ( 2 & $f ) ) // Membro
- return 'Membro';
- if ( ( 4 & $f ) ) // Owner
- return 'Owner';
- if ( ( 32 & $f ) && ( 1 & $f ) && !( 2 & $f ) ) // Main Owner
- return 'MainOwner';
- if ( !( 1 & $f ) && !( 2 & $f ) ) // Guest
- return 'Guest';
- if ( ( 16 & $f ) ) // Banido
- return 'Banido';
- if ( ( 2 & $f ) && !( 1 & $f ) ) // Moderador
- return 'Moderador';
- if ( 1 & $f ) // Main Owner
- return 'MainOwner';
- return 0;
- }
- /* Tornar um usuario ... */
- function tornar( $id = 0, $tipo )
- {
- switch ( $tipo )
- {
- case 'Guest':
- $this->enviar( '<c u="' . $id . '" t="/r" />' );
- break;
- case 'Membro':
- $this->enviar( '<c u="' . $id . '" t="/e" />' );
- break;
- case 'Mod':
- $this->enviar( '<c u="' . $id . '" t="/m" />' );
- break;
- case 'Owner':
- $this->enviar( '<c u="' . $id . '" t="/M" />' );
- break;
- } //$tipo
- }
- /* Carregar o bot e informacoes */
- public function carregar( $verifi = True, $teste_var = True )
- {
- $x = '';
- try
- {
- $x = rtrim( @socket_read( $this->socket, 2048 ) );
- $x = str_replace( '', '', $x );
- }
- catch ( Exception $e )
- {
- return 'DESLIGADO';
- }
- if ( !$x )
- return 'DESLIGADO';
- if ( $x[ strlen( $x ) - 1 ] != '>' )
- $x .= $this->carregar( True );
- if ( $verifi )
- $this->packets( $x, $teste_var );
- return $x;
- }
- /* Enviar packets */
- public function enviar( $packet )
- {
- if ( $packet[ strlen( $packet ) - 1 ] != chr( 0 ) )
- $packet .= chr( 0 );
- echo "[BOT]-> {$packet}\n";
- return socket_write( $this->socket, $packet, strlen( $packet ) );
- }
- /* Remover _ do packet ['U'] */
- public function passarU( $id )
- {
- $retorna = explode( '_', $id );
- return ( $retorna[ 0 ] );
- }
- /* Funcao de reiniciar o bot */
- public function reiniciar( )
- {
- $this->conectar();
- $this->entrar( $this->IDSala );
- }
- /* Enviar boas vindas */
- function enviarWelcome( $mensagem, $id, $f, $nome )
- {
- if ( !$mensagem )
- {
- return False;
- } //!$mensagem
- $mensagem = str_replace( '{chat}', $this->sala, $mensagem );
- $mensagem = str_replace( '{online}', count( $this->usuarios ), $mensagem );
- $mensagem = str_replace( '{rank}', $this->ranks( $f ), $mensagem );
- $mensagem = str_replace( '{usuario}', $nome, $mensagem );
- $this->enviarMSG( $mensagem, 'PM', $id );
- }
- /* Enviar MSG, definido com tipo e ID */
- function enviarMSG( $mensagem, $tipo = 'MSG', $id = 0 )
- {
- if ( !$mensagem )
- {
- return False;
- } //!$mensagem
- switch ( $tipo )
- {
- case 'MSG': // Sample
- $this->enviar( '<m t="' . $mensagem . '" u="' . $this->botInfo[ 'i' ] . '" />' );
- break;
- case 'PM': // PM
- $this->enviar( '<p u="' . $id . '" t="' . $mensagem . '" d="' . $id . '" />' );
- break;
- case 'PC': // Privado
- $this->enviar( '<z d="' . $id . '" u="' . $this->botInfo[ 'i' ] . '" t="' . $mensagem . '" />' );
- break;
- } //$tipo
- }
- /* Tipos de packets/ e tambem aonde ficam os comandos */
- public function tipos( $tipo, $packet )
- {
- switch ( $tipo )
- {
- /* Packets */
- case 'u':
- $this->usuarios[ $this->passarU( $packet[ 'u' ] ) ] = $packet;
- $usuario = ( $packet[ 'N' ] ) ? $packet[ 'N' ] : $packet[ 'u' ];
- if ( $this->autowelcome != False && !isset( $packet[ 's' ] ) )
- {
- $this->enviarWelcome( $this->autowelcome, $packet[ 'u' ], $packet[ 'f' ], $usuario );
- } //$this->autowelcome != False && !isset( $packet[ 's' ] )
- if ( !isset( $packet[ 'f' ] ) || empty( $packet[ 'f' ] ) || $this->ranks( $packet[ 'f' ] ) == 'Guest' )
- {
- if ( $this->automember && isset( $packet[ 'n' ] ) )
- {
- $this->tornar( $packet[ 'u' ], 'Membro' );
- } //$this->automember && isset( $packet[ 'n' ] )
- } //!isset( $packet[ 'f' ] ) || empty( $packet[ 'f' ] ) || $this->ranks( $packet[ 'f' ] ) == 'Guest'
- break;
- case 'z':
- $mensagem = ( $this->packet[ 'z' ][ 't' ] ) ? $this->packet[ 'z' ][ 't' ] : False;
- if ( $mensagem == "/l" )
- {
- $this->enviarMSG( '/a_xatiZerang', 'PC', $packet[ 'u' ] );
- } //$mensagem == "/l"
- break;
- case 'm':
- case 'p':
- if ( isset( $packet[ 'i' ] ) && $packet[ 'i' ] > 0 )
- break;
- $msg = $mensagem = explode( ' ', $packet[ 't' ] );
- unset( $msg[ 0 ] );
- $msg = implode( ' ', $msg );
- if ( isset( $mensagem[ 0 ] ) && $mensagem[ 0 ][ 0 ] != '!' )
- break;
- $user = $this->usuarios[ $this->passarU( $packet[ 'u' ] ) ];
- $usuario = ( $user[ 'N' ] ) ? $user[ 'N' ] : $user[ 'u' ];
- switch ( substr( $mensagem[ 0 ], 1 ) )
- {
- /* Comandos para todos */
- case 'say':
- // !say [msg]
- $this->enviarMSG( $usuario . ': ' . $msg );
- break;
- case 'info':
- // !info
- $this->enviarMSG( 'zBots System 5.2 [PHP Version]', 'PM', $packet[ 'u' ] );
- break;
- case 'users':
- $this->enviarMSG( $usuario . ': ' . 'existe ' . count( $this->usuarios ) . ' usuarios online.' );
- break;
- /* Comandos para admin */
- case 'reiniciar':
- // !reiniciar
- if ( !in_array( $packet[ 'u' ], $this->admins ) )
- {
- return $this->enviarMSG( 'Você não tem permição para usar este comando!', 'PM', $packet[ 'u' ] );
- } //!in_array( $packet[ 'u' ], $this->admins )
- $this->enviarMSG( '[Servidor]: Estou sendo reiniciado (backoff)' );
- $this->reiniciar();
- break;
- case 'desligar':
- case 'die':
- // !die
- if ( !in_array( $packet[ 'u' ], $this->admins ) )
- {
- return $this->enviarMSG( 'Você não tem permição para usar este comando!', 'PM', $packet[ 'u' ] );
- } //!in_array( $packet[ 'u' ], $this->admins )
- $this->enviarMSG( '[Servidor]: Estou sendo desligado (bye)' );
- die( );
- break;
- case 'automember':
- // !automember [on/off]
- if ( !in_array( $packet[ 'u' ], $this->admins ) )
- {
- return $this->enviarMSG( 'Você não tem permição para usar este comando!', 'PM', $packet[ 'u' ] );
- } //!in_array( $packet[ 'u' ], $this->admins )
- switch ( $mensagem[ 1 ] )
- {
- case 'on':
- $this->automember = True;
- $this->enviarMSG( 'O sistema de automember foi ativado!' );
- break;
- case 'off':
- $this->automember = False;
- $this->enviarMSG( 'O sistema de automember foi desativado!' );
- break;
- default:
- $this->enviarMSG( 'Você deve escolher uma opçao [on/off].' );
- } //$mensagem[ 1 ]
- break;
- case 'welcome':
- // !welcome [off/mensagem]
- unset( $msg[ 0 ] );
- $nova = implode( " ", $msg );
- if ( $nova == 'off' )
- {
- $this->autowelcome = False;
- return $this->enviarMSG( 'Mensagem de autowelcome foi desativado!' );
- } //$nova == 'off'
- $this->autowelcome = ( $nova );
- $this->enviar( 'Mensagem de autowelcome foi atualizado!' );
- break;
- } //substr( $mensagem[ 0 ], 1 )
- } //$tipo
- }
- }
- $bot = new zBot(); // Estanciar nova class
- while ( True )
- {
- if ( $bot->carregar() == 'DESLIGADO' )
- {
- $bot->desconectar();
- $bot->entrar();
- } //$bot->carregar() == 'DESLIGADO'
- } //True
- ?>
Advertisement
Add Comment
Please, Sign In to add comment