mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
rewrites to optionals
This commit is contained in:
parent
348faa345b
commit
ff6c6405aa
28 changed files with 760 additions and 494 deletions
|
|
@ -211,7 +211,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public TableView execute() throws MageException {
|
||||
try {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session to found : " + sessionId);
|
||||
return null;
|
||||
}
|
||||
UUID userId = session.get().getUserId();
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
logger.error("User for session not found. session = " + sessionId);
|
||||
|
|
@ -247,9 +252,14 @@ public class MageServerImpl implements MageServer {
|
|||
user.showUserMessage("Create tournament", message);
|
||||
throw new MageException("No message");
|
||||
}
|
||||
TableView table = GamesRoomManager.instance.getRoom(roomId).createTournamentTable(userId, options);
|
||||
logger.debug("Tournament table " + table.getTableId() + " created");
|
||||
return table;
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (!room.isPresent()) {
|
||||
|
||||
} else {
|
||||
TableView table = room.get().createTournamentTable(userId, options);
|
||||
logger.debug("Tournament table " + table.getTableId() + " created");
|
||||
return table;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -261,8 +271,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
execute("removeTable", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -271,13 +286,23 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("joinTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return false;
|
||||
}
|
||||
UUID userId = session.get().getUserId();
|
||||
logger.debug(name + " joins tableId: " + tableId);
|
||||
if (userId == null) {
|
||||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
return GamesRoomManager.instance.getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (!room.isPresent()) {
|
||||
logger.error("room not found : " + roomId);
|
||||
return false;
|
||||
}
|
||||
return room.get().joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
|
||||
}
|
||||
});
|
||||
|
|
@ -288,7 +313,12 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("joinTournamentTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return false;
|
||||
}
|
||||
UUID userId = session.get().getUserId();
|
||||
if (logger.isTraceEnabled()) {
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
user.ifPresent(user1 -> logger.trace("join tourn. tableId: " + tableId + ' ' + name));
|
||||
|
|
@ -297,7 +327,11 @@ public class MageServerImpl implements MageServer {
|
|||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
return GamesRoomManager.instance.getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
return room.get().joinTournamentTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
});
|
||||
|
|
@ -308,10 +342,16 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("submitDeck", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
boolean ret = TableManager.instance.submitDeck(userId, tableId, deckList);
|
||||
logger.debug("Session " + sessionId + " submitted deck");
|
||||
return ret;
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return false;
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
boolean ret = TableManager.instance.submitDeck(userId, tableId, deckList);
|
||||
logger.debug("Session " + sessionId + " submitted deck");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -319,9 +359,15 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void updateDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException, GameException {
|
||||
execute("updateDeck", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.updateDeck(userId, tableId, deckList);
|
||||
logger.trace("Session " + sessionId + " updated deck");
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.updateDeck(userId, tableId, deckList);
|
||||
logger.trace("Session " + sessionId + " updated deck");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -329,11 +375,11 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public List<TableView> getTables(UUID roomId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getTables();
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
return room.get().getTables();
|
||||
} else {
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
|
|
@ -345,47 +391,44 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public List<MatchView> getFinishedMatches(UUID roomId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getFinished();
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
return room.get().getFinished();
|
||||
} else {
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getRoomUsersInfo();
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
return room.get().getRoomUsersInfo();
|
||||
} else {
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws MageException {
|
||||
public Optional<TableView> getTable(UUID roomId, UUID tableId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getTable(tableId);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
return room.flatMap(r -> r.getTable(tableId));
|
||||
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -405,12 +448,22 @@ public class MageServerImpl implements MageServer {
|
|||
// }
|
||||
@Override
|
||||
public boolean startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (!TableManager.instance.getController(tableId).changeTableStateToStarting()) {
|
||||
Optional<TableController> controller = TableManager.instance.getController(tableId);
|
||||
if (!controller.isPresent()) {
|
||||
logger.error("table not found : " + tableId);
|
||||
return false;
|
||||
}
|
||||
if (!controller.get().changeTableStateToStarting()) {
|
||||
return false;
|
||||
}
|
||||
execute("startMatch", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.startMatch(userId, roomId, tableId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.startMatch(userId, roomId, tableId);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
@ -427,12 +480,22 @@ public class MageServerImpl implements MageServer {
|
|||
// }
|
||||
@Override
|
||||
public boolean startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (!TableManager.instance.getController(tableId).changeTableStateToStarting()) {
|
||||
Optional<TableController> controller = TableManager.instance.getController(tableId);
|
||||
if (!controller.isPresent()) {
|
||||
logger.error("table not found : " + tableId);
|
||||
return false;
|
||||
}
|
||||
if (!controller.get().changeTableStateToStarting()) {
|
||||
return false;
|
||||
}
|
||||
execute("startTournament", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.startTournament(userId, roomId, tableId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.startTournament(userId, roomId, tableId);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
@ -463,8 +526,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException {
|
||||
execute("joinChat", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ChatManager.instance.joinChat(chatId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ChatManager.instance.joinChat(chatId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -472,8 +540,13 @@ public class MageServerImpl implements MageServer {
|
|||
public void leaveChat(final UUID chatId, final String sessionId) throws MageException {
|
||||
execute("leaveChat", sessionId, () -> {
|
||||
if (chatId != null) {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ChatManager.instance.leaveChat(chatId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ChatManager.instance.leaveChat(chatId, userId);
|
||||
}
|
||||
} else {
|
||||
logger.warn("The chatId is null. sessionId = " + sessionId);
|
||||
}
|
||||
|
|
@ -493,13 +566,18 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getRoomChatId(UUID roomId) throws MageException {
|
||||
public Optional<UUID> getRoomChatId(UUID roomId) throws MageException {
|
||||
try {
|
||||
return GamesRoomManager.instance.getRoom(roomId).getChatId();
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (!room.isPresent()) {
|
||||
logger.error("roomId not found : " + roomId);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(room.get().getChatId());
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -507,8 +585,14 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("isTableOwner", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return TableManager.instance.isTableOwner(tableId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return false;
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
return TableManager.instance.isTableOwner(tableId, userId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -516,63 +600,99 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void swapSeats(final String sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws MageException {
|
||||
execute("swapSeats", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.swapSeats(tableId, userId, seatNum1, seatNum2);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.swapSeats(tableId, userId, seatNum1, seatNum2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
TableState tableState = TableManager.instance.getController(tableId).getTableState();
|
||||
if (tableState != TableState.WAITING && tableState != TableState.READY_TO_START) {
|
||||
// table was already started, so player can't leave anymore now
|
||||
return false;
|
||||
Optional<TableController> tableController = TableManager.instance.getController(tableId);
|
||||
if (tableController.isPresent()) {
|
||||
TableState tableState = tableController.get().getTableState();
|
||||
if (tableState != TableState.WAITING && tableState != TableState.READY_TO_START) {
|
||||
// table was already started, so player can't leave anymore now
|
||||
return false;
|
||||
}
|
||||
execute("leaveTable", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (!room.isPresent()) {
|
||||
logger.error("room not found : " + roomId);
|
||||
} else {
|
||||
|
||||
room.get().leaveTable(userId, tableId);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.error("table not found : " + tableId);
|
||||
}
|
||||
execute("leaveTable", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
GamesRoomManager.instance.getRoom(roomId).leaveTable(userId, tableId);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getTableChatId(UUID tableId) throws MageException {
|
||||
public Optional<UUID> getTableChatId(UUID tableId) throws MageException {
|
||||
try {
|
||||
return TableManager.instance.getChatId(tableId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("joinGame", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
GameManager.instance.joinGame(gameId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
GameManager.instance.joinGame(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("joinDraft", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
DraftManager.instance.joinDraft(draftId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
DraftManager.instance.joinDraft(draftId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
execute("joinTournament", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TournamentManager.instance.joinTournament(tournamentId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TournamentManager.instance.joinTournament(tournamentId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getGameChatId(UUID gameId) throws MageException {
|
||||
public Optional<UUID> getGameChatId(UUID gameId) throws MageException {
|
||||
try {
|
||||
return GameManager.instance.getChatId(gameId);
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -583,13 +703,13 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws MageException {
|
||||
public Optional<UUID> getTournamentChatId(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.instance.getChatId(tournamentId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -661,11 +781,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendCardMark(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
||||
execute("sendCardMark", sessionId, () -> {
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
DraftManager.instance.sendCardMark(draftId, session.getUserId(), cardPick);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
UUID userId = session.get().getUserId();
|
||||
DraftManager.instance.sendCardMark(draftId, userId, cardPick);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -673,11 +794,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void quitMatch(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("quitMatch", sessionId, () -> {
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
GameManager.instance.quitMatch(gameId, session.getUserId());
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " gameId:" + gameId);
|
||||
UUID userId = session.get().getUserId();
|
||||
|
||||
GameManager.instance.quitMatch(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -685,11 +808,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void quitTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
execute("quitTournament", sessionId, () -> {
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
TournamentManager.instance.quit(tournamentId, session.getUserId());
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " tournamentId:" + tournamentId);
|
||||
UUID userId = session.get().getUserId();
|
||||
|
||||
TournamentManager.instance.quit(tournamentId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -697,16 +822,17 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void quitDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("quitDraft", sessionId, () -> {
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session == null) {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
return;
|
||||
}
|
||||
UUID tableId = DraftManager.instance.getControllerByDraftId(draftId).getTableId();
|
||||
Table table = TableManager.instance.getTable(tableId);
|
||||
if (table.isTournament()) {
|
||||
UUID tournamentId = table.getTournament().getId();
|
||||
TournamentManager.instance.quit(tournamentId, session.getUserId());
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
UUID tableId = DraftManager.instance.getControllerByDraftId(draftId).getTableId();
|
||||
Table table = TableManager.instance.getTable(tableId);
|
||||
if (table.isTournament()) {
|
||||
UUID tournamentId = table.getTournament().getId();
|
||||
TournamentManager.instance.quit(tournamentId, userId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -714,12 +840,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerAction(final PlayerAction playerAction, final UUID gameId, final String sessionId, final Object data) throws MageException {
|
||||
execute("sendPlayerAction", sessionId, () -> {
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session == null) {
|
||||
logger.error("Session not found sessionId: " + sessionId + " gameId:" + gameId);
|
||||
return;
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
GameManager.instance.sendPlayerAction(playerAction, gameId, userId, data);
|
||||
}
|
||||
GameManager.instance.sendPlayerAction(playerAction, gameId, session.getUserId(), data);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -728,8 +855,18 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return GamesRoomManager.instance.getRoom(roomId).watchTable(userId, tableId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return false;
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
if (GamesRoomManager.instance.getRoom(roomId).isPresent()) {
|
||||
return GamesRoomManager.instance.getRoom(roomId).get().watchTable(userId, tableId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -742,19 +879,29 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void watchGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("watchGame", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
GameManager.instance.watchGame(gameId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
GameManager.instance.watchGame(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("stopWatching", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
GameManager.instance.stopWatching(gameId, userId);
|
||||
user.removeGameWatchInfo(gameId);
|
||||
});
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
GameManager.instance.stopWatching(gameId, userId);
|
||||
user.removeGameWatchInfo(gameId);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
|
@ -762,48 +909,78 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void replayGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("replayGame", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.replayGame(gameId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.replayGame(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("startReplay", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.startReplay(gameId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.startReplay(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("stopReplay", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.stopReplay(gameId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.stopReplay(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("nextPlay", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.nextPlay(gameId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.nextPlay(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previousPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("previousPlay", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.previousPlay(gameId, userId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.previousPlay(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipForward(final UUID gameId, final String sessionId, final int moves) throws MageException {
|
||||
execute("skipForward", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.skipForward(gameId, userId, moves);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.skipForward(gameId, userId, moves);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -832,8 +1009,13 @@ public class MageServerImpl implements MageServer {
|
|||
public void cheat(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
|
||||
execute("cheat", sessionId, () -> {
|
||||
if (testMode) {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
GameManager.instance.cheat(gameId, userId, playerId, deckList);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
GameManager.instance.cheat(gameId, userId, playerId, deckList);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -844,8 +1026,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public Boolean execute() {
|
||||
if (testMode) {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return GameManager.instance.cheat(gameId, userId, playerId, cardName);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
return GameManager.instance.cheat(gameId, userId, playerId, cardName);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -957,8 +1144,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
execute("removeTable", sessionId, () -> {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -971,8 +1163,13 @@ public class MageServerImpl implements MageServer {
|
|||
public void sendFeedbackMessage(final String sessionId, final String username, final String title, final String type, final String message, final String email) throws MageException {
|
||||
if (title != null && message != null) {
|
||||
execute("sendFeedbackMessage", sessionId, () -> {
|
||||
String host = SessionManager.instance.getSession(sessionId).getHost();
|
||||
FeedbackServiceImpl.instance.feedback(username, title, type, message, email, host);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error(String.format("Session not found: %s", sessionId));
|
||||
} else {
|
||||
FeedbackServiceImpl.instance.feedback(username, title, type, message, email, session.get().getHost());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1104,8 +1301,14 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public GameView execute() throws MageException {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return GameManager.instance.getGameView(gameId, userId, playerId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return null;
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
return GameManager.instance.getGameView(gameId, userId, playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1120,8 +1323,14 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return TableManager.instance.watchTable(userId, tableId);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return false;
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
return TableManager.instance.watchTable(userId, tableId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1140,9 +1349,9 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public DraftPickView execute() {
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
return DraftManager.instance.sendCardPick(draftId, session.getUserId(), cardPick, hiddenCards);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (session.isPresent()) {
|
||||
return DraftManager.instance.sendCardPick(draftId, session.get().getUserId(), cardPick, hiddenCards);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
}
|
||||
|
|
@ -1163,7 +1372,12 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public TableView execute() throws MageException {
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return null;
|
||||
}
|
||||
UUID userId = session.get().getUserId();
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
logger.error("User for session not found. session = " + sessionId);
|
||||
|
|
@ -1183,13 +1397,19 @@ public class MageServerImpl implements MageServer {
|
|||
throw new MageException("No message");
|
||||
}
|
||||
|
||||
TableView table = GamesRoomManager.instance.getRoom(roomId).createTable(userId, options);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("TABLE created - tableId: " + table.getTableId() + ' ' + table.getTableName());
|
||||
logger.debug("- " + user.getName() + " userId: " + user.getId());
|
||||
logger.debug("- chatId: " + TableManager.instance.getChatId(table.getTableId()));
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
TableView table = room.get().createTable(userId, options);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("TABLE created - tableId: " + table.getTableId() + ' ' + table.getTableName());
|
||||
logger.debug("- " + user.getName() + " userId: " + user.getId());
|
||||
logger.debug("- chatId: " + TableManager.instance.getChatId(table.getTableId()));
|
||||
}
|
||||
return table;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,17 +263,20 @@ public final class Main {
|
|||
|
||||
@Override
|
||||
public void handleConnectionException(Throwable throwable, Client client) {
|
||||
Session session = SessionManager.instance.getSession(client.getSessionId());
|
||||
if (session != null) {
|
||||
|
||||
String sessionId = client.getSessionId();
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
StringBuilder sessionInfo = new StringBuilder();
|
||||
Optional<User> user = UserManager.instance.getUser(session.getUserId());
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent()) {
|
||||
sessionInfo.append(user.get().getName()).append(" [").append(user.get().getGameInfo()).append(']');
|
||||
} else {
|
||||
sessionInfo.append("[user missing] ");
|
||||
}
|
||||
sessionInfo.append(" at ").append(session.getHost()).append(" sessionId: ").append(session.getId());
|
||||
sessionInfo.append(" at ").append(session.get().getHost()).append(" sessionId: ").append(session.get().getId());
|
||||
if (throwable instanceof ClientDisconnectedException) {
|
||||
// Seems like the random diconnects from public server land here and should not be handled as explicit disconnects
|
||||
// So it should be possible to reconnect to server and continue games if DisconnectReason is set to LostConnection
|
||||
|
|
@ -372,7 +375,12 @@ public final class Main {
|
|||
} else {
|
||||
host = "localhost";
|
||||
}
|
||||
SessionManager.instance.getSession(sessionId).setHost(host);
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
session.get().setHost(host);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
package mage.server;
|
||||
|
||||
import java.rmi.Remote;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,16 +27,12 @@
|
|||
*/
|
||||
package mage.server;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import mage.MageException;
|
||||
import mage.constants.Constants;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.players.net.UserData;
|
||||
import mage.players.net.UserGroup;
|
||||
import mage.server.game.GamesRoom;
|
||||
import mage.server.game.GamesRoomManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.server.util.SystemUtil;
|
||||
|
|
@ -47,8 +43,13 @@ import org.jboss.remoting.callback.Callback;
|
|||
import org.jboss.remoting.callback.HandleCallbackException;
|
||||
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Session {
|
||||
|
|
@ -129,7 +130,7 @@ public class Session {
|
|||
}
|
||||
}
|
||||
|
||||
static private String validateUserName(String userName) {
|
||||
private static String validateUserName(String userName) {
|
||||
if (userName.equals("Admin")) {
|
||||
return "User name Admin already in use";
|
||||
}
|
||||
|
|
@ -152,7 +153,7 @@ public class Session {
|
|||
return null;
|
||||
}
|
||||
|
||||
static private String validatePassword(String password, String userName) {
|
||||
private static String validatePassword(String password, String userName) {
|
||||
ConfigSettings config = ConfigSettings.instance;
|
||||
if (password.length() < config.getMinPasswordLength()) {
|
||||
return "Password may not be shorter than " + config.getMinPasswordLength() + " characters";
|
||||
|
|
@ -171,7 +172,7 @@ public class Session {
|
|||
return null;
|
||||
}
|
||||
|
||||
static private String validateEmail(String email) {
|
||||
private static String validateEmail(String email) {
|
||||
|
||||
if (email == null || email.isEmpty()) {
|
||||
return "Email address cannot be blank";
|
||||
|
|
@ -248,10 +249,12 @@ public class Session {
|
|||
}
|
||||
this.userId = user.getId();
|
||||
if (reconnect) { // must be connected to receive the message
|
||||
UUID chatId = GamesRoomManager.instance.getRoom(GamesRoomManager.instance.getMainRoomId()).getChatId();
|
||||
if (chatId != null) {
|
||||
ChatManager.instance.joinChat(chatId, userId);
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(GamesRoomManager.instance.getMainRoomId());
|
||||
if (!room.isPresent()) {
|
||||
logger.error("main room not found");
|
||||
return null;
|
||||
}
|
||||
ChatManager.instance.joinChat(room.get().getChatId(), userId);
|
||||
ChatManager.instance.sendReconnectMessage(userId);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -331,7 +334,7 @@ public class Session {
|
|||
return; //user was already disconnected by other thread
|
||||
}
|
||||
User user = _user.get();
|
||||
if(!user.isConnected()){
|
||||
if (!user.isConnected()) {
|
||||
return;
|
||||
}
|
||||
if (!user.getSessionId().equals(sessionId)) {
|
||||
|
|
@ -381,7 +384,7 @@ public class Session {
|
|||
callbackHandler.handleCallbackOneway(new Callback(call));
|
||||
} catch (HandleCallbackException ex) {
|
||||
ex.printStackTrace();
|
||||
UserManager.instance.getUser(userId).ifPresent(user-> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
logger.warn("SESSION CALLBACK EXCEPTION - " + user.getName() + " userId " + userId);
|
||||
logger.warn(" - method: " + call.getMethod());
|
||||
logger.warn(" - cause: " + getBasicCause(ex).toString());
|
||||
|
|
|
|||
|
|
@ -49,15 +49,15 @@ public enum SessionManager {
|
|||
|
||||
private final ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<>();
|
||||
|
||||
public Session getSession(@Nonnull String sessionId) {
|
||||
public Optional<Session> getSession(@Nonnull String sessionId) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null && session.getUserId() != null && UserManager.instance.getUser(session.getUserId()) == null) {
|
||||
logger.error("User for session " + sessionId + " with userId " + session.getUserId() + " is missing. Session removed.");
|
||||
// can happen if user from same host signs in multiple time with multiple clients, after he disconnects with one client
|
||||
disconnect(sessionId, DisconnectReason.ConnectingOtherInstance);
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
return session;
|
||||
return Optional.of(session);
|
||||
}
|
||||
|
||||
public void createSession(String sessionId, InvokerCallbackHandler callbackHandler) {
|
||||
|
|
@ -168,26 +168,26 @@ public enum SessionManager {
|
|||
*/
|
||||
public void disconnectUser(String sessionId, String userSessionId) {
|
||||
if (isAdmin(sessionId)) {
|
||||
User userAdmin;
|
||||
if ((userAdmin = getUserFromSession(sessionId)) != null) {
|
||||
User user;
|
||||
if ((user = getUserFromSession(userSessionId)) != null) {
|
||||
getUserFromSession(sessionId).ifPresent(admin -> {
|
||||
Optional<User> u = getUserFromSession(userSessionId);
|
||||
if (u.isPresent()) {
|
||||
User user = u.get();
|
||||
user.showUserMessage("Admin operation", "Your session was disconnected by Admin.");
|
||||
userAdmin.showUserMessage("Admin action", "User" + user.getName() + " was disconnected.");
|
||||
admin.showUserMessage("Admin action", "User" + user.getName() + " was disconnected.");
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
} else {
|
||||
userAdmin.showUserMessage("Admin operation", "User with sessionId " + userSessionId + " could not be found!");
|
||||
admin.showUserMessage("Admin operation", "User with sessionId " + userSessionId + " could not be found!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private User getUserFromSession(String sessionId) {
|
||||
Session session = getSession(sessionId);
|
||||
if (session == null) {
|
||||
return null;
|
||||
private Optional<User> getUserFromSession(String sessionId) {
|
||||
Optional<Session> session = getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return UserManager.instance.getUser(session.getUserId()).get();
|
||||
return UserManager.instance.getUser(session.get().getUserId());
|
||||
}
|
||||
|
||||
public void endUserSession(String sessionId, String userSessionId) {
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ public class TableController {
|
|||
newTournamentPlayer.setState(oldTournamentPlayer.getState());
|
||||
newTournamentPlayer.setReplacedTournamentPlayer(oldTournamentPlayer);
|
||||
|
||||
DraftManager.instance.getController(table.getId()).replacePlayer(oldPlayer, newPlayer);
|
||||
DraftManager.instance.getController(table.getId()).ifPresent(controller -> controller.replacePlayer(oldPlayer, newPlayer));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -307,29 +307,29 @@ public class TableController {
|
|||
user.showUserMessage("Join Table", message);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean restrictedColor = false;
|
||||
String badColor = "";
|
||||
int colorVal = edhPowerLevel % 10;
|
||||
if (colorVal == 6 && deckEdhPowerLevel >= 10000000) {
|
||||
restrictedColor = true;
|
||||
badColor = "white";
|
||||
badColor = "white";
|
||||
}
|
||||
if (colorVal == 4 && deckEdhPowerLevel % 10000000 >= 1000000) {
|
||||
restrictedColor = true;
|
||||
badColor = "blue";
|
||||
badColor = "blue";
|
||||
}
|
||||
if (colorVal == 3 && deckEdhPowerLevel % 1000000 >= 100000) {
|
||||
restrictedColor = true;
|
||||
badColor = "black";
|
||||
badColor = "black";
|
||||
}
|
||||
if (colorVal == 2 && deckEdhPowerLevel % 100000 >= 10000) {
|
||||
restrictedColor = true;
|
||||
badColor = "red";
|
||||
badColor = "red";
|
||||
}
|
||||
if (colorVal == 1 && deckEdhPowerLevel % 10000 >= 1000) {
|
||||
restrictedColor = true;
|
||||
badColor = "green";
|
||||
badColor = "green";
|
||||
}
|
||||
if (restrictedColor) {
|
||||
String message = new StringBuilder("Your deck contains ")
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import mage.game.match.Match;
|
|||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
import mage.players.Player;
|
||||
import mage.server.game.GameController;
|
||||
import mage.server.game.GameManager;
|
||||
|
|
@ -114,19 +115,22 @@ public enum TableManager {
|
|||
return tables.get(tableId);
|
||||
}
|
||||
|
||||
public Match getMatch(UUID tableId) {
|
||||
public Optional<Match> getMatch(UUID tableId) {
|
||||
if (controllers.containsKey(tableId)) {
|
||||
return controllers.get(tableId).getMatch();
|
||||
return Optional.of(controllers.get(tableId).getMatch());
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Collection<Table> getTables() {
|
||||
return tables.values();
|
||||
}
|
||||
|
||||
public TableController getController(UUID tableId) {
|
||||
return controllers.get(tableId);
|
||||
public Optional<TableController> getController(UUID tableId) {
|
||||
if (controllers.containsKey(tableId)) {
|
||||
return Optional.of(controllers.get(tableId));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException {
|
||||
|
|
@ -214,11 +218,11 @@ public enum TableManager {
|
|||
}
|
||||
}
|
||||
|
||||
public UUID getChatId(UUID tableId) {
|
||||
public Optional<UUID> getChatId(UUID tableId) {
|
||||
if (controllers.containsKey(tableId)) {
|
||||
return controllers.get(tableId).getChatId();
|
||||
return Optional.of(controllers.get(tableId).getChatId());
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -313,9 +317,9 @@ public enum TableManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void addPlayer(UUID userId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
|
||||
public void addPlayer(UUID userId, UUID tableId, TournamentPlayer player) throws GameException {
|
||||
if (controllers.containsKey(tableId)) {
|
||||
controllers.get(tableId).addPlayer(userId, player, playerType, deck);
|
||||
controllers.get(tableId).addPlayer(userId, player.getPlayer(), player.getPlayerType(), player.getDeck());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -352,10 +356,10 @@ public enum TableManager {
|
|||
Collection<User> users = UserManager.instance.getUsers();
|
||||
logger.debug("--------User: " + users.size() + " [userId | since | lock | name -----------------------");
|
||||
for (User user : users) {
|
||||
Session session = SessionManager.instance.getSession(user.getSessionId());
|
||||
Optional<Session> session = SessionManager.instance.getSession(user.getSessionId());
|
||||
String sessionState = "N";
|
||||
if (session != null) {
|
||||
if (session.isLocked()) {
|
||||
if (session.isPresent()) {
|
||||
if (session.get().isLocked()) {
|
||||
sessionState = "L";
|
||||
} else {
|
||||
sessionState = "+";
|
||||
|
|
@ -390,8 +394,7 @@ public enum TableManager {
|
|||
if (table.getState() != TableState.FINISHED) {
|
||||
// remove tables and games not valid anymore
|
||||
logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
|
||||
TableController tableController = getController(table.getId());
|
||||
if (tableController != null) {
|
||||
getController(table.getId()).ifPresent(tableController -> {
|
||||
if ((table.isTournament() && !tableController.isTournamentStillValid()) ||
|
||||
(!table.isTournament() && !tableController.isMatchTableStillValid())) {
|
||||
try {
|
||||
|
|
@ -401,7 +404,7 @@ public enum TableManager {
|
|||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.debug("Table Health check error tableId: " + table.getId());
|
||||
|
|
|
|||
|
|
@ -27,14 +27,8 @@
|
|||
*/
|
||||
package mage.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import mage.cards.decks.Deck;
|
||||
|
|
@ -246,10 +240,9 @@ public class User {
|
|||
|
||||
public void fireCallback(final ClientCallback call) {
|
||||
if (isConnected()) {
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.fireCallback(call);
|
||||
}
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session ->
|
||||
session.fireCallback(call)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -378,8 +371,13 @@ public class User {
|
|||
entry.getValue().construct(0); // TODO: Check if this is correct
|
||||
}
|
||||
for (Entry<UUID, Deck> entry : sideboarding.entrySet()) {
|
||||
TableController controller = TableManager.instance.getController(entry.getKey());
|
||||
ccSideboard(entry.getValue(), entry.getKey(), controller.getRemainingTime(), controller.getOptions().isLimited());
|
||||
Optional<TableController> controller = TableManager.instance.getController(entry.getKey());
|
||||
if(controller.isPresent()) {
|
||||
ccSideboard(entry.getValue(), entry.getKey(), controller.get().getRemainingTime(), controller.get().getOptions().isLimited());
|
||||
}
|
||||
else{
|
||||
logger.error("sideboarding id not found : "+entry.getKey());
|
||||
}
|
||||
}
|
||||
ServerMessagesUtil.instance.incReconnects();
|
||||
logger.trace(userName + " ended reconnect");
|
||||
|
|
@ -784,8 +782,11 @@ public class User {
|
|||
if (table.getState() == TableState.FINISHED) {
|
||||
number++;
|
||||
} else {
|
||||
TableController tableController = TableManager.instance.getController(table.getId());
|
||||
if (tableController != null && tableController.isUserStillActive(userId)) {
|
||||
Optional<TableController> tableController = TableManager.instance.getController(table.getId());
|
||||
if(!tableController.isPresent()){
|
||||
logger.error("table not found : "+table.getId());
|
||||
}
|
||||
else if (tableController.get().isUserStillActive(userId)) {
|
||||
number++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ package mage.server.draft;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -129,11 +130,11 @@ public class DraftController {
|
|||
checkStart();
|
||||
}
|
||||
|
||||
public DraftSession getDraftSession(UUID playerId) {
|
||||
public Optional<DraftSession> getDraftSession(UUID playerId) {
|
||||
if (draftSessions.containsKey(playerId)) {
|
||||
return draftSessions.get(playerId);
|
||||
return Optional.of(draftSessions.get(playerId));
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public boolean replacePlayer(Player oldPlayer, Player newPlayer) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.server.draft;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -87,12 +88,7 @@ public enum DraftManager {
|
|||
return draftControllers.get(draftId);
|
||||
}
|
||||
|
||||
public DraftController getController(UUID tableId) {
|
||||
for (DraftController controller: draftControllers.values()) {
|
||||
if (controller.getTableId().equals(tableId)) {
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
public Optional<DraftController> getController(UUID tableId) {
|
||||
return draftControllers.values().stream().filter(controller -> controller.getTableId().equals(tableId)).findFirst();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
|
@ -59,12 +60,12 @@ public enum GameManager {
|
|||
}
|
||||
}
|
||||
|
||||
public UUID getChatId(UUID gameId) {
|
||||
public Optional<UUID> getChatId(UUID gameId) {
|
||||
GameController gameController = gameControllers.get(gameId);
|
||||
if (gameController != null) {
|
||||
return gameController.getChatId();
|
||||
return Optional.of(gameController.getChatId());
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void sendPlayerUUID(UUID gameId, UUID userId, UUID data) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
package mage.server.game;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
|
@ -55,7 +56,7 @@ public interface GamesRoom extends Room {
|
|||
TableView createTournamentTable(UUID userId, TournamentOptions options);
|
||||
void removeTable(UUID userId, UUID tableId);
|
||||
void removeTable(UUID tableId);
|
||||
TableView getTable(UUID tableId);
|
||||
Optional<TableView> getTable(UUID tableId);
|
||||
void leaveTable(UUID userId, UUID tableId);
|
||||
boolean watchTable(UUID userId, UUID tableId) throws MageException;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,10 +28,7 @@
|
|||
package mage.server.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
|
@ -180,11 +177,11 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableView getTable(UUID tableId) {
|
||||
public Optional<TableView> getTable(UUID tableId) {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return new TableView(tables.get(tableId));
|
||||
return Optional.of(new TableView(tables.get(tableId)));
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
|
@ -57,8 +58,12 @@ public enum GamesRoomManager {
|
|||
return mainRoomId;
|
||||
}
|
||||
|
||||
public GamesRoom getRoom(UUID roomId) {
|
||||
return rooms.get(roomId);
|
||||
public Optional<GamesRoom> getRoom(UUID roomId) {
|
||||
if(rooms.containsKey(roomId)) {
|
||||
return Optional.of(rooms.get(roomId));
|
||||
}
|
||||
return Optional.empty();
|
||||
|
||||
}
|
||||
|
||||
public void removeTable(UUID tableId) {
|
||||
|
|
|
|||
|
|
@ -249,16 +249,21 @@ public class TournamentController {
|
|||
table.setState(TableState.WAITING);
|
||||
TournamentPlayer player1 = pair.getPlayer1();
|
||||
TournamentPlayer player2 = pair.getPlayer2();
|
||||
tableManager.addPlayer(getPlayerUserId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.getDeck());
|
||||
tableManager.addPlayer(getPlayerUserId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getPlayerType(), player2.getDeck());
|
||||
table.setState(TableState.STARTING);
|
||||
tableManager.startTournamentSubMatch(null, table.getId());
|
||||
Match match = tableManager.getMatch(table.getId());
|
||||
match.setTableId(tableId);
|
||||
pair.setMatch(match);
|
||||
pair.setTableId(table.getId());
|
||||
player1.setState(TournamentPlayerState.DUELING);
|
||||
player2.setState(TournamentPlayerState.DUELING);
|
||||
Optional<UUID> user1Id = getPlayerUserId(player1.getPlayer().getId());
|
||||
Optional<UUID> user2Id = getPlayerUserId(player2.getPlayer().getId());
|
||||
if (user1Id.isPresent() && user2Id.isPresent()) {
|
||||
tableManager.addPlayer(getPlayerUserId(player1.getPlayer().getId()).get(), table.getId(), player1);
|
||||
tableManager.addPlayer(getPlayerUserId(player2.getPlayer().getId()).get(), table.getId(), player2);
|
||||
table.setState(TableState.STARTING);
|
||||
tableManager.startTournamentSubMatch(null, table.getId());
|
||||
tableManager.getMatch(table.getId()).ifPresent(match -> {
|
||||
match.setTableId(tableId);
|
||||
pair.setMatch(match);
|
||||
pair.setTableId(table.getId());
|
||||
player1.setState(TournamentPlayerState.DUELING);
|
||||
player2.setState(TournamentPlayerState.DUELING);
|
||||
});
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
logger.fatal("TournamentController startMatch error", ex);
|
||||
}
|
||||
|
|
@ -271,18 +276,20 @@ public class TournamentController {
|
|||
table.setTournamentSubTable(true);
|
||||
table.setTournament(tournament);
|
||||
table.setState(TableState.WAITING);
|
||||
|
||||
for (TournamentPlayer player : round.getAllPlayers()) {
|
||||
tableManager.addPlayer(getPlayerUserId(player.getPlayer().getId()), table.getId(), player.getPlayer(), player.getPlayerType(), player.getDeck());
|
||||
}
|
||||
table.setState(TableState.STARTING);
|
||||
tableManager.startTournamentSubMatch(null, table.getId());
|
||||
Match match = tableManager.getMatch(table.getId());
|
||||
match.setTableId(tableId);
|
||||
round.setMatch(match);
|
||||
round.setTableId(table.getId());
|
||||
for (TournamentPlayer player : round.getAllPlayers()) {
|
||||
player.setState(TournamentPlayerState.DUELING);
|
||||
if (round.getAllPlayers().stream().allMatch(tournamentPlayer -> getPlayerUserId(tournamentPlayer.getPlayer().getId()).isPresent())) {
|
||||
for (TournamentPlayer player : round.getAllPlayers()) {
|
||||
tableManager.addPlayer(getPlayerUserId(player.getPlayer().getId()).get(), table.getId(), player);
|
||||
}
|
||||
table.setState(TableState.STARTING);
|
||||
tableManager.startTournamentSubMatch(null, table.getId());
|
||||
tableManager.getMatch(table.getId()).ifPresent(match -> {
|
||||
match.setTableId(tableId);
|
||||
round.setMatch(match);
|
||||
round.setTableId(table.getId());
|
||||
for (TournamentPlayer player : round.getAllPlayers()) {
|
||||
player.setState(TournamentPlayerState.DUELING);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
logger.fatal("TournamentController startMatch error", ex);
|
||||
|
|
@ -307,9 +314,13 @@ public class TournamentController {
|
|||
if (tournamentSessions.containsKey(playerId)) {
|
||||
TournamentSession tournamentSession = tournamentSessions.get(playerId);
|
||||
tournamentSession.construct(timeout);
|
||||
UserManager.instance.getUser(getPlayerUserId(playerId)).get().addConstructing(playerId, tournamentSession);
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
player.setState(TournamentPlayerState.CONSTRUCTING);
|
||||
getPlayerUserId(playerId).ifPresent(userId -> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
user.addConstructing(playerId, tournamentSession);
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
player.setState(TournamentPlayerState.CONSTRUCTING);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -385,13 +396,11 @@ public class TournamentController {
|
|||
if (!checkToReplaceDraftPlayerByAi(userId, tournamentPlayer)) {
|
||||
this.abortDraftTournament();
|
||||
} else {
|
||||
DraftController draftController = DraftManager.instance.getController(tableId);
|
||||
if (draftController != null) {
|
||||
DraftSession draftSession = draftController.getDraftSession(playerId);
|
||||
if (draftSession != null) {
|
||||
DraftManager.instance.kill(draftSession.getDraftId(), userId);
|
||||
}
|
||||
}
|
||||
DraftManager.instance.getController(tableId).ifPresent(draftController -> {
|
||||
draftController.getDraftSession(playerId).ifPresent(draftSession ->
|
||||
DraftManager.instance.kill(draftSession.getDraftId(), userId));
|
||||
|
||||
});
|
||||
}
|
||||
status = TourneyQuitStatus.DURING_DRAFTING;
|
||||
} else if (tournamentPlayer.getState() == TournamentPlayerState.CONSTRUCTING) {
|
||||
|
|
@ -419,8 +428,8 @@ public class TournamentController {
|
|||
// replace player that quits with draft bot
|
||||
if (humans > 1) {
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
TableController tableController = TableManager.instance.getController(tableId);
|
||||
if (tableController != null) {
|
||||
TableManager.instance.getController(tableId).ifPresent(tableController -> {
|
||||
|
||||
String replacePlayerName = "Draftbot";
|
||||
if (user.isPresent()) {
|
||||
replacePlayerName = "Draftbot (" + user.get().getName() + ')';
|
||||
|
|
@ -432,19 +441,14 @@ public class TournamentController {
|
|||
user.get().removeTournament(leavingPlayer.getPlayer().getId());
|
||||
}
|
||||
ChatManager.instance.broadcast(chatId, "", leavingPlayer.getPlayer().getLogName() + " was replaced by draftbot", MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private UUID getPlayerUserId(UUID playerId) {
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
private Optional<UUID> getPlayerUserId(UUID playerId) {
|
||||
return userPlayerMap.entrySet().stream().filter(entry -> entry.getValue().equals(playerId)).map(Entry::getKey).findFirst();
|
||||
}
|
||||
|
||||
public TournamentView getTournamentView() {
|
||||
|
|
@ -453,7 +457,7 @@ public class TournamentController {
|
|||
|
||||
private void abortDraftTournament() {
|
||||
tournament.setAbort(true);
|
||||
DraftManager.instance.getController(tableId).abortDraft();
|
||||
DraftManager.instance.getController(tableId).ifPresent(DraftController::abortDraft);
|
||||
}
|
||||
|
||||
public boolean isAbort() {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.server.tournament;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
|
@ -85,10 +86,14 @@ public enum TournamentManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public UUID getChatId(UUID tournamentId) {
|
||||
return controllers.get(tournamentId).getChatId();
|
||||
public Optional<UUID> getChatId(UUID tournamentId) {
|
||||
if(controllers.containsKey(tournamentId)) {
|
||||
return Optional.of(controllers.get(tournamentId).getChatId());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
public void removeTournament(UUID tournamentId) {
|
||||
TournamentController tournamentController = controllers.get(tournamentId);
|
||||
if (tournamentController != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue