X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FMembers.pm;h=8c24d66e79489d5fca2e6fff22f548dd2f0f249b;hp=d5b634c5b80d57c682cd30c7ec8df9c1ed658f4a;hb=de167765cdfe5d5203b270e3e31d6dd183b60820;hpb=79f96e8569b30cf0a0ee0cc698acc98ff2d67725 diff --git a/lib/NDWeb/Controller/Members.pm b/lib/NDWeb/Controller/Members.pm index d5b634c..8c24d66 100644 --- a/lib/NDWeb/Controller/Members.pm +++ b/lib/NDWeb/Controller/Members.pm @@ -445,6 +445,75 @@ 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 =~ /(\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){ + + my $inc = {message => $&}; + my $amount = $8; + { + $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,$9); + 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}); + $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 ) = @_;