X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FMembers.pm;h=6afbb6511d058b02ad5511d087b890515388ea9e;hb=e1450c026acb6bff904eb5a3b893dc5f270ba0a1;hp=8c7f6cbb4c981fee2cf2edd40ab41aa20181b22b;hpb=5f201b31d1ed259f7eec068794b477f886a77bcb;p=ndwebbie.git
diff --git a/lib/NDWeb/Controller/Members.pm b/lib/NDWeb/Controller/Members.pm
index 8c7f6cb..6afbb65 100644
--- a/lib/NDWeb/Controller/Members.pm
+++ b/lib/NDWeb/Controller/Members.pm
@@ -78,19 +78,43 @@ ORDER BY landing_tick DESC
LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $1) ftv ON ftv.ftid = ft.ftid
WHERE ft.fbid = 1
GROUP BY ft.ftid, ft.subject,ft.sticky,u.username
- HAVING count(NULLIF(COALESCE(ft.sticky OR fp.time > ftv.time,TRUE),FALSE)) >= 1
+ HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= 1
ORDER BY sticky DESC,last_post 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 {
my ( $self, $c ) = @_;
my $dbh = $c->model;
+ my $hostname = html_escape $c->req->param('hostname');
$dbh->do(q{UPDATE users SET hostmask = ? WHERE uid = ?
- },undef, html_escape $c->req->param('hostname'), $c->user->id);
+ },undef, $hostname, $c->user->id);
+
+ $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(''));
}
@@ -100,10 +124,11 @@ sub postsmsupdate : Local {
my $dbh = $c->model;
my $callme = $c->req->param('callme') || 0;
+ my $sms = html_escape $c->req->param('sms');
+ my $smsnote = $c->req->param('smsnote');
$dbh->do(q{
UPDATE users SET sms = $1, call_if_needed = $2, sms_note = $3 WHERE uid = $4
- },undef, html_escape $c->req->param('sms'),$callme
- ,$c->req->param('smsnote'), $c->user->id);
+ },undef, $sms, $callme, $smsnote, $c->user->id);
$c->res->redirect($c->uri_for(''));
}
@@ -137,10 +162,11 @@ sub postowncoords : Local {
$c->flash(error => "No planet at coords: $x:$y:$z");
}
}else{
- $c->flash(error => $c->req->param('planet') . " are not valid coords.");
+ my $error = $c->req->param('planet') . " are not valid coords.";
+ $c->flash(error => $error);
}
- $c->res->redirect($c->uri_for(''));
+ $c->res->redirect($c->uri_for('/'.$c->session->{referrer}));
}
sub postfleetsupdates : Local {
@@ -192,17 +218,19 @@ sub postircrequest : Local {
my ( $self, $c ) = @_;
my $dbh = $c->model;
+ my $message = $c->req->param('message');
if ($c->req->param('channel')){
my $query = $dbh->prepare(q{
INSERT INTO irc_requests (uid,channel,message) VALUES($1,$2,$3)
});
- $query->execute($c->user->id,$c->req->param('channel'),$c->req->param('message'));
+ my $channel = $c->user->id,$c->req->param('channel');
+ $query->execute($channel, $message);
$c->signal_bots;
- $c->flash(reply => "Msg sent to: ".$c->req->param('channel'));
+ $c->flash(reply => "Msg sent to: ".$channel);
$c->res->redirect($c->uri_for('ircrequest'));
}else{
- $c->stash(ircmessage => $c->req->param('message'));
+ $c->stash(ircmessage => $message);
$c->go('ircrequest');
}
}
@@ -304,7 +332,8 @@ sub postintelmessage : Local {
SELECT coords(x,y,z), tick() FROM current_planet_stats WHERE pid = $1
}, undef, $c->user->planet);
- $c->req->param(message => "[i]Posted by $coords at tick $tick [/i]\n\n" . $c->req->param('message'));
+ my $message = "[i]Posted by $coords at tick $tick [/i]\n\n" . $c->req->param('message');
+ $c->req->param(message => $message);
$c->forward('/forum/insertThread',[12]);
$c->forward('/forum/insertPost',[$c->stash->{thread}]);
$c->flash(intelmessage => 1);
@@ -330,7 +359,7 @@ sub insertintel : Private {
});
my @scans;
my $intel = $c->req->param('message');
- while ($intel =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\w+)}g){
+ while ($intel =~ m{https?://[\w.]+/.+?scan(_id|_grp)?=(\w+)}g){
my $groupscan = (defined $1 && $1 eq '_grp') || 0;
my %scan;
$scan{id} = $2;
@@ -357,13 +386,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 +436,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 +449,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 {
@@ -482,7 +513,8 @@ 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});
+ my $mission = $c->req->param('mission');
+ my @missions = parseconfirmations($mission, $c->stash->{TICK});
for my $m (@missions){
if ($m->{mission} eq 'Return'){
$c->forward("addReturnFleet", [$m]);
@@ -492,7 +524,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,46 +586,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+ ETA \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 (?\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]*)
+ \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 @targets = split /\s+/, $+{targets};
+ my @lts = split /\s+/, $+{lts};
+ my @etas;
+ local $_ = $+{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],
- target => $match{target}->[$i],
+ mission => '' ,
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){
+ if ($mission{amount} == 0){
+ push @slots,\%mission;
+ next;
+ }
+
+ if ($missions[0] eq 'Alliance Standby'){
+ shift @missions;
+ push @slots,\%mission;
+ next;
+ }
+
+ given(shift @etas){
+ 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',
@@ -601,18 +671,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+((?:\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 {
@@ -622,8 +692,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});