]> ruin.nu Git - ndwebbie.git/commitdiff
big restructure
authorMichael Andreen <harv@ruin.nu>
Sun, 7 Jan 2007 19:44:37 +0000 (19:44 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 7 Jan 2007 19:44:37 +0000 (19:44 +0000)
41 files changed:
ND.pm
ND/Web/Pages/AddIntel.pm [new file with mode: 0644]
ND/Web/Pages/Alliances.pm [new file with mode: 0644]
ND/Web/Pages/Calls.pm [new file with mode: 0644]
ND/Web/Pages/Check.pm [new file with mode: 0644]
ND/Web/Pages/CovOp.pm [new file with mode: 0644]
ND/Web/Pages/DefRequest.pm [new file with mode: 0644]
ND/Web/Pages/EditRaid.pm [new file with mode: 0644]
ND/Web/Pages/Forum.pm [new file with mode: 0644]
ND/Web/Pages/Intel.pm [new file with mode: 0644]
ND/Web/Pages/LaunchConfirmation.pm [new file with mode: 0644]
ND/Web/Pages/Main.pm [new file with mode: 0644]
ND/Web/Pages/MemberIntel.pm [new file with mode: 0644]
ND/Web/Pages/Motd.pm [new file with mode: 0644]
ND/Web/Pages/PlanetNaps.pm [new file with mode: 0644]
ND/Web/Pages/Points.pm [new file with mode: 0644]
ND/Web/Pages/Raids.pm [new file with mode: 0644]
ND/Web/Pages/Resources.pm [new file with mode: 0644]
ND/Web/Pages/Top100.pm [new file with mode: 0644]
ND/Web/Pages/Users.pm [new file with mode: 0644]
addintel.pl [deleted file]
alliances.pl [deleted file]
calls.pl [deleted file]
check.pl [deleted file]
covop.pl [deleted file]
defrequest.pl [deleted file]
editRaid.pl [deleted file]
forum.pl [deleted file]
intel.pl [deleted file]
launchConfirmation.pl [deleted file]
main.pl [deleted file]
memberIntel.pl [deleted file]
motd.pl [deleted file]
pages [deleted file]
planetNaps.pl [deleted file]
points.pl [deleted file]
raids.pl [deleted file]
resources.pl [deleted file]
startup.pl
top100.pl [deleted file]
users.pl [deleted file]

diff --git a/ND.pm b/ND.pm
index e95198a8898fbc709b1a595fe9b87f6b85834531..dd017f3a4201c73c8a579373ace4d9446e0d1eb1 100755 (executable)
--- a/ND.pm
+++ b/ND.pm
@@ -31,6 +31,9 @@ use Fcntl 'O_RDONLY';
 use strict;
 use warnings FATAL => 'all';
 
+chdir '/var/www/ndawn/code';
+our %PAGES;
+our $NOACCESS = HTML::Template->new(filename => 'templates/NoAccess.tmpl', global_vars => 1, cache => 1);
 
 sub handler {
        local $ND::r = shift;
@@ -49,15 +52,16 @@ sub handler {
        if ($ENV{'SCRIPT_NAME'} =~ /(\w+)(\.(pl|php|pm))?$/){
                $ND::PAGE = $1 unless $1 eq 'index' and $3 eq 'pl';
        }
-       if ($ENV{REQUEST_URI} =~ m{^.*/(\w+)$}){
-               param($1,1);
-       }
-       $ND::PAGE = '' unless defined $ND::PAGE;
-       page();
+       $ND::PAGE = 'main' unless exists $PAGES{$ND::PAGE};
+
+       $PAGES{$ND::PAGE}->{parse}->($ENV{REQUEST_URI});
+
+       page($ND::PAGE);
        return Apache2::Const::OK;
 }
 
 sub page {
+       my ($PAGE) = @_;
        our $DBH = ND::DB::DB();
        $DBH->do(q{SET timezone = 'GMT'});
 
@@ -84,14 +88,11 @@ sub page {
                $ATTACKER = 1 if $attack;
        }
 
-       tie my @pages, 'Tie::File', "/var/www/ndawn/code/pages", mode => O_RDONLY, memory => 0 or die $!;
-       $ND::PAGE = 'main' unless grep { /^$ND::PAGE$/ } @pages;
-
        our $XML = 0;
-       $XML = 1 if param('xml') and $ND::PAGE =~ /^(raids)$/;
-
        our $AJAX = 1;
 
+       $PAGES{$PAGE}->{process}->();
+
        my $type = 'text/html';
        if ($XML){
                $type = 'text/xml';
@@ -102,11 +103,7 @@ sub page {
                $ND::BODY->param(PAGE => '/'.$ND::PAGE);
        }
 
-       unless (my $return = do "$ND::PAGE.pl"){
-               $ERROR .= "<p><b>couldn't parse $ND::PAGE: $@</b></p>" if $@;
-               $ERROR .= "<p><b>couldn't do $ND::PAGE: $!</b></p>"    unless defined $return && defined $!;
-               $ERROR .= "<p><b>couldn't run $ND::PAGE</b></p>"       unless $return;
-       }
+       $ND::BODY = $PAGES{$PAGE}->{render}->($DBH,$ND::BODY);
 
        unless ($XML){
                my $fleetupdate = $DBH->selectrow_array('SELECT landing_tick FROM fleets WHERE uid = ? AND fleet = 0',undef,$UID);
diff --git a/ND/Web/Pages/AddIntel.pm b/ND/Web/Pages/AddIntel.pm
new file mode 100644 (file)
index 0000000..8c03a02
--- /dev/null
@@ -0,0 +1,94 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::AddIntel;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Forum;
+use ND::Web::Include;
+
+$ND::PAGES{addintel} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       $ND::TEMPLATE->param(TITLE => 'Add Intel and Scans');
+
+       my $error;
+
+       return $ND::NOACCESS unless isMember();
+
+       if (defined param('cmd')){
+               if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
+                       my $findscan = $DBH->prepare("SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 48");
+                       my $addscan = $DBH->prepare('INSERT INTO scans (scan_id,tick,"type") VALUES (?,tick(),?)');
+                       my $addpoint = $DBH->prepare('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ');
+                       my $intel = param('intel');
+                       my @scans;
+                       while ($intel =~ m/http:\/\/game.planetarion.com\/showscan.pl\?scan_id=(\d+)/g){
+                               my %scan;
+                               $scan{Scan} = $1;
+                               $scan{Message} = "Scan $1: ";
+                               $findscan->execute($1);
+                               if ($findscan->rows == 0){
+                                       if ($addscan->execute($1,$ND::UID)){
+                                               $addpoint->execute($ND::UID);
+                                               $scan{Message} .= '<i>added</i>';
+                                       }else{
+                                               $scan{Message} .= "<b>something went wrong:</b> <i>$DBH->errstr</i>";
+                                       }
+                               }else{
+                                       $scan{Message} .= '<b>already exists</b>';
+                               }
+                               push @scans,\%scan;
+                       }
+                       $BODY->param(Scans => \@scans);
+                       my $tick = $ND::TICK;
+                       $tick = param('tick') if $tick =~ /^(\d+)$/;
+                       my $addintel = $DBH->prepare(qq{SELECT add_intel(?,?,?,?,?,?,?,?,?,?,?)});
+                       while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\*?\s+.+(?:Ter|Cat|Xan|Zik)?\s+(\d+)\s+(Attack|Defend)\s+(\d+)/g){
+                               $addintel->execute($tick,$9, $1,$2,$3,$4,$5,$6,$7,$8,$ND::UID) or $error .= $DBH->errstr;
+                       }
+               }
+               if (param('cmd') eq 'submit_message'){
+                       my $board = {id => 12};
+                       my $subject = param('subject');
+                       unless ($subject){
+                               if (param('intel') =~ /(.*\w.*)/){
+                                       $subject = $1;
+                               }
+
+                       }
+                       if (my $thread = addForumThread $DBH,$board,$ND::UID,$subject){
+                               $error .= p 'Intel message added' if addForumPost $DBH,$thread,$ND::UID,param('intel')
+                       }
+               }
+       }
+       $BODY->param(Tick => $ND::TICK);
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+1;
diff --git a/ND/Web/Pages/Alliances.pm b/ND/Web/Pages/Alliances.pm
new file mode 100644 (file)
index 0000000..aec9ea4
--- /dev/null
@@ -0,0 +1,162 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Alliances;
+use strict;
+use warnings FATAL => 'all';
+use ND::Include;
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{alliances} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       my $error;
+
+       $ND::TEMPLATE->param(TITLE => 'Alliances');
+
+       return $ND::NOACCESS unless isHC();
+
+       my $alliance;
+       if (defined param('alliance') && param('alliance') =~ /^(\d+)$/){
+               my $query = $DBH->prepare(q{SELECT id,name, relationship FROM alliances WHERE id = ?});
+               $alliance = $DBH->selectrow_hashref($query,undef,$1);
+       }
+       if ($alliance && defined param('cmd') && param ('cmd') eq 'change'){
+               $DBH->begin_work;
+               if (param('crelationship')){
+                       my $value = escapeHTML(param('relationship'));
+                       if ($DBH->do(q{UPDATE alliances SET relationship = ? WHERE id =?}
+                                       ,undef,$value,$alliance->{id})){
+                               $alliance->{relationship} = $value;
+                               log_message $ND::UID,"HC set alliance: $alliance->{id} relationship: $value";
+                       }else{
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       }
+               }
+               my $coords = param('coords');
+               my $findplanet = $DBH->prepare(q{SELECT id FROM current_planet_stats WHERE x = ? AND y = ? AND z = ?});
+               my $addplanet = $DBH->prepare(q{
+                       UPDATE planets SET alliance_id = $2, nick = coalesce($3,nick)
+                       WHERE id = $1;
+                       });
+               while ($coords =~ m/(\d+):(\d+):(\d+)(?:\s+nick=\s*(\S+))?/g){
+                       my ($id) = $DBH->selectrow_array($findplanet,undef,$1,$2,$3) or $ND::ERROR .= p $DBH->errstr;
+                       if ($addplanet->execute($id,$alliance->{id},$4)){
+                               my $nick = '';
+                               $nick = '(nick $4)' if defined $4;
+                               $error .= "<p> Added planet $1:$2:$3 $nick to this alliance</p>";
+                               intel_log $ND::UID,$id,"HC Added planet $1:$2:$3 $nick to alliance: $alliance->{id} ($alliance->{name})";
+                       }else{
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       }
+               }
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+       }
+
+       if ($alliance){
+               $BODY->param(Alliance => $alliance->{name});
+               $BODY->param(Id => $alliance->{id});
+               my @relationships;
+               for my $relationship ("&nbsp;","Friendly", "NAP", "Hostile"){
+                       push @relationships,{Rel => $relationship, Selected => defined $alliance->{relationship} && $relationship eq $alliance->{relationship}}
+               }
+               $BODY->param(Relationships => \@relationships);
+
+               my $order = "p.x,p.y,p.z";
+               if (defined param('order') && param('order') =~ /^(score|size|value|xp|hit_us|race)$/){
+                       $order = "$1 DESC";
+               }
+               my $members = $DBH->prepare(qq{
+                       SELECT coords(x,y,z), nick, ruler, planet, race, size, score, value, xp,
+                       planet_status,hit_us, sizerank, scorerank, valuerank, xprank
+                       FROM current_planet_stats p
+                       WHERE p.alliance_id = ?
+                       ORDER BY $order});
+               my @members;
+               $members->execute($alliance->{id});
+               my $i = 0;
+               while (my $member = $members->fetchrow_hashref){
+                       $i++;
+                       $member->{ODD} = $i % 2;
+                       push @members,$member;
+               }
+               $BODY->param(Members => \@members);
+
+               my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin, t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',qq{not ingal AND (t.alliance_id = ? OR t.alliance_id = ?)
+                               AND (i.mission = 'Defend' OR i.mission = 'AllyDef')
+                               AND (t.alliance_id != ? OR t.alliance_id IS NULL OR o.alliance_id != ? OR o.alliance_id IS NULL)
+                               AND i.sender NOT IN (SELECT planet FROM users u NATURAL JOIN groupmembers gm WHERE gid = 8 AND planet IS NOT NULL)
+                               }));
+               $query->execute($alliance->{id},$alliance->{id},$alliance->{id},$alliance->{id}) or $error .= $DBH->errstr;
+
+               my @intel;
+               $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;
+               }
+               $BODY->param(Intel => \@intel);
+       }else{
+
+               my $order = "score DESC";
+               if (defined param('order') && param('order') =~ /^(score|kscore|size|ksize|members|kmem|kxp|kxp|scavg|kscavg|siavg|ksiavg|kxpavg|kvalue|kvalavg)$/){
+                       $order = "$1 DESC";
+               }
+               my $query = $DBH->prepare(qq{
+                       SELECT DISTINCT a.id,name,COALESCE(s.score,SUM(p.score)) AS score,COALESCE(s.size,SUM(p.size)) AS size,s.members,count(*) AS kmem,
+                       COALESCE(SUM(p.score),-1) AS kscore, COALESCE(SUM(p.size),-1) AS ksize, COALESCE(SUM(p.xp),-1) AS kxp,COALESCE(SUM(p.value),-1) AS kvalue,
+                       COALESCE(s.score/LEAST(s.members,60),-1) AS scavg, COALESCE(AVG(p.score)::int,-1) AS kscavg, COALESCE(s.size/s.members,-1) AS siavg,
+                       COALESCE(AVG(p.size)::int,-1) AS ksiavg, COALESCE(AVG(p.xp)::int,-1) AS kxpavg, COALESCE(AVG(p.value)::int,-1) AS kvalavg
+                       FROM alliances a 
+                       LEFT OUTER JOIN (SELECT * FROM alliance_stats WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON s.id = a.id
+                       LEFT OUTER JOIN current_planet_stats p ON p.alliance_id = a.id
+                       GROUP BY a.id,a.name,s.score,s.size,s.members
+                       ORDER BY $order
+                       })or $error .= $DBH->errstr;
+               $query->execute or $error .= $DBH->errstr;
+               my @alliances;
+               my $i = 0;
+               while (my $alliance = $query->fetchrow_hashref){
+                       next unless (defined $alliance->{score} || $alliance->{kscore} > 0);
+                       $i++;
+                       $alliance->{ODD} = $i % 2;
+                       push @alliances, $alliance;
+               }
+               $BODY->param(Alliances => \@alliances);
+       }
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+1;
diff --git a/ND/Web/Pages/Calls.pm b/ND/Web/Pages/Calls.pm
new file mode 100644 (file)
index 0000000..208b1a9
--- /dev/null
@@ -0,0 +1,245 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+package ND::Web::Pages::Calls;
+use strict;
+use warnings FATAL => 'all';
+use ND::Include;
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{calls} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       #if ($uri =~ m{^/.*/(\w+)$}){
+       #       param('list',$1);
+       #}
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       my $error;
+
+       $ND::TEMPLATE->param(TITLE => 'Defense Calls');
+
+       return $ND::NOACCESS unless isDC();
+
+       my $call;
+       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 
+                       JOIN users u ON c.member = u.uid
+                       LEFT OUTER JOIN users dc ON c.dc = dc.uid
+                       JOIN current_planet_stats p ON u.planet = p.id
+                       WHERE c.id = ?});
+               $call = $DBH->selectrow_hashref($query,undef,$1);
+       }
+       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_message $ND::UID,"DC updated landing tick for call $call->{id}";
+                               }else{
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+                       if (param('cinfo')){
+                               if ($DBH->do(q{UPDATE calls SET info = ? WHERE id = ?}
+                                               ,undef,param('info'),$call->{id})){
+                                       $call->{info} = param('info');
+                                       log_message $ND::UID,"DC updated info for call $call->{id}";
+                               }else{
+                                       $error .= "<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$/){
+                       $error .= "test";
+                       my $extra_vars = '';
+                       if (param('cmd') eq 'Cover call'){
+                               $extra_vars = ", covered = TRUE, open = FALSE";
+                       }elsif (param('cmd') eq 'Uncover call'){
+                               $extra_vars = ", covered = FALSE, open = TRUE";
+                       }elsif (param('cmd') eq 'Ignore call'){
+                               $extra_vars = ", covered = FALSE, open = FALSE";
+                       }elsif (param('cmd') eq 'Open call'){
+                               $extra_vars = ", covered = FALSE, open = TRUE";
+                       }
+                       if ($DBH->do(qq{UPDATE calls SET dc = ? $extra_vars WHERE id = ?},
+                                       ,undef,$ND::UID,$call->{id})){
+                               $call->{covered} = (param('cmd') eq 'Cover call');
+                               $call->{open} = (param('cmd') =~ /^(Uncover|Open) call$/);
+                               $call->{DC} = $ND::USER;
+                       }else{
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       }
+               }elsif(param('cmd') eq 'Remove'){
+                       $DBH->begin_work;
+                       my $query = $DBH->prepare(q{DELETE FROM incomings WHERE id = ? AND call = ?});
+                       for my $param (param()){
+                               if ($param =~ /^change:(\d+)$/){
+                                       if($query->execute($1,$call->{id})){
+                                               log_message $ND::UID,"DC deleted fleet: $1, call $call->{id}";
+                                       }else{
+                                               $error .= "<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 = ?});
+                       for my $param (param()){
+                               if ($param =~ /^change:(\d+)$/){
+                                       my $shiptype = escapeHTML(param("shiptype:$1"));
+                                       if($query->execute($shiptype,$1,$call->{id})){
+                                               log_message $ND::UID,"DC set fleet: $1, call $call->{id} to: $shiptype";
+                                       }else{
+                                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       }
+                               }
+                       }
+                       $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+               }
+       }
+
+       if ($call){
+               $BODY->param(Call => $call->{id});
+               $BODY->param(Coords => $call->{coords});
+               $BODY->param(DefensePoints => $call->{defense_points});
+               $BODY->param(LandingTick => $call->{landing_tick});
+               $BODY->param(ETA => $call->{landing_tick}-$ND::TICK);
+               $BODY->param(Info => $call->{info});
+               $BODY->param(DC => $call->{dc});
+               if ($call->{covered}){
+                       $BODY->param(Cover => 'Uncover');
+               }else{
+                       $BODY->param(Cover => 'Cover');
+               }
+               if ($call->{open} && !$call->{covered}){
+                       $BODY->param(Ignore => 'Ignore');
+               }else{
+                       $BODY->param(Ignore => 'Open');
+               }
+               my $fleets = $DBH->prepare(q{
+                       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;
+                       push @fleets, $fleet;
+               }
+               $BODY->param(Fleets => \@fleets);
+
+               my $attackers = $DBH->prepare(q{
+                       SELECT coords(p.x,p.y,p.z), p.planet_status, p.race,i.eta,i.amount,i.fleet,i.shiptype,p.relationship,p.alliance,i.id
+                       FROM incomings i
+                       JOIN current_planet_stats p ON i.sender = p.id
+                       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);
+       }else{
+               my $where = 'open AND c.landing_tick-6 > tick()';
+               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, 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,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';
+                       }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;
+               }
+               $BODY->param(Calls => \@calls);
+       }
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+1;
diff --git a/ND/Web/Pages/Check.pm b/ND/Web/Pages/Check.pm
new file mode 100644 (file)
index 0000000..60600bb
--- /dev/null
@@ -0,0 +1,201 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Check;
+use strict;
+use warnings FATAL => 'all';
+no warnings qw(uninitialized);
+use ND::Include;
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{check} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       #TODO: Improved apache conf needed
+       #if ($uri =~ m{^/.*/((\d+)(?: |:)(\d+)(?:(?: |:)(\d+))?(?: |:(\d+))?)$}){
+       #       param('coords',$1);
+       #}
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       $ND::TEMPLATE->param(TITLE => 'Check planets and galaxies');
+
+       $BODY->param(isBC => isMember() && (isOfficer() || isBC));
+
+       return $ND::NOACCESS unless $ND::ATTACKER;
+
+       my ($x,$y,$z);
+       if (param('coords') =~ /(\d+)(?: |:)(\d+)(?:(?: |:)(\d+))?(?: |:(\d+))?/){
+               $x = $1;
+               $y = $2;
+               $z = $3;
+               $BODY->param(Coords => param('coords'));
+       }else{
+               $ND::ERROR .= p b q{Couldn't parse coords};
+               return $BODY;
+       }
+
+       if (isMember() && param('cmd') eq 'arbiter'){
+               my $query = $DBH->prepare(q{SELECT count(*) AS friendlies FROM current_planet_stats WHERE x = ? AND y = ? 
+                       AND (planet_status IN ('Friendly','NAP') OR relationship IN ('Friendly','NAP'))});
+               my ($count) = $DBH->selectrow_array($query,undef,$x,$y);
+               if ($count > 0){
+                       $BODY->param(Arbiter => '<b>DO NOT ATTACK THIS GAL</b>');
+               }else{
+                       $BODY->param(Arbiter => '<b>KILL THESE BASTARDS</b>');
+               }
+               log_message $ND::UID,"Arbiter check on $x:$y";
+       }
+
+       my $where = '';
+       my $extra_columns = '';
+
+       $where = 'AND z = ?' if defined $z;
+       if (isMember() && isOfficer()){
+               $extra_columns = ",planet_status,hit_us, alliance,relationship,nick";
+       }elsif (isMember() && isBC()){
+               $extra_columns = ", planet_status,hit_us, alliance,relationship";
+       }
+
+       my $query = $DBH->prepare(qq{Select id,coords(x,y,z), ((ruler || ' OF ') || p.planet) as planet,race, size, score, value, xp, sizerank, scorerank, valuerank, xprank, p.value - p.size*200 - coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue  $extra_columns from current_planet_stats p LEFT OUTER JOIN covop_targets c ON p.id = c.planet where x = ? AND y = ? $where order by x,y,z asc});
+
+       if (defined $z){
+               $query->execute($x,$y,$z);
+       }else{
+               $query->execute($x,$y);
+               if (isMember() && (isBC() || isOfficer()) && !isHC()){
+                       log_message $ND::UID,"BC browsing $x:$y";
+               }
+       }
+       my @planets;
+       my $planet_id = undef;
+       my $i = 0;
+       while (my ($id,$coords,$planet,$race,$size,$score,$value,$xp,$sizerank,$scorerank,$valuerank,$xprank
+                       ,$fleetvalue,$resvalue,$planet_status,$hit_us,$alliance,$relationship,$nick) = $query->fetchrow){
+               $planet_id = $id;
+               my %planet = (Coords => $coords, Planet => $planet, Race => $race, Size => "$size ($sizerank)"
+                       , Score => "$score ($scorerank)", Value => "$value ($valuerank)", XP => "$xp ($xprank)"
+                       , FleetValue => "$fleetvalue ($resvalue)");
+               if (isMember() && (isOfficer() || isBC())){
+                       $planet{HitUs} = $hit_us;
+                       $planet{Alliance} = "$alliance ($relationship)";
+                       $planet{Nick} = "$nick ($planet_status)";
+                       $planet{PlanetStatus} = $planet_status;
+                       $planet{Relationship} = $relationship;
+                       $planet{isBC} = 1;
+                       if ($z && $alliance eq 'NewDawn'){
+                               log_message $ND::UID,"BC browsing ND planet $coords tick $ND::TICK";
+                       }
+               }
+               $i++;
+               $planet{ODD} = $i % 2;
+               push @planets,\%planet;
+       }
+       $BODY->param(Planets => \@planets);
+
+       if ($z && $planet_id){
+               $BODY->param(OnePlanet => 1);
+
+               my $query = $DBH->prepare(q{ 
+                       SELECT i.mission, i.tick AS landingtick,MIN(eta) AS eta, i.amount, coords(p.x,p.y,p.z) AS target
+                       FROM intel i
+                       JOIN (planets
+                       NATURAL JOIN planet_stats) p ON i.target = p.id
+                       JOIN (planets
+                       NATURAL JOIN planet_stats) p2 ON i.sender = p2.id
+                       WHERE  p.tick = ( SELECT max(tick) FROM planet_stats) AND i.tick > tick() AND i.uid = -1 
+                       AND p2.tick = p.tick AND p2.id = ?
+                       GROUP BY p.x,p.y,p.z,p2.x,p2.y,p2.z,i.mission,i.tick,i.amount,i.ingal,i.uid
+                       ORDER BY p.x,p.y,p.z});
+               $query->execute($planet_id);
+               my @missions;
+               while (my ($mission,$landingtick,$eta,$amount,$target) = $query->fetchrow){
+                       push @missions,{Target => $target, Mission => $mission, LandingTick => $landingtick
+                               , ETA => $eta, Amount => $amount};
+               }
+               $BODY->param(Missions => \@missions);
+
+               my @scans;
+               $query = $DBH->prepare(q{SELECT value,tick FROM planet_stats 
+                       WHERE id = ? AND tick > tick() - 24});
+               my $scan = q{
+               <p>Value the last 24 ticks</p>
+               <table><tr><th>Tick</th><th>Value</th><th>Difference</th></tr>};
+               my $old = 0;
+               $query->execute($planet_id);
+               while (my($value,$tick) = $query->fetchrow){
+                       my $diff = $value-$old;
+                       $old = $value;
+                       my $class = 'Defend';
+                       $class = 'Attack' if $diff < 0;
+                       $scan .= qq{<tr><td>$tick</td><td>$value</td><td class="$class">$diff</td></tr>};
+               }
+               $scan .= q{</table>};
+               push @scans, {Scan => $scan};
+
+               $query = $DBH->prepare(q{SELECT x,y,z,tick FROM planet_stats WHERE id = ?});
+               $scan = q{
+               <p>Previous Coords</p>
+               <table><tr><th>Tick</th><th>Value</th><th>Difference</th></tr>};
+               $query->execute($planet_id);
+               $x = $y = $z = 0;
+               while (my($nx,$ny,$nz,$tick) = $query->fetchrow){
+                       if ($nx != $x || $ny != $y || $nz != $z){
+                               $x = $nx;
+                               $y = $ny;
+                               $z = $nz;
+                               $scan .= qq{<tr><td>$tick</td><td>$x:$y:$z</td></tr>};
+                       }
+               }
+               $scan .= q{</table>};
+               push @scans, {Scan => $scan};
+
+               $query = $DBH->prepare(q{SELECT DISTINCT ON (type) type,scan_id, tick, scan FROM scans WHERE planet = ?
+                       GROUP BY type,scan_id, tick, scan ORDER BY type,tick DESC});
+               $query->execute($planet_id);
+               my %scans;
+               while (my($type,$scan_id,$tick,$scan) = $query->fetchrow){
+                       $scans{$type} = [$scan_id,$tick,$scan];
+               }
+               for my $type ('Planet','Jumpgate','Unit','Military','Fleet Analysis','Surface Analysis','Technology Analysis','News'){
+                       next unless exists $scans{$type};
+                       my $scan_id = $scans{$type}->[0];
+                       my $tick = $scans{$type}->[1];
+                       my $scan = $scans{$type}->[2];
+                       if ($ND::TICK - $tick > 10){
+                               $scan =~ s{<table( cellpadding="\d+")?>}{<table$1 class="old">};
+                       }
+                       push @scans,{Scan => qq{
+                               <p><b><a href="http://game.planetarion.com/showscan.pl?scan_id=$scan_id">$type</a> Scan from tick $tick</b></p>
+                               $scan}};
+               }
+
+               $BODY->param(Scans => \@scans);
+       }
+       return $BODY;
+}
+
+1;
diff --git a/ND/Web/Pages/CovOp.pm b/ND/Web/Pages/CovOp.pm
new file mode 100644 (file)
index 0000000..5f1a59c
--- /dev/null
@@ -0,0 +1,86 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::CovOp;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{covop} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       if ($uri =~ m{^/.*/(\w+)$}){
+               param('list',$1);
+       }
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       $ND::TEMPLATE->param(TITLE => 'CovOp Targets');
+
+       return $ND::NOACCESS unless isMember();
+
+       my $show = q{AND ((planet_status IS NULL OR NOT planet_status IN ('Friendly','NAP')) AND  (relationship IS NULL OR NOT relationship IN ('Friendly','NAP')))};
+       $show = '' if defined param('show') && param('show') eq 'all';
+       if (defined param('covop') && param('covop') =~ /^(\d+)$/){
+               my $update = $DBH->prepare('UPDATE covop_targets SET covop_by = ?, last_covop = tick() WHERE planet = ? ');
+               $update->execute($ND::UID,$1);
+       }
+
+       my $list = '';
+       my $where = '';
+       if (defined param('list') && param('list') eq 'distwhores'){
+               $list = '&amp;list=distwhores';
+               $where = qq{WHERE dists > 0 $show
+               ORDER BY dists DESC,COALESCE(sec_centres::float/structures*100,0)ASC}
+       }else{
+               $where = qq{WHERE MaxResHack > 130000 
+               $show
+               ORDER BY COALESCE(sec_centres::float/structures*100,0) ASC,MaxResHack DESC,metal+crystal+eonium DESC};
+       }
+
+       my $query = $DBH->prepare(qq{SELECT id, coords, metal, crystal, eonium, sec_centres::float/structures*100 AS secs, dists, last_covop, username, MaxResHack
+               FROM (SELECT p.id,coords(x,y,z), metal,crystal,eonium,
+               sec_centres,NULLIF(structures,0) AS structures,dists,last_covop,
+               u.username,max_bank_hack(metal,crystal,eonium,p.value,(SELECT value FROM
+               current_planet_stats WHERE id = ?)) AS MaxResHack, planet_status, relationship
+               FROM covop_targets c JOIN current_planet_stats p ON p.id = c.planet
+               LEFT OUTER JOIN users u ON u.uid = c.covop_by) AS foo
+               $where});
+       $query->execute($ND::PLANET);
+
+       my @targets;
+       my $i = 0;
+       while (my ($id,$coords,$metal,$crystal,$eonium,$seccents,$dists,$lastcovop,$user,$max) = $query->fetchrow){
+               $i++;
+               push @targets,{Username => $user, Target => $id, Coords => $coords
+                       , Metal => $metal, Crystal => $crystal, Eonium => $eonium, SecCents => $seccents
+                       , Dists => $dists, MaxResHack => $max, LastCovOp => $lastcovop, List => $list, ODD => $i % 2};
+       }
+       $BODY->param(Targets => \@targets);
+       return $BODY;
+}
+
+1;
diff --git a/ND/Web/Pages/DefRequest.pm b/ND/Web/Pages/DefRequest.pm
new file mode 100644 (file)
index 0000000..9329e31
--- /dev/null
@@ -0,0 +1,54 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::DefRequest;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{defrequest} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       $ND::TEMPLATE->param(TITLE => 'Request Defense');
+
+       my $error;
+
+       return $ND::NOACCESS unless isMember();
+
+       if (defined param('cmd') && param('cmd') eq 'submit'){
+               my $insert = $DBH->prepare('INSERT INTO defense_requests (uid,message) VALUES (?,?)');
+               if($insert->execute($ND::UID,param('message'))){
+                       $BODY->param(Reply => param('message'));
+               }else{
+                       $error .= "<b>".$DBH->errstr."</b>";
+               }
+       }
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+1;
diff --git a/ND/Web/Pages/EditRaid.pm b/ND/Web/Pages/EditRaid.pm
new file mode 100644 (file)
index 0000000..f7f8a9f
--- /dev/null
@@ -0,0 +1,214 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+package ND::Web::Pages::EditRaid;
+use strict;
+use warnings FATAL => 'all';
+use ND::Include;
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{editRaid} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       #if ($uri =~ m{^/.*/(\w+)$}){
+       #       param('list',$1);
+       #}
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       my $error;
+
+       $ND::TEMPLATE->param(TITLE => 'Create/Edit Raids');
+
+       return $ND::NOACCESS unless isBC();
+
+       my @alliances = alliances();
+       $BODY->param(Alliances => \@alliances);
+
+       my $raid;
+       if (defined param 'raid' and param('raid') =~ /^(\d+)$/){
+               my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords,open FROM raids WHERE id = ?});
+               $raid = $DBH->selectrow_hashref($query,undef,$1);
+       }
+       if (defined param('cmd') && param('cmd') eq 'submit'){
+               my $query = $DBH->prepare(q{INSERT INTO raids (tick,waves,message) VALUES(?,?,'')});
+               if ($query->execute(param('tick'),param('waves'))){
+                       $raid = $DBH->last_insert_id(undef,undef,undef,undef,"raids_id_seq");
+                       my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords,open FROM raids WHERE id = ?});
+                       $raid = $DBH->selectrow_hashref($query,undef,$raid);
+               }else{
+                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+               }
+       }
+
+       if ($raid && defined param('cmd')){
+               if (param('cmd') eq 'remove'){
+                       $DBH->do(q{UPDATE raids SET open = FALSE, removed = TRUE WHERE id = ?},undef,$raid->{id});
+               }elsif (param('cmd') eq 'Open'){
+                       if($DBH->do(q{UPDATE raids SET open = TRUE, removed = FALSE WHERE id = ?},undef,$raid->{id})){
+                               $raid->{open} = 1;
+                               $raid->{removed} = 0;
+                       }
+               }elsif (param('cmd') eq 'Close'){
+                       if ($DBH->do(q{UPDATE raids SET open = FALSE WHERE id = ?},undef,$raid->{id})){
+                               $raid->{open} = 0;
+                       }
+               }elsif (param('cmd') eq 'showcoords'){
+                       if($DBH->do(q{UPDATE raids SET released_coords = TRUE WHERE id = ?},undef,$raid->{id})){
+                               $raid->{released_coords} = 1;
+                       }
+               }elsif (param('cmd') eq 'hidecoords'){
+                       if($DBH->do(q{UPDATE raids SET released_coords = FALSE WHERE id = ?},undef,$raid->{id})){
+                               $raid->{released_coords} = 0;
+                       }
+               }elsif (param('cmd') eq 'comment'){
+                       $DBH->do(q{UPDATE raid_targets SET comment = ? WHERE id = ?}
+                               ,undef,escapeHTML(param('comment')),param('target'))
+                               or $error .= p($DBH->errstr);
+
+               }elsif (param('cmd') eq 'change'){
+                       $DBH->begin_work;
+                       my $message = escapeHTML(param('message'));
+                       $raid->{message} = $message;
+                       $raid->{waves} = param('waves');
+                       $raid->{tick} = param('tick');
+                       unless ($DBH->do(qq{UPDATE raids SET message = ?, tick = ?, waves = ? WHERE id = ?}
+                                       ,undef,$message,param('tick'),param('waves'),$raid->{id})){
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       }
+                       my $sizelimit = '';
+                       if (param('sizelimit') =~ /^(\d+)$/){
+                               $sizelimit = "AND p.size >= $1";
+                               unless ($DBH->do(qq{DELETE FROM raid_targets WHERE id IN (SELECT t.id FROM current_planet_stats p 
+                                               JOIN raid_targets t ON p.id = t.planet WHERE p.size < ? AND t.raid = ?)},undef,$1,$raid->{id})){
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+                       my $targets = param('targets');
+                       my $addtarget = $DBH->prepare(qq{INSERT INTO raid_targets(raid,planet) (
+                               SELECT ?, id FROM current_planet_stats p WHERE x = ? AND y = ? AND COALESCE(z = ?,TRUE) $sizelimit)});
+                       while ($targets =~ m/(\d+):(\d+)(?::(\d+))?/g){
+                               unless ($addtarget->execute($raid->{id},$1,$2,$3)){
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+                       if (param('alliance') =~ /^(\d+)$/ && $1 != 1){
+                               log_message $ND::UID,"BC adding alliance $1 to raid";
+                               my $addtarget = $DBH->prepare(qq{INSERT INTO raid_targets(raid,planet) (
+                                       SELECT ?,id FROM current_planet_stats p WHERE alliance_id = ? $sizelimit)});
+                               unless ($addtarget->execute($raid->{id},$1)){
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+                       my $groups = $DBH->prepare('SELECT gid,groupname FROM groups WHERE attack');
+                       my $delgroup = $DBH->prepare(q{DELETE FROM raid_access WHERE raid = ? AND gid = ?});
+                       my $addgroup = $DBH->prepare(q{INSERT INTO raid_access (raid,gid) VALUES(?,?)});
+                       $groups->execute();
+                       while (my $group = $groups->fetchrow_hashref){
+                               my $query;
+                               next unless defined param $group->{gid};
+                               if (param($group->{gid}) eq 'remove'){
+                                       $query = $delgroup;
+                               }elsif(param($group->{gid}) eq 'add'){
+                                       $query = $addgroup;
+                               }
+                               if ($query){
+                                       unless ($query->execute($raid->{id},$group->{gid})){
+                                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       }
+                               }
+                       }
+                       unless ($DBH->commit){
+                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                       }
+               }
+       }
+       if ($raid && param('removeTarget')){
+               $error .= "test";
+               unless($DBH->do(q{DELETE FROM raid_targets WHERE raid = ? AND id = ?}
+                               ,undef,$raid->{id},param('removeTarget'))){
+                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+               }
+       }
+
+       my $groups = $DBH->prepare(q{SELECT g.gid,g.groupname,raid FROM groups g LEFT OUTER JOIN (SELECT gid,raid FROM raid_access WHERE raid = ?) AS ra ON g.gid = ra.gid WHERE g.attack});
+       $groups->execute($raid ? $raid->{id} : undef);
+
+       my @addgroups;
+       my @remgroups;
+       while (my $group = $groups->fetchrow_hashref){
+               if ($group->{raid}){
+                       push @remgroups,{Id => $group->{gid}, Name => $group->{groupname}};
+               }else{
+                       push @addgroups,{Id => $group->{gid}, Name => $group->{groupname}};
+               }
+       }
+       $BODY->param(RemoveGroups => \@remgroups);
+       $BODY->param(AddGroups => \@addgroups);
+
+
+       if ($raid){
+
+               $BODY->param(Raid => $raid->{id});
+               if($raid->{open}){
+                       $BODY->param(Open => 'Close');
+               }else{
+                       $BODY->param(Open => 'Open');
+               }
+               if($raid->{released_coords}){
+                       $BODY->param(ShowCoords => 'hidecoords');
+                       $BODY->param(ShowCoordsName => 'Hide');
+               }else{
+                       $BODY->param(ShowCoords => 'showcoords');
+                       $BODY->param(ShowCoordsName => 'Show');
+               }
+               $BODY->param(Waves => $raid->{waves});
+               $BODY->param(LandingTick => $raid->{tick});
+               $BODY->param(Message => $raid->{message});
+
+               my $order = "p.x,p.y,p.z";
+               if (param('order') && param('order') =~ /^(score|size|value|xp|race)$/){
+                       $order = "$1 DESC";
+               }
+
+               my $targetquery = $DBH->prepare(qq{SELECT r.id,coords(x,y,z),raid,comment,size,score,value,race,planet_status AS planetstatus,relationship,comment
+                       FROM current_planet_stats p JOIN raid_targets r ON p.id = r.planet 
+                       WHERE r.raid = ?
+                       ORDER BY $order});
+               $targetquery->execute($raid->{id}) or $error .= $DBH->errstr;
+               my @targets;
+               while (my $target = $targetquery->fetchrow_hashref){
+                       push @targets,$target;
+               }
+               $BODY->param(Targets => \@targets);
+       }else{
+               $BODY->param(Waves => 3);
+               $BODY->param(LandingTick => $ND::TICK+12);
+       }
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+
+1;
diff --git a/ND/Web/Pages/Forum.pm b/ND/Web/Pages/Forum.pm
new file mode 100644 (file)
index 0000000..3e8f30e
--- /dev/null
@@ -0,0 +1,166 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Forum;
+use strict;
+use warnings FATAL => 'all';
+no warnings 'uninitialized';
+use ND::Web::Forum;
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{forum} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       if ($uri =~ m{^/.*/allUnread$}){
+               param('allUnread',1);
+       }
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+
+       $ND::TEMPLATE->param(TITLE => 'Forum');
+
+       my $board;
+       if(param('b')){
+               my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
+                       FROM forum_boards fb NATURAL JOIN forum_access fa
+                       WHERE fb.fbid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
+                       WHERE uid = $2))
+                       GROUP BY fb.fbid,fb.board});
+               $board = $DBH->selectrow_hashref($boards,undef,param('b'),$ND::UID) or $ND::ERROR .= p($DBH->errstr);
+       }
+
+       my $thread;
+       my $findThread = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject, bool_or(fa.post) AS post
+               FROM forum_boards fb NATURAL JOIN forum_access fa NATURAL JOIN forum_threads ft
+               WHERE ft.ftid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
+               WHERE uid = $2))
+               GROUP BY ft.ftid,ft.subject});
+       if(param('t')){
+               $thread = $DBH->selectrow_hashref($findThread,undef,param('t'),$ND::UID) or $ND::ERROR .= p($DBH->errstr);
+       }
+
+       if (defined param('cmd') && param('cmd') eq 'forumpost'){
+               $DBH->begin_work;
+               if ($board && $board->{post}){
+                       $thread = addForumThread $DBH,$board,$ND::UID,param('subject');
+               }
+               if ($thread && $thread->{post}){
+                       addForumPost($DBH,$thread,$ND::UID,param('message'));
+               }
+               $DBH->commit or $ND::ERROR .= p($DBH->errstr);
+       }
+
+       my $categories = $DBH->prepare(q{SELECT fcid AS id,category FROM forum_categories ORDER BY fcid});
+       my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts, max(fp.time)::timestamp as last_post
+               FROM forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
+               WHERE ft.fbid = $1
+               GROUP BY ft.ftid, ft.subject
+               HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= $3
+               ORDER BY last_post DESC});
+
+       if ($thread){ #Display the thread
+               $BODY->param(Thread => viewForumThread $thread);
+
+       }elsif($board){ #List threads in this board
+               $BODY->param(Board => $board->{board});
+               $BODY->param(Post => $board->{post});
+               $BODY->param(Id => $board->{id});
+               $threads->execute($board->{id},$ND::UID,0) or $ND::ERROR .= p($DBH->errstr);
+               my $i = 0;
+               my @threads;
+               while (my $thread = $threads->fetchrow_hashref){
+                       $i++;
+                       $thread->{Odd} = $i % 2;
+                       push @threads,$thread;
+               }
+               $BODY->param(Threads => \@threads);
+
+       }elsif(defined param('allUnread')){ #List threads in this board
+               $BODY->param(AllUnread => 1);
+               $BODY->param(Id => $board->{id});
+               $categories->execute or $ND::ERROR .= p($DBH->errstr);
+               my @categories;
+               my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
+                       FROM forum_boards fb NATURAL JOIN forum_access fa
+                       WHERE fb.fcid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
+                       WHERE uid = $2))
+                       GROUP BY fb.fbid,fb.board
+                       ORDER BY fb.fbid
+                       });
+               while (my $category = $categories->fetchrow_hashref){
+                       $boards->execute($category->{id},$ND::UID) or $ND::ERROR .= p($DBH->errstr);
+                       my @boards;
+                       while (my $board = $boards->fetchrow_hashref){
+                               $threads->execute($board->{id},$ND::UID,1) or $ND::ERROR .= p($DBH->errstr);
+                               my $i = 0;
+                               my @threads;
+                               while (my $thread = $threads->fetchrow_hashref){
+                                       $i++;
+                                       $thread->{Odd} = $i % 2;
+                                       push @threads,$thread;
+                               }
+                               $board->{Threads} = \@threads;
+                               delete $board->{post};
+                               push @boards,$board if $i > 0;
+                       }
+                       $category->{Boards} = \@boards;
+                       delete $category->{id};
+                       push @categories,$category if @boards;
+               }
+               $BODY->param(Categories => \@categories);
+
+       }else{ #List boards
+               $BODY->param(Overview => 1);
+               $categories->execute or $ND::ERROR .= p($DBH->errstr);
+               my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board,count(NULLIF(COALESCE(fp.fpid::boolean,FALSE) AND COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread
+                       FROM forum_boards fb LEFT OUTER JOIN (forum_threads ft JOIN forum_posts fp USING (ftid)) ON fb.fbid = ft.fbid LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
+                       WHERE fb.fcid = $1 AND 
+                       fb.fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($2)))
+                       GROUP BY fb.fbid, fb.board
+                       ORDER BY fb.fbid        });
+               my @categories;
+               while (my $category = $categories->fetchrow_hashref){
+                       $boards->execute($category->{id},$ND::UID) or $ND::ERROR .= p($DBH->errstr);
+                       my @boards;
+                       my $i = 0;
+                       while (my $board = $boards->fetchrow_hashref){
+                               $i++;
+                               $board->{Odd} = $i % 2;
+                               push @boards,$board;
+                       }
+                       $category->{Boards} = \@boards;
+                       delete $category->{id};
+                       push @categories,$category if $i > 0;
+               }
+               $BODY->param(Categories => \@categories);
+
+       }
+       return $BODY;
+}
+
+1;
+
diff --git a/ND/Web/Pages/Intel.pm b/ND/Web/Pages/Intel.pm
new file mode 100644 (file)
index 0000000..5a4a47c
--- /dev/null
@@ -0,0 +1,243 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Intel;
+use strict;
+use warnings FATAL => 'all';
+use ND::Web::Forum;
+use ND::Web::Include;
+use ND::Include;
+use CGI qw/:standard/;
+
+$ND::PAGES{intel} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       if ($uri =~ m{^/.*/(\w+)$}){
+               param('list',$1);
+       }
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+
+       my $error;
+
+       $ND::TEMPLATE->param(TITLE => 'Intel');
+
+       return $ND::NOACCESS unless isIntel() || isHC();
+
+       my $planet;
+       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,ftid FROM current_planet_stats
+                       WHERE  x = ? AND y = ? AND z = ?});
+               $planet = $DBH->selectrow_hashref($query,undef,$1,$2,$3) or $ND::ERROR .= p $DBH->errstr;
+       }
+
+       my $showticks = 'AND (i.tick - i.eta) > (tick() - 48)';
+       if (defined param('show')){
+               if (param('show') eq 'all'){
+                       $showticks = '';
+               }elsif (param('show') =~ /^(\d+)$/){
+                       $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
+               }
+       }
+
+       my $thread;
+       if (defined $planet){
+               $thread = $DBH->selectrow_hashref(q{SELECT ftid AS id, subject FROM forum_threads
+                       where ftid = $1},undef,$planet->{ftid}) or $ND::ERROR .= p($DBH->errstr);
+       }
+
+       if (defined param('cmd') && param('cmd') eq 'coords'){
+               my $coords = param('coords');
+               $DBH->do(q{CREATE TEMPORARY TABLE coordlist (
+                       x integer NOT NULL,
+                       y integer NOT NULL,
+                       z integer NOT NULL,
+                       PRIMARY KEY (x,y,z)
+                       )});
+               my $insert = $DBH->prepare(q{INSERT INTO coordlist (x,y,z) VALUES(?,?,?)});
+               while ($coords =~ m/(\d+):(\d+):(\d+)/g){
+                       $insert->execute($1,$2,$3);
+               }
+               my $planets = $DBH->prepare(q{SELECT (((p.x || ':') || p.y) || ':') || p.z AS coords, alliance FROM current_planet_stats p
+                       JOIN coordlist c ON p.x = c.x AND p.y = c.y AND p.z = c.z
+                       ORDER BY alliance, p.x, p.y, p.z});
+               $planets->execute;
+               my @planets;
+               while (my $planet = $planets->fetchrow_hashref){
+                       push @planets,$planet;
+               }
+               $BODY->param(CoordList => \@planets);
+       }
+       if (defined $thread and defined param('cmd') and param('cmd') eq 'forumpost'){
+               addForumPost($DBH,$thread,$ND::UID,param('message'));
+       }
+
+       if ($planet && defined param('cmd')){
+               if (param('cmd') eq 'change'){
+                       $DBH->begin_work;
+                       if (param('cnick')){
+                               my $value = escapeHTML(param('nick'));
+                               if ($DBH->do(q{UPDATE planets SET nick = ? WHERE id =?}
+                                               ,undef,$value,$planet->{id})){
+                                       intel_log $ND::UID,$planet->{id},"Set nick to: $value";
+                                       $planet->{nick} = $value;
+                               }else{
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+                       if (param('cchannel')){
+                               my $value = escapeHTML(param('channel'));
+                               if ($DBH->do(q{UPDATE planets SET channel = ? WHERE id =?}
+                                               ,undef,$value,$planet->{id})){
+                                       intel_log $ND::UID,$planet->{id},"Set channel to: $value";
+                                       $planet->{channel} = $value;
+                               }else{
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+                       if (param('cstatus')){
+                               my $value = escapeHTML(param('status'));
+                               if ($DBH->do(q{UPDATE planets SET planet_status = ? WHERE id =?}
+                                               ,undef,$value,$planet->{id})){
+                                       intel_log $ND::UID,$planet->{id},"Set planet_status to: $value";
+                                       $planet->{planet_status} = $value;
+                               }else{
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+                       if (param('calliance')){
+                               if ($DBH->do(q{UPDATE planets SET alliance_id = NULLIF(?,-1) WHERE id =?}
+                                               ,undef,param('alliance'),$planet->{id})){
+                                       intel_log $ND::UID,$planet->{id},"Set alliance_id to: ".param('alliance');
+                                       $planet->{alliance_id} = param('alliance');
+                               }else{
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+                       $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+               }
+       }
+
+       if (param('coords')){
+               my $channel = param('coords');
+               $channel = $planet->{channel} if ($planet);
+               my $findchannel = $DBH->prepare('SELECT coords(x,y,z),alliance,nick,channel FROM current_planet_stats WHERE channel ILIKE ? ');
+               $findchannel->execute($channel);
+               my @channelusers;
+               while (my $user = $findchannel->fetchrow_hashref){
+                       push @channelusers,$user;
+               }
+               $BODY->param(ChannelUsers => \@channelusers);
+       }
+
+       if ($planet){
+               $BODY->param(Coords => $planet->{coords});
+               $BODY->param(Planet => $planet->{id});
+               $BODY->param(Nick => $planet->{nick});
+               $BODY->param(Channel => $planet->{channel});
+               my @status;
+               for my $status ("&nbsp;","Friendly", "NAP", "Hostile"){
+                       push @status,{Status => $status, Selected => defined $planet->{planet_status} && $status eq $planet->{planet_status}}
+               }
+               $BODY->param(PlanetStatus => \@status);
+               my @alliances = alliances($planet->{alliance_id});
+               $BODY->param(Alliances => \@alliances);
+
+               $BODY->param(Thread => viewForumThread $thread);
+
+               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 @incomings;
+               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 @incomings,$intel;
+               }
+               push @intellists,{Message => 'Incoming fleets', Intel => \@incomings, Origin => 1};
+
+               $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};
+                       }
+                       $i++;
+                       $intel->{ODD} = $i % 2;
+                       push @outgoings,$intel;
+               }
+               push @intellists,{Message => 'Outgoing Fleets', Intel => \@outgoings, Target => 1};
+
+               $BODY->param(IntelLIsts => \@intellists);
+
+       }elsif(!param('coords')){
+               my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin, t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',qq{not ingal
+                               AND ((( t.alliance_id != o.alliance_id OR t.alliance_id IS NULL OR o.alliance_id IS NULL) AND i.mission != 'Attack')
+                               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 $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};
+               $BODY->param(IntelLIsts => \@intellists);
+       }
+       my $query = $DBH->prepare(q{SELECT i.id, u.username, i.message, report_date FROM intel_messages i
+               JOIN users u ON u.uid = i.uid
+               WHERE NOT handled ORDER BY report_date});
+       $query->execute;
+       my @messages;
+       while (my $message = $query->fetchrow_hashref){
+               $message->{message} = parseMarkup($message->{message});
+               push @messages,$message;
+       }
+       #$BODY->param(IntelMessages => \@messages);
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+1;
diff --git a/ND/Web/Pages/LaunchConfirmation.pm b/ND/Web/Pages/LaunchConfirmation.pm
new file mode 100644 (file)
index 0000000..29cb13c
--- /dev/null
@@ -0,0 +1,133 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::LaunchCoonfirmation;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Include;
+use ND::Include;
+
+$ND::PAGES{launchConfirmation} = {parse => \&parse, process => \&process, render=> \&render};
+
+
+sub parse {
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       $ND::TEMPLATE->param(TITLE => 'Launch Confirmation');
+
+       my $error;
+
+       return $ND::NOACCESS unless isMember();
+
+       if (defined param('cmd') && param('cmd') eq 'submit'){
+               my $missions = param('mission');
+               my $findplanet = $DBH->prepare("SELECT planetid(?,?,?,?)");
+               my $findattacktarget = $DBH->prepare(q{SELECT c.target,c.wave,c.launched FROM  raid_claims c
+                       JOIN raid_targets t ON c.target = t.id
+                       JOIN raids r ON t.raid = r.id
+                       WHERE c.uid = ? AND r.tick+c.wave-1 = ? AND t.planet = ?
+                       AND r.open AND not r.removed});
+               my $finddefensetarget = $DBH->prepare(q{SELECT NULL});
+               my $addattackpoint = $DBH->prepare('UPDATE users SET attack_points = attack_points + 1 WHERE uid = ?');
+               my $launchedtarget = $DBH->prepare('UPDATE raid_claims SET launched = True WHERE uid = ? AND target = ? AND wave = ?');
+               my $addfleet = $DBH->prepare(qq{INSERT INTO fleets (uid,target,mission,landing_tick,fleet,eta,back) VALUES (?,?,?,?,(SELECT max(fleet)+1 from fleets WHERE uid = ?),?,?)});
+               my $addships = $DBH->prepare('INSERT INTO fleet_ships (fleet,ship,amount) VALUES (?,?,?)');
+
+               my $fleet = $DBH->prepare("SELECT id FROM fleets WHERE uid = ? AND fleet = 0");
+               my ($basefleet) = $DBH->selectrow_array($fleet,undef,$ND::UID);
+               unless ($basefleet){
+                       my $insert = $DBH->prepare(q{INSERT INTO fleets (uid,target,mission,landing_tick,fleet,eta,back) VALUES (?,?,'Full fleet',0,0,0,0)});
+                       $insert->execute($ND::UID,$ND::PLANET);
+               }
+               my @missions;
+               $DBH->begin_work;
+               while ($missions =~ m/\S+\s+(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)\s+\((?:(\d+)\+)?(\d+)\).*?(?:\d+hrs\s+)?\d+mins\s+(Attack|Defend|Return|Fake Attack|Fake Defend)(.*?)(?:Launching in tick (\d+), arrival in tick (\d+)|ETA: \d+, Return ETA: (\d+))/sg){
+                       my %mission;
+
+                       my $tick = $ND::TICK+$8;
+                       $tick += $7 if defined $7;
+                       my $eta = $8;
+                       my $mission = $9;
+                       my $x = $4;
+                       my $y = $5;
+                       my $z = $6;
+                       $mission{Tick} = $tick;
+                       $mission{Mission} = $mission;
+                       $mission{Target} = "$x:$y:$z";
+                       if ($12){
+                               $tick = $12;
+                       }elsif ($13){
+                               $eta += $13;
+                       }
+
+                       my ($planet_id) = $DBH->selectrow_array($findplanet,undef,$x,$y,$z,$ND::TICK);
+
+                       my $findtarget = $finddefensetarget;
+                       if ($mission eq 'Attack'){
+                               $findtarget = $findattacktarget;
+                       }elsif ($mission eq 'Defend'){
+                               $findtarget = $finddefensetarget;
+                       }
+
+                       $findtarget->execute($ND::UID,$tick,$planet_id);
+
+                       if ($findtarget->rows == 0){
+                               $mission{Warning} = "YOU DON'T HAVE A TARGET WITH THAT LANDING TICK";
+                       }elsif ($mission eq 'Attack'){
+                               my $claim = $findtarget->fetchrow_hashref;
+                               if ($claim->{launched}){
+                                       $mission{Warning} = "Already launched on this target:$claim->{target},$claim->{wave},$claim->{launched}";
+                               }else{
+                                       $addattackpoint->execute($ND::UID);
+                                       $launchedtarget->execute($ND::UID,$claim->{target},$claim->{wave});
+                                       $mission{Warning} = "OK:$claim->{target},$claim->{wave},$claim->{launched}";
+                                       log_message $ND::UID,"Gave attack point for confirmation on $mission mission to $x:$y:$z, landing tick $tick";
+                               }
+                       }
+
+                       $addfleet->execute($ND::UID,$planet_id,$mission,$tick,$ND::UID,$eta,$tick+$eta-1) or $error .= '<p>'.$DBH->errstr.'</p>';
+                       my $fleet = $DBH->last_insert_id(undef,undef,undef,undef,"fleets_id_seq");
+                       $mission{Fleet} = $fleet;
+                       $mission{Back} = $tick+$eta-1;
+                       my $ships = $10;
+                       my @ships;
+                       while ($ships =~ m/((?:\w+ )*\w+)\s+\w+\s+\w+\s+(?:Steal|Normal|Emp|Normal\s+Cloaked|Pod|Struc)\s+(\d+)/g){
+                               $addships->execute($fleet,$1,$2);
+                               push @ships,{Ship => $1, Amount => $2};
+                       }
+                       $mission{Ships} = \@ships;
+                       log_message $ND::UID,"Pasted confirmation for $mission mission to $x:$y:$z, landing tick $tick";
+                       push @missions,\%mission;
+               }
+               $DBH->commit or $error .= '<p>'.$DBH->errstr.'</p>';
+               $BODY->param(Missions => \@missions);
+       }
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+
+
+1;
diff --git a/ND/Web/Pages/Main.pm b/ND/Web/Pages/Main.pm
new file mode 100644 (file)
index 0000000..3e8d751
--- /dev/null
@@ -0,0 +1,170 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Main;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Include;
+use ND::Web::Include;
+
+$ND::PAGES{main} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       $ND::TEMPLATE->param(TITLE => 'Main Page');
+
+       my $error;
+
+       if (defined param('cmd')){
+               if (param('cmd') eq 'fleet'){
+                       $DBH->begin_work;
+                       my $fleet = $DBH->prepare("SELECT id FROM fleets WHERE uid = ? AND fleet = 0");
+                       my ($id) = $DBH->selectrow_array($fleet,undef,$ND::UID);
+                       unless ($id){
+                               my $insert = $DBH->prepare(q{INSERT INTO fleets (uid,target,mission,landing_tick,fleet,eta,back) VALUES (?,?,'Full fleet',0,0,0,0)});
+                               $insert->execute($ND::UID,$ND::PLANET);
+                               ($id) = $DBH->selectrow_array($fleet,undef,$ND::UID);
+                       }
+                       my $delete = $DBH->prepare("DELETE FROM fleet_ships WHERE fleet = ?");
+                       $delete->execute($id);
+                       my $insert = $DBH->prepare('INSERT INTO fleet_ships (fleet,ship,amount) VALUES (?,?,?)');
+                       $fleet = param('fleet');
+                       $fleet =~ s/,//g;
+                       while ($fleet =~ m/((?:[A-Z][a-z]+ )*[A-Z][a-z]+)\s+(\d+)/g){
+                               $insert->execute($id,$1,$2) or $error .= '<p>'.$DBH->errstr.'</p>';
+                       }
+                       $fleet = $DBH->prepare('UPDATE fleets SET landing_tick = tick() WHERE id = ?');
+                       $fleet->execute($id);
+                       $DBH->commit;
+               }elsif (param('cmd') eq 'Recall Fleets'){
+                       $DBH->begin_work;
+                       my $updatefleets = $DBH->prepare('UPDATE fleets SET back = tick() + (tick() - (landing_tick - eta))  WHERE uid = ? AND id = ?');
+
+                       for my $param (param()){
+                               if ($param =~ /^change:(\d+)$/){
+                                       if($updatefleets->execute($ND::UID,$1)){
+                                               log_message $ND::UID,"Member recalled fleet $1";
+                                       }else{
+                                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       }
+                               }
+                       }
+                       $DBH->commit or $error .= '<p>'.$DBH->errstr.'</p>';
+               }elsif (param('cmd') eq 'Change Fleets'){
+                       $DBH->begin_work;
+                       my $updatefleets = $DBH->prepare('UPDATE fleets SET back = ? WHERE uid = ? AND id = ?');
+                       for my $param (param()){
+                               if ($param =~ /^change:(\d+)$/){
+                                       if($updatefleets->execute(param("back:$1"),$ND::UID,$1)){
+                                               log_message $ND::UID,"Member set fleet $1 to be back tick: ".param("back:$1");
+                                       }else{
+                                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                                       }
+                               }
+                       }
+                       $DBH->commit or $error .= '<p>'.$DBH->errstr.'</p>';
+               }
+       }
+       if (param('sms')){ my $query = $DBH->prepare('UPDATE users SET sms = ? WHERE uid = ?');
+               $query->execute(escapeHTML(param('sms')),$ND::UID);
+       }
+       if (isMember() && !$ND::PLANET && defined param('planet') && (param('planet') =~ m/(\d+)(?: |:)(\d+)(?: |:)(\d+)/)){
+               my $query = $DBH->prepare(q{
+                       UPDATE users SET planet = 
+                       (SELECT id from current_planet_stats where x = ? AND y = ? AND z = ?)
+                       WHERE uid = ? });
+               $query->execute($1,$2,$3,$ND::UID);
+       }
+       if(param('oldpass') && param('pass')){
+               my $query = $DBH->prepare('UPDATE users SET password = MD5(?) WHERE password = MD5(?) AND uid = ?');
+               $query->execute(param('pass'),param('oldpass'),$ND::UID);
+       }
+
+       my ($motd) = $DBH->selectrow_array("SELECT value FROM misc WHERE id='MOTD'");
+
+       $BODY->param(MOTD => parseMarkup($motd));
+       $BODY->param(Username => $ND::USER);
+       $BODY->param(isMember => isMember());
+       $BODY->param(isHC => isHC());
+       my @groups = map {name => $_}, sort keys %ND::GROUPS;
+       $BODY->param(Groups => \@groups);
+
+
+       my $query = $DBH->prepare(q{SELECT planet,defense_points,attack_points,scan_points,humor_points, (attack_points+defense_points+scan_points/20) as total_points, sms,rank FROM users WHERE uid = ?});
+
+       my ($planet,$defense_points,$attack_points,$scan_points,$humor_points,$total_points,$sms,$rank) = $DBH->selectrow_array($query,undef,$ND::UID);
+
+       $ND::PLANET = $planet unless $ND::PLANET;
+
+       $BODY->param(NDRank => $rank);
+       $BODY->param(DefensePoints => $defense_points);
+       $BODY->param(AttackPoints => $attack_points);
+       $BODY->param(ScanPoints => $scan_points);
+       $BODY->param(HumorPoints => $humor_points);
+       $BODY->param(TotalPoints => $total_points);
+
+       $BODY->param(hasPlanet => $planet);
+
+       if ($planet){
+               my @row = $DBH->selectrow_array('SELECT ruler,planet,coords(x,y,z),size,sizerank
+                       ,score,scorerank,value,valuerank,xp,xprank FROM current_planet_stats
+                       WHERE id = ?',undef,$planet);
+               $BODY->param(PlanetName => "$row[0] OF $row[1] ($row[2])");
+               $BODY->param(PlanetSize => "$row[3] ($row[4])");
+               $BODY->param(PlanetScore => "$row[5] ($row[6])");
+               $BODY->param(PlanetValue => "$row[7] ($row[8])");
+               $BODY->param(PlanetXP => "$row[9] ($row[10])");
+       }
+
+
+       $query = $DBH->prepare(q{SELECT f.fleet,f.id, coords(x,y,z) AS target, mission, sum(fs.amount) AS amount, landing_tick, back
+FROM fleets f 
+JOIN fleet_ships fs ON f.id = fs.fleet 
+JOIN current_planet_stats p ON f.target = p.id
+WHERE f.uid = ? AND (f.fleet = 0 OR back >= ?)
+GROUP BY f.fleet,f.id, x,y,z, mission, landing_tick,back
+ORDER BY f.fleet
+               });
+
+       $query->execute($ND::UID,$ND::TICK) or $error .= '<p>'.$DBH->errstr.'</p>';
+       my @fleets;
+       my $i = 0;
+       while (my $fleet = $query->fetchrow_hashref){
+               $i++;
+               $fleet->{ODD} = $i % 2;
+               push @fleets,$fleet;
+       }
+       $BODY->param(Fleets => \@fleets);
+
+       $BODY->param(SMS => $sms);
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+
+
+1;
+
diff --git a/ND/Web/Pages/MemberIntel.pm b/ND/Web/Pages/MemberIntel.pm
new file mode 100644 (file)
index 0000000..c70b52b
--- /dev/null
@@ -0,0 +1,97 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::MemberIntel;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{memberIntel} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       if ($uri =~ m{^/.*/(\w+)$}){
+               param('list',$1);
+       }
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       my $error;
+
+       $ND::TEMPLATE->param(TITLE => 'Member Intel');
+
+       return $ND::NOACCESS unless isHC();
+
+       my $showticks = 'AND i.tick > tick()';
+       if (defined param('show')){
+               if (param('show') eq 'all'){
+                       $showticks = '';
+               }elsif (param('show') =~ /^(\d+)$/){
+                       $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
+               }
+       }
+
+
+       my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin, coords(t.x,t.y,t.z) AS target, t.nick',"t.alliance_id = 1 $showticks"));
+       $query->execute() or $error .= $DBH->errstr;
+       my @intellists;
+       my @incomings;
+       my $i = 0;
+       while (my $intel = $query->fetchrow_hashref){
+               if ($intel->{ingal}){
+                       $intel->{missionclass} = 'ingal';
+               }else{
+                       $intel->{missionclass} = $intel->{mission};
+               }
+               $intel->{oalliance} = ' ' unless $intel->{oalliance};
+               $i++;
+               $intel->{ODD} = $i % 2;
+               push @incomings,$intel;
+       }
+       push @intellists,{Message => 'Incoming fleets', Intel => \@incomings, Origin => 1};
+
+       $query = $DBH->prepare(intelquery('o.nick,coords(o.x,o.y,o.z) AS origin,t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.alliance_id = 1 $showticks"));
+       $query->execute() 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};
+               }
+               $intel->{talliance} = ' ' unless $intel->{talliance};
+               $i++;
+               $intel->{ODD} = $i % 2;
+               push @outgoings,$intel;
+       }
+       push @intellists,{Message => 'Outgoing Fleets', Intel => \@outgoings, Target => 1};
+
+       $BODY->param(IntelLIsts => \@intellists);
+
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+1;
diff --git a/ND/Web/Pages/Motd.pm b/ND/Web/Pages/Motd.pm
new file mode 100644 (file)
index 0000000..a0ad8a4
--- /dev/null
@@ -0,0 +1,60 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Motd;
+use strict;
+use warnings FATAL => 'all';
+use ND::Include;
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{motd} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+
+       $ND::TEMPLATE->param(TITLE => 'Edit MOTD');
+
+
+       return $ND::NOACCESS unless isHC();
+
+       if (defined param 'cmd' and param('cmd') eq 'change'){
+               $DBH->begin_work;
+               my $query = $DBH->prepare(q{UPDATE misc SET value= ? WHERE id='MOTD'});
+               my $motd = escapeHTML(param('motd'));
+               $query->execute($motd);
+               log_message $ND::UID,"Updated MOTD";
+               $DBH->commit;
+               $BODY->param(MOTD => $motd);
+       }else{
+               my ($motd) = $DBH->selectrow_array(q{SELECT value FROM misc WHERE id='MOTD'});
+               $BODY->param(MOTD => $motd);
+       }
+       return $BODY;
+}
+
+1;
diff --git a/ND/Web/Pages/PlanetNaps.pm b/ND/Web/Pages/PlanetNaps.pm
new file mode 100644 (file)
index 0000000..13aafb5
--- /dev/null
@@ -0,0 +1,59 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::PlanetNaps;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{planetNaps} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       my $error;
+
+       $ND::TEMPLATE->param(TITLE => 'List planet naps');
+
+       return $ND::NOACCESS unless isHC();
+
+       my $query = $DBH->prepare(qq{Select coords(x,y,z), ((ruler || ' OF ') || p.planet) as planet,race, size, score, value, xp, sizerank, scorerank, valuerank, xprank, p.value - p.size*200 - coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue, planet_status,hit_us, alliance,relationship,nick from current_planet_stats p LEFT OUTER JOIN covop_targets c ON p.id = c.planet WHERE planet_status IN ('Friendly','NAP') order by x,y,z asc});
+
+       $query->execute or $error .= p($DBH->errstr);
+       my @planets;
+       my $i = 0;
+       while (my $planet = $query->fetchrow_hashref){
+               $i++;
+               $planet->{ODD} = $i % 2;
+               push @planets,$planet;
+       }
+       $BODY->param(Planets => \@planets);
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+
+1;
diff --git a/ND/Web/Pages/Points.pm b/ND/Web/Pages/Points.pm
new file mode 100644 (file)
index 0000000..30512fb
--- /dev/null
@@ -0,0 +1,67 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Points;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{points} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       $ND::TEMPLATE->param(TITLE => 'Top Members');
+
+       return $ND::NOACCESS unless isMember();
+
+       my $type = "total";
+       if (defined param('type') && param('type') =~ /^(defense|attack|total|humor|scan|rank)$/){
+               $type = $1;
+       }
+       $type .= '_points' unless ($type eq 'rank');
+
+       my $order = 'DESC';
+       $order = 'ASC' if ($type eq 'rank');
+
+       my $limit = 'LIMIT 10';
+       $limit = '' if isHC();
+
+       my $query = $DBH->prepare("SELECT username,defense_points,attack_points,scan_points,humor_points, (attack_points+defense_points+scan_points/20) as total_points, rank FROM users WHERE uid IN (SELECT uid FROM groupmembers WHERE gid = 2) ORDER BY $type $order $limit");
+       $query->execute;
+
+       my @members;
+       my $i = 0;
+       while (my ($username,$defense,$attack,$scan,$humor,$total,$rank) = $query->fetchrow){
+               $i++;
+               push @members,{Username => $username, Defense => $defense, Attack => $attack
+                       , Scan => $scan, Humor => $humor, Total => $total, Rank => $rank, ODD => $i % 2};
+       }
+       $BODY->param(Members => \@members);
+       return $BODY;
+}
+
+1;
diff --git a/ND/Web/Pages/Raids.pm b/ND/Web/Pages/Raids.pm
new file mode 100644 (file)
index 0000000..fcaf6b1
--- /dev/null
@@ -0,0 +1,228 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Raids;
+use strict;
+use warnings FATAL => 'all';
+use ND::Include;
+use POSIX;
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{raids} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       #if ($uri =~ m{^/.*/(\w+)$}){
+       #       param('list',$1);
+       #}
+}
+
+sub process {
+       $ND::XML = 1 if param('xml');
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+
+       my $raid;
+       if (defined param('raid')){
+               my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords FROM raids WHERE id = ? AND open AND not removed AND id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)});
+               $raid = $DBH->selectrow_hashref($query,undef,param('raid'),$ND::UID);
+       }
+
+       if (defined param('cmd') && defined param('target') && defined param('wave') && param('target') =~ /^(\d+)$/ && param('wave') =~ /^(\d+)$/){
+               my $target = param('target');
+               my $wave = param('wave');
+
+               my $findtarget = $DBH->prepare("SELECT rt.id FROM raid_targets rt NATURAL JOIN raid_access ra NATURAL JOIN groupmembers where uid = ? AND id = ?");
+               my $result = $DBH->selectrow_array($findtarget,undef,$ND::UID,$target);
+               if ($result != $target){
+                       return $ND::NOACCESS;   
+               }
+
+               $DBH->begin_work;
+               if (param('cmd') eq 'Claim'){
+                       my $claims = $DBH->prepare(qq{SELECT username FROM raid_claims NATURAL JOIN users WHERE target = ? AND wave = ?});
+                       $claims->execute($target,$wave);
+                       if ($claims->rows == 0){
+                               my $query = $DBH->prepare(q{INSERT INTO raid_claims (target,uid,wave) VALUES(?,?,?)});
+                               if($query->execute($target,$ND::UID,$wave)){
+                                       log_message $ND::UID,"Claimed target $target wave $wave.";
+                               }
+                       }
+               }
+               if (param('cmd') eq 'Join'){
+                       my $claims = $DBH->prepare(qq{SELECT username FROM raid_claims
+                               NATURAL JOIN users WHERE target = ? AND wave = ? AND
+                               joinable = TRUE});
+                       $claims->execute($target,$wave);
+                       if ($claims->rows != 0){
+                               my $query = $DBH->prepare(q{INSERT INTO raid_claims (target,uid,wave,joinable) VALUES(?,?,?,TRUE)});
+                               if($query->execute($target,$ND::UID,$wave)){
+                                       log_message $ND::UID,"Joined target $target wave $wave.";
+                               }
+                       }
+               }
+               if (param('cmd') eq 'set' && defined param('joinable') && param('joinable') =~ /(TRUE|FALSE)/){
+                       my $claims = $DBH->prepare(qq{SELECT username FROM raid_claims NATURAL JOIN users WHERE target = ? AND wave = ? AND uid = ?});
+                       $claims->execute($target,$wave,$ND::UID);
+                       if ($claims->rows != 0){
+                               $DBH->do(q{UPDATE raid_claims SET joinable = ? WHERE target = ? AND wave = ?},undef,$1,$target,$wave)
+                       }
+               }
+               if (param('cmd') eq 'Unclaim'){
+                       my $query = $DBH->prepare(qq{DELETE FROM raid_claims WHERE target = ? AND uid = ? AND wave = ?});
+                       if ($query->execute($target,$ND::UID,$wave)){
+                               log_message $ND::UID,"Unclaimed target $target wave $wave.";
+                       }
+               }
+               $DBH->commit;
+               if ($ND::XML && $raid){
+                       generateClaimXml($raid,undef,$target);
+               }
+       }
+       if ($ND::XML && $raid && param('cmd') eq 'update' ){
+               my $from;
+               if (param('from') =~ /^[-\d\ \:\.]+$/){
+                       $from = param('from');
+               }
+               generateClaimXml($raid,$from);
+       }
+       if ($ND::XML && param('cmd') eq 'gettargets' ){
+               $_ = listTargets();
+               $BODY->param(TargetList => $_);
+       }
+
+       return $BODY if $ND::XML;
+
+       $ND::TEMPLATE->param(TITLE => 'Raids');
+       #$ND::TEMPLATE->param(HEADER => '<script type="text/javascript" src="raid.js"></script>');
+       if ($raid){#We have a raid, so list all targets
+               $BODY->param(Raid => $raid->{id});
+               $BODY->param(Ajax => $ND::AJAX);
+               my $noingal = '';
+               my $planet;
+               if ($ND::PLANET){
+                       my $query = $DBH->prepare("SELECT value, score,x,y FROM current_planet_stats WHERE id = ?");
+                       $planet = $DBH->selectrow_hashref($query,undef,$ND::PLANET);
+                       $noingal = "AND NOT (x = $planet->{x} AND y = $planet->{y})";
+               }
+               $BODY->param(Message => parseMarkup($raid->{message}));
+               $BODY->param(LandingTick => parseMarkup($raid->{tick}));
+               my $targetquery = $DBH->prepare(qq{SELECT r.id, r.planet, size, score, value, coords(p.x,p.y,p.z), race, p.value - p.size*200 -coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue, comment
+                       FROM current_planet_stats p 
+                       JOIN raid_targets r ON p.id = r.planet 
+                       LEFT OUTER JOIN covop_targets c ON p.id = c.planet
+                       WHERE r.raid = ?
+                       $noingal
+                       ORDER BY size});
+               $targetquery->execute($raid->{id});
+               my @targets;
+               while (my $target = $targetquery->fetchrow_hashref){
+                       my %target;
+                       $target{Id} = $target->{id};
+                       $target{Race} = $target->{race};
+                       $target{Ajax} = $ND::AJAX;
+                       my $num = pow(10,length($target->{score})-2);
+                       $target{Score} = ceil($target->{score}/$num)*$num;
+                       $num = pow(10,length($target->{value})-2);
+                       $target{Value} = ceil($target->{value}/$num)*$num;
+                       $num = pow(10,length($target->{size})-2);
+                       $target{Size} = floor($target->{size}/$num)*$num;
+                       $num = pow(10,length($target->{fleetvalue})-2);
+                       $target{FleetValue} = floor($target->{fleetvalue}/$num)*$num;
+                       if (defined $target->{resvalue}){
+                               $num = pow(10,length($target->{resvalue})-2);
+                               $target{ResValue} = floor($target->{resvalue}/$num)*$num;
+                       }
+                       $target{comment} = parseMarkup($target->{comment}) if ($target->{comment});
+
+                       my $scans = $DBH->prepare(q{SELECT DISTINCT ON (type) type, tick, scan FROM scans 
+                               WHERE planet = ? AND type ~ 'Unit|Planet|Military|.* Analysis' AND tick + 24 > tick()
+                               GROUP BY type, tick, scan ORDER BY type ,tick DESC});
+                       $scans->execute($target->{planet});
+                       my %scans;
+                       while (my $scan = $scans->fetchrow_hashref){
+                               $scans{$scan->{type}} = $scan;
+                       }
+
+                       my @scans;
+                       for my $type ('Planet','Unit','Military','Surface Analysis','Technology Analysis'){
+                               next unless exists $scans{$type};
+                               my $scan = $scans{$type};
+                               if ($ND::TICK - $scan->{tick} > 5){
+                                       $scan->{scan} =~ s{<table( cellpadding="\d+")?>}{<table$1 class="old">};
+                               }
+                               if ($type eq 'Planet'){
+                                       $target{PlanetScan} = $scan->{scan};
+                                       next;
+                               }
+                               push @scans,{Scan => $scan->{scan}};
+                       }
+                       $target{Scans} = \@scans;
+
+                       my @roids;
+                       my @claims;
+                       my $size = $target{Size};
+                       for (my $i = 1; $i <= $raid->{waves}; $i++){
+                               my $roids = floor(0.25*$size);
+                               $size -= $roids;
+                               my $xp;
+                               if ($planet){
+                                       $xp = max(0,floor($roids * 10 * (min(2,$target{Score}/$planet->{score}) + min(2,$target{Value}/$planet->{value})-1)));
+                               }
+                               push @roids,{Wave => $i, Roids => $roids, XP => $xp};
+                               if ($ND::AJAX){
+                                       push @claims,{Wave => $i, Target => $target{Id}}
+                               }else{
+                                       push @claims,{Wave => $i, Target => $target{Id}, Command => 'Claim'
+                                               , Owner => 1, Raid => $raid->{id}, Joinable => 0};
+                               }
+                       }
+                       $target{Roids} = \@roids;
+                       $target{Claims} = \@claims;
+
+                       push @targets,\%target;
+               }
+               $BODY->param(Targets => \@targets);
+       }else{#list raids if we haven't chosen one yet
+               my $query = $DBH->prepare(q{SELECT id,released_coords FROM raids WHERE open AND not removed AND
+                       id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)});
+               $query->execute($ND::UID);
+               my @raids;
+               while (my $raid = $query->fetchrow_hashref){
+                       push @raids,{Raid => $raid->{id}, ReleasedCoords => $raid->{released_coords}, isBC => isBC()};
+               }
+               $BODY->param(Raids => \@raids);
+
+               if (isBC()){
+                       my $query = $DBH->prepare(q{SELECT id,open FROM raids WHERE not removed AND (not open 
+                               OR id NOT IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?))});
+                       $query->execute($ND::UID);
+                       my @raids;
+                       while (my $raid = $query->fetchrow_hashref){
+                               push @raids,{Raid => $raid->{id}, Open => $raid->{open}};
+                       }
+                       $BODY->param(ClosedRaids => \@raids);
+               }
+       }
+       return $BODY;
+}
+1;
diff --git a/ND/Web/Pages/Resources.pm b/ND/Web/Pages/Resources.pm
new file mode 100644 (file)
index 0000000..66b3444
--- /dev/null
@@ -0,0 +1,75 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Resources;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{resources} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       my $error;
+
+       $ND::TEMPLATE->param(TITLE => 'Alliance Resources');
+
+       return $ND::NOACCESS unless isHC();
+
+       my $order = "respplanet DESC";
+       if (defined param('order') && param('order') =~ /^(size|score|resources|respplanet|nscore|nscore2|nscore3)$/){
+               $order = "$1 DESC";
+       }
+
+
+       my $query = $DBH->prepare(qq{
+               SELECT a.id,a.name,a.relationship,s.members,s.score,s.size,r.resources,r.planets, resources/planets AS respplanet, 
+               resources / 300 AS scoregain, score + (resources / 300) AS nscore, 
+               (resources/planets*LEAST(members,60))/300 AS scoregain2, score + (resources/planets*LEAST(members,60))/300 AS nscore2,
+               (s.size::int8*(1464-tick())*250)/100 + score + (resources/planets*LEAST(members,60))/300 AS nscore3,
+               (s.size::int8*(1464-tick())*250)/100 AS scoregain3
+               FROM (SELECT alliance_id AS id,sum(metal+crystal+eonium) AS resources, count(*) AS planets 
+               FROM planets p join covop_targets c ON p.id = c.planet GROUP by alliance_id) r 
+               NATURAL JOIN alliances a 
+               LEFT OUTER JOIN (SELECT * FROM alliance_stats WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON a.id = s.id
+               ORDER BY $order
+               });
+       $query->execute;
+       my @alliances;
+       my $i = 0;
+       while (my $alliance = $query->fetchrow_hashref){
+               $i++;
+               $alliance->{ODD} = $i % 2;
+               push @alliances,$alliance;
+       }
+       $BODY->param(Alliances => \@alliances);
+
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+1;
diff --git a/ND/Web/Pages/Top100.pm b/ND/Web/Pages/Top100.pm
new file mode 100644 (file)
index 0000000..a962b2d
--- /dev/null
@@ -0,0 +1,89 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Top100;
+use strict;
+use warnings FATAL => 'all';
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{top100} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       #TODO: Need to fix some links first
+       #if ($uri =~ m{^/[^/]+/(\w+)}){
+       #       param('order',$1);
+       #}
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+       $ND::TEMPLATE->param(TITLE => 'Top100 ');
+
+       my $error = '';
+
+       $BODY->param(isHC => isHC());
+
+       return $ND::NOACCESS unless isMember();
+
+       my $offset = 0;
+       if (defined param('offset') && param('offset') =~ /^(\d+)$/){
+               $offset = $1;
+       }
+       $BODY->param(Offset => $offset);
+       $BODY->param(PrevOffset => $offset - 100);
+       $BODY->param(NextOffset => $offset + 100);
+
+       my $order = 'scorerank';
+       if (defined param('order') && param('order') =~ /^(scorerank|sizerank|valuerank|xprank|hit_us)$/){
+               $order = $1;
+       }
+       $BODY->param(Order => $order);
+       $order .= ' DESC' if ($order eq 'hit_us');
+
+
+       my $extra_columns = '';
+       if (isHC()){
+               $extra_columns = ",planet_status,hit_us, alliance,relationship,nick";
+       }
+       my $query = $DBH->prepare(qq{SELECT coords(x,y,z),((ruler || ' OF ') || planet) as planet,race,
+               size, score, value, xp, sizerank, scorerank, valuerank, xprank
+               $extra_columns FROM current_planet_stats ORDER BY $order LIMIT 100 OFFSET ?});
+       $query->execute($offset) or $error .= p($DBH->errstr);
+       my @planets;
+       my $i = 0;
+       while (my $planet = $query->fetchrow_hashref){
+               if (isHC){
+                       $planet->{isHC} = 1;
+               }
+               $i++;
+               $planet->{ODD} = $i % 2;
+               push @planets,$planet;
+       }
+       $BODY->param(Planets => \@planets);
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+
+1;
diff --git a/ND/Web/Pages/Users.pm b/ND/Web/Pages/Users.pm
new file mode 100644 (file)
index 0000000..a53f9a5
--- /dev/null
@@ -0,0 +1,152 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+package ND::Web::Pages::Users;
+use strict;
+use warnings FATAL => 'all';
+use ND::Include;
+use CGI qw/:standard/;
+use ND::Web::Include;
+
+$ND::PAGES{users} = {parse => \&parse, process => \&process, render=> \&render};
+
+sub parse {
+       my ($uri) = @_;
+       #if ($uri =~ m{^/.*/(\w+)$}){
+       #       param('list',$1);
+       #}
+}
+
+sub process {
+
+}
+
+sub render {
+       my ($DBH,$BODY) = @_;
+
+       $ND::TEMPLATE->param(TITLE => 'Users');
+
+       return $ND::NOACCESS  unless isHC();
+
+       my $error = '';
+       my $user;
+       if (defined param('user') && param('user') =~ /^(\d+)$/){
+               my $query = $DBH->prepare(q{
+                       SELECT uid,username,hostmask,coords(x,y,z) AS planet,attack_points,defense_points,scan_points,humor_points  
+                       FROM users u LEFT OUTER JOIN current_planet_stats p ON u.planet = p.id
+                       WHERE uid = ?;
+                       }) or $error .= "<p> Something went wrong: </p>";
+               $user = $DBH->selectrow_hashref($query,undef,$1) or $error.= "<p> Something went wrong: ".$DBH->errstr."</p>";
+       }
+
+
+       if ($user && defined param('cmd') && param('cmd') eq 'change'){
+               $DBH->begin_work;
+               for my $param (param()){
+                       if ($param =~ /^c:(\w+)$/){
+                               my $column = $1;
+                               my $value = param($column);
+                               if ($column eq 'planet'){
+                                       if ($value eq ''){
+                                               $value = undef;
+                                       }elsif($value =~ /^(\d+)\D+(\d+)\D+(\d+)$/){
+                                               ($value) = $DBH->selectrow_array(q{SELECT id FROM
+                                                       current_planet_stats WHERE x = ? and y = ? and z =?}
+                                                       ,undef,$1,$2,$3);
+                                       }
+                               }
+                               if ($DBH->do(qq{UPDATE users SET $column = ? WHERE uid = ? }
+                                               ,undef,$value,$user->{uid})){
+                                       $user->{$column} = param($column);
+                                       log_message $ND::UID,"HC set $column to $value for user: $user->{uid}";
+                               }else{
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+               }
+               my $groups = $DBH->prepare('SELECT gid,groupname FROM groups');
+               my $delgroup = $DBH->prepare(q{DELETE FROM groupmembers WHERE uid = ? AND gid = ?});
+               my $addgroup = $DBH->prepare(q{INSERT INTO groupmembers (uid,gid) VALUES(?,?)});
+               $groups->execute();
+               while (my $group = $groups->fetchrow_hashref){
+                       my $query;
+                       next unless defined param($group->{gid});
+                       if (param($group->{gid}) eq 'remove'){
+                               $query = $delgroup;
+                       }elsif(param($group->{gid}) eq 'add'){
+                               $query = $addgroup;
+                       }
+                       if ($query){
+                               if ($query->execute($user->{uid},$group->{gid})){
+                                       my ($action,$a2) = ('added','to');
+                                       ($action,$a2) = ('removed','from') if param($group->{gid}) eq 'remove';
+                                       log_message $ND::UID,"HC $action user: $user->{uid} ($user->{username}) $a2 group: $group->{gid} ($group->{groupname})";
+                               }else{
+                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               }
+                       }
+               }
+               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+       }
+
+       if ($user){
+               $BODY->param(User => $user->{uid});
+               $BODY->param(Username => $user->{username});
+               $BODY->param(Hostmask => $user->{hostmask});
+               $BODY->param(Planet => $user->{planet});
+               $BODY->param(Attack_points => $user->{attack_points});
+               $BODY->param(Defense_points => $user->{defense_points});
+               $BODY->param(Scan_points => $user->{scan_points});
+               $BODY->param(humor_points => $user->{humor_points});
+
+               my $groups = $DBH->prepare(q{SELECT g.gid,g.groupname,uid FROM groups g LEFT OUTER JOIN (SELECT gid,uid FROM groupmembers WHERE uid = ?) AS gm ON g.gid = gm.gid});
+               $groups->execute($user->{uid});
+
+               my @addgroups;
+               my @remgroups;
+               while (my $group = $groups->fetchrow_hashref){
+                       if ($group->{uid}){
+                               push @remgroups,{Id => $group->{gid}, Name => $group->{groupname}};
+                       }else{
+                               push @addgroups,{Id => $group->{gid}, Name => $group->{groupname}};
+                       }
+               }
+               $BODY->param(RemoveGroups => \@remgroups);
+               $BODY->param(AddGroups => \@addgroups);
+
+       }else{
+               my $query = $DBH->prepare(qq{SELECT u.uid,username,TRIM(',' FROM concat(g.groupname||',')) AS groups
+                       FROM users u LEFT OUTER JOIN (groupmembers gm NATURAL JOIN groups g) ON gm.uid = u.uid
+                       WHERE u.uid > 0
+                       GROUP BY u.uid,username
+                       ORDER BY username})or $error .= $DBH->errstr;
+               $query->execute or $error .= $DBH->errstr;
+               my @users;
+               my $i = 0;
+               while (my $user = $query->fetchrow_hashref){
+                       $i++;
+                       $user->{ODD} = $i % 2;
+                       push @users, $user;
+               }
+               $BODY->param(Users => \@users);
+       }
+       $BODY->param(Error => $error);
+       return $BODY;
+}
+1;
diff --git a/addintel.pl b/addintel.pl
deleted file mode 100644 (file)
index b3d5aed..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Web::Forum;
-
-$ND::TEMPLATE->param(TITLE => 'Add Intel and Scans');
-
-our $BODY;
-our $DBH;
-our $ERROR;
-my $error;
-
-die "You don't have access" unless isMember();
-
-if (defined param('cmd')){
-       if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
-               my $findscan = $DBH->prepare("SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 48");
-               my $addscan = $DBH->prepare('INSERT INTO scans (scan_id,tick,"type") VALUES (?,tick(),?)');
-               my $addpoint = $DBH->prepare('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ');
-               my $intel = param('intel');
-               my @scans;
-               while ($intel =~ m/http:\/\/game.planetarion.com\/showscan.pl\?scan_id=(\d+)/g){
-                       my %scan;
-                       $scan{Scan} = $1;
-                       $scan{Message} = "Scan $1: ";
-                       $findscan->execute($1);
-                       if ($findscan->rows == 0){
-                               if ($addscan->execute($1,$ND::UID)){
-                                       $addpoint->execute($ND::UID);
-                                       $scan{Message} .= '<i>added</i>';
-                               }else{
-                                       $scan{Message} .= "<b>something went wrong:</b> <i>$DBH->errstr</i>";
-                               }
-                       }else{
-                               $scan{Message} .= '<b>already exists</b>';
-                       }
-                       push @scans,\%scan;
-               }
-               $BODY->param(Scans => \@scans);
-               my $tick = $ND::TICK;
-               $tick = param('tick') if $tick =~ /^(\d+)$/;
-               my $addintel = $DBH->prepare(qq{SELECT add_intel(?,?,?,?,?,?,?,?,?,?,?)});
-               while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\*?\s+.+(?:Ter|Cat|Xan|Zik)?\s+(\d+)\s+(Attack|Defend)\s+(\d+)/g){
-                       $addintel->execute($tick,$9, $1,$2,$3,$4,$5,$6,$7,$8,$ND::UID) or $error .= $DBH->errstr;
-               }
-       }
-       if (param('cmd') eq 'submit_message'){
-               my $board = {id => 12};
-               my $subject = param('subject');
-               unless ($subject){
-                       if (param('intel') =~ /(.*\w.*)/){
-                               $subject = $1;
-                       }
-                       
-               }
-               if (my $thread = addForumThread $DBH,$board,$ND::UID,$subject){
-                       $error .= p 'Intel message added' if addForumPost $DBH,$thread,$ND::UID,param('intel')
-               }
-       }
-}
-$BODY->param(Tick => $ND::TICK);
-$BODY->param(Error => $error);
-1;
diff --git a/alliances.pl b/alliances.pl
deleted file mode 100644 (file)
index 4f89a48..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-our $BODY;
-our $DBH;
-our $ERROR;
-my $error;
-
-$ND::TEMPLATE->param(TITLE => 'Alliances');
-
-die "You don't have access" unless isHC();
-
-my $alliance;
-if (defined param('alliance') && param('alliance') =~ /^(\d+)$/){
-       my $query = $DBH->prepare(q{SELECT id,name, relationship FROM alliances WHERE id = ?});
-       $alliance = $DBH->selectrow_hashref($query,undef,$1);
-}
-if ($alliance && defined param('cmd') && param ('cmd') eq 'change'){
-       $DBH->begin_work;
-       if (param('crelationship')){
-               my $value = escapeHTML(param('relationship'));
-               if ($DBH->do(q{UPDATE alliances SET relationship = ? WHERE id =?}
-                               ,undef,$value,$alliance->{id})){
-                       $alliance->{relationship} = $value;
-                       log_message $ND::UID,"HC set alliance: $alliance->{id} relationship: $value";
-               }else{
-                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-               }
-       }
-       my $coords = param('coords');
-       my $findplanet = $DBH->prepare(q{SELECT id FROM current_planet_stats WHERE x = ? AND y = ? AND z = ?});
-       my $addplanet = $DBH->prepare(q{
-UPDATE planets SET alliance_id = $2, nick = coalesce($3,nick)
-WHERE id = $1;
-               });
-       while ($coords =~ m/(\d+):(\d+):(\d+)(?:\s+nick=\s*(\S+))?/g){
-               my ($id) = $DBH->selectrow_array($findplanet,undef,$1,$2,$3) or $ERROR .= p $DBH->errstr;
-               if ($addplanet->execute($id,$alliance->{id},$4)){
-                       my $nick = '';
-                       $nick = '(nick $4)' if defined $4;
-                       $error .= "<p> Added planet $1:$2:$3 $nick to this alliance</p>";
-                       intel_log $ND::UID,$id,"HC Added planet $1:$2:$3 $nick to alliance: $alliance->{id} ($alliance->{name})";
-               }else{
-                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-               }
-       }
-       $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-}
-
-if ($alliance){
-       $BODY->param(Alliance => $alliance->{name});
-       $BODY->param(Id => $alliance->{id});
-       my @relationships;
-       for my $relationship ("&nbsp;","Friendly", "NAP", "Hostile"){
-               push @relationships,{Rel => $relationship, Selected => defined $alliance->{relationship} && $relationship eq $alliance->{relationship}}
-       }
-       $BODY->param(Relationships => \@relationships);
-
-       my $order = "p.x,p.y,p.z";
-       if (defined param('order') && param('order') =~ /^(score|size|value|xp|hit_us|race)$/){
-               $order = "$1 DESC";
-       }
-       my $members = $DBH->prepare(qq{
-SELECT coords(x,y,z), nick, ruler, planet, race, size, score, value, xp,
-       planet_status,hit_us, sizerank, scorerank, valuerank, xprank
-       FROM current_planet_stats p
-WHERE p.alliance_id = ?
-ORDER BY $order});
-       my @members;
-       $members->execute($alliance->{id});
-       my $i = 0;
-       while (my $member = $members->fetchrow_hashref){
-               $i++;
-               $member->{ODD} = $i % 2;
-               push @members,$member;
-       }
-       $BODY->param(Members => \@members);
-
-       my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin, t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',qq{not ingal AND (t.alliance_id = ? OR t.alliance_id = ?)
-       AND (i.mission = 'Defend' OR i.mission = 'AllyDef')
-       AND (t.alliance_id != ? OR t.alliance_id IS NULL OR o.alliance_id != ? OR o.alliance_id IS NULL)
-       AND i.sender NOT IN (SELECT planet FROM users u NATURAL JOIN groupmembers gm WHERE gid = 8 AND planet IS NOT NULL)
-                       }));
-       $query->execute($alliance->{id},$alliance->{id},$alliance->{id},$alliance->{id}) or $error .= $DBH->errstr;
-
-       my @intel;
-       $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;
-       }
-       $BODY->param(Intel => \@intel);
-}else{
-
-       my $order = "score DESC";
-       if (defined param('order') && param('order') =~ /^(score|kscore|size|ksize|members|kmem|kxp|kxp|scavg|kscavg|siavg|ksiavg|kxpavg|kvalue|kvalavg)$/){
-               $order = "$1 DESC";
-       }
-       my $query = $DBH->prepare(qq{
-SELECT DISTINCT a.id,name,COALESCE(s.score,SUM(p.score)) AS score,COALESCE(s.size,SUM(p.size)) AS size,s.members,count(*) AS kmem,
-       COALESCE(SUM(p.score),-1) AS kscore, COALESCE(SUM(p.size),-1) AS ksize, COALESCE(SUM(p.xp),-1) AS kxp,COALESCE(SUM(p.value),-1) AS kvalue,
-       COALESCE(s.score/LEAST(s.members,60),-1) AS scavg, COALESCE(AVG(p.score)::int,-1) AS kscavg, COALESCE(s.size/s.members,-1) AS siavg,
-       COALESCE(AVG(p.size)::int,-1) AS ksiavg, COALESCE(AVG(p.xp)::int,-1) AS kxpavg, COALESCE(AVG(p.value)::int,-1) AS kvalavg
-FROM alliances a 
-       LEFT OUTER JOIN (SELECT * FROM alliance_stats WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON s.id = a.id
-       LEFT OUTER JOIN current_planet_stats p ON p.alliance_id = a.id
-GROUP BY a.id,a.name,s.score,s.size,s.members
-ORDER BY $order
-               })or $error .= $DBH->errstr;
-       $query->execute or $error .= $DBH->errstr;
-       my @alliances;
-       my $i = 0;
-       while (my $alliance = $query->fetchrow_hashref){
-               next unless (defined $alliance->{score} || $alliance->{kscore} > 0);
-               $i++;
-               $alliance->{ODD} = $i % 2;
-               push @alliances, $alliance;
-       }
-       $BODY->param(Alliances => \@alliances);
-}
-$BODY->param(Error => $error);
-1;
diff --git a/calls.pl b/calls.pl
deleted file mode 100644 (file)
index 342f47d..0000000
--- a/calls.pl
+++ /dev/null
@@ -1,227 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-our $BODY;
-our $DBH;
-my $error;
-
-$ND::TEMPLATE->param(TITLE => 'Defense Calls');
-
-die "You don't have access" unless isDC();
-
-my $call;
-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 
-       JOIN users u ON c.member = u.uid
-       LEFT OUTER JOIN users dc ON c.dc = dc.uid
-       JOIN current_planet_stats p ON u.planet = p.id
-WHERE c.id = ?});
-       $call = $DBH->selectrow_hashref($query,undef,$1);
-}
-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_message $ND::UID,"DC updated landing tick for call $call->{id}";
-                       }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-               if (param('cinfo')){
-                       if ($DBH->do(q{UPDATE calls SET info = ? WHERE id = ?}
-                                       ,undef,param('info'),$call->{id})){
-                               $call->{info} = param('info');
-                               log_message $ND::UID,"DC updated info for call $call->{id}";
-                       }else{
-                               $error .= "<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$/){
-               $error .= "test";
-               my $extra_vars = '';
-               if (param('cmd') eq 'Cover call'){
-                       $extra_vars = ", covered = TRUE, open = FALSE";
-               }elsif (param('cmd') eq 'Uncover call'){
-                       $extra_vars = ", covered = FALSE, open = TRUE";
-               }elsif (param('cmd') eq 'Ignore call'){
-                       $extra_vars = ", covered = FALSE, open = FALSE";
-               }elsif (param('cmd') eq 'Open call'){
-                       $extra_vars = ", covered = FALSE, open = TRUE";
-               }
-               if ($DBH->do(qq{UPDATE calls SET dc = ? $extra_vars WHERE id = ?},
-                       ,undef,$ND::UID,$call->{id})){
-                       $call->{covered} = (param('cmd') eq 'Cover call');
-                       $call->{open} = (param('cmd') =~ /^(Uncover|Open) call$/);
-                       $call->{DC} = $ND::USER;
-               }else{
-                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-               }
-       }elsif(param('cmd') eq 'Remove'){
-               $DBH->begin_work;
-               my $query = $DBH->prepare(q{DELETE FROM incomings WHERE id = ? AND call = ?});
-               for my $param (param()){
-                       if ($param =~ /^change:(\d+)$/){
-                               if($query->execute($1,$call->{id})){
-                                       log_message $ND::UID,"DC deleted fleet: $1, call $call->{id}";
-                               }else{
-                                       $error .= "<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 = ?});
-               for my $param (param()){
-                       if ($param =~ /^change:(\d+)$/){
-                               my $shiptype = escapeHTML(param("shiptype:$1"));
-                               if($query->execute($shiptype,$1,$call->{id})){
-                                       log_message $ND::UID,"DC set fleet: $1, call $call->{id} to: $shiptype";
-                               }else{
-                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                               }
-                       }
-               }
-               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-       }
-}
-
-if ($call){
-       $BODY->param(Call => $call->{id});
-       $BODY->param(Coords => $call->{coords});
-       $BODY->param(DefensePoints => $call->{defense_points});
-       $BODY->param(LandingTick => $call->{landing_tick});
-       $BODY->param(ETA => $call->{landing_tick}-$ND::TICK);
-       $BODY->param(Info => $call->{info});
-       $BODY->param(DC => $call->{dc});
-       if ($call->{covered}){
-               $BODY->param(Cover => 'Uncover');
-       }else{
-               $BODY->param(Cover => 'Cover');
-       }
-       if ($call->{open} && !$call->{covered}){
-               $BODY->param(Ignore => 'Ignore');
-       }else{
-               $BODY->param(Ignore => 'Open');
-       }
-       my $fleets = $DBH->prepare(q{
-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;
-               push @fleets, $fleet;
-       }
-       $BODY->param(Fleets => \@fleets);
-       
-       my $attackers = $DBH->prepare(q{
-SELECT coords(p.x,p.y,p.z), p.planet_status, p.race,i.eta,i.amount,i.fleet,i.shiptype,p.relationship,p.alliance,i.id
-FROM incomings i
-       JOIN current_planet_stats p ON i.sender = p.id
-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);
-}else{
-       my $where = 'open AND c.landing_tick-6 > tick()';
-       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, 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,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';
-               }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;
-       }
-       $BODY->param(Calls => \@calls);
-}
-$BODY->param(Error => $error);
-1;
diff --git a/check.pl b/check.pl
deleted file mode 100644 (file)
index 04f49d3..0000000
--- a/check.pl
+++ /dev/null
@@ -1,183 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-no warnings qw(uninitialized);
-use ND::Include;
-
-$ND::TEMPLATE->param(TITLE => 'Check planets and galaxies');
-
-our $BODY;
-our $DBH;
-
-$BODY->param(isBC => isMember() && (isOfficer() || isBC));
-
-
-die "You don't have access" unless $ND::ATTACKER;
-
-my ($x,$y,$z);
-if (param('coords') =~ /(\d+)(?: |:)(\d+)(?:(?: |:)(\d+))?(?: |:(\d+))?/){
-       $x = $1;
-       $y = $2;
-       $z = $3;
-       $BODY->param(Coords => param('coords'));
-}else{
-       die "Bad coords";
-}
-
-if (isMember() && param('cmd') eq 'arbiter'){
-       my $query = $DBH->prepare(q{SELECT count(*) AS friendlies FROM current_planet_stats WHERE x = ? AND y = ? 
-               AND (planet_status IN ('Friendly','NAP') OR relationship IN ('Friendly','NAP'))});
-       my ($count) = $DBH->selectrow_array($query,undef,$x,$y);
-       if ($count > 0){
-               $BODY->param(Arbiter => '<b>DO NOT ATTACK THIS GAL</b>');
-       }else{
-               $BODY->param(Arbiter => '<b>KILL THESE BASTARDS</b>');
-       }
-       log_message $ND::UID,"Arbiter check on $x:$y";
-}
-
-my $where = '';
-my $extra_columns = '';
-
-$where = 'AND z = ?' if defined $z;
-if (isMember() && isOfficer()){
-       $extra_columns = ",planet_status,hit_us, alliance,relationship,nick";
-}elsif (isMember() && isBC()){
-       $extra_columns = ", planet_status,hit_us, alliance,relationship";
-}
-
-my $query = $DBH->prepare(qq{Select id,coords(x,y,z), ((ruler || ' OF ') || p.planet) as planet,race, size, score, value, xp, sizerank, scorerank, valuerank, xprank, p.value - p.size*200 - coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue  $extra_columns from current_planet_stats p LEFT OUTER JOIN covop_targets c ON p.id = c.planet where x = ? AND y = ? $where order by x,y,z asc});
-
-if (defined $z){
-       $query->execute($x,$y,$z);
-}else{
-       $query->execute($x,$y);
-       if (isMember() && (isBC() || isOfficer()) && !isHC()){
-               log_message $ND::UID,"BC browsing $x:$y";
-       }
-}
-my @planets;
-my $planet_id = undef;
-my $i = 0;
-while (my ($id,$coords,$planet,$race,$size,$score,$value,$xp,$sizerank,$scorerank,$valuerank,$xprank
-               ,$fleetvalue,$resvalue,$planet_status,$hit_us,$alliance,$relationship,$nick) = $query->fetchrow){
-       $planet_id = $id;
-       my %planet = (Coords => $coords, Planet => $planet, Race => $race, Size => "$size ($sizerank)"
-               , Score => "$score ($scorerank)", Value => "$value ($valuerank)", XP => "$xp ($xprank)"
-               , FleetValue => "$fleetvalue ($resvalue)");
-       if (isMember() && (isOfficer() || isBC())){
-               $planet{HitUs} = $hit_us;
-               $planet{Alliance} = "$alliance ($relationship)";
-               $planet{Nick} = "$nick ($planet_status)";
-               $planet{PlanetStatus} = $planet_status;
-               $planet{Relationship} = $relationship;
-               $planet{isBC} = 1;
-               if ($z && $alliance eq 'NewDawn'){
-                       log_message $ND::UID,"BC browsing ND planet $coords tick $ND::TICK";
-               }
-       }
-       $i++;
-       $planet{ODD} = $i % 2;
-       push @planets,\%planet;
-}
-$BODY->param(Planets => \@planets);
-
-if ($z && $planet_id){
-       $BODY->param(OnePlanet => 1);
-
-       my $query = $DBH->prepare(q{ 
-SELECT i.mission, i.tick AS landingtick,MIN(eta) AS eta, i.amount, coords(p.x,p.y,p.z) AS target
-FROM intel i
-       JOIN (planets
-               NATURAL JOIN planet_stats) p ON i.target = p.id
-       JOIN (planets
-               NATURAL JOIN planet_stats) p2 ON i.sender = p2.id
-WHERE  p.tick = ( SELECT max(tick) FROM planet_stats) AND i.tick > tick() AND i.uid = -1 
-       AND p2.tick = p.tick AND p2.id = ?
-GROUP BY p.x,p.y,p.z,p2.x,p2.y,p2.z,i.mission,i.tick,i.amount,i.ingal,i.uid
-ORDER BY p.x,p.y,p.z});
-       $query->execute($planet_id);
-       my @missions;
-       while (my ($mission,$landingtick,$eta,$amount,$target) = $query->fetchrow){
-               push @missions,{Target => $target, Mission => $mission, LandingTick => $landingtick
-                       , ETA => $eta, Amount => $amount};
-       }
-       $BODY->param(Missions => \@missions);
-
-       my @scans;
-       $query = $DBH->prepare(q{SELECT value,tick FROM planet_stats 
-               WHERE id = ? AND tick > tick() - 24});
-       my $scan = q{
-<p>Value the last 24 ticks</p>
-<table><tr><th>Tick</th><th>Value</th><th>Difference</th></tr>};
-       my $old = 0;
-       $query->execute($planet_id);
-       while (my($value,$tick) = $query->fetchrow){
-               my $diff = $value-$old;
-               $old = $value;
-               my $class = 'Defend';
-               $class = 'Attack' if $diff < 0;
-               $scan .= qq{<tr><td>$tick</td><td>$value</td><td class="$class">$diff</td></tr>};
-       }
-       $scan .= q{</table>};
-       push @scans, {Scan => $scan};
-
-       $query = $DBH->prepare(q{SELECT x,y,z,tick FROM planet_stats WHERE id = ?});
-       $scan = q{
-<p>Previous Coords</p>
-<table><tr><th>Tick</th><th>Value</th><th>Difference</th></tr>};
-       $query->execute($planet_id);
-       $x = $y = $z = 0;
-       while (my($nx,$ny,$nz,$tick) = $query->fetchrow){
-               if ($nx != $x || $ny != $y || $nz != $z){
-                       $x = $nx;
-                       $y = $ny;
-                       $z = $nz;
-                       $scan .= qq{<tr><td>$tick</td><td>$x:$y:$z</td></tr>};
-               }
-       }
-       $scan .= q{</table>};
-       push @scans, {Scan => $scan};
-
-       $query = $DBH->prepare(q{SELECT DISTINCT ON (type) type,scan_id, tick, scan FROM scans WHERE planet = ?
-               GROUP BY type,scan_id, tick, scan ORDER BY type,tick DESC});
-       $query->execute($planet_id);
-       my %scans;
-       while (my($type,$scan_id,$tick,$scan) = $query->fetchrow){
-               $scans{$type} = [$scan_id,$tick,$scan];
-       }
-       for my $type ('Planet','Jumpgate','Unit','Military','Fleet Analysis','Surface Analysis','Technology Analysis','News'){
-               next unless exists $scans{$type};
-               my $scan_id = $scans{$type}->[0];
-               my $tick = $scans{$type}->[1];
-               my $scan = $scans{$type}->[2];
-               if ($ND::TICK - $tick > 10){
-                       $scan =~ s{<table( cellpadding="\d+")?>}{<table$1 class="old">};
-               }
-               push @scans,{Scan => qq{
-<p><b><a href="http://game.planetarion.com/showscan.pl?scan_id=$scan_id">$type</a> Scan from tick $tick</b></p>
-$scan}};
-       }
-
-       $BODY->param(Scans => \@scans);
-}
-
-1;
diff --git a/covop.pl b/covop.pl
deleted file mode 100644 (file)
index a07c47f..0000000
--- a/covop.pl
+++ /dev/null
@@ -1,69 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-
-$ND::TEMPLATE->param(TITLE => 'CovOp Targets');
-
-our $BODY;
-our $DBH;
-
-die "You don't have access" unless isMember();
-
-my $show = q{AND ((planet_status IS NULL OR NOT planet_status IN ('Friendly','NAP')) AND  (relationship IS NULL OR NOT relationship IN ('Friendly','NAP')))};
-$show = '' if defined param('show') && param('show') eq 'all';
-if (defined param('covop') && param('covop') =~ /^(\d+)$/){
-       my $update = $DBH->prepare('UPDATE covop_targets SET covop_by = ?, last_covop = tick() WHERE planet = ? ');
-       $update->execute($ND::UID,$1);
-}
-
-my $list = '';
-my $where = '';
-if (defined param('list') && param('list') eq 'distwhores'){
-       $list = '&amp;list=distwhores';
-       $where = qq{WHERE dists > 0 $show
-ORDER BY dists DESC,COALESCE(sec_centres::float/structures*100,0)ASC}
-}else{
-       $where = qq{WHERE MaxResHack > 130000 
-               $show
-ORDER BY COALESCE(sec_centres::float/structures*100,0) ASC,MaxResHack DESC,metal+crystal+eonium DESC};
-}
-
-my $query = $DBH->prepare(qq{SELECT id, coords, metal, crystal, eonium, sec_centres::float/structures*100 AS secs, dists, last_covop, username, MaxResHack
-FROM (SELECT p.id,coords(x,y,z), metal,crystal,eonium,
-       sec_centres,NULLIF(structures,0) AS structures,dists,last_covop,
-       u.username,max_bank_hack(metal,crystal,eonium,p.value,(SELECT value FROM
-       current_planet_stats WHERE id = ?)) AS MaxResHack, planet_status, relationship
-FROM covop_targets c JOIN current_planet_stats p ON p.id = c.planet
-       LEFT OUTER JOIN users u ON u.uid = c.covop_by) AS foo
-       $where});
-$query->execute($ND::PLANET);
-
-my @targets;
-my $i = 0;
-while (my ($id,$coords,$metal,$crystal,$eonium,$seccents,$dists,$lastcovop,$user,$max) = $query->fetchrow){
-       $i++;
-       push @targets,{Username => $user, Target => $id, Coords => $coords
-               , Metal => $metal, Crystal => $crystal, Eonium => $eonium, SecCents => $seccents
-               , Dists => $dists, MaxResHack => $max, LastCovOp => $lastcovop, List => $list, ODD => $i % 2};
-}
-$BODY->param(Targets => \@targets);
-
-1;
diff --git a/defrequest.pl b/defrequest.pl
deleted file mode 100644 (file)
index c53f372..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-
-$ND::TEMPLATE->param(TITLE => 'Request Defense');
-
-our $BODY;
-our $DBH;
-my $error;
-
-die "You don't have access" unless isMember();
-
-if (defined param('cmd') && param('cmd') eq 'submit'){
-       my $insert = $DBH->prepare('INSERT INTO defense_requests (uid,message) VALUES (?,?)');
-       if($insert->execute($ND::UID,param('message'))){
-               $BODY->param(Reply => param('message'));
-       }else{
-               $error .= "<b>".$DBH->errstr."</b>";
-       }
-}
-$BODY->param(Error => $error);
-1;
diff --git a/editRaid.pl b/editRaid.pl
deleted file mode 100644 (file)
index 94ed68d..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-our $BODY;
-our $DBH;
-my $error;
-
-$ND::TEMPLATE->param(TITLE => 'Create/Edit Raids');
-
-die "You don't have access" unless isBC();
-
-my @alliances = alliances();
-$BODY->param(Alliances => \@alliances);
-
-my $raid;
-if (defined param 'raid' and param('raid') =~ /^(\d+)$/){
-       my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords,open FROM raids WHERE id = ?});
-       $raid = $DBH->selectrow_hashref($query,undef,$1);
-}
-if (defined param('cmd') && param('cmd') eq 'submit'){
-       my $query = $DBH->prepare(q{INSERT INTO raids (tick,waves,message) VALUES(?,?,'')});
-       if ($query->execute(param('tick'),param('waves'))){
-               $raid = $DBH->last_insert_id(undef,undef,undef,undef,"raids_id_seq");
-               my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords,open FROM raids WHERE id = ?});
-               $raid = $DBH->selectrow_hashref($query,undef,$raid);
-       }else{
-               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-       }
-}
-
-if ($raid && defined param('cmd')){
-       if (param('cmd') eq 'remove'){
-               $DBH->do(q{UPDATE raids SET open = FALSE, removed = TRUE WHERE id = ?},undef,$raid->{id});
-       }elsif (param('cmd') eq 'Open'){
-               if($DBH->do(q{UPDATE raids SET open = TRUE, removed = FALSE WHERE id = ?},undef,$raid->{id})){
-                       $raid->{open} = 1;
-                       $raid->{removed} = 0;
-               }
-       }elsif (param('cmd') eq 'Close'){
-               if ($DBH->do(q{UPDATE raids SET open = FALSE WHERE id = ?},undef,$raid->{id})){
-                       $raid->{open} = 0;
-               }
-       }elsif (param('cmd') eq 'showcoords'){
-               if($DBH->do(q{UPDATE raids SET released_coords = TRUE WHERE id = ?},undef,$raid->{id})){
-                       $raid->{released_coords} = 1;
-               }
-       }elsif (param('cmd') eq 'hidecoords'){
-               if($DBH->do(q{UPDATE raids SET released_coords = FALSE WHERE id = ?},undef,$raid->{id})){
-                       $raid->{released_coords} = 0;
-               }
-       }elsif (param('cmd') eq 'comment'){
-               $DBH->do(q{UPDATE raid_targets SET comment = ? WHERE id = ?}
-                       ,undef,escapeHTML(param('comment')),param('target'))
-                       or $error .= p($DBH->errstr);
-
-       }elsif (param('cmd') eq 'change'){
-               $DBH->begin_work;
-               my $message = escapeHTML(param('message'));
-               $raid->{message} = $message;
-               $raid->{waves} = param('waves');
-               $raid->{tick} = param('tick');
-               unless ($DBH->do(qq{UPDATE raids SET message = ?, tick = ?, waves = ? WHERE id = ?}
-                               ,undef,$message,param('tick'),param('waves'),$raid->{id})){
-                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-               }
-               my $sizelimit = '';
-               if (param('sizelimit') =~ /^(\d+)$/){
-                       $sizelimit = "AND p.size >= $1";
-                       unless ($DBH->do(qq{DELETE FROM raid_targets WHERE id IN (SELECT t.id FROM current_planet_stats p 
-       JOIN raid_targets t ON p.id = t.planet WHERE p.size < ? AND t.raid = ?)},undef,$1,$raid->{id})){
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-               my $targets = param('targets');
-               my $addtarget = $DBH->prepare(qq{INSERT INTO raid_targets(raid,planet) (
-       SELECT ?, id FROM current_planet_stats p WHERE x = ? AND y = ? AND COALESCE(z = ?,TRUE) $sizelimit)});
-               while ($targets =~ m/(\d+):(\d+)(?::(\d+))?/g){
-                       unless ($addtarget->execute($raid->{id},$1,$2,$3)){
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-               if (param('alliance') =~ /^(\d+)$/ && $1 != 1){
-                       log_message $ND::UID,"BC adding alliance $1 to raid";
-                       my $addtarget = $DBH->prepare(qq{INSERT INTO raid_targets(raid,planet) (
-       SELECT ?,id FROM current_planet_stats p WHERE alliance_id = ? $sizelimit)});
-                       unless ($addtarget->execute($raid->{id},$1)){
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-               my $groups = $DBH->prepare('SELECT gid,groupname FROM groups WHERE attack');
-               my $delgroup = $DBH->prepare(q{DELETE FROM raid_access WHERE raid = ? AND gid = ?});
-               my $addgroup = $DBH->prepare(q{INSERT INTO raid_access (raid,gid) VALUES(?,?)});
-               $groups->execute();
-               while (my $group = $groups->fetchrow_hashref){
-                       my $query;
-                       next unless defined param $group->{gid};
-                       if (param($group->{gid}) eq 'remove'){
-                               $query = $delgroup;
-                       }elsif(param($group->{gid}) eq 'add'){
-                               $query = $addgroup;
-                       }
-                       if ($query){
-                               unless ($query->execute($raid->{id},$group->{gid})){
-                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                               }
-                       }
-               }
-               unless ($DBH->commit){
-                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-               }
-       }
-}
-if ($raid && param('removeTarget')){
-       $error .= "test";
-       unless($DBH->do(q{DELETE FROM raid_targets WHERE raid = ? AND id = ?}
-                       ,undef,$raid->{id},param('removeTarget'))){
-               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-       }
-}
-
-my $groups = $DBH->prepare(q{SELECT g.gid,g.groupname,raid FROM groups g LEFT OUTER JOIN (SELECT gid,raid FROM raid_access WHERE raid = ?) AS ra ON g.gid = ra.gid WHERE g.attack});
-$groups->execute($raid ? $raid->{id} : undef);
-
-my @addgroups;
-my @remgroups;
-while (my $group = $groups->fetchrow_hashref){
-       if ($group->{raid}){
-               push @remgroups,{Id => $group->{gid}, Name => $group->{groupname}};
-       }else{
-               push @addgroups,{Id => $group->{gid}, Name => $group->{groupname}};
-       }
-}
-$BODY->param(RemoveGroups => \@remgroups);
-$BODY->param(AddGroups => \@addgroups);
-
-
-if ($raid){
-
-       $BODY->param(Raid => $raid->{id});
-       if($raid->{open}){
-               $BODY->param(Open => 'Close');
-       }else{
-               $BODY->param(Open => 'Open');
-       }
-       if($raid->{released_coords}){
-               $BODY->param(ShowCoords => 'hidecoords');
-               $BODY->param(ShowCoordsName => 'Hide');
-       }else{
-               $BODY->param(ShowCoords => 'showcoords');
-               $BODY->param(ShowCoordsName => 'Show');
-       }
-       $BODY->param(Waves => $raid->{waves});
-       $BODY->param(LandingTick => $raid->{tick});
-       $BODY->param(Message => $raid->{message});
-       
-       my $order = "p.x,p.y,p.z";
-       if (param('order') && param('order') =~ /^(score|size|value|xp|race)$/){
-               $order = "$1 DESC";
-       }
-
-       my $targetquery = $DBH->prepare(qq{SELECT r.id,coords(x,y,z),raid,comment,size,score,value,race,planet_status AS planetstatus,relationship,comment
-               FROM current_planet_stats p JOIN raid_targets r ON p.id = r.planet 
-               WHERE r.raid = ?
-               ORDER BY $order});
-       $targetquery->execute($raid->{id}) or $error .= $DBH->errstr;
-       my @targets;
-       while (my $target = $targetquery->fetchrow_hashref){
-               push @targets,$target;
-       }
-       $BODY->param(Targets => \@targets);
-}else{
-       $BODY->param(Waves => 3);
-       $BODY->param(LandingTick => $ND::TICK+12);
-}
-$BODY->param(Error => $error);
-
-1;
diff --git a/forum.pl b/forum.pl
deleted file mode 100644 (file)
index e006b20..0000000
--- a/forum.pl
+++ /dev/null
@@ -1,150 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-no warnings 'uninitialized';
-use ND::Web::Forum;
-
-$ND::TEMPLATE->param(TITLE => 'Forum');
-
-our $BODY;
-our $DBH;
-our $ERROR;
-
-
-my $board;
-if(param('b')){
-my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
-FROM forum_boards fb NATURAL JOIN forum_access fa
-WHERE fb.fbid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
-       WHERE uid = $2))
-GROUP BY fb.fbid,fb.board});
-       $board = $DBH->selectrow_hashref($boards,undef,param('b'),$ND::UID) or $ERROR .= p($DBH->errstr);
-}
-
-my $thread;
-my $findThread = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject, bool_or(fa.post) AS post
-FROM forum_boards fb NATURAL JOIN forum_access fa NATURAL JOIN forum_threads ft
-WHERE ft.ftid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
-       WHERE uid = $2))
-GROUP BY ft.ftid,ft.subject});
-if(param('t')){
-       $thread = $DBH->selectrow_hashref($findThread,undef,param('t'),$ND::UID) or $ERROR .= p($DBH->errstr);
-}
-
-if (defined param('cmd') && param('cmd') eq 'forumpost'){
-       $DBH->begin_work;
-       if ($board && $board->{post}){
-               $thread = addForumThread $DBH,$board,$ND::UID,param('subject');
-       }
-       if ($thread && $thread->{post}){
-               addForumPost($DBH,$thread,$ND::UID,param('message'));
-       }
-       $DBH->commit or $ERROR .= p($DBH->errstr);
-}
-
-my $categories = $DBH->prepare(q{SELECT fcid AS id,category FROM forum_categories ORDER BY fcid});
-my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts, max(fp.time)::timestamp as last_post
-FROM forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
-WHERE ft.fbid = $1
-GROUP BY ft.ftid, ft.subject
-HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= $3
-ORDER BY last_post DESC});
-
-if ($thread){ #Display the thread
-       $BODY->param(Thread => viewForumThread $thread);
-
-}elsif($board){ #List threads in this board
-       $BODY->param(Board => $board->{board});
-       $BODY->param(Post => $board->{post});
-       $BODY->param(Id => $board->{id});
-       $threads->execute($board->{id},$ND::UID,0) or $ERROR .= p($DBH->errstr);
-       my $i = 0;
-       my @threads;
-       while (my $thread = $threads->fetchrow_hashref){
-               $i++;
-               $thread->{Odd} = $i % 2;
-               push @threads,$thread;
-       }
-       $BODY->param(Threads => \@threads);
-
-}elsif(defined param('allUnread')){ #List threads in this board
-       $BODY->param(AllUnread => 1);
-       $BODY->param(Id => $board->{id});
-       $categories->execute or $ERROR .= p($DBH->errstr);
-       my @categories;
-       my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
-FROM forum_boards fb NATURAL JOIN forum_access fa
-WHERE fb.fcid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
-       WHERE uid = $2))
-GROUP BY fb.fbid,fb.board
-ORDER BY fb.fbid
-});
-       while (my $category = $categories->fetchrow_hashref){
-               $boards->execute($category->{id},$ND::UID) or $ERROR .= p($DBH->errstr);
-               my @boards;
-               while (my $board = $boards->fetchrow_hashref){
-                       $threads->execute($board->{id},$ND::UID,1) or $ERROR .= p($DBH->errstr);
-                       my $i = 0;
-                       my @threads;
-                       while (my $thread = $threads->fetchrow_hashref){
-                               $i++;
-                               $thread->{Odd} = $i % 2;
-                               push @threads,$thread;
-                       }
-                       $board->{Threads} = \@threads;
-                       delete $board->{post};
-                       push @boards,$board if $i > 0;
-               }
-               $category->{Boards} = \@boards;
-               delete $category->{id};
-               push @categories,$category if @boards;
-       }
-       $BODY->param(Categories => \@categories);
-
-}else{ #List boards
-       $BODY->param(Overview => 1);
-       $categories->execute or $ERROR .= p($DBH->errstr);
-my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board,count(NULLIF(COALESCE(fp.fpid::boolean,FALSE) AND COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread
-FROM forum_boards fb LEFT OUTER JOIN (forum_threads ft JOIN forum_posts fp USING (ftid)) ON fb.fbid = ft.fbid LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
-WHERE fb.fcid = $1 AND 
-       fb.fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($2)))
-GROUP BY fb.fbid, fb.board
-ORDER BY fb.fbid       });
-       my @categories;
-       while (my $category = $categories->fetchrow_hashref){
-               $boards->execute($category->{id},$ND::UID) or $ERROR .= p($DBH->errstr);
-               my @boards;
-               my $i = 0;
-               while (my $board = $boards->fetchrow_hashref){
-                       $i++;
-                       $board->{Odd} = $i % 2;
-                       push @boards,$board;
-               }
-               $category->{Boards} = \@boards;
-               delete $category->{id};
-               push @categories,$category if $i > 0;
-       }
-       $BODY->param(Categories => \@categories);
-
-}
-
-1;
-
diff --git a/intel.pl b/intel.pl
deleted file mode 100644 (file)
index e5ce1e0..0000000
--- a/intel.pl
+++ /dev/null
@@ -1,225 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Web::Forum;
-use ND::Include;
-
-our $BODY;
-our $DBH;
-our $ERROR;
-my $error;
-
-$ND::TEMPLATE->param(TITLE => 'Intel');
-
-die "You don't have access" unless isIntel() || isHC();
-
-my $planet;
-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,ftid FROM current_planet_stats
-WHERE  x = ? AND y = ? AND z = ?});
-       $planet = $DBH->selectrow_hashref($query,undef,$1,$2,$3) or $ND::ERROR .= p $DBH->errstr;
-}
-
-my $showticks = 'AND (i.tick - i.eta) > (tick() - 48)';
-if (defined param('show')){
-       if (param('show') eq 'all'){
-               $showticks = '';
-       }elsif (param('show') =~ /^(\d+)$/){
-               $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
-       }
-}
-
-my $thread;
-if (defined $planet){
-       $thread = $DBH->selectrow_hashref(q{SELECT ftid AS id, subject FROM forum_threads
-               where ftid = $1},undef,$planet->{ftid}) or $ERROR .= p($DBH->errstr);
-}
-
-if (defined param('cmd') && param('cmd') eq 'coords'){
-       my $coords = param('coords');
-       $DBH->do(q{CREATE TEMPORARY TABLE coordlist (
-       x integer NOT NULL,
-       y integer NOT NULL,
-       z integer NOT NULL,
-       PRIMARY KEY (x,y,z)
-               )});
-       my $insert = $DBH->prepare(q{INSERT INTO coordlist (x,y,z) VALUES(?,?,?)});
-       while ($coords =~ m/(\d+):(\d+):(\d+)/g){
-               $insert->execute($1,$2,$3);
-       }
-       my $planets = $DBH->prepare(q{SELECT (((p.x || ':') || p.y) || ':') || p.z AS coords, alliance FROM current_planet_stats p
-       JOIN coordlist c ON p.x = c.x AND p.y = c.y AND p.z = c.z
-ORDER BY alliance, p.x, p.y, p.z});
-       $planets->execute;
-       my @planets;
-       while (my $planet = $planets->fetchrow_hashref){
-               push @planets,$planet;
-       }
-       $BODY->param(CoordList => \@planets);
-}
-if (defined $thread and defined param('cmd') and param('cmd') eq 'forumpost'){
-       addForumPost($DBH,$thread,$ND::UID,param('message'));
-}
-
-if ($planet && defined param('cmd')){
-       if (param('cmd') eq 'change'){
-               $DBH->begin_work;
-               if (param('cnick')){
-                       my $value = escapeHTML(param('nick'));
-                       if ($DBH->do(q{UPDATE planets SET nick = ? WHERE id =?}
-                                       ,undef,$value,$planet->{id})){
-                               intel_log $ND::UID,$planet->{id},"Set nick to: $value";
-                               $planet->{nick} = $value;
-                       }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-               if (param('cchannel')){
-                       my $value = escapeHTML(param('channel'));
-                       if ($DBH->do(q{UPDATE planets SET channel = ? WHERE id =?}
-                                       ,undef,$value,$planet->{id})){
-                               intel_log $ND::UID,$planet->{id},"Set channel to: $value";
-                               $planet->{channel} = $value;
-                       }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-               if (param('cstatus')){
-                       my $value = escapeHTML(param('status'));
-                       if ($DBH->do(q{UPDATE planets SET planet_status = ? WHERE id =?}
-                                       ,undef,$value,$planet->{id})){
-                               intel_log $ND::UID,$planet->{id},"Set planet_status to: $value";
-                               $planet->{planet_status} = $value;
-                       }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-               if (param('calliance')){
-                       if ($DBH->do(q{UPDATE planets SET alliance_id = NULLIF(?,-1) WHERE id =?}
-                                       ,undef,param('alliance'),$planet->{id})){
-                               intel_log $ND::UID,$planet->{id},"Set alliance_id to: ".param('alliance');
-                               $planet->{alliance_id} = param('alliance');
-                       }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-       }
-}
-
-if (param('coords')){
-       my $channel = param('coords');
-       $channel = $planet->{channel} if ($planet);
-       my $findchannel = $DBH->prepare('SELECT coords(x,y,z),alliance,nick,channel FROM current_planet_stats WHERE channel ILIKE ? ');
-       $findchannel->execute($channel);
-       my @channelusers;
-       while (my $user = $findchannel->fetchrow_hashref){
-               push @channelusers,$user;
-       }
-       $BODY->param(ChannelUsers => \@channelusers);
-}
-
-if ($planet){
-       $BODY->param(Coords => $planet->{coords});
-       $BODY->param(Planet => $planet->{id});
-       $BODY->param(Nick => $planet->{nick});
-       $BODY->param(Channel => $planet->{channel});
-       my @status;
-       for my $status ("&nbsp;","Friendly", "NAP", "Hostile"){
-               push @status,{Status => $status, Selected => defined $planet->{planet_status} && $status eq $planet->{planet_status}}
-       }
-       $BODY->param(PlanetStatus => \@status);
-       my @alliances = alliances($planet->{alliance_id});
-       $BODY->param(Alliances => \@alliances);
-
-       $BODY->param(Thread => viewForumThread $thread);
-
-       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 @incomings;
-       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 @incomings,$intel;
-       }
-       push @intellists,{Message => 'Incoming fleets', Intel => \@incomings, Origin => 1};
-
-       $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};
-               }
-               $i++;
-               $intel->{ODD} = $i % 2;
-               push @outgoings,$intel;
-       }
-       push @intellists,{Message => 'Outgoing Fleets', Intel => \@outgoings, Target => 1};
-
-       $BODY->param(IntelLIsts => \@intellists);
-
-}elsif(!param('coords')){
-       my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin, t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',qq{not ingal
-                       AND ((( t.alliance_id != o.alliance_id OR t.alliance_id IS NULL OR o.alliance_id IS NULL) AND i.mission != 'Attack')
-                               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 $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};
-       $BODY->param(IntelLIsts => \@intellists);
-}
-my $query = $DBH->prepare(q{SELECT i.id, u.username, i.message, report_date FROM intel_messages i
-       JOIN users u ON u.uid = i.uid
-       WHERE NOT handled ORDER BY report_date});
-$query->execute;
-my @messages;
-while (my $message = $query->fetchrow_hashref){
-       $message->{message} = parseMarkup($message->{message});
-       push @messages,$message;
-}
-#$BODY->param(IntelMessages => \@messages);
-$BODY->param(Error => $error);
-1;
diff --git a/launchConfirmation.pl b/launchConfirmation.pl
deleted file mode 100644 (file)
index ffe6b11..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-
-$ND::TEMPLATE->param(TITLE => 'Launch Confirmation');
-
-our $BODY;
-our $DBH;
-my $error;
-
-
-
-die "You don't have access" unless isMember();
-
-if (defined param('cmd') && param('cmd') eq 'submit'){
-       my $missions = param('mission');
-       my $findplanet = $DBH->prepare("SELECT planetid(?,?,?,?)");
-       my $findattacktarget = $DBH->prepare(q{SELECT c.target,c.wave,c.launched FROM  raid_claims c
-               JOIN raid_targets t ON c.target = t.id
-               JOIN raids r ON t.raid = r.id
-               WHERE c.uid = ? AND r.tick+c.wave-1 = ? AND t.planet = ?
-               AND r.open AND not r.removed});
-       my $finddefensetarget = $DBH->prepare(q{SELECT NULL});
-       my $addattackpoint = $DBH->prepare('UPDATE users SET attack_points = attack_points + 1 WHERE uid = ?');
-       my $launchedtarget = $DBH->prepare('UPDATE raid_claims SET launched = True WHERE uid = ? AND target = ? AND wave = ?');
-       my $addfleet = $DBH->prepare(qq{INSERT INTO fleets (uid,target,mission,landing_tick,fleet,eta,back) VALUES (?,?,?,?,(SELECT max(fleet)+1 from fleets WHERE uid = ?),?,?)});
-       my $addships = $DBH->prepare('INSERT INTO fleet_ships (fleet,ship,amount) VALUES (?,?,?)');
-
-       my $fleet = $DBH->prepare("SELECT id FROM fleets WHERE uid = ? AND fleet = 0");
-       my ($basefleet) = $DBH->selectrow_array($fleet,undef,$ND::UID);
-       unless ($basefleet){
-               my $insert = $DBH->prepare(q{INSERT INTO fleets (uid,target,mission,landing_tick,fleet,eta,back) VALUES (?,?,'Full fleet',0,0,0,0)});
-               $insert->execute($ND::UID,$ND::PLANET);
-       }
-       my @missions;
-       $DBH->begin_work;
-       while ($missions =~ m/\S+\s+(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)\s+\((?:(\d+)\+)?(\d+)\).*?(?:\d+hrs\s+)?\d+mins\s+(Attack|Defend|Return|Fake Attack|Fake Defend)(.*?)(?:Launching in tick (\d+), arrival in tick (\d+)|ETA: \d+, Return ETA: (\d+))/sg){
-               my %mission;
-
-               my $tick = $ND::TICK+$8;
-               $tick += $7 if defined $7;
-               my $eta = $8;
-               my $mission = $9;
-               my $x = $4;
-               my $y = $5;
-               my $z = $6;
-               $mission{Tick} = $tick;
-               $mission{Mission} = $mission;
-               $mission{Target} = "$x:$y:$z";
-               if ($12){
-                       $tick = $12;
-               }elsif ($13){
-                       $eta += $13;
-               }
-
-               my ($planet_id) = $DBH->selectrow_array($findplanet,undef,$x,$y,$z,$ND::TICK);
-
-               my $findtarget = $finddefensetarget;
-               if ($mission eq 'Attack'){
-                       $findtarget = $findattacktarget;
-               }elsif ($mission eq 'Defend'){
-                       $findtarget = $finddefensetarget;
-               }
-
-               $findtarget->execute($ND::UID,$tick,$planet_id);
-
-               if ($findtarget->rows == 0){
-                       $mission{Warning} = "YOU DON'T HAVE A TARGET WITH THAT LANDING TICK";
-               }elsif ($mission eq 'Attack'){
-                       my $claim = $findtarget->fetchrow_hashref;
-                       if ($claim->{launched}){
-                               $mission{Warning} = "Already launched on this target:$claim->{target},$claim->{wave},$claim->{launched}";
-                       }else{
-                               $addattackpoint->execute($ND::UID);
-                               $launchedtarget->execute($ND::UID,$claim->{target},$claim->{wave});
-                               $mission{Warning} = "OK:$claim->{target},$claim->{wave},$claim->{launched}";
-                               log_message $ND::UID,"Gave attack point for confirmation on $mission mission to $x:$y:$z, landing tick $tick";
-                       }
-               }
-
-               $addfleet->execute($ND::UID,$planet_id,$mission,$tick,$ND::UID,$eta,$tick+$eta-1) or $error .= '<p>'.$DBH->errstr.'</p>';
-               my $fleet = $DBH->last_insert_id(undef,undef,undef,undef,"fleets_id_seq");
-               $mission{Fleet} = $fleet;
-               $mission{Back} = $tick+$eta-1;
-               my $ships = $10;
-               my @ships;
-               while ($ships =~ m/((?:\w+ )*\w+)\s+\w+\s+\w+\s+(?:Steal|Normal|Emp|Normal\s+Cloaked|Pod|Struc)\s+(\d+)/g){
-                       $addships->execute($fleet,$1,$2);
-                       push @ships,{Ship => $1, Amount => $2};
-               }
-               $mission{Ships} = \@ships;
-               log_message $ND::UID,"Pasted confirmation for $mission mission to $x:$y:$z, landing tick $tick";
-               push @missions,\%mission;
-       }
-       $DBH->commit or $error .= '<p>'.$DBH->errstr.'</p>';
-       $BODY->param(Missions => \@missions);
-}
-$BODY->param(Error => $error);
-
-
-1;
diff --git a/main.pl b/main.pl
deleted file mode 100644 (file)
index 91c347e..0000000
--- a/main.pl
+++ /dev/null
@@ -1,156 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-
-$ND::TEMPLATE->param(TITLE => 'Main Page');
-
-our $BODY;
-our $DBH;
-my $error;
-
-if (defined param('cmd')){
-       if (param('cmd') eq 'fleet'){
-               $DBH->begin_work;
-               my $fleet = $DBH->prepare("SELECT id FROM fleets WHERE uid = ? AND fleet = 0");
-               my ($id) = $DBH->selectrow_array($fleet,undef,$ND::UID);
-               unless ($id){
-                       my $insert = $DBH->prepare(q{INSERT INTO fleets (uid,target,mission,landing_tick,fleet,eta,back) VALUES (?,?,'Full fleet',0,0,0,0)});
-                       $insert->execute($ND::UID,$ND::PLANET);
-                       ($id) = $DBH->selectrow_array($fleet,undef,$ND::UID);
-               }
-               my $delete = $DBH->prepare("DELETE FROM fleet_ships WHERE fleet = ?");
-               $delete->execute($id);
-               my $insert = $DBH->prepare('INSERT INTO fleet_ships (fleet,ship,amount) VALUES (?,?,?)');
-               $fleet = param('fleet');
-               $fleet =~ s/,//g;
-               while ($fleet =~ m/((?:[A-Z][a-z]+ )*[A-Z][a-z]+)\s+(\d+)/g){
-                       $insert->execute($id,$1,$2) or $error .= '<p>'.$DBH->errstr.'</p>';
-               }
-               $fleet = $DBH->prepare('UPDATE fleets SET landing_tick = tick() WHERE id = ?');
-               $fleet->execute($id);
-               $DBH->commit;
-       }elsif (param('cmd') eq 'Recall Fleets'){
-               $DBH->begin_work;
-               my $updatefleets = $DBH->prepare('UPDATE fleets SET back = tick() + (tick() - (landing_tick - eta))  WHERE uid = ? AND id = ?');
-
-               for my $param (param()){
-                       if ($param =~ /^change:(\d+)$/){
-                               if($updatefleets->execute($ND::UID,$1)){
-                                       log_message $ND::UID,"Member recalled fleet $1";
-                               }else{
-                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                               }
-                       }
-               }
-               $DBH->commit or $error .= '<p>'.$DBH->errstr.'</p>';
-       }elsif (param('cmd') eq 'Change Fleets'){
-               $DBH->begin_work;
-               my $updatefleets = $DBH->prepare('UPDATE fleets SET back = ? WHERE uid = ? AND id = ?');
-               for my $param (param()){
-                       if ($param =~ /^change:(\d+)$/){
-                               if($updatefleets->execute(param("back:$1"),$ND::UID,$1)){
-                                       log_message $ND::UID,"Member set fleet $1 to be back tick: ".param("back:$1");
-                               }else{
-                                       $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                               }
-                       }
-               }
-               $DBH->commit or $error .= '<p>'.$DBH->errstr.'</p>';
-       }
-}
-if (param('sms')){
-       my $query = $DBH->prepare('UPDATE users SET sms = ? WHERE uid = ?');
-       $query->execute(escapeHTML(param('sms')),$ND::UID);
-}
-if (isMember() && !$ND::PLANET && defined param('planet') && (param('planet') =~ m/(\d+)(?: |:)(\d+)(?: |:)(\d+)/)){
-       my $query = $DBH->prepare(q{
-UPDATE users SET planet = 
-       (SELECT id from current_planet_stats where x = ? AND y = ? AND z = ?)
-WHERE uid = ? });
-       $query->execute($1,$2,$3,$ND::UID);
-}
-if(param('oldpass') && param('pass')){
-       my $query = $DBH->prepare('UPDATE users SET password = MD5(?) WHERE password = MD5(?) AND uid = ?');
-       $query->execute(param('pass'),param('oldpass'),$ND::UID);
-}
-
-my ($motd) = $DBH->selectrow_array("SELECT value FROM misc WHERE id='MOTD'");
-
-$BODY->param(MOTD => parseMarkup($motd));
-$BODY->param(Username => $ND::USER);
-$BODY->param(isMember => isMember());
-$BODY->param(isHC => isHC());
-my @groups = map {name => $_}, sort keys %ND::GROUPS;
-$BODY->param(Groups => \@groups);
-
-
-my $query = $DBH->prepare(q{SELECT planet,defense_points,attack_points,scan_points,humor_points, (attack_points+defense_points+scan_points/20) as total_points, sms,rank FROM users WHERE uid = ?});
-
-my ($planet,$defense_points,$attack_points,$scan_points,$humor_points,$total_points,$sms,$rank) = $DBH->selectrow_array($query,undef,$ND::UID);
-
-$ND::PLANET = $planet unless $ND::PLANET;
-
-$BODY->param(NDRank => $rank);
-$BODY->param(DefensePoints => $defense_points);
-$BODY->param(AttackPoints => $attack_points);
-$BODY->param(ScanPoints => $scan_points);
-$BODY->param(HumorPoints => $humor_points);
-$BODY->param(TotalPoints => $total_points);
-
-$BODY->param(hasPlanet => $planet);
-
-if ($planet){
-       my @row = $DBH->selectrow_array('SELECT ruler,planet,coords(x,y,z),size,sizerank
-                       ,score,scorerank,value,valuerank,xp,xprank FROM current_planet_stats
-                       WHERE id = ?',undef,$planet);
-       $BODY->param(PlanetName => "$row[0] OF $row[1] ($row[2])");
-       $BODY->param(PlanetSize => "$row[3] ($row[4])");
-       $BODY->param(PlanetScore => "$row[5] ($row[6])");
-       $BODY->param(PlanetValue => "$row[7] ($row[8])");
-       $BODY->param(PlanetXP => "$row[9] ($row[10])");
-}
-
-
-$query = $DBH->prepare(q{SELECT f.fleet,f.id, coords(x,y,z) AS target, mission, sum(fs.amount) AS amount, landing_tick, back
-FROM fleets f 
-       JOIN fleet_ships fs ON f.id = fs.fleet 
-       JOIN current_planet_stats p ON f.target = p.id
-WHERE f.uid = ? AND (f.fleet = 0 OR back >= ?)
-GROUP BY f.fleet,f.id, x,y,z, mission, landing_tick,back
-ORDER BY f.fleet
-});
-
-$query->execute($ND::UID,$ND::TICK) or $error .= '<p>'.$DBH->errstr.'</p>';
-my @fleets;
-my $i = 0;
-while (my $fleet = $query->fetchrow_hashref){
-       $i++;
-       $fleet->{ODD} = $i % 2;
-       push @fleets,$fleet;
-}
-$BODY->param(Fleets => \@fleets);
-
-$BODY->param(SMS => $sms);
-$BODY->param(Error => $error);
-
-1;
-
diff --git a/memberIntel.pl b/memberIntel.pl
deleted file mode 100644 (file)
index 66e0dcd..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-our $BODY;
-our $DBH;
-my $error;
-
-$ND::TEMPLATE->param(TITLE => 'Member Intel');
-
-die "You don't have access" unless isHC();
-
-my $showticks = 'AND i.tick > tick()';
-if (defined param('show')){
-       if (param('show') eq 'all'){
-               $showticks = '';
-       }elsif (param('show') =~ /^(\d+)$/){
-               $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
-       }
-}
-
-
-my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin, coords(t.x,t.y,t.z) AS target, t.nick',"t.alliance_id = 1 $showticks"));
-$query->execute() or $error .= $DBH->errstr;
-my @intellists;
-my @incomings;
-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 @incomings,$intel;
-}
-push @intellists,{Message => 'Incoming fleets', Intel => \@incomings, Origin => 1};
-
-$query = $DBH->prepare(intelquery('o.nick,coords(o.x,o.y,o.z) AS origin,t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.alliance_id = 1 $showticks"));
-$query->execute() 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};
-       }
-       $i++;
-       $intel->{ODD} = $i % 2;
-       push @outgoings,$intel;
-}
-push @intellists,{Message => 'Outgoing Fleets', Intel => \@outgoings, Target => 1};
-
-$BODY->param(IntelLIsts => \@intellists);
-
-$BODY->param(Error => $error);
-1;
diff --git a/motd.pl b/motd.pl
deleted file mode 100644 (file)
index b324cc0..0000000
--- a/motd.pl
+++ /dev/null
@@ -1,44 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-
-$ND::TEMPLATE->param(TITLE => 'Edit MOTD');
-
-our $BODY;
-our $DBH;
-
-die "You don't have access" unless isHC();
-
-if (defined param 'cmd' and param('cmd') eq 'change'){
-       $DBH->begin_work;
-       my $query = $DBH->prepare(q{UPDATE misc SET value= ? WHERE id='MOTD'});
-       my $motd = escapeHTML(param('motd'));
-       $query->execute($motd);
-       log_message $ND::UID,"Updated MOTD";
-       $DBH->commit;
-       $BODY->param(MOTD => $motd);
-}else{
-       my ($motd) = $DBH->selectrow_array(q{SELECT value FROM misc WHERE id='MOTD'});
-       $BODY->param(MOTD => $motd);
-}
-
-1;
diff --git a/pages b/pages
deleted file mode 100644 (file)
index d03af29..0000000
--- a/pages
+++ /dev/null
@@ -1,19 +0,0 @@
-main
-check
-motd
-points
-covop
-top100
-launchConfirmation
-addintel
-defrequest
-raids
-editRaid
-calls
-intel
-users
-alliances
-memberIntel
-resources
-planetNaps
-forum
diff --git a/planetNaps.pl b/planetNaps.pl
deleted file mode 100644 (file)
index ff5a837..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-
-$ND::TEMPLATE->param(TITLE => 'List planet naps');
-
-our $BODY;
-our $DBH;
-my $error;
-
-die "You don't have access" unless isHC();
-
-
-
-my $query = $DBH->prepare(qq{Select coords(x,y,z), ((ruler || ' OF ') || p.planet) as planet,race, size, score, value, xp, sizerank, scorerank, valuerank, xprank, p.value - p.size*200 - coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue, planet_status,hit_us, alliance,relationship,nick from current_planet_stats p LEFT OUTER JOIN covop_targets c ON p.id = c.planet WHERE planet_status IN ('Friendly','NAP') order by x,y,z asc});
-
-$query->execute or $error .= p($DBH->errstr);
-my @planets;
-my $i = 0;
-while (my $planet = $query->fetchrow_hashref){
-       $i++;
-       $planet->{ODD} = $i % 2;
-       push @planets,$planet;
-}
-$BODY->param(Planets => \@planets);
-$BODY->param(Error => $error);
-
-1;
diff --git a/points.pl b/points.pl
deleted file mode 100644 (file)
index e1a1886..0000000
--- a/points.pl
+++ /dev/null
@@ -1,54 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-
-$ND::TEMPLATE->param(TITLE => 'Top Members');
-
-our $BODY;
-our $DBH;
-
-die "You don't have access" unless isMember();
-
-my $type = "total";
-if (defined param('type') && param('type') =~ /^(defense|attack|total|humor|scan|rank)$/){
-       $type = $1;
-}
-$type .= '_points' unless ($type eq 'rank');
-
-my $order = 'DESC';
-$order = 'ASC' if ($type eq 'rank');
-
-my $limit = 'LIMIT 10';
-$limit = '' if isHC();
-
-my $query = $DBH->prepare("SELECT username,defense_points,attack_points,scan_points,humor_points, (attack_points+defense_points+scan_points/20) as total_points, rank FROM users WHERE uid IN (SELECT uid FROM groupmembers WHERE gid = 2) ORDER BY $type $order $limit");
-$query->execute;
-
-my @members;
-my $i = 0;
-while (my ($username,$defense,$attack,$scan,$humor,$total,$rank) = $query->fetchrow){
-       $i++;
-       push @members,{Username => $username, Defense => $defense, Attack => $attack
-               , Scan => $scan, Humor => $humor, Total => $total, Rank => $rank, ODD => $i % 2};
-}
-$BODY->param(Members => \@members);
-
-1;
diff --git a/raids.pl b/raids.pl
deleted file mode 100644 (file)
index a3cb3cc..0000000
--- a/raids.pl
+++ /dev/null
@@ -1,210 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-use POSIX;
-our $BODY;
-our $DBH;
-our $XML;
-
-my $raid;
-if (defined param('raid')){
-       my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords FROM raids WHERE id = ? AND open AND not removed AND id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)});
-       $raid = $DBH->selectrow_hashref($query,undef,param('raid'),$ND::UID);
-}
-
-if (defined param('cmd') && defined param('target') && defined param('wave') && param('target') =~ /^(\d+)$/ && param('wave') =~ /^(\d+)$/){
-       my $target = param('target');
-       my $wave = param('wave');
-       
-       my $findtarget = $DBH->prepare("SELECT rt.id FROM raid_targets rt NATURAL JOIN raid_access ra NATURAL JOIN groupmembers where uid = ? AND id = ?");
-       my $result = $DBH->selectrow_array($findtarget,undef,$ND::UID,$target);
-       if ($result != $target){
-               die("You don't have access to that target");
-       }
-
-       $DBH->begin_work;
-       if (param('cmd') eq 'Claim'){
-               my $claims = $DBH->prepare(qq{SELECT username FROM raid_claims NATURAL JOIN users WHERE target = ? AND wave = ?});
-               $claims->execute($target,$wave);
-               if ($claims->rows == 0){
-                       my $query = $DBH->prepare(q{INSERT INTO raid_claims (target,uid,wave) VALUES(?,?,?)});
-                       if($query->execute($target,$ND::UID,$wave)){
-                               log_message $ND::UID,"Claimed target $target wave $wave.";
-                       }
-               }
-       }
-       if (param('cmd') eq 'Join'){
-               my $claims = $DBH->prepare(qq{SELECT username FROM raid_claims
-                       NATURAL JOIN users WHERE target = ? AND wave = ? AND
-                       joinable = TRUE});
-               $claims->execute($target,$wave);
-               if ($claims->rows != 0){
-                       my $query = $DBH->prepare(q{INSERT INTO raid_claims (target,uid,wave,joinable) VALUES(?,?,?,TRUE)});
-                       if($query->execute($target,$ND::UID,$wave)){
-                               log_message $ND::UID,"Joined target $target wave $wave.";
-                       }
-               }
-       }
-       if (param('cmd') eq 'set' && defined param('joinable') && param('joinable') =~ /(TRUE|FALSE)/){
-               my $claims = $DBH->prepare(qq{SELECT username FROM raid_claims NATURAL JOIN users WHERE target = ? AND wave = ? AND uid = ?});
-               $claims->execute($target,$wave,$ND::UID);
-               if ($claims->rows != 0){
-                       $DBH->do(q{UPDATE raid_claims SET joinable = ? WHERE target = ? AND wave = ?},undef,$1,$target,$wave)
-               }
-       }
-       if (param('cmd') eq 'Unclaim'){
-               my $query = $DBH->prepare(qq{DELETE FROM raid_claims WHERE target = ? AND uid = ? AND wave = ?});
-               if ($query->execute($target,$ND::UID,$wave)){
-                       log_message $ND::UID,"Unclaimed target $target wave $wave.";
-               }
-       }
-       $DBH->commit;
-       if ($XML && $raid){
-               generateClaimXml($raid,undef,$target);
-       }
-}
-if ($XML && $raid && param('cmd') eq 'update' ){
-       my $from;
-       if (param('from') =~ /^[-\d\ \:\.]+$/){
-               $from = param('from');
-       }
-       generateClaimXml($raid,$from);
-}
-if ($XML && param('cmd') eq 'gettargets' ){
-       $_ = listTargets();
-       $BODY->param(TargetList => $_);
-}
-
-unless ($XML){
-       $ND::TEMPLATE->param(TITLE => 'Raids');
-       #$ND::TEMPLATE->param(HEADER => '<script type="text/javascript" src="raid.js"></script>');
-       if ($raid){#We have a raid, so list all targets
-               $BODY->param(Raid => $raid->{id});
-               $BODY->param(Ajax => $ND::AJAX);
-               my $noingal = '';
-               my $planet;
-               if ($ND::PLANET){
-                       my $query = $DBH->prepare("SELECT value, score,x,y FROM current_planet_stats WHERE id = ?");
-                       $planet = $DBH->selectrow_hashref($query,undef,$ND::PLANET);
-                       $noingal = "AND NOT (x = $planet->{x} AND y = $planet->{y})";
-               }
-               $BODY->param(Message => parseMarkup($raid->{message}));
-               $BODY->param(LandingTick => parseMarkup($raid->{tick}));
-               my $targetquery = $DBH->prepare(qq{SELECT r.id, r.planet, size, score, value, coords(p.x,p.y,p.z), race, p.value - p.size*200 -coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue, comment
-FROM current_planet_stats p 
-       JOIN raid_targets r ON p.id = r.planet 
-       LEFT OUTER JOIN covop_targets c ON p.id = c.planet
-WHERE r.raid = ?
-       $noingal
-ORDER BY size});
-               $targetquery->execute($raid->{id});
-               my @targets;
-               while (my $target = $targetquery->fetchrow_hashref){
-                       my %target;
-                       $target{Id} = $target->{id};
-                       $target{Race} = $target->{race};
-                       $target{Ajax} = $ND::AJAX;
-                       my $num = pow(10,length($target->{score})-2);
-                       $target{Score} = ceil($target->{score}/$num)*$num;
-                       $num = pow(10,length($target->{value})-2);
-                       $target{Value} = ceil($target->{value}/$num)*$num;
-                       $num = pow(10,length($target->{size})-2);
-                       $target{Size} = floor($target->{size}/$num)*$num;
-                       $num = pow(10,length($target->{fleetvalue})-2);
-                       $target{FleetValue} = floor($target->{fleetvalue}/$num)*$num;
-                       if (defined $target->{resvalue}){
-                               $num = pow(10,length($target->{resvalue})-2);
-                               $target{ResValue} = floor($target->{resvalue}/$num)*$num;
-                       }
-                       $target{comment} = parseMarkup($target->{comment}) if ($target->{comment});
-
-                       my $scans = $DBH->prepare(q{SELECT DISTINCT ON (type) type, tick, scan FROM scans 
-                               WHERE planet = ? AND type ~ 'Unit|Planet|Military|.* Analysis' AND tick + 24 > tick()
-                               GROUP BY type, tick, scan ORDER BY type ,tick DESC});
-                       $scans->execute($target->{planet});
-                       my %scans;
-                       while (my $scan = $scans->fetchrow_hashref){
-                               $scans{$scan->{type}} = $scan;
-                       }
-
-                       my @scans;
-                       for my $type ('Planet','Unit','Military','Surface Analysis','Technology Analysis'){
-                               next unless exists $scans{$type};
-                               my $scan = $scans{$type};
-                               if ($ND::TICK - $scan->{tick} > 5){
-                                       $scan->{scan} =~ s{<table( cellpadding="\d+")?>}{<table$1 class="old">};
-                               }
-                               if ($type eq 'Planet'){
-                                       $target{PlanetScan} = $scan->{scan};
-                                       next;
-                               }
-                               push @scans,{Scan => $scan->{scan}};
-                       }
-                       $target{Scans} = \@scans;
-
-                       my @roids;
-                       my @claims;
-                       my $size = $target{Size};
-                       for (my $i = 1; $i <= $raid->{waves}; $i++){
-                               my $roids = floor(0.25*$size);
-                               $size -= $roids;
-                               my $xp;
-                               if ($planet){
-                                       $xp = max(0,floor($roids * 10 * (min(2,$target{Score}/$planet->{score}) + min(2,$target{Value}/$planet->{value})-1)));
-                               }
-                               push @roids,{Wave => $i, Roids => $roids, XP => $xp};
-                               if ($ND::AJAX){
-                                       push @claims,{Wave => $i, Target => $target{Id}}
-                               }else{
-                                       push @claims,{Wave => $i, Target => $target{Id}, Command => 'Claim'
-                                               , Owner => 1, Raid => $raid->{id}, Joinable => 0};
-                               }
-                       }
-                       $target{Roids} = \@roids;
-                       $target{Claims} = \@claims;
-
-                       push @targets,\%target;
-               }
-               $BODY->param(Targets => \@targets);
-       }else{#list raids if we haven't chosen one yet
-               my $query = $DBH->prepare(q{SELECT id,released_coords FROM raids WHERE open AND not removed AND
-id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)});
-               $query->execute($ND::UID);
-               my @raids;
-               while (my $raid = $query->fetchrow_hashref){
-                       push @raids,{Raid => $raid->{id}, ReleasedCoords => $raid->{released_coords}, isBC => isBC()};
-               }
-               $BODY->param(Raids => \@raids);
-
-               if (isBC()){
-                       my $query = $DBH->prepare(q{SELECT id,open FROM raids WHERE not removed AND (not open 
-OR id NOT IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?))});
-                       $query->execute($ND::UID);
-                       my @raids;
-                       while (my $raid = $query->fetchrow_hashref){
-                               push @raids,{Raid => $raid->{id}, Open => $raid->{open}};
-                       }
-                       $BODY->param(ClosedRaids => \@raids);
-               }
-       }
-}
-1;
diff --git a/resources.pl b/resources.pl
deleted file mode 100644 (file)
index fa64c32..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-our $BODY;
-our $DBH;
-my $error;
-
-$ND::TEMPLATE->param(TITLE => 'Alliance Resources');
-
-die "You don't have access" unless isHC();
-
-my $order = "respplanet DESC";
-if (defined param('order') && param('order') =~ /^(size|score|resources|respplanet|nscore|nscore2|nscore3)$/){
-       $order = "$1 DESC";
-}
-
-
-my $query = $DBH->prepare(qq{
-SELECT a.id,a.name,a.relationship,s.members,s.score,s.size,r.resources,r.planets, resources/planets AS respplanet, 
-       resources / 300 AS scoregain, score + (resources / 300) AS nscore, 
-       (resources/planets*LEAST(members,60))/300 AS scoregain2, score + (resources/planets*LEAST(members,60))/300 AS nscore2,
-       (s.size::int8*(1464-tick())*250)/100 + score + (resources/planets*LEAST(members,60))/300 AS nscore3,
-       (s.size::int8*(1464-tick())*250)/100 AS scoregain3
-FROM (SELECT alliance_id AS id,sum(metal+crystal+eonium) AS resources, count(*) AS planets 
-               FROM planets p join covop_targets c ON p.id = c.planet GROUP by alliance_id) r 
-       NATURAL JOIN alliances a 
-       LEFT OUTER JOIN (SELECT * FROM alliance_stats WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON a.id = s.id
-ORDER BY $order
-       });
-$query->execute;
-my @alliances;
-my $i = 0;
-while (my $alliance = $query->fetchrow_hashref){
-       $i++;
-       $alliance->{ODD} = $i % 2;
-       push @alliances,$alliance;
-}
-$BODY->param(Alliances => \@alliances);
-
-$BODY->param(Error => $error);
-1;
index 30d3163875ba8d282f38bf22ac0cb3d7e9d5161e..31d64d68a3d79c3af7fe1b0a52f5a5bd92bb6b95 100644 (file)
@@ -1,21 +1,43 @@
 use lib qw(/var/www/ndawn/code/);
 
-use POSIX;
 
 use CGI qw/:standard/;
 use HTML::Template;
+use Tie::File;
+use POSIX;
 
 use Apache::DBI();
 DBI->install_driver("Pg");
 use DBI;
 use DBD::Pg qw(:pg_types);
 
+use ND;
 use ND::DB;
 use ND::Include;
+use ND::Web::AuthHandler;
 use ND::Web::Include;
 use ND::Web::Forum;
 
-use Tie::File;
+use ND::Web::Pages::Main;
+use ND::Web::Pages::AddIntel;
+use ND::Web::Pages::Points;
+use ND::Web::Pages::LaunchConfirmation;
+use ND::Web::Pages::CovOp;
+use ND::Web::Pages::Top100;
+use ND::Web::Pages::DefRequest;
+use ND::Web::Pages::Check;
+use ND::Web::Pages::Raids;
+use ND::Web::Pages::EditRaid;
+use ND::Web::Pages::Calls;
+use ND::Web::Pages::Users;
+use ND::Web::Pages::Intel;
+use ND::Web::Pages::Alliances;
+use ND::Web::Pages::MemberIntel;
+use ND::Web::Pages::Resources;
+use ND::Web::Pages::PlanetNaps;
+use ND::Web::Pages::Motd;
+use ND::Web::Pages::Forum;
+
 
 
 1;
diff --git a/top100.pl b/top100.pl
deleted file mode 100644 (file)
index 1e3b85c..0000000
--- a/top100.pl
+++ /dev/null
@@ -1,71 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-
-$ND::TEMPLATE->param(TITLE => 'Top100 ');
-
-our $BODY;
-our $DBH;
-my $error = '';
-
-$BODY->param(isHC => isHC());
-
-
-die "You don't have access" unless isMember();
-
-my $offset = 0;
-if (defined param('offset') && param('offset') =~ /^(\d+)$/){
-       $offset = $1;
-}
-$BODY->param(Offset => $offset);
-$BODY->param(PrevOffset => $offset - 100);
-$BODY->param(NextOffset => $offset + 100);
-
-my $order = 'scorerank';
-if (defined param('order') && param('order') =~ /^(scorerank|sizerank|valuerank|xprank|hit_us)$/){
-       $order = $1;
-}
-$BODY->param(Order => $order);
-$order .= ' DESC' if ($order eq 'hit_us');
-
-
-my $extra_columns = '';
-if (isHC()){
-       $extra_columns = ",planet_status,hit_us, alliance,relationship,nick";
-}
-my $query = $DBH->prepare(qq{SELECT coords(x,y,z),((ruler || ' OF ') || planet) as planet,race,
-       size, score, value, xp, sizerank, scorerank, valuerank, xprank
-       $extra_columns FROM current_planet_stats ORDER BY $order LIMIT 100 OFFSET ?});
-$query->execute($offset) or $error .= p($DBH->errstr);
-my @planets;
-my $i = 0;
-while (my $planet = $query->fetchrow_hashref){
-       if (isHC){
-               $planet->{isHC} = 1;
-       }
-       $i++;
-       $planet->{ODD} = $i % 2;
-       push @planets,$planet;
-}
-$BODY->param(Planets => \@planets);
-$BODY->param(Error => $error);
-
-1;
diff --git a/users.pl b/users.pl
deleted file mode 100644 (file)
index ba87e92..0000000
--- a/users.pl
+++ /dev/null
@@ -1,133 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-our $BODY;
-our $DBH;
-
-$ND::TEMPLATE->param(TITLE => 'Users');
-
-die "You don't have access" unless isHC();
-
-my $error = '';
-my $user;
-if (defined param('user') && param('user') =~ /^(\d+)$/){
-       my $query = $DBH->prepare(q{
-SELECT uid,username,hostmask,coords(x,y,z) AS planet,attack_points,defense_points,scan_points,humor_points  
-       FROM users u LEFT OUTER JOIN current_planet_stats p ON u.planet = p.id
-WHERE uid = ?;
-}) or $error .= "<p> Something went wrong: </p>";
-       $user = $DBH->selectrow_hashref($query,undef,$1) or $error.= "<p> Something went wrong: ".$DBH->errstr."</p>";
-}
-
-
-if ($user && defined param('cmd') && param('cmd') eq 'change'){
-       $DBH->begin_work;
-       for my $param (param()){
-               if ($param =~ /^c:(\w+)$/){
-                       my $column = $1;
-                       my $value = param($column);
-                       if ($column eq 'planet'){
-                               if ($value eq ''){
-                                       $value = undef;
-                               }elsif($value =~ /^(\d+)\D+(\d+)\D+(\d+)$/){
-                                       ($value) = $DBH->selectrow_array(q{SELECT id FROM
-                                               current_planet_stats WHERE x = ? and y = ? and z =?}
-                                               ,undef,$1,$2,$3);
-                               }
-                       }
-                       if ($DBH->do(qq{UPDATE users SET $column = ? WHERE uid = ? }
-                                       ,undef,$value,$user->{uid})){
-                               $user->{$column} = param($column);
-                               log_message $ND::UID,"HC set $column to $value for user: $user->{uid}";
-                       }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-       }
-       my $groups = $DBH->prepare('SELECT gid,groupname FROM groups');
-       my $delgroup = $DBH->prepare(q{DELETE FROM groupmembers WHERE uid = ? AND gid = ?});
-       my $addgroup = $DBH->prepare(q{INSERT INTO groupmembers (uid,gid) VALUES(?,?)});
-       $groups->execute();
-       while (my $group = $groups->fetchrow_hashref){
-               my $query;
-               next unless defined param($group->{gid});
-               if (param($group->{gid}) eq 'remove'){
-                       $query = $delgroup;
-               }elsif(param($group->{gid}) eq 'add'){
-                       $query = $addgroup;
-               }
-               if ($query){
-                       if ($query->execute($user->{uid},$group->{gid})){
-                               my ($action,$a2) = ('added','to');
-                               ($action,$a2) = ('removed','from') if param($group->{gid}) eq 'remove';
-                               log_message $ND::UID,"HC $action user: $user->{uid} ($user->{username}) $a2 group: $group->{gid} ($group->{groupname})";
-                       }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-                       }
-               }
-       }
-       $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
-}
-
-if ($user){
-       $BODY->param(User => $user->{uid});
-       $BODY->param(Username => $user->{username});
-       $BODY->param(Hostmask => $user->{hostmask});
-       $BODY->param(Planet => $user->{planet});
-       $BODY->param(Attack_points => $user->{attack_points});
-       $BODY->param(Defense_points => $user->{defense_points});
-       $BODY->param(Scan_points => $user->{scan_points});
-       $BODY->param(humor_points => $user->{humor_points});
-
-       my $groups = $DBH->prepare(q{SELECT g.gid,g.groupname,uid FROM groups g LEFT OUTER JOIN (SELECT gid,uid FROM groupmembers WHERE uid = ?) AS gm ON g.gid = gm.gid});
-       $groups->execute($user->{uid});
-
-       my @addgroups;
-       my @remgroups;
-while (my $group = $groups->fetchrow_hashref){
-       if ($group->{uid}){
-               push @remgroups,{Id => $group->{gid}, Name => $group->{groupname}};
-       }else{
-               push @addgroups,{Id => $group->{gid}, Name => $group->{groupname}};
-       }
-}
-$BODY->param(RemoveGroups => \@remgroups);
-$BODY->param(AddGroups => \@addgroups);
-
-}else{
-       my $query = $DBH->prepare(qq{SELECT u.uid,username,TRIM(',' FROM concat(g.groupname||',')) AS groups
-               FROM users u LEFT OUTER JOIN (groupmembers gm NATURAL JOIN groups g) ON gm.uid = u.uid
-               WHERE u.uid > 0
-               GROUP BY u.uid,username
-               ORDER BY username})or $error .= $DBH->errstr;
-       $query->execute or $error .= $DBH->errstr;
-       my @users;
-       my $i = 0;
-       while (my $user = $query->fetchrow_hashref){
-               $i++;
-               $user->{ODD} = $i % 2;
-               push @users, $user;
-       }
-       $BODY->param(Users => \@users);
-}
-$BODY->param(Error => $error);
-1;