From f6172920f8ba7bfd9a15260edcf01322bf09472b Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sat, 16 May 2009 23:31:14 +0200 Subject: [PATCH] Converted .sethostile --- Commands/Intel.pm | 49 ++++++++++++++++++++++++++++++++++++++++++++++ Context.pm | 11 +++++++++++ Intel.pm | 24 +---------------------- database/roles.sql | 5 +++++ ndawn.pl | 2 +- 5 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 Commands/Intel.pm diff --git a/Commands/Intel.pm b/Commands/Intel.pm new file mode 100644 index 0000000..5e79c96 --- /dev/null +++ b/Commands/Intel.pm @@ -0,0 +1,49 @@ +#************************************************************************** +# Copyright (C) 2009 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::Intel; + +use strict; +use warnings; +use feature ':5.10'; + +use Moose; +use MooseX::MethodAttributes; + +sub sethostile + : Help(Usage: .sethostile X:Y:Z) + : ACL(irc_sethostile) +{ + my ($self,$c,$msg) = @_; + my ($x,$y,$z) = $msg =~ /^(\d+)\D(\d+)\D(\d+)$/ or die 'ARGS'; + my $dbh = $c->model; + + my $findid = $dbh->prepare(q{SELECT planetid(?,?,?,tick())}); + my ($id) = $dbh->selectrow_array($findid,undef,$x,$y,$z); + $dbh->begin_work; + my $rv = $dbh->do(q{UPDATE planets SET planet_status = 'Hostile' WHERE id = $1} + ,undef,$id); + if ($rv == 1){ + $c->reply("$x:$y:$z is now marked s hostile"); + $c->intel_log($id,"Set planet_status to: 'Hostile'"); + } + $dbh->commit; +} + +1; diff --git a/Context.pm b/Context.pm index 9d37655..6831bde 100644 --- a/Context.pm +++ b/Context.pm @@ -109,6 +109,17 @@ sub message { $self->server->command("$command $msg"); } +sub intel_log { + my ($c,$planet, $message) = @_; + my $log = $c->model->prepare_cached(q{ +INSERT INTO forum_posts (ftid,uid,message) VALUES( + (SELECT ftid FROM planets WHERE id = $3) + ,(SELECT uid FROM users WHERE hostmask ILIKE $1) + ,$2) + }); + $log->execute($c->host,$message,$planet); +} + sub _build_roles { my ($self) = @_; diff --git a/Intel.pm b/Intel.pm index 18ea15f..7594c09 100644 --- a/Intel.pm +++ b/Intel.pm @@ -27,29 +27,7 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/setHostile setNick setAlly setChannel/; - -sub setHostile { - my ($msg, $command) = @_; - my ($x,$y,$z); - if(defined $msg && $msg =~ /^(\d+)\D(\d+)\D(\d+)$/){ - $x = $1; - $y = $2; - $z = $3; - }else{ - $ND::server->command("notice $ND::nick Usage: .$command X:Y:Z"); - return; - } - if(my $user = dc()){ - my $findid = $ND::DBH->prepare_cached(q{SELECT planetid(?,?,?,tick())}); - my ($id) = $ND::DBH->selectrow_array($findid,undef,$x,$y,$z); - my $rv = $ND::DBH->do(q{UPDATE planets SET planet_status = 'Hostile' WHERE id = $1},undef,$id); - if ($rv == 1){ - $ND::server->command("msg $ND::target $x:$y:$z is now marked s hostile"); - intel_log $user->{uid},$id,"Set planet_status to: 'Hostile'"; - } - } -} +our @EXPORT = qw/setNick setAlly setChannel/; sub setNick { my ($msg, $command) = @_; diff --git a/database/roles.sql b/database/roles.sql index d98dce6..b84e53d 100644 --- a/database/roles.sql +++ b/database/roles.sql @@ -24,6 +24,7 @@ INSERT INTO roles VALUES('irc_a'); INSERT INTO roles VALUES('irc_d'); INSERT INTO roles VALUES('irc_s'); INSERT INTO roles VALUES('irc_h'); +INSERT INTO roles VALUES('irc_sethostile'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel'); @@ -49,6 +50,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_a'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_d'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_s'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_h'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_sethostile'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan'); @@ -76,12 +78,14 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_a'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_d'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_s'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_h'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_sethostile'); INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others'); INSERT INTO group_roles (gid,role) VALUES(4,'irc_a'); 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(5,'irc_sethostile'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_p_intel'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_points_others'); @@ -89,6 +93,7 @@ INSERT INTO group_roles (gid,role) VALUES(6,'irc_sms'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_getships'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_getfleet'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_d'); +INSERT INTO group_roles (gid,role) VALUES(6,'irc_sethostile'); INSERT INTO group_roles (gid,role) VALUES(8,'irc_scanreqs'); INSERT INTO group_roles (gid,role) VALUES(8,'irc_anonscan'); diff --git a/ndawn.pl b/ndawn.pl index 594477e..49a7a07 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','PA','Channel','Scans','Quotes','Members','Usermgm'); +$disp->load('Basic','PA','Channel','Scans','Quotes','Members','Usermgm','Intel'); $ND::scanchan = '#testarmer'; $disp->add_channel('#testarlite', ['pub','help','channel','def']); -- 2.39.2