1 package NDWeb::Controller::Root;
5 use parent 'Catalyst::Controller';
10 # Sets the actions in this controller to be registered with no prefix
11 # so they function identically to actions created in MyApp.pm
13 __PACKAGE__->config->{namespace} = '';
17 NDWeb::Controller::Root - Root Controller for NDWeb
21 [enter your description here]
31 sub index : Local Path Args(0) {
32 my ( $self, $c ) = @_;
36 my ( $self, $c ) = @_;
37 $c->res->body( 'Page not found' );
38 $c->response->status(404);
44 $c->res->redirect($c->uri_for('index'));
48 $c->stash(error => 'Bad password');
49 $c->stash(template => 'index.tt2');
56 $c->res->redirect($c->uri_for('index'));
62 $c->res->header( 'Cache-Control' =>
63 'no-store, no-cache, must-revalidate,'.
64 'post-check=0, pre-check=0, max-age=0'
66 $c->res->header( 'Pragma' => 'no-cache' );
67 $c->res->header( 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT' );
70 sub listTargets : Private {
75 my $query = $dbh->prepare(q{SELECT t.id, r.id AS raid, r.tick+c.wave-1 AS landingtick,
76 (released_coords AND old_claim(timestamp)) AS released_coords, coords(x,y,z),c.launched,c.wave,c.joinable
78 JOIN raid_targets t ON c.target = t.id
79 JOIN raids r ON t.raid = r.id
80 JOIN current_planet_stats p ON t.planet = p.id
81 WHERE c.uid = $1 AND r.tick+c.wave > tick() AND r.open AND not r.removed
82 ORDER BY r.tick+c.wave,x,y,z});
83 $query->execute($c->user->id) or die $dbh->errstr;
85 while (my $target = $query->fetchrow_hashref){
86 push @targets, $target;
89 $c->stash(claimedtargets => \@targets);
92 sub listAlliances : Private {
95 push @alliances,{id => -1, name => ''};
96 my $query = $c->model->prepare(q{SELECT id,name FROM alliances ORDER BY LOWER(name)});
98 while (my $ally = $query->fetchrow_hashref){
99 push @alliances,$ally;
101 $c->stash(alliances => \@alliances);
106 my $dbh = $c ->model;
108 $c->stash(dbh => $dbh);
110 $dbh->do(q{SET timezone = 'GMT'});
112 $c->stash(TICK =>$dbh->selectrow_array('SELECT tick()',undef));
113 $c->stash(STICK =>$dbh->selectrow_array('SELECT max(tick) FROM planet_stats',undef));
114 $c->stash->{game}->{tick} = $c->stash->{TICK};
116 if ($c->user_exists){
117 $c->stash(UID => $c->user->id);
119 $c->stash(UID => -4);
124 sub access_denied : Private {
125 my ($self, $c, $action) = @_;
127 $c->log->debug('moo' . $action);
129 # Set the error message
130 $c->stash->{template} = 'access_denied.tt2';
136 Attempt to render a view, if needed.
140 sub end : ActionClass('RenderView') {
143 my $dbh = $c ->model;
145 if ($c->user_exists && $c->res->status == 200){
147 if ($c->check_user_roles(qw/member_menu/)){
148 $fleetupdate = $dbh->selectrow_array(q{SELECT tick FROM fleets WHERE sender = ?
149 AND mission = 'Full fleet' AND tick > tick() - 24
150 },undef,$c->user->planet);
151 $fleetupdate = 0 unless defined $fleetupdate;
154 my ($unread,$newposts) = $dbh->selectrow_array(unread_query,undef,$c->user->id) or die $dbh->errstr;
158 name => $c->user->username,
159 css => $c->user->css,
160 newposts => $newposts,
161 unreadposts => $unread
163 $c->stash->{user}->{attacker} = $c->check_user_roles(qw/attack_menu/)
164 && (!$c->check_user_roles(qw/member_menu/)
165 || ($c->user->planet && (($c->stash->{TICK} - $fleetupdate < 24)
166 || $c->check_user_roles(qw/no_fleet_update/)))),
167 $c->forward('listTargets');
173 Michael Andreen (harv@ruin.nu)