X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FCalls.pm;h=48eac7eeb1e1406cadc01214e5f65154b32a31c8;hb=25cfbba80f992bd251751782e30cb8c3d57b53d3;hp=7b7e523204019553f2e8fe7065595004ebf93e89;hpb=0dc4622c02076fcd47acc56ad60511b10fb522b9;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Calls.pm b/lib/NDWeb/Controller/Calls.pm index 7b7e523..48eac7e 100644 --- a/lib/NDWeb/Controller/Calls.pm +++ b/lib/NDWeb/Controller/Calls.pm @@ -146,16 +146,31 @@ SELECT ship,amount from ships_home WHERE pid = $1 AND tick = $2 $c->stash(fleets => \@fleets); my $defenders = $dbh->prepare(q{ +WITH lc AS ( + SELECT fid,uid,back,eta,landing_tick + FROM launch_confirmations + WHERE pid = $1 AND landing_tick = $2 +), lcp AS ( + SELECT DISTINCT ON (fid) fid,tick,value + FROM lc + JOIN users u USING (uid) + JOIN planet_stats USING (pid) + WHERE tick <= landing_tick - eta + ORDER BY fid,tick DESC +), lcv AS ( + SELECT fid,(sum(amount*(metal+crystal+eonium)) / value)::int AS value_ratio + FROM lcp + JOIN fleet_ships fs USING (fid) + JOIN ship_stats s USING (ship) + GROUP BY fid, value +) SELECT DISTINCT ON (x,y,z,pid,name,amount,back) fid,mission, name, eta , amount, coords(x,y,z) AS coords, landing_tick AS tick, pid AS planet - ,back, (back <> landing_tick + eta - 1) AS recalled + ,back, (back <> landing_tick + eta - 1) AS recalled, value_ratio FROM fleets f LEFT OUTER JOIN current_planet_stats s USING (pid) - JOIN ( - SELECT fid,back,eta,landing_tick - FROM launch_confirmations - WHERE pid = $1 AND landing_tick = $2 - ) lc USING (fid) + JOIN lc USING (fid) + JOIN lcv USING (fid) WHERE mission IN ('Defend', 'Fake Defend') ORDER BY x,y,z }); @@ -253,13 +268,15 @@ sub postcallupdate : Local { if ($c->req->param('cmd') eq 'Submit'){ my $logmess = ''; if ($c->req->param('ctick')){ + my $tick = $c->req->param('tick'); $dbh->do(q{UPDATE calls SET landing_tick = ? WHERE call = ?} - ,undef,$c->req->param('tick'),$call->{call}); + ,undef,$tick,$call->{call}); $logmess .= "Updated landing tick from [B] $call->{landing_tick} [/B]\n"; } if ($c->req->param('cinfo')){ + my $info = $c->req->param('info'); $dbh->do(q{UPDATE calls SET info = ? WHERE call = ?} - ,undef,$c->req->param('info'),$call->{call}); + ,undef,$info,$call->{call}); $logmess .= "Updated info\n"; } if ($c->req->param('ccalc')){ @@ -269,8 +286,9 @@ sub postcallupdate : Local { $logmess .= html_escape('Updated calc to: [URL]'.$calc."[/URL]\n"); } if ($c->req->param('cstatus')){ + my $status = $c->req->param('status'); $dbh->do(q{UPDATE calls SET status = $1, dc = $2 WHERE call = $3} - ,undef,$c->req->param('status'),$c->user->id,$call->{call}); + ,undef,$status,$c->user->id,$call->{call}); $logmess .= "Changed status to: ".$c->req->param('status')."\n"; } $log->execute($c->user->id,$call->{ftid},$logmess) if $log;