1 #**************************************************************************
2 # Copyright (C) 2006 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 NDWeb::Pages::CovOp;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
26 use base qw/NDWeb::XMLPage/;
28 $NDWeb::Page::PAGES{covop} = __PACKAGE__;
32 if ($uri =~ m{^/.*/(\w+)$}){
40 $self->{TITLE} = 'CovOp Targets';
41 my $DBH = $self->{DBH};
43 return $self->noAccess unless $self->isMember;
45 my $show = q{AND (NOT planet_status IN ('Friendly','NAP')) AND (relationship IS NULL OR NOT relationship IN ('Friendly','NAP'))};
46 $show = '' if defined param('show') && param('show') eq 'all';
47 if (defined param('covop') && param('covop') =~ /^(\d+)$/){
48 my $update = $DBH->prepare(q{INSERT INTO covop_attacks (uid,id,tick) VALUES(?,?,tick())});
49 $update->execute($ND::UID,$1) or warn $DBH->errstr;
54 if (defined param('list') && param('list') eq 'distwhores'){
55 $list = 'list=distwhores';
56 $where = qq{AND distorters > 0 $show
57 ORDER BY distorters DESC,COALESCE(seccents::float/structures*100,0)ASC}
59 $where = qq{AND MaxResHack > 130000
61 ORDER BY minalert ASC,MaxResHack DESC};
63 $BODY->param(List => $list);
65 my $query = $DBH->prepare(qq{SELECT id, coords, metal, crystal, eonium
66 , covop_alert(seccents,structures,gov,0) AS minalert
67 , covop_alert(seccents,structures,gov,50) AS maxalert
69 , MaxResHack,co.tick AS lastcovop
70 FROM (SELECT p.id,coords(x,y,z), metal,crystal,eonium,
71 seccents,NULLIF(ss.total::integer,0) AS structures,distorters
72 ,max_bank_hack(metal,crystal,eonium,p.value
73 ,(SELECT value FROM current_planet_stats WHERE id = ?)) AS MaxResHack
74 , planet_status, relationship,gov
75 FROM current_planet_stats p
76 LEFT OUTER JOIN planet_scans ps ON p.id = ps.planet
77 LEFT OUTER JOIN structure_scans ss ON p.id = ss.planet
79 LEFT OUTER JOIN (SELECT id,max(tick) AS tick FROM covop_attacks GROUP BY id) co USING (id)
80 WHERE (metal IS NOT NULL OR seccents IS NOT NULL)
82 }) or warn $DBH->errstr;
83 $query->execute($self->{PLANET}) or warn $DBH->errstr;
86 while (my $target = $query->fetchrow_hashref){
87 push @targets,$target;
89 $BODY->param(Targets => \@targets);