Example #1
0
 public synchronized void startTournament(UUID userId) {
   try {
     if (userId.equals(this.userId) && table.getState().equals(TableState.STARTING)) {
       tournament.setStartTime();
       TournamentManager.getInstance()
           .createTournamentSession(tournament, userPlayerMap, table.getId());
       for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
         User user = UserManager.getInstance().getUser(entry.getKey());
         if (user != null) {
           logger.info(
               new StringBuilder("User ")
                   .append(user.getName())
                   .append(" tournament started: ")
                   .append(tournament.getId())
                   .append(" userId: ")
                   .append(user.getId()));
           user.ccTournamentStarted(tournament.getId(), entry.getValue());
         }
       }
       ServerMessagesUtil.getInstance().incTournamentsStarted();
     }
   } catch (Exception ex) {
     logger.fatal("Error starting tournament", ex);
     TableManager.getInstance().removeTable(table.getId());
     TournamentManager.getInstance().quit(tournament.getId(), userId);
   }
 }
Example #2
0
  private void startGame(UUID choosingPlayerId) throws GameException {
    try {
      match.startGame();
      table.initGame();
      GameOptions gameOptions = new GameOptions();
      gameOptions.rollbackTurnsAllowed = match.getOptions().isRollbackTurnsAllowed();
      match.getGame().setGameOptions(gameOptions);
      GameManager.getInstance()
          .createGameSession(
              match.getGame(), userPlayerMap, table.getId(), choosingPlayerId, gameOptions);
      String creator = null;
      StringBuilder opponent = new StringBuilder();
      for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { // no AI players
        if (match.getPlayer(entry.getValue()) != null
            && !match.getPlayer(entry.getValue()).hasQuit()) {
          User user = UserManager.getInstance().getUser(entry.getKey());
          if (user != null) {
            user.ccGameStarted(match.getGame().getId(), entry.getValue());

            if (creator == null) {
              creator = user.getName();
            } else {
              if (opponent.length() > 0) {
                opponent.append(" - ");
              }
              opponent.append(user.getName());
            }
          } else {
            logger.error(
                "Unable to find user: "******"  playerId: " + entry.getValue());
            MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
            if (matchPlayer != null && !matchPlayer.hasQuit()) {
              matchPlayer.setQuit(true);
            }
          }
        }
      }
      // Append AI opponents to the log file
      for (MatchPlayer mPlayer : match.getPlayers()) {
        if (!mPlayer.getPlayer().isHuman()) {
          if (opponent.length() > 0) {
            opponent.append(" - ");
          }
          opponent.append(mPlayer.getName());
        }
      }
      ServerMessagesUtil.getInstance().incGamesStarted();

      // log about game started
      logger.info(
          "GAME started "
              + (match.getGame() != null ? match.getGame().getId() : "no Game")
              + " ["
              + match.getName()
              + "] "
              + creator
              + " - "
              + opponent.toString());
      logger.debug("- matchId: " + match.getId() + " [" + match.getName() + "]");
      if (match.getGame() != null) {
        logger.debug("- chatId:  " + GameManager.getInstance().getChatId(match.getGame().getId()));
      }
    } catch (Exception ex) {
      logger.fatal("Error starting game table: " + table.getId(), ex);
      if (table != null) {
        TableManager.getInstance().removeTable(table.getId());
      }
      if (match != null) {
        Game game = match.getGame();
        if (game != null) {
          GameManager.getInstance().removeGame(game.getId());
        }
      }
    }
  }