Esempio n. 1
0
 /**
  * Ends the current game and starts if neccessary the next game
  *
  * @return true if table can be closed
  */
 public boolean endGameAndStartNextGame() {
   // get player that chooses who goes first
   Game game = match.getGame();
   if (game == null) {
     return true;
   }
   UUID choosingPlayerId = match.getChooser();
   match.endGame();
   if (ConfigSettings.getInstance().isSaveGameActivated() && !game.isSimulation()) {
     if (GameManager.getInstance().saveGame(game.getId())) {
       match.setReplayAvailable(true);
     }
   }
   GameManager.getInstance().removeGame(game.getId());
   try {
     if (!match.hasEnded()) {
       if (match.getGame() != null && match.getGame().getGameType().isSideboardingAllowed()) {
         sideboard();
       }
       if (!match.hasEnded()) {
         startGame(choosingPlayerId);
       } else {
         closeTable();
       }
     } else {
       closeTable();
     }
   } catch (GameException ex) {
     logger.fatal(null, ex);
   }
   return match.hasEnded();
 }
Esempio n. 2
0
 @BeforeClass
 public static void init() {
   Logger.getRootLogger().setLevel(Level.DEBUG);
   logger.info("Starting MAGE tests");
   logger.info("Logging level: " + logger.getLevel());
   deleteSavedGames();
   ConfigSettings config = ConfigSettings.getInstance();
   for (GamePlugin plugin : config.getGameTypes()) {
     GameFactory.getInstance()
         .addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
   }
   for (GamePlugin plugin : config.getTournamentTypes()) {
     TournamentFactory.getInstance()
         .addTournamentType(plugin.getName(), loadTournamentType(plugin), loadPlugin(plugin));
   }
   for (Plugin plugin : config.getPlayerTypes()) {
     PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin));
   }
   //        for (Plugin plugin : config.getDeckTypes()) {
   //            DeckValidatorFactory.getInstance().addDeckType(plugin.getName(),
   // loadPlugin(plugin));
   //        }
   Copier.setLoader(classLoader);
 }
Esempio n. 3
0
 private void matchEnd() {
   if (match != null) {
     for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
       MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
       // opponent(s) left during sideboarding
       if (matchPlayer != null) {
         if (!matchPlayer.hasQuit()) {
           User user = UserManager.getInstance().getUser(entry.getKey());
           if (user != null) {
             if (table.getState().equals(TableState.SIDEBOARDING)) {
               StringBuilder sb = new StringBuilder();
               if (table.isTournamentSubTable()) {
                 sb.append("Your tournament match of round ");
                 sb.append(table.getTournament().getRounds().size());
                 sb.append(" is over. ");
               } else {
                 sb.append("Match [").append(match.getName()).append("] is over. ");
               }
               if (match.getPlayers().size() > 2) {
                 sb.append("All your opponents have lost or quit the match.");
               } else {
                 sb.append("Your opponent has quit the match.");
               }
               user.showUserMessage("Match info", sb.toString());
             }
             // remove table from user - table manager holds table for display of finished matches
             if (!table.isTournamentSubTable()) {
               user.removeTable(entry.getValue());
             }
           }
         }
       }
     }
     // free resources no longer needed
     match.cleanUpOnMatchEnd(
         ConfigSettings.getInstance().isSaveGameActivated(), table.isTournament());
   }
 }
