Search in sources :

Example 1 with Table

use of mage.game.Table in project mage by magefree.

the class User method removeUserFromAllTables.

public void removeUserFromAllTables(DisconnectReason reason) {
    logger.trace("REMOVE " + userName + " Draft sessions " + draftSessions.size());
    for (DraftSession draftSession : draftSessions.values()) {
        draftSession.setKilled();
    }
    draftSessions.clear();
    logger.trace("REMOVE " + userName + " Tournament sessions " + userTournaments.size());
    for (UUID tournamentId : userTournaments.values()) {
        managerFactory.tournamentManager().quit(tournamentId, userId);
    }
    userTournaments.clear();
    constructing.clear();
    logger.trace("REMOVE " + userName + " Tables " + tables.size());
    for (Entry<UUID, Table> entry : tables.entrySet()) {
        logger.debug("-- leave tableId: " + entry.getValue().getId());
        managerFactory.tableManager().leaveTable(userId, entry.getValue().getId());
    }
    tables.clear();
    sideboarding.clear();
    logger.trace("REMOVE " + userName + " Game sessions: " + gameSessions.size());
    for (GameSessionPlayer gameSessionPlayer : gameSessions.values()) {
        logger.debug("-- kill game session of gameId: " + gameSessionPlayer.getGameId());
        managerFactory.gameManager().quitMatch(gameSessionPlayer.getGameId(), userId);
        gameSessionPlayer.quitGame();
    }
    gameSessions.clear();
    logger.trace("REMOVE " + userName + " watched Games " + watchedGames.size());
    for (Iterator<UUID> it = watchedGames.iterator(); it.hasNext(); ) {
        // Iterator to prevent ConcurrentModificationException
        UUID gameId = it.next();
        managerFactory.gameManager().stopWatching(gameId, userId);
    }
    watchedGames.clear();
    logger.trace("REMOVE " + userName + " Chats ");
    managerFactory.chatManager().removeUser(userId, reason);
}
Also used : Table(mage.game.Table) DraftSession(mage.server.draft.DraftSession) GameSessionPlayer(mage.server.game.GameSessionPlayer)

Example 2 with Table

use of mage.game.Table in project mage by magefree.

the class MageServerImpl method quitDraft.

@Override
public void quitDraft(final UUID draftId, final String sessionId) throws MageException {
    execute("quitDraft", sessionId, () -> {
        try {
            callExecutor.execute(() -> {
                managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
                    UUID userId = session.getUserId();
                    UUID tableId = managerFactory.draftManager().getControllerByDraftId(draftId).getTableId();
                    Table table = managerFactory.tableManager().getTable(tableId);
                    if (table.isTournament()) {
                        UUID tournamentId = table.getTournament().getId();
                        managerFactory.tournamentManager().quit(tournamentId, userId);
                    }
                });
            });
        } catch (Exception ex) {
            handleException(ex);
        }
    });
}
Also used : Table(mage.game.Table) MageVersionException(mage.remote.MageVersionException) MageException(mage.MageException)

Example 3 with Table

use of mage.game.Table in project mage by magefree.

the class UserNameSorter method createTable.

@Override
public TableView createTable(UUID userId, MatchOptions options) {
    Table table = managerFactory.tableManager().createTable(this.getRoomId(), userId, options);
    tables.put(table.getId(), table);
    return new TableView(table);
}
Also used : Table(mage.game.Table) TableView(mage.view.TableView)

Example 4 with Table

use of mage.game.Table in project mage by magefree.

the class UserNameSorter method update.

private void update() {
    List<Table> allTables = new ArrayList<>(tables.values());
    allTables.sort(new TableListSorter());
    List<MatchView> matchList = new ArrayList<>();
    List<TableView> tableList = new ArrayList<>();
    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 removeUserFromAllTablesAndChat it
            if (table.isTournament()) {
                managerFactory.tournamentManager().removeTournament(table.getTournament().getId());
            }
            this.removeTable(table.getId());
        }
    }
    tableView = tableList;
    matchView = matchList;
    List<UsersView> users = new ArrayList<>();
    for (User user : managerFactory.userManager().getUsers()) {
        if (user.getUserState() != User.UserState.Offline && !user.getName().equals("Admin")) {
            try {
                users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getMatchHistory(), user.getMatchQuitRatio(), user.getTourneyHistory(), user.getTourneyQuitRatio(), user.getGameInfo(), user.getPingInfo(), user.getUserData().getGeneralRating(), user.getUserData().getConstructedRating(), user.getUserData().getLimitedRating()));
            } 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>", user.getUserData() != null ? user.getUserData().getGeneralRating() : 0, user.getUserData() != null ? user.getUserData().getConstructedRating() : 0, user.getUserData() != null ? user.getUserData().getLimitedRating() : 0));
            }
        }
    }
    users.sort((one, two) -> one.getUserName().compareToIgnoreCase(two.getUserName()));
    List<RoomUsersView> roomUserInfo = new ArrayList<>();
    roomUserInfo.add(new RoomUsersView(users, managerFactory.gameManager().getNumberActiveGames(), managerFactory.threadExecutor().getActiveThreads(managerFactory.threadExecutor().getGameExecutor()), managerFactory.configSettings().getMaxGameThreads()));
    roomUsersView = roomUserInfo;
}
Also used : Table(mage.game.Table) User(mage.server.User) MatchView(mage.view.MatchView) MageException(mage.MageException) GameException(mage.game.GameException) RoomUsersView(mage.view.RoomUsersView) UsersView(mage.view.UsersView) RoomUsersView(mage.view.RoomUsersView) TableView(mage.view.TableView)

Example 5 with Table

use of mage.game.Table in project mage by magefree.

the class UserNameSorter method removeTable.

@Override
public void removeTable(UUID tableId) {
    Table table = tables.get(tableId);
    if (table != null) {
        table.cleanUp();
        tables.remove(tableId);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Table removed: " + tableId);
        }
    }
}
Also used : Table(mage.game.Table)

Aggregations

Table (mage.game.Table)12 GameException (mage.game.GameException)4 MageException (mage.MageException)3 TournamentPlayer (mage.game.tournament.TournamentPlayer)3 TableView (mage.view.TableView)3 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 TableManager (mage.server.managers.TableManager)2 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Game (mage.game.Game)1 Match (mage.game.match.Match)1 MageVersionException (mage.remote.MageVersionException)1 User (mage.server.User)1 DraftSession (mage.server.draft.DraftSession)1 GameSessionPlayer (mage.server.game.GameSessionPlayer)1 MatchView (mage.view.MatchView)1 RoomUsersView (mage.view.RoomUsersView)1 UsersView (mage.view.UsersView)1