forked from External/mage
[app-wiring-refactor]: Remove static initialisation
- Remove all enum static managers - Introduce interfaces for the managers - Define new application wiring class (`ManagerFactory`) - Externalise the configuration
This commit is contained in:
parent
cf3dd2d94c
commit
d0c2135e17
48 changed files with 1385 additions and 911 deletions
|
|
@ -23,15 +23,14 @@ import mage.players.PlayerType;
|
|||
import mage.players.net.UserData;
|
||||
import mage.remote.MageVersionException;
|
||||
import mage.server.draft.CubeFactory;
|
||||
import mage.server.draft.DraftManager;
|
||||
import mage.server.game.*;
|
||||
import mage.server.game.GameFactory;
|
||||
import mage.server.game.GamesRoom;
|
||||
import mage.server.game.PlayerFactory;
|
||||
import mage.server.managers.ManagerFactory;
|
||||
import mage.server.services.impl.FeedbackServiceImpl;
|
||||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.server.util.ServerMessagesUtil;
|
||||
import mage.server.util.SystemUtil;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.utils.*;
|
||||
import mage.view.*;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
|
|
@ -49,9 +48,10 @@ import java.util.concurrent.ExecutorService;
|
|||
public class MageServerImpl implements MageServer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MageServerImpl.class);
|
||||
private static final ExecutorService callExecutor = ThreadExecutor.instance.getCallExecutor();
|
||||
private final ExecutorService callExecutor;
|
||||
private static final SecureRandom RANDOM = new SecureRandom();
|
||||
|
||||
private final ManagerFactory managerFactory;
|
||||
private final String adminPassword;
|
||||
private final boolean testMode;
|
||||
private final LinkedHashMap<String, String> activeAuthTokens = new LinkedHashMap<String, String>() {
|
||||
|
|
@ -62,15 +62,17 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
};
|
||||
|
||||
public MageServerImpl(String adminPassword, boolean testMode) {
|
||||
public MageServerImpl(ManagerFactory managerFactory, String adminPassword, boolean testMode) {
|
||||
this.managerFactory = managerFactory;
|
||||
this.adminPassword = adminPassword;
|
||||
this.testMode = testMode;
|
||||
this.callExecutor = managerFactory.threadExecutor().getCallExecutor();
|
||||
ServerMessagesUtil.instance.getMessages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerUser(String sessionId, String userName, String password, String email) throws MageException {
|
||||
return SessionManager.instance.registerUser(sessionId, userName, password, email);
|
||||
return managerFactory.sessionManager().registerUser(sessionId, userName, password, email);
|
||||
}
|
||||
|
||||
// generateAuthToken returns a uniformly distributed 6-digits string.
|
||||
|
|
@ -80,7 +82,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public boolean emailAuthToken(String sessionId, String email) throws MageException {
|
||||
if (!ConfigSettings.instance.isAuthenticationActivated()) {
|
||||
if (!managerFactory.configSettings().isAuthenticationActivated()) {
|
||||
sendErrorMessageToClient(sessionId, "Registration is disabled by the server config");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -96,10 +98,10 @@ public class MageServerImpl implements MageServer {
|
|||
String text = "Use this auth token to reset " + authorizedUser.name + "'s password: " + authToken + '\n'
|
||||
+ "It's valid until the next server restart.";
|
||||
boolean success;
|
||||
if (!ConfigSettings.instance.getMailUser().isEmpty()) {
|
||||
success = MailClient.sendMessage(email, subject, text);
|
||||
if (!managerFactory.configSettings().getMailUser().isEmpty()) {
|
||||
success = managerFactory.mailClient().sendMessage(email, subject, text);
|
||||
} else {
|
||||
success = MailgunClient.sendMessage(email, subject, text);
|
||||
success = managerFactory.mailgunClient().sendMessage(email, subject, text);
|
||||
}
|
||||
if (!success) {
|
||||
sendErrorMessageToClient(sessionId, "There was an error inside the server while emailing an auth token");
|
||||
|
|
@ -110,7 +112,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException {
|
||||
if (!ConfigSettings.instance.isAuthenticationActivated()) {
|
||||
if (!managerFactory.configSettings().isAuthenticationActivated()) {
|
||||
sendErrorMessageToClient(sessionId, "Registration is disabled by the server config");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -139,7 +141,7 @@ public class MageServerImpl implements MageServer {
|
|||
logger.info("MageVersionException: userName=" + userName + ", version=" + version + " sessionId=" + sessionId);
|
||||
throw new MageVersionException(version, Main.getVersion());
|
||||
}
|
||||
return SessionManager.instance.connectUser(sessionId, userName, password, userIdStr);
|
||||
return managerFactory.sessionManager().connectUser(sessionId, userName, password, userIdStr);
|
||||
} catch (MageException ex) {
|
||||
if (ex instanceof MageVersionException) {
|
||||
throw ex;
|
||||
|
|
@ -154,7 +156,7 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
return SessionManager.instance.setUserData(userName, sessionId, userData, clientVersion, userIdStr);
|
||||
return managerFactory.sessionManager().setUserData(userName, sessionId, userData, clientVersion, userIdStr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -168,7 +170,7 @@ public class MageServerImpl implements MageServer {
|
|||
if (!adminPassword.equals(this.adminPassword)) {
|
||||
throw new MageException("Wrong password");
|
||||
}
|
||||
return SessionManager.instance.connectAdmin(sessionId);
|
||||
return managerFactory.sessionManager().connectAdmin(sessionId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -186,13 +188,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public TableView execute() throws MageException {
|
||||
try {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().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);
|
||||
Optional<User> _user = managerFactory.userManager().getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
logger.error("User for session not found. session = " + sessionId);
|
||||
return null;
|
||||
|
|
@ -205,7 +207,7 @@ public class MageServerImpl implements MageServer {
|
|||
throw new MageException("No message");
|
||||
}
|
||||
// check AI players max
|
||||
String maxAiOpponents = ConfigSettings.instance.getMaxAiOpponents();
|
||||
String maxAiOpponents = managerFactory.configSettings().getMaxAiOpponents();
|
||||
if (maxAiOpponents != null) {
|
||||
int aiPlayers = 0;
|
||||
for (PlayerType playerType : options.getPlayerTypes()) {
|
||||
|
|
@ -241,7 +243,7 @@ public class MageServerImpl implements MageServer {
|
|||
user.showUserMessage("Create tournament", message);
|
||||
throw new MageException("No message");
|
||||
}
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (!room.isPresent()) {
|
||||
|
||||
} else {
|
||||
|
|
@ -260,9 +262,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
execute("removeTable", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
managerFactory.tableManager().removeTable(userId, tableId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -272,7 +274,7 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("joinTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -282,7 +284,7 @@ public class MageServerImpl implements MageServer {
|
|||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (!room.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -297,20 +299,20 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("joinTournamentTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
UUID userId = session.get().getUserId();
|
||||
if (logger.isTraceEnabled()) {
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
Optional<User> user = managerFactory.userManager().getUser(userId);
|
||||
user.ifPresent(user1 -> logger.trace("join tourn. tableId: " + tableId + ' ' + name));
|
||||
}
|
||||
if (userId == null) {
|
||||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
return room.get().joinTournamentTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
}
|
||||
|
|
@ -325,12 +327,12 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("submitDeck", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
return false;
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
boolean ret = TableManager.instance.submitDeck(userId, tableId, deckList);
|
||||
boolean ret = managerFactory.tableManager().submitDeck(userId, tableId, deckList);
|
||||
logger.debug("Session " + sessionId + " submitted deck");
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -341,13 +343,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void updateDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException {
|
||||
execute("updateDeck", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.updateDeck(userId, tableId, deckList);
|
||||
managerFactory.tableManager().updateDeck(userId, tableId, deckList);
|
||||
logger.trace("Session " + sessionId + " updated deck");
|
||||
}
|
||||
});
|
||||
|
|
@ -357,7 +359,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public List<TableView> getTables(UUID roomId) throws MageException {
|
||||
try {
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
return room.get().getTables();
|
||||
} else {
|
||||
|
|
@ -373,7 +375,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public List<MatchView> getFinishedMatches(UUID roomId) throws MageException {
|
||||
try {
|
||||
return GamesRoomManager.instance.getRoom(roomId).map(GamesRoom::getFinished).orElse(new ArrayList<>());
|
||||
return managerFactory.gamesRoomManager().getRoom(roomId).map(GamesRoom::getFinished).orElse(new ArrayList<>());
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -383,7 +385,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException {
|
||||
try {
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
return room.get().getRoomUsersInfo();
|
||||
} else {
|
||||
|
|
@ -399,7 +401,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws MageException {
|
||||
try {
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
return room.flatMap(r -> r.getTable(tableId)).orElse(null);
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -410,22 +412,12 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public boolean ping(String sessionId, String pingInfo) {
|
||||
return SessionManager.instance.extendUserSession(sessionId, pingInfo);
|
||||
return managerFactory.sessionManager().extendUserSession(sessionId, pingInfo);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void deregisterClient(final String sessionId) throws MageException {
|
||||
// execute("deregisterClient", sessionId, new Action() {
|
||||
// @Override
|
||||
// public void execute() {
|
||||
// SessionManager.instance.disconnect(sessionId, true);
|
||||
// logger.debug("Client deregistered ...");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
@Override
|
||||
public boolean startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
Optional<TableController> controller = TableManager.instance.getController(tableId);
|
||||
Optional<TableController> controller = managerFactory.tableManager().getController(tableId);
|
||||
if (!controller.isPresent()) {
|
||||
logger.error("table not found : " + tableId);
|
||||
return false;
|
||||
|
|
@ -434,30 +426,20 @@ public class MageServerImpl implements MageServer {
|
|||
return false;
|
||||
}
|
||||
execute("startMatch", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.startMatch(userId, roomId, tableId);
|
||||
managerFactory.tableManager().startMatch(userId, roomId, tableId);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void startChallenge(final String sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws MageException {
|
||||
// execute("startChallenge", sessionId, new Action() {
|
||||
// @Override
|
||||
// public void execute() {
|
||||
// UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
// TableManager.instance.startChallenge(userId, roomId, tableId, challengeId);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
@Override
|
||||
public boolean startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
Optional<TableController> controller = TableManager.instance.getController(tableId);
|
||||
Optional<TableController> controller = managerFactory.tableManager().getController(tableId);
|
||||
if (!controller.isPresent()) {
|
||||
logger.error("table not found : " + tableId);
|
||||
return false;
|
||||
|
|
@ -466,12 +448,12 @@ public class MageServerImpl implements MageServer {
|
|||
return false;
|
||||
}
|
||||
execute("startTournament", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TableManager.instance.startTournament(userId, roomId, tableId);
|
||||
managerFactory.tableManager().startTournament(userId, roomId, tableId);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
|
@ -481,7 +463,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public TournamentView getTournament(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.instance.getTournamentView(tournamentId);
|
||||
return managerFactory.tournamentManager().getTournamentView(tournamentId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -493,7 +475,7 @@ public class MageServerImpl implements MageServer {
|
|||
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
() -> ChatManager.instance.broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE, true, null, ChatMessage.MessageType.TALK, null)
|
||||
() -> managerFactory.chatManager().broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE, true, null, ChatMessage.MessageType.TALK, null)
|
||||
);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
|
|
@ -503,10 +485,10 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException {
|
||||
execute("joinChat", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
|
||||
UUID userId = session.getUserId();
|
||||
ChatManager.instance.joinChat(chatId, userId);
|
||||
managerFactory.chatManager().joinChat(chatId, userId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -515,9 +497,9 @@ public class MageServerImpl implements MageServer {
|
|||
public void leaveChat(final UUID chatId, final String sessionId) throws MageException {
|
||||
execute("leaveChat", sessionId, () -> {
|
||||
if (chatId != null) {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
ChatManager.instance.leaveChat(chatId, userId);
|
||||
managerFactory.chatManager().leaveChat(chatId, userId);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -527,7 +509,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getMainRoomId() throws MageException {
|
||||
try {
|
||||
return GamesRoomManager.instance.getMainRoomId();
|
||||
return managerFactory.gamesRoomManager().getMainRoomId();
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -538,7 +520,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getRoomChatId(UUID roomId) throws MageException {
|
||||
try {
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (!room.isPresent()) {
|
||||
logger.error("roomId not found : " + roomId);
|
||||
return null;
|
||||
|
|
@ -555,12 +537,12 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("isTableOwner", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
return false;
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
return TableManager.instance.isTableOwner(tableId, userId);
|
||||
return managerFactory.tableManager().isTableOwner(tableId, userId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -569,16 +551,16 @@ 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, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
TableManager.instance.swapSeats(tableId, userId, seatNum1, seatNum2);
|
||||
managerFactory.tableManager().swapSeats(tableId, userId, seatNum1, seatNum2);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
Optional<TableController> tableController = TableManager.instance.getController(tableId);
|
||||
Optional<TableController> tableController = managerFactory.tableManager().getController(tableId);
|
||||
if (tableController.isPresent()) {
|
||||
TableState tableState = tableController.get().getTableState();
|
||||
if (tableState != TableState.WAITING && tableState != TableState.READY_TO_START) {
|
||||
|
|
@ -586,9 +568,9 @@ public class MageServerImpl implements MageServer {
|
|||
return false;
|
||||
}
|
||||
execute("leaveTable", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
GamesRoomManager.instance.getRoom(roomId).ifPresent(room ->
|
||||
managerFactory.gamesRoomManager().getRoom(roomId).ifPresent(room ->
|
||||
room.leaveTable(userId, tableId));
|
||||
|
||||
});
|
||||
|
|
@ -604,7 +586,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getTableChatId(UUID tableId) throws MageException {
|
||||
try {
|
||||
return TableManager.instance.getChatId(tableId).orElse(null);
|
||||
return managerFactory.tableManager().getChatId(tableId).orElse(null);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -614,9 +596,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void joinGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("joinGame", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
GameManager.instance.joinGame(gameId, userId);
|
||||
managerFactory.gameManager().joinGame(gameId, userId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -624,9 +606,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void joinDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("joinDraft", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
DraftManager.instance.joinDraft(draftId, userId);
|
||||
managerFactory.draftManager().joinDraft(draftId, userId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -634,12 +616,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
execute("joinTournament", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
TournamentManager.instance.joinTournament(tournamentId, userId);
|
||||
managerFactory.tournamentManager().joinTournament(tournamentId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -648,7 +630,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getGameChatId(UUID gameId) throws MageException {
|
||||
try {
|
||||
return GameManager.instance.getChatId(gameId).orElse(null);
|
||||
return managerFactory.gameManager().getChatId(gameId).orElse(null);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -659,7 +641,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.instance.getChatId(tournamentId).orElse(null);
|
||||
return managerFactory.tournamentManager().getChatId(tournamentId).orElse(null);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -669,9 +651,8 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerUUID(final UUID gameId, final String sessionId, final UUID data) throws MageException {
|
||||
execute("sendPlayerUUID", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
Optional<User> user = managerFactory.sessionManager().getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
// logger.warn("sendPlayerUUID gameId=" + gameId + " sessionId=" + sessionId + " username=" + user.getName());
|
||||
user.get().sendPlayerUUID(gameId, data);
|
||||
} else {
|
||||
logger.warn("Your session expired: gameId=" + gameId + ", sessionId=" + sessionId);
|
||||
|
|
@ -682,7 +663,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerString(final UUID gameId, final String sessionId, final String data) throws MageException {
|
||||
execute("sendPlayerString", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
Optional<User> user = managerFactory.sessionManager().getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
user.get().sendPlayerString(gameId, data);
|
||||
} else {
|
||||
|
|
@ -694,7 +675,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerManaType(final UUID gameId, final UUID playerId, final String sessionId, final ManaType data) throws MageException {
|
||||
execute("sendPlayerManaType", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
Optional<User> user = managerFactory.sessionManager().getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
user.get().sendPlayerManaType(gameId, playerId, data);
|
||||
} else {
|
||||
|
|
@ -706,7 +687,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerBoolean(final UUID gameId, final String sessionId, final Boolean data) throws MageException {
|
||||
execute("sendPlayerBoolean", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
Optional<User> user = managerFactory.sessionManager().getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
user.get().sendPlayerBoolean(gameId, data);
|
||||
} else {
|
||||
|
|
@ -718,7 +699,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerInteger(final UUID gameId, final String sessionId, final Integer data) throws MageException {
|
||||
execute("sendPlayerInteger", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
Optional<User> user = managerFactory.sessionManager().getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
user.get().sendPlayerInteger(gameId, data);
|
||||
} else {
|
||||
|
|
@ -735,9 +716,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendCardMark(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
||||
execute("sendCardMark", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
DraftManager.instance.sendCardMark(draftId, userId, cardPick);
|
||||
managerFactory.draftManager().sendCardMark(draftId, userId, cardPick);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -748,9 +729,9 @@ public class MageServerImpl implements MageServer {
|
|||
try {
|
||||
callExecutor.execute(
|
||||
() -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
GameManager.instance.quitMatch(gameId, userId);
|
||||
managerFactory.gameManager().quitMatch(gameId, userId);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
@ -766,10 +747,10 @@ public class MageServerImpl implements MageServer {
|
|||
try {
|
||||
callExecutor.execute(
|
||||
() -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
||||
TournamentManager.instance.quit(tournamentId, userId);
|
||||
managerFactory.tournamentManager().quit(tournamentId, userId);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
@ -786,14 +767,14 @@ public class MageServerImpl implements MageServer {
|
|||
try {
|
||||
callExecutor.execute(
|
||||
() -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(
|
||||
session -> {
|
||||
UUID userId = session.getUserId();
|
||||
UUID tableId = DraftManager.instance.getControllerByDraftId(draftId).getTableId();
|
||||
Table table = TableManager.instance.getTable(tableId);
|
||||
UUID tableId = managerFactory.draftManager().getControllerByDraftId(draftId).getTableId();
|
||||
Table table = managerFactory.tableManager().getTable(tableId);
|
||||
if (table.isTournament()) {
|
||||
UUID tournamentId = table.getTournament().getId();
|
||||
TournamentManager.instance.quit(tournamentId, userId);
|
||||
managerFactory.tournamentManager().quit(tournamentId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -808,9 +789,9 @@ 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, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
GameManager.instance.sendPlayerAction(playerAction, gameId, userId, data);
|
||||
managerFactory.gameManager().sendPlayerAction(playerAction, gameId, userId, data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -820,14 +801,14 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().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);
|
||||
if (managerFactory.gamesRoomManager().getRoom(roomId).isPresent()) {
|
||||
return managerFactory.gamesRoomManager().getRoom(roomId).get().watchTable(userId, tableId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -846,10 +827,10 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("watchGame", sessionId, new ActionWithResult<Boolean>() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
return SessionManager.instance.getSession(sessionId)
|
||||
return managerFactory.sessionManager().getSession(sessionId)
|
||||
.map(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
return GameManager.instance.watchGame(gameId, userId);
|
||||
return managerFactory.gameManager().watchGame(gameId, userId);
|
||||
}).orElse(false);
|
||||
}
|
||||
|
||||
|
|
@ -863,10 +844,10 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("stopWatching", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
GameManager.instance.stopWatching(gameId, userId);
|
||||
managerFactory.userManager().getUser(userId).ifPresent(user -> {
|
||||
managerFactory.gameManager().stopWatching(gameId, userId);
|
||||
user.removeGameWatchInfo(gameId);
|
||||
});
|
||||
});
|
||||
|
|
@ -877,9 +858,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void replayGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("replayGame", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
ReplayManager.instance.replayGame(gameId, userId);
|
||||
managerFactory.replayManager().replayGame(gameId, userId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -887,9 +868,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void startReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("startReplay", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
ReplayManager.instance.startReplay(gameId, userId);
|
||||
managerFactory.replayManager().startReplay(gameId, userId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -897,12 +878,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void stopReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("stopReplay", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.stopReplay(gameId, userId);
|
||||
managerFactory.replayManager().stopReplay(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -910,12 +891,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void nextPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("nextPlay", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.nextPlay(gameId, userId);
|
||||
managerFactory.replayManager().nextPlay(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -923,12 +904,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void previousPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("previousPlay", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.previousPlay(gameId, userId);
|
||||
managerFactory.replayManager().previousPlay(gameId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -936,12 +917,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void skipForward(final UUID gameId, final String sessionId, final int moves) throws MageException {
|
||||
execute("skipForward", sessionId, () -> {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
ReplayManager.instance.skipForward(gameId, userId, moves);
|
||||
managerFactory.replayManager().skipForward(gameId, userId, moves);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -971,9 +952,9 @@ 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) {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
GameManager.instance.cheat(gameId, userId, playerId, deckList);
|
||||
managerFactory.gameManager().cheat(gameId, userId, playerId, deckList);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -985,12 +966,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public Boolean execute() {
|
||||
if (testMode) {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().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 managerFactory.gameManager().cheat(gameId, userId, playerId, cardName);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -1024,13 +1005,13 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public void disconnectUser(final String sessionId, final String userSessionId) throws MageException {
|
||||
execute("disconnectUser", sessionId, () -> SessionManager.instance.disconnectUser(sessionId, userSessionId));
|
||||
execute("disconnectUser", sessionId, () -> managerFactory.sessionManager().disconnectUser(sessionId, userSessionId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void muteUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||
execute("muteUser", sessionId, () -> {
|
||||
UserManager.instance.getUserByName(userName).ifPresent(user -> {
|
||||
managerFactory.userManager().getUserByName(userName).ifPresent(user -> {
|
||||
Date muteUntil = new Date(Calendar.getInstance().getTimeInMillis() + (durationMinutes * Timer.ONE_MINUTE));
|
||||
user.showUserMessage("Admin info", "You were muted for chat messages until " + SystemUtil.dateFormat.format(muteUntil) + '.');
|
||||
user.setChatLockedUntil(muteUntil);
|
||||
|
|
@ -1042,12 +1023,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void lockUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||
execute("lockUser", sessionId, () -> {
|
||||
UserManager.instance.getUserByName(userName).ifPresent(user -> {
|
||||
managerFactory.userManager().getUserByName(userName).ifPresent(user -> {
|
||||
Date lockUntil = new Date(Calendar.getInstance().getTimeInMillis() + (durationMinutes * Timer.ONE_MINUTE));
|
||||
user.showUserMessage("Admin info", "Your user profile was locked until " + SystemUtil.dateFormat.format(lockUntil) + '.');
|
||||
user.setLockedUntil(lockUntil);
|
||||
if (user.isConnected()) {
|
||||
SessionManager.instance.disconnectUser(sessionId, user.getSessionId());
|
||||
managerFactory.sessionManager().disconnectUser(sessionId, user.getSessionId());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -1058,15 +1039,15 @@ public class MageServerImpl implements MageServer {
|
|||
public void setActivation(final String sessionId, final String userName, boolean active) throws MageException {
|
||||
execute("setActivation", sessionId, () -> {
|
||||
AuthorizedUser authorizedUser = AuthorizedUserRepository.instance.getByName(userName);
|
||||
Optional<User> u = UserManager.instance.getUserByName(userName);
|
||||
Optional<User> u = managerFactory.userManager().getUserByName(userName);
|
||||
if (u.isPresent()) {
|
||||
User user = u.get();
|
||||
user.setActive(active);
|
||||
if (!user.isActive() && user.isConnected()) {
|
||||
SessionManager.instance.disconnectUser(sessionId, user.getSessionId());
|
||||
managerFactory.sessionManager().disconnectUser(sessionId, user.getSessionId());
|
||||
}
|
||||
} else if (authorizedUser != null) {
|
||||
User theUser = new User(userName, "localhost", authorizedUser);
|
||||
User theUser = new User(managerFactory, userName, "localhost", authorizedUser);
|
||||
theUser.setActive(active);
|
||||
}
|
||||
|
||||
|
|
@ -1076,18 +1057,18 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void toggleActivation(final String sessionId, final String userName) throws MageException {
|
||||
execute("toggleActivation", sessionId, ()
|
||||
-> UserManager.instance.getUserByName(userName).ifPresent(user
|
||||
-> managerFactory.userManager().getUserByName(userName).ifPresent(user
|
||||
-> {
|
||||
user.setActive(!user.isActive());
|
||||
if (!user.isActive() && user.isConnected()) {
|
||||
SessionManager.instance.disconnectUser(sessionId, user.getSessionId());
|
||||
managerFactory.sessionManager().disconnectUser(sessionId, user.getSessionId());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endUserSession(final String sessionId, final String userSessionId) throws MageException {
|
||||
execute("endUserSession", sessionId, () -> SessionManager.instance.endUserSession(sessionId, userSessionId));
|
||||
execute("endUserSession", sessionId, () -> managerFactory.sessionManager().endUserSession(sessionId, userSessionId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1100,9 +1081,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
execute("removeTable", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
managerFactory.tableManager().removeTable(userId, tableId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -1116,7 +1097,7 @@ 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, ()
|
||||
-> SessionManager.instance.getSession(sessionId).ifPresent(
|
||||
-> managerFactory.sessionManager().getSession(sessionId).ifPresent(
|
||||
session -> FeedbackServiceImpl.instance.feedback(username, title, type, message, email, session.getHost())
|
||||
));
|
||||
}
|
||||
|
|
@ -1126,7 +1107,7 @@ public class MageServerImpl implements MageServer {
|
|||
public void sendBroadcastMessage(final String sessionId, final String message) throws MageException {
|
||||
if (message != null) {
|
||||
execute("sendBroadcastMessage", sessionId, () -> {
|
||||
for (User user : UserManager.instance.getUsers()) {
|
||||
for (User user : managerFactory.userManager().getUsers()) {
|
||||
if (message.toLowerCase(Locale.ENGLISH).startsWith("warn")) {
|
||||
user.fireCallback(new ClientCallback(ClientCallbackMethod.SERVER_MESSAGE, null, new ChatMessage("SERVER", message, null, null, MessageColor.RED)));
|
||||
} else {
|
||||
|
|
@ -1138,12 +1119,12 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
private void sendErrorMessageToClient(final String sessionId, final String message) throws MageException {
|
||||
execute("sendErrorMessageToClient", sessionId, () -> SessionManager.instance.sendErrorMessageToClient(sessionId, message));
|
||||
execute("sendErrorMessageToClient", sessionId, () -> managerFactory.sessionManager().sendErrorMessageToClient(sessionId, message));
|
||||
}
|
||||
|
||||
protected void execute(final String actionName, final String sessionId, final Action action, boolean checkAdminRights) throws MageException {
|
||||
if (checkAdminRights) {
|
||||
if (!SessionManager.instance.isAdmin(sessionId)) {
|
||||
if (!managerFactory.sessionManager().isAdmin(sessionId)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -1151,11 +1132,11 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
protected void execute(final String actionName, final String sessionId, final Action action) throws MageException {
|
||||
if (SessionManager.instance.isValidSession(sessionId)) {
|
||||
if (managerFactory.sessionManager().isValidSession(sessionId)) {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
() -> {
|
||||
if (SessionManager.instance.isValidSession(sessionId)) {
|
||||
if (managerFactory.sessionManager().isValidSession(sessionId)) {
|
||||
try {
|
||||
action.execute();
|
||||
} catch (MageException me) {
|
||||
|
|
@ -1172,7 +1153,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
protected <T> T executeWithResult(String actionName, final String sessionId, final ActionWithResult<T> action, boolean checkAdminRights) throws MageException {
|
||||
if (checkAdminRights) {
|
||||
if (!SessionManager.instance.isAdmin(sessionId)) {
|
||||
if (!managerFactory.sessionManager().isAdmin(sessionId)) {
|
||||
return action.negativeResult();
|
||||
}
|
||||
}
|
||||
|
|
@ -1181,7 +1162,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
//TODO: also run in threads with future task
|
||||
protected <T> T executeWithResult(String actionName, final String sessionId, final ActionWithResult<T> action) throws MageException {
|
||||
if (SessionManager.instance.isValidSession(sessionId)) {
|
||||
if (managerFactory.sessionManager().isValidSession(sessionId)) {
|
||||
try {
|
||||
return action.execute();
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -1218,15 +1199,15 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
}
|
||||
|
||||
private static class ListActionWithNullNegativeResult extends ActionWithNullNegativeResult<List<UserView>> {
|
||||
private class ListActionWithNullNegativeResult extends ActionWithNullNegativeResult<List<UserView>> {
|
||||
|
||||
@Override
|
||||
public List<UserView> execute() throws MageException {
|
||||
return UserManager.instance.getUserInfoList();
|
||||
return managerFactory.userManager().getUserInfoList();
|
||||
}
|
||||
}
|
||||
|
||||
private static class GameViewActionWithNullNegativeResult extends ActionWithNullNegativeResult<GameView> {
|
||||
private class GameViewActionWithNullNegativeResult extends ActionWithNullNegativeResult<GameView> {
|
||||
|
||||
private final String sessionId;
|
||||
private final UUID gameId;
|
||||
|
|
@ -1240,18 +1221,18 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public GameView execute() throws MageException {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
logger.error("Session not found : " + sessionId);
|
||||
return null;
|
||||
} else {
|
||||
//UUID userId = session.get().getUserId();
|
||||
return GameManager.instance.getGameView(gameId, playerId);
|
||||
return managerFactory.gameManager().getGameView(gameId, playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyActionWithBooleanResult extends ActionWithBooleanResult {
|
||||
private class MyActionWithBooleanResult extends ActionWithBooleanResult {
|
||||
|
||||
private final String sessionId;
|
||||
private final UUID tableId;
|
||||
|
|
@ -1263,17 +1244,17 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
return false;
|
||||
} else {
|
||||
UUID userId = session.get().getUserId();
|
||||
return TableManager.instance.watchTable(userId, tableId);
|
||||
return managerFactory.tableManager().watchTable(userId, tableId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class DraftPickViewActionWithNullNegativeResult extends ActionWithNullNegativeResult<DraftPickView> {
|
||||
private class DraftPickViewActionWithNullNegativeResult extends ActionWithNullNegativeResult<DraftPickView> {
|
||||
|
||||
private final String sessionId;
|
||||
private final UUID draftId;
|
||||
|
|
@ -1289,9 +1270,9 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public DraftPickView execute() {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (session.isPresent()) {
|
||||
return DraftManager.instance.sendCardPick(draftId, session.get().getUserId(), cardPick, hiddenCards);
|
||||
return managerFactory.draftManager().sendCardPick(draftId, session.get().getUserId(), cardPick, hiddenCards);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
}
|
||||
|
|
@ -1299,7 +1280,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
}
|
||||
|
||||
private static class MyActionWithTableViewResult extends ActionWithTableViewResult {
|
||||
private class MyActionWithTableViewResult extends ActionWithTableViewResult {
|
||||
|
||||
private final String sessionId;
|
||||
private final MatchOptions options;
|
||||
|
|
@ -1313,12 +1294,12 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public TableView execute() throws MageException {
|
||||
Optional<Session> session = SessionManager.instance.getSession(sessionId);
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
UUID userId = session.get().getUserId();
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
Optional<User> _user = managerFactory.userManager().getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
logger.error("User for session not found. session = " + sessionId);
|
||||
return null;
|
||||
|
|
@ -1349,13 +1330,13 @@ public class MageServerImpl implements MageServer {
|
|||
user.showUserMessage("Create table", message);
|
||||
throw new MageException("No message");
|
||||
}
|
||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(roomId);
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().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()));
|
||||
logger.debug("- chatId: " + managerFactory.tableManager().getChatId(table.getTableId()));
|
||||
}
|
||||
return table;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue