X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FMembers.pm;h=6afbb6511d058b02ad5511d087b890515388ea9e;hb=e1450c026acb6bff904eb5a3b893dc5f270ba0a1;hp=d5b634c5b80d57c682cd30c7ec8df9c1ed658f4a;hpb=8518049dc07ba0554aea4224d6c195bbacd9b8a6;p=ndwebbie.git
diff --git a/lib/NDWeb/Controller/Members.pm b/lib/NDWeb/Controller/Members.pm
index d5b634c..6afbb65 100644
--- a/lib/NDWeb/Controller/Members.pm
+++ b/lib/NDWeb/Controller/Members.pm
@@ -78,7 +78,7 @@ 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);
@@ -95,8 +95,9 @@ 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(''));
}
@@ -123,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(''));
}
@@ -160,56 +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(''));
-}
-
-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(''));
+ $c->res->redirect($c->uri_for('/'.$c->session->{referrer}));
}
sub postfleetsupdates : Local {
@@ -261,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');
}
}
@@ -373,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);
@@ -399,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;
@@ -426,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 $&";
};
@@ -445,6 +405,77 @@ sub insertintel : Private {
$c->flash(scans => \@scans);
}
+sub addincs : Local {
+ my ( $self, $c ) = @_;
+ $c->stash(incs => $c->flash->{incs});
+
+}
+
+sub postincs : Local {
+ my ( $self, $c ) = @_;
+ my $dbh = $c->model;
+
+ my @incs;
+
+ my $user = $dbh->prepare(q{
+SELECT uid FROM users u
+WHERE pid = planetid($1,$2,$3,tick())
+ AND uid IN (SELECT uid FROM groupmembers WHERE gid = 'M')
+ });
+ my $call = $dbh->prepare(q{
+SELECT call
+FROM calls WHERE uid = $1 AND landing_tick = tick() + $2
+ });
+ my $fleet = $dbh->prepare(q{
+SELECT pid
+FROM incomings i
+WHERE pid = planetid($1,$2,$3,tick()) AND amount = $4 and fleet = $5 AND call = $6
+ });
+ my $irc = $dbh->prepare(q{
+INSERT INTO irc_requests (uid,channel,message) VALUES($1,'def',$2)
+ });
+
+ my $msg = $c->req->param('message');
+ 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 = $9;
+ {
+ $amount =~ s/,//g;
+ }
+ try {
+ 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,$10);
+ if ($call){
+ my $pid = $dbh->selectrow_hashref($fleet,undef,$4,$5,$6,$amount,$7,$call);
+ die 'Duplicate' if $pid;
+
+ }
+
+ my $message = "$1:$2:$3 $4:$5:$6 $7 $8 $amount $10";
+ $irc->execute($c->user->id, $message);
+ $inc->{status} = 'Added';
+
+ } catch {
+ when (m(^(.*) at )){
+ $inc->{status} = $1;
+ }
+ default {
+ $inc->{status} = $_;
+ }
+ };
+ push @incs, $inc;
+ }
+
+ $c->signal_bots if @incs;
+ $c->flash(incs => \@incs);
+ $c->res->redirect($c->uri_for('addincs'));
+}
+
sub launchConfirmation : Local {
my ( $self, $c ) = @_;
@@ -457,7 +488,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)
@@ -467,7 +498,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 (?,?,?)
@@ -475,44 +506,70 @@ 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});
+ 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]);
- $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;
@@ -529,46 +586,103 @@ UPDATE launch_confirmations SET back = $2 WHERE fid = $1
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};
+ 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+ 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+ (\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;
}
- $mission{ships} = \@ships;
+ for my $i (0..2){
+ my %mission = (
+ name => $match{name}->[$i],
+ mission => '' ,
+ amount => $match{amount}->[$i],
+ num => $i,
+ ships => []
+ );
+ if ($mission{amount} == 0){
+ push @slots,\%mission;
+ next;
+ }
+
+ if ($missions[0] eq 'Alliance Standby'){
+ shift @missions;
+ push @slots,\%mission;
+ next;
+ }
- if ($mission{amount} == 0){
- warn "No ships in: $ships";
- next;
+ given(shift @etas){
+ when(/$missionetare/sx){
+ $mission{tick} = $3;
+ $mission{eta} = $2 + $+{eta};
+ $mission{back} = $3 + $mission{eta} - 1;
+ $mission{target} = shift @targets;
+ $mission{lt} = shift @lts;
+ $mission{mission} = shift @missions;
+ }
+ 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 @slots,\%mission;
+ }
+ push @slots,{
+ 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+((?:\d+\s*){5})/g){
+ my $ship = $1;
+ my @amounts = split /\D+/, $3;
+ 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 @{$slots[$i]->{ships}},{ship => $ship, amount => $amounts[$i]} if $amounts[$i] > 0;
+ }
+ $slots[3]->{amount} += $amounts[3];
}
- push @missions,\%mission;
}
- return @missions;
+ return @slots;
}
sub findDuplicateFleet : Private {
@@ -577,11 +691,12 @@ 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 (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->{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};
@@ -630,7 +745,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}";
}
}
@@ -641,17 +756,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";
}
}