1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
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. *
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. *
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 #**************************************************************************/
20 package NDWeb::Pages::MemberIntel;
23 use CGI qw/:standard/;
26 use base qw/NDWeb::XMLPage/;
28 $NDWeb::Page::PAGES{memberIntel} = __PACKAGE__;
33 $self->{TITLE} = 'Member Intel';
34 my $DBH = $self->{DBH};
37 return $self->noAccess unless $self->isHC;
39 my $showticks = 'AND i.tick > tick()';
40 if (defined param('show')){
41 if (param('show') eq 'all'){
43 }elsif (param('show') =~ /^(\d+)$/){
44 $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
49 if (defined param('uid') && param('uid') =~ /^(\d+)$/){
50 my $query = $DBH->prepare(q{SELECT username,uid FROM users WHERE uid = ?
52 $user = $DBH->selectrow_hashref($query,undef,$1);
56 $BODY->param(UID => $user->{uid});
57 my $query = $DBH->prepare(q{
58 SELECT coords(t.x,t.y,t.z), i.eta, i.tick, rt.id AS ndtarget, rc.launched, inc.landing_tick
60 LEFT OUTER JOIN (SELECT * FROM intel WHERE amount = -1) i ON i.sender = u.planet
61 LEFT OUTER JOIN current_planet_stats t ON i.target = t.id
62 LEFT OUTER JOIN (SELECT rt.id,planet,tick FROM raids r
63 JOIN raid_targets rt ON r.id = rt.raid) rt ON rt.planet = i.target
64 AND (rt.tick + 12) > i.tick AND rt.tick < i.tick
65 LEFT OUTER JOIN raid_claims rc ON rt.id = rc.target AND rc.uid = u.uid
66 LEFT OUTER JOIN (SELECT sender, eta, landing_tick FROM calls c
67 JOIN incomings i ON i.call = c.id) inc ON inc.sender = i.target
68 AND (inc.landing_tick + inc.eta) >= i.tick
69 AND (inc.landing_tick - inc.eta - 1) <= (i.tick - i.eta)
70 WHERE u.uid = $1 AND i.mission = 'Attack'
71 ORDER BY (i.tick - i.eta)
73 $query->execute($user->{uid}) or $error .= $DBH->errstr;
77 while (my $intel = $query->fetchrow_hashref){
78 my $attack = {target => $intel->{coords}, tick => $intel->{tick}};
79 if ($intel->{ndtarget}){
80 if (defined $intel->{launched}){
81 $attack->{Other} = 'Claimed '.($intel->{launched} ? 'and confirmed' : 'but NOT confirmed');
83 $attack->{Other} = 'Launched at a tick that was not claimed';
85 push @nd_attacks, $attack;
87 push @other_attacks, $attack;
91 push @attacks, {name => 'ND Attacks', list => \@nd_attacks};
92 push @attacks, {name => 'Other', list => \@other_attacks};
93 $BODY->param(Attacks => \@attacks);
95 $query = $DBH->prepare(q{
96 SELECT coords(t.x,t.y,t.z),t.alliance_id, t.alliance, i.eta, i.tick, i.ingal
98 JOIN (SELECT * FROM intel WHERE amount = -1) i ON i.sender = u.planet
99 LEFT OUTER JOIN current_planet_stats t ON i.target = t.id
100 WHERE u.uid = $1 AND (i.mission = 'Defend' OR i.mission = 'AllyDef')
101 ORDER BY (i.tick - i.eta)
103 $query->execute($user->{uid}) or $error .= $DBH->errstr;
107 while (my $intel = $query->fetchrow_hashref){
108 my $def = {target => $intel->{coords}.(defined $intel->{alliance} ? " ($intel->{alliance})" : ''), tick => $intel->{tick}};
109 if (defined $intel->{alliance_id} && $intel->{alliance_id} == 1){
111 }elsif($intel->{ingal}){
112 push @ingal_def, $def;
114 push @other_def, $def;
118 push @defenses, {name => 'ND Def', list => \@nd_def};
119 push @defenses, {name => 'Ingal Def', list => \@ingal_def};
120 push @defenses, {name => 'Other', list => \@other_def};
121 $BODY->param(Defenses => \@defenses);
124 my $query = $DBH->prepare(q{SELECT u.uid,u.username,u.attack_points, u.defense_points, n.tick
125 ,count(CASE WHEN i.mission = 'Attack' THEN 1 ELSE NULL END) AS attacks
126 ,count(CASE WHEN (i.mission = 'Defend' OR i.mission = 'AllyDef') THEN 1 ELSE NULL END) AS defenses
128 JOIN groupmembers gm USING (uid)
129 LEFT OUTER JOIN (SELECT DISTINCT ON (planet) planet,tick from scans where type = 'News' ORDER BY planet,tick DESC) n USING (planet)
130 LEFT OUTER JOIN (SELECT * FROM intel WHERE amount = -1) i ON i.sender = u.planet
131 LEFT OUTER JOIN current_planet_stats t ON i.target = t.id
133 GROUP BY u.uid,u.username,u.attack_points, u.defense_points,n.tick
134 ORDER BY attacks DESC,defenses DESC, attack_points DESC, defense_points DESC});
135 $query->execute() or $error .= $DBH->errstr;
138 while (my $intel = $query->fetchrow_hashref){
140 $intel->{ODD} = $i % 2;
141 $intel->{OLD} = 'OLD' if (!defined $intel->{tick} || $self->{TICK} > $intel->{tick} + 60);
142 delete $intel->{tick};
143 push @members,$intel;
145 $BODY->param(Members => \@members);
147 $BODY->param(Error => $error);