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); } }
protected function _administrated_games() { $t = $this->_template; $ids = $this->_auth->get_administrated_ids('game'); $t->games = new \Core\Li(); if (count($ids) > 0) { $params = \Trouble\GameContainer::params($this->_auth->user_id()); $params['filters'][] = new \Core\Filter('id', $ids, 'in'); $params['order'] = new \Core\Order('start_date', 'desc'); $t->games->extend(\Trouble\Game::container()->get($params)); } return $t->render('games_list.php'); }
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]}"); } }