]> ruin.nu Git - ndwebbie.git/blob - calls.pl
11c4ed7b747ae3454cceed78a95bf8c78e3cf85c
[ndwebbie.git] / calls.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 use POSIX;
22 our $BODY;
23 our $DBH;
24 our $LOG;
25
26 $ND::TEMPLATE->param(TITLE => 'Defense Calls');
27
28 die "You don't have access" unless isBC();
29
30
31 my $call;
32 if (param('call') =~ /^(\d+)$/){
33         my $query = $DBH->prepare(q{});
34         $call = $DBH->selectrow_hashref($query,undef,$1);
35 }
36
37 if ($call){
38 }else{
39         my $where = 'open AND c.landing_tick-6 > tick()';
40         if (param('show') eq 'covered'){
41                 $where = 'covered';
42         }elsif (param('show') eq 'all'){
43                 $where = 'true';
44         }elsif (param('show') eq 'uncovered'){
45                 $where = 'not covered';
46         }
47         my $query = $DBH->prepare(qq{
48 SELECT c.id, coords(p.x,p.y,p.z), u.defense_points, c.landing_tick, 
49         TRIM('/' FROM concat(p2.race||'/')) AS race, TRIM('/' FROM concat(i.amount||'/')) AS amount,
50         TRIM('/' FROM concat(i.eta||'/')) AS eta, TRIM('/' FROM concat(i.shiptype||'/')) AS shiptype,
51         TRIM('/' FROM concat(c.landing_tick - tick() ||'/')) AS curreta,
52         TRIM('/' FROM concat(p2.alliance ||'/')) AS alliance,
53         TRIM('/' FROM concat(coords(p2.x,p2.y,p2.z) ||'/')) AS attackers
54 FROM calls c 
55         JOIN incomings i ON i.call = c.id
56         JOIN users u ON c.member = u.uid
57         JOIN current_planet_stats p ON u.planet = p.id
58         JOIN current_planet_stats p2 ON i.sender = p2.id
59 WHERE $where
60 GROUP BY c.id, p.x,p.y,p.z, u.username, c.landing_tick, c.info,u.defense_points
61 ORDER BY c.landing_tick DESC
62                 })or print $DBH->errstr;
63         $query->execute or print $DBH->errstr;
64         my @calls;
65         my $i = 0;
66         while (my $call = $query->fetchrow_hashref){
67                 $call->{ODD} = $i % 2;
68                 push @calls, $call;
69                 $i++;
70         }
71         $BODY->param(Calls => \@calls);
72 }
73 1;