X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=blobdiff_plain;f=CommonStates.pm;h=5c0ab703aefd63b66691b72f955e322a8f67df94;hp=b91cd9f1e39d235f62cb8259b0cade333c078a64;hb=a4667cce6415476312d6932f92f89fb28101ab88;hpb=4c40fd39668614135ae9370092b5d17355bad15c diff --git a/CommonStates.pm b/CommonStates.pm index b91cd9f..5c0ab70 100644 --- a/CommonStates.pm +++ b/CommonStates.pm @@ -26,9 +26,13 @@ use POE::Session; use POE::Component::IRC::Plugin::Logger; use POE::Component::IRC::Plugin::BotTraffic; use POE::Component::IRC::Plugin::Connector; +use POE::Component::IRC::Plugin::AutoJoin; +use POE::Component::IRC::Plugin::NickReclaim; use NDIRC::Dispatcher; +use IO::File; + # We registered for all events, this will produce some debug info. sub _default { my ($event, $args) = @_[ARG0 .. $#_]; @@ -56,6 +60,8 @@ sub _start { $kernel->sig( USR2 => 'sig_usr2' ); $kernel->sig( INT => 'signal_handler' ); + $irc->plugin_add( 'NickReclaim', POE::Component::IRC::Plugin::NickReclaim->new() ); + $irc->plugin_add( 'AutoJoin', POE::Component::IRC::Plugin::NickReclaim->new() ); $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() ); $irc->plugin_add('Logger', POE::Component::IRC::Plugin::Logger->new( Path => 'irclogs', @@ -67,41 +73,56 @@ sub _start { Strip_formatting => 1, )); - $heap->{connector} = POE::Component::IRC::Plugin::Connector->new(); + $heap->{connector} = POE::Component::IRC::Plugin::Connector->new( + servers => ['irc.netgamers.org', 'underworld.no.eu.netgamers.org' + ,'firefly.no.eu.netgamers.org', 'underworld.ca.us.netgamers.org' ] + ); $irc->plugin_add( 'Connector' => $heap->{connector} ); $kernel->signal($session => 'USR2'); $irc->yield( register => 'all' ); - $irc->yield( connect => { } ); + $irc->yield( connect => { server => 'irc.netgamers.org' } ); $kernel->delay( refresh => 60 ); return; } +sub auth { + my $heap = $_[HEAP]; + + if (my $f = new IO::File 'auth'){ + my $user = <$f>; + chomp $user; + my $pass = <$f>; + chomp $pass; + $heap->{irc}->yield(qbot_auth => $user => $pass); + } +} + sub sig_usr1 { - my $kernel = $_[KERNEL]; + my ($kernel,$heap) = @_[KERNEL,HEAP]; + $kernel->yield( 'refresh' ); } sub sig_usr2 { my $heap = $_[HEAP]; - open COMMANDS, 'commands'; - my @commands = split /\W+/, do { local $/; }; - close COMMANDS; - - say "Loading commands from: @commands"; my $disp = new NDIRC::Dispatcher; - $disp->load(@commands); - open CHANNELS, 'channels'; - while (){ + if (my $commands = new IO::File 'commands'){ + my @commands = split /\W+/, do{local $/; <$commands>}; + say "Loading commands from: @commands"; + $disp->load(@commands); + } + + my $channels = new IO::File 'channels'; + while (<$channels>){ my ($chan, @types) = split /\s+/; say "$chan - @types"; $disp->add_channel($chan,\@types); } - close CHANNELS; $heap->{disp} = $disp; } @@ -127,6 +148,7 @@ sub signal_handler { given($signal_name){ when ('INT') { exit unless $heap->{irc}->connected; + $heap->{INT} = 1; $heap->{irc}->yield(quit => 'Bye!'); $kernel->sig_handled(); } @@ -137,11 +159,11 @@ sub signal_handler { sub irc_disconnected { my ($sender,$heap) = @_[SENDER,HEAP]; - exit; + exit if $heap->{INT}; } sub irc_001 { - my ($sender,$heap) = @_[SENDER,HEAP]; + my ($sender,$heap,$kernel) = @_[SENDER,HEAP,KERNEL]; # Since this is an irc_* event, we can get the component's object by # accessing the heap of the sender. Then we register and connect to the @@ -150,6 +172,9 @@ sub irc_001 { print "Connected to ", $irc->server_name(), "\n"; + $kernel->yield( 'auth' ); + $irc->yield( mode => $irc->nick_name, '+ix'); + # we join our channels $irc->yield( join => $_ ) for grep /^#/, keys %{$heap->{disp}->channels}; return;