]> ruin.nu Git - NDIRC.git/commitdiff
Converted the .gs command
authorMichael Andreen <harv@ruin.nu>
Sat, 9 May 2009 21:34:39 +0000 (23:34 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 9 May 2009 21:34:39 +0000 (23:34 +0200)
Commands/Scans.pm [new file with mode: 0644]
Scans.pm
database/roles.sql
ndawn.pl

diff --git a/Commands/Scans.pm b/Commands/Scans.pm
new file mode 100644 (file)
index 0000000..2cb0c3c
--- /dev/null
@@ -0,0 +1,94 @@
+#**************************************************************************
+#   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::Scans;
+
+use strict;
+use warnings;
+use feature ':5.10';
+
+use Moose;
+use MooseX::MethodAttributes;
+
+my %scanid = (p => 1, l => 2, d => 3, u => 4, n => 5, j => 7, a => 8);
+
+my @scantypes = ('Planet','Landing', 'Development'
+       ,'Unit', 'News', 'Incoming', 'Jumpgate', 'Advanced Unit');
+
+sub gs
+       : Help(syntax: gs type X:Y:Z message | type is the first character in the scan name, like p for planet scan, message is a message to scanners, like plz or thanks like plz or thanks)
+       : ACL(irc_gs)
+       : Type(pm)
+{
+       my ($self,$c,$args) = @_;
+
+       my ($typeid, $x, $y, $z, $msg) = $args =~ /^([pdunja]) (\d+)\D+(\d+)\D+(\d+) (\S.*)/
+               or die 'ARGS';
+       $typeid = $scanid{$typeid};
+       my $type = $scantypes[$typeid-1];
+
+       my $planet = $c->model->selectrow_array(q{SELECT planetid($1,$2,$3,tick())}
+               ,undef,$x,$y,$z);
+
+       my $query = $c->model->prepare(q{SELECT scan_id
+               FROM scans
+               WHERE planet = $1 AND type = $2 AND tick >= tick()});
+       $query->execute($planet,$type);
+
+       if (my $scan = $query->fetchrow_hashref){
+               $c->reply("scan already exist: "
+                       . "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}");
+       }else{
+               my $req = $c->model->prepare(q{
+SELECT * FROM scan_requests
+WHERE uid = (SELECT uid FROM users WHERE hostmask ILIKE $1)
+       AND planet = $2 AND type = $3 AND NOT sent
+               });
+               $req->execute($c->host,$planet,$type);
+
+               my $id;
+               if(my $scan = $req->fetchrow_hashref){
+                       $req = $c->model->prepare(q{
+UPDATE scan_requests SET nick = $1, tick = tick(), time = NOW()
+WHERE id = $2
+                       });
+                       $req->execute($c->nick,$scan->{id});
+                       $id = $scan->{id};
+               }else{
+                       $req = $c->model->prepare(q{
+INSERT INTO scan_requests (uid,nick,planet,type)
+VALUES((SELECT uid FROM users WHERE hostmask ILIKE $1),$2,$3,$4) RETURNING (id)
+                       });
+                       $req->execute($c->host,$c->nick,$planet,$type);
+                       $id = $req->fetchrow;
+               }
+
+               if ($id){
+                       $c->message("msg $ND::scanchan"
+                               ,"<b>$id</b> http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z"
+                               . " ($x:$y:$z $type) | <".$c->nick."> $msg"
+                       );
+                       $c->reply("sent request ($x:$y:$z $type)");
+               }else{
+                       $c->reply("something went wrong..");
+               }
+       }
+}
+
+1;
index 9349838f6e7195533ac63784993e17ffe50bbe26..b2621e8d332da3b3332fe9abf8e04ead03357dff 100644 (file)
--- a/Scans.pm
+++ b/Scans.pm
@@ -84,74 +84,6 @@ sub sendScan {
        }
 }
 
