// 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); } } }
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; }
// 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); } } } } }
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); } } }
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); } } }
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(); } } }
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(); }
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(); }