]> ruin.nu Git - NDIRC.git/commitdiff
Removed the global variables for special chans, using targets hashref in Dispatcher...
authorMichael Andreen <harv@ruin.nu>
Wed, 19 Aug 2009 22:28:42 +0000 (00:28 +0200)
committerMichael Andreen <harv@ruin.nu>
Wed, 19 Aug 2009 22:28:42 +0000 (00:28 +0200)
Commands/Def.pm
Commands/Scans.pm
CommonStates.pm
Dispatcher.pm
Eos.pm
ndawn.pl

index b115dd44be93aefc3cdcdc315e34fa02a88302fb..d7862a364fdbe6d1ddda62cfeda6a0f34e4e6096 100644 (file)
@@ -75,9 +75,9 @@ ORDER BY c.landing_tick;
                        return;
                }
        }
-       $c->message(notice => $ND::memchan, "DEFENSE REQUIRED!! WAKE UP!!");
-       $c->message(privmsg => $ND::memchan, "DEFENSE REQUIRED $mess $callinfo MSG "
-               .$c->nick." TO RESPOND");
+       $c->message(notice => $c->disp->targets->{members}, "DEFENSE REQUIRED!! WAKE UP!!");
+       $c->message(privmsg => $c->disp->targets->{members}, "DEFENSE REQUIRED "
+               ."$mess $callinfo MSG ".$c->nick." TO RESPOND");
 }
 
 sub settype
index acfe9a90cbecb27f1b5012c24a7376be2093f6d5..315903190c6ddf5b5e15e57f4d5c9cf9c3ed10a6 100644 (file)
@@ -93,7 +93,7 @@ VALUES((SELECT uid FROM users WHERE hostmask ILIKE $1),$2,$3,$4) RETURNING (id)
                }
 
                if ($id){
-                       $c->message(privmsg => $ND::scanchan
+                       $c->message(privmsg =>$c->disp->targets->{scans}
                                ,"<b>$id</b> http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z"
                                . " ($x:$y:$z $type) | <".$c->nick."> $msg"
                        );
index 5c0ab703aefd63b66691b72f955e322a8f67df94..e46481cdc0f648f93e27539a14cf4368ca880ef9 100644 (file)
@@ -121,6 +121,10 @@ sub sig_usr2 {
        while (<$channels>){
                my ($chan, @types) = split /\s+/;
                say "$chan - @types";
+               if ($chan =~ /^(.*):(.*)$/){
+                       $chan = $1;
+                       $disp->set_target($2,$chan);
+               }
                $disp->add_channel($chan,\@types);
        }
 
index a96c32e164843fda69c1998d5b18abad2f89fa4f..7c4b0a60618c10eaa56180bf1dcd9729102c38b9 100644 (file)
@@ -30,17 +30,23 @@ use NDIRC::Command;
 
 
 has commands => (
-       is => 'rw',
+       is => 'ro',
        isa => 'HashRef[Object]',
        default => sub{ {} },
 );
 
 has channels => (
-       is => 'rw',
+       is => 'ro',
        isa => 'HashRef[ArrayRef[Str]]',
        default => sub{ {} },
 );
 
+has targets => (
+       is => 'ro',
+       isa => 'HashRef[Str]',
+       default => sub{ {} },
+);
+
 sub load {
        my $self = shift;
 
@@ -122,6 +128,11 @@ sub has_command {
        return 0;
 }
 
+sub set_target {
+       my ($self,$label,$target) = @_;
+       $self->targets->{$label} = $target;
+}
+
 sub run_command {
        my ($self,$c,$command,$args) = @_;
 
diff --git a/Eos.pm b/Eos.pm
index 325f69591eee73b1428af2be9d23d6cc010a0c8b..079b7c9012ddc7acdc00a6f3c54bb369669b8bf5 100644 (file)
--- a/Eos.pm
+++ b/Eos.pm
@@ -58,8 +58,9 @@ sub irc_msg {
        if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},DB())){
                #Command parsed and run successfully
        }else{
-               $irc->yield(privmsg => $ND::defchan, chr(3)."04 $nick >> $msg");
-               parseCommand("~report_incs $msg",$irc,$nick,' BATCH ',$ND::defchan,$heap->{disp},DB());
+               my $disp = $heap->{disp};
+               $irc->yield(privmsg => $disp->targets->{def}, chr(3)."04 $nick >> $msg");
+               parseCommand("~report_incs $msg",$irc,$nick,' BATCH ',$disp->targets->{def},$heap->{disp},DB());
        }
 }
 
@@ -67,10 +68,11 @@ sub irc_join {
        my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
        my ($nick,$username,$address) = ( split /[!@]/, $who );
        my $irc = $sender->get_heap();
+       my $disp = $heap->{disp};
 
        my $dbh = DB();
 
-       if ($channel =~ /^$ND::memchan$/i){
+       if (lc $channel ~~ lc $disp->targets->{members}){
                if (time - $last_announcement < 1){
                        $last_announcement = time;
                        return;
@@ -82,14 +84,14 @@ FROM users u WHERE hostmask = ?
                }, undef, $address);
                if ($user){
                        if ($user->{password} eq ''){
-                               $irc->yield(privmsg => $ND::memchan, "$nick: Get a new random password with /msg delling !getpass . If you don't know your username, then you can get it with .points");
+                               $irc->yield(privmsg => $disp->targets->{members}, "$nick: Get a new random password with /msg delling !getpass . If you don't know your username, then you can get it with .points");
                        }
                        if ($tick > 36 && not defined $user->{pid}){
-                               $irc->yield(privmsg => $ND::memchan, "$nick: go to https://nd.ruin.nu/ and enter your coords.");
+                               $irc->yield(privmsg => $disp->targets->{members}, "$nick: go to https://nd.ruin.nu/ and enter your coords.");
                        }
 
                        if (not defined $user->{last_forum_visit}){
-                               $irc->yield(privmsg => $ND::memchan, "$nick: Go read the forum! https://nd.ruin.nu/forum");
+                               $irc->yield(privmsg => $disp->targets->{members}, "$nick: Go read the forum! https://nd.ruin.nu/forum");
                        }else {
                                my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
                                if ($unread && $unread->{new}){
@@ -111,28 +113,27 @@ sub refresh {
        print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
 
        my $irc = $heap->{irc};
+       my $disp = $heap->{disp};
        my $dbh = DB();
 
        my @row = $dbh->selectrow_array(q{SELECT tick(), max(tick) FROM planet_stats});
        if ($tick != $row[0]){
                $tick = $row[0];
-               $irc->yield(privmsg => $ND::defchan, "New tick: $tick");
+               $irc->yield(privmsg => $disp->targets->{def}, "New tick: $tick");
        }
        if (defined $row[1] && $stattick != $row[1]){
                $stattick = $row[1];
-               $irc->yield(privmsg => $ND::memchan, "New tick: $stattick");
+               $irc->yield(privmsg => $disp->targets->{members}, "New tick: $stattick");
        }
        my $ircreqs = $dbh->prepare(q{SELECT id,username,message,channel FROM irc_requests NATURAL JOIN users WHERE not sent});
        my $upircreq = $dbh->prepare(q{UPDATE irc_requests SET sent = TRUE WHERE id = ?});
        $ircreqs->execute;
        while (my $req = $ircreqs->fetchrow_hashref){
                if ($req->{channel} eq 'def'){
-                       $irc->yield(privmsg => $ND::defchan, chr(3)."04 ## $req->{username} via webbie ## >> $req->{message}");
-                       parseCommand("~report_incs $req->{message}",$irc,$req->{username},' BATCH ',$ND::defchan,$heap->{disp},$dbh);
-               }elsif($req->{channel} eq 'scan'){
-                       $irc->yield(privmsg => $ND::scanchan, "<$req->{username} via webbie> $req->{message}");
-               }elsif($req->{channel} eq 'members'){
-                       $irc->yield(privmsg => $ND::memchan, "<$req->{username} via webbie> $req->{message}");
+                       $irc->yield(privmsg => $disp->targets->{def}, chr(3)."04 ## $req->{username} via webbie ## >> $req->{message}");
+                       parseCommand("~report_incs $req->{message}",$irc,$req->{username},' BATCH ',$disp->targets->{def},$heap->{disp},$dbh);
+               }elsif(exists $disp->targets->{$req->{channel}}){
+                       $irc->yield(privmsg => $disp->targets->{$req->{channel}}, "<$req->{username} via webbie> $req->{message}");
                }
                $upircreq->execute($req->{id});
        }
@@ -152,7 +153,7 @@ GROUP BY username,call,tick,dm.fleet,p.value
        my $updefmis = $dbh->prepare(q{UPDATE defense_missions SET announced = TRUE WHERE fleet = ?});
        $defmissions->execute();
        while (my $mission = $defmissions->fetchrow_hashref){
-               $irc->yield(privmsg => $ND::defchan, chr(3)."06 $mission->{username} sent def to call $mission->{call}, $mission->{value}% of value (tick $mission->{tick}) https://nd.ruin.nu/calls/edit/$mission->{call}");
+               $irc->yield(privmsg => $disp->targets->{def}, chr(3)."06 $mission->{username} sent def to call $mission->{call}, $mission->{value}% of value (tick $mission->{tick}) https://nd.ruin.nu/calls/edit/$mission->{call}");
                $updefmis->execute($mission->{fleet});
        }
 }
index e89dc3a38cb982966c07beb93212779e23bea834..ca60ea24e1c6593a29fe7339661c61290e15eafa 100755 (executable)
--- a/ndawn.pl
+++ b/ndawn.pl
@@ -28,6 +28,8 @@ use POE qw(Component::IRC::Qnet::State);
 use NDIRC::CommonStates;
 eval "require NDIRC::$ARGV[0]";
 
+die $@ if $@;
+
 # We create a new PoCo-IRC object
 my $irc = POE::Component::IRC::Qnet::State->spawn(
        nick => $ARGV[0],
@@ -36,10 +38,6 @@ my $irc = POE::Component::IRC::Qnet::State->spawn(
 
 $irc->service_bots(QBOT => 'P@cservice.netgamers.org');
 
-$ND::scanchan = '#testarmer';
-$ND::defchan = '#testarlite';
-$ND::memchan = '#testarmer';
-
 POE::Session->create(
        package_states => [
                'NDIRC::CommonStates' => [ qw(_default _start irc_001 sig_DIE sig_usr1 sig_usr2