]> ruin.nu Git - NDIRC.git/blobdiff - Commands/PA.pm
Added planet intel to g command
[NDIRC.git] / Commands / PA.pm
index 500e93b8e7b65874ca948978566bd566d6307b6e..1db6ac1c8db4f4a3e5d288425ec8f86f3cc73a06 100644 (file)
@@ -70,7 +70,7 @@ WITH p AS (SELECT pid,coords(x,y,z),ruler,planet,race,score,size,value,scorerank
 )
 SELECT * FROM p, tags;
        });
-       $f->execute($x,$y,$z,$nick,$c->uid,$c->check_user_roles(qw/irc_p_intel/));
+       $f->execute($x,$y,$z,$nick,$c->uid,$c->check_user_roles(qw/irc_p_intel/) // 0);
        if (my $planet = $f->fetchrow_hashref()){
                for (keys %{$planet}){
                        $planet->{$_} = valuecolor(1,$planet->{$_});
@@ -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