From c6964887c87acd5769ec90ce8734407f74433fc7 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Wed, 6 May 2009 21:49:57 +0200 Subject: [PATCH] Converted the .p command --- Commands/PA.pm | 66 ++++++++++++++++++++++++++++++++++++++++++++++ PA.pm | 34 +----------------------- database/roles.sql | 18 +++++++++++++ ndawn.pl | 2 +- 4 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 Commands/PA.pm create mode 100644 database/roles.sql diff --git a/Commands/PA.pm b/Commands/PA.pm new file mode 100644 index 0000000..87e2290 --- /dev/null +++ b/Commands/PA.pm @@ -0,0 +1,66 @@ +#************************************************************************** +# Copyright (C) 2008 by Michael Andreen * +# * +# 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 6c39098..04cf743 100644 --- 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 index 0000000..e0263be --- /dev/null +++ b/database/roles.sql @@ -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'); diff --git a/ndawn.pl b/ndawn.pl index 6ddc8f7..ffb7e58 100644 --- 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']); -- 2.39.2