Search in sources :

Example 11 with User

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

the class GameController method sendInfoAboutPlayersNotJoinedYetAndTryToFixIt.

private void sendInfoAboutPlayersNotJoinedYetAndTryToFixIt() {
    // runs every 5 secs untill all players join
    for (Player player : game.getPlayers().values()) {
        if (player.canRespond() && player.isHuman()) {
            Optional<User> requestedUser = getUserByPlayerId(player.getId());
            if (requestedUser.isPresent()) {
                User user = requestedUser.get();
                // TODO: workaround to fix not started games in tourneys, need to find out real reason
                if (gameSessions.get(player.getId()) == null) {
                    // join the game because player has not joined or was removed because of disconnect
                    String problemPlayerFixes;
                    user.removeConstructing(player.getId());
                    managerFactory.gameManager().joinGame(game.getId(), user.getId());
                    logger.warn("Forced join of player " + player.getName() + " (" + user.getUserState() + ") to gameId: " + game.getId());
                    if (user.isConnected()) {
                        // init game session, see reconnect()
                        GameSessionPlayer session = gameSessions.get(player.getId());
                        if (session != null) {
                            problemPlayerFixes = "re-send start game event";
                            logger.warn("Send forced game start event for player " + player.getName() + " in gameId: " + game.getId());
                            user.ccGameStarted(session.getGameId(), player.getId());
                            session.init();
                            managerFactory.gameManager().sendPlayerString(session.getGameId(), user.getId(), "");
                        } else {
                            problemPlayerFixes = "leave on broken game session";
                            logger.error("Can't find game session for forced join, leave it: player " + player.getName() + " in gameId: " + game.getId());
                            player.leave();
                        }
                    } else {
                        problemPlayerFixes = "leave on disconnected";
                        logger.warn("User disconnected, leave him after forced join: player " + player.getName() + " in gameId: " + game.getId());
                        player.leave();
                    }
                    managerFactory.chatManager().broadcast(chatId, player.getName(), user.getPingInfo() + " is forced to join the game (waiting ends after " + GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS + " secs, applied fixes: " + problemPlayerFixes + ")", MessageColor.BLUE, true, game, ChatMessage.MessageType.STATUS, null);
                }
                if (!user.isConnected() && user.getSecondsDisconnected() > GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS) {
                    // Cancel player join possibility lately
                    logger.debug("Player " + player.getName() + " - canceled joining game (after " + user.getSecondsDisconnected() + " secs of inactivity) gameId: " + game.getId());
                    player.leave();
                }
            } else if (!player.hasLeft()) {
                logger.debug("Player " + player.getName() + " canceled game (no user) gameId: " + game.getId());
                player.leave();
            }
        }
    }
    checkStart();
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) User(mage.server.User)

Example 12 with User

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

the class GameSessionPlayer method requestPermissionToSeeHandCards.

public void requestPermissionToSeeHandCards(UUID watcherId) {
    if (!killed) {
        Optional<User> watcher = userManager.getUser(watcherId);
        Optional<User> user = userManager.getUser(userId);
        if (user.isPresent() && watcher.isPresent()) {
            UserRequestMessage userRequestMessage = new UserRequestMessage("User request", "Allow user <b>" + watcher.get().getName() + "</b> for this match to see your hand cards?<br>" + "(You can revoke this every time using related popup menu item of your battlefield.)");
            userRequestMessage.setRelatedUser(watcherId, watcher.get().getName());
            userRequestMessage.setGameId(game.getId());
            userRequestMessage.setButton1("Accept", PlayerAction.ADD_PERMISSION_TO_SEE_HAND_CARDS);
            userRequestMessage.setButton2("Reject", null);
            user.get().fireCallback(new ClientCallback(ClientCallbackMethod.USER_REQUEST_DIALOG, game.getId(), userRequestMessage));
        }
    }
}
Also used : ClientCallback(mage.interfaces.callback.ClientCallback) User(mage.server.User)

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