]> ruin.nu Git - NDIRC.git/commitdiff
Converted the .p command
authorMichael Andreen <harv@ruin.nu>
Wed, 6 May 2009 19:49:57 +0000 (21:49 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 9 May 2009 13:35:50 +0000 (15:35 +0200)
Commands/PA.pm [new file with mode: 0644]
PA.pm
database/roles.sql [new file with mode: 0644]
ndawn.pl

diff --git a/Commands/PA.pm b/Commands/PA.pm
new file mode 100644 (file)
index 0000000..87e2290
--- /dev/null
@@ -0,0 +1,66 @@
+#**************************************************************************
+#   Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package NDIRC::Commands::PA;
+
+use strict;
+use warnings;
+
+use Moose;
+use MooseX::MethodAttributes;
+
+use NDIRC::Misc;
+
+sub p
+       : Help(usage: .p X:Y:Z | or .p nick with high enough access)
+{
+       my ($self, $c, $msg) = @_;
+
+       my ($x,$y,$z,$nick);
+       if ($msg =~ /(\d+)\D+(\d+)\D+(\d+)/){
+               $x = $1;
+               $y = $2;
+               $z = $3;
+       }elsif ($msg && $c->check_user_roles(qw/irc_p_nick/)){
+               $nick = $msg;
+       }else{
+               die "ARGS";
+       }
+
+       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
+       });
+       $f->execute($x,$y,$z,$nick);
+       if (my $planet = $f->fetchrow_hashref()){
+               for (keys %{$planet}){
+                       $planet->{$_} = valuecolor(1,$planet->{$_});
+               }
+               my $ally = "";
+               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})");
+       }else{
+               $c->reply("Couldn't find planet: $msg");
+       }
+}
+
+1;
diff --git a/PA.pm b/PA.pm
index 6c39098a874249213da80824b51c70cfd49d5455..04cf743386feaa8847b9415721d276f3f67fed30 100644 (file)
--- a/PA.pm
+++ b/PA.pm
@@ -28,40 +28,8 @@ require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/checkPlanet checkGal shipEff shipStop parseValue prettyValue calcXp findCovOpper tick_time/;
+our @EXPORT = qw/checkGal shipEff shipStop parseValue prettyValue calcXp findCovOpper tick_time/;
 
-sub checkPlanet {
-       my ($msg) = @_;
-
-       my ($x,$y,$z,$nick);
-       if ($msg =~ /(\d+)\D+(\d+)\D+(\d+)/){
-               $x = $1;
-               $y = $2;
-               $z = $3;
-       }elsif ((officer() || ia() || intel()) && defined $msg){
-               $nick = $msg;
-       }else{
-               $ND::server->command("notice $ND::nick usage .p X:Y:Z".(officer() || ia() ? ' or .p nick' : ''));
-               return;
-       }
-       my $f = $ND::DBH->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
-       });
-       $f->execute($x,$y,$z,$nick);
-       if (my $planet = $f->fetchrow_hashref()){
-               for (keys %{$planet}){
-                       $planet->{$_} = valuecolor(1,$planet->{$_});
-               }
-               my $ally = "";
-               if (officer() || ia() || dc() || intel()){
-                       $ally = "Alliance=$planet->{alliance} ($planet->{relationship}), Nick=$planet->{nick} ($planet->{planet_status}), Channel: $planet->{channel}, Hostile Count: $planet->{hit_us},";
-               }
-               $ND::server->command("notice $ND::nick $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})");
-       }else{
-               $ND::server->command("notice $ND::nick Couldn't find planet: $msg");
-       }
-}
 sub checkGal {
        my ($msg) = @_;
 
diff --git a/database/roles.sql b/database/roles.sql
new file mode 100644 (file)
index 0000000..e0263be
--- /dev/null
@@ -0,0 +1,18 @@
+INSERT INTO roles VALUES('irc_p_nick');
+INSERT INTO roles VALUES('irc_p_intel');
+
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
+INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
+
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_p_nick');
+INSERT INTO group_roles (gid,role) VALUES(3,'irc_p_intel');
+
+INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_nick');
+INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_intel');
+
+INSERT INTO group_roles (gid,role) VALUES(6,'irc_p_intel');
+
+INSERT INTO group_roles (gid,role) VALUES(18,'irc_p_nick');
+INSERT INTO group_roles (gid,role) VALUES(18,'irc_p_intel');
+
+INSERT INTO group_roles (gid,role) VALUES(19,'irc_p_intel');
index 6ddc8f74d44d134e80c95c03bf194e68166fd0aa..ffb7e5851a9ec17c1c396af7722d7887b6290a49 100644 (file)
--- a/ndawn.pl
+++ b/ndawn.pl
@@ -55,7 +55,7 @@ my $TICK = $DBH->selectrow_array('SELECT tick()');
 
 my $disp = new NDIRC::Dispatcher;
 
-$disp->load('Basic');
+$disp->load('Basic','PA');
 
 $disp->add_channel('#testarlite', ['pub','help']);
 $disp->add_channel('#testarmer', ['pub','help']);