chdir $ENV{'DOCUMENT_ROOT'};
our $DBH = undef;
-our $UID = undef;
-our $PLANET = undef;
-our $TEMPLATE = undef;
-our $TICK = undef;
+our $USER = $ENV{'REMOTE_USER'};
+my $error;
-$ND::TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl');
+our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl');
for my $file ("db.pl","include.pl"){
unless (my $return = do $file){
- warn "couldn't parse $file: $@" if $@;
- warn "couldn't do $file: $!" unless defined $return;
- warn "couldn't run $file" unless $return;
+ print "couldn't parse $file: $@" if $@;
+ print "couldn't do $file: $!" unless defined $return;
+ print "couldn't run $file" unless $return;
}
}
-($UID,$PLANET) = $DBH->selectrow_array('SELECT uid,planet FROM users WHERE username = ?'
+our ($UID,$PLANET) = $DBH->selectrow_array('SELECT uid,planet FROM users WHERE username = ?'
,undef,$ENV{'REMOTE_USER'});
-($TICK) = $DBH->selectrow_array('SELECT tick()',undef);
+our ($TICK) = $DBH->selectrow_array('SELECT tick()',undef);
my $query = $DBH->prepare('SELECT groupname,attack,gid from groupmembers NATURAL JOIN groups WHERE uid = ?');
our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)');
my $page = 'main';
-if (param('page') =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest)$/){
+if (param('page') =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest|raids|editRaid|calls|intel|users|alliances)$/){
$page = $1;
}
-print header;
-$ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl");
+our $XML = 0;
+$XML = 1 if param('xml') and $page =~ /^(raids)$/;
+
+my $type = 'text/html';
+if ($XML){
+ $type = 'text/xml';
+ $ND::TEMPLATE = HTML::Template->new(filename => "templates/xml.tmpl");
+ $ND::BODY = HTML::Template->new(filename => "templates/${page}.xml.tmpl");
+}else{
+ $ND::BODY = HTML::Template->new(filename => "templates/${page}.tmpl");
+}
+
unless (my $return = do "${page}.pl"){
- print "<p><b>couldn't parse $page: $@</b></p>" if $@;
- print "<p><b>couldn't do $page: $!</b></p>" unless defined $return;
- print "<p><b>couldn't run $page</b></p>" unless $return;
+ $error .= "<p><b>couldn't parse $page: $@</b></p>" if $@;
+ $error .= "<p><b>couldn't do $page: $!</b></p>" unless defined $return;
+ $error .= "<p><b>couldn't run $page</b></p>" unless $return;
}
-my $fleetupdate = $DBH->selectrow_array('SELECT landing_tick FROM fleets WHERE uid = ? AND fleet = 0',undef,$UID);
-
-$TEMPLATE->param(Tick => $TICK);
-$TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember());
-$TEMPLATE->param(isHC => isHC());
-$TEMPLATE->param(isDC => isDC());
-$TEMPLATE->param(isBC => isBC());
-$TEMPLATE->param(isAttacker => $ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET)));
-if ($ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET))){
- my $query = $DBH->prepare(qq{SELECT t.id, r.id AS raid, r.tick+c.wave-1 AS landingtick, released_coords, coords(x,y,z),c.launched
-FROM raid_claims c
- JOIN raid_targets t ON c.target = t.id
- JOIN raids r ON t.raid = r.id
- JOIN current_planet_stats p ON t.planet = p.id
-WHERE c.uid = ? AND r.tick+c.wave > ? AND r.open AND not r.removed
-ORDER BY r.tick+c.wave,x,y,z});
- $query->execute($UID,$TICK);
- my @targets;
- while (my $target = $query->fetchrow_hashref){
- my $coords = "Target $target->{id}";
- $coords = $target->{coords} if $target->{released_coords};
- push @targets,{Coords => $coords, Launched => $target->{launched}, Raid => $target->{raid}
- , Target => $target->{id}, Tick => $target->{landingtick}};
+unless ($XML){
+ my $fleetupdate = $DBH->selectrow_array('SELECT landing_tick FROM fleets WHERE uid = ? AND fleet = 0',undef,$UID);
+
+
+ $TEMPLATE->param(Tick => $TICK);
+ $TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember());
+ $TEMPLATE->param(isHC => isHC());
+ $TEMPLATE->param(isDC => isDC());
+ $TEMPLATE->param(isBC => isBC());
+ $TEMPLATE->param(isAttacker => $ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET)));
+ if ($ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET))){
+ $ND::TEMPLATE->param(Targets => listTargets());
}
- $ND::TEMPLATE->param(Targets => \@targets);
-}
+ $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1');
+ $TEMPLATE->param(Error => $error);
+}
$ND::TEMPLATE->param(BODY => $ND::BODY->output);
-print $TEMPLATE->output;
+my $output = $TEMPLATE->output;
+print header(-type=> $type, -charset => 'utf-8', -Content_Length => length $output);
+print $output;
$DBH->disconnect;
$DBH = undef;
$UID = undef;
+$USER = undef;
$PLANET = undef;
$TEMPLATE = undef;
$TICK = undef;