X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FMembers.pm;h=19f7a2d128d784baefc8697a24310df0ff0d450d;hb=539c51827d7c3f5a1ed3fbdf09e1e44c21d334cb;hp=f3fdedb0fea609cfe2217d1cf3a2996207f34f03;hpb=15d94c254b3f539cae6e9074e3a34a0ecababfa9;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Members.pm b/lib/NDWeb/Controller/Members.pm index f3fdedb..19f7a2d 100644 --- a/lib/NDWeb/Controller/Members.pm +++ b/lib/NDWeb/Controller/Members.pm @@ -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 =~ /(\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; } @@ -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 'No user with these coords' 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 'Duplicate' 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} = 'Added'; } catch { @@ -492,7 +517,7 @@ WHERE uid = $1 AND num = $2 AND back > tick() }else{ $m->{pid} = $c->user->planet; } - }elsif ($m->{target} =~ /^(\d+):(\d+):(\d+)$/) { + }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."; @@ -554,54 +579,84 @@ 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:\s*(\d+)/sx; + my $missionetare = qr/\s* (\d+ \+ \s*)? (\d+) \s+ + Arrival:\s*(\d+) \s+ + \QReturn ETA:\E\s*(?:(?Instant) \s+ Cancel \s+ Order + | (?\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?\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+ + Ships \s+ Cla \s+ T\s?1 \s+ T\s?2 \s+ T\s?3 \s+ Base \s+ \(i\) \s (?.+?) \s+ \(i\) \s+ (?.+?) \s+ \(i\) \s+ (?.+?) \s+ \(i\) \s+ TOTAL \s+ (?.+?) - \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)*) \W+ - \QLaunch Tick:\E \t (?(\d*\t)*) \W+ - ETA: \t? (?([^\t]+\t?)*) + \QTotal Ships in Fleet\E \s+ (\d+) \s+ (?\d+) \s+ (?\d+) \s+ (?\d+) \s+ + Mission: \s* (?(?:$missre)*) \s* + Target: \s* (?((\d+:\d+:\d+)?\s)*) \s* + \QLaunch Tick:\E \s* (?(\d+\s+)*) \s* + ETA: \s* (?(?:$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; + } + + if ($missions[0] eq 'Alliance Standby'){ + shift @missions; + 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} = $2 + $+{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? '$mission{mission}'" if $mission{mission} ne 'Return'; } } - push @missions,\%mission; + push @slots,\%mission; } - push @missions,{ + push @slots,{ name => 'Main', num => 3, mission => 'Full fleet', @@ -609,18 +664,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 { @@ -630,8 +685,9 @@ sub findDuplicateFleet : Private { my $findfleet = $dbh->prepare(q{ 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 - COALESCE(uid = $1 AND num = $2 AND lc.pid = $5 AND landing_tick = $6, TRUE) +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->{num} ,$m->{mission},$m->{amount}, $m->{pid}, $m->{tick});