+++ /dev/null
-#**************************************************************************
-# Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
-# *
-# 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 *
-# the Free Software Foundation; either version 2 of the License, or *
-# (at your option) any later version. *
-# *
-# This program is distributed in the hope that it will be useful, *
-# but WITHOUT ANY WARRANTY; without even the implied warranty of *
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
-# GNU General Public License for more details. *
-# *
-# You should have received a copy of the GNU General Public License *
-# along with this program; if not, write to the *
-# Free Software Foundation, Inc., *
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
-#**************************************************************************/
-
-package NDWeb::Pages::CovOp;
-use strict;
-use warnings FATAL => 'all';
-use CGI qw/:standard/;
-use NDWeb::Include;
-
-use base qw/NDWeb::XMLPage/;
-
-$NDWeb::Page::PAGES{covop} = __PACKAGE__;
-
-sub parse {
- my ($uri) = @_;
- if ($uri =~ m{^/.*/(\w+)$}){
- param('list',$1);
- }
-}
-
-sub render_body {
- my $self = shift;
- my ($BODY) = @_;
- $self->{TITLE} = 'CovOp Targets';
- my $DBH = $self->{DBH};
-
- return $self->noAccess unless $self->isMember;
-
- my $show = q{AND (NOT planet_status IN ('Friendly','NAP')) AND (relationship IS NULL OR NOT relationship IN ('Friendly','NAP'))};
- $show = '' if defined param('show') && param('show') eq 'all';
- if (defined param('covop') && param('covop') =~ /^(\d+)$/){
- my $update = $DBH->prepare(q{INSERT INTO covop_attacks (uid,id,tick) VALUES(?,?,tick())});
- $update->execute($ND::UID,$1) or warn $DBH->errstr;
- }
-
- my $list = '';
- my $where = '';
- if (defined param('list') && param('list') eq 'distwhores'){
- $list = 'list=distwhores';
- $where = qq{AND distorters > 0 $show
- ORDER BY distorters DESC,COALESCE(seccents::float/structures*100,0)ASC}
- }else{
- $where = qq{AND MaxResHack > 130000
- $show
- ORDER BY minalert ASC,MaxResHack DESC};
- }
- $BODY->param(List => $list);
-
- my $query = $DBH->prepare(qq{SELECT id, coords, metal, crystal, eonium
- , covop_alert(seccents,structures,gov,0) AS minalert
- , covop_alert(seccents,structures,gov,50) AS maxalert
- , distorters,gov
- , MaxResHack,co.tick AS lastcovop
- FROM (SELECT p.id,coords(x,y,z), metal,crystal,eonium,
- seccents,NULLIF(ss.total::integer,0) AS structures,distorters
- ,max_bank_hack(metal,crystal,eonium,p.value
- ,(SELECT value FROM current_planet_stats WHERE id = ?)) AS MaxResHack
- , planet_status, relationship,gov
- FROM current_planet_stats p
- LEFT OUTER JOIN planet_scans ps ON p.id = ps.planet
- LEFT OUTER JOIN structure_scans ss ON p.id = ss.planet
- ) AS foo
- LEFT OUTER JOIN (SELECT id,max(tick) AS tick FROM covop_attacks GROUP BY id) co USING (id)
- WHERE (metal IS NOT NULL OR seccents IS NOT NULL)
- $where
- }) or warn $DBH->errstr;
- $query->execute($self->{PLANET}) or warn $DBH->errstr;
-
- my @targets;
- while (my $target = $query->fetchrow_hashref){
- push @targets,$target;
- }
- $BODY->param(Targets => \@targets);
- return $BODY;
-}
-
-1;
INSERT INTO roles VALUES('graphs_intel');
INSERT INTO roles VALUES('members');
INSERT INTO roles VALUES('members_points_nolimit');
+INSERT INTO roles VALUES('covop');
INSERT INTO group_roles (gid,role) VALUES(2,'member_menu');
INSERT INTO group_roles (gid,role) VALUES(2,'attack_menu');
INSERT INTO group_roles (gid,role) VALUES(2,'members');
+INSERT INTO group_roles (gid,role) VALUES(2,'covop');
INSERT INTO group_roles (gid,role) VALUES(6,'dc_menu');
__PACKAGE__->deny_access_unless('/graphs/alliancevsintel',[qw/graphs_intel/]);
__PACKAGE__->deny_access_unless('/graphs/avgalliancevsintel',[qw/graphs_intel/]);
__PACKAGE__->deny_access_unless('/members',[qw/members/]);
+__PACKAGE__->deny_access_unless('/covop',[qw/covop/]);
=head1 NAME
--- /dev/null
+package NDWeb::Controller::CovOp;
+
+use strict;
+use warnings;
+use parent 'Catalyst::Controller';
+
+=head1 NAME
+
+NDWeb::Controller::CovOp - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+ my ( $self, $c ) = @_;
+ $c->stash( where => q{AND MaxResHack > 130000
+ ORDER BY minalert ASC,MaxResHack DESC});
+}
+
+sub distwhores : Local {
+ my ( $self, $c ) = @_;
+ $c->stash( where => qq{AND distorters > 0
+ ORDER BY distorters DESC, minalert ASC});
+}
+
+sub marktarget : Local {
+ my ( $self, $c, $target ) = @_;
+ my $dbh = $c->model;
+
+ my $update = $dbh->prepare(q{INSERT INTO covop_attacks (uid,id,tick) VALUES(?,?,tick())});
+ $update->execute($c->user->id,$target);
+
+ $c->res->redirect($c->req->referer);
+}
+
+sub end : Private {
+ my ( $self, $c ) = @_;
+ my $dbh = $c->model;
+
+ my $query = $dbh->prepare(q{SELECT id, coords, metal, crystal, eonium
+ , covop_alert(seccents,structures,gov,0) AS minalert
+ , covop_alert(seccents,structures,gov,50) AS maxalert
+ , distorters,gov
+ , MaxResHack,co.tick AS lastcovop
+ FROM (SELECT p.id,coords(x,y,z), metal,crystal,eonium,
+ seccents,NULLIF(ss.total::integer,0) AS structures,distorters
+ ,max_bank_hack(metal,crystal,eonium,p.value
+ ,(SELECT value FROM current_planet_stats WHERE id = ?)) AS MaxResHack
+ , planet_status, relationship,gov
+ FROM current_planet_stats p
+ LEFT OUTER JOIN planet_scans ps ON p.id = ps.planet
+ LEFT OUTER JOIN structure_scans ss ON p.id = ss.planet
+ ) AS foo
+ LEFT OUTER JOIN (SELECT id,max(tick) AS tick FROM covop_attacks GROUP BY id) co USING (id)
+ WHERE (metal IS NOT NULL OR seccents IS NOT NULL)
+ AND (NOT planet_status IN ('Friendly','NAP'))
+ AND (relationship IS NULL OR NOT relationship IN ('Friendly','NAP'))
+ } . $c->stash->{where});
+ $query->execute($c->user->planet);
+
+ my @targets;
+ while (my $target = $query->fetchrow_hashref){
+ push @targets,$target;
+ }
+ $c->stash(targets => \@targets);
+
+ $c->stash(template => 'covop/index.tt2');
+ $c->forward('/end');
+}
+=head1 AUTHOR
+
+Michael Andreen (harv@ruin.nu)
+
+=head1 LICENSE
+
+GPL 2.0, or later
+
+=cut
+
+1;
push @targets, $target;
}
- $c->stash(targets => \@targets);
+ $c->stash(claimedtargets => \@targets);
}
sub auto : Private {
[% IF targets%]
<table>
<tr><th>Target</th><th>Tick</th></tr>
- [% FOR target IN targets %]
+ [% FOR target IN claimedtargets %]
<tr>
<td><a href="[% target.released_coords and c.uri_for('/check',target.coords)%]">
[% target.released_coords and target.coords%][% IF target.launched%]*[% END %]</a></td>
<li><a href="/members/addintel">Add intel/scans</a></li>
<li><a href="/members/launchConfirmation">Launch confirmation</a></li>
<li><a href="/covop">CovOp targets</a></li>
- <li><a href="/covop?list=distwhores">Distwhores</a></li>
+ <li><a href="/covop/distwhores">Distwhores</a></li>
<li><a href="/members/defrequest">Request defense</a></li>
</ul>
[% ELSE %]
--- /dev/null
+[% META title = 'Covert operations' %]
+<table>
+ <tr>
+ <th>Coords</th><th>Metal</th><th>Crystal</th><th>Eonium</th><th>Gov</th><th>Alert</th><th>Dists</th><th>Max (15 agents)</th><th>Last covop (tick)</th>
+ </tr>
+
+[% debug(targets.size) %]
+[% FOR t IN targets %]
+ <tr align="center" class="[% loop.count % 2 == 0 ? 'even' : 'odd' %]">
+ <td><a href="[% c.uri_for('/stats/planet',t.id) %]">[% t.coords %]</a></td>
+ <td>[% t.metal %]</td>
+ <td>[% t.crystal %]</td>
+ <td>[% t.eonium %]</td>
+ <td>[% t.gov %]</td>
+ <td>[% t.minalert %] - [% t.maxalert %]</td>
+ <td>[% t.distorters %]</td>
+ <td>[% t.maxreshack %]</td>
+ <td>[% t.lastcovop %]</td>
+ <td><a href="[% c.uri_for('marktarget', t.id) %]">Did CovOp this tick</a></td>
+ </tr>
+[% END %]
+</table>
--- /dev/null
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+BEGIN { use_ok 'Catalyst::Test', 'NDWeb' }
+BEGIN { use_ok 'NDWeb::Controller::CovOp' }
+
+ok( request('/covop')->is_success, 'Request should succeed' );
+
+
+++ /dev/null
-<table>
- <tr>
- <th>Coords</th><th>Metal</th><th>Crystal</th><th>Eonium</th><th>Gov</th><th>Alert</th><th>Dists</th><th>Max (15 agents)</th><th>Last covop (tick)</th>
- </tr>
- <TMPL_LOOP Targets>
- <tr align="center" class="<TMPL_IF __odd__>odd<TMPL_ELSE>even</TMPL_IF>">
- <td><a href="/check?coords=<TMPL_VAR NAME=Coords>"><TMPL_VAR NAME=Coords></a></td>
- <td><TMPL_VAR NAME=Metal></td>
- <td><TMPL_VAR NAME=Crystal></td>
- <td><TMPL_VAR NAME=Eonium></td>
- <td><TMPL_VAR NAME=Gov></td>
- <td><TMPL_VAR NAME=MinAlert> - <TMPL_VAR NAME=MaxAlert></td>
- <td><TMPL_VAR NAME=Distorters></td>
- <td><TMPL_VAR NAME=MaxResHack></td>
- <td><TMPL_VAR NAME=LastCovOp></td>
- <td><a href="/<TMPL_VAR NAME=PAGE>?<TMPL_VAR NAME=List>&covop=<TMPL_VAR NAME=Id>">Did CovOp this tick</a></td>
- </tr>
- </TMPL_LOOP>
-</table>