Search in sources :

Example 1 with User

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

the class GameSessionPlayer method requestPermissionToRollbackTurn.

public void requestPermissionToRollbackTurn(UUID requestingUserId, int numberTurns) {
    if (!killed) {
        Optional<User> requestingUser = userManager.getUser(requestingUserId);
        Optional<User> requestedUser = userManager.getUser(userId);
        if (requestedUser.isPresent() && requestingUser.isPresent()) {
            String message;
            switch(numberTurns) {
                case 0:
                    message = "Allow rollback to the start of the current turn?";
                    break;
                case 1:
                    message = "Allow rollback to the start of the previous turn?";
                    break;
                default:
                    message = "Allow to rollback " + numberTurns + " turns?";
            }
            UserRequestMessage userRequestMessage = new UserRequestMessage("Request by " + requestedUser.get().getName(), message);
            userRequestMessage.setRelatedUser(requestingUserId, requestingUser.get().getName());
            userRequestMessage.setGameId(game.getId());
            userRequestMessage.setButton1("Accept", PlayerAction.ADD_PERMISSION_TO_ROLLBACK_TURN);
            userRequestMessage.setButton2("Deny", PlayerAction.DENY_PERMISSON_TO_ROLLBACK_TURN);
            requestedUser.get().fireCallback(new ClientCallback(ClientCallbackMethod.USER_REQUEST_DIALOG, game.getId(), userRequestMessage));
        }
    }
}
Also used : ClientCallback(mage.interfaces.callback.ClientCallback) User(mage.server.User)

Example 2 with User

use of mage.server.User 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 3 with User

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

the class TournamentController method checkToReplaceDraftPlayerByAi.

private boolean checkToReplaceDraftPlayerByAi(UUID userId, TournamentPlayer leavingPlayer) {
    int humans = 0;
    for (TournamentPlayer tPlayer : tournament.getPlayers()) {
        if (tPlayer.getPlayer().isHuman()) {
            humans++;
        }
    }
    // replace player that quits with draft bot
    if (humans > 1) {
        Optional<User> user = managerFactory.userManager().getUser(userId);
        managerFactory.tableManager().getController(tableId).ifPresent(tableController -> {
            String replacePlayerName = "Draftbot";
            if (user.isPresent()) {
                replacePlayerName = "Draftbot (" + user.get().getName() + ')';
            }
            tableController.replaceDraftPlayer(leavingPlayer.getPlayer(), replacePlayerName, PlayerType.COMPUTER_DRAFT_BOT, 5);
            if (user.isPresent()) {
                user.get().removeDraft(leavingPlayer.getPlayer().getId());
                user.get().removeTable(leavingPlayer.getPlayer().getId());
                user.get().removeTournament(leavingPlayer.getPlayer().getId());
            }
            managerFactory.chatManager().broadcast(chatId, "", leavingPlayer.getPlayer().getLogName() + " was replaced by draftbot", MessageColor.BLACK, true, null, MessageType.STATUS, null);
        });
        return true;
    }
    return false;
}
Also used : User(mage.server.User) TournamentPlayer(mage.game.tournament.TournamentPlayer)

Example 4 with User

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

the class TournamentController method join.

