]> ruin.nu Git - ndwebbie.git/commitdiff
Converted launch confirmation
authorMichael Andreen <harv@ruin.nu>
Wed, 25 Jun 2008 17:19:15 +0000 (19:19 +0200)
committerMichael Andreen <harv@ruin.nu>
Wed, 25 Jun 2008 17:19:15 +0000 (19:19 +0200)
NDWeb/Pages/LaunchConfirmation.pm [deleted file]
lib/NDWeb/Controller/Members.pm
root/src/members/launchConfirmation.tt2 [new file with mode: 0644]
templates/launchConfirmation.tmpl [deleted file]

diff --git a/NDWeb/Pages/LaunchConfirmation.pm b/NDWeb/Pages/LaunchConfirmation.pm
deleted file mode 100644 (file)
index 581ad7b..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-#**************************************************************************
-#   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::LaunchCoonfirmation;
-use strict;
-use warnings FATAL => 'all';
-use CGI qw/:standard/;
-use NDWeb::Include;
-use ND::Include;
-
-use base qw/NDWeb::XMLPage/;
-
-$NDWeb::Page::PAGES{launchConfirmation} = __PACKAGE__;
-
-sub render_body {
-       my $self = shift;
-       my ($BODY) = @_;
-       $self->{TITLE} = 'Launch Confirmation';
-       my $DBH = $self->{DBH};
-
-       return $self->noAccess unless $self->isMember;
-
-       my $error;
-
-
-       if (defined param('cmd') && param('cmd') eq 'submit'){
-               my $missions = param('mission');
-               my $findplanet = $DBH->prepare("SELECT planetid(?,?,?,?)");
-               my $findattacktarget = $DBH->prepare(q{SELECT c.target,c.wave,c.launched FROM  raid_claims c
-                       JOIN raid_targets t ON c.target = t.id
-                       JOIN raids r ON t.raid = r.id
-                       WHERE c.uid = ? AND r.tick+c.wave-1 = ? AND t.planet = ?
-                       AND r.open AND not r.removed});
-               my $finddefensetarget = $DBH->prepare(q{SELECT c.id FROM calls c 
-                               JOIN users u ON c.member = u.uid 
-                       WHERE u.planet = $1 AND c.landing_tick = $2
-               });
-               my $informDefChannel = $DBH->prepare(q{INSERT INTO defense_missions 
-                       (fleet,call) VALUES (?,?)});
-               my $addattackpoint = $DBH->prepare(q{UPDATE users SET 
-                       attack_points = attack_points + 1 WHERE uid = ?});
-               my $launchedtarget = $DBH->prepare(q{UPDATE raid_claims SET launched = True
-                       WHERE uid = ? AND target = ? AND wave = ?});
-               my $addfleet = $DBH->prepare(q{INSERT INTO fleets 
-                       (uid,name,mission,sender,target,tick,eta,back,amount)
-                       VALUES (?,?,?,?,?,?,?,?,?) RETURNING id
-               });
-               my $addships = $DBH->prepare(q{INSERT INTO fleet_ships (id,ship,amount)
-                       VALUES (?,?,?)});
-               my @missions;
-               $DBH->begin_work;
-               while ($missions =~ m/([^\n]+)\s+(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)
-                       \s+\((?:(\d+)\+)?(\d+)\).*?(?:\d+hrs\s+)?\d+mins?\s+
-                       (Attack|Defend|Return|Fake\ Attack|Fake\ Defend)
-                       (.*?)
-                       (?:Launching\ in\ tick\ (\d+),\ arrival\ in\ tick\ (\d+)
-                               |ETA:\ \d+,\ Return\ ETA:\ (\d+)
-                               |Return\ ETA:\ (\d+)
-                               )/sgx){
-                       next if $10 eq 'Return';
-                       my %mission;
-                       my $name = $1;
-                       my $tick = $self->{TICK}+$9;
-                       $tick += $8 if defined $8;
-                       my $eta = $9;
-                       my $mission = $10;
-                       my $x = $5;
-                       my $y = $6;
-                       my $z = $7;
-                       my $back = $tick + $eta - 1;
-                       if ($13){
-                               $tick = $13;
-                       }elsif ($14){
-                               $back += $14;
-                       }
-                       $mission{Tick} = $tick;
-                       $mission{Mission} = $mission;
-                       $mission{Target} = "$x:$y:$z";
-                       $mission{Back} = $back;
-
-                       my ($planet_id) = $DBH->selectrow_array($findplanet,undef,$x,$y,$z,$self->{TICK});
-
-                       my $findtarget = $finddefensetarget;
-                       if ($mission eq 'Attack'){
-                               $findtarget = $findattacktarget;
-                               $findtarget->execute($ND::UID,$tick,$planet_id) or warn $DBH->errstr;;
-                       }elsif ($mission eq 'Defend'){
-                               $findtarget = $finddefensetarget;
-                               $findtarget->execute($planet_id,$tick) or warn $DBH->errstr;;
-                       }
-
-                       my $ships = $11;
-                       my @ships;
-                       my $amount = 0;
-                       while ($ships =~ m/((?:\w+ )*\w+)\s+\w+\s+(?:(?:\w+|-)\s+){3}(?:Steal|Normal|Emp|Normal\s+Cloaked|Pod|Structure Killer)\s+(\d+)/g){
-                               $amount += $2;
-                               push @ships,{Ship => $1, Amount => $2};
-                       }
-                       $mission{Ships} = \@ships;
-
-                       if ($amount == 0){
-                               warn "No ships in: $ships";
-                               next;
-                       }
-                       my $fleet = $DBH->selectrow_array($addfleet,undef,$ND::UID,$name,$mission
-                               ,$self->{PLANET},$planet_id,$tick,$eta,$back,$amount);
-                       $mission{Fleet} = $fleet;
-                       for my $ship (@ships){
-                               $addships->execute($fleet,$ship->{Ship},$ship->{Amount})
-                                       or warn $DBH->errstr;
-                       }
-
-                       if ($findtarget->rows == 0){
-                               $mission{Warning} = p b 'No matching target!';
-                       }elsif ($mission eq 'Attack'){
-                               my $claim = $findtarget->fetchrow_hashref;
-                               if ($claim->{launched}){
-                                       $mission{Warning} = "Already launched on this target:$claim->{target},$claim->{wave},$claim->{launched}";
-                               }else{
-                                       $addattackpoint->execute($ND::UID) or warn $DBH->errstr;
-                                       $launchedtarget->execute($ND::UID,$claim->{target},$claim->{wave}) or warn $DBH->errstr;
-                                       $mission{Warning} = "OK:$claim->{target},$claim->{wave},$claim->{launched}";
-                                       log_message $ND::UID,"Gave attack point for confirmation on $mission mission to $x:$y:$z, landing tick $tick";
-                               }
-                       }elsif ($mission eq 'Defend'){
-                               my $call = $findtarget->fetchrow_hashref;
-                               $informDefChannel->execute($fleet,$call->{id}) or warn $DBH->errstr;
-                       }
-
-                       log_message $ND::UID,"Pasted confirmation for $mission mission to $x:$y:$z, landing tick $tick";
-                       push @missions,\%mission;
-               }
-               $DBH->commit or warn $DBH->errstr;
-               $BODY->param(Missions => \@missions);
-       }
-       $BODY->param(Error => $error);
-       return $BODY;
-}
-
-
-1;
index f3a53f4f9ba9df0032cd0f85e6a7488bdaf58899..78bbe80d58c67b796d5bbd2739eda9a62d4527cf 100644 (file)
@@ -146,6 +146,143 @@ sub insertintel : Private {
        $c->flash(scans => \@scans);
 }
 
+sub launchConfirmation : Local {
+       my ( $self, $c ) = @_;
+
+       $c->stash(missions => $c->flash->{missions});
+}
+
+sub postconfirmation : Local {
+       my ( $self, $c ) = @_;
+       my $dbh = $c->model;
+
+       eval {
+               my $missions = $c->req->param('mission');
+               my $findplanet = $dbh->prepare("SELECT planetid(?,?,?,?)");
+               my $findattacktarget = $dbh->prepare(q{SELECT c.target,c.wave,c.launched
+                       FROM  raid_claims c
+                               JOIN raid_targets t ON c.target = t.id
+                               JOIN raids r ON t.raid = r.id
+                       WHERE c.uid = ? AND r.tick+c.wave-1 = ? AND t.planet = ?
+                               AND r.open AND not r.removed
+                       });
+               my $finddefensetarget = $dbh->prepare(q{SELECT c.id FROM calls c
+                               JOIN users u ON c.member = u.uid
+                       WHERE u.planet = $1 AND c.landing_tick = $2
+               });
+               my $informDefChannel = $dbh->prepare(q{INSERT INTO defense_missions
+                       (fleet,call) VALUES (?,?)
+                       });
+               my $addattackpoint = $dbh->prepare(q{UPDATE users SET
+                       attack_points = attack_points + 1 WHERE uid = ?
+                       });
+               my $launchedtarget = $dbh->prepare(q{UPDATE raid_claims SET launched = True
+                       WHERE uid = ? AND target = ? AND wave = ?
+                       });
+               my $addfleet = $dbh->prepare(q{INSERT INTO fleets
+                       (uid,name,mission,sender,target,tick,eta,back,amount)
+                       VALUES ($1,$2,$3,(SELECT planet FROM users WHERE uid = $1),$4,$5,$6,$7,$8)
+                       RETURNING id
+                       });
+               my $addships = $dbh->prepare(q{INSERT INTO fleet_ships (id,ship,amount)
+                       VALUES (?,?,?)
+                       });
+               my $log = $dbh->prepare(q{INSERT INTO forum_posts (ftid,uid,message) VALUES(
+                       (SELECT ftid FROM users WHERE uid = $1),$1,$2)
+                       });
+               my @missions;
+               $dbh->begin_work;
+               while ($missions =~ m/([^\n]+)\s+(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)
+                       \s+\((?:(\d+)\+)?(\d+)\).*?(?:\d+hrs\s+)?\d+mins?\s+
+                       (Attack|Defend|Return|Fake\ Attack|Fake\ Defend)
+                       (.*?)
+                       (?:Launching\ in\ tick\ (\d+),\ arrival\ in\ tick\ (\d+)
+                               |ETA:\ \d+,\ Return\ ETA:\ (\d+)
+                               |Return\ ETA:\ (\d+)
+                               )/sgx){
+                       next if $10 eq 'Return';
+                       my %mission;
+                       my $name = $1;
+                       my $tick = $c->stash->{TICK}+$9;
+                       $tick += $8 if defined $8;
+                       my $eta = $9;
+                       my $mission = $10;
+                       my $x = $5;
+                       my $y = $6;
+                       my $z = $7;
+                       my $back = $tick + $eta - 1;
+                       if ($13){
+                               $tick = $13;
+                       }elsif ($14){
+                               $back += $14;
+                       }
+                       $mission{tick} = $tick;
+                       $mission{mission} = $mission;
+                       $mission{target} = "$x:$y:$z";
+                       $mission{back} = $back;
+
+                       my ($planet_id) = $dbh->selectrow_array($findplanet,undef,$x,$y,$z,$c->stash->{TICK});
+
+                       my $findtarget = $finddefensetarget;
+                       if ($mission eq 'Attack'){
+                               $findtarget = $findattacktarget;
+                               $findtarget->execute($c->user->id,$tick,$planet_id);
+                       }elsif ($mission eq 'Defend'){
+                               $findtarget = $finddefensetarget;
+                               $findtarget->execute($planet_id,$tick);
+                       }
+
+                       my $ships = $11;
+                       my @ships;
+                       my $amount = 0;
+                       while ($ships =~ m/((?:\w+ )*\w+)\s+\w+\s+(?:(?:\w+|-)\s+){3}(?:Steal|Normal|Emp|Normal\s+Cloaked|Pod|Structure Killer)\s+(\d+)/g){
+                               $amount += $2;
+                               push @ships,{ship => $1, amount => $2};
+                       }
+                       $mission{ships} = \@ships;
+
+                       if ($amount == 0){
+                               warn "No ships in: $ships";
+                               next;
+                       }
+                       my $fleet = $dbh->selectrow_array($addfleet,undef,$c->user->id,$name,$mission
+                               ,$planet_id,$tick,$eta,$back,$amount);
+                       $mission{fleet} = $fleet;
+                       for my $ship (@ships){
+                               $addships->execute($fleet,$ship->{ship},$ship->{amount});
+                       }
+
+                       if ($findtarget->rows == 0){
+                               $mission{warning} = 'No matching target!';
+                       }elsif ($mission eq 'Attack'){
+                               my $claim = $findtarget->fetchrow_hashref;
+                               if ($claim->{launched}){
+                                       $mission{warning} = "Already launched on this target:$claim->{target},$claim->{wave},$claim->{launched}";
+                               }else{
+                                       $addattackpoint->execute($c->user->id);
+                                       $launchedtarget->execute($c->user->id,$claim->{target},$claim->{wave});
+                                       $mission{warning} = "OK:$claim->{target},$claim->{wave},$claim->{launched}";
+                                       $log->execute($c->user->id,"Gave attack point for confirmation on $mission mission to $x:$y:$z, landing tick $tick");
+                               }
+                       }elsif ($mission eq 'Defend'){
+                               my $call = $findtarget->fetchrow_hashref;
+                               $informDefChannel->execute($fleet,$call->{id});
+                       }
+
+                       $log->execute($c->user->id,"Pasted confirmation for $mission mission to $x:$y:$z, landing tick $tick");
+                       push @missions,\%mission;
+               }
+               $dbh->commit;
+               $c->flash(missions => \@missions);
+       };
+       if ($@){
+               $dbh->rollback;
+               die $@;
+       }
+
+       $c->res->redirect($c->uri_for('launchConfirmation'));
+}
+
 =head1 AUTHOR
 
 Michael Andreen (harv@ruin.nu)
diff --git a/root/src/members/launchConfirmation.tt2 b/root/src/members/launchConfirmation.tt2
new file mode 100644 (file)
index 0000000..88d1f89
--- /dev/null
@@ -0,0 +1,35 @@
+[% META title = 'Launch confirmation' %]
+[% FOR m IN missions %]
+[% IF m.warning %]<h4 style="color: red">[% m.warning %]</h4>[% END %]
+<p>Adding the following fleet: [% m.fleet %]
+<br>Target: [% m.target %]
+<br>Mission: [% m.mission %]
+<br>Landing tick: [% m.tick %]
+<br>Back: [% m.back %]
+</p>
+<table>
+       [% FOR s IN m.ships %]
+       <tr><td>[% s.ship %]</td><td>[% s.amount %]</td></tr>
+       [% END %]
+</table>
+<hr/>
+[% END %]
+
+[% IF missions.size == 0 %]
+<h3 style="color: red">COULD NOT PARSE YOUR MISSIONS, MAKE SURE YOU'VE READ THE INSTRUCTIONS AND PASTED WHAT WE ASK FOR</h3>
+[% END %]
+<form action="[% c.uri_for('postconfirmation') %]" method="post"><fieldset> <legend>Launch confirmation</legend>
+       <p>Paste all (ctrl+a should be ok, but try with just single mission if you get an error, save the ctrl+a output and contact harv) information from <b>missions page</b> here (NOT from news page, and not overview, nor gal status). It's ok to paste when prelaunched, as long as you're sure you won't change your plans.</p>
+       <p>A valid launch confirmation looks like this, but can also be after the fleet has launched and has ETA/Return ETA shown as last line:</p>
+       <pre>
+Some fleet name        X:Y:Z   A:B:C (2+8)
+9hrs 28mins    Defend
+Ship   Class   Target  Type    Count
+Viper  Corvette        Frigate Emp     50
+
+Launching in tick 117, arrival in tick 124, Return ETA: Instant
+       </pre>
+       <textarea rows="25" cols="80" name="mission"></textarea>
+       <br>
+       <input type="submit" name="cmd" value="Submit">
+</fieldset></form>
diff --git a/templates/launchConfirmation.tmpl b/templates/launchConfirmation.tmpl
deleted file mode 100644 (file)
index ef1681c..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<TMPL_VAR NAME=Error>
-<TMPL_LOOP Missions>
-<TMPL_IF Warning><p><b><TMPL_VAR NAME=Warning></b></p></TMPL_IF>
-<p>Adding the following fleet: <TMPL_VAR NAME=Fleet>
-<br/>Target: <TMPL_VAR NAME=Target>
-<br/>Mission: <TMPL_VAR NAME=Mission>
-<br/>Landing tick: <TMPL_VAR NAME=Tick>
-<br/>Back: <TMPL_VAR NAME=Back>
-</p>
-<table>
-<TMPL_LOOP Ships>
-       <tr><td><TMPL_VAR NAME=Ship></td><td><TMPL_VAR NAME=Amount></td></tr>
-</TMPL_LOOP>
-</table>
-<hr/>
-</TMPL_LOOP>
-<form action="<TMPL_VAR NAME=PAGE>" method="post"><fieldset> <legend>Launch confirmation</legend>
-       <p>Paste all (ctrl+a should be ok, but try with just single mission if you get an error, save the ctrl+a output and contact harv) information from <b>missions page</b> here (NOT from news page, and not overview, nor gal status). It's ok to paste when prelaunched, as long as you're sure you won't change your plans.</p>
-       <p>A valid launch confirmation looks like this, but can also be after the fleet has launched and has ETA/Return ETA shown as last line:</p>
-       <pre>
-Some fleet name        X:Y:Z   A:B:C (2+8)
-9hrs 28mins    Defend
-Ship   Class   Target  Type    Count
-Viper  Corvette        Frigate Emp     50
-
-Launching in tick 117, arrival in tick 124, Return ETA: Instant
-       </pre>
-       <textarea rows="25" cols="80" name="mission"></textarea>
-       <input type="hidden" name="cmd" value="submit"/>
-       <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
-       <br/>
-       <input type="submit" value="Submit"/>
-</fieldset></form>