From: Michael Andreen Date: Wed, 4 Nov 2009 12:05:01 +0000 (+0100) Subject: Replace the retal cron job with a web page X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=4e9d3ae6bff7db31eeef5110180ac6e440502dd3 Replace the retal cron job with a web page --- diff --git a/lib/NDWeb/Controller/Raids.pm b/lib/NDWeb/Controller/Raids.pm index 50983d7..26e9157 100644 --- a/lib/NDWeb/Controller/Raids.pm +++ b/lib/NDWeb/Controller/Raids.pm @@ -693,6 +693,67 @@ WHERE fid = $1 $c->res->redirect("http://game.planetarion.com/bcalc.pl?$query"); } +sub retal : Local { + my ($self, $c) = @_; + my $dbh = $c->model; + + my $incs = $dbh->prepare(q{ +SELECT coords(x,y,z),pid,race,size,score,value,alliance + ,array_agg(i.eta) AS eta,array_agg(amount) AS amount + ,array_agg(shiptype) AS type,array_agg(fleet) AS name + ,array_agg(c.landing_tick) AS landing +FROM calls c + JOIN incomings i USING (call) + JOIN current_planet_stats p USING (pid) +WHERE c.status <> 'Covered' AND c.landing_tick BETWEEN tick() AND tick() + 6 + AND c.landing_tick + GREATEST(i.eta,7) > tick() + 10 +GROUP BY pid,race,x,y,z,size,score,value,alliance +ORDER BY size DESC + }); + $incs->execute; + $c->stash(planets => $incs->fetchall_arrayref({})); + +} + +sub postcreateretal : Local { + my ($self, $c) = @_; + my $dbh = $c->model; + + $dbh->begin_work; + my $query = $dbh->prepare(q{INSERT INTO raids (tick,waves,message) VALUES(?,?,?) RETURNING (id)}); + $query->execute($c->req->param('tick'),$c->req->param('waves') + ,html_escape $c->req->param('message')); + my $raid = $query->fetchrow_array; + $c->forward('log',[$raid,"Created retal raid landing at tick: ".$c->req->param('tick')]); + + if ($c->req->param('target')) { + my @targets = $c->req->param('target'); + + my $addtarget = $dbh->prepare(q{ +INSERT INTO raid_targets(raid,pid,comment) ( + SELECT $1,pid,array_to_string(array_agg( + fleet || ': eta=' || eta || ', amount=' || amount || ', type=' || shiptype + || ' landing=' || landing_tick || 'back=' || landing_tick + eta + ),'\n') + FROM calls c + JOIN incomings i USING (call) + JOIN current_planet_stats p USING (pid) + WHERE c.status <> 'Covered' AND c.landing_tick BETWEEN tick() AND tick() + 6 + AND c.landing_tick + GREATEST(i.eta,7) > tick() + 10 + AND pid = ANY ($2) + GROUP BY pid + ) + }); + $addtarget->execute($raid,\@targets); + $c->forward('log',[$raid,"BC added planets (@targets) to retal_raid"]); + } + $dbh->do(q{INSERT INTO raid_access (raid,gid) VALUES(?,'M')} + ,undef,$raid); + $dbh->commit; + + $c->res->redirect($c->uri_for('edit',$raid)); +} + sub listAlliances : Private { my ($self, $c) = @_; diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index 0c0a37f..ef01321 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -100,6 +100,7 @@ [% END %] [% IF c.check_user_roles("dc_menu") %] diff --git a/root/src/raids/retal.tt2 b/root/src/raids/retal.tt2 new file mode 100644 index 0000000..4526892 --- /dev/null +++ b/root/src/raids/retal.tt2 @@ -0,0 +1,41 @@ +
+ + + + + + + + + + + +[% FOR p IN planets %] + + + + + + + + + + +[% END %] +
CoordsAllianceRaceSizeScoreValueFleets outAdd to raid
[% p.coords %][% p.alliance %][% p.race %][% p.size | commify %][% p.score | commify %][% p.value | commify %][% FOR eta IN p.eta %] + [% + name = p.name.shift; + amount = p.amount.shift; + type = p.type.shift; + tick = p.landing.shift; + back = tick + eta; + %] +

[% name %]: eta=[% eta %] amount=[% amount | commify %] type=[% type | html %] + landing=[% tick %] back=[%back%]

+ [% END %]
+

Landing tick:

+

Number of waves:

+

Raid message here

+

+

+
diff --git a/scripts/createretal.pl b/scripts/createretal.pl deleted file mode 100755 index 6ee3ef4..0000000 --- a/scripts/createretal.pl +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/perl -q{ -/*************************************************************************** - * 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. * - ***************************************************************************/ -}; - -use strict; -use warnings; -use DBI; -use DBD::Pg qw(:pg_types); - -use FindBin; -use lib "$FindBin::Bin/../lib"; - -use ND::DB; - -our $dbh = ND::DB::DB(); - -$dbh->begin_work; - -my $query = $dbh->prepare(q{INSERT INTO raids (tick,waves,message) - VALUES(tick() + 10,3,'Retal raid') RETURNING (id)}); -$query->execute; -my $raid = $query->fetchrow_array; - -$query->finish; - -print "$raid\n"; - -$dbh->do(q{INSERT INTO raid_access (raid,gid) VALUES(?,'M')} - ,undef,$raid); - -my $addtarget = $dbh->prepare(q{INSERT INTO raid_targets(raid,pid,comment) - VALUES($1,$2,$3)}); - -my $incs = $dbh->prepare(q{SELECT pid,array_agg(i.eta) AS eta,array_agg(amount) AS amount - ,array_agg(shiptype) AS type,array_agg(fleet) AS name,array_agg(c.landing_tick) AS landing - FROM calls c - JOIN incomings i USING (call) - WHERE c.status <> 'Covered' AND c.landing_tick BETWEEN tick() AND tick() + 6 - AND c.landing_tick + GREATEST(i.eta,7) > tick() + 10 - GROUP BY pid - }); -$incs->execute; - -while (my $inc = $incs->fetchrow_hashref){ - my $comment = ''; - for my $eta (@{$inc->{eta}}){ - my $amount = shift @{$inc->{amount}}; - my $type = shift @{$inc->{type}}; - my $name = shift @{$inc->{name}}; - my $landing = shift @{$inc->{landing}}; - my $back = $landing + $eta; - $comment .= "$name: ETA=$eta Amount=$amount Type:'$type' Landing tick=$landing Estimated back:$back\n"; - } - $addtarget->execute($raid,$inc->{pid},$comment); -} - -$dbh->commit; -#$dbh->rollback; - -$dbh->disconnect;