X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FScans.pm;h=acfe9a90cbecb27f1b5012c24a7376be2093f6d5;hb=e8c94cdebefdc428ea92fde6db63f18d3e8399b2;hp=134629bb49fbdf69592df7824451bcd21e75e799;hpb=227e9bfcf736a4a413d68b9f83a25636c13d8e0b;p=NDIRC.git diff --git a/Commands/Scans.pm b/Commands/Scans.pm index 134629b..acfe9a9 100644 --- a/Commands/Scans.pm +++ b/Commands/Scans.pm @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (C) 2008 by Michael Andreen * +# 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 * @@ -26,6 +26,15 @@ use feature ':5.10'; use Moose; use MooseX::MethodAttributes; +sub getscans + : Help(syntax: .getscans X:Y:Z) + : Type(pm) +{ + my ($self,$c,$args) = @_; + my ($x,$y,$z) = $args =~ /(\d+)\D+(\d+)\D+(\d+)/ or die 'ARGS'; + $c->reply("https://nd.ruin.nu/stats/find/$x:$y:$z"); +} + my %scanid = (p => 1, l => 2, d => 3, u => 4, n => 5, j => 7, a => 8); my @scantypes = ('Planet','Landing', 'Development' @@ -45,10 +54,14 @@ sub gs my $planet = $c->model->selectrow_array(q{SELECT planetid($1,$2,$3,tick())} ,undef,$x,$y,$z); + unless ($planet){ + $c->reply("There is no planet with coords $x:$y:$z, try again after the tick."); + return; + } my $query = $c->model->prepare(q{SELECT scan_id FROM scans - WHERE planet = $1 AND type = $2 AND tick >= tick()}); + WHERE pid = $1 AND type = $2 AND tick >= tick()}); $query->execute($planet,$type); if (my $scan = $query->fetchrow_hashref){ @@ -58,7 +71,7 @@ sub gs 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 + AND pid = $2 AND type = $3 AND NOT sent }); $req->execute($c->host,$planet,$type); @@ -72,7 +85,7 @@ WHERE id = $2 $id = $scan->{id}; }else{ $req = $c->model->prepare(q{ -INSERT INTO scan_requests (uid,nick,planet,type) +INSERT INTO scan_requests (uid,nick,pid,type) VALUES((SELECT uid FROM users WHERE hostmask ILIKE $1),$2,$3,$4) RETURNING (id) }); $req->execute($c->host,$c->nick,$planet,$type); @@ -80,7 +93,7 @@ VALUES((SELECT uid FROM users WHERE hostmask ILIKE $1),$2,$3,$4) RETURNING (id) } if ($id){ - $c->message("msg $ND::scanchan" + $c->message(privmsg => $ND::scanchan ,"$id http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z" . " ($x:$y:$z $type) | <".$c->nick."> $msg" ); @@ -115,10 +128,10 @@ sub scanreqs my $reqs = $c->model->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 + JOIN current_planet_stats p USING (pid) WHERE sr.time > NOW() - '30 min'::INTERVAL AND NOT EXISTS (SELECT scan_id FROM scans - WHERE planet = sr.planet + WHERE pid = sr.pid AND type = sr.type AND tick >= sr.tick ) @@ -135,4 +148,104 @@ 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 pid = 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"); +} + +sub anon + : Help(syntax: .anon nick message) + : Type(scan) + : ACL(irc_anonscan) +{ + my ($self, $c, $msg) = @_; + my ($target,$mess) = $msg =~ /^(\S+) (.*)$/ or die 'ARGS'; + + $c->message(privmsg => $target, "$mess (reply with /msg " + .$c->channel.")"); + $c->message(privmsg => $c->channel, "$target << $mess"); +} + +sub addscan + : Help(syntax: .addscan list of scans) +{ + my ($self, $c, $msg) = @_; + my $dbh = $c->model; + + my $oldscan = $dbh->prepare(q{ +SELECT scan_id FROM scans +WHERE groupscan = $1 AND scan_id = LOWER($2) AND tick >= tick() - 168 + }); + my $addscan = $dbh->prepare(q{ +INSERT INTO scans (scan_id,tick,groupscan,uid) VALUES (LOWER($1),tick(),$2,COALESCE($3,-1)) + }); + my $user = $dbh->selectrow_hashref(q{SELECT uid,username, scan_points, tick() + FROM users WHERE hostmask ILIKE ? },undef,$c->host); + my $groupscans = 0; + my $scans = 0; + eval { + $dbh->begin_work; + while ($msg =~ m{/.+?scan(_id|_grp)?=(\w+)}g){ + my $id = $2; + my $group = ($1 ~~ /_grp/ || 0); + unless($dbh->selectrow_array($oldscan,undef,$group,$id)){ + $addscan->execute($id,$group,$user->{uid}); + if ($group){ + $groupscans++; + }else{ + $scans++; + } + } + } + if ($user->{uid} && ($scans || $groupscans)){ + $dbh->do(q{UPDATE users SET scan_points = scan_points + $2 WHERE uid = $1} + ,undef,$user->{uid},$scans); + my $points = $user->{scan_points} + $scans; + $c->reply("Added $scans scans and $groupscans groupscans, $points in total."); + } + $dbh->commit; + }; + if ($@){ + $dbh->rollback; + die $@; + } +} + 1;