]> ruin.nu Git - ndwebbie.git/blobdiff - calls.pl
fatal warnings
[ndwebbie.git] / calls.pl
index b5b4374f0b45d3b8b77b608760256905f053ec4c..8aab04a63540aaa10a071b0ea2a604888fd59ca5 100644 (file)
--- a/calls.pl
+++ b/calls.pl
 #**************************************************************************/
 
 use strict;
+use warnings FATAL => 'all';
+no warnings qw(uninitialized);
 use POSIX;
 our $BODY;
 our $DBH;
 our $LOG;
+my $error;
 
 $ND::TEMPLATE->param(TITLE => 'Defense Calls');
 
-die "You don't have access" unless isBC();
+die "You don't have access" unless isDC();
 
 my $call;
 if (param('call') =~ /^(\d+)$/){
@@ -47,7 +50,7 @@ if ($call){
                                $call->{landing_tick} = param('tick');
                                $LOG->execute($ND::UID,"DC updated landing tick for call $call->{id}");
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('cinfo')){
@@ -56,12 +59,12 @@ if ($call){
                                $call->{info} = param('info');
                                $LOG->execute($ND::UID,"DC updated info for call $call->{id}");
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
-               $DBH->commit or print "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
        }elsif(param('cmd') =~ /^(Cover|Uncover|Ignore|Open|Take) call$/){
-               print "test";
+               $error .= "test";
                my $extra_vars = '';
                if (param('cmd') eq 'Cover call'){
                        $extra_vars = ", covered = TRUE, open = FALSE";
@@ -78,7 +81,7 @@ if ($call){
                        $call->{open} = (param('cmd') =~ /^(Uncover|Open) call$/);
                        $call->{DC} = $ND::USER;
                }else{
-                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                }
        }elsif(param('cmd') eq 'Remove'){
                $DBH->begin_work;
@@ -88,11 +91,11 @@ if ($call){
                                if($query->execute($1,$call->{id})){
                                        $LOG->execute($ND::UID,"DC deleted fleet: $1, call $call->{id}");
                                }else{
-                                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                                }
                        }
                }
-               $DBH->commit or print "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
        }elsif(param('cmd') eq 'Change'){
                $DBH->begin_work;
                my $query = $DBH->prepare(q{UPDATE incomings SET shiptype = ? WHERE id = ? AND call = ?});
@@ -102,11 +105,11 @@ if ($call){
                                if($query->execute($shiptype,$1,$call->{id})){
                                        $LOG->execute($ND::UID,"DC set fleet: $1, call $call->{id} to: $shiptype");
                                }else{
-                                       print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                                }
                        }
                }
-               $DBH->commit or print "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
        }
 }
 
@@ -129,11 +132,12 @@ if ($call){
                $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;
@@ -141,6 +145,8 @@ ORDER BY fleet ASC});
                $ships->execute($fleet->{id});
                my @ships;
                while (my $ship = $ships->fetchrow_hashref){
+                       $i++;
+                       $ship->{ODD} = $i % 2;
                        push @ships,$ship;
                }
                $fleet->{Ships} = \@ships;
@@ -156,7 +162,10 @@ WHERE i.call = ?
 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);
@@ -169,30 +178,50 @@ ORDER BY p.x,p.y,p.z});
        }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, 
-       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,
-       TRIM('/' FROM concat(p2.alliance ||'/')) AS alliance,
-       TRIM('/' FROM concat(coords(p2.x,p2.y,p2.z) ||'/')) AS attackers
+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,
+       TRIM('/' FROM concat(p2.alliance ||' /')) AS alliance,
+       TRIM('/' FROM concat(coords(p2.x,p2.y,p2.z) ||' /')) AS attackers
 FROM calls c 
        JOIN incomings i ON i.call = c.id
        JOIN users u ON c.member = u.uid
        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 print $DBH->errstr;
-       $query->execute or print $DBH->errstr;
+               })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';
+               }elsif ($call->{defense_points} < $maxpoints){
+                       $call->{DefPrio} = 'MediumPrio';
+               }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});
                push @calls, $call;
-               $i++;
        }
        $BODY->param(Calls => \@calls);
 }
+$BODY->param(Error => $error);
 1;