]> ruin.nu Git - ndwebbie.git/commitdiff
Update fleet parsing for r38, launch confirmation and fleet update is combined
authorMichael Andreen <harv@ruin.nu>
Fri, 6 Aug 2010 23:56:25 +0000 (01:56 +0200)
committerMichael Andreen <harv@ruin.nu>
Fri, 6 Aug 2010 23:56:25 +0000 (01:56 +0200)
database/r38fleets.sql [new file with mode: 0644]
lib/NDWeb/Controller/Members.pm
root/lib/site/leftbar.tt2
root/src/members/index.tt2
root/src/members/launchConfirmation.tt2

diff --git a/database/r38fleets.sql b/database/r38fleets.sql
new file mode 100644 (file)
index 0000000..861ecb0
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE launch_confirmations ADD COLUMN num INT NOT NULL;
index 8c24d66e79489d5fca2e6fff22f548dd2f0f249b..0751b4040979fc992e90bc0ed6bc2650589a9307 100644 (file)
@@ -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 (?<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;
 }
@@ -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";
        }
 }
 
index 6b06905da79ce00674a3005d8aa45f09884bfe86..41b658d9fa4d9b12e41b73044dce607bdb75f81c 100644 (file)
 <div id="targets">[% PROCESS inc/targetlist.tt2 %]</div>
 [% ELSIF c.check_user_roles("member_menu") %]
        [% IF c.user.planet %]
-       <p><b>Update your fleet to see raids and launch confirmation</b></p>
-<form action="[% c.uri_for('/members/postfleetupdate') %]" method="post">
-       <p>Paste your total fleet from ships section on overview here:</p>
-       <p><textarea rows="5" cols="15" name="fleet"></textarea>
+       <p><b>Update your fleets to see raids and launch confirmation</b></p>
+<form action="[% c.uri_for('/members/postconfirmation') %]" method="post">
+       <p>Paste your fleets from fleets page here:</p>
+       <p><textarea rows="5" cols="15" name="mission"></textarea>
        <br><input type="submit" value="Submit">
        </p>
 </form>
index d3f4ebcc3682ad1045de5c70fd1828c1eff03767..a2ef6fbb653fca5faa277b7a7e08de42cc85bd03 100644 (file)
@@ -152,15 +152,6 @@ CrBs: <input type="checkbox" name="class" value="z"[% IF attackgroups.grep('z').
        </p>
 </fieldset>
 </form>
-[% IF c.user.planet %]
-<form action="[% c.uri_for('postfleetupdate') %]" method="post">
-<fieldset class="forum-post"> <legend>Fleet</legend>
-       <p>Paste your total fleet from ships section on overview here (do it daily to see the menus):</p>
-       <textarea rows="15" cols="50" name="fleet"></textarea>
-       <br><input type="submit" value="Submit">
-</fieldset>
-</form>
-[% END %]
 </div>
 [% IF c.user.planet %]
 <img class="graph" src="[% c.uri_for('/graphs/planetstats',c.user.planet,STICK) %]" alt="stats for your planet" height="300" width="500">
index fd5487d0b5aa5c0be7adf48b26b3c204d0ee8748..04a7770ec363e4e7a6debee09043d7b653ed5ccf 100644 (file)
@@ -3,12 +3,14 @@
 [% 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>