]> ruin.nu Git - ndwebbie.git/blobdiff - intel.pl
fatal warnings
[ndwebbie.git] / intel.pl
index d596957149e74e6865c09d08d7e7426dc58d5cc3..5db6f9bdbe1ef9a7fffca368b4fb2324ffb64034 100644 (file)
--- a/intel.pl
+++ b/intel.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 => 'Intel');
 
@@ -73,7 +76,7 @@ if ($planet){
                                        ,undef,$value,$planet->{id})){
                                $planet->{nick} = $value;
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('cchannel')){
@@ -82,7 +85,7 @@ if ($planet){
                                        ,undef,$value,$planet->{id})){
                                $planet->{channel} = $value;
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('cstatus')){
@@ -91,7 +94,7 @@ if ($planet){
                                        ,undef,$value,$planet->{id})){
                                $planet->{planet_status} = $value;
                        }else{
-                               print "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
                        }
                }
                if (param('calliance')){
@@ -99,10 +102,10 @@ if ($planet){
                                        ,undef,param('alliance'),$planet->{id})){
                                $planet->{alliance_id} = param('alliance');
                        }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>";
        }
 }
 
@@ -132,31 +135,37 @@ if ($planet){
        $BODY->param(Alliances => \@alliances);
 
        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 print $DBH->errstr;
+       $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}){
                        $intel->{missionclass} = 'ingal';
                }else{
                        $intel->{missionclass} = $intel->{mission};
                }
-               push @intel,$intel;
+               $i++;
+               $intel->{ODD} = $i % 2;
+               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->execute($planet->{id}) or print $DBH->errstr;
-       my @intel;
+       $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 @outgoings;
+       $i = 0;
        while (my $intel = $query->fetchrow_hashref){
                if ($intel->{ingal}){
                        $intel->{missionclass} = 'ingal';
                }else{
                        $intel->{missionclass} = $intel->{mission};
                }
-               push @intel,$intel;
+               $i++;
+               $intel->{ODD} = $i % 2;
+               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);
 
@@ -166,16 +175,19 @@ if ($planet){
                                OR ( t.alliance_id = o.alliance_id AND i.mission = 'Attack'))
                        AND i.sender NOT IN (SELECT planet FROM users u NATURAL JOIN groupmembers gm WHERE gid = 8 AND planet IS NOT NULL)
                        $showticks}));
-       $query->execute() or print $DBH->errstr;
+       $query->execute() or $error .= $DBH->errstr;
 
        my @intellists;
        my @intel;
+       my $i = 0;
        while (my $intel = $query->fetchrow_hashref){
                if ($intel->{ingal}){
                        $intel->{missionclass} = 'ingal';
                }else{
                        $intel->{missionclass} = $intel->{mission};
                }
+               $i++;
+               $intel->{ODD} = $i % 2;
                push @intel,$intel;
        }
        push @intellists,{Message => q{Intel where alliances doesn't match}, Intel => \@intel, Origin => 1, Target => 1};
@@ -191,4 +203,5 @@ while (my $message = $query->fetchrow_hashref){
        push @messages,$message;
 }
 $BODY->param(IntelMessages => \@messages);
+$BODY->param(Error => $error);
 1;