Exemplo n.º 1
0
 private function createGame(array &$data)
 {
     if (!isset($_POST['name']) || empty($_POST['name'])) {
         throw new GameCreationException('Missing game name.');
     }
     if (!isset($_POST['players'])) {
         throw new GameCreationException('Missing players.');
     }
     if (!isset($_POST['password1'])) {
         $_POST['password1'] = '';
     }
     if (!isset($_POST['password2'])) {
         $_POST['password2'] = '';
     }
     if (!isset($_POST['color'])) {
         throw new GameCreationException('Missing color.');
     }
     $creator_joins = isset($_POST['play']);
     $gamesModeration = new GamesModeration(ModelUser::getCurrentUser()->getId());
     $gamesModeration->create($_POST['name'], $_POST['players'], $_POST['password1'], $_POST['password2'], $creator_joins, $_POST['color']);
     $data['status'] = array('message' => 'Game successfully created.');
     return $data;
 }
Exemplo n.º 2
0
 private function do_creator_action(array &$data)
 {
     $gamesModeration = new GamesModeration(ModelUser::getCurrentUser()->getId());
     if (isset($_POST['kick'])) {
         $gamesModeration->kickUser(intval($_POST['kick']), $this->id_game);
         $data['status'] = array('message' => 'User successfully kicked.');
         return;
     }
     if (isset($_POST['change_pw'])) {
         $gamesModeration->changePassword($_POST['password1'], $_POST['password2'], $this->id_game);
         $data['status'] = array('message' => 'Password successfully changed.');
         return;
     }
     if (isset($_POST['start'])) {
         $gamesModeration->startGame($this->id_game);
         $data['status'] = array('message' => 'Game successfully started.');
         return;
     }
     if (isset($_POST['delete_affirmed'])) {
         $gamesModeration->deleteGame($this->id_game);
         $data['status'] = array('message' => 'Game successfully deleted.');
         return;
     }
 }