예제 #1
0
 public function _game_killboard()
 {
     $t = $this->_template;
     $g = $this->_game;
     $kill_storage = \Core\Storage::container()->get_storage('Kill');
     $kill_mapper = \Trouble\Kill::mapper()->attach_storage($kill_storage);
     if (!$this->_game instanceof \Trouble\Game) {
         throw new \Core\Error("No game.");
     }
     $g->attach_mapper('Kill', $kill_mapper);
     $t->killboard = \Trouble\Killboard::container()->get_game_killboard($g)->load_data();
     return $t->render('killboard.php');
 }
예제 #2
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);
     }
 }