]> ruin.nu Git - ndwebbie.git/blob - check.pl
inital commit of the check page
[ndwebbie.git] / check.pl
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 use strict;
21
22 $ND::TEMPLATE->param(TITLE => 'Check planets and galaxies');
23
24 our $BODY;
25 our $DBH;
26
27 $BODY->param(isBC => isMember() && (isOfficer() || isBC));
28
29
30 die "You don't have access" unless $ND::ATTACKER;
31
32 my ($x,$y,$z);
33 if (param('coords') =~ /(\d+)(?: |:)(\d+)(?:(?: |:)(\d+))?(?: |:(\d+))?/){
34         $x = $1;
35         $y = $2;
36         $z = $3;
37 }else{
38         die "Bad coords";
39 }
40
41 if (param('cmd') eq 'arbiter'){
42 }
43
44 my $where = '';
45 my $extra_columns = '';
46
47 $where = 'AND z = ?' if defined $z;
48 if (isMember() && isOfficer()){
49         $extra_columns = ",planet_status,hit_us, alliance,relationship,nick";
50 }elsif (isMember() && isBC()){
51         $extra_columns = ", planet_status,hit_us, alliance,relationship";
52 }
53
54 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});
55
56 if (defined $z){
57         $query->execute($x,$y,$z);
58 }else{
59         $query->execute($x,$y);
60 }
61 my @planets;
62 while (my ($id,$coords,$planet,$race,$size,$score,$value,$xp,$sizerank,$scorerank,$valuerank,$xprank
63                 ,$fleetvalue,$resvalue,$planet_status,$hit_us,$alliance,$relationship,$nick) = $query->fetchrow){
64         my %planet = (Coords => $coords, Planet => $planet, Race => $race, Size => "$size ($sizerank)"
65                 , Score => "$score ($scorerank)", Value => "$value ($valuerank)", XP => "$xp ($xprank)"
66                 , FleetValue => "$fleetvalue ($resvalue)");
67         if (isMember() && (isOfficer() || isBC())){
68                 $planet{HitUs} = $hit_us;
69                 $planet{Alliance} = "$alliance ($relationship)";
70                 $planet{Nick} = "$nick ($planet_status)";
71                 $planet{PlanetStatus} = $planet_status;
72                 $planet{Relationship} = $relationship;
73                 $planet{isBC} = 1;
74         }
75         push @planets,\%planet;
76 }
77 $BODY->param(Planets => \@planets);
78
79 1;