-our %scanid = (p => 1, l => 2, d => 3, u => 4, n => 5, j => 7, a => 8);
-
-our @scantypes = ('Planet','Landing', 'Development'
-       ,'Unit', 'News', 'Incoming', 'Jumpgate', 'Advanced Unit');
-
-sub reqScan {
-       my ($msg, $command) = @_;
-
-       my ($x, $y, $z, $type, $typeid);
-       if (defined $msg && $msg =~ /^([pdunja]) (\d+)\D+(\d+)\D+(\d+) (\S.*)/){
-               $typeid = $scanid{$1};
-               $type = $scantypes[$typeid-1];
-               ($x,$y,$z) = ($2,$3,$4);
-               $msg = $5;
-       }else{
-               $ND::server->command("notice $ND::nick syntax: $command type X:Y:Z message"
-                       . " | type is the first character in the scan name, like p for planet scan, message is a message to scanners, like plz or thanks like plz or thanks");
-               return;
-       }
-
-       if (my $user = member){
-
-               my $planet = $ND::DBH->selectrow_array(q{SELECT planetid($1,$2,$3,$4)}
-                       ,undef,$x,$y,$z,$ND::tick);
-
-               my $query = $ND::DBH->prepare(q{SELECT scan_id
-                       FROM scans
-                       WHERE planet = $1 AND type = $2 AND tick >= $3});
-               $query->execute($planet,$type,$ND::tick);
-
-               if (my $scan = $query->fetchrow_hashref){
-                       $ND::server->command("notice $ND::nick scan already exist: "
-                               . "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}");
-               }else{
-                       my $req = $ND::DBH->prepare(q{SELECT * FROM scan_requests
-                               WHERE uid = $1 AND planet = $2
-                                       AND type = $3 AND NOT sent
-                       });
-                       $req->execute($user->{uid},$planet,$type);
-
-                       my $id;
-                       if(my $scan = $req->fetchrow_hashref){
-                               $req = $ND::DBH->prepare(q{UPDATE scan_requests
-                                       SET nick = $1, tick = tick(), time = NOW()
-                                       WHERE id = $2});
-                               $req->execute($ND::nick,$scan->{id});
-                               $id = $scan->{id};
-                       }else{
-                               $req = $ND::DBH->prepare(q{INSERT INTO scan_requests
-                                       (uid,nick,planet,type) VALUES($1,$2,$3,$4)
-                                       RETURNING (id)});
-                               $req->execute($user->{uid},$ND::nick,$planet,$type);
-                               $id = $req->fetchrow;
-                       }
-
-                       if ($id){
-                               $ND::server->command("msg $ND::scanchan "
-                                       . "$ND::B$id$ND::O http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z"
-                                       . " ($x:$y:$z $type) | <$ND::nick> $msg"
-                               );
-                               $ND::server->command("notice $ND::nick sent request ($x:$y:$z $type)");
-                       }else{
-                               $ND::server->command("notice $ND::nick something went wrong..");
-                       }
-
-               }
-       }
-}
 
 our %scantypes;
 {
index 9a31ced48b7d2a7c4a2e43562fc96386cd9fdfae..2a2e1e0ac446cdfebfce2f4f7573d1ace17bd45d 100644 (file)
@@ -2,12 +2,15 @@ INSERT INTO roles VALUES('irc_p_nick');
 INSERT INTO roles VALUES('irc_p_intel');
 INSERT INTO roles VALUES('irc_masterop');
 INSERT INTO roles VALUES('irc_masterinvite');
+INSERT INTO roles VALUES('irc_gs');
 
 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(1,'irc_masterop');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_masterinvite');
 
+INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs');
+
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_masterop');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_masterinvite');
index 744aef4a17ca8519c2b44833c560b47831f679c3..76fca28c3d6899574ffaeecae66831cee0004f25 100644 (file)
--- a/ndawn.pl
+++ b/ndawn.pl
@@ -55,26 +55,33 @@ my $TICK = $DBH->selectrow_array('SELECT tick()');
 
 my $disp = new NDIRC::Dispatcher;
 
-$disp->load('Basic','PA','Channel');
+$disp->load('Basic','PA','Channel','Scans');
 
+$ND::scanchan = '#testarmer';
 $disp->add_channel('#testarlite', ['pub','help','channel']);
-$disp->add_channel('#testarmer', ['pub','help','channel']);
+$disp->add_channel('#testarmer', ['pub','help','channel','scan']);
 $disp->add_channel('pm', ['pub','help','pm']);
 
 sub event_pubmsg {
        my ($server, $msg, $nick, $address, $channel) = @_;
 
-       if (parseCommand($msg,$server,$nick,$address,$channel,$disp,DB())){
-               #Command parsed and run successfully
-       }
+       eval {
+               if (parseCommand($msg,$server,$nick,$address,$channel,$disp,DB())){
+                       #Command parsed and run successfully
+               }
+       };
+       print $@ if $@;
 }
 
 sub event_privmsg {
        my ($server, $msg, $nick, $address) = @_;
 
-       if (parseCommand($msg,$server,$nick,$address,'pm',$disp,DB())){
-               #Command parsed and run successfully
-       }
+       eval {
+               if (parseCommand($msg,$server,$nick,$address,'pm',$disp,DB())){
+                       #Command parsed and run successfully
+               }
+       };
+       print $@ if $@;
 }
 
 sub refresh {