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