]> ruin.nu Git - ndwebbie.git/blobdiff - intel.pl
more fatal warnings and other cleanup
[ndwebbie.git] / intel.pl
index 90498c29dd5307b56cfe8af6e2779956f59f3153..47ef0279a78da81f8e62e6844a1ecd95e15b5399 100644 (file)
--- a/intel.pl
+++ b/intel.pl
@@ -18,7 +18,7 @@
 #**************************************************************************/
 
 use strict;
-use POSIX;
+use warnings FATAL => 'all';
 our $BODY;
 our $DBH;
 our $LOG;
@@ -29,20 +29,22 @@ $ND::TEMPLATE->param(TITLE => 'Intel');
 die "You don't have access" unless isIntel() || isHC();
 
 my $planet;
-if (param('coords') =~ /^(\d+)(?: |:)(\d+)(?: |:)(\d+)$/){
+if (defined param('coords') && param('coords') =~ /^(\d+)(?: |:)(\d+)(?: |:)(\d+)$/){
        my $query = $DBH->prepare(q{SELECT x,y,z,coords(x,y,z),id, nick, alliance,alliance_id, planet_status,channel FROM current_planet_stats
 WHERE  x = ? AND y = ? AND z = ?});
        $planet = $DBH->selectrow_hashref($query,undef,$1,$2,$3);
 }
 
 my $showticks = 'AND (i.tick - i.eta) > (tick() - 48)';
-if (param('show') eq 'all'){
-       $showticks = '';
-}elsif (param('show') =~ /^(\d+)$/){
-       $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
+if (defined param('show')){
+       if (param('show') eq 'all'){
+               $showticks = '';
+       }elsif (param('show') =~ /^(\d+)$/){
+               $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
+       }
 }
 
-if (param('cmd') eq 'coords'){
+if (defined param('cmd') && param('cmd') eq 'coords'){
        my $coords = param('coords');
        $DBH->do(q{CREATE TEMPORARY TABLE coordlist (
        x integer NOT NULL,
@@ -65,7 +67,7 @@ ORDER BY alliance, p.x, p.y, p.z});
        $BODY->param(CoordList => \@planets);
 }
 
-if ($planet){
+if ($planet && defined param('cmd')){
        if (param('cmd') eq 'change'){
                $DBH->begin_work;
                if (param('cnick')){
@@ -126,7 +128,7 @@ if ($planet){
        $BODY->param(Channel => $planet->{channel});
        my @status;
        for my $status (" ","Friendly", "NAP", "Hostile"){
-               push @status,{Status => $status, Selected => $status eq $planet->{planet_status}}
+               push @status,{Status => $status, Selected => defined $planet->{planet_status} && $status eq $planet->{planet_status}}
        }
        $BODY->param(PlanetStatus => \@status);
        my @alliances = alliances($planet->{alliance_id});
@@ -135,7 +137,7 @@ if ($planet){
        my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin',"t.id = ? $showticks"));
        $query->execute($planet->{id}) or $error .= $DBH->errstr;
        my @intellists;
-       my @intel;
+       my @incomings;
        my $i = 0;
        while (my $intel = $query->fetchrow_hashref){
                if ($intel->{ingal}){
@@ -145,14 +147,14 @@ if ($planet){
                }
                $i++;
                $intel->{ODD} = $i % 2;
-               push @intel,$intel;
+               push @incomings,$intel;
        }
-       push @intellists,{Message => 'Incoming fleets', Intel => \@intel, Origin => 1};
+       push @intellists,{Message => 'Incoming fleets', Intel => \@incomings, Origin => 1};
 
-       my $query = $DBH->prepare(intelquery('t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.id = ? $showticks"));
+       $query = $DBH->prepare(intelquery('t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.id = ? $showticks"));
        $query->execute($planet->{id}) or $error .= $DBH->errstr;
-       my @intel;
-       my $i = 0;
+       my @outgoings;
+       $i = 0;
        while (my $intel = $query->fetchrow_hashref){
                if ($intel->{ingal}){
                        $intel->{missionclass} = 'ingal';
@@ -161,9 +163,9 @@ if ($planet){
                }
                $i++;
                $intel->{ODD} = $i % 2;
-               push @intel,$intel;
+               push @outgoings,$intel;
        }
-       push @intellists,{Message => 'Outgoing Fleets', Intel => \@intel, Target => 1};
+       push @intellists,{Message => 'Outgoing Fleets', Intel => \@outgoings, Target => 1};
 
        $BODY->param(IntelLIsts => \@intellists);