Search in sources :

Example 6 with User

use of mage.server.User in project mage by magefree.

the class GameController method requestPermissionToRollback.

private int requestPermissionToRollback(UUID userIdRequester, int numberTurns) {
    int requests = 0;
    for (Player player : game.getState().getPlayers().values()) {
        Optional<User> requestedUser = getUserByPlayerId(player.getId());
        if (player.isInGame() && player.isHuman() && requestedUser.isPresent() && !requestedUser.get().getId().equals(userIdRequester)) {
            requests++;
            GameSessionPlayer gameSession = gameSessions.get(player.getId());
            if (gameSession != null) {
                gameSession.requestPermissionToRollbackTurn(userIdRequester, numberTurns);
            }
        }
    }
    return requests;
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) User(mage.server.User)

Example 7 with User

use of mage.server.User in project mage by magefree.

the class TournamentController method isTournamentStillValid.

/**
 * Check tournaments that are not already finished, if they are in a still
 * valid state
 *
 * @param tableState state of the tournament table
 * @return true - if tournament is valid false - if tournament is not valid
 * and should be removed
 */
public boolean isTournamentStillValid(TableState tableState) {
    int activePlayers = 0;
    for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
        TournamentPlayer tournamentPlayer = tournament.getPlayer(entry.getValue());
        if (tournamentPlayer != null) {
            if (!tournamentPlayer.hasQuit()) {
                if (tournamentPlayer.getPlayer().isHuman()) {
                    Optional<User> user = managerFactory.userManager().getUser(entry.getKey());
                    if (!user.isPresent()) {
                        logger.debug("Tournament user is missing but player active -> start quit - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
                        // active tournament player but the user is no longer online
                        quit(entry.getKey());
                    } else {
                        activePlayers++;
                    }
                }
            }
        } else {
            // tournament player is missing
            logger.debug("Tournament player is missing - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
        }
    }
    for (TournamentPlayer tournamentPlayer : tournament.getPlayers()) {
        if (!tournamentPlayer.getPlayer().isHuman()) {
            if (!tournamentPlayer.hasQuit()) {
                activePlayers++;
            }
        }
    }
    if (activePlayers < 2 && tableState != TableState.WAITING) {
        logger.debug("Tournament has less than 2 active players - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
        return false;
    }
    return true;
}
Also used : User(mage.server.User) TournamentPlayer(mage.game.tournament.TournamentPlayer) UUID(java.util.UUID)

Example 8 with User

use of mage.server.User in project mage by magefree.

the class DraftSession method init.

public boolean init() {
    if (!killed) {
        Optional<User> user = managerFactory.userManager().getUser(userId);
        if (user.isPresent()) {
            if (futureTimeout != null && !futureTimeout.isDone()) {
                int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
                user.get().fireCallback(new ClientCallback(ClientCallbackMethod.DRAFT_INIT, draft.getId(), new DraftClientMessage(getDraftView(), getDraftPickView(remaining))));
            }
            return true;
        }
    }
    return false;
}
Also used : ClientCallback(mage.interfaces.callback.ClientCallback) User(mage.server.User) DraftClientMessage(mage.view.DraftClientMessage)

Example 9 with User

use of mage.server.User in project mage by magefree.

the class GameController method viewSideboard.

private void viewSideboard(UUID playerId, UUID userId, UUID targetPlayerId) {
    Player needPlayer = game.getPlayer(playerId);
    if (needPlayer != null && needPlayer.isHuman()) {
        for (MatchPlayer p : managerFactory.tableManager().getTable(tableId).getMatch().getPlayers()) {
            if (p.getPlayer().getId().equals(playerId)) {
                Optional<User> u = managerFactory.userManager().getUser(userId);
                u.ifPresent(user -> user.ccViewSideboard(tableId, game.getId(), targetPlayerId));
            }
        }
    }
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) User(mage.server.User) MatchPlayer(mage.game.match.MatchPlayer)

Example 10 with User

use of mage.server.User in project mage by magefree.

the class GameController method join.

public void join(UUID userId) {
    UUID playerId = userPlayerMap.get(userId);
    if (playerId == null) {
        logger.fatal("Join game failed!");
        logger.fatal("- gameId: " + game.getId());
        logger.fatal("- userId: " + userId);
        return;
    }
    Optional<User> user = managerFactory.userManager().getUser(userId);
    if (!user.isPresent()) {
        logger.fatal("User not found : " + userId);
        return;
    }
    Player player = game.getPlayer(playerId);
    if (player == null) {
        logger.fatal("Player not found - playerId: " + playerId);
        return;
    }
    GameSessionPlayer gameSession = gameSessions.get(playerId);
    String joinType;
    if (gameSession == null) {
        gameSession = new GameSessionPlayer(managerFactory, game, userId, playerId);
        final Lock w = gameSessionsLock.writeLock();
        w.lock();
        try {
            gameSessions.put(playerId, gameSession);
        } finally {
            w.unlock();
        }
        joinType = "joined";
    } else {
        joinType = "rejoined";
    }
    user.get().addGame(playerId, gameSession);
    logger.debug("Player " + player.getName() + ' ' + playerId + " has " + joinType + " gameId: " + game.getId());
    managerFactory.chatManager().broadcast(chatId, "", game.getPlayer(playerId).getLogName() + " has " + joinType + " the game", MessageColor.ORANGE, true, game, MessageType.GAME, null);
    checkStart();
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) User(mage.server.User) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

User (mage.server.User)12 MatchPlayer (mage.game.match.MatchPlayer)5 Player (mage.players.Player)5 TournamentPlayer (mage.game.tournament.TournamentPlayer)3 ClientCallback (mage.interfaces.callback.ClientCallback)3 UUID (java.util.UUID)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 MageException (mage.MageException)2 java.io (java.io)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 java.util.concurrent (java.util.concurrent)1 Collectors (java.util.stream.Collectors)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 Ability (mage.abilities.Ability)1 PassAbility (mage.abilities.common.PassAbility)1 Card (mage.cards.Card)1 Cards (mage.cards.Cards)1