iZerang

zBots Xat System 5.2[Updated]

Oct 4th, 2015
33,832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.86 KB | None | 0 0
  1. <?php
  2. set_time_limit( 0 ); // Definir tempo limite
  3. error_reporting( 0 ); // Caso o script de algum erro, nao mostrar ele
  4.  
  5. class zBot
  6. {
  7.     /* Bot Config */
  8.     public $sala = 'Failures'; // Sala em que sera ativado o bot [necessario ter o power BOT]
  9.     public $usuario = 'Login do bot'; // Login da conta que sera usada para o bot
  10.     public $senha = 'Senha do bot'; // Senha da conta que sera usada para o bot
  11.     /* Sample Config */
  12.     public $botID = 1314323233; // O id do bot
  13.     public $botNome = 'Bot'; // O nome do bot
  14.     public $botAvatar = '1'; // O avatar do bot
  15.     public $botHome = 'http://xat.com/Failures'; // A homepage do bot [casinha]
  16.     public $admins = array( 97868863 ); // IDs com acesso exemplo array(42,100,96218942); etc...
  17.     public $automember = True; // True = ativado, False = desativado
  18.     public $autowelcome = 'Bem-vindo ao {chat} - {usuario}, seu cargo atual é: {rank}!'; //Mensagem de boas vindas, extra:{usuario},{online},{rank} e {chat}
  19.     /* Uso extra */
  20.     public $socket;
  21.     public $packet;
  22.     public $logado;
  23.     public $IDSala;
  24.     public $usuarios;
  25.     public $passKey;
  26.     public $ip;
  27.     public $porta;
  28.     public $xatIP = '107.182.224.236' // Os IPs podem mudar, para isso contacte o iZerang!
  29.     public $botInfo = array( );
  30.    
  31.     /* Funcao de conectar bot ao xat.com */
  32.     public function conectar( )
  33.     {
  34.         if ( empty( $this->usuario ) || empty( $this->senha ) )
  35.             die( "--> Voce deve digitar login/senha.\n" );
  36.         if ( !is_numeric( $this->sala ) )
  37.         {
  38.             $url          = file_get_contents( 'http://xat.com/' . $this->sala );
  39.             $parte1       = explode( 'name="chat" FlashVars="id=', $url );
  40.             $final        = explode( '&', $parte1[ 1 ] );
  41.             $this->IDSala = $final[ 0 ];
  42.         } //!is_numeric( $this->sala )
  43.         else
  44.             $this->IDSala = $this->sala;
  45.         if ( !is_numeric( $this->IDSala ) )
  46.             die( "--> Este chat grupo nao existe.\n" );
  47.         if ( $this->IDSala < 8 )
  48.         {
  49.             $porta2 = 10000 - 1 + $this->IDSala;
  50.         } //$this->IDSala < 8
  51.         else
  52.         {
  53.             $porta2 = 10000 + 7 + ( $this->IDSala % 32 );
  54.         }
  55.         $this->ip     = $this->xatIP;
  56.         $this->porta  = $porta2;
  57.         $this->socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
  58.         socket_set_option( $this->socket, SOL_SOCKET, SO_RCVTIMEO, array(
  59.              'sec' => 1000,
  60.             'usec' => 0
  61.         ) );
  62.         if ( !socket_connect( $this->socket, $this->ip, $this->porta ) )
  63.         {
  64.             die( "--> Falha ao conectar.\n" );
  65.         } //!socket_connect( $this->socket, $this->ip, $this->porta )
  66.         echo "<-- Conectando em {$this->ip}:{$this->porta}\n";
  67.     }
  68.    
  69.     /* Desconectar bot, usado apenas para simples comandos tipo reiniciar etc... */
  70.     public function desconectar( )
  71.     {
  72.         if ( isset( $this->socket ) && $this->socket == True )
  73.             socket_close( $this->socket );
  74.         $this->socket = False;
  75.     }
  76.    
  77.     /* Fazer login no xat.com e pegar informacoes sobre o bot */
  78.     public function logar()
  79.     {
  80.         $p = fsockopen( $this->ip, 10001, $e, $e, 1 );
  81.         stream_set_timeout( $p, 2 );
  82.         $packet = '<y u="' . $this->botID . '" r="' . $this->IDSala . '" m="1" />';
  83.         fwrite( $p, $packet . chr( 0 ) );
  84.         $x      = trim( fread( $p, 1024 ) );
  85.         $packet = '<v r="' . $this->IDSala . '" p="' . $this->passKey . '" n="' . $this->usuario . '" />';
  86.         fwrite( $p, $packet . chr( 0 ) );
  87.         $x = trim( fread( $p, 1024 ) );
  88.         $this->packets( $x );
  89.         $this->botInfo = $this->packet[ 'v' ];
  90.         if ( count( $this->botInfo ) <= 4 )
  91.             return False;
  92.         return $this->botInfo;
  93.     }
  94.    
  95.     /* A parte principal, conectar o bot ate a sala */
  96.     public function entrar( $sala = False )
  97.     {
  98.         if ( $this->socket == FALSE ) {
  99.             $this->conectar();
  100.             $ch = curl_init("http://xat.com/web_gear/chat/register.php");
  101.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  102.             curl_setopt($ch, CURLOPT_POST, true);
  103.             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);
  104.             $exec = curl_exec($ch);
  105.             curl_close($ch);
  106.             $part1 = explode('&pw=', $exec);
  107.             $passKey = explode( '"', $part1[1]);
  108.             if(!$ch) {die("<-- Tente novamente!");}
  109.             if(!$passKey[0]) {die("<-- Login ou senha invalidos!");}
  110.             $this->passKey = $passKey[0];
  111.             $this->logado = $this->logar();
  112.         } //$this->soc == FALSE
  113.         unset( $this->packet[ 'y' ] );
  114.         $this->enviar( '<y u="' . $this->botID . '" r="' . $this->IDSala . '" m="1" />' );
  115.         while ( !is_array( $this->packet[ 'y' ] ) )
  116.             $this->carregar();
  117.         if ( $this->logado != False )
  118.         {
  119.             $j2 = '';
  120.             $j2 .= 'cb="' . $this->packet[ 'y' ][ 'c' ] . '" ';
  121.             $j2 .= 'q="1" ';
  122.             $j2 .= 'y="' . $this->packet[ 'y' ][ 'i' ] . '" ';
  123.             $j2 .= 'k="' . $this->botInfo[ 'k1' ] . '" ';
  124.             $j2 .= 'k3="' . $this->botInfo[ 'k3' ] . '" ';
  125.             if ( isset( $this->botInfo[ 'd1' ] ) )
  126.                 $j2 .= 'd1="' . $this->botInfo[ 'd1' ] . '" ';
  127.             $j2 .= 'p="0" ';
  128.             $j2 .= 'c="' . $this->IDSala . '" ';
  129.             $j2 .= 'u="' . $this->botID . '" ';
  130.             $j2 .= 'f="0" ';
  131.             for ( $x = 0; $x < 15; $x++ )
  132.                 if ( $x == 1 )
  133.                     continue;
  134.                 elseif ( isset( $this->botInfo[ 'd' . $x ] ) )
  135.                     $j2 .= 'd' . $x . '="' . $this->botInfo[ 'd' . $x ] . '" ';
  136.             if ( isset( $this->botInfo[ 'sn' ] ) )
  137.                 $j2 .= 'sn="' . $this->botInfo[ 'sn' ] . '" ';
  138.             if ( isset( $this->botInfo[ 'dx' ] ) )
  139.                 $j2 .= 'dx="' . $this->botInfo[ 'dx' ] . '" ';
  140.             if ( isset( $this->botInfo[ 'z' ] ) )
  141.                 $j2 .= 'z="' . $this->botInfo[ 'z' ] . '" ';
  142.             else
  143.                 $this->botInfo[ 'dx' ] = '';
  144.             $j2 .= 'dt="' . $this->botInfo[ 'dt' ] . '" ';
  145.             $j2 .= 'N="' . $this->botInfo[ 'n' ] . '" ';
  146.             $j2 .= 'n="' . $this->botNome . '" ';
  147.             $j2 .= 'a="' . $this->botAvatar . '" ';
  148.             $j2 .= 'h="' . $this->botHome . '" ';
  149.             $j2 .= 'v="0" ';
  150.             $j2 = trim( $j2 );
  151.             $j2 = '<j2 ' . $j2 . ' />';
  152.             $this->enviar( $j2 );
  153.         } //$this->logado != False
  154.         else
  155.             die( "--> Erro, Captcha/J2 Incorreto ou falha de conexao.\n" );
  156.     }
  157.    
  158.     /* Verificar os packets se estao corretos, etc... */
  159.     public function packets( $packet, $teste = True, $teste2 = False )
  160.     {
  161.         if ( substr_count( $packet, '>' ) > 1 )
  162.         {
  163.             $packet = explode( '/>', $packet );
  164.             $teste2 = True;
  165.         } //substr_count( $packet, '>' ) > 1
  166.         foreach ( (Array) $packet as $p )
  167.         {
  168.             if ( $teste2 )
  169.                 $p .= '/>';
  170.             $p = trim( $p );
  171.             if ( strlen( $p ) < 5 )
  172.                 return;
  173.             echo "[XAT]-> {$p}\n";
  174.             $tipo = trim( strtolower( substr( $p, 1, strpos( $p . ' ', ' ' ) ) ) );
  175.             $p    = trim( str_replace( '<' . $tipo, '', str_replace( '/>', '', $p ) ) );
  176.             $p    = str_replace( '"', "", str_replace( '" ', "&", str_replace( "&", "__38", $p ) ) );
  177.             parse_str( $p, $this->packet[ $tipo ] );
  178.             foreach ( $this->packet[ $tipo ] as $x => $v )
  179.                 $this->packet[ $tipo ][ $x ] = str_replace( "__38", "&", str_replace( "pl_", "+", $v ) );
  180.             if ( $teste )
  181.                 $this->tipos( $tipo, $this->packet[ $tipo ] );
  182.         } //(Array) $packet as $p
  183.     }
  184.    
  185.     /* Verificar os ranks */
  186.     public function ranks( $x )
  187.     {
  188.         $f = $this->passarU( $x );
  189.         if ( $f == -1 ) // Guest
  190.             return 'Guest';
  191.         if ( ( 16 & $f ) ) // Banido
  192.             return 'Banido';
  193.         if ( ( 1 & $f ) && ( 2 & $f ) ) // Membro
  194.             return 'Membro';
  195.         if ( ( 4 & $f ) ) // Owner
  196.             return 'Owner';
  197.         if ( ( 32 & $f ) && ( 1 & $f ) && !( 2 & $f ) ) // Main Owner
  198.             return 'MainOwner';
  199.         if ( !( 1 & $f ) && !( 2 & $f ) ) // Guest
  200.             return 'Guest';
  201.         if ( ( 16 & $f ) ) // Banido
  202.             return 'Banido';
  203.         if ( ( 2 & $f ) && !( 1 & $f ) ) // Moderador
  204.             return 'Moderador';
  205.         if ( 1 & $f ) // Main Owner
  206.             return 'MainOwner';
  207.         return 0;
  208.     }
  209.    
  210.     /* Tornar um usuario ... */
  211.     function tornar( $id = 0, $tipo )
  212.     {
  213.         switch ( $tipo )
  214.         {
  215.             case 'Guest':
  216.                 $this->enviar( '<c u="' . $id . '" t="/r" />' );
  217.                 break;
  218.            
  219.             case 'Membro':
  220.                 $this->enviar( '<c u="' . $id . '" t="/e" />' );
  221.                 break;
  222.            
  223.             case 'Mod':
  224.                 $this->enviar( '<c u="' . $id . '" t="/m" />' );
  225.                 break;
  226.            
  227.             case 'Owner':
  228.                 $this->enviar( '<c u="' . $id . '" t="/M" />' );
  229.                 break;
  230.         } //$tipo
  231.     }
  232.    
  233.     /* Carregar o bot e informacoes */
  234.     public function carregar( $verifi = True, $teste_var = True )
  235.     {
  236.         $x = '';
  237.         try
  238.         {
  239.             $x = rtrim( @socket_read( $this->socket, 2048 ) );
  240.             $x = str_replace( '', '', $x );
  241.         }
  242.         catch ( Exception $e )
  243.         {
  244.             return 'DESLIGADO';
  245.         }
  246.         if ( !$x )
  247.             return 'DESLIGADO';
  248.         if ( $x[ strlen( $x ) - 1 ] != '>' )
  249.             $x .= $this->carregar( True );
  250.         if ( $verifi )
  251.             $this->packets( $x, $teste_var );
  252.         return $x;
  253.     }
  254.    
  255.     /* Enviar packets */
  256.     public function enviar( $packet )
  257.     {
  258.         if ( $packet[ strlen( $packet ) - 1 ] != chr( 0 ) )
  259.             $packet .= chr( 0 );
  260.         echo "[BOT]-> {$packet}\n";
  261.         return socket_write( $this->socket, $packet, strlen( $packet ) );
  262.     }
  263.    
  264.     /* Remover _ do packet ['U'] */
  265.     public function passarU( $id )
  266.     {
  267.         $retorna = explode( '_', $id );
  268.         return ( $retorna[ 0 ] );
  269.     }
  270.    
  271.     /* Funcao de reiniciar o bot */
  272.     public function reiniciar( )
  273.     {
  274.         $this->conectar();
  275.         $this->entrar( $this->IDSala );
  276.     }
  277.    
  278.     /* Enviar boas vindas */
  279.     function enviarWelcome( $mensagem, $id, $f, $nome )
  280.     {
  281.         if ( !$mensagem )
  282.         {
  283.             return False;
  284.         } //!$mensagem
  285.         $mensagem = str_replace( '{chat}', $this->sala, $mensagem );
  286.         $mensagem = str_replace( '{online}', count( $this->usuarios ), $mensagem );
  287.         $mensagem = str_replace( '{rank}', $this->ranks( $f ), $mensagem );
  288.         $mensagem = str_replace( '{usuario}', $nome, $mensagem );
  289.         $this->enviarMSG( $mensagem, 'PM', $id );
  290.     }
  291.    
  292.     /* Enviar MSG, definido com tipo e ID */
  293.     function enviarMSG( $mensagem, $tipo = 'MSG', $id = 0 )
  294.     {
  295.         if ( !$mensagem )
  296.         {
  297.             return False;
  298.         } //!$mensagem
  299.         switch ( $tipo )
  300.         {
  301.             case 'MSG': // Sample
  302.                 $this->enviar( '<m t="' . $mensagem . '" u="' . $this->botInfo[ 'i' ] . '" />' );
  303.                 break;
  304.            
  305.             case 'PM': // PM
  306.                 $this->enviar( '<p u="' . $id . '" t="' . $mensagem . '" d="' . $id . '" />' );
  307.                 break;
  308.            
  309.             case 'PC': // Privado
  310.                 $this->enviar( '<z d="' . $id . '" u="' . $this->botInfo[ 'i' ] . '" t="' . $mensagem . '" />' );
  311.                 break;
  312.         } //$tipo
  313.     }
  314.    
  315.     /* Tipos de packets/ e tambem aonde ficam os comandos */
  316.     public function tipos( $tipo, $packet )
  317.     {
  318.         switch ( $tipo )
  319.         {
  320.             /* Packets */
  321.             case 'u':
  322.                 $this->usuarios[ $this->passarU( $packet[ 'u' ] ) ] = $packet;
  323.                 $usuario                                            = ( $packet[ 'N' ] ) ? $packet[ 'N' ] : $packet[ 'u' ];
  324.                 if ( $this->autowelcome != False && !isset( $packet[ 's' ] ) )
  325.                 {
  326.                     $this->enviarWelcome( $this->autowelcome, $packet[ 'u' ], $packet[ 'f' ], $usuario );
  327.                 } //$this->autowelcome != False && !isset( $packet[ 's' ] )
  328.                 if ( !isset( $packet[ 'f' ] ) || empty( $packet[ 'f' ] ) || $this->ranks( $packet[ 'f' ] ) == 'Guest' )
  329.                 {
  330.                     if ( $this->automember && isset( $packet[ 'n' ] ) )
  331.                     {
  332.                         $this->tornar( $packet[ 'u' ], 'Membro' );
  333.                     } //$this->automember && isset( $packet[ 'n' ] )
  334.                 } //!isset( $packet[ 'f' ] ) || empty( $packet[ 'f' ] ) || $this->ranks( $packet[ 'f' ] ) == 'Guest'
  335.                 break;
  336.            
  337.             case 'z':
  338.                 $mensagem = ( $this->packet[ 'z' ][ 't' ] ) ? $this->packet[ 'z' ][ 't' ] : False;
  339.                 if ( $mensagem == "/l" )
  340.                 {
  341.                     $this->enviarMSG( '/a_xatiZerang', 'PC', $packet[ 'u' ] );
  342.                 } //$mensagem == "/l"
  343.                 break;
  344.            
  345.             case 'm':
  346.             case 'p':
  347.                 if ( isset( $packet[ 'i' ] ) && $packet[ 'i' ] > 0 )
  348.                     break;
  349.                 $msg = $mensagem = explode( ' ', $packet[ 't' ] );
  350.                 unset( $msg[ 0 ] );
  351.                 $msg = implode( ' ', $msg );
  352.                 if ( isset( $mensagem[ 0 ] ) && $mensagem[ 0 ][ 0 ] != '!' )
  353.                     break;
  354.                 $user    = $this->usuarios[ $this->passarU( $packet[ 'u' ] ) ];
  355.                 $usuario = ( $user[ 'N' ] ) ? $user[ 'N' ] : $user[ 'u' ];
  356.                 switch ( substr( $mensagem[ 0 ], 1 ) )
  357.                 {
  358.                     /* Comandos para todos */
  359.                     case 'say':
  360.                         // !say [msg]
  361.                         $this->enviarMSG( $usuario . ': ' . $msg );
  362.                         break;
  363.                    
  364.                     case 'info':
  365.                         // !info
  366.                         $this->enviarMSG( 'zBots System 5.2 [PHP Version]', 'PM', $packet[ 'u' ] );
  367.                         break;
  368.                    
  369.                     case 'users':
  370.                         $this->enviarMSG( $usuario . ': ' . 'existe ' . count( $this->usuarios ) . ' usuarios online.' );
  371.                         break;
  372.                    
  373.                     /* Comandos para admin */
  374.                     case 'reiniciar':
  375.                         // !reiniciar
  376.                         if ( !in_array( $packet[ 'u' ], $this->admins ) )
  377.                         {
  378.                             return $this->enviarMSG( 'Você não tem permição para usar este comando!', 'PM', $packet[ 'u' ] );
  379.                         } //!in_array( $packet[ 'u' ], $this->admins )
  380.                         $this->enviarMSG( '[Servidor]: Estou sendo reiniciado (backoff)' );
  381.                         $this->reiniciar();
  382.                         break;
  383.                    
  384.                     case 'desligar':
  385.                     case 'die':
  386.                         // !die
  387.                         if ( !in_array( $packet[ 'u' ], $this->admins ) )
  388.                         {
  389.                             return $this->enviarMSG( 'Você não tem permição para usar este comando!', 'PM', $packet[ 'u' ] );
  390.                         } //!in_array( $packet[ 'u' ], $this->admins )
  391.                         $this->enviarMSG( '[Servidor]: Estou sendo desligado (bye)' );
  392.                         die( );
  393.                         break;
  394.                    
  395.                     case 'automember':
  396.                         // !automember [on/off]
  397.                         if ( !in_array( $packet[ 'u' ], $this->admins ) )
  398.                         {
  399.                             return $this->enviarMSG( 'Você não tem permição para usar este comando!', 'PM', $packet[ 'u' ] );
  400.                         } //!in_array( $packet[ 'u' ], $this->admins )
  401.                         switch ( $mensagem[ 1 ] )
  402.                         {
  403.                             case 'on':
  404.                                 $this->automember = True;
  405.                                 $this->enviarMSG( 'O sistema de automember foi ativado!' );
  406.                                 break;
  407.                            
  408.                             case 'off':
  409.                                 $this->automember = False;
  410.                                 $this->enviarMSG( 'O sistema de automember foi desativado!' );
  411.                                 break;
  412.                            
  413.                             default:
  414.                                 $this->enviarMSG( 'Você deve escolher uma opçao [on/off].' );
  415.                         } //$mensagem[ 1 ]
  416.                         break;
  417.                    
  418.                     case 'welcome':
  419.                         // !welcome [off/mensagem]
  420.                         unset( $msg[ 0 ] );
  421.                         $nova = implode( " ", $msg );
  422.                         if ( $nova == 'off' )
  423.                         {
  424.                             $this->autowelcome = False;
  425.                             return $this->enviarMSG( 'Mensagem de autowelcome foi desativado!' );
  426.                         } //$nova == 'off'
  427.                         $this->autowelcome = ( $nova );
  428.                         $this->enviar( 'Mensagem de autowelcome foi atualizado!' );
  429.                         break;
  430.                        
  431.                 } //substr( $mensagem[ 0 ], 1 )
  432.         } //$tipo
  433.     }
  434.    
  435. }
  436. $bot = new zBot(); // Estanciar nova class
  437. while ( True )
  438. {
  439.     if ( $bot->carregar() == 'DESLIGADO' )
  440.     {
  441.         $bot->desconectar();
  442.         $bot->entrar();
  443.     } //$bot->carregar() == 'DESLIGADO'
  444. } //True
  445. ?>
Advertisement
Add Comment
Please, Sign In to add comment