From: Michael Andreen Date: Sun, 10 May 2009 16:08:54 +0000 (+0200) Subject: Converted the .scan command X-Git-Url: https://ruin.nu/git/?a=commitdiff_plain;h=c8e65de85f3c2724a5290e0ee612b83e7f63aea0;p=NDIRC.git Converted the .scan command --- diff --git a/Commands/Scans.pm b/Commands/Scans.pm index 11f3337..1f5f347 100644 --- a/Commands/Scans.pm +++ b/Commands/Scans.pm @@ -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("$type scan of $x:$y:$z " + . "($scan->{scan_id} pt: $scan->{tick}): $text"); +} + 1; diff --git a/Scans.pm b/Scans.pm index 2b33361..a22983d 100644 --- 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; diff --git a/database/roles.sql b/database/roles.sql index 6d21757..999ae1f 100644 --- a/database/roles.sql +++ b/database/roles.sql @@ -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');