1 #**************************************************************************
2 # Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package NDIRC::Commands::Scans;
27 use MooseX::MethodAttributes;
29 my %scanid = (p => 1, l => 2, d => 3, u => 4, n => 5, j => 7, a => 8);
31 my @scantypes = ('Planet','Landing', 'Development'
32 ,'Unit', 'News', 'Incoming', 'Jumpgate', 'Advanced Unit');
35 : 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)
39 my ($self,$c,$args) = @_;
41 my ($typeid, $x, $y, $z, $msg) = $args =~ /^([pdunja]) (\d+)\D+(\d+)\D+(\d+) (\S.*)/
43 $typeid = $scanid{$typeid};
44 my $type = $scantypes[$typeid-1];
46 my $planet = $c->model->selectrow_array(q{SELECT planetid($1,$2,$3,tick())}
49 my $query = $c->model->prepare(q{SELECT scan_id
51 WHERE planet = $1 AND type = $2 AND tick >= tick()});
52 $query->execute($planet,$type);
54 if (my $scan = $query->fetchrow_hashref){
55 $c->reply("scan already exist: "
56 . "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}");
58 my $req = $c->model->prepare(q{
59 SELECT * FROM scan_requests
60 WHERE uid = (SELECT uid FROM users WHERE hostmask ILIKE $1)
61 AND planet = $2 AND type = $3 AND NOT sent
63 $req->execute($c->host,$planet,$type);
66 if(my $scan = $req->fetchrow_hashref){
67 $req = $c->model->prepare(q{
68 UPDATE scan_requests SET nick = $1, tick = tick(), time = NOW()
71 $req->execute($c->nick,$scan->{id});
74 $req = $c->model->prepare(q{
75 INSERT INTO scan_requests (uid,nick,planet,type)
76 VALUES((SELECT uid FROM users WHERE hostmask ILIKE $1),$2,$3,$4) RETURNING (id)
78 $req->execute($c->host,$c->nick,$planet,$type);
83 $c->message("msg $ND::scanchan"
84 ,"<b>$id</b> http://game.planetarion.com/waves.pl?id=$typeid&x=$x&y=$y&z=$z"
85 . " ($x:$y:$z $type) | <".$c->nick."> $msg"
87 $c->reply("sent request ($x:$y:$z $type)");
89 $c->reply("something went wrong..");
97 %scantypes = map {$_ => $i++} @scantypes;
101 : Help(syntax: .scanreqs [-pdunja] | Lists scan requests that haven't been handled. The argument can be used to omit types you don't have, like .scanreqs -ja to list all requests except jumpgates and advanced unit scans.)
104 my ($self, $c, $msg) = @_;
107 if ($msg =~ /^-([pdunja]+)$/){
109 push @notype, $scantypes[$scanid{$_}-1];
115 my $reqs = $c->model->prepare(q{
116 SELECT min(sr.id) AS id, x,y,z,type
117 FROM scan_requests sr
118 JOIN current_planet_stats p ON p.id = sr.planet
119 WHERE sr.time > NOW() - '30 min'::INTERVAL
120 AND NOT EXISTS (SELECT scan_id FROM scans
121 WHERE planet = sr.planet
129 $reqs->execute(\@notype);
131 while (my $req = $reqs->fetchrow_hashref){
132 $text .= "<b>$req->{id}</b> http://game.planetarion.com/waves.pl?id=$scantypes{$req->{type}}&x=$req->{x}&y=$req->{y}&z=$req->{z} "
135 $c->reply($text || 'No unhandled requests.');