Exemplo n.º 1
0
 public function register_kill()
 {
     import('trouble.kill');
     import('core.validation');
     try {
         $validator = \Core\Validator::validator('\\Trouble\\Kill');
         $validator->validate($_POST, \Trouble\Kill::validation());
         $this->_game_action(function ($agent_id) {
             $now = new \DateTime();
             if (empty($_POST['when_happened_date'])) {
                 $date = $now->format('Y-m-d');
             } else {
                 $date = $_POST['when_happened_date'];
             }
             if (empty($_POST['when_happened_time'])) {
                 $time = $now->format('H:i');
             } else {
                 $time = $_POST['when_happened_time'];
             }
             $_POST['when_happened'] = new \DateTime($date . $time);
             $game = \Trouble\Game::container()->get_by_id($_POST['game_id'])->kill_agent_target($agent_id, $_POST);
         }, 'Kill registered.');
     } catch (\Trouble\GameIncorrectPKNError $e) {
         echo $this->_return_message("Error", "Incorrect PKN. If believed to be correct, please contact game administrator.");
     } catch (\Trouble\KillTooEarlyError $e) {
         echo $this->_return_message("Error", "Kill date too early for game.");
     } catch (\Trouble\KillTooLateError $e) {
         echo $this->_return_message("Error", "Kill date too late for game.");
     } catch (\Trouble\KillInFutureError $e) {
         echo $this->_return_message("Error", "Kill date in future. We don't allow time travellers.");
     } catch (\Core\ValidationError $e) {
         echo $this->_return_message("Error", "Validation error(s):", $e->get_errors());
     } catch (\Exception $e) {
         $this->_unhandled_exception($e);
     }
 }
Exemplo n.º 2
0
 protected function _edit()
 {
     $t = $this->_template;
     $t->add('_jsapps', 'game_form');
     $storage = \Core\Storage::container()->get_storage('Game');
     $mapper = \Trouble\Game::mapper()->attach_storage($storage);
     try {
         if ($this->_args['game_id']) {
             $t->title = "Edit Game";
             $game = $this->_game;
             $this->_auth->check_admin('game', $game->id);
             $game->form_start_date = $game->start_date->format('Y-m-d');
             $game->form_end_date = $game->end_date->format('Y-m-d');
             $t->administration = $this->_administration($game);
             $t->vouchers = $this->_vouchers($game);
         } else {
             $t->title = "Game Creation";
             $t->new = True;
             $game = \Trouble\Game::create($_POST, True);
         }
         $t->game = $game;
         return $t->render('forms/game.php');
     } catch (\Core\AuthDeniedError $e) {
         throw new \Core\HTTPError(401, "Editing Game");
     } catch (\Core\AuthNotLoggedInError $e) {
         throw new \Core\HTTPError(401, "Editing Game");
     }
 }
Exemplo n.º 3
0
 private function _init_game()
 {
     if (!$this->_args['game_id']) {
         return False;
     }
     try {
         $this->_game = \Trouble\Game::container()->get_by_id($this->_args['game_id']);
         $this->_game->load_players(True);
         $this->_init_player();
     } catch (\Trouble\GameNotFoundError $e) {
         throw new \Core\HTTPError(404, "Game #{$this->_args[game_id]}");
     }
 }