LucasRed

Untitled

Jan 1st, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.68 KB | None | 0 0
  1. // ----- IRC Script -----
  2.  
  3. g_IRC <- null;
  4.  
  5. // CHANGEME
  6. IRC_SERVER <- "irc.liberty-unleashed.co.uk";
  7. IRC_ECHO_CHANNEL <- "#extreme-addicts.echo";
  8. IRC_NICKNAME <- "Quack";
  9.  
  10. const IRC_COL_WHITE = "\x000300";
  11. const IRC_COL_BLACK = "\x000301";
  12. const IRC_COL_DARKBLUE = "\x000302";
  13. const IRC_COL_DARKGREEN = "\x000303";
  14. const IRC_COL_RED = "\x000304";
  15. const IRC_COL_BROWN = "\x000305";
  16. const IRC_COL_PURPLE = "\x000306";
  17. const IRC_COL_ORANGE = "\x000307";
  18. const IRC_COL_YELLOW = "\x000308";
  19. const IRC_COL_GREEN = "\x000309";
  20. const IRC_COL_AQUA = "\x000310";
  21. const IRC_COL_CYAN = "\x000311";
  22. const IRC_COL_BLUE = "\x000312";
  23. const IRC_COL_PINK = "\x000313";
  24. const IRC_COL_DARKGREY = "\x000314";
  25. const IRC_COL_LIGHTGREY = "\x000315";
  26. const IRC_COL       = "\x0003";
  27. const IRC_COL_BOLD  = "\x0002";
  28.  
  29.  
  30. function EchoMessage( out )
  31. {
  32.     Message( out );
  33.     IRC_PrivMsg( g_IRC, IRC_ECHO_CHANNEL, out );
  34. }  
  35.  
  36. function IRC_onRaw( irc, host, data )
  37. {
  38.     //print( host + " - " + data );
  39. }
  40.  
  41. // Fired 10 seconds after disconnecting to reconnect
  42. function ReconnectIRC( irc )
  43. {
  44.     print( "Attempting to reconnect to IRC..." );
  45.     if ( IRC_Connect( irc ) == true )
  46.         print( "Reconnected successfully" );
  47.     else
  48.     {
  49.         print( "Unable to reconnect. Retrying in 10 seconds..." );
  50.        
  51.         NewTimer( "ReconnectIRC", 10000, 1, irc );
  52.     }
  53. }
  54.  
  55. function IRC_onDisconnect( irc )
  56. {
  57.     print( "IRC bot has disconnected from the server. Reconnecting..." );
  58.    
  59.     if ( IRC_Connect( irc ) == true )
  60.         print( "Reconnected successfully" );
  61.     else
  62.     {
  63.         print( "Unable to reconnect. Retrying in 10 seconds..." );
  64.        
  65.         NewTimer( "ReconnectIRC", 10000, 1, irc );
  66.     }
  67. }
  68.  
  69. function IRC_onNumeric( irc, numeric, host, data )
  70. {
  71.     if ( numeric == 001 )
  72.     {
  73.         // Numeric 1 is the RPL_WELCOME message which means we have connected
  74.  
  75.         // Join our channel
  76.         IRC_Join( irc, IRC_ECHO_CHANNEL, "" );
  77.     }
  78. }
  79.  
  80. function IRC_onJoin( irc, host, data )
  81. {
  82.     // Called when somebody joins the channel
  83.     local nick = split( host, "!:" )[0];
  84.     local chan = split( data, ":" )[0];
  85.    
  86.     if ( nick == IRC_GetNick( irc ) )
  87.     {
  88.         // We joined a channel
  89.         print( "Joined channel " + chan + " on " + IRC_GetNetworkName( irc ) );
  90.     }
  91. }
  92.  
  93. function IRC_onPrivMsg( irc, host, channel, message )
  94. {
  95.     local nick = split( host, "!:" )[0];
  96.        
  97.     local cmd = GetTok( message, " ", 1 );
  98.     if ( cmd == "!playercount" )
  99.     {
  100.         // Return how many players are on the server
  101.         IRC_PrivMsg( irc, IRC_ECHO_CHANNEL, "There are currently " + GetPlayers() + "/" + GetMaxPlayers() + " players on the server." );
  102.     }
  103.     else if ( cmd == "!kick" )
  104.     {
  105.         local modes = IRC_GetUserModes( irc, channel, nick );
  106.         if ( modes != "" )
  107.         {
  108.             if ( IsIn( modes, "o" ) )
  109.             {
  110.                 // Person has operator on the channel
  111.                 local numArgs = NumTok( message, " " );
  112.                 if ( numArgs > 1 )
  113.                 {
  114.                     local user = GetTok( message, " ", 2 );
  115.                    
  116.                     local reason = "No Reason";
  117.                     if ( numArgs >= 3 )
  118.                         reason = GetTok( message, " ", 3, numArgs );
  119.                    
  120.                     local plr = null;
  121.            
  122.                     if ( IsNum( user ) ) plr = FindPlayer( user.tointeger() );
  123.                     else plr = FindPlayer( user );
  124.                    
  125.                     if ( plr )
  126.                     {
  127.                         EchoMessage( "IRC Admin " + nick + " has kicked " + plr + " [" + reason + "]" );
  128.                         KickPlayer( plr );
  129.                     }
  130.                     else
  131.                         IRC_PrivMsg( irc, IRC_ECHO_CHANNEL, "Player not found." );
  132.                 }
  133.             }
  134.         }
  135.     }
  136.     else if ( cmd == "!ban" )
  137.     {
  138.         local modes = IRC_GetUserModes( irc, channel, nick );
  139.         if ( modes != "" )
  140.         {
  141.             if ( IsIn( modes, "a" ) )
  142.             {
  143.                 // Person has operator on the channel
  144.                 local numArgs = NumTok( message, " " );
  145.                 if ( numArgs > 1 )
  146.                 {
  147.                     local user = GetTok( message, " ", 2 );
  148.                    
  149.                     local reason = "No Reason";
  150.                     if ( numArgs >= 3 )
  151.                         reason = GetTok( message, " ", 3, numArgs );
  152.                    
  153.                     local plr = null;
  154.            
  155.                     if ( IsNum( user ) ) plr = FindPlayer( user.tointeger() );
  156.                     else plr = FindPlayer( user );
  157.                    
  158.                     if ( plr )
  159.                     {
  160.                         EchoMessage( "IRC Admin " + nick + " has kicked " + plr + " [" + reason + "]" );
  161.                         BanPlayer( plr );
  162.                     }
  163.                     else
  164.                         IRC_PrivMsg( irc, IRC_ECHO_CHANNEL, "Player not found." );
  165.                 }
  166.             }
  167.         }
  168.     }
  169.     else
  170.     {
  171.         // If a command hasnt been issued, send the message
  172.         if ( channel == IRC_ECHO_CHANNEL )
  173.         {
  174.             if ( cmd[0] != '.' )
  175.                 Message( "(IRC) " + nick + ": " + message );
  176.         }
  177.     }
  178.    
  179.     //print( "(" + channel + ") " + nick + ": " + message );
  180. }
  181.  
  182. function onPlayerJoin( plr )
  183. {
  184.     IRC_PrivMsg( g_IRC, IRC_ECHO_CHANNEL, IRC_COL_LIGHTGREY + "[" + plr.ID + "] " + IRC_COL_BROWN + plr.Name + " has joined the server." );
  185. }
  186.  
  187. function onPlayerPart( plr, reasonid )
  188. {
  189.     local reason = "Unknown";
  190.     switch ( reasonid )
  191.     {
  192.         case PARTREASON_DISCONNECTED:
  193.             reason = "Disconnected";
  194.             break;
  195.         case PARTREASON_TIMEOUT:
  196.             reason = "Timeout";
  197.             break;
  198.         case PARTREASON_KICKED:
  199.             reason = "Kicked";
  200.             break;
  201.         case PARTREASON_BANNED:
  202.             reason = "Banned";
  203.             break;
  204.     }
  205.     IRC_PrivMsg( g_IRC, IRC_ECHO_CHANNEL, IRC_COL_LIGHTGREY + "[" + plr.ID + "] " + IRC_COL_BROWN + plr.Name + " has left the server. " + IRC_COL_RED + "[" + reason + "]" );
  206. }
  207.  
  208. function onPlayerChat( plr, text )
  209. {
  210.     IRC_PrivMsg( g_IRC, IRC_ECHO_CHANNEL, IRC_COL_LIGHTGREY + "[" + plr.ID + "] " + IRC_COL_AQUA + plr.Name + IRC_COL + ": " + text );
  211. }
  212.  
  213. function onConsoleInput( cmd, text )
  214. {
  215.     if ( cmd == "irc_join" )
  216.     {
  217.         IRC_Join( g_IRC, text, "" );
  218.     }
  219.     else if ( cmd == "irc_echo" )
  220.     {
  221.         IRC_PrivMsg( g_IRC, IRC_ECHO_CHANNEL, "Switching echo to " + text );
  222.         IRC_Part( g_IRC, IRC_ECHO_CHANNEL, "Moving echo channel" );
  223.         IRC_Join( g_IRC, text, "" );
  224.         IRC_PrivMsg( g_IRC, text, "Echo channel has been moved to here from " + IRC_ECHO_CHANNEL );
  225.         IRC_ECHO_CHANNEL <- text;
  226.     }
  227. }
Add Comment
Please, Sign In to add comment