]> ruin.nu Git - NDIRC.git/blobdiff - Commands/PA.pm
Added planet intel to g command
[NDIRC.git] / Commands / PA.pm
index 52fb3a007a1241c3cdc9e234f3c244cc3defde45..1db6ac1c8db4f4a3e5d288425ec8f86f3cc73a06 100644 (file)
@@ -55,11 +55,22 @@ sub p
        }
 
        my $f = $c->model->prepare(q{
-SELECT coords(x,y,z),ruler,planet,race,score,size,value,scorerank,sizerank,
-       valuerank, xp, xprank, alliance, relationship, nick, planet_status, hit_us, channel
-FROM current_planet_stats WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4 LIMIT 1
+WITH p AS (SELECT pid,coords(x,y,z),ruler,planet,race,score,size,value,scorerank,sizerank,
+               valuerank, xp, xprank, alliance, relationship, nick, planet_status, hit_us, channel
+       FROM current_planet_stats
+       WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4 LIMIT 1
+), t AS (SELECT tag,bool_or(uid = $5) AS own,max(time) AS time
+       FROM planet_tags
+       WHERE pid = (SELECT pid FROM p)
+               AND ($6 OR uid = $5)
+       GROUP BY tag
+       ORDER BY time DESC
+), tags AS (SELECT array_to_string(array_agg(tag || CASE WHEN own THEN '*' ELSE '' END),' ') AS tags
+       FROM t
+)
+SELECT * FROM p, tags;
        });
-       $f->execute($x,$y,$z,$nick);
+       $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->{$_});
@@ -68,7 +79,7 @@ FROM current_planet_stats WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4
                if ($c->check_user_roles(qw/irc_p_intel/)){
                        $ally = "Alliance=$planet->{alliance} ($planet->{relationship}), Nick=$planet->{nick} ($planet->{planet_status}), Channel: $planet->{channel}, Hostile Count: $planet->{hit_us},";
                }
-               $c->reply("$planet->{coords} $planet->{ruler} OF $planet->{planet},$ally Race=$planet->{race}, Score=$planet->{score} ($planet->{scorerank}), Size=$planet->{size} ($planet->{sizerank}), Value=$planet->{value} ($planet->{valuerank}), XP=$planet->{xp} ($planet->{xprank})");
+               $c->reply("$planet->{coords} $planet->{ruler} OF $planet->{planet},$ally Race=$planet->{race}, Score=$planet->{score} ($planet->{scorerank}), Size=$planet->{size} ($planet->{sizerank}), Value=$planet->{value} ($planet->{valuerank}), XP=$planet->{xp} ($planet->{xprank}) TAGS: $planet->{tags}");
        }else{
                $c->reply("Couldn't find planet: $msg");
        }
@@ -80,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