]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Controller/Members.pm
Parse the new gal status and ally def page formats
[ndwebbie.git] / lib / NDWeb / Controller / Members.pm
index a7f6fb3020622150664e18463df8c12307150e78..e8a7d0e70e3d509b23a62787c5a9c85c502e5e20 100644 (file)
@@ -83,6 +83,12 @@ ORDER BY landing_tick DESC
                });
        $announcements->execute($c->user->id);
        $c->stash(announcements => $announcements->fetchall_arrayref({}) );
+
+       my ($attackgroups) = $dbh->selectrow_array(q{
+SELECT array_agg(gid) FROM groupmembers WHERE gid IN ('x','y','z') AND uid = $1
+               }, undef, $c->user->id);
+       $c->stash(attackgroups => $attackgroups);
+
 }
 
 sub posthostupdate : Local {
@@ -95,6 +101,23 @@ sub posthostupdate : Local {
        $c->res->redirect($c->uri_for(''));
 }
 
+sub postattackgroups : Local {
+       my ( $self, $c ) = @_;
+       my $dbh = $c->model;
+
+       my @groups = $c->req->param('class');
+       $dbh->do(q{DELETE FROM groupmembers WHERE gid IN ('x','y','z') AND gid <> ALL($1) AND uid = $2
+               },undef, \@groups, $c->user->id);
+
+       $dbh->do(q{INSERT INTO groupmembers (uid,gid) (
+               SELECT $2, gid FROM unnest($1::text[]) AS gid WHERE gid IN ('x','y','z')
+       EXCEPT
+               SELECT uid,gid FROM groupmembers WHERE uid = $2
+               )},undef, \@groups, $c->user->id);
+
+       $c->res->redirect($c->uri_for(''));
+}
+
 sub postsmsupdate : Local {
        my ( $self, $c ) = @_;
        my $dbh = $c->model;
@@ -357,13 +380,13 @@ sub insertintel : Private {
        });
        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 $&";
                };
@@ -407,11 +430,12 @@ INSERT INTO irc_requests (uid,channel,message) VALUES($1,'def',$2)
                });
 
        my $msg = $c->req->param('message');
-       while ($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){
+       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;
                }
@@ -419,14 +443,15 @@ INSERT INTO irc_requests (uid,channel,message) VALUES($1,'def',$2)
                        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 {
@@ -554,54 +579,78 @@ WHERE uid = $1 AND num = $2 AND back > tick()
 sub parseconfirmations {
        my ( $missions, $tick ) = @_;
        return unless $missions;
-       my @missions;
-       $missions =~ s/,//g;
+       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:(\d+)/sx;
+       my $missionetare = qr/(\d+) (\s+ \(\+\d+\))? \s+
+               Arrival:(\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/((?:Fake\ )?\w+)\s*/x;
        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 \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?\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?)*)
+               \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 @etas = split /\t/, $+{etas};
-               my @targets = split /\t/, $+{targets};
-               my @lts = split /\t/, $+{lts};
+               my @targets = split /\s+/, $+{targets};
+               my @lts = split /\s+/, $+{lts};
+               my @etas;
+               my $_ = $+{etas};
+               while(/$etare/sxg){
+                       push @etas, $1;
+               }
+               my @missions ;
+               $_ = $+{missions};
+               while(/$missre/sxg){
+                       push @missions, $1;
+               }
                for my $i (0..2){
                        my %mission = (
                                name => $match{name}->[$i],
-                               mission => $match{mission}->[$i],
+                               mission => '' ,
                                amount => $match{amount}->[$i],
                                num => $i,
                                ships => []
                        );
-                       if      ($mission{amount} == 0){
-                               push @missions,\%mission;
+                       if ($mission{amount} == 0){
+                               push @slots,\%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){
+                               when(/$missionetare/sx){
                                        $mission{tick} = $3;
-                                       $mission{eta} = $1 + $4;
+                                       $mission{eta} = $1 + $+{eta};
                                        $mission{back} = $3 + $mission{eta} - 1;
+                                       $mission{target} = shift @targets;
+                                       $mission{lt} = shift @lts;
+                                       $mission{mission} = shift @missions;
                                }
-                               when(/^(\d+) \W+
-                                       Arrival:\ (\d+)/sx){
+                               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?' if $mission{mission} ne 'Return';
                                }
                        }
-                       push @missions,\%mission;
+                       push @slots,\%mission;
                }
-               push @missions,{
+               push @slots,{
                        name => 'Main',
                        num => 3,
                        mission => 'Full fleet',
@@ -609,18 +658,18 @@ sub parseconfirmations {
                        amount => 0,
                        ships => []
                };
-               while ($match{ships}->[0] =~ m/((?:\w+ )*\w+)\s+(FI|CO|FR|DE|CR|BS)[^\d]+([\d\s]+)/g){
+               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 $amount = shift @amounts;
-                       die "Ships don't sum up properly" if $amounts[3] != $amount + $amounts[0] + $amounts[1] + $amounts[2];
+                       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 @{$missions[$i]->{ships}},{ship => $ship, amount => $amounts[$i]} if $amounts[$i] > 0;
+                               push @{$slots[$i]->{ships}},{ship => $ship, amount => $amounts[$i]} if $amounts[$i] > 0;
                        }
-                       $missions[3]->{amount} += $amounts[3];
+                       $slots[3]->{amount} += $amounts[3];
                }
        }
-       return @missions;
+       return @slots;
 }
 
 sub findDuplicateFleet : Private {
@@ -631,7 +680,7 @@ sub findDuplicateFleet : Private {
 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 tick > $6 - 6
+       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->{num}