$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 @intel;
while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)
- \*?\s+(.+)(?:Ter|Cat|Xan|Zik|Etd)?
- \s+(\d+)\s+(Attack|Defend)\s+(\d+)/gx){
+ \*?\s+(A|D)\s+(.+?)\s+(?:(?:Ter|Cat|Xan|Zik|Etd)\s+)?(\d+)\s+(\d+)/gx){
my $ingal = ($1 == $4 && $2 == $5) || 0;
my $lt = $tick + $10;
my $back = ($ingal ? $lt + 4 : undef);
+ my $mission = $7 eq 'A' ? 'Attack' : 'Defend';
eval {
- $addintel->execute($7,$9,$lt,$1,$2,$3,$4,$5,$6,$tick,$10,$8
+ $addintel->execute($8,$mission,$lt,$1,$2,$3,$4,$5,$6,$tick,$10,$9
,$ingal,$back, $c->user->id);
push @intel,"Added $&";
};
});
my $msg = $c->req->param('message');
- while ($msg =~ /(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\s+([^:]*\S+)\s+(?:Ter|Cat|Xan|Zik|Etd)\s+([\d,]+)\s+Attack\s+(\d+)/gc
- || $msg =~ /(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)\s+\((?:Ter|Cat|Xan|Zik|Etd)\)\s+([^,]*\S+)\s+([\d,]+)\s+(\d+)\s+\(\d+\)/gc){
+ while ($msg =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\*?\s+A\s+(.+?)\s+(Ter|Cat|Xan|Zik|Etd)\s+(\d+)\s+(\d+)/gc
+ ||$msg =~ /expand\s+(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\s+([^:]*\S+)\s+(Ter|Cat|Xan|Zik|Etd)\s+([\d,]+)\s+(\d+)/gc
+ || $msg =~ /(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)\s+\((Ter|Cat|Xan|Zik|Etd)\)\s+([^,]*\S+)\s+([\d,]+)\s+(\d+)\s+\(\d+\)/gc){
my $inc = {message => $&};
- my $amount = $8;
+ my $amount = $9;
{
$amount =~ s/,//g;
}
my $uid = $dbh->selectrow_array($user,undef,$1,$2,$3);
die '<i>No user with these coords</i>' unless $uid;
- my $call = $dbh->selectrow_array($call,undef,$uid,$9);
+ my $call = $dbh->selectrow_array($call,undef,$uid,$10);
if ($call){
my $pid = $dbh->selectrow_hashref($fleet,undef,$4,$5,$6,$amount,$7,$call);
die '<i>Duplicate</i>' if $pid;
}
- $irc->execute($c->user->id, $inc->{message});
+ my $message = "$1:$2:$3 $4:$5:$6 $7 $8 $amount $10";
+ $irc->execute($c->user->id, $message);
$inc->{status} = '<b>Added</b>';
} catch {
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;
sub parseconfirmations {
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};
+ my @slots;
+ $missions =~ s/\s?,\s?//g;
+ $missions =~ s/\s*([:+])\s*/$1/g;
+ $missions =~ s/\(\s/(/g;
+ $missions =~ s/\s\)/)/g;
+ my $returnetare = qr/(\d+) \s+
+ Arrival:\s*(\d+)/sx;
+ my $missionetare = qr/\s* (\d+ \+ \s*)? (\d+) \s+
+ Arrival:\s*(\d+) \s+
+ \QReturn ETA:\E\s*(?:(?<eta>Instant) \s+ Cancel \s+ Order
+ | (?<eta>\d+) \s+ Ticks \s+ Recall \s+ Fleet)/sx;
+ my $etare = qr/(Galaxy:\d+Universe:\d+(?:Alliance:\d+)?
+ |$missionetare
+ |$returnetare)\s*/x;
+ my $missre = qr/((?:Alliance\ Standby)|(?:(?:Fake\ )?\w+))\s*/x;
+ if ($missions =~ m/
+ Ships \s+ Cla \s+ T\s?1 \s+ T\s?2 \s+ T\s?3 \s+ Base \s+ \(i\) \s (?<name>.+?) \s+ \(i\) \s+ (?<name>.+?) \s+ \(i\) \s+ (?<name>.+?) \s+ \(i\) \s+ TOTAL \s+
+ (?<ships>.+?)
+ \QTotal Ships in Fleet\E \s+ (\d+) \s+ (?<amount>\d+) \s+ (?<amount>\d+) \s+ (?<amount>\d+) \s+
+ Mission: \s* (?<missions>(?:$missre)*) \s*
+ Target: \s* (?<targets>((\d+:\d+:\d+)?\s)*) \s*
+ \QLaunch Tick:\E \s* (?<lts>(\d+\s+)*) \s*
+ ETA: \s* (?<etas>(?:$etare)*)
+ /sx){
+ my %match = %-;
+ my @targets = split /\s+/, $+{targets};
+ my @lts = split /\s+/, $+{lts};
+ my @etas;
+ my $_ = $+{etas};
+ while(/$etare/sxg){
+ push @etas, $1;
}
- $mission{ships} = \@ships;
+ my @missions ;
+ $_ = $+{missions};
+ while(/$missre/sxg){
+ push @missions, $1;
+ }
+ for my $i (0..2){
+ my %mission = (
+ name => $match{name}->[$i],
+ mission => '' ,
+ amount => $match{amount}->[$i],
+ num => $i,
+ ships => []
+ );
+ if ($mission{amount} == 0){
+ push @slots,\%mission;
+ next;
+ }
- if ($mission{amount} == 0){
- warn "No ships in: $ships";
- next;
+ if ($missions[0] eq 'Alliance Standby'){
+ shift @missions;
+ push @slots,\%mission;
+ next;
+ }
+
+ given(shift @etas){
+ when(/$missionetare/sx){
+ $mission{tick} = $3;
+ $mission{eta} = $2 + $+{eta};
+ $mission{back} = $3 + $mission{eta} - 1;
+ $mission{target} = shift @targets;
+ $mission{lt} = shift @lts;
+ $mission{mission} = shift @missions;
+ }
+ when(/$returnetare/sx){
+ $mission{tick} = $2;
+ $mission{eta} = $1;
+ $mission{back} = $2;
+ $mission{target} = shift @targets;
+ $mission{lt} = shift @lts;
+ $mission{mission} = shift @missions;
+ die "Did you forget some at the end? '$mission{mission}'" if $mission{mission} ne 'Return';
+ }
+ }
+ push @slots,\%mission;
+ }
+ push @slots,{
+ 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*){5})/g){
+ my $ship = $1;
+ my @amounts = split /\D+/, $3;
+ my $base = shift @amounts;
+ die "Ships don't sum up properly" if $amounts[3] != $base + $amounts[0] + $amounts[1] + $amounts[2];
+ for my $i (0..3){
+ push @{$slots[$i]->{ships}},{ship => $ship, amount => $amounts[$i]} if $amounts[$i] > 0;
+ }
+ $slots[3]->{amount} += $amounts[3];
}
- push @missions,\%mission;
}
- return @missions;
+ return @slots;
}
sub findDuplicateFleet : Private {
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 (mission <> 'Full fleet' OR tick > $6 - 6)
+ 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";
}
}