示例#1
0
 // remove user from all tournament sub tables
 public void userQuitTournamentSubTables(UUID userId) {
   for (TableController controller : controllers.values()) {
     if (controller.getTable() != null) {
       if (controller.getTable().isTournamentSubTable()) {
         controller.leaveTable(userId);
       }
     } else {
       logger.error("TableManager.userQuitTournamentSubTables table == null - userId " + userId);
     }
   }
 }
示例#2
0
 public boolean removeTable(UUID userId, UUID tableId) {
   if (isTableOwner(tableId, userId) || UserManager.getInstance().isAdmin(userId)) {
     leaveTable(userId, tableId);
     TableController tableController = controllers.get(tableId);
     if (tableController != null) {
       ChatManager.getInstance().destroyChatSession(tableController.getChatId());
       removeTable(tableId);
     }
     return true;
   }
   return false;
 }
示例#3
0
 // remove user from all sub tables of a tournament
 public void userQuitTournamentSubTables(UUID tournamentId, UUID userId) {
   for (TableController controller : controllers.values()) {
     if (controller.getTable().isTournamentSubTable()
         && controller.getTable().getTournament().getId().equals(tournamentId)) {
       Match match = controller.getTable().getMatch();
       if (match != null) {
         if (match.getGame() != null) {
           GameManager.getInstance().quitMatch(match.getGame().getId(), userId);
         }
       }
     }
   }
 }
示例#4
0
  public void leaveTable(UUID userId, UUID tableId) {
    TableController tableController = controllers.get(tableId);
    if (tableController != null) {
      // table not started yet and user is the owner, remove the table
      Table table = getTable(tableId);
      if (table != null
          && isTableOwner(tableId, userId)
          && (table.getState().equals(TableState.WAITING)
              || table.getState().equals(TableState.STARTING))) {
        removeTable(tableId);

      } else {
        logger.debug("TABLE leave - userId: " + userId + "  tableId: " + tableId);
        tableController.leaveTable(userId);
      }
    }
  }
示例#5
0
 private void checkExpired() {
   debugServerState();
   Date now = new Date();
   List<UUID> toRemove = new ArrayList<>();
   for (Table table : tables.values()) {
     if (!table.getState().equals(TableState.FINISHED)) {
       // remove all not finished tables created more than expire_time ago
       long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
       if (diff >= EXPIRE_TIME) {
         logger.warn(
             "Table expired: id = "
                 + table.getId()
                 + ", created_by="
                 + table.getControllerName()
                 + ". Removing...");
         toRemove.add(table.getId());
       }
       // remove tables not valid anymore
       else if (!table.isTournament()) {
         TableController tableController = getController(table.getId());
         if (!tableController.isMatchTableStillValid()) {
           logger.warn(
               "Table with no active human player: id = "
                   + table.getId()
                   + ", created_by="
                   + table.getControllerName()
                   + ". Removing...");
           toRemove.add(table.getId());
         }
       }
     }
   }
   for (UUID tableId : toRemove) {
     try {
       removeTable(tableId);
     } catch (Exception e) {
       logger.error(e);
     }
   }
 }
示例#6
0
  public void removeTable(UUID tableId) {
    if (tables.containsKey(tableId)) {

      TableController tableController = controllers.get(tableId);
      if (tableController != null) {
        controllers.remove(tableId);
        tableController.cleanUp();
      }

      Table table = tables.get(tableId);
      tables.remove(tableId);

      // If table is not finished, the table has to be removed completly (if finished it will be
      // removed in GamesRoomImpl.Update())
      if (!table.getState().equals(TableState.FINISHED)) {
        GamesRoomManager.getInstance().removeTable(tableId);
      }
      if (table.getMatch() != null && table.getMatch().getGame() != null) {
        table.getMatch().getGame().end();
      }
    }
  }
示例#7
0
 public Table createTournamentTable(UUID roomId, UUID userId, TournamentOptions options) {
   TableController tableController = new TableController(roomId, userId, options);
   controllers.put(tableController.getTable().getId(), tableController);
   tables.put(tableController.getTable().getId(), tableController.getTable());
   return tableController.getTable();
 }
示例#8
0
 public Table createTable(UUID roomId, MatchOptions options) {
   TableController tableController = new TableController(roomId, null, options);
   controllers.put(tableController.getTable().getId(), tableController);
   tables.put(tableController.getTable().getId(), tableController.getTable());
   return tableController.getTable();
 }