public synchronized void join(UUID userId) {
    UUID playerId = userPlayerMap.get(userId);
    if (playerId == null) {
        if (logger.isDebugEnabled()) {
            managerFactory.userManager().getUser(userId).ifPresent(user -> logger.debug(user.getName() + " shows tournament panel  tournamentId: " + tournament.getId()));
        }
        return;
    }
    if (tournamentSessions.containsKey(playerId)) {
        logger.debug("player reopened tournament panel userId: " + userId + " tournamentId: " + tournament.getId());
        return;
    }
    // first join of player
    TournamentSession tournamentSession = new TournamentSession(managerFactory, tournament, userId, tableId, playerId);
    tournamentSessions.put(playerId, tournamentSession);
    Optional<User> _user = managerFactory.userManager().getUser(userId);
    if (_user.isPresent()) {
        User user = _user.get();
        user.addTournament(playerId, tournament.getId());
        TournamentPlayer player = tournament.getPlayer(playerId);
        player.setJoined();
        logger.debug("player " + player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
        managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
        checkStart();
    } else {
        logger.error("User not found  userId: " + userId + "   tournamentId: " + tournament.getId());
    }
}
Also used : User(mage.server.User) TournamentPlayer(mage.game.tournament.TournamentPlayer) UUID(java.util.UUID)

Example 5 with User

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

the class GameController method attemptToFixGame.

public String attemptToFixGame(User user) {
    if (game == null) {
        return "";
    }
    GameState state = game.getState();
    if (state == null) {
        return "";
    }
    logger.warn("FIX command was called by " + user.getName() + " for game " + game.getId() + " - players: " + game.getPlayerList().stream().map(game::getPlayer).filter(Objects::nonNull).map(p -> p.getName() + (p.isInGame() ? " (play)" : " (out)")).collect(Collectors.joining(", ")));
    StringBuilder sb = new StringBuilder();
    sb.append("<font color='red'>FIX command called by ").append(user.getName()).append("</font>");
    // font resize start for all next logs
    sb.append("<font size='-2'>");
    sb.append("<br>Game ID: ").append(game.getId());
    if (game.getTurn().getPhaseType() == null) {
        sb.append("<br>Phase: not started").append(" Step: not started");
    } else {
        sb.append("<br>Phase: ").append(game.getTurn().getPhaseType().toString()).append(" Step: ").append(game.getTurn().getStepType().toString());
    }
    // pings info
    sb.append("<br>");
    sb.append(getPingsInfo());
    boolean fixedAlready = false;
    // for logs info
    List<String> fixActions = new ArrayList<>();
    // fix active
    Player playerActive = game.getPlayer(state.getActivePlayerId());
    sb.append("<br>Fixing active player: ").append(getName(playerActive));
    if (playerActive != null && !playerActive.canRespond()) {
        fixActions.add("active player fix");
        sb.append("<br><font color='red'>WARNING, active player can't respond.</font>");
        sb.append("<br>Try to concede...");
        playerActive.concede(game);
        // abort any wait response actions
        playerActive.leave();
        sb.append(" (").append(asWarning("OK")).append(", concede done)");
        sb.append("<br>Try to skip step...");
        Phase currentPhase = game.getPhase();
        if (currentPhase != null) {
            currentPhase.getStep().skipStep(game, state.getActivePlayerId());
            fixedAlready = true;
            sb.append(" (").append(asWarning("OK")).append(", skip step done)");
        } else {
            sb.append(" (").append(asBad("FAIL")).append(", step is null)");
        }
    } else {
        sb.append(playerActive != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
    }
    // fix lost choosing dialog
    Player choosingPlayer = game.getPlayer(state.getChoosingPlayerId());
    sb.append("<br>Fixing choosing player: ").append(getName(choosingPlayer));
    if (choosingPlayer != null && !choosingPlayer.canRespond()) {
        fixActions.add("choosing player fix");
        sb.append("<br><font color='red'>WARNING, choosing player can't respond.</font>");
        sb.append("<br>Try to concede...");
        choosingPlayer.concede(game);
        // abort any wait response actions
        choosingPlayer.leave();
        sb.append(" (").append(asWarning("OK")).append(", concede done)");
        sb.append("<br>Try to skip step...");
        if (fixedAlready) {
            sb.append(" (OK, already skipped before)");
        } else {
            Phase currentPhase = game.getPhase();
            if (currentPhase != null) {
                currentPhase.getStep().skipStep(game, state.getActivePlayerId());
                fixedAlready = true;
                sb.append(" (").append(asWarning("OK")).append(", skip step done)");
            } else {
                sb.append(" (").append(asBad("FAIL")).append(", step is null)");
            }
        }
    } else {
        sb.append(choosingPlayer != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
    }
    // fix lost priority
    Player priorityPlayer = game.getPlayer(state.getPriorityPlayerId());
    sb.append("<br>Fixing priority player: ").append(getName(priorityPlayer));
    if (priorityPlayer != null && !priorityPlayer.canRespond()) {
        fixActions.add("priority player fix");
        sb.append("<br><font color='red'>WARNING, priority player can't respond.</font>");
        sb.append("<br>Try to concede...");
        priorityPlayer.concede(game);
        // abort any wait response actions
        priorityPlayer.leave();
        sb.append(" (").append(asWarning("OK")).append(", concede done)");
        sb.append("<br>Try to skip step...");
        if (fixedAlready) {
            sb.append(" (").append(asWarning("OK")).append(", already skipped before)");
        } else {
            Phase currentPhase = game.getPhase();
            if (currentPhase != null) {
                currentPhase.getStep().skipStep(game, state.getActivePlayerId());
                fixedAlready = true;
                sb.append(" (").append(asWarning("OK")).append(", skip step done)");
            } else {
                sb.append(" (").append(asBad("FAIL")).append(", step is null)");
            }
        }
    } else {
        sb.append(priorityPlayer != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
    }
    // fix timeout
    sb.append("<br>Fixing future timeout: ");
    if (futureTimeout != null) {
        sb.append("cancelled?=").append(futureTimeout.isCancelled());
        sb.append("...done?=").append(futureTimeout.isDone());
        int delay = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
        sb.append("...getDelay?=").append(delay);
        if (delay < 25) {
            fixActions.add("future timeout fix");
            sb.append("<br><font color='red'>WARNING, future timeout delay < 25</font>");
            sb.append("<br>Try to pass...");
            PassAbility pass = new PassAbility();
            game.endTurn(pass);
            sb.append(" (").append(asWarning("OK")).append(", pass done)");
        } else {
            sb.append(" (").append(asGood("OK")).append(", delay > 25)");
        }
    } else {
        sb.append(" (").append(asGood("OK")).append(", timeout is not using)");
    }
    // ALL DONE
    if (fixActions.isEmpty()) {
        fixActions.add("none");
    }
    String appliedFixes = fixActions.stream().collect(Collectors.joining(", "));
    sb.append("<br>Applied fixes: ").append(appliedFixes);
    // font resize end
    sb.append("</font>");
    sb.append("<br>");
    logger.warn("FIX command result for game " + game.getId() + ": " + appliedFixes);
    return sb.toString();
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) java.util(java.util) Zone(mage.constants.Zone) MessageType(mage.view.ChatMessage.MessageType) Splitter(mage.server.util.Splitter) mage.game(mage.game) MessageColor(mage.view.ChatMessage.MessageColor) TableEvent(mage.game.events.TableEvent) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Player(mage.players.Player) mage.view(mage.view) Logger(org.apache.log4j.Logger) ManaType(mage.constants.ManaType) PlayerAction(mage.constants.PlayerAction) User(mage.server.User) SystemUtil(mage.server.util.SystemUtil) StreamUtils(mage.utils.StreamUtils) Card(mage.cards.Card) DeckCardLists(mage.cards.decks.DeckCardLists) PriorityTimer(mage.utils.timer.PriorityTimer) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Choice(mage.choices.Choice) PassAbility(mage.abilities.common.PassAbility) java.util.concurrent(java.util.concurrent) Cards(mage.cards.Cards) Deck(mage.cards.decks.Deck) Plane(mage.game.command.Plane) MageException(mage.MageException) CardRepository(mage.cards.repository.CardRepository) Collectors(java.util.stream.Collectors) Phase(mage.game.turn.Phase) Action(mage.interfaces.Action) Lock(java.util.concurrent.locks.Lock) PlayerQueryEvent(mage.game.events.PlayerQueryEvent) ManagerFactory(mage.server.managers.ManagerFactory) Main(mage.server.Main) java.io(java.io) CardInfo(mage.cards.repository.CardInfo) Permanent(mage.game.permanent.Permanent) Entry(java.util.Map.Entry) Listener(mage.game.events.Listener) GZIPOutputStream(java.util.zip.GZIPOutputStream) Ability(mage.abilities.Ability) MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) PassAbility(mage.abilities.common.PassAbility) Phase(mage.game.turn.Phase)

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