mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
refactor: improved and reorganized client-server api, added additional logs, fixed miss admin checks for some commands
This commit is contained in:
parent
e43e918c67
commit
75958e3710
21 changed files with 371 additions and 364 deletions
|
|
@ -26,13 +26,12 @@ import java.util.*;
|
|||
/**
|
||||
* Network: client side session
|
||||
*
|
||||
* Only one session/server per GUI's client
|
||||
* Only one session/server per GUI's client supports
|
||||
*
|
||||
* Created by IGOUDT on 15-9-2016.
|
||||
* @author IGOUDT
|
||||
*/
|
||||
public final class SessionHandler {
|
||||
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SessionHandler.class);
|
||||
|
||||
private static Session session;
|
||||
|
|
@ -65,7 +64,7 @@ public final class SessionHandler {
|
|||
|
||||
public static boolean connect(Connection connection) {
|
||||
lastConnectError = "";
|
||||
if (session.connect(connection)) {
|
||||
if (session.connectStart(connection)) {
|
||||
return true;
|
||||
} else {
|
||||
lastConnectError = session.getLastError();
|
||||
|
|
@ -78,11 +77,11 @@ public final class SessionHandler {
|
|||
}
|
||||
|
||||
public static boolean stopConnecting() {
|
||||
return session.stopConnecting();
|
||||
return session.connectAbort();
|
||||
}
|
||||
|
||||
public static void disconnect(boolean showmessage) {
|
||||
session.disconnect(showmessage);
|
||||
session.connectStop(showmessage);
|
||||
}
|
||||
|
||||
public static void sendPlayerAction(PlayerAction playerAction, UUID gameId, Object relatedUserId) {
|
||||
|
|
@ -377,14 +376,14 @@ public final class SessionHandler {
|
|||
}
|
||||
|
||||
public static boolean emailAuthToken(Connection connection) {
|
||||
return session.emailAuthToken(connection);
|
||||
return session.sendAuthSendTokenToEmail(connection);
|
||||
}
|
||||
|
||||
public static boolean resetPassword(Connection connection) {
|
||||
return session.resetPassword(connection);
|
||||
return session.sendAuthResetPassword(connection);
|
||||
}
|
||||
|
||||
public static boolean register(Connection connection) {
|
||||
return session.register(connection);
|
||||
return session.sendAuthRegister(connection);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ public class NewTableDialog extends MageDialog {
|
|||
for (TablePlayerPanel player : players) {
|
||||
if (player.getPlayerType() != PlayerType.HUMAN) {
|
||||
if (!player.joinTable(roomId, table.getTableId())) {
|
||||
// error message must be send by the server
|
||||
// error message must be sent by a server
|
||||
SessionHandler.removeTable(roomId, table.getTableId());
|
||||
table = null;
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class MultiConnectTest {
|
|||
connection.setPort(17171);
|
||||
connection.setProxyType(Connection.ProxyType.NONE);
|
||||
|
||||
session.connect(connection);
|
||||
session.connectStart(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import mage.interfaces.callback.CallbackClient;
|
|||
import mage.utils.MageVersion;
|
||||
|
||||
/**
|
||||
* Network: client side commands to process from a server
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface MageClient extends CallbackClient {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.interfaces;
|
||||
|
||||
import mage.MageException;
|
||||
|
|
@ -20,99 +19,99 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Network: server side commands to process from a client
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author BetaSteward_at_googlemail.com, JayDi85
|
||||
*/
|
||||
public interface MageServer {
|
||||
|
||||
// registers a user to the user DB.
|
||||
boolean registerUser(String sessionId, String userName, String password, String email) throws MageException;
|
||||
boolean authRegister(String sessionId, String userName, String password, String email) throws MageException;
|
||||
|
||||
boolean emailAuthToken(String sessionId, String email) throws MageException;
|
||||
boolean authSendTokenToEmail(String sessionId, String email) throws MageException;
|
||||
|
||||
boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException;
|
||||
boolean authResetPassword(String sessionId, String email, String authToken, String password) throws MageException;
|
||||
|
||||
boolean connectUser(String userName, String password, String sessionId, MageVersion version, String userIdStr) throws MageException;
|
||||
|
||||
boolean connectAdmin(String password, String sessionId, MageVersion version) throws MageException;
|
||||
|
||||
// update methods
|
||||
List<ExpansionInfo> getMissingExpansionData(List<String> codes);
|
||||
boolean connectSetUserData(String userName, String sessionId, UserData userData, String clientVersion, String userIdStr) throws MageException;
|
||||
|
||||
List<CardInfo> getMissingCardsData(List<String> classNames);
|
||||
|
||||
// user methods
|
||||
boolean setUserData(String userName, String sessionId, UserData userData, String clientVersion, String userIdStr) throws MageException;
|
||||
|
||||
void sendFeedbackMessage(String sessionId, String username, String title, String type, String message, String email) throws MageException;
|
||||
|
||||
// server state methods
|
||||
ServerState getServerState() throws MageException;
|
||||
|
||||
List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException;
|
||||
|
||||
List<MatchView> getFinishedMatches(UUID roomId) throws MageException;
|
||||
|
||||
Object getServerMessagesCompressed(String sessionId) throws MageException; // messages of the day
|
||||
|
||||
// ping - extends session
|
||||
boolean ping(String sessionId, String pingInfo) throws MageException;
|
||||
|
||||
//table methods
|
||||
TableView createTable(String sessionId, UUID roomId, MatchOptions matchOptions) throws MageException;
|
||||
void serverAddFeedbackMessage(String sessionId, String username, String title, String type, String message, String email) throws MageException;
|
||||
|
||||
TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions tournamentOptions) throws MageException;
|
||||
Object serverGetPromotionMessages(String sessionId) throws MageException;
|
||||
|
||||
boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
|
||||
// sync cards send sets db
|
||||
// TODO: outdated, no more client/server sync, can be removed?
|
||||
List<ExpansionInfo> syncGetMissingExpansionData(List<String> codes);
|
||||
List<CardInfo> syncGetMissingCardsData(List<String> classNames);
|
||||
|
||||
boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
|
||||
// server state methods
|
||||
ServerState serverGetState() throws MageException;
|
||||
|
||||
boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
|
||||
UUID serverGetMainRoomId() throws MageException;
|
||||
|
||||
void updateDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
|
||||
List<RoomUsersView> roomGetUsers(UUID roomId) throws MageException;
|
||||
|
||||
boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
List<MatchView> roomGetFinishedMatches(UUID roomId) throws MageException;
|
||||
|
||||
boolean watchTournamentTable(String sessionId, UUID tableId) throws MageException;
|
||||
TableView roomCreateTable(String sessionId, UUID roomId, MatchOptions matchOptions) throws MageException;
|
||||
|
||||
boolean leaveTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
TableView roomCreateTournament(String sessionId, UUID roomId, TournamentOptions tournamentOptions) throws MageException;
|
||||
|
||||
void swapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws MageException;
|
||||
boolean roomJoinTable(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
|
||||
|
||||
void removeTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
boolean roomJoinTournament(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
|
||||
|
||||
boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
boolean deckSubmit(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
|
||||
|
||||
TableView getTable(UUID roomId, UUID tableId) throws MageException;
|
||||
void deckSave(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
|
||||
|
||||
List<TableView> getTables(UUID roomId) throws MageException;
|
||||
boolean roomWatchTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
//chat methods
|
||||
void sendChatMessage(UUID chatId, String userName, String message) throws MageException;
|
||||
boolean roomWatchTournament(String sessionId, UUID tableId) throws MageException;
|
||||
|
||||
void joinChat(UUID chatId, String sessionId, String userName) throws MageException;
|
||||
boolean roomLeaveTableOrTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
void leaveChat(UUID chatId, String sessionId) throws MageException;
|
||||
void tableSwapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws MageException;
|
||||
|
||||
UUID getTableChatId(UUID tableId) throws MageException;
|
||||
void tableRemove(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
UUID getGameChatId(UUID gameId) throws MageException;
|
||||
boolean tableIsOwner(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
UUID getRoomChatId(UUID roomId) throws MageException;
|
||||
TableView roomGetTableById(UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
UUID getTournamentChatId(UUID tournamentId) throws MageException;
|
||||
List<TableView> roomGetAllTables(UUID roomId) throws MageException;
|
||||
|
||||
//room methods
|
||||
UUID getMainRoomId() throws MageException;
|
||||
void chatSendMessage(UUID chatId, String userName, String message) throws MageException;
|
||||
|
||||
//game methods
|
||||
boolean startMatch(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
void chatJoin(UUID chatId, String sessionId, String userName) throws MageException;
|
||||
|
||||
void joinGame(UUID gameId, String sessionId) throws MageException;
|
||||
void chatLeave(UUID chatId, String sessionId) throws MageException;
|
||||
|
||||
boolean watchGame(UUID gameId, String sessionId) throws MageException;
|
||||
UUID chatFindByGame(UUID gameId) throws MageException;
|
||||
|
||||
void stopWatching(UUID gameId, String sessionId) throws MageException;
|
||||
UUID chatFindByTable(UUID tableId) throws MageException;
|
||||
|
||||
UUID chatFindByTournament(UUID tournamentId) throws MageException;
|
||||
|
||||
UUID chatFindByRoom(UUID roomId) throws MageException;
|
||||
|
||||
boolean matchStart(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
void matchQuit(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void gameJoin(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
@Deprecated // TODO: implement GameView request on miss client side data, e.g. on reconnect (empty player panels bug)?
|
||||
GameView gameGetView(UUID gameId, String sessionId, UUID playerId) throws MageException;
|
||||
|
||||
boolean gameWatchStart(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void gameWatchStop(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void sendPlayerUUID(UUID gameId, String sessionId, UUID data) throws MageException;
|
||||
|
||||
|
|
@ -124,69 +123,58 @@ public interface MageServer {
|
|||
|
||||
void sendPlayerManaType(UUID gameId, UUID playerId, String sessionId, ManaType data) throws MageException;
|
||||
|
||||
void quitMatch(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
GameView getGameView(UUID gameId, String sessionId, UUID playerId) throws MageException;
|
||||
|
||||
// priority, undo, concede, mana pool
|
||||
void sendPlayerAction(PlayerAction playerAction, UUID gameId, String sessionId, Object data) throws MageException;
|
||||
|
||||
//tournament methods
|
||||
boolean startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
DraftPickView sendDraftCardPick(UUID draftId, String sessionId, UUID cardId, Set<UUID> hiddenCards) throws MageException;
|
||||
|
||||
void joinTournament(UUID draftId, String sessionId) throws MageException;
|
||||
void sendDraftCardMark(UUID draftId, String sessionId, UUID cardId) throws MageException;
|
||||
|
||||
void quitTournament(UUID tournamentId, String sessionId) throws MageException;
|
||||
boolean tournamentStart(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
|
||||
TournamentView getTournament(UUID tournamentId) throws MageException;
|
||||
void tournamentJoin(UUID draftId, String sessionId) throws MageException;
|
||||
|
||||
//draft methods
|
||||
void joinDraft(UUID draftId, String sessionId) throws MageException;
|
||||
void tournamentQuit(UUID tournamentId, String sessionId) throws MageException;
|
||||
|
||||
void quitDraft(UUID draftId, String sessionId) throws MageException;
|
||||
TournamentView tournamentFindById(UUID tournamentId) throws MageException;
|
||||
|
||||
DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId, Set<UUID> hiddenCards) throws MageException;
|
||||
void draftJoin(UUID draftId, String sessionId) throws MageException;
|
||||
|
||||
void sendCardMark(UUID draftId, String sessionId, UUID cardId) throws MageException;
|
||||
void draftQuit(UUID draftId, String sessionId) throws MageException;
|
||||
|
||||
void setBoosterLoaded(UUID draftId, String sessionId) throws MageException;
|
||||
void draftSetBoosterLoaded(UUID draftId, String sessionId) throws MageException;
|
||||
|
||||
//challenge methods
|
||||
// void startChallenge(String sessionId, UUID roomId, UUID tableId, UUID challengeId) throws MageException;
|
||||
//replay methods
|
||||
void replayGame(UUID gameId, String sessionId) throws MageException;
|
||||
void replayInit(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void startReplay(UUID gameId, String sessionId) throws MageException;
|
||||
void replayStart(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void stopReplay(UUID gameId, String sessionId) throws MageException;
|
||||
void replayStop(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void nextPlay(UUID gameId, String sessionId) throws MageException;
|
||||
void replayNext(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void previousPlay(UUID gameId, String sessionId) throws MageException;
|
||||
void replayPrevious(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
void skipForward(UUID gameId, String sessionId, int moves) throws MageException;
|
||||
void replaySkipForward(UUID gameId, String sessionId, int moves) throws MageException;
|
||||
|
||||
//test methods
|
||||
void cheat(UUID gameId, String sessionId, UUID playerId, DeckCardLists deckList) throws MageException;
|
||||
void cheatMultiple(UUID gameId, String sessionId, UUID playerId, DeckCardLists deckList) throws MageException;
|
||||
|
||||
boolean cheat(UUID gameId, String sessionId, UUID playerId, String cardName) throws MageException;
|
||||
boolean cheatOne(UUID gameId, String sessionId, UUID playerId, String cardName) throws MageException;
|
||||
|
||||
//admin methods
|
||||
List<UserView> getUsers(String sessionId) throws MageException;
|
||||
List<UserView> adminGetUsers(String sessionId) throws MageException;
|
||||
|
||||
void disconnectUser(String sessionId, String userSessionId) throws MageException;
|
||||
void adminDisconnectUser(String sessionId, String userSessionId) throws MageException;
|
||||
|
||||
void endUserSession(String sessionId, String userSessionId) throws MageException;
|
||||
void adminEndUserSession(String sessionId, String userSessionId) throws MageException;
|
||||
|
||||
void muteUser(String sessionId, String userName, long durationMinutes) throws MageException;
|
||||
void adminMuteUser(String sessionId, String userName, long durationMinutes) throws MageException;
|
||||
|
||||
void lockUser(String sessionId, String userName, long durationMinutes) throws MageException;
|
||||
void adminLockUser(String sessionId, String userName, long durationMinutes) throws MageException;
|
||||
|
||||
void setActivation(String sessionId, String userName, boolean active) throws MageException;
|
||||
void adminActivateUser(String sessionId, String userName, boolean active) throws MageException;
|
||||
|
||||
void toggleActivation(String sessionId, String userName) throws MageException;
|
||||
void adminToggleActivateUser(String sessionId, String userName) throws MageException;
|
||||
|
||||
void removeTable(String sessionId, UUID tableId) throws MageException;
|
||||
void adminTableRemove(String sessionId, UUID tableId) throws MageException;
|
||||
|
||||
void sendBroadcastMessage(String sessionId, String message) throws MageException;
|
||||
void adminSendBroadcastMessage(String sessionId, String message) throws MageException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.remote;
|
||||
|
||||
import mage.remote.interfaces.ChatSession;
|
||||
|
|
@ -13,11 +12,11 @@ import mage.remote.interfaces.ServerState;
|
|||
import mage.remote.interfaces.Testable;
|
||||
|
||||
/**
|
||||
* Extracted interface for SessionImpl class.
|
||||
* Network: client/server session
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public interface Session extends ClientData, Connect, GamePlay, GameTypes, ServerState, ChatSession, Feedback, PlayerActions, Replays, Testable {
|
||||
|
||||
public void appendJsonLog(ActionData actionData);
|
||||
void appendJsonLog(ActionData actionData);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ public class SessionImpl implements Session {
|
|||
showMessageToUser(addMessage + (ex.getMessage() != null ? ex.getMessage() : ""));
|
||||
} catch (MageVersionException ex) {
|
||||
logger.warn("Connect: wrong versions");
|
||||
disconnect(false);
|
||||
connectStop(false);
|
||||
if (!canceled) {
|
||||
showMessageToUser(ex.getMessage());
|
||||
}
|
||||
|
|
@ -188,26 +188,26 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
} catch (Throwable t) {
|
||||
logger.fatal("Connect: FAIL", t);
|
||||
disconnect(false);
|
||||
connectStop(false);
|
||||
if (!canceled) {
|
||||
showMessageToUser(t.getMessage());
|
||||
}
|
||||
} finally {
|
||||
lastRemotingTask = null;
|
||||
if (closeConnectionOnFinish) {
|
||||
disconnect(false); // it's ok on mutiple calls
|
||||
connectStop(false); // it's ok on mutiple calls
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean register(final Connection connection) {
|
||||
public synchronized boolean sendAuthRegister(final Connection connection) {
|
||||
return doRemoteConnection(connection) && doRemoteWorkAndHandleErrors(true, true, new RemotingTask() {
|
||||
@Override
|
||||
public boolean work() throws Throwable {
|
||||
logger.info("Registration: username " + getUserName() + " for email " + getEmail());
|
||||
boolean result = server.registerUser(sessionId, connection.getUsername(), connection.getPassword(), connection.getEmail());
|
||||
boolean result = server.authRegister(sessionId, connection.getUsername(), connection.getPassword(), connection.getEmail());
|
||||
logger.info("Registration: " + (result ? "DONE, check your email for new password" : "FAIL"));
|
||||
return result;
|
||||
}
|
||||
|
|
@ -215,12 +215,12 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean emailAuthToken(final Connection connection) {
|
||||
public synchronized boolean sendAuthSendTokenToEmail(final Connection connection) {
|
||||
return doRemoteConnection(connection) && doRemoteWorkAndHandleErrors(true, true, new RemotingTask() {
|
||||
@Override
|
||||
public boolean work() throws Throwable {
|
||||
logger.info("Auth request: requesting auth token for username " + getUserName() + " to email " + getEmail());
|
||||
boolean result = server.emailAuthToken(sessionId, connection.getEmail());
|
||||
boolean result = server.authSendTokenToEmail(sessionId, connection.getEmail());
|
||||
logger.info("Auth request: " + (result ? "DONE, check your email for auth token" : "FAIL"));
|
||||
return result;
|
||||
}
|
||||
|
|
@ -228,12 +228,12 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean resetPassword(final Connection connection) {
|
||||
public synchronized boolean sendAuthResetPassword(final Connection connection) {
|
||||
return doRemoteConnection(connection) && doRemoteWorkAndHandleErrors(true, true, new RemotingTask() {
|
||||
@Override
|
||||
public boolean work() throws Throwable {
|
||||
logger.info("Password reset: reseting password for username " + getUserName());
|
||||
boolean result = server.resetPassword(sessionId, connection.getEmail(), connection.getAuthToken(), connection.getPassword());
|
||||
boolean result = server.authResetPassword(sessionId, connection.getEmail(), connection.getAuthToken(), connection.getPassword());
|
||||
logger.info("Password reset: " + (result ? "DONE, now you can login with new password" : "FAIL"));
|
||||
return result;
|
||||
}
|
||||
|
|
@ -241,7 +241,7 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean connect(final Connection connection) {
|
||||
public synchronized boolean connectStart(final Connection connection) {
|
||||
return doRemoteConnection(connection) && doRemoteWorkAndHandleErrors(false, true, new RemotingTask() {
|
||||
@Override
|
||||
public boolean work() throws Throwable {
|
||||
|
|
@ -257,7 +257,7 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
if (result) {
|
||||
serverState = server.getServerState();
|
||||
serverState = server.serverGetState();
|
||||
|
||||
// client side check for incompatible versions
|
||||
if (client.getVersion().compareTo(serverState.getVersion()) != 0) {
|
||||
|
|
@ -265,7 +265,7 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
if (!connection.getUsername().equals("Admin")) {
|
||||
server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr());
|
||||
server.connectSetUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr());
|
||||
updateDatabase(connection.isForceDBComparison(), serverState);
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean stopConnecting() {
|
||||
public boolean connectAbort() {
|
||||
canceled = true;
|
||||
if (lastRemotingTask != null) {
|
||||
lastRemotingTask.cancel();
|
||||
|
|
@ -297,7 +297,7 @@ public class SessionImpl implements Session {
|
|||
private boolean doRemoteConnection(final Connection connection) {
|
||||
// connect to server and setup all data, can be canceled
|
||||
if (isConnected()) {
|
||||
disconnect(true);
|
||||
connectStop(true);
|
||||
}
|
||||
this.connection = connection;
|
||||
this.canceled = false;
|
||||
|
|
@ -461,7 +461,7 @@ public class SessionImpl implements Session {
|
|||
if (result) {
|
||||
return true;
|
||||
} else {
|
||||
disconnect(false);
|
||||
connectStop(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -474,7 +474,7 @@ public class SessionImpl implements Session {
|
|||
long expansionDBVersion = ExpansionRepository.instance.getContentVersionFromDB();
|
||||
if (forceDBComparison || serverState.getExpansionsContentVersion() > expansionDBVersion) {
|
||||
List<String> setCodes = ExpansionRepository.instance.getSetCodes();
|
||||
List<ExpansionInfo> expansions = server.getMissingExpansionData(setCodes);
|
||||
List<ExpansionInfo> expansions = server.syncGetMissingExpansionData(setCodes);
|
||||
logger.info("DB: updating sets... Found new: " + expansions.size());
|
||||
ExpansionRepository.instance.saveSets(expansions, null, serverState.getExpansionsContentVersion());
|
||||
}
|
||||
|
|
@ -483,7 +483,7 @@ public class SessionImpl implements Session {
|
|||
long cardDBVersion = CardRepository.instance.getContentVersionFromDB();
|
||||
if (forceDBComparison || serverState.getCardsContentVersion() > cardDBVersion) {
|
||||
List<String> classNames = CardRepository.instance.getClassNames();
|
||||
List<CardInfo> cards = server.getMissingCardsData(classNames);
|
||||
List<CardInfo> cards = server.syncGetMissingCardsData(classNames);
|
||||
logger.info("DB: updating cards... Found new: " + cards.size());
|
||||
CardRepository.instance.saveCards(cards, serverState.getCardsContentVersion());
|
||||
}
|
||||
|
|
@ -524,7 +524,7 @@ public class SessionImpl implements Session {
|
|||
* ask the user if they want to try to reconnect
|
||||
*/
|
||||
@Override
|
||||
public synchronized void disconnect(boolean askForReconnect) {
|
||||
public synchronized void connectStop(boolean askForReconnect) {
|
||||
if (isConnected()) {
|
||||
logger.info("Disconnecting...");
|
||||
sessionState = SessionState.DISCONNECTING;
|
||||
|
|
@ -556,7 +556,7 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reconnect(Throwable throwable) {
|
||||
public synchronized void connectReconnect(Throwable throwable) {
|
||||
client.disconnected(true);
|
||||
}
|
||||
|
||||
|
|
@ -564,7 +564,7 @@ public class SessionImpl implements Session {
|
|||
public synchronized boolean sendFeedback(String title, String type, String message, String email) {
|
||||
if (isConnected()) {
|
||||
try {
|
||||
server.sendFeedbackMessage(sessionId, connection.getUsername(), title, type, message, email);
|
||||
server.serverAddFeedbackMessage(sessionId, connection.getUsername(), title, type, message, email);
|
||||
return true;
|
||||
} catch (MageException e) {
|
||||
logger.error(e);
|
||||
|
|
@ -592,7 +592,7 @@ public class SessionImpl implements Session {
|
|||
@Override
|
||||
public void handleConnectionException(Throwable throwable, Client client) {
|
||||
logger.info("Connect: lost connection to server.", throwable);
|
||||
reconnect(throwable);
|
||||
connectReconnect(throwable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -654,7 +654,7 @@ public class SessionImpl implements Session {
|
|||
public UUID getMainRoomId() {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.getMainRoomId();
|
||||
return server.serverGetMainRoomId();
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -666,7 +666,7 @@ public class SessionImpl implements Session {
|
|||
public Optional<UUID> getRoomChatId(UUID roomId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return Optional.of(server.getRoomChatId(roomId));
|
||||
return Optional.of(server.chatFindByRoom(roomId));
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -678,7 +678,7 @@ public class SessionImpl implements Session {
|
|||
public Optional<UUID> getTableChatId(UUID tableId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return Optional.of(server.getTableChatId(tableId));
|
||||
return Optional.of(server.chatFindByTable(tableId));
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -690,7 +690,7 @@ public class SessionImpl implements Session {
|
|||
public Optional<UUID> getGameChatId(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return Optional.of(server.getGameChatId(gameId));
|
||||
return Optional.of(server.chatFindByGame(gameId));
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -704,7 +704,7 @@ public class SessionImpl implements Session {
|
|||
public Optional<TableView> getTable(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return Optional.of(server.getTable(roomId, tableId));
|
||||
return Optional.of(server.roomGetTableById(roomId, tableId));
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -716,7 +716,7 @@ public class SessionImpl implements Session {
|
|||
public boolean watchTable(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.watchTable(sessionId, roomId, tableId);
|
||||
server.roomWatchTable(sessionId, roomId, tableId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -731,7 +731,7 @@ public class SessionImpl implements Session {
|
|||
public boolean watchTournamentTable(UUID tableId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.watchTournamentTable(sessionId, tableId);
|
||||
server.roomWatchTournament(sessionId, tableId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -751,7 +751,7 @@ public class SessionImpl implements Session {
|
|||
deckList.setCardLayout(null);
|
||||
deckList.setSideboardLayout(null);
|
||||
}
|
||||
return server.joinTable(sessionId, roomId, tableId, playerName, playerType, skill, deckList, password);
|
||||
return server.roomJoinTable(sessionId, roomId, tableId, playerName, playerType, skill, deckList, password);
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
handleGameException(ex);
|
||||
|
|
@ -772,7 +772,7 @@ public class SessionImpl implements Session {
|
|||
deckList.setCardLayout(null);
|
||||
deckList.setSideboardLayout(null);
|
||||
}
|
||||
return server.joinTournamentTable(sessionId, roomId, tableId, playerName, playerType, skill, deckList, password);
|
||||
return server.roomJoinTournament(sessionId, roomId, tableId, playerName, playerType, skill, deckList, password);
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
handleGameException(ex);
|
||||
|
|
@ -788,7 +788,7 @@ public class SessionImpl implements Session {
|
|||
public Collection<TableView> getTables(UUID roomId) throws MageRemoteException {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.getTables(roomId);
|
||||
return server.roomGetAllTables(roomId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -803,7 +803,7 @@ public class SessionImpl implements Session {
|
|||
public Collection<MatchView> getFinishedMatches(UUID roomId) throws MageRemoteException {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.getFinishedMatches(roomId);
|
||||
return server.roomGetFinishedMatches(roomId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -818,7 +818,7 @@ public class SessionImpl implements Session {
|
|||
public Collection<RoomUsersView> getRoomUsers(UUID roomId) throws MageRemoteException {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.getRoomUsers(roomId);
|
||||
return server.roomGetUsers(roomId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -833,7 +833,7 @@ public class SessionImpl implements Session {
|
|||
public TournamentView getTournament(UUID tournamentId) throws MageRemoteException {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.getTournament(tournamentId);
|
||||
return server.tournamentFindById(tournamentId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -848,7 +848,7 @@ public class SessionImpl implements Session {
|
|||
public Optional<UUID> getTournamentChatId(UUID tournamentId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return Optional.of(server.getTournamentChatId(tournamentId));
|
||||
return Optional.of(server.chatFindByTournament(tournamentId));
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -974,7 +974,7 @@ public class SessionImpl implements Session {
|
|||
public DraftPickView sendCardPick(UUID draftId, UUID cardId, Set<UUID> hiddenCards) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.sendCardPick(draftId, sessionId, cardId, hiddenCards);
|
||||
return server.sendDraftCardPick(draftId, sessionId, cardId, hiddenCards);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -988,7 +988,7 @@ public class SessionImpl implements Session {
|
|||
public DraftPickView sendCardMark(UUID draftId, UUID cardId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.sendCardMark(draftId, sessionId, cardId);
|
||||
server.sendDraftCardMark(draftId, sessionId, cardId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1002,7 +1002,7 @@ public class SessionImpl implements Session {
|
|||
public boolean setBoosterLoaded(UUID draftId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.setBoosterLoaded(draftId, sessionId);
|
||||
server.draftSetBoosterLoaded(draftId, sessionId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1016,7 +1016,7 @@ public class SessionImpl implements Session {
|
|||
public boolean joinChat(UUID chatId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.joinChat(chatId, sessionId, connection.getUsername());
|
||||
server.chatJoin(chatId, sessionId, connection.getUsername());
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1032,7 +1032,7 @@ public class SessionImpl implements Session {
|
|||
// lock.readLock().lock();
|
||||
try {
|
||||
if (isConnected() && chatId != null) {
|
||||
server.leaveChat(chatId, sessionId);
|
||||
server.chatLeave(chatId, sessionId);
|
||||
}
|
||||
return true;
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1050,7 +1050,7 @@ public class SessionImpl implements Session {
|
|||
// lock.readLock().lock();
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.sendChatMessage(chatId, connection.getUsername(), message);
|
||||
server.chatSendMessage(chatId, connection.getUsername(), message);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1067,7 +1067,7 @@ public class SessionImpl implements Session {
|
|||
public boolean sendBroadcastMessage(String message) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.sendBroadcastMessage(sessionId, message);
|
||||
server.adminSendBroadcastMessage(sessionId, message);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1082,7 +1082,7 @@ public class SessionImpl implements Session {
|
|||
public boolean joinGame(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.joinGame(gameId, sessionId);
|
||||
server.gameJoin(gameId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1097,7 +1097,7 @@ public class SessionImpl implements Session {
|
|||
public boolean joinDraft(UUID draftId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.joinDraft(draftId, sessionId);
|
||||
server.draftJoin(draftId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1112,7 +1112,7 @@ public class SessionImpl implements Session {
|
|||
public boolean joinTournament(UUID tournamentId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.joinTournament(tournamentId, sessionId);
|
||||
server.tournamentJoin(tournamentId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1127,7 +1127,7 @@ public class SessionImpl implements Session {
|
|||
public boolean watchGame(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.watchGame(gameId, sessionId);
|
||||
return server.gameWatchStart(gameId, sessionId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1141,7 +1141,7 @@ public class SessionImpl implements Session {
|
|||
public boolean replayGame(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.replayGame(gameId, sessionId);
|
||||
server.replayInit(gameId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1156,7 +1156,7 @@ public class SessionImpl implements Session {
|
|||
public TableView createTable(UUID roomId, MatchOptions matchOptions) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.createTable(sessionId, roomId, matchOptions);
|
||||
return server.roomCreateTable(sessionId, roomId, matchOptions);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1170,7 +1170,7 @@ public class SessionImpl implements Session {
|
|||
public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.createTournamentTable(sessionId, roomId, tournamentOptions);
|
||||
return server.roomCreateTournament(sessionId, roomId, tournamentOptions);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1184,7 +1184,7 @@ public class SessionImpl implements Session {
|
|||
public boolean isTableOwner(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.isTableOwner(sessionId, roomId, tableId);
|
||||
return server.tableIsOwner(sessionId, roomId, tableId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1198,7 +1198,7 @@ public class SessionImpl implements Session {
|
|||
public boolean removeTable(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.removeTable(sessionId, roomId, tableId);
|
||||
server.tableRemove(sessionId, roomId, tableId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1220,7 +1220,7 @@ public class SessionImpl implements Session {
|
|||
public boolean removeTable(UUID tableId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.removeTable(sessionId, tableId);
|
||||
server.adminTableRemove(sessionId, tableId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1235,7 +1235,7 @@ public class SessionImpl implements Session {
|
|||
public boolean swapSeats(UUID roomId, UUID tableId, int seatNum1, int seatNum2) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.swapSeats(sessionId, roomId, tableId, seatNum1, seatNum2);
|
||||
server.tableSwapSeats(sessionId, roomId, tableId, seatNum1, seatNum2);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1249,7 +1249,7 @@ public class SessionImpl implements Session {
|
|||
@Override
|
||||
public boolean leaveTable(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
if (isConnected() && server.leaveTable(sessionId, roomId, tableId)) {
|
||||
if (isConnected() && server.roomLeaveTableOrTournament(sessionId, roomId, tableId)) {
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1264,7 +1264,7 @@ public class SessionImpl implements Session {
|
|||
public boolean startMatch(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return (server.startMatch(sessionId, roomId, tableId));
|
||||
return (server.matchStart(sessionId, roomId, tableId));
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1275,7 +1275,7 @@ public class SessionImpl implements Session {
|
|||
@Override
|
||||
public boolean startTournament(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
if (isConnected() && server.startTournament(sessionId, roomId, tableId)) {
|
||||
if (isConnected() && server.tournamentStart(sessionId, roomId, tableId)) {
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1309,7 +1309,7 @@ public class SessionImpl implements Session {
|
|||
deck.setCardLayout(null);
|
||||
deck.setSideboardLayout(null);
|
||||
}
|
||||
return server.submitDeck(sessionId, tableId, deck);
|
||||
return server.deckSubmit(sessionId, tableId, deck);
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
handleGameException(ex);
|
||||
|
|
@ -1329,7 +1329,7 @@ public class SessionImpl implements Session {
|
|||
deck.setCardLayout(null);
|
||||
deck.setSideboardLayout(null);
|
||||
}
|
||||
server.updateDeck(sessionId, tableId, deck);
|
||||
server.deckSave(sessionId, tableId, deck);
|
||||
return true;
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
|
|
@ -1346,7 +1346,7 @@ public class SessionImpl implements Session {
|
|||
public boolean quitMatch(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.quitMatch(gameId, sessionId);
|
||||
server.matchQuit(gameId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1361,7 +1361,7 @@ public class SessionImpl implements Session {
|
|||
public boolean quitTournament(UUID tournamentId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.quitTournament(tournamentId, sessionId);
|
||||
server.tournamentQuit(tournamentId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1376,7 +1376,7 @@ public class SessionImpl implements Session {
|
|||
public boolean quitDraft(UUID draftId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.quitDraft(draftId, sessionId);
|
||||
server.draftQuit(draftId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1409,7 +1409,7 @@ public class SessionImpl implements Session {
|
|||
public boolean stopWatching(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.stopWatching(gameId, sessionId);
|
||||
server.gameWatchStop(gameId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1424,7 +1424,7 @@ public class SessionImpl implements Session {
|
|||
public boolean startReplay(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.startReplay(gameId, sessionId);
|
||||
server.replayStart(gameId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1439,7 +1439,7 @@ public class SessionImpl implements Session {
|
|||
public boolean stopReplay(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.stopReplay(gameId, sessionId);
|
||||
server.replayStop(gameId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1454,7 +1454,7 @@ public class SessionImpl implements Session {
|
|||
public boolean nextPlay(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.nextPlay(gameId, sessionId);
|
||||
server.replayNext(gameId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1469,7 +1469,7 @@ public class SessionImpl implements Session {
|
|||
public boolean previousPlay(UUID gameId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.previousPlay(gameId, sessionId);
|
||||
server.replayPrevious(gameId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1484,7 +1484,7 @@ public class SessionImpl implements Session {
|
|||
public boolean skipForward(UUID gameId, int moves) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.skipForward(gameId, sessionId, moves);
|
||||
server.replaySkipForward(gameId, sessionId, moves);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1499,7 +1499,7 @@ public class SessionImpl implements Session {
|
|||
public boolean cheat(UUID gameId, UUID playerId, DeckCardLists deckList) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.cheat(gameId, sessionId, playerId, deckList);
|
||||
server.cheatMultiple(gameId, sessionId, playerId, deckList);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1514,7 +1514,7 @@ public class SessionImpl implements Session {
|
|||
public List<UserView> getUsers() {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.getUsers(sessionId);
|
||||
return server.adminGetUsers(sessionId);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1528,7 +1528,7 @@ public class SessionImpl implements Session {
|
|||
public List<String> getServerMessages() {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return (List<String>) CompressUtil.decompress(server.getServerMessagesCompressed(sessionId));
|
||||
return (List<String>) CompressUtil.decompress(server.serverGetPromotionMessages(sessionId));
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
@ -1539,10 +1539,10 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean disconnectUser(String userSessionId) {
|
||||
public boolean sendAdminDisconnectUser(String userSessionId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.disconnectUser(sessionId, userSessionId);
|
||||
server.adminDisconnectUser(sessionId, userSessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1554,10 +1554,10 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean endUserSession(String userSessionId) {
|
||||
public boolean sendAdminEndUserSession(String userSessionId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.endUserSession(sessionId, userSessionId);
|
||||
server.adminEndUserSession(sessionId, userSessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1569,10 +1569,10 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean muteUserChat(String userName, long durationMinutes) {
|
||||
public boolean sendAdminMuteUserChat(String userName, long durationMinutes) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.muteUser(sessionId, userName, durationMinutes);
|
||||
server.adminMuteUser(sessionId, userName, durationMinutes);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1584,10 +1584,10 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean setActivation(String userName, boolean active) {
|
||||
public boolean sendAdminActivateUser(String userName, boolean active) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.setActivation(sessionId, userName, active);
|
||||
server.adminActivateUser(sessionId, userName, active);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1599,10 +1599,10 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean toggleActivation(String userName) {
|
||||
public boolean sendAdminToggleActivateUser(String userName) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.toggleActivation(sessionId, userName);
|
||||
server.adminToggleActivateUser(sessionId, userName);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1614,10 +1614,10 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean lockUser(String userName, long durationMinute) {
|
||||
public boolean sendAdminLockUser(String userName, long durationMinute) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.lockUser(sessionId, userName, durationMinute);
|
||||
server.adminLockUser(sessionId, userName, durationMinute);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1679,7 +1679,7 @@ public class SessionImpl implements Session {
|
|||
public boolean updatePreferencesForServer(UserData userData) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.setUserData(connection.getUsername(), sessionId, userData, null, null);
|
||||
server.connectSetUserData(connection.getUsername(), sessionId, userData, null, null);
|
||||
}
|
||||
return true;
|
||||
} catch (MageException ex) {
|
||||
|
|
@ -1718,7 +1718,7 @@ public class SessionImpl implements Session {
|
|||
return true;
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
disconnect(true);
|
||||
connectStop(true);
|
||||
} catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
|
|
@ -1752,7 +1752,6 @@ public class SessionImpl implements Session {
|
|||
public String getLastError() {
|
||||
return lastError;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MageAuthenticator extends Authenticator {
|
||||
|
|
|
|||
|
|
@ -5,43 +5,45 @@ import mage.remote.Connection;
|
|||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Network: client side commands for a server
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public interface Connect {
|
||||
|
||||
boolean register(Connection connection);
|
||||
String getSessionId();
|
||||
|
||||
boolean emailAuthToken(Connection connection);
|
||||
String getLastError();
|
||||
|
||||
boolean resetPassword(Connection connection);
|
||||
Optional<String> getServerHostname();
|
||||
|
||||
boolean connect(Connection connection);
|
||||
boolean sendAuthRegister(Connection connection);
|
||||
|
||||
boolean stopConnecting();
|
||||
boolean sendAuthSendTokenToEmail(Connection connection);
|
||||
|
||||
void disconnect(boolean showMessage);
|
||||
boolean sendAuthResetPassword(Connection connection);
|
||||
|
||||
void reconnect(Throwable throwable);
|
||||
boolean connectStart(Connection connection);
|
||||
|
||||
boolean connectAbort();
|
||||
|
||||
void connectStop(boolean showMessage);
|
||||
|
||||
void connectReconnect(Throwable throwable);
|
||||
|
||||
boolean ping();
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
Optional<String> getServerHostname();
|
||||
boolean sendAdminDisconnectUser(String userSessionId);
|
||||
|
||||
boolean disconnectUser(String userSessionId);
|
||||
boolean sendAdminEndUserSession(String userSessionId);
|
||||
|
||||
boolean endUserSession(String userSessionId);
|
||||
boolean sendAdminMuteUserChat(String userName, long durationMinute);
|
||||
|
||||
boolean muteUserChat(String userName, long durationMinute);
|
||||
boolean sendAdminActivateUser(String userName, boolean active);
|
||||
|
||||
boolean setActivation(String userName, boolean active);
|
||||
boolean sendAdminToggleActivateUser(String userName);
|
||||
|
||||
boolean toggleActivation(String userName);
|
||||
|
||||
boolean lockUser(String userName, long durationMinute);
|
||||
|
||||
String getSessionId();
|
||||
|
||||
String getLastError();
|
||||
boolean sendAdminLockUser(String userName, long durationMinute);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
public boolean connect(Connection connection) {
|
||||
if (session.connect(connection)) {
|
||||
if (session.connectStart(connection)) {
|
||||
this.consolePanel1.start();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
if (session.isConnected()) {
|
||||
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
this.consolePanel1.stop();
|
||||
session.disconnect(false);
|
||||
session.connectStop(false);
|
||||
}
|
||||
} else {
|
||||
connectDialog.showDialog(this);
|
||||
|
|
@ -251,7 +251,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
if (JOptionPane.showConfirmDialog(this, "You are currently connected. Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
}
|
||||
session.disconnect(false);
|
||||
session.connectStop(false);
|
||||
} else {
|
||||
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Confirm exit", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@
|
|||
|
||||
private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisconnectActionPerformed
|
||||
int row = this.tblUsers.convertRowIndexToModel(tblUsers.getSelectedRow());
|
||||
ConsoleFrame.getSession().disconnectUser((String) tableUserModel.getValueAt(row, TableUserModel.POS_SESSION_ID));
|
||||
ConsoleFrame.getSession().sendAdminDisconnectUser((String) tableUserModel.getValueAt(row, TableUserModel.POS_SESSION_ID));
|
||||
}//GEN-LAST:event_btnDisconnectActionPerformed
|
||||
|
||||
private void btnEndSessionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEndSessionActionPerformed
|
||||
|
|
@ -321,7 +321,7 @@
|
|||
|
||||
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to end userSessionId " + userSessionId + '?', "WARNING",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
ConsoleFrame.getSession().endUserSession(userSessionId);
|
||||
ConsoleFrame.getSession().sendAdminEndUserSession(userSessionId);
|
||||
}
|
||||
}//GEN-LAST:event_btnEndSessionActionPerformed
|
||||
|
||||
|
|
@ -331,7 +331,7 @@
|
|||
long durationMinute = ((Number) spinnerMuteDurationMinutes.getValue()).longValue();
|
||||
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to mute user: " + userName + " for " + durationMinute + " minutes?", "WARNING",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
ConsoleFrame.getSession().muteUserChat(userName, durationMinute);
|
||||
ConsoleFrame.getSession().sendAdminMuteUserChat(userName, durationMinute);
|
||||
}
|
||||
}//GEN-LAST:event_btnMuteUserActionPerformed
|
||||
|
||||
|
|
@ -346,17 +346,17 @@
|
|||
|
||||
if (JOptionPane.showConfirmDialog(null, "Did you want to set user: " + userName + " to active?", "WARNING",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
ConsoleFrame.getSession().setActivation(userName, true);
|
||||
ConsoleFrame.getSession().sendAdminActivateUser(userName, true);
|
||||
return;
|
||||
}
|
||||
if (JOptionPane.showConfirmDialog(null, "Did you want to set user: " + userName + " to inactive?", "WARNING",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
ConsoleFrame.getSession().setActivation(userName, false);
|
||||
ConsoleFrame.getSession().sendAdminActivateUser(userName, false);
|
||||
return;
|
||||
}
|
||||
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to toggle activation for user: " + userName + '?', "WARNING",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
ConsoleFrame.getSession().toggleActivation(userName);
|
||||
ConsoleFrame.getSession().sendAdminToggleActivateUser(userName);
|
||||
return;
|
||||
}
|
||||
}//GEN-LAST:event_btnDeActivateActionPerformed
|
||||
|
|
@ -367,7 +367,7 @@
|
|||
long durationMinute = ((Number) spinnerMuteDurationMinutes.getValue()).longValue();
|
||||
if (JOptionPane.showConfirmDialog(null, "Are you sure you mean to lock user: " + userName + " for " + durationMinute + " minutes?", "WARNING",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
ConsoleFrame.getSession().lockUser(userName, durationMinute);
|
||||
ConsoleFrame.getSession().sendAdminLockUser(userName, durationMinute);
|
||||
}
|
||||
}//GEN-LAST:event_btnLockUserActionPerformed
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public enum DisconnectReason {
|
|||
Disconnected(" has left XMage"),
|
||||
CleaningUp(" [cleaning up]"),
|
||||
ConnectingOtherInstance(" reconnected and replaced still active old session"),
|
||||
AdminDisconnect(" was disconnected by the Admin"),
|
||||
AdminDisconnect(" was disconnected by the admin"),
|
||||
SessionExpired(" session expired"),
|
||||
Undefined("");
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean registerUser(String sessionId, String userName, String password, String email) throws MageException {
|
||||
public boolean authRegister(String sessionId, String userName, String password, String email) throws MageException {
|
||||
return managerFactory.sessionManager().registerUser(sessionId, userName, password, email);
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean emailAuthToken(String sessionId, String email) throws MageException {
|
||||
public boolean authSendTokenToEmail(String sessionId, String email) throws MageException {
|
||||
if (!managerFactory.configSettings().isAuthenticationActivated()) {
|
||||
sendErrorMessageToClient(sessionId, Session.REGISTRATION_DISABLED_MESSAGE);
|
||||
return false;
|
||||
|
|
@ -113,7 +113,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException {
|
||||
public boolean authResetPassword(String sessionId, String email, String authToken, String password) throws MageException {
|
||||
if (!managerFactory.configSettings().isAuthenticationActivated()) {
|
||||
sendErrorMessageToClient(sessionId, Session.REGISTRATION_DISABLED_MESSAGE);
|
||||
return false;
|
||||
|
|
@ -162,7 +162,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean setUserData(final String userName, final String sessionId, final UserData userData, final String clientVersion, final String userIdStr) throws MageException {
|
||||
public boolean connectSetUserData(final String userName, final String sessionId, final UserData userData, final String clientVersion, final String userIdStr) throws MageException {
|
||||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
|
|
@ -189,12 +189,12 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableView createTable(final String sessionId, final UUID roomId, final MatchOptions options) throws MageException {
|
||||
return executeWithResult("createTable", sessionId, new MyActionWithTableViewResult(sessionId, options, roomId));
|
||||
public TableView roomCreateTable(final String sessionId, final UUID roomId, final MatchOptions options) throws MageException {
|
||||
return executeWithResult("createTable", sessionId, new CreateTableAction(sessionId, options, roomId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableView createTournamentTable(final String sessionId, final UUID roomId, final TournamentOptions options) throws MageException {
|
||||
public TableView roomCreateTournament(final String sessionId, final UUID roomId, final TournamentOptions options) throws MageException {
|
||||
return executeWithResult("createTournamentTable", sessionId, new ActionWithTableViewResult() {
|
||||
@Override
|
||||
public TableView execute() throws MageException {
|
||||
|
|
@ -275,7 +275,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public void tableRemove(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
execute("removeTable", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -285,7 +285,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final PlayerType playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException {
|
||||
public boolean roomJoinTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final PlayerType playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException {
|
||||
return executeWithResult("joinTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
|
|
@ -310,7 +310,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTournamentTable(final String sessionId, final UUID roomId, final UUID tableId, final String name, final PlayerType playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException {
|
||||
public boolean roomJoinTournament(final String sessionId, final UUID roomId, final UUID tableId, final String name, final PlayerType playerType, final int skill, final DeckCardLists deckList, final String password) throws MageException {
|
||||
return executeWithResult("joinTournamentTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
|
|
@ -338,8 +338,8 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean submitDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException {
|
||||
return executeWithResult("submitDeck", sessionId, new ActionWithBooleanResult() {
|
||||
public boolean deckSubmit(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException {
|
||||
return executeWithResult("deckSubmit", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
|
|
@ -356,7 +356,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException {
|
||||
public void deckSave(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException {
|
||||
execute("updateDeck", sessionId, () -> {
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
|
|
@ -372,7 +372,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public List<TableView> getTables(UUID roomId) throws MageException {
|
||||
public List<TableView> roomGetAllTables(UUID roomId) throws MageException {
|
||||
try {
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
|
|
@ -388,7 +388,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public List<MatchView> getFinishedMatches(UUID roomId) throws MageException {
|
||||
public List<MatchView> roomGetFinishedMatches(UUID roomId) throws MageException {
|
||||
try {
|
||||
return managerFactory.gamesRoomManager().getRoom(roomId).map(GamesRoom::getFinished).orElse(new ArrayList<>());
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -398,7 +398,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException {
|
||||
public List<RoomUsersView> roomGetUsers(UUID roomId) throws MageException {
|
||||
try {
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (room.isPresent()) {
|
||||
|
|
@ -414,7 +414,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws MageException {
|
||||
public TableView roomGetTableById(UUID roomId, UUID tableId) throws MageException {
|
||||
try {
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
return room.flatMap(r -> r.getTable(tableId)).orElse(null);
|
||||
|
|
@ -431,7 +431,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public boolean matchStart(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
Optional<TableController> controller = managerFactory.tableManager().getController(tableId);
|
||||
if (!controller.isPresent()) {
|
||||
logger.error("table not found : " + tableId);
|
||||
|
|
@ -453,7 +453,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public boolean tournamentStart(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
Optional<TableController> controller = managerFactory.tableManager().getController(tableId);
|
||||
if (!controller.isPresent()) {
|
||||
logger.error("table not found : " + tableId);
|
||||
|
|
@ -476,7 +476,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public TournamentView getTournament(UUID tournamentId) throws MageException {
|
||||
public TournamentView tournamentFindById(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return managerFactory.tournamentManager().getTournamentView(tournamentId);
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -487,7 +487,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
|
||||
public void chatSendMessage(final UUID chatId, final String userName, final String message) throws MageException {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
() -> managerFactory.chatManager().broadcast(chatId, userName, HtmlEscape.escapeHtml4(message), MessageColor.BLUE, true, null, ChatMessage.MessageType.TALK, null)
|
||||
|
|
@ -498,7 +498,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException {
|
||||
public void chatJoin(final UUID chatId, final String sessionId, final String userName) throws MageException {
|
||||
execute("joinChat", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
|
||||
|
|
@ -509,7 +509,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void leaveChat(final UUID chatId, final String sessionId) throws MageException {
|
||||
public void chatLeave(final UUID chatId, final String sessionId) throws MageException {
|
||||
execute("leaveChat", sessionId, () -> {
|
||||
if (chatId != null) {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
|
|
@ -522,7 +522,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getMainRoomId() throws MageException {
|
||||
public UUID serverGetMainRoomId() throws MageException {
|
||||
try {
|
||||
return managerFactory.gamesRoomManager().getMainRoomId();
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -533,7 +533,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getRoomChatId(UUID roomId) throws MageException {
|
||||
public UUID chatFindByRoom(UUID roomId) throws MageException {
|
||||
try {
|
||||
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
|
||||
if (!room.isPresent()) {
|
||||
|
|
@ -548,7 +548,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isTableOwner(final String sessionId, UUID roomId, final UUID tableId) throws MageException {
|
||||
public boolean tableIsOwner(final String sessionId, UUID roomId, final UUID tableId) throws MageException {
|
||||
return executeWithResult("isTableOwner", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() {
|
||||
|
|
@ -564,7 +564,7 @@ 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 {
|
||||
public void tableSwapSeats(final String sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws MageException {
|
||||
execute("swapSeats", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -574,7 +574,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public boolean roomLeaveTableOrTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
Optional<TableController> tableController = managerFactory.tableManager().getController(tableId);
|
||||
if (tableController.isPresent()) {
|
||||
TableState tableState = tableController.get().getTableState();
|
||||
|
|
@ -599,7 +599,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getTableChatId(UUID tableId) throws MageException {
|
||||
public UUID chatFindByTable(UUID tableId) throws MageException {
|
||||
try {
|
||||
return managerFactory.tableManager().getChatId(tableId).orElse(null);
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -609,7 +609,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void joinGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
public void gameJoin(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("joinGame", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -619,7 +619,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void joinDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
public void draftJoin(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("joinDraft", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -629,7 +629,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
public void tournamentJoin(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
execute("joinTournament", sessionId, () -> {
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
|
|
@ -643,7 +643,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getGameChatId(UUID gameId) throws MageException {
|
||||
public UUID chatFindByGame(UUID gameId) throws MageException {
|
||||
try {
|
||||
return managerFactory.gameManager().getChatId(gameId).orElse(null);
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -654,7 +654,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws MageException {
|
||||
public UUID chatFindByTournament(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return managerFactory.tournamentManager().getChatId(tournamentId).orElse(null);
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -724,12 +724,12 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick, final Set<UUID> hiddenCards) throws MageException {
|
||||
return executeWithResult("sendCardPick", sessionId, new DraftPickViewActionWithNullNegativeResult(sessionId, draftId, cardPick, hiddenCards));
|
||||
public DraftPickView sendDraftCardPick(final UUID draftId, final String sessionId, final UUID cardPick, final Set<UUID> hiddenCards) throws MageException {
|
||||
return executeWithResult("sendCardPick", sessionId, new SendCardPickAction(sessionId, draftId, cardPick, hiddenCards));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCardMark(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
||||
public void sendDraftCardMark(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
||||
execute("sendCardMark", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -739,7 +739,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setBoosterLoaded(final UUID draftId, final String sessionId) throws MageException {
|
||||
public void draftSetBoosterLoaded(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("setBoosterLoaded", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -749,7 +749,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void quitMatch(final UUID gameId, final String sessionId) throws MageException {
|
||||
public void matchQuit(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("quitMatch", sessionId, () -> {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
|
|
@ -767,7 +767,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void quitTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
public void tournamentQuit(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
execute("quitTournament", sessionId, () -> {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
|
|
@ -787,7 +787,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
|
||||
public void quitDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
public void draftQuit(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("quitDraft", sessionId, () -> {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
|
|
@ -822,7 +822,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean watchTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public boolean roomWatchTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
|
|
@ -843,12 +843,12 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean watchTournamentTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
return executeWithResult("setUserData", sessionId, new MyActionWithBooleanResult(sessionId, tableId));
|
||||
public boolean roomWatchTournament(final String sessionId, final UUID tableId) throws MageException {
|
||||
return executeWithResult("setUserData", sessionId, new WatchTournamentTableAction(sessionId, tableId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean watchGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
public boolean gameWatchStart(final UUID gameId, final String sessionId) throws MageException {
|
||||
return executeWithResult("watchGame", sessionId, new ActionWithResult<Boolean>() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
|
|
@ -867,7 +867,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
|
||||
public void gameWatchStop(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("stopWatching", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -881,7 +881,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void replayGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
public void replayInit(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("replayGame", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -891,7 +891,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
public void replayStart(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("startReplay", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
|
|
@ -901,7 +901,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void stopReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
public void replayStop(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("stopReplay", sessionId, () -> {
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
|
|
@ -914,7 +914,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void nextPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
public void replayNext(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("nextPlay", sessionId, () -> {
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
|
|
@ -927,7 +927,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void previousPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
public void replayPrevious(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("previousPlay", sessionId, () -> {
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
|
|
@ -940,7 +940,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void skipForward(final UUID gameId, final String sessionId, final int moves) throws MageException {
|
||||
public void replaySkipForward(final UUID gameId, final String sessionId, final int moves) throws MageException {
|
||||
execute("skipForward", sessionId, () -> {
|
||||
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId);
|
||||
if (!session.isPresent()) {
|
||||
|
|
@ -954,7 +954,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
//TODO: check how often it is used
|
||||
public ServerState getServerState() throws MageException {
|
||||
public ServerState serverGetState() throws MageException {
|
||||
try {
|
||||
return new ServerState(
|
||||
GameFactory.instance.getGameTypes(),
|
||||
|
|
@ -974,7 +974,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void cheat(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
|
||||
public void cheatMultiple(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
|
||||
execute("cheat", sessionId, () -> {
|
||||
if (testMode) {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
|
|
@ -986,7 +986,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean cheat(final UUID gameId, final String sessionId, final UUID playerId, final String cardName) throws MageException {
|
||||
public boolean cheatOne(final UUID gameId, final String sessionId, final UUID playerId, final String cardName) throws MageException {
|
||||
return executeWithResult("cheatOne", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() {
|
||||
|
|
@ -1012,8 +1012,8 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) throws MageException {
|
||||
return executeWithResult("getGameView", sessionId, new GameViewActionWithNullNegativeResult(sessionId, gameId, playerId));
|
||||
public GameView gameGetView(final UUID gameId, final String sessionId, final UUID playerId) throws MageException {
|
||||
return executeWithResult("getGameView", sessionId, new GetGameViewAction(sessionId, gameId, playerId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1024,30 +1024,32 @@ public class MageServerImpl implements MageServer {
|
|||
* @throws MageException
|
||||
*/
|
||||
@Override
|
||||
public List<UserView> getUsers(String sessionId) throws MageException {
|
||||
return executeWithResult("getUsers", sessionId, new ListActionWithNullNegativeResult(), true);
|
||||
public List<UserView> adminGetUsers(String sessionId) throws MageException {
|
||||
return executeWithResult("adminGetUsers", sessionId, new GetUsersAction(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnectUser(final String sessionId, final String userSessionId) throws MageException {
|
||||
execute("disconnectUser", sessionId, () -> managerFactory.sessionManager().disconnectUser(sessionId, userSessionId));
|
||||
public void adminDisconnectUser(final String sessionId, final String userSessionId) throws MageException {
|
||||
execute("adminDisconnectUser", sessionId,
|
||||
() -> managerFactory.sessionManager().disconnectUser(sessionId, userSessionId),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void muteUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||
execute("muteUser", sessionId, () -> {
|
||||
public void adminMuteUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||
execute("adminMuteUser", sessionId, () -> {
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||
execute("lockUser", sessionId, () -> {
|
||||
public void adminLockUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||
execute("adminLockUser", sessionId, () -> {
|
||||
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) + '.');
|
||||
|
|
@ -1056,13 +1058,12 @@ public class MageServerImpl implements MageServer {
|
|||
managerFactory.sessionManager().disconnectUser(sessionId, user.getSessionId());
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivation(final String sessionId, final String userName, boolean active) throws MageException {
|
||||
execute("setActivation", sessionId, () -> {
|
||||
public void adminActivateUser(final String sessionId, final String userName, boolean active) throws MageException {
|
||||
execute("adminActivateUser", sessionId, () -> {
|
||||
AuthorizedUser authorizedUser = AuthorizedUserRepository.getInstance().getByName(userName);
|
||||
Optional<User> u = managerFactory.userManager().getUserByName(userName);
|
||||
if (u.isPresent()) {
|
||||
|
|
@ -1075,25 +1076,25 @@ public class MageServerImpl implements MageServer {
|
|||
User theUser = new User(managerFactory, userName, "localhost", authorizedUser);
|
||||
theUser.setActive(active);
|
||||
}
|
||||
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleActivation(final String sessionId, final String userName) throws MageException {
|
||||
execute("toggleActivation", sessionId, ()
|
||||
-> managerFactory.userManager().getUserByName(userName).ifPresent(user
|
||||
-> {
|
||||
public void adminToggleActivateUser(final String sessionId, final String userName) throws MageException {
|
||||
execute("adminToggleActivateUser", sessionId, () -> managerFactory.userManager().getUserByName(userName).ifPresent(user -> {
|
||||
user.setActive(!user.isActive());
|
||||
if (!user.isActive() && user.isConnected()) {
|
||||
managerFactory.sessionManager().disconnectUser(sessionId, user.getSessionId());
|
||||
}
|
||||
}));
|
||||
}), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endUserSession(final String sessionId, final String userSessionId) throws MageException {
|
||||
execute("endUserSession", sessionId, () -> managerFactory.sessionManager().endUserSession(sessionId, userSessionId));
|
||||
public void adminEndUserSession(final String sessionId, final String userSessionId) throws MageException {
|
||||
execute("adminEndUserSession", sessionId,
|
||||
() -> managerFactory.sessionManager().endUserSession(sessionId, userSessionId),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1104,22 +1105,22 @@ public class MageServerImpl implements MageServer {
|
|||
* @throws MageException
|
||||
*/
|
||||
@Override
|
||||
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
execute("removeTable", sessionId, () -> {
|
||||
public void adminTableRemove(final String sessionId, final UUID tableId) throws MageException {
|
||||
execute("adminTableRemove", sessionId, () -> {
|
||||
managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
managerFactory.tableManager().removeTable(userId, tableId);
|
||||
});
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerMessagesCompressed(String sessionId) throws MageException {
|
||||
return executeWithResult("getGameView", sessionId, new MyActionWithNullNegativeResult());
|
||||
public Object serverGetPromotionMessages(String sessionId) throws MageException {
|
||||
return executeWithResult("serverGetPromotionMessages", sessionId, new GetPromotionMessagesAction());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFeedbackMessage(final String sessionId, final String username, final String title, final String type, final String message, final String email) throws MageException {
|
||||
public void serverAddFeedbackMessage(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, ()
|
||||
-> managerFactory.sessionManager().getSession(sessionId).ifPresent(
|
||||
|
|
@ -1129,7 +1130,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendBroadcastMessage(final String sessionId, final String message) throws MageException {
|
||||
public void adminSendBroadcastMessage(final String sessionId, final String message) throws MageException {
|
||||
if (message != null) {
|
||||
execute("sendBroadcastMessage", sessionId, () -> {
|
||||
for (User user : managerFactory.userManager().getUsers()) {
|
||||
|
|
@ -1148,10 +1149,8 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
protected void execute(final String actionName, final String sessionId, final Action action, boolean checkAdminRights) throws MageException {
|
||||
if (checkAdminRights) {
|
||||
if (!managerFactory.sessionManager().isAdmin(sessionId)) {
|
||||
return;
|
||||
}
|
||||
if (checkAdminRights && !managerFactory.sessionManager().checkAdminAccess(sessionId)) {
|
||||
return;
|
||||
}
|
||||
execute(actionName, sessionId, action);
|
||||
}
|
||||
|
|
@ -1177,10 +1176,8 @@ 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 (!managerFactory.sessionManager().isAdmin(sessionId)) {
|
||||
return action.negativeResult();
|
||||
}
|
||||
if (checkAdminRights && !managerFactory.sessionManager().checkAdminAccess(sessionId)) {
|
||||
return action.negativeResult();
|
||||
}
|
||||
return executeWithResult(actionName, sessionId, action);
|
||||
}
|
||||
|
|
@ -1198,7 +1195,7 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ExpansionInfo> getMissingExpansionData(List<String> codes) {
|
||||
public List<ExpansionInfo> syncGetMissingExpansionData(List<String> codes) {
|
||||
List<ExpansionInfo> result = new ArrayList<>();
|
||||
for (ExpansionInfo expansionInfo : ExpansionRepository.instance.getAll()) {
|
||||
if (!codes.contains(expansionInfo.getCode())) {
|
||||
|
|
@ -1210,21 +1207,20 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<CardInfo> getMissingCardsData(List<String> classNames) {
|
||||
public List<CardInfo> syncGetMissingCardsData(List<String> classNames) {
|
||||
List<CardInfo> res = CardRepository.instance.getMissingCards(classNames);
|
||||
logger.info("Missing cards downloaded: " + res.size());
|
||||
return res;
|
||||
}
|
||||
|
||||
private static class MyActionWithNullNegativeResult extends ActionWithNullNegativeResult<Object> {
|
||||
|
||||
private static class GetPromotionMessagesAction extends ActionWithNullNegativeResult<Object> {
|
||||
@Override
|
||||
public Object execute() throws MageException {
|
||||
return CompressUtil.compress(ServerMessagesUtil.instance.getMessages());
|
||||
}
|
||||
}
|
||||
|
||||
private class ListActionWithNullNegativeResult extends ActionWithNullNegativeResult<List<UserView>> {
|
||||
private class GetUsersAction extends ActionWithNullNegativeResult<List<UserView>> {
|
||||
|
||||
@Override
|
||||
public List<UserView> execute() throws MageException {
|
||||
|
|
@ -1232,13 +1228,13 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
}
|
||||
|
||||
private class GameViewActionWithNullNegativeResult extends ActionWithNullNegativeResult<GameView> {
|
||||
private class GetGameViewAction extends ActionWithNullNegativeResult<GameView> {
|
||||
|
||||
private final String sessionId;
|
||||
private final UUID gameId;
|
||||
private final UUID playerId;
|
||||
|
||||
public GameViewActionWithNullNegativeResult(String sessionId, UUID gameId, UUID playerId) {
|
||||
public GetGameViewAction(String sessionId, UUID gameId, UUID playerId) {
|
||||
this.sessionId = sessionId;
|
||||
this.gameId = gameId;
|
||||
this.playerId = playerId;
|
||||
|
|
@ -1257,12 +1253,12 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
}
|
||||
|
||||
private class MyActionWithBooleanResult extends ActionWithBooleanResult {
|
||||
private class WatchTournamentTableAction extends ActionWithBooleanResult {
|
||||
|
||||
private final String sessionId;
|
||||
private final UUID tableId;
|
||||
|
||||
public MyActionWithBooleanResult(String sessionId, UUID tableId) {
|
||||
public WatchTournamentTableAction(String sessionId, UUID tableId) {
|
||||
this.sessionId = sessionId;
|
||||
this.tableId = tableId;
|
||||
}
|
||||
|
|
@ -1279,14 +1275,14 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
}
|
||||
|
||||
private class DraftPickViewActionWithNullNegativeResult extends ActionWithNullNegativeResult<DraftPickView> {
|
||||
private class SendCardPickAction extends ActionWithNullNegativeResult<DraftPickView> {
|
||||
|
||||
private final String sessionId;
|
||||
private final UUID draftId;
|
||||
private final UUID cardPick;
|
||||
private final Set<UUID> hiddenCards;
|
||||
|
||||
public DraftPickViewActionWithNullNegativeResult(String sessionId, UUID draftId, UUID cardPick, Set<UUID> hiddenCards) {
|
||||
public SendCardPickAction(String sessionId, UUID draftId, UUID cardPick, Set<UUID> hiddenCards) {
|
||||
this.sessionId = sessionId;
|
||||
this.draftId = draftId;
|
||||
this.cardPick = cardPick;
|
||||
|
|
@ -1305,13 +1301,13 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
}
|
||||
|
||||
private class MyActionWithTableViewResult extends ActionWithTableViewResult {
|
||||
private class CreateTableAction extends ActionWithTableViewResult {
|
||||
|
||||
private final String sessionId;
|
||||
private final MatchOptions options;
|
||||
private final UUID roomId;
|
||||
|
||||
public MyActionWithTableViewResult(String sessionId, MatchOptions options, UUID roomId) {
|
||||
public CreateTableAction(String sessionId, MatchOptions options, UUID roomId) {
|
||||
this.sessionId = sessionId;
|
||||
this.options = options;
|
||||
this.roomId = roomId;
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ public final class Main {
|
|||
try {
|
||||
MageServer testServer = (MageServer) TransporterClient.createTransporterClient(serverLocator.getLocatorURI(), MageServer.class, metadata);
|
||||
if (testServer != null) {
|
||||
testServer.getServerState();
|
||||
testServer.serverGetState();
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class SessionManagerImpl implements SessionManager {
|
|||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
session.connectAdmin();
|
||||
logger.info("Admin connected from " + session.getHost());
|
||||
logger.warn("Admin connected from " + session.getHost());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -155,19 +155,20 @@ public class SessionManagerImpl implements SessionManager {
|
|||
*/
|
||||
@Override
|
||||
public void disconnectUser(String sessionId, String userSessionId) {
|
||||
if (isAdmin(sessionId)) {
|
||||
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.");
|
||||
admin.showUserMessage("Admin action", "User" + user.getName() + " was disconnected.");
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
} else {
|
||||
admin.showUserMessage("Admin operation", "User with sessionId " + userSessionId + " could not be found!");
|
||||
}
|
||||
});
|
||||
if (!checkAdminAccess(sessionId)) {
|
||||
return;
|
||||
}
|
||||
getUserFromSession(sessionId).ifPresent(admin -> {
|
||||
Optional<User> u = getUserFromSession(userSessionId);
|
||||
if (u.isPresent()) {
|
||||
User user = u.get();
|
||||
user.showUserMessage("Admin action", "Your session was disconnected by admin");
|
||||
admin.showUserMessage("Admin result", "User " + user.getName() + " was disconnected");
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
} else {
|
||||
admin.showUserMessage("Admin result", "User with sessionId " + userSessionId + " could not be found");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<User> getUserFromSession(String sessionId) {
|
||||
|
|
@ -178,15 +179,27 @@ public class SessionManagerImpl implements SessionManager {
|
|||
|
||||
@Override
|
||||
public void endUserSession(String sessionId, String userSessionId) {
|
||||
if (isAdmin(sessionId)) {
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
if (!checkAdminAccess(sessionId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdmin(String sessionId) {
|
||||
return getSession(sessionId).map(Session::isAdmin).orElse(false);
|
||||
|
||||
public boolean checkAdminAccess(String sessionId) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session == null) {
|
||||
logger.error("Wrong admin access with unknown session: " + sessionId, new Throwable());
|
||||
} else if (!session.isAdmin()) {
|
||||
String info = String.format("sessionId %s for userId %s at %s",
|
||||
session.getId(),
|
||||
session.getUserId(),
|
||||
session.getHost()
|
||||
);
|
||||
logger.error("Wrong admin access with user session: " + info, new Throwable());
|
||||
}
|
||||
return session != null && session.isAdmin();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -271,9 +271,9 @@ public class User {
|
|||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_TOURNAMENT, tournamentId));
|
||||
}
|
||||
|
||||
public void showUserMessage(final String titel, String message) {
|
||||
public void showUserMessage(final String title, String message) {
|
||||
List<String> messageData = new LinkedList<>();
|
||||
messageData.add(titel);
|
||||
messageData.add(title);
|
||||
messageData.add(message);
|
||||
fireCallback(new ClientCallback(ClientCallbackMethod.SHOW_USERMESSAGE, null, messageData));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class DraftController {
|
|||
(Listener<PlayerQueryEvent>) event -> {
|
||||
try {
|
||||
switch (event.getQueryType()) {
|
||||
case PICK_CARD:
|
||||
case DRAFT_PICK_CARD:
|
||||
pickCard(event.getPlayerId(), event.getMax());
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,6 +229,12 @@ public class GameController implements GameCallback {
|
|||
case PERSONAL_MESSAGE:
|
||||
informPersonal(event.getPlayerId(), event.getMessage());
|
||||
break;
|
||||
case TOURNAMENT_CONSTRUCT:
|
||||
case DRAFT_PICK_CARD:
|
||||
// tournament and draft events, impossible to catch it here
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown game event: " + event.getQueryType());
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("Player event listener error ", ex);
|
||||
|
|
@ -771,15 +777,14 @@ public class GameController implements GameCallback {
|
|||
|
||||
public void sendPlayerBoolean(UUID userId, final Boolean data) {
|
||||
sendMessage(userId, playerId -> getGameSession(playerId).sendPlayerBoolean(data));
|
||||
|
||||
}
|
||||
|
||||
public void sendPlayerInteger(UUID userId, final Integer data) {
|
||||
sendMessage(userId, playerId -> getGameSession(playerId).sendPlayerInteger(data));
|
||||
|
||||
}
|
||||
|
||||
private synchronized void updateGame() {
|
||||
private void updatePriorityTimers() {
|
||||
// update player timers to actual values
|
||||
if (!timers.isEmpty()) {
|
||||
for (Player player : game.getState().getPlayers().values()) {
|
||||
PriorityTimer timer = timers.get(player.getId());
|
||||
|
|
@ -788,6 +793,10 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void updateGame() {
|
||||
updatePriorityTimers();
|
||||
for (final GameSessionPlayer gameSession : getGameSessions()) {
|
||||
gameSession.update();
|
||||
}
|
||||
|
|
@ -941,7 +950,7 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
|
||||
public GameView getGameView(UUID playerId) {
|
||||
public synchronized GameView getGameView(UUID playerId) {
|
||||
return getGameSession(playerId).getGameView();
|
||||
}
|
||||
|
||||
|
|
@ -1116,14 +1125,13 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
|
||||
private GameSessionPlayer getGameSession(UUID playerId) {
|
||||
if (!timers.isEmpty()) {
|
||||
Player player = game.getState().getPlayer(playerId);
|
||||
PriorityTimer timer = timers.get(playerId);
|
||||
if (timer != null) {
|
||||
//logger.warn("Timer Player " + player.getName()+ " " + player.getPriorityTimeLeft() + " Timer: " + timer.getCount());
|
||||
player.setPriorityTimeLeft(timer.getCount());
|
||||
}
|
||||
}
|
||||
// TODO: check parent callers - there are possible problems with sync, can be related to broken "fix" logs too
|
||||
// It modify players data, but:
|
||||
// * some sendXXX methods calls without synchronized (getGameSession can be in read mode?)
|
||||
// * some informXXX methods calls with synchronized (users must get actual data, so keep write mode and add synchronized?)
|
||||
// find actual timers before send data
|
||||
updatePriorityTimers();
|
||||
|
||||
return gameSessions.get(playerId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import javax.annotation.Nonnull;
|
|||
import java.util.Optional;
|
||||
|
||||
public interface SessionManager {
|
||||
|
||||
Optional<Session> getSession(@Nonnull String sessionId);
|
||||
|
||||
void createSession(String sessionId, InvokerCallbackHandler callbackHandler);
|
||||
|
|
@ -31,7 +32,7 @@ public interface SessionManager {
|
|||
|
||||
void endUserSession(String sessionId, String userSessionId);
|
||||
|
||||
boolean isAdmin(String sessionId);
|
||||
boolean checkAdminAccess(String sessionId);
|
||||
|
||||
boolean isValidSession(@Nonnull String sessionId);
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ public class TournamentController {
|
|||
(Listener<PlayerQueryEvent>) event -> {
|
||||
try {
|
||||
switch (event.getQueryType()) {
|
||||
case CONSTRUCT:
|
||||
case TOURNAMENT_CONSTRUCT:
|
||||
construct(event.getPlayerId(), event.getMax());
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -548,7 +548,7 @@ public class LoadTest {
|
|||
this.client = new SimpleMageClient(joinGameChat, logsPrefix, TEST_SHOW_GAME_LOGS_AS_HTML);
|
||||
this.session = new SessionImpl(this.client);
|
||||
|
||||
this.session.connect(this.connection);
|
||||
this.session.connectStart(this.connection);
|
||||
this.client.setSession(this.session);
|
||||
this.roomID = this.session.getMainRoomId();
|
||||
|
||||
|
|
@ -607,7 +607,7 @@ public class LoadTest {
|
|||
}
|
||||
|
||||
public void disconnect() {
|
||||
this.session.disconnect(false);
|
||||
this.session.connectStop(false);
|
||||
}
|
||||
|
||||
public void concede() {
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
|
|||
PLAY_X_MANA,
|
||||
AMOUNT,
|
||||
MULTI_AMOUNT,
|
||||
PICK_CARD,
|
||||
CONSTRUCT,
|
||||
DRAFT_PICK_CARD,
|
||||
TOURNAMENT_CONSTRUCT,
|
||||
CHOOSE_PILE,
|
||||
PERSONAL_MESSAGE
|
||||
}
|
||||
|
|
@ -224,11 +224,11 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
|
|||
}
|
||||
|
||||
public static PlayerQueryEvent pickCard(UUID playerId, String message, List<Card> booster, int time) {
|
||||
return new PlayerQueryEvent(playerId, message, booster, QueryType.PICK_CARD, time);
|
||||
return new PlayerQueryEvent(playerId, message, booster, QueryType.DRAFT_PICK_CARD, time);
|
||||
}
|
||||
|
||||
public static PlayerQueryEvent construct(UUID playerId, String message, int time) {
|
||||
return new PlayerQueryEvent(playerId, message, QueryType.CONSTRUCT, time);
|
||||
return new PlayerQueryEvent(playerId, message, QueryType.TOURNAMENT_CONSTRUCT, time);
|
||||
}
|
||||
|
||||
public static PlayerQueryEvent informPersonal(UUID playerId, String message) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue