+ default{
+ $c->flash( error => $_);
+ }
+ };
+ $c->res->redirect($c->uri_for('launchConfirmation'));
+}
+
+sub parseconfirmations {
+ my ( $missions, $tick ) = @_;
+ return unless $missions;
+ my @missions;
+ $missions =~ s/,//g;
+ if ($missions =~ m/
+ Ships \s?\t Cla \s?\t T1 \s?\t T2 \s?\t T3 \s?\t Base\ \(i\) \s (?<name>.+?)\ \(i\) \s?\t (?<name>.+?)\ \(i\) \s?\t (?<name>.+?)\ \(i\) \s?\t TOTAL \W+
+ (?<ships>.+?)
+ \QTotal Ships in Fleet\E \s?\t (\d+) \s?\t (?<amount>\d+) \s?\t (?<amount>\d+) \s?\t (?<amount>\d+) \W+
+ Mission: \t (?<mission>\w*) \t (?<mission>\w*) \t (?<mission>\w*) \W+
+ Target: \t (?<targets>((\d+:\d+:\d+)?\t)*) \W+
+ \QLaunch Tick:\E \t (?<lts>(\d*\t)*) \W+
+ ETA: \t? (?<etas>([^\t]+\t?)*)
+ /sx){
+ my %match = %-;
+ my @etas = split /\t/, $+{etas};
+ my @targets = split /\t/, $+{targets};
+ my @lts = split /\t/, $+{lts};
+ for my $i (0..2){
+ my %mission = (
+ name => $match{name}->[$i],
+ mission => $match{mission}->[$i],
+ amount => $match{amount}->[$i],
+ num => $i,
+ ships => []
+ );
+ if ($mission{amount} == 0){
+ push @missions,\%mission;
+ next;
+ }
+
+ $mission{target} = shift @targets;
+ $mission{lt} = shift @lts;
+ given(shift @etas){
+ when(/^(\d+) (\s+ \(\+\d+\))? \W+
+ Arrival:\ (\d+) \W+
+ \QReturn ETA: \E(Instant|\d+)/sx){
+ $mission{tick} = $3;
+ $mission{eta} = $1 + $4;
+ $mission{back} = $3 + $mission{eta} - 1;
+ }
+ when(/^(\d+) \W+
+ Arrival:\ (\d+)/sx){
+ $mission{tick} = $2;
+ $mission{eta} = $1;
+ $mission{back} = $2;
+ }
+ }
+ push @missions,\%mission;
+ }
+ push @missions,{
+ name => 'Main',
+ num => 3,
+ mission => 'Full fleet',
+ tick => $tick,
+ amount => 0,
+ ships => []
+ };
+ while ($match{ships}->[0] =~ m/((?:\w+ )*\w+)\s+(FI|CO|FR|DE|CR|BS)[^\d]+([\d\s]+)/g){
+ my $ship = $1;
+ my @amounts = split /\D+/, $3;
+ my $amount = shift @amounts;
+ die "Ships don't sum up properly" if $amounts[3] != $amount + $amounts[0] + $amounts[1] + $amounts[2];
+ for my $i (0..3){
+ push @{$missions[$i]->{ships}},{ship => $ship, amount => $amounts[$i]} if $amounts[$i] > 0;
+ }
+ $missions[3]->{amount} += $amounts[3];
+ }
+ }
+ return @missions;
+}
+
+sub findDuplicateFleet : Private {
+ my ( $self, $c, $m ) = @_;
+ my $dbh = $c->model;
+
+ my $findfleet = $dbh->prepare(q{
+SELECT fid FROM fleets f
+ LEFT JOIN launch_confirmations lc USING (fid)
+WHERE f.pid = (SELECT pid FROM users WHERE uid = $1) AND mission = $3 AND amount = $4 AND
+ COALESCE(uid = $1 AND num = $2 AND lc.pid = $5 AND landing_tick = $6, TRUE)
+ });
+ my $fid = $dbh->selectrow_array($findfleet,undef,$c->user->id,$m->{num}
+ ,$m->{mission},$m->{amount}, $m->{pid}, $m->{tick});
+ $c->forward("matchShips", [$m,$fid]);
+ $m->{fid} = $fid if $m->{match};
+}
+
+sub addAttackFleet : Private {
+ my ( $self, $c, $m ) = @_;
+ my $dbh = $c->model;
+
+ 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.pid = ?
+ AND r.open AND not r.removed
+ });
+ my $launchedtarget = $dbh->prepare(q{
+UPDATE raid_claims SET launched = TRUE
+WHERE uid = ? AND target = ? AND wave = ?
+ });
+ my $claim = $dbh->selectrow_hashref($findattacktarget,undef,$c->user->id,$m->{tick},$m->{pid});
+ if ($claim->{launched}){
+ $m->{warning} = "Already launched on this target:$claim->{target},$claim->{wave},$claim->{launched}";
+ }elsif(defined $claim->{launched}){
+ $launchedtarget->execute($c->user->id,$claim->{target},$claim->{wave});
+ $m->{warning} = "OK:$claim->{target},$claim->{wave},$claim->{launched}";
+ }else{
+ $m->{warning} = "You haven't claimed this target";