]> ruin.nu Git - NDIRC.git/commitdiff
Converted the .scan command
authorMichael Andreen <harv@ruin.nu>
Sun, 10 May 2009 16:08:54 +0000 (18:08 +0200)
committerMichael Andreen <harv@ruin.nu>
Sun, 10 May 2009 16:08:54 +0000 (18:08 +0200)
Commands/Scans.pm
Scans.pm
database/roles.sql

index 11f3337308eeaef821ff59383f43764ccb918001..1f5f347272b405baf7e579747b1888de081adab2 100644 (file)
@@ -144,4 +144,46 @@ ORDER BY id
        $c->reply($text || 'No unhandled requests.');
 }
 
+sub scan
+       : Help(syntax: scan type X:Y:Z [tick] | type is the first character in the scan name, like p for planet scan. Specify a tick if you want scans older than the specified tick.)
+       : ACL(irc_scan)
+       : Type(pm)
+{
+       my ($self, $c,$msg) = @_;
+
+       my ($t, $x, $y, $z, $tick)
+               = $msg =~ /^([pdunja]) (\d+)\D+(\d+)\D+(\d+)(?: (\d+))?/ or die 'ARGS';
+       my $type =$scantypes[$scanid{$t}-1];
+
+       my $scan = $c->model->selectrow_hashref(q{
+SELECT id, scan_id, tick FROM scans
+WHERE type = $1 AND planet = planetid($2,$3,$4,0) AND COALESCE(tick < $5,TRUE)
+ORDER BY tick DESC LIMIT 1
+                       },undef,$type,$x,$y,$z,$tick);
+       unless ($scan->{id}){
+               $c->reply("No $type scan for $x:$y:$z. Planet might not exist.");
+               return;
+       }
+       my $text = '';
+       given ($t){
+               when(/[ua]/){
+                       my $fid = $c->model->selectrow_array(q{
+SELECT fid FROM fleet_scans WHERE id = $1
+                       },undef,$scan->{id});
+                       my $ships = $c->model->prepare(q{
+SELECT ship,amount FROM fleet_ships WHERE fid = $1 ORDER BY num
+                       });
+                       $ships->execute($fid);
+                       while (my $ship = $ships->fetchrow_hashref){
+                               $text .= " $ship->{ship} $ship->{amount} |"
+                       }
+               }
+               default {
+                       $text = "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}";
+               }
+       }
+       $c->reply("<b>$type</b> scan of $x:$y:$z "
+               . "($scan->{scan_id} pt: <b>$scan->{tick}</b>): $text");
+}
+
 1;
index 2b33361c65413da1665e70fe11e78f6a8e6fe3a4..a22983dd3bfb836f66a635b8dd37be1adaccc1b2 100644 (file)
--- a/Scans.pm
+++ b/Scans.pm
@@ -25,7 +25,7 @@ require Exporter;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/addScan addScanGroup sendScan reqScan scanReqs getScan/;
+our @EXPORT = qw/addScan addScanGroup sendScan/;
 
 sub addScan {
        my ($id,$verbose) = @_;
@@ -84,51 +84,6 @@ sub sendScan {
        }
 }
 
-sub getScan {
-       my ($msg, $command) = @_;
-
-       my ($t, $x, $y, $z, $type, $tick);
-       if (defined $msg && $msg =~ /^([pdunja]) (\d+)\D+(\d+)\D+(\d+)(?: (\d+))?/){
-               $t = $1;
-               $type =$scantypes[$scanid{$1}-1];
-               ($x,$y,$z) = ($2,$3,$4);
-               $tick = $5;
-       }else{
-               $ND::server->command("notice $ND::nick syntax: $command type X:Y:Z [tick]"
-                       . " | type is the first character in the scan name, like p for planet scan."
-                       . " Specify a tick if you want scans older than the specified tick."
-               );
-               return;
-       }
-
-       if (my $user = member){
-               my $scan = $ND::DBH->selectrow_hashref(q{
-SELECT id, scan_id, tick FROM scans
-WHERE type = $1 AND planet = planetid($2,$3,$4,0) AND COALESCE(tick < $5,TRUE)
-ORDER BY tick DESC LIMIT 1
-                       },undef,$type,$x,$y,$z,$tick);
-               unless ($scan->{id}){
-                       $ND::server->command("notice $ND::nick No such scan");
-               }
-               my $text = '|';
-               if ($t =~ /[uja]/){
-                       my $fid = $ND::DBH->selectrow_array(q{
-SELECT fid FROM fleet_scans WHERE id = $1
-                               },undef,$scan->{id});
-                       my $ships = $ND::DBH->prepare(q{
-SELECT ship,amount FROM fleet_ships WHERE fid = $1 ORDER BY num
-                               });
-                       $ships->execute($fid);
-                       while (my $ship = $ships->fetchrow_hashref){
-                               $text .= " $ship->{ship} $ship->{amount} |"
-                       }
-               }else{
-                       $text = "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}";
-               }
-               $ND::server->command("notice $ND::nick $ND::B$type$ND::O scan of $x:$y:$z "
-                       . "($scan->{scan_id} pt: $ND::B$scan->{tick}$ND::O) $text");
-       }
-}
 
 
 1;
index 6d21757c6c464e6c927af90ba6d971ef30503f21..999ae1feade38ac7caa9abfdaae94c89236d422a 100644 (file)
@@ -4,6 +4,7 @@ INSERT INTO roles VALUES('irc_masterop');
 INSERT INTO roles VALUES('irc_masterinvite');
 INSERT INTO roles VALUES('irc_gs');
 INSERT INTO roles VALUES('irc_scanreqs');
+INSERT INTO roles VALUES('irc_scan');
 
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel');
@@ -12,6 +13,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_masterinvite');
 INSERT INTO group_roles (gid,role) VALUES(1,'irc_scanreqs');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs');
+INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan');
 
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_p_nick');
 INSERT INTO group_roles (gid,role) VALUES(3,'irc_masterop');