$c->res->redirect($c->uri_for(''));
}
-sub postfleetupdate : Local {
- my ( $self, $c ) = @_;
- my $dbh = $c->model;
-
- my $fleet = $c->req->param('fleet');
- $fleet =~ s/,//g;
- my $amount = 0;
- my @ships;
- while ($fleet =~ m/((?:[A-Z][a-z]+ )*[A-Z][a-z]+)\s+(\d+)/g){
- $amount += $2;
- push @ships, [$1,$2];
- }
- if ($amount){
- $dbh->begin_work;
- eval{
- my $insert = $dbh->prepare(q{INSERT INTO fleets
- (pid,name,mission,tick,amount)
- VALUES (?,'Main','Full fleet',tick(),?) RETURNING fid});
- my ($id) = $dbh->selectrow_array($insert,undef
- ,$c->user->planet,$amount);
- $insert = $dbh->prepare(q{INSERT INTO fleet_ships
- (fid,ship,amount) VALUES (?,?,?)});
- for my $s (@ships){
- unshift @{$s},$id;
- $insert->execute(@{$s});
- }
- $insert = $dbh->prepare(q{INSERT INTO full_fleets
- (fid,uid) VALUES (?,?)});
- $insert->execute($id,$c->user->id);
- $dbh->commit;
- };
- if ($@){
- if ($@ =~ m/insert or update on table "fleet_ships" violates foreign key constraint "fleet_ships_ship_fkey"\s+DETAIL:\s+Key \(ship\)=\(([^)]+)\)/){
- $c->flash( error => "'$1' is NOT a valid ship");
- }else{
- $c->flash( error => $@);
- }
- $dbh->rollback;
- }
- }else{
- $c->flash( error => 'Fleet does not contain any ships');
- }
-
- $c->res->redirect($c->uri_for(''));
-}
-
sub postfleetsupdates : Local {
my ( $self, $c ) = @_;
my $dbh = $c->model;
my $dbh = $c->model;
try {
- my $findplanet = $dbh->prepare("SELECT planetid(?,?,?,?)");
+ my $findplanet = $dbh->prepare(q{SELECT planetid(?,?,?,tick())});
my $addfleet = $dbh->prepare(q{INSERT INTO fleets
(name,mission,pid,tick,amount)
VALUES ($2,$3,(SELECT pid FROM users WHERE uid = $1),tick(),$4)
UPDATE launch_confirmations SET back = $2 WHERE fid = $1
});
my $addconfirmation = $dbh->prepare(q{INSERT INTO launch_confirmations
- (fid,uid,pid,landing_tick,eta,back) VALUES ($1,$2,$3,$4,$5,$6)
+ (fid,uid,pid,landing_tick,eta,back,num) VALUES ($1,$2,$3,$4,$5,$6,$7)
});
my $addships = $dbh->prepare(q{INSERT INTO fleet_ships (fid,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 $return = $dbh->prepare(q{
+UPDATE launch_confirmations SET back = tick()
+WHERE uid = $1 AND num = $2 AND back > tick()
+ });
+ my $fullfleet = $dbh->prepare(q{INSERT INTO full_fleets
+ (fid,uid) VALUES (?,?)});
$dbh->begin_work;
my @missions = parseconfirmations($c->req->param('mission'), $c->stash->{TICK});
for my $m (@missions){
if ($m->{mission} eq 'Return'){
$c->forward("addReturnFleet", [$m]);
- $updatefleet->execute($m->{fid},$m->{back}) if $m->{fid};
- next;
+ if($m->{fid}){
+ $updatefleet->execute($m->{fid},$m->{back});
+ next;
+ }else{
+ $m->{pid} = $c->user->planet;
+ }
+ }elsif ($m->{target} =~ /^(\d+):(\d+):(\d+)$/) {
+ $m->{pid} = $dbh->selectrow_array($findplanet,undef,$1,$2,$3);
+ unless ($m->{pid}){
+ $m->{warning} = "No planet at $m->{target}, try again next tick.";
+ next;
+ }
}
- $m->{pid} = $dbh->selectrow_array($findplanet,undef,@{$m->{target}},$c->stash->{TICK});
- unless ($m->{pid}){
- $m->{warning} = "No planet at @{$m->{target}}, try again next tick.";
+
+ #Recall fleets with same slot number
+ $return->execute($c->user->id,$m->{num});
+
+ unless ($m->{mission}){
+ $m->{warning} = "Not on a mission, but matching fleets recalled";
next;
}
$c->forward("findDuplicateFleet", [$m]);
if ($m->{match}){
- $m->{warning} = "Already confirmed this fleet, changing back to to match this paste";
- $updatefleet->execute($m->{fid},$m->{back});
+ $m->{warning} = "Already confirmed this fleet, updating changed information";
+ $updatefleet->execute($m->{fid},$m->{back}) if $m->{pid};
next;
}
+
$m->{fleet} = $dbh->selectrow_array($addfleet,undef,$c->user->id,$m->{name}
,$m->{mission},$m->{amount});
+
+ if ($m->{mission} eq 'Full fleet'){
+ $fullfleet->execute($m->{fleet},$c->user->id);
+ }else{
+ $addconfirmation->execute($m->{fleet},$c->user->id,$m->{pid},$m->{tick},$m->{eta},$m->{back},$m->{num});
+ }
+
if ($m->{mission} eq 'Attack'){
$c->forward("addAttackFleet", [$m]);
}elsif ($m->{mission} eq 'Defend'){
$c->forward("addDefendFleet", [$m]);
}
- $addconfirmation->execute($m->{fleet},$c->user->id,$m->{pid},$m->{tick},$m->{eta},$m->{back});
-
for my $ship (@{$m->{ships}}){
$addships->execute($m->{fleet},$ship->{ship},$ship->{amount});
}
- $log->execute($c->user->id,"Pasted confirmation for $m->{mission} mission to @{$m->{target}}, landing tick $m->{tick}");
+ $log->execute($c->user->id,"Pasted confirmation for $m->{mission} mission to $m->{target}, landing tick $m->{tick}");
}
- $dbh->commit;
$c->flash(missions => \@missions);
+ $dbh->commit;
$c->signal_bots;
} catch {
$dbh->rollback;
my ( $missions, $tick ) = @_;
return unless $missions;
my @missions;
- while ($missions =~ m/\s*([^\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){
- my $tick = $tick;
- $tick += $9;
- $tick += $8 if defined $8;
- $tick = $13 if defined $13;
- my $eta = $9;
- $eta += $14 if defined $14;
- my %mission = (
- name => $1,
- mission => $10,
- tick => $tick,
- eta => $eta,
- back => $10 eq 'Return' ? $tick : $tick + $eta - 1,
- target => [$5,$6,$7],
- from => [$2,$3,$4],
- );
- my $ships = $11;
- my @ships;
- $mission{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){
- $mission{amount} += $2;
- push @ships,{ship => $1, amount => $2};
+ $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 (?<target>\d+:\d+:\d+)? \t (?<target>\d+:\d+:\d+)? \t (?<target>\d+:\d+:\d+)? \W+
+ \QLaunch Tick:\E \t (?<lt>\d*) \t (?<lt>\d*) \t (?<lt>\d*) \W+
+ ETA: \t (?<eta>[^\t]*) \t (?<eta>[^\t]*) \t (?<eta>[^\t]*)
+ /sx){
+ my %match = %-;
+ for my $i (0..2){
+ my %mission = (
+ name => $match{name}->[$i],
+ mission => $match{mission}->[$i],
+ target => $match{target}->[$i],
+ amount => $match{amount}->[$i],
+ lt => $match{lt}->[$i],
+ num => $i,
+ ships => []
+ );
+ given($match{eta}->[$i]){
+ 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;
}
- $mission{ships} = \@ships;
-
- if ($mission{amount} == 0){
- warn "No ships in: $ships";
- next;
+ 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];
}
- push @missions,\%mission;
}
return @missions;
}
my $findfleet = $dbh->prepare(q{
SELECT fid FROM fleets f
- JOIN launch_confirmations lc USING (fid)
-WHERE uid = $1 AND name = $2 AND mission = $3 AND amount = $4
- AND lc.pid = $5 AND landing_tick = $6
+ 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->{name}
+ 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};
if ($call->{call}){
$informDefChannel->execute($m->{fleet},$call->{call});
}else{
- $m->{warning} = "No call for @{$m->{target}} landing tick $m->{tick}";
+ $m->{warning} = "No call for $m->{target} landing tick $m->{tick}";
}
}
my $findfleet = $dbh->prepare(q{
SELECT fid FROM fleets f
JOIN launch_confirmations lc USING (fid)
-WHERE uid = $1 AND name = $2 AND amount = $3
+WHERE uid = $1 AND num = $2 AND amount = $3
AND back >= $4
});
- my $fid = $dbh->selectrow_array($findfleet,undef,$c->user->id,$m->{name}
+ my $fid = $dbh->selectrow_array($findfleet,undef,$c->user->id,$m->{num}
,$m->{amount}, $m->{tick});
$c->forward("matchShips", [$m,$fid]);
if ($m->{match}){
$m->{fid} = $fid;
$m->{warning} = "Return fleet, changed back tick to match the return eta.";
} else {
- $m->{warning} = "Couldn't find a fleet matching this returning fleet. Recall manually.";
+ $m->{warning} = "Couldn't find a fleet matching this returning fleet, so adding a new fleet that is returning";
}
}
[% IF m.warning %]<h4 style="color: red">[% m.warning %]</h4>[% END %]
<p>Adding the following fleet: [% m.fleet %]
<br>Name: [% m.name %]
-<br>Target: [% m.target.join(":") %]
+<br>Num: [% m.num %]
+<br>Target: [% m.target %]
<br>Mission: [% m.mission %]
<br>Landing tick: [% m.tick %]
<br>ETA: [% m.eta %]
<br>Back: [% m.back %]
<br>Amount: [% m.amount %]
+<br>LT: [% m.lt %]
</p>
<table>
[% FOR s IN m.ships %]
[% 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>
+<h4 style="color: red">If you are using Internet Explorer you have to switch to Opera, Firefox or Chrome</h4>
[% 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>
+ <p>Paste all (ctrl+a should be ok, but try with just the fleet information if you get an error, save the ctrl+a output and contact harv) information from <b>fleets page</b> here (NOT from news page, and not overview, nor gal status).</p>
+ <p>A valid launch confirmation looks like this:</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
+Ships Cla T1 T2 T3 Base (i) Alpha (i) Beta (i) Gamma (i) TOTAL
+Beetle CO FI CO -- 0 10,000 0 0 10,000
+Viper CO DE FR -- 0 10,000 0 0 10,000
+Locust FR CR BS -- 0 0 0 10,000 10,000
+Roach CR FR DE -- 0 0 2,000 0 1,000
+Scarab CR CR DE FR 0 0 1,000 0 1,000
+Tarantula CR BS CR -- 0 0 1,000 0 1,000
+Mantis BS CO FI -- 1,000 0 0 0 1,000
+Mosquito CO RO RO RO 0 1,000 0 0 1,000
+Hornet CR RO RO RO 0 0 3,000 0 1,000
+Termite BS ST ST ST 1,000 0 0 0 1,000
-Launching in tick 117, arrival in tick 124, Return ETA: Instant
+Total Ships in Fleet 2,000 21,000 4,000 10,000
+
+
+Mission: Attack Defend
+Target: 1:3:1 1:3:2
+Launch Tick: 5734 5745
+ETA: Galaxy: 5, Universe: 8 10
+Arrival: 5743
+Return ETA: Instant
+ Cancel Order 9 (+11)
+Arrival: 5753
+Return ETA: Instant
+ Cancel Order
</pre>
<textarea rows="25" cols="80" name="mission"></textarea>
<br>