]> ruin.nu Git - NDIRC.git/blobdiff - Commands/PA.pm
Added planet intel to g command
[NDIRC.git] / Commands / PA.pm
index 9f7ae8a4071542d536ee3e705c0db5288f8f256d..1db6ac1c8db4f4a3e5d288425ec8f86f3cc73a06 100644 (file)
@@ -91,16 +91,33 @@ sub g
        my ($self, $c, $msg) = @_;
 
        my ($x,$y) = ($msg =~ /(\d+)\D+(\d+)/) or die 'ARGS';
+       my $dbh = $c->model;
 
-       my $f = $c->model->prepare(q{
+       my $f = $dbh->prepare(q{
 SELECT score,scorerank,size,sizerank,value,valuerank,planets
 FROM galaxies WHERE x = ? AND y = ? AND tick = (SELECT max(tick) from galaxies)
-       });
+               });
        $f->execute($x,$y);
-       while (my @row = $f->fetchrow()){
-               @row = map (valuecolor(1),@row);
-               $c->reply("$x:$y  Score=$row[0] ($row[1]), Size=$row[2] ($row[3]), Value=$row[4] ($row[5]), Planets=$row[6]");
+       my @row = $f->fetchrow;
+       unless (@row){
+               $c->reply("No planet at $x:$y");
+               return;
+       }
+       my @planets;
+       if ($c->check_user_roles(qw/irc_g_intel/)) {
+               my $query = $dbh->prepare(q{
+SELECT z,COALESCE(nick,'?') AS nick,COALESCE(alliance,'?') AS alliance
+FROM current_planet_stats
+WHERE x = $1 AND y = $2 ORDER BY z
+               });
+               $query->execute($x,$y);
+               while(my $p = $query->fetchrow_hashref){
+                       push @planets, "$p->{z} [$p->{nick}/$p->{alliance}]";
+               }
        }
+       @row = map (valuecolor(1),@row);
+       $c->reply("$x:$y  Score=$row[0] ($row[1]), Size=$row[2] ($row[3]), Value=$row[4] ($row[5]), Planets=$row[6] - "
+               . join " ", @planets);
 }
 
 sub time