Esempio n. 4
0
 public String registerUserHandling(String userName) throws MageException {
   this.isAdmin = false;
   if (userName.equals("Admin")) {
     return "User name Admin already in use";
   }
   if (userName.length() > ConfigSettings.getInstance().getMaxUserNameLength()) {
     return new StringBuilder("User name may not be longer than ")
         .append(ConfigSettings.getInstance().getMaxUserNameLength())
         .append(" characters")
         .toString();
   }
   if (userName.length() < ConfigSettings.getInstance().getMinUserNameLength()) {
     return new StringBuilder("User name may not be shorter than ")
         .append(ConfigSettings.getInstance().getMinUserNameLength())
         .append(" characters")
         .toString();
   }
   Pattern p =
       Pattern.compile(
           ConfigSettings.getInstance().getUserNamePattern(), Pattern.CASE_INSENSITIVE);
   Matcher m = p.matcher(userName);
   if (m.find()) {
     return new StringBuilder("User name '")
         .append(userName)
         .append("' includes not allowed characters: use a-z, A-Z and 0-9")
         .toString();
   }
   User user = UserManager.getInstance().createUser(userName, host);
   boolean reconnect = false;
   if (user == null) { // user already exists
     user = UserManager.getInstance().findUser(userName);
     if (user.getHost().equals(host)) {
       user.updateLastActivity(null); // minimizes possible expiration
       this.userId = user.getId();
       if (user.getSessionId().isEmpty()) {
         logger.info("Reconnecting session for " + userName);
         reconnect = true;
       } else {
         // disconnect previous session
         logger.info("Disconnecting another user instance: " + userName);
         SessionManager.getInstance()
             .disconnect(user.getSessionId(), DisconnectReason.ConnectingOtherInstance);
       }
     } else {
       return new StringBuilder("User name ")
           .append(userName)
           .append(" already in use (or your IP address changed)")
           .toString();
     }
   }
   if (!UserManager.getInstance().connectToSession(sessionId, user.getId())) {
     return new StringBuilder("Error connecting ").append(userName).toString();
   }
   this.userId = user.getId();
   if (reconnect) { // must be connected to receive the message
     UUID chatId =
         GamesRoomManager.getInstance()
             .getRoom(GamesRoomManager.getInstance().getMainRoomId())
             .getChatId();
     if (chatId != null) {
       ChatManager.getInstance().joinChat(chatId, userId);
     }
     ChatManager.getInstance().sendReconnectMessage(userId);
   }
   return null;
 }
Esempio n. 5
0
  private void update() {
    ArrayList<TableView> tableList = new ArrayList<>();
    ArrayList<MatchView> matchList = new ArrayList<>();
    List<Table> allTables = new ArrayList<>(tables.values());
    Collections.sort(allTables, new TableListSorter());
    for (Table table : allTables) {
      if (table.getState() != TableState.FINISHED) {
        tableList.add(new TableView(table));
      } else if (matchList.size() < 50) {
        matchList.add(new MatchView(table));
      } else {
        // more since 50 matches finished since this match so remove it
        if (table.isTournament()) {
          TournamentManager.getInstance().removeTournament(table.getTournament().getId());
        }
        this.removeTable(table.getId());
      }
    }
    tableView = tableList;
    matchView = matchList;
    List<UsersView> users = new ArrayList<>();
    for (User user : UserManager.getInstance().getUsers()) {
      try {
        users.add(
            new UsersView(
                user.getUserData().getFlagName(),
                user.getName(),
                user.getMatchHistory(),
                user.getMatchQuitRatio(),
                user.getTourneyHistory(),
                user.getTourneyQuitRatio(),
                user.getGameInfo(),
                user.getPingInfo()));
      } catch (Exception ex) {
        logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
        users.add(
            new UsersView(
                (user.getUserData() != null && user.getUserData().getFlagName() != null)
                    ? user.getUserData().getFlagName()
                    : "world",
                user.getName() != null ? user.getName() : "<no name>",
                user.getMatchHistory() != null ? user.getMatchHistory() : "<no match history>",
                user.getMatchQuitRatio(),
                user.getTourneyHistory() != null
                    ? user.getTourneyHistory()
                    : "<no tourney history>",
                user.getTourneyQuitRatio(),
                "[exception]",
                user.getPingInfo() != null ? user.getPingInfo() : "<no ping>"));
      }
    }

    Collections.sort(users, new UserNameSorter());
    List<RoomUsersView> roomUserInfo = new ArrayList<>();
    roomUserInfo.add(
        new RoomUsersView(
            users,
            GameManager.getInstance().getNumberActiveGames(),
            ThreadExecutor.getInstance()
                .getActiveThreads(ThreadExecutor.getInstance().getGameExecutor()),
            ConfigSettings.getInstance().getMaxGameThreads()));
    roomUsersView = roomUserInfo;
  }