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);
}
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);
}
});
}
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);
}
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;
}
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);
}
}
}
Aggregations