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