#!/usr/bin/perl #use warnings; use strict; use POE; use POE::Component::IRC; use POE::Component::Client::TCP; use POE::Filter::Stream;; ### BEGIN REMREM ### ## RenRem Settings my $renport = 4853; # The gameserver port my $renhost = 'somehost'; # Ip/hostname of the gameserver my $renpassword = 'somepass'; # admin password ## Buffering OFF! $| = 1; # Prevents buffering problems ##renrem output settings my $reout = 'off'; ### OUTPUT STARTUP MESSAGES TO CONSOLE my $botver = 'TRiNiTY build 118'; my $botver2 = 'A lightweight Renegade admin facility.'; my $startuptime = localtime; my $uptime = $startuptime; print " [$startuptime] ### TRiNiTY RenAdmin Facility. Designed by Phil W ;-) ###\n"; print " [$startuptime] ######\n"; print " [$startuptime] $botver Starting up...\n"; print " [$startuptime] Initializing connection to RenRem server...\n"; sub renrem_on # Connetion to RenRem POE::Component::Client::TCP->new ( RemoteAddress => $renhost, RemotePort => $renport, Connected => \&on_renconnect, ServerInput => \&on_renrecieve, Disconnected => \&on_rendisconnect, ); sub on_rendisconnect{ # Attempt to reconnect when disconnected from renrem my $tsa = localtime; #my $kernel; #$_[KERNEL]->delay( reconnect => 60 ); print " [$tsa] WARNING!:Disconnection Detected, trying to re-establish communication with renrem...\n"; } sub on_renconnect { my $ts = localtime; print " [$ts] Sucessfully connected to $renhost:$renport !...\n"; $_[HEAP]->{server}->put($renpassword); } sub on_renrecieve { my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP, ARG0 ]; my $ts = localtime; print " [$ts] $input\n"; # NOT all input is wanted, disguard any common stings which are not needed if($input =~ /GameSpy mode active/ || $input =~ /Id Name/ || $input =~ /Welcome to Renegade Remote Control/ || $input =~ /Score Side Ping Address/ || $input =~ /([0-9][0-9][0-9]\.[0-9][0-9]\.[0-9][0-9])/ || $input =~ /GDI/ || $input =~ /Nod/ || $input =~ /Gameplay in progress/ || $input =~ /Map :/ || $input =~ /NOD :/ || $input =~ /Gameplay Pending/ || $input =~ /Time :/ || $input =~ /Fps :/ || $input =~ /Total current bandwidth usage for players/ || $input =~ / NOD / || $input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W(Load)\W\d\d/ || $input =~ /Total current bandwidth usage for players/ || $input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W(Load)\W\d/) { # do nothing if these pattens are matched } elsif($input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W(No players)/) { #Check to see if no players are in the server $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." ); $reout = 'off'; } elsif($input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W[^@ \.]/) { #otherwise output to IRC $kernel->post( magnet => privmsg => '#ulfserver', $input ); } else { #disguard any unmatched or unwanted patterns #$kernel->post( magnet => privmsg => '#ulfserver', $input ); } } } ######################### RENREM COMPLETED - NOW CONNECT TO IRC ####################################################### sub CHANNEL () { "someircchannel" } my $botver2 = 'A standalone Renegade admin facility..'; #:: IRC Settings my $ircnetwork = 'someircserver'; my $ircport = 6667; my $ircname = 'TRiNiTY-'; my $ircident = $botver; my $ircnick = 'TRiNiTY-'; my $ircmode; # Create the component that will represent an IRC network. POE::Component::IRC->new("magnet"); # Create the bot session. The new() call specifies the events the bot # knows about and the functions that will handle those events. POE::Session->new ( _start => \&bot_start, irc_001 => \&on_connect, irc_public => \&on_public, irc_msg => \&on_msg, irc_mode => \&on_mode, ); # The bot session has started. Register this bot with the "magnet" # IRC component. Select a nickname. Connect to a server. sub bot_start { my $kernel = $_[KERNEL]; my $heap = $_[HEAP]; my $session = $_[SESSION]; $kernel->post( magnet => register => "all" ); #my $nick = 'TRiNiTY-'; $kernel->post( magnet => connect => { Nick => $ircnick, Username => $ircname, Ircname => $ircident, Server => $ircnetwork, Port => $ircport, } ); } # The bot has successfully connected to a server. Join a channel. sub on_connect { $_[KERNEL]->post( magnet => join => CHANNEL ); $_[KERNEL]->post( magnet => msg => "NickServ\@services.dal.net :IDENTIFY somepassword\r\n" ); } # Handle Private Messages to the Bot sub on_msg { my ( $kernel, $who, $where, $msg ) = @_[ KERNEL, ARG0, ARG1, ARG2 ]; my $nick = ( split /!/, $who )[0]; my $channel = $where->[0]; my $ts = localtime; print " [$ts] <$nick:$channel> $msg\n"; } # Will Handle Changes in status on the IRC channel sub on_mode { my ( $kernel, $from, $channel, $themode, $userchanged ) = @_[ KERNEL, ARG0, ARG1, ARG2, ARG3 ]; my $fromnick = ( split /!/, $from )[0]; my $ts = localtime; print " [$ts] <$fromnick:$channel> $themode $userchanged\n"; } # The bot has received a public message. Parse it for commands, and # respond to interesting things. sub on_public { my ( $kernel, $who, $where, $msg ) = @_[ KERNEL, ARG0, ARG1, ARG2 ]; my $nick = ( split /!/, $who )[0]; my $channel = $where->[0]; my $ts = localtime; ####### Print What Was Sent to IRC to The Console ###### print " [$ts] <$nick:$channel> $msg\n"; # !Version Sent if ($msg =~ /!version/) { print " [$ts] <$channel> version request detected\n"; $kernel->post( magnet => privmsg => CHANNEL, $botver ); $kernel->post( magnet => privmsg => CHANNEL, $botver2 ); } # !broadcast Messages Sent if ($msg =~ /!broadcast/) { #retrieve the message sent my $renmsg = split(/!broadcast/, $msg); print " [$ts] <$channel> msg $nick\@TRiNiTY\: $renmsg\n"; # output to console $kernel->post( magnet => privmsg => CHANNEL, "$nick\@TRiNiTY\: $renmsg\n"); #output to IRC ## HERE I WANT TO SENT THE $RENMSG FROM THE IRC CHANNEL TO THE TCP SERVER $_[HEAP]->{server}->put("msg $nick\@TRiNiTY\: $renmsg"); # sends message to tcp server } # !renrem sent if ($msg =~ /!renrem/) { if ($msg =~ /\-on/) { $kernel->post( magnet => privmsg => CHANNEL, "RenRem output mode: Activated!"); $reout = 'on'; } elsif ($msg =~ /\-off/) { $kernel->post( magnet => privmsg => CHANNEL, "RenRem output mode: Deactivated!"); $reout = 'off'; } elsif ($msg =~ /\-about/) { $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."); } else { $kernel->post( magnet => privmsg => CHANNEL, "!renrem (usage) < -about/-on/-off >"); } print " [$ts] RenRem output set to $reout by $nick on $channel\n" } } # Run the bot until it is done. $poe_kernel->run(); exit 0;