LucasRed

Multibots editados

Nov 6th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.63 KB | None | 0 0
  1. BotNick     <-  [ "Dasty", "Desty", "Dusty" ];      // The BotNames
  2.  
  3. const NickServ      =   "123";                      // The NickServ Password
  4.  
  5. const server        =   "82.192.76.195";                    // Server Ip
  6. const port      =    6667;                      // Server port
  7.  
  8. const chan      =   "#BRL";                 // Home channel
  9. const pass      =   "";                     // Channel password
  10.  
  11. const schan     = "#BRL.staff"
  12. const spass     = "china01"
  13.  
  14. const PREFIX        =   "!";                        // The command prefix.
  15.  
  16.  
  17. local socket        =   {};                     // A empty table to put our socket instances in.
  18.  
  19. local count         =   0;                      // A counter to count recieved data.
  20.  
  21. local prev      =   null;                       // A var to hold the BotName that last sent data to IRC.
  22.  
  23.  
  24. function LoadBot()
  25. {
  26.     // A var to count.
  27.     local t = 0;
  28.  
  29.     // Iterate our BotNames.
  30.     while ( t < BotNick.len() )
  31.     {
  32.         // Open a new socket and send the data to be parsed.
  33.         socket[ t ] <- NewSocket( "connect" );
  34.  
  35.         // Connect our socket to the server.
  36.         socket[ t ].Connect( server, port );
  37.  
  38.         // The function to call, once connected.
  39.         socket[ t ].SetNewConnFunc( "Login" );
  40.  
  41.         // Increase our var.
  42.         t++;
  43.     }
  44.     NewTimer( "porn", 10000, 1 );
  45. }
  46.  
  47. function porn()
  48. {
  49.     socket[ 0 ].Send( "JOIN " + chan + " " + pass + "\n" );
  50.     socket[ 0 ].Send( "JOIN " + schan + " " + spass + "\n" );
  51.    
  52.     socket[ 1 ].Send( "JOIN " + chan + " " + pass + "\n" );
  53.     socket[ 1 ].Send( "JOIN " + schan + " " + spass + "\n" );
  54.    
  55.     socket[ 2 ].Send( "JOIN " + chan + " " + pass + "\n" );
  56.     socket[ 2 ].Send( "JOIN " + schan + " " + spass + "\n" );
  57.     // Infelizmente só funcionou assim. Nem com reza braba essa peste pegou do meu jeito "padrão"
  58. }
  59.  
  60. function connect( data )
  61. {
  62.     // Parse the data
  63.     local  
  64.         raw         =   split( data, "\r\n" ),
  65.         event       =   raw.len() > 1 ? split( raw[ 1 ], " " ) : "",
  66.         EventID     =   event.len() > 1 ? event[ 1 ] : "";
  67.  
  68.     // Find the Ping event.
  69.     local
  70.         FindPing    =   split( raw[ 0 ], " " ),
  71.         ping        =   FindPing[ 0 ];
  72.  
  73.    
  74.     // Find the channel event ( I've done this separately for de-bugging purposes )
  75.     local
  76.         FindChan    =   split( raw[ 0 ], " " ),
  77.         channel     =   FindChan.len() > 2 ? FindChan[ 2 ] : "";
  78.  
  79.  
  80.     // Ok, Now let's get those irc commands ( Join, part, Kick...etc etc )
  81.     local
  82.         FindIrcCommand  =   split( raw[ 0 ], " " ),
  83.         IrcCommand  =   FindIrcCommand.len() > 1 ? FindIrcCommand[ 1 ] : "";
  84.  
  85.     // Reply to ping's ( 'PONG' + irc server )
  86.     if ( ping == "PING" )
  87.     {
  88.         // A var to count.
  89.         local t = 0;
  90.  
  91.         // Iterate our BotNames.
  92.         while ( t < BotNick.len() )
  93.         {
  94.             socket[ t ].Send( "PONG " + FindPing[ 1 ] + "\n" );
  95.  
  96.             // Increase var.
  97.             t++;
  98.         }
  99.     }
  100.  
  101.     // We got the welcome message, so We're connected.
  102.     if ( EventID == "001" )
  103.     {
  104.         // A var to count.
  105.         local t = 0;
  106.  
  107.         // Iterante the BotNames
  108.         while ( t < BotNick.len() )
  109.         {
  110.             // Join our HomeChannel
  111.             // socket[ t ].Send( "JOIN " + chan + " " + pass + "\n" ); função do diabo que não presta1
  112.             // socket[ t ].Send( "JOIN " + schan + " " + spass + "\n" ); função do diabo que não presta2
  113.  
  114.  
  115.             // Login to NickServ.
  116.             socket[ t ].Send( "PRIVMSG NickServ IDENTIFY " + NickServ + "\n" ); // se esse lishu não fizer login com nicks registrados, põe na função porn 3 vezes (ID's 0, 1 e 2)
  117.  
  118.             // Increase var.
  119.             t++;
  120.         }
  121.     }
  122.  
  123.     // This is returned at the end of a NAMES request, after all visible names are returned.
  124.     else if ( EventID == "366" )
  125.     {
  126.         // A dynamic array to store each user's class instance in.
  127.         NickList        <-  [];
  128.  
  129.         // Now, Lets parse the names query.
  130.         local
  131.             FindUsers   =   split( raw[ 0 ], ":" ),
  132.             users       =   split( FindUsers[ 1 ], " " );
  133.  
  134.         // Iterate our parsed list of users.
  135.         for ( local i = 0; i < users.len(); i++ )
  136.         {
  137.             // Establish the level symbol.
  138.             local
  139.                 Level   =   users[ i ].slice( 0, 1 );
  140.  
  141.             if ( Level == "~" ) NickList.push( UserLevels( users[ i ].slice( 1, users[ i ].len() ), "Owner", 5 ) );
  142.             else if ( Level == "&" ) NickList.push( UserLevels( users[ i ].slice( 1, users[ i ].len() ), "SOP", 4 ) );
  143.             else if ( Level == "@" ) NickList.push( UserLevels( users[ i ].slice( 1, users[ i ].len() ), "AOP", 3 ) );
  144.             else if ( Level == "%" ) NickList.push( UserLevels( users[ i ].slice( 1, users[ i ].len() ), "HOP", 2 ) );
  145.             else if ( Level == "+" ) NickList.push( UserLevels( users[ i ].slice( 1, users[ i ].len() ), "VOP", 1 ) );
  146.             else NickList.push( UserLevels( users[ i ], "User", 0 ) );
  147.         }
  148.     }
  149.     if ( IrcCommand == "KICK" )
  150.     {
  151.         // A var to count.
  152.         local t = 0;
  153.  
  154.         // Iterante the BotNames
  155.         while ( t < BotNick.len() )
  156.         {
  157.             // Re-join our channel when kicked
  158.             socket[ t ].Send( "JOIN " + chan + " " + pass + "\n" );
  159.  
  160.             // Increase var.
  161.             t++;
  162.         }
  163.     }
  164.     else if ( ( IrcCommand == "MODE" ) || ( IrcCommand == "NICK" ) || ( IrcCommand == "JOIN" ) || ( IrcCommand == "PART" ) || ( IrcCommand == "QUIT" ) )
  165.     {
  166.         // Send a NAMES request.
  167.         socket[ 0 ].Send( "NAMES :" + chan + "\n" );
  168.     }
  169.    
  170.     // Somethings been said in our HomeChannel.
  171.  
  172.         // Find the text that was typed.
  173.             local
  174.             FindText    =   split( raw[ 0 ], ":" ),
  175.             text        =   FindText.len() > 1 ? FindText[ 1 ] : "",
  176.             prefix      =   text != "" ? text.slice( 0, 1 ) : "";
  177.    
  178.             // Find the command that was typed.
  179.             local
  180.                 Findcmd     =   text != "" ? split( text, " " ) : "",
  181.                 cmd     =   Findcmd != "" ? Findcmd[ 0 ].slice( 1, Findcmd[ 0 ].len() ) : "";
  182.  
  183.  
  184.             // Find the text that was typed after the command.
  185.             local
  186.                 NewText     =   text != "" ? strip( text.slice( cmd.len() + 1, text.len() ) ) : "";
  187.  
  188.  
  189.             // Find the person that typed the text.
  190.             local
  191.                 FindNick    =   split( raw[ 0 ], "!" ),
  192.                 Nick        =   FindNick[ 0 ].slice( 1, FindNick[ 0 ].len() );
  193.  
  194.                 if ( count % BotNick.len() == 0 )
  195.                 {
  196.                     if ( prefix == PREFIX )
  197.                     {
  198.                         switch ( channel )
  199.                         {
  200.                             case chan:
  201.                                 ProcessCommands( Nick, cmd, NewText );
  202.                                 break;
  203.                                
  204.                             case schan:
  205.                                 AdminCommands( Nick, cmd, NewText );
  206.                                 break;
  207.                         }
  208.                     }
  209.                    
  210.                     else if ( prefix == "." )
  211.                     {
  212.                         SendToIRC( "* " + Nick + "[IRC]: " + text.slice( 1 ) );
  213.                         Message( "* " + Nick + "[IRC]: " + text.slice( 1 ) );
  214.                     }
  215.                 }
  216.                 count++;
  217.         // Ensure a command was typed with our prefix.
  218. }
  219.  
  220. function Login()
  221. {
  222.     // Our counter.
  223.     local t = 0;
  224.    
  225.     // Iterate the BotNames
  226.     while ( t < BotNick.len() )
  227.     {
  228.         // Set the bots name and real name
  229.         socket[ t ].Send( "USER " + BotNick[ t ] + " 0 * : " + BotNick[ t ] + " \n" );
  230.  
  231.         // Set the nick that the bot will use on the irc server
  232.         socket[ t ].Send( "NICK " + BotNick[ t ] + "\n" );
  233.    
  234.         // Increase our counter.
  235.         t++;
  236.     }
  237. }
  238.  
  239. // Send a message to be echoed.
  240. function SendToIRC( text )
  241. {
  242.     // Establish the index of the next bot.
  243.     local
  244.         BotID       =   FindNexBotId();
  245.  
  246.     // Send the data to IRC.
  247.     socket[ BotID ].Send( "PRIVMSG " + chan + " " + text + "\n" );
  248. }
  249.  
  250. // Establish the index of the next bot.
  251. function FindNexBotId()
  252. {
  253.     // If the index exists.
  254.     try{
  255.         local
  256.             next    =   BotNick.find( prev ) + 1;   // Find the next array index.
  257.             prev    =   BotNick[ next ];        // Put it's value in our var.
  258.         return  next;                       // Return the index.
  259.     } catch ( e ) { prev = BotNick[ 0 ]; return 0; }        // Return index zero on error.
  260. }
  261.  
  262. // A empty class to store Channel Users and their levels.
  263. class UserLevels
  264. {
  265.     // The Constructor.
  266.     constructor( ... ) {
  267.  
  268.         user    =   vargv[ 0 ];
  269.         level   =   vargv[ 1 ];
  270.         ilevel  =   vargv[ 2 ];
  271.     }
  272.  
  273.     // Reset Property values
  274.     user    =   null;
  275.     level   =   null;
  276.     ilevel  =   null;
  277. }
  278.  
  279. // Find the specified user's level.
  280. function FindLevel( user, ilevel )
  281. {
  282.     // Iterate our NickList array.
  283.     foreach ( obj in NickList )
  284.     {
  285.         // Ensure a class instance was found.
  286.         if ( obj != null )
  287.         {
  288.             // Add the object properties to a tmp variable, so we can access squirrel's VM built in manipulation functions for that data type.
  289.             local tmp = obj.user;
  290.  
  291.             // Perform a string comparison, if we get a match, return the 'level' property.
  292.             if ( tmp.find( user ) != null )
  293.             {
  294.                 // Return the numerical level if 'true'
  295.                 if ( ilevel ) return obj.ilevel;
  296.        
  297.                 // Otherwise return the Non-Numerical level.
  298.                 else return obj.level;
  299.             }
  300.         }
  301.     }
  302. }
  303.  
  304.  
  305. // The commands.
  306. function ProcessCommands( nick, cmd, text )
  307. {
  308.     if ( cmd == "commands" )
  309.     {
  310.         SendToIRC( ">> Current commands: " + "say, players" );
  311.     }
  312.     else if ( cmd == "level" )
  313.     {
  314.         // Change parameter two, to 'true' for numerical level.
  315.         SendToIRC( FindLevel( nick, false ) );
  316.     }
  317.     else if ( cmd == "say" )
  318.     {
  319.         // Check text is not a empty string.
  320.         if ( text == "" ) SendToIRC( "Error: Missing paremeter - text" );
  321.         else
  322.         {
  323.             // Send the message in-game
  324.             Message( "[ irc " + FindLevel( nick, false ) + " ] " + nick + ":" +  " " + text );
  325.            
  326.             // Echo it back, so we know whats happening.
  327.             SendToIRC( "[ irc " + FindLevel( nick, false ) + " ] " + nick + ":" +  " " + text );
  328.         }
  329.     }
  330.     else if ( cmd == "players" )
  331.     {
  332.         // A tempory var to collect our players in
  333.         local   tmp     =   "",
  334.             count   =   0;
  335.  
  336.         // Iterate all players 
  337.         for( local i=0; i < 50; ++i )
  338.         {
  339.             // Grab it's instance in a variable.
  340.             local plr = FindPlayer( i );
  341.  
  342.             // If a instance has been found
  343.             if ( plr )
  344.             {
  345.                 // Add it to our temp string.
  346.                 tmp = tmp + " " + plr.Name + "[" + plr.ID + "]" + ",",
  347.  
  348.                 // Increase our counter
  349.                 count++;
  350.             }
  351.         }
  352.        
  353.         // Output if tmp is not a empty string still.
  354.         tmp != "" ? SendToIRC( "Online Players: " + strip( tmp.slice(0, tmp.len() - 1) ) ) : "";
  355.  
  356.         // Output our player count.
  357.         SendToIRC( "Total players: " + count );
  358.     }
  359.  
  360.     // Anything else is a unknown command.
  361.     else SendToIRC( "I don't know that command!" );
  362. }
  363.  
  364. function AdminCommands( nick, cmd, text )
  365. {
  366.     if ( cmd == "cmds" ) SendToIRC( "cu dos admins" );
  367.     else SendToIRC( "comando inválido, use !cmds" );
  368. }
Advertisement
Add Comment
Please, Sign In to add comment