X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Scans.pm;h=2b33361c65413da1665e70fe11e78f6a8e6fe3a4;hb=f4fda6de68d23833ffe61c81f29177cc210b3825;hp=146efeaf5ae25c0bc0a01824c921ea28fa90dc7c;hpb=c1a76498be9dbf78753d51d2d9173abdcd4efd70;p=NDIRC.git diff --git a/Scans.pm b/Scans.pm index 146efea..2b33361 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/; +our @EXPORT = qw/addScan addScanGroup sendScan reqScan scanReqs getScan/; sub addScan { my ($id,$verbose) = @_; @@ -84,107 +84,51 @@ 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 { +sub getScan { 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]; + 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); - $msg = $5; + $tick = $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"); + $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 $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.."); + 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"); } } -our %scantypes; -{ - my $i = 1; - %scantypes = map {$_ => $i++} @scantypes; -} - -sub scanReqs { - my ($msg, $command) = @_; - - if (scanner()){ - - my $reqs = $ND::DBH->prepare(q{SELECT min(sr.id) AS id, x,y,z,type - FROM scan_requests sr - JOIN current_planet_stats p ON p.id = sr.planet - WHERE sr.time > NOW() - '30 min'::INTERVAL - AND NOT EXISTS (SELECT scan_id FROM scans - WHERE planet = sr.planet - AND type = sr.type - AND tick >= sr.tick - ) - GROUP BY x,y,z,type - ORDER BY id - }); - $reqs->execute; - my $text = ''; - while (my $req = $reqs->fetchrow_hashref){ - $text .= "$ND::B$req->{id}$ND::O http://game.planetarion.com/waves.pl?id=$scantypes{$req->{type}}&x=$req->{x}&y=$req->{y}&z=$req->{z} " - } - - $text = 'No unhandled reqests.' unless $text; - $ND::server->command("notice $ND::nick $text"); - } -} 1;