From: Michael Andreen Date: Wed, 25 Jun 2008 21:45:06 +0000 (+0200) Subject: Converted covop target list X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=80ad5ca3ad49aa9cc029fe3baaff513e422ef499 Converted covop target list --- diff --git a/NDWeb/Pages/CovOp.pm b/NDWeb/Pages/CovOp.pm deleted file mode 100644 index 16a429b..0000000 --- a/NDWeb/Pages/CovOp.pm +++ /dev/null @@ -1,93 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 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 * -# 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; diff --git a/database/group_roles.sql b/database/group_roles.sql index 3ae93d4..16e0c4e 100644 --- a/database/group_roles.sql +++ b/database/group_roles.sql @@ -21,10 +21,12 @@ INSERT INTO roles VALUES('alliances_resources'); 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'); diff --git a/lib/NDWeb.pm b/lib/NDWeb.pm index 238e5f4..b47a9fa 100644 --- a/lib/NDWeb.pm +++ b/lib/NDWeb.pm @@ -72,6 +72,7 @@ __PACKAGE__->deny_access_unless('/alliances/resources',[qw/alliances_resources/] __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 diff --git a/lib/NDWeb/Controller/CovOp.pm b/lib/NDWeb/Controller/CovOp.pm new file mode 100644 index 0000000..68ef8a8 --- /dev/null +++ b/lib/NDWeb/Controller/CovOp.pm @@ -0,0 +1,90 @@ +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; diff --git a/lib/NDWeb/Controller/Root.pm b/lib/NDWeb/Controller/Root.pm index 9048fd0..16f0e8c 100644 --- a/lib/NDWeb/Controller/Root.pm +++ b/lib/NDWeb/Controller/Root.pm @@ -86,7 +86,7 @@ ORDER BY r.tick+c.wave,x,y,z}); push @targets, $target; } - $c->stash(targets => \@targets); + $c->stash(claimedtargets => \@targets); } sub auto : Private { diff --git a/root/lib/inc/targetlist.tt2 b/root/lib/inc/targetlist.tt2 index 4b1890f..4f8cced 100644 --- a/root/lib/inc/targetlist.tt2 +++ b/root/lib/inc/targetlist.tt2 @@ -1,7 +1,7 @@ [% IF targets%] - [% FOR target IN targets %] + [% FOR target IN claimedtargets %] diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index 450cfdc..62a7bf0 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -32,7 +32,7 @@
  • Add intel/scans
  • Launch confirmation
  • CovOp targets
  • -
  • Distwhores
  • +
  • Distwhores
  • Request defense
  • [% ELSE %] diff --git a/root/src/covop/index.tt2 b/root/src/covop/index.tt2 new file mode 100644 index 0000000..1c44bee --- /dev/null +++ b/root/src/covop/index.tt2 @@ -0,0 +1,22 @@ +[% META title = 'Covert operations' %] +
    TargetTick
    [% target.released_coords and target.coords%][% IF target.launched%]*[% END %]
    + + + + +[% debug(targets.size) %] +[% FOR t IN targets %] + + + + + + + + + + + + +[% END %] +
    CoordsMetalCrystalEoniumGovAlertDistsMax (15 agents)Last covop (tick)
    [% t.coords %][% t.metal %][% t.crystal %][% t.eonium %][% t.gov %][% t.minalert %] - [% t.maxalert %][% t.distorters %][% t.maxreshack %][% t.lastcovop %]Did CovOp this tick
    diff --git a/t/controller_CovOp.t b/t/controller_CovOp.t new file mode 100644 index 0000000..f608b36 --- /dev/null +++ b/t/controller_CovOp.t @@ -0,0 +1,10 @@ +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' ); + + diff --git a/templates/covop.tmpl b/templates/covop.tmpl deleted file mode 100644 index 2a80247..0000000 --- a/templates/covop.tmpl +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - -
    CoordsMetalCrystalEoniumGovAlertDistsMax (15 agents)Last covop (tick)
    - Did CovOp this tick