Advertisement
Brandan

RenRem

Jul 1st, 2012
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.37 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #use warnings;
  4. use strict;
  5.  
  6. use POE;
  7. use POE::Component::IRC;
  8. use POE::Component::Client::TCP;
  9. use POE::Filter::Stream;;
  10.  
  11. ### BEGIN REMREM ###
  12.  
  13. ## RenRem Settings
  14. my $renport = 4853;    # The gameserver port
  15. my $renhost  = 'somehost';  # Ip/hostname of the gameserver
  16. my $renpassword = 'somepass';  # admin password
  17.  
  18. ## Buffering OFF!
  19. $| = 1; # Prevents buffering problems
  20.  
  21. ##renrem output settings
  22. my $reout = 'off';
  23.  
  24. ### OUTPUT STARTUP MESSAGES TO CONSOLE
  25. my $botver = 'TRiNiTY build 118';
  26. my $botver2 = 'A lightweight Renegade admin facility.';
  27. my $startuptime = localtime;
  28. my $uptime = $startuptime;
  29. print " [$startuptime] ### TRiNiTY RenAdmin Facility. Designed by Phil W ;-) ###\n";
  30. print " [$startuptime] ######\n";
  31. print " [$startuptime] $botver Starting up...\n";
  32. print " [$startuptime] Initializing connection to RenRem server...\n";
  33.  
  34. sub renrem_on
  35. # Connetion to RenRem
  36. POE::Component::Client::TCP->new
  37.       ( RemoteAddress => $renhost,
  38.         RemotePort => $renport,        
  39.         Connected => \&on_renconnect,
  40.     ServerInput => \&on_renrecieve,
  41.     Disconnected   => \&on_rendisconnect,
  42.       );
  43.  
  44. sub on_rendisconnect{
  45.     # Attempt to reconnect when disconnected from renrem
  46.     my $tsa = localtime;
  47.     #my $kernel;
  48.     #$_[KERNEL]->delay( reconnect => 60 );
  49.     print " [$tsa] WARNING!:Disconnection Detected, trying to re-establish communication with renrem...\n";
  50. }
  51.  
  52. sub on_renconnect {
  53.         my $ts = localtime;
  54.             print " [$ts] Sucessfully connected to $renhost:$renport !...\n";
  55.         $_[HEAP]->{server}->put($renpassword);    
  56. }
  57.  
  58. sub on_renrecieve {
  59.        my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP, ARG0 ];
  60.        my $ts = localtime;
  61.        print " [$ts] $input\n";
  62.        
  63.        # NOT all input is wanted, disguard any common stings which are not needed
  64.         if($input =~ /GameSpy mode active/ || $input =~ /Id  Name/ || $input =~ /Welcome to Renegade Remote
  65. Control/ || $input =~ /Score Side Ping Address/ || $input =~ /([0-9][0-9][0-9]\.[0-9][0-9]\.[0-9][0-9])/ || $input =~
  66. /GDI/ || $input =~ /Nod/ || $input =~ /Gameplay in progress/ || $input =~ /Map :/ || $input =~ /NOD :/ || $input =~
  67. /Gameplay Pending/ || $input =~ /Time :/ || $input =~ /Fps :/ || $input =~ /Total current bandwidth usage for
  68. players/ || $input =~ /  NOD / || $input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W(Load)\W\d\d/ || $input =~
  69. /Total current bandwidth usage for players/ || $input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W(Load)\W\d/)
  70.         {
  71.             # do nothing if these pattens are matched
  72.         }
  73.         elsif($input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W(No players)/)
  74.         {
  75.             #Check to see if no players are in the server
  76.             $kernel->post( magnet => privmsg => '#ulfserver', "Warning: The renrem output module has been deactivated due to the server being empty at present. It can be re-enabled at a later date using the \!renrem \-on command." );
  77.             $reout = 'off';
  78.         }  
  79.         elsif($input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W[^@ \.]/)
  80.         {
  81.             #otherwise output to IRC
  82.             $kernel->post( magnet => privmsg => '#ulfserver', $input );
  83.         }
  84.         else
  85.         {  
  86.             #disguard any unmatched or unwanted patterns    
  87.             #$kernel->post( magnet => privmsg => '#ulfserver', $input );
  88.             }
  89.        }
  90.  
  91. }
  92. ######################### RENREM COMPLETED - NOW CONNECT TO IRC #######################################################
  93.  
  94. sub CHANNEL () { "someircchannel" }
  95. my $botver2 = 'A standalone Renegade admin facility..';
  96.  
  97. #:: IRC Settings
  98. my $ircnetwork = 'someircserver';
  99. my $ircport = 6667;    
  100. my $ircname = 'TRiNiTY-';
  101. my $ircident = $botver;
  102. my $ircnick = 'TRiNiTY-';
  103. my $ircmode;
  104.  
  105. # Create the component that will represent an IRC network.
  106. POE::Component::IRC->new("magnet");
  107.  
  108. # Create the bot session.  The new() call specifies the events the bot
  109. # knows about and the functions that will handle those events.
  110. POE::Session->new
  111.   ( _start => \&bot_start,
  112.     irc_001    => \&on_connect,
  113.     irc_public => \&on_public,
  114.     irc_msg => \&on_msg,
  115.     irc_mode => \&on_mode,
  116.   );
  117.  
  118. # The bot session has started.  Register this bot with the "magnet"
  119. # IRC component.  Select a nickname.  Connect to a server.
  120.  
  121. sub bot_start {
  122.     my $kernel  = $_[KERNEL];
  123.     my $heap    = $_[HEAP];
  124.     my $session = $_[SESSION];
  125.     $kernel->post( magnet => register => "all" );
  126.  
  127.     #my $nick = 'TRiNiTY-';
  128.     $kernel->post( magnet => connect =>
  129.           { Nick => $ircnick,
  130.             Username => $ircname,
  131.             Ircname  => $ircident,
  132.             Server   => $ircnetwork,
  133.             Port     => $ircport,
  134.           }
  135.     );
  136. }
  137.  
  138. # The bot has successfully connected to a server.  Join a channel.
  139. sub on_connect {
  140.         $_[KERNEL]->post( magnet => join => CHANNEL );
  141.         $_[KERNEL]->post( magnet => msg => "NickServ\@services.dal.net :IDENTIFY somepassword\r\n" );
  142. }
  143.  
  144. # Handle Private Messages to the Bot
  145.  
  146. sub on_msg {
  147.  
  148.     my ( $kernel, $who, $where, $msg ) = @_[ KERNEL, ARG0, ARG1, ARG2 ];
  149.     my $nick = ( split /!/, $who )[0];
  150.         my $channel = $where->[0];
  151.         my $ts = localtime;
  152.  
  153.     print " [$ts] <$nick:$channel> $msg\n";
  154.  
  155. }
  156.  
  157. # Will Handle Changes in status on the IRC channel
  158.  
  159. sub on_mode {
  160.    
  161.     my ( $kernel, $from, $channel, $themode, $userchanged ) = @_[ KERNEL, ARG0, ARG1, ARG2, ARG3 ];
  162.         my $fromnick = ( split /!/, $from )[0];
  163.     my $ts = localtime;
  164.    
  165.     print " [$ts] <$fromnick:$channel> $themode $userchanged\n";
  166.    
  167.    
  168.        
  169. }
  170.  
  171. # The bot has received a public message.  Parse it for commands, and
  172. # respond to interesting things.
  173.  
  174. sub on_public {
  175.  
  176.     my ( $kernel, $who, $where, $msg ) = @_[ KERNEL, ARG0, ARG1, ARG2 ];
  177.     my $nick = ( split /!/, $who )[0];
  178.     my $channel = $where->[0];
  179.     my $ts = localtime;
  180.    
  181.     ####### Print What Was Sent to IRC to The Console ######
  182.     print " [$ts] <$nick:$channel> $msg\n";
  183.  
  184.  
  185.     # !Version Sent
  186.     if ($msg =~ /!version/) {
  187.    
  188.     print " [$ts] <$channel> version request detected\n";    
  189.     $kernel->post( magnet => privmsg => CHANNEL, $botver );
  190.         $kernel->post( magnet => privmsg => CHANNEL, $botver2 );
  191.     }
  192.     # !broadcast Messages Sent
  193.     if ($msg =~ /!broadcast/) {
  194.    
  195.     #retrieve the message sent
  196.     my $renmsg = split(/!broadcast/, $msg);
  197.     print " [$ts] <$channel> msg $nick\@TRiNiTY\: $renmsg\n"; # output to console
  198.     $kernel->post( magnet => privmsg => CHANNEL, "$nick\@TRiNiTY\: $renmsg\n"); #output to IRC
  199.    
  200.     ## HERE I WANT TO SENT THE $RENMSG FROM THE IRC CHANNEL TO THE TCP SERVER
  201.     $_[HEAP]->{server}->put("msg $nick\@TRiNiTY\: $renmsg");    # sends message to tcp server
  202.     }  
  203.  
  204.    # !renrem sent
  205.    if ($msg =~ /!renrem/) {
  206.     if ($msg =~ /\-on/)
  207.     {
  208.         $kernel->post( magnet => privmsg => CHANNEL, "RenRem output mode: Activated!");
  209.         $reout = 'on';
  210.     }
  211.     elsif ($msg =~ /\-off/)
  212.     {
  213.         $kernel->post( magnet => privmsg => CHANNEL, "RenRem output mode: Deactivated!");
  214.         $reout = 'off';
  215.     }
  216.     elsif ($msg =~ /\-about/)
  217.         {
  218.                 $kernel->post( magnet => privmsg => CHANNEL, "$nick: About the RenRem TRiNiTY plugin \- This module allows for server messages to be forwarded over the IRC chat protocol to a pool of clients and provides key gameserver functionality.");
  219.         }
  220.         else
  221.     {      
  222.         $kernel->post( magnet => privmsg => CHANNEL, "!renrem (usage) < -about/-on/-off >");
  223.     }
  224.     print " [$ts] RenRem output set to $reout by $nick on $channel\n"
  225.     }
  226.  
  227.        
  228. }
  229.  
  230.  
  231. # Run the bot until it is done.
  232. $poe_kernel->run();
  233. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement