From: Michael Andreen Date: Fri, 6 Aug 2010 23:56:25 +0000 (+0200) Subject: Update fleet parsing for r38, launch confirmation and fleet update is combined X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=30262dafa6c73a1d1cbb493e66b59e267eaa6682 Update fleet parsing for r38, launch confirmation and fleet update is combined --- diff --git a/database/r38fleets.sql b/database/r38fleets.sql new file mode 100644 index 0000000..861ecb0 --- /dev/null +++ b/database/r38fleets.sql @@ -0,0 +1 @@ +ALTER TABLE launch_confirmations ADD COLUMN num INT NOT NULL; diff --git a/lib/NDWeb/Controller/Members.pm b/lib/NDWeb/Controller/Members.pm index 8c24d66..0751b40 100644 --- a/lib/NDWeb/Controller/Members.pm +++ b/lib/NDWeb/Controller/Members.pm @@ -166,52 +166,6 @@ sub postowncoords : Local { $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; @@ -526,7 +480,7 @@ sub postconfirmation : Local { 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) @@ -536,7 +490,7 @@ sub postconfirmation : Local { 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 (?,?,?) @@ -544,44 +498,69 @@ UPDATE launch_confirmations SET back = $2 WHERE fid = $1 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; @@ -599,43 +578,62 @@ 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}; + $missions =~ s/,//g; + if ($missions =~ m/ + Ships \s?\t Cla \s?\t T1 \s?\t T2 \s?\t T3 \s?\t Base\ \(i\) \s (?.+?)\ \(i\) \s?\t (?.+?)\ \(i\) \s?\t (?.+?)\ \(i\) \s?\t TOTAL \W+ + (?.+?) + \QTotal Ships in Fleet\E \s?\t (\d+) \s?\t (?\d+) \s?\t (?\d+) \s?\t (?\d+) \W+ + Mission: \t (?\w*) \t (?\w*) \t (?\w*) \W+ + Target: \t (?\d+:\d+:\d+)? \t (?\d+:\d+:\d+)? \t (?\d+:\d+:\d+)? \W+ + \QLaunch Tick:\E \t (?\d*) \t (?\d*) \t (?\d*) \W+ + ETA: \t (?[^\t]*) \t (?[^\t]*) \t (?[^\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; } @@ -646,11 +644,11 @@ 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 + 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}; @@ -699,7 +697,7 @@ INSERT INTO defense_missions (fleet,call) VALUES (?,?) 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}"; } } @@ -710,17 +708,17 @@ sub addReturnFleet : Private { 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"; } } diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index 6b06905..41b658d 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -71,10 +71,10 @@
[% PROCESS inc/targetlist.tt2 %]
[% ELSIF c.check_user_roles("member_menu") %] [% IF c.user.planet %] -

Update your fleet to see raids and launch confirmation

-
-

Paste your total fleet from ships section on overview here:

-

+

Update your fleets to see raids and launch confirmation

+ +

Paste your fleets from fleets page here:

+


diff --git a/root/src/members/index.tt2 b/root/src/members/index.tt2 index d3f4ebc..a2ef6fb 100644 --- a/root/src/members/index.tt2 +++ b/root/src/members/index.tt2 @@ -152,15 +152,6 @@ CrBs: -[% IF c.user.planet %] -
-
Fleet -

Paste your total fleet from ships section on overview here (do it daily to see the menus):

- -
-
-
-[% END %] [% IF c.user.planet %] stats for your planet diff --git a/root/src/members/launchConfirmation.tt2 b/root/src/members/launchConfirmation.tt2 index fd5487d..04a7770 100644 --- a/root/src/members/launchConfirmation.tt2 +++ b/root/src/members/launchConfirmation.tt2 @@ -3,12 +3,14 @@ [% IF m.warning %]

[% m.warning %]

[% END %]

Adding the following fleet: [% m.fleet %]
Name: [% m.name %] -
Target: [% m.target.join(":") %] +
Num: [% m.num %] +
Target: [% m.target %]
Mission: [% m.mission %]
Landing tick: [% m.tick %]
ETA: [% m.eta %]
Back: [% m.back %]
Amount: [% m.amount %] +
LT: [% m.lt %]

[% FOR s IN m.ships %] @@ -20,17 +22,37 @@ [% IF missions.size == 0 %]

COULD NOT PARSE YOUR MISSIONS, MAKE SURE YOU'VE READ THE INSTRUCTIONS AND PASTED WHAT WE ASK FOR

+

If you are using Internet Explorer you have to switch to Opera, Firefox or Chrome

[% END %]
Launch confirmation -

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 missions page 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.

-

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:

+

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 fleets page here (NOT from news page, and not overview, nor gal status).

+

A valid launch confirmation looks like this:

-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