#**************************************************************************/
use strict;
-use POSIX;
+use warnings FATAL => 'all';
our $BODY;
our $DBH;
-our $LOG;
my $error;
$ND::TEMPLATE->param(TITLE => 'Defense Calls');
die "You don't have access" unless isDC();
my $call;
-if (param('call') =~ /^(\d+)$/){
+if (defined param('call') && param('call') =~ /^(\d+)$/){
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
FROM calls c
WHERE c.id = ?});
$call = $DBH->selectrow_hashref($query,undef,$1);
}
-if ($call){
+if ($call && defined param('cmd')){
if (param('cmd') eq 'Submit'){
$DBH->begin_work;
if (param('ctick')){
if ($DBH->do(q{UPDATE calls SET landing_tick = ? WHERE id = ?}
,undef,param('tick'),$call->{id})){
$call->{landing_tick} = param('tick');
- $LOG->execute($ND::UID,"DC updated landing tick for call $call->{id}");
+ log_message $ND::UID,"DC updated landing tick for call $call->{id}";
}else{
$error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
}
if ($DBH->do(q{UPDATE calls SET info = ? WHERE id = ?}
,undef,param('info'),$call->{id})){
$call->{info} = param('info');
- $LOG->execute($ND::UID,"DC updated info for call $call->{id}");
+ log_message $ND::UID,"DC updated info for call $call->{id}";
}else{
$error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
}
for my $param (param()){
if ($param =~ /^change:(\d+)$/){
if($query->execute($1,$call->{id})){
- $LOG->execute($ND::UID,"DC deleted fleet: $1, call $call->{id}");
+ log_message $ND::UID,"DC deleted fleet: $1, call $call->{id}";
}else{
$error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
}
if ($param =~ /^change:(\d+)$/){
my $shiptype = escapeHTML(param("shiptype:$1"));
if($query->execute($shiptype,$1,$call->{id})){
- $LOG->execute($ND::UID,"DC set fleet: $1, call $call->{id} to: $shiptype");
+ log_message $ND::UID,"DC set fleet: $1, call $call->{id} to: $shiptype";
}else{
$error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
}
$BODY->param(Ignore => 'Open');
}
my $fleets = $DBH->prepare(q{
-SELECT id,mission,landing_tick,eta, (landing_tick+eta-1) AS back FROM fleets WHERE uid = ? AND (fleet = 0 OR (landing_tick + eta > ? AND landing_tick - eta - 11 < ? ))
+SELECT id,mission,landing_tick,eta, back FROM fleets WHERE uid = ? AND (fleet = 0 OR (back >= ? AND landing_tick - eta - 11 < ? ))
ORDER BY fleet ASC});
my $ships = $DBH->prepare('SELECT ship,amount FROM fleet_ships WHERE fleet = ?');
$fleets->execute($call->{member},$call->{landing_tick},$call->{landing_tick});
my @fleets;
+ my $i = 0;
while (my $fleet = $fleets->fetchrow_hashref){
if ($fleet->{back} == $call->{landing_tick}){
$fleet->{Fleetcatch} = 1;
$ships->execute($fleet->{id});
my @ships;
while (my $ship = $ships->fetchrow_hashref){
+ $i++;
+ $ship->{ODD} = $i % 2;
push @ships,$ship;
}
$fleet->{Ships} = \@ships;
ORDER BY p.x,p.y,p.z});
$attackers->execute($call->{id});
my @attackers;
+ $i = 0;
while(my $attacker = $attackers->fetchrow_hashref){
+ $i++;
+ $attacker->{ODD} = $i % 2;
push @attackers,$attacker;
}
$BODY->param(Attackers => \@attackers);
}else{
my $where = 'open AND c.landing_tick-6 > tick()';
- if (param('show') eq 'covered'){
- $where = 'covered';
- }elsif (param('show') eq 'all'){
- $where = 'true';
- }elsif (param('show') eq 'uncovered'){
- $where = 'not covered';
+ if (defined param('show')){
+ if (param('show') eq 'covered'){
+ $where = 'covered';
+ }elsif (param('show') eq 'all'){
+ $where = 'true';
+ }elsif (param('show') eq 'uncovered'){
+ $where = 'not covered';
+ }
}
my $pointlimits = $DBH->prepare(q{SELECT value :: int FROM misc WHERE id = ?});
my ($minpoints) = $DBH->selectrow_array($pointlimits,undef,'DEFMIN');
my ($maxpoints) = $DBH->selectrow_array($pointlimits,undef,'DEFMAX');
my $query = $DBH->prepare(qq{
-SELECT c.id, coords(p.x,p.y,p.z), u.defense_points, c.landing_tick,
+SELECT c.id, coords(p.x,p.y,p.z), u.defense_points, c.landing_tick, c.dc,
TRIM('/' FROM concat(p2.race||' /')) AS race, TRIM('/' FROM concat(i.amount||' /')) AS amount,
TRIM('/' FROM concat(i.eta||' /')) AS eta, TRIM('/' FROM concat(i.shiptype||' /')) AS shiptype,
TRIM('/' FROM concat(c.landing_tick - tick() ||' /')) AS curreta,
JOIN current_planet_stats p ON u.planet = p.id
JOIN current_planet_stats p2 ON i.sender = p2.id
WHERE $where
-GROUP BY c.id, p.x,p.y,p.z, u.username, c.landing_tick, c.info,u.defense_points
+GROUP BY c.id, p.x,p.y,p.z, u.username, c.landing_tick, c.info,u.defense_points,c.dc
ORDER BY c.landing_tick DESC
})or $error .= $DBH->errstr;
$query->execute or $error .= $DBH->errstr;
my @calls;
my $i = 0;
+ my $tick = $ND::TICK;
while (my $call = $query->fetchrow_hashref){
if ($call->{defense_points} < $minpoints){
$call->{DefPrio} = 'LowestPrio';
}else{
$call->{DefPrio} = 'HighestPrio';
}
+ while ($tick - 24 > $call->{landing_tick}){
+ $tick -= 24;
+ push @calls,{};
+ $i = 0;
+ }
+ $call->{dc} = 'Hostile' unless defined $call->{dc};
$i++;
$call->{ODD} = $i % 2;
$call->{shiptype} = escapeHTML($call->{shiptype});