X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FCalls.pm;h=4033e5c06f6111a78ec04bde4b8847afef7edfc5;hb=2a703f7250ea25f2f556eb25b644dcb7268f92ce;hp=d3a44e301eb3c1c0418975ed588c71e6d92f87df;hpb=0bf0cd98e5e467bd8608a478b204d7e2ae0fcaa6;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Calls.pm b/lib/NDWeb/Controller/Calls.pm index d3a44e3..4033e5c 100644 --- a/lib/NDWeb/Controller/Calls.pm +++ b/lib/NDWeb/Controller/Calls.pm @@ -68,15 +68,15 @@ sub list : Local { ,u.defense_points, u.attack_points, c.landing_tick ,dc.username AS dc, (c.landing_tick - tick()) AS curreta ,p2.race, i.amount, i.eta, i.shiptype, p2.alliance - ,coords(p2.x,p2.y,p2.z), COUNT(DISTINCT f.id) AS fleets + ,coords(p2.x,p2.y,p2.z), COUNT(DISTINCT f.fid) AS fleets FROM calls c JOIN users u ON c.member = u.uid JOIN current_planet_stats p ON u.planet = p.id LEFT OUTER JOIN incomings i ON i.call = c.id LEFT OUTER JOIN current_planet_stats p2 ON i.sender = p2.id LEFT OUTER JOIN users dc ON c.dc = dc.uid - LEFT OUTER JOIN fleets f ON f.target = u.planet - AND f.tick = c.landing_tick AND f.back = f.tick + f.eta - 1 + LEFT OUTER JOIN launch_confirmations f ON f.target = u.planet + AND f.landing_tick = c.landing_tick AND f.back = f.landing_tick + f.eta - 1 WHERE $where GROUP BY c.id, p.x,p.y,p.z,p.id, p.size, p.score, p.value, c.landing_tick ,u.defense_points,u.attack_points,dc.username @@ -113,18 +113,38 @@ sub edit : Local { my $outgoings = $dbh->prepare(q{ - SELECT i.id,i.mission, i.name, i.tick,eta - , i.amount, coords(x,y,z) AS coords, t.id AS planet - FROM fleets i - LEFT OUTER JOIN (planets - NATURAL JOIN planet_stats) t ON i.target = t.id - AND t.tick = ( SELECT MAX(tick) FROM planet_stats) - WHERE i.sender = $1 - AND (i.tick > $2 - 14 OR i.mission = 'Full fleet') - ORDER BY i.tick,x,y,z +( + SELECT DISTINCT ON (mission,name) fid,mission,name,tick, NULL AS eta + ,amount, NULL AS coords, planet, NULL AS back, NULL AS recalled + FROM fleets f + WHERE planet = $1 AND tick <= $2 AND ( + mission = 'Full fleet' + OR fid IN (SELECT fid FROM fleet_scans) + ) AND ( + mission = 'Full fleet' + OR tick >= $2 - 12 + ) + ORDER BY mission,name,tick DESC +) UNION ( + SELECT fid,mission,name,landing_tick AS tick, eta, amount + , coords(x,y,z), t.id AS planet, back + , (back <> landing_tick + eta - 1) AS recalled + FROM fleets f + JOIN launch_confirmations USING (fid) + LEFT OUTER JOIN current_planet_stats t ON target = t.id + WHERE f.planet = $1 AND back >= $2 AND landing_tick - eta - 12 < $2 +) UNION ( + SELECT DISTINCT ON (tick,x,y,z,mission,name,amount) + NULL as fid, i.mission, i.name, i.tick,eta + , i.amount, coords(x,y,z), t.id AS planet, back, NULL AS recalled + FROM intel i + LEFT OUTER JOIN current_planet_stats t ON i.target = t.id + WHERE uid = -1 AND i.sender = $1 AND i.tick > $2 - 14 AND i.tick < $2 + 14 + ORDER BY i.tick,x,y,z,mission,name,amount,back +) }); my $ships = $dbh->prepare(q{SELECT ship,amount FROM fleet_ships - WHERE id = ? ORDER BY num + WHERE fid = ? ORDER BY num }); $outgoings->execute($call->{planet},$call->{landing_tick}); my @fleets; @@ -133,34 +153,44 @@ sub edit : Local { $fleet->{back} == $call->{landing_tick}){ $fleet->{fleetcatch} = 1; } - $ships->execute($fleet->{id}); - if ($ships->rows != 0){ + if ($fleet->{fid}){ + $ships->execute($fleet->{fid}); my @ships; while (my $ship = $ships->fetchrow_hashref){ push @ships,$ship; } + push @ships, {ship => 'No', amount => 'ships'} if @ships == 0; $fleet->{ships} = \@ships; } push @fleets, $fleet; } + + my $available = $dbh->prepare(q{ +SELECT ship,amount from ships_home WHERE planet = $1 AND tick = $2 + }); + $available->execute($call->{planet}, $call->{landing_tick}); + my $fleet = {fid => $call->{member}, mission => 'Available' + , name => 'At home', ships => $available->fetchall_arrayref({}) + }; + push @fleets, $fleet; + $c->stash(fleets => \@fleets); my $defenders = $dbh->prepare(q{ - SELECT DISTINCT ON (i.tick,x,y,z,s.id,i.name,i.amount) i.id,i.mission, i.name, i.tick,eta - , i.amount, coords(x,y,z) AS coords, s.id AS planet - FROM fleets i - LEFT OUTER JOIN (planets - NATURAL JOIN planet_stats) s ON i.sender = s.id - AND s.tick = ( SELECT MAX(tick) FROM planet_stats) - WHERE i.target = ? - AND i.tick = ? AND i.mission = 'Defend' - ORDER BY i.tick,x,y,z +SELECT DISTINCT ON (x,y,z,s.id,name,amount,back) fid,mission, name, eta + , amount, coords(x,y,z) AS coords, landing_tick AS tick, f.planet + ,back, (back <> landing_tick + eta - 1) AS recalled +FROM launch_confirmations lc + JOIN fleets f USING (fid) + LEFT OUTER JOIN current_planet_stats s ON f.planet = s.id +WHERE target = ? AND landing_tick = ? AND mission = 'Defend' +ORDER BY x,y,z }); $defenders->execute($call->{planet},$call->{landing_tick}); my @defenders; while (my $fleet = $defenders->fetchrow_hashref){ - $ships->execute($fleet->{id}); + $ships->execute($fleet->{fid}); if ($ships->rows != 0){ my @ships; while (my $ship = $ships->fetchrow_hashref){ @@ -186,8 +216,8 @@ sub edit : Local { $outgoings->execute($attacker->{planet},$call->{landing_tick}); my @missions; while (my $mission = $outgoings->fetchrow_hashref){ - $ships->execute($mission->{id}); - if ($ships->rows != 0){ + if ($mission->{fid}){ + $ships->execute($mission->{fid}); my @ships; while (my $ship = $ships->fetchrow_hashref){ push @ships,$ship; @@ -211,13 +241,14 @@ sub defleeches : Local { my $query = $dbh->prepare(q{SELECT username,defense_points,count(id) AS calls , SUM(fleets) AS fleets, SUM(recalled) AS recalled + ,count(NULLIF(fleets,0)) AS defended_calls FROM (SELECT username,defense_points,c.id,count(f.target) AS fleets - , count(NULLIF(f.tick + f.eta -1 = f.back,TRUE)) AS recalled + , count(NULLIF(f.landing_tick + f.eta -1 = f.back,TRUE)) AS recalled FROM users u JOIN calls c ON c.member = u.uid - LEFT OUTER JOIN fleets f ON u.planet = f.target - AND c.landing_tick = f.tick - WHERE (f.mission = 'Defend' AND f.uid > 0 AND f.back IS NOT NULL AND NOT ingal) - OR f.target IS NULL + LEFT OUTER JOIN ( + SELECT * FROM launch_confirmations JOIN fleets USING (fid) + WHERE mission = 'Defend' + ) f ON u.planet = f.target AND c.landing_tick = f.landing_tick GROUP BY username,defense_points,c.id ) d GROUP BY username,defense_points ORDER BY fleets DESC, defense_points @@ -261,6 +292,12 @@ sub postcallupdate : Local { ,undef,$c->req->param('info'),$call->{id}); $log->execute($c->user->id,$call->{ftid},"Updated info"); } + if ($c->req->param('ccalc')){ + my $calc = $c->req->param('calc'); + $dbh->do(q{UPDATE calls SET calc = ? WHERE id = ?} + ,undef,$calc,$call->{id}); + $log->execute($c->user->id,$call->{ftid},html_escape('Updated calc to: [URL]'.$calc.'[/URL]')); + } }elsif($c->req->param('cmd') =~ /^(Cover|Uncover|Ignore|Open|Take) call$/){ my $extra_vars = ''; if ($1 eq 'Cover'){ @@ -331,7 +368,7 @@ sub findCall : Private { my $query = $dbh->prepare(q{ SELECT c.id, coords(p.x,p.y,p.z), c.landing_tick, c.info, covered ,open, dc.username AS dc, u.defense_points,c.member AS uid - ,u.planet, u.username AS member, u.sms,c.ftid + ,u.planet, u.username AS member, u.sms,c.ftid,calc FROM calls c JOIN users u ON c.member = u.uid LEFT OUTER JOIN users dc ON c.dc = dc.uid