refactor: improved and reorganized client-server api, added additional logs, fixed miss admin checks for some commands

This commit is contained in:
Oleg Agafonov 2023-11-22 23:52:00 +04:00
parent e43e918c67
commit 75958e3710
21 changed files with 371 additions and 364 deletions

View file

@ -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 {

View file

@ -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);
boolean ping(String sessionId, String pingInfo) throws MageException;
void serverAddFeedbackMessage(String sessionId, String username, String title, String type, String message, String email) throws MageException;
// user methods
boolean setUserData(String userName, String sessionId, UserData userData, String clientVersion, String userIdStr) throws MageException;
Object serverGetPromotionMessages(String sessionId) throws MageException;
void sendFeedbackMessage(String sessionId, String username, String title, String type, String message, String email) throws MageException;
// 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);
// server state methods
ServerState getServerState() throws MageException;
ServerState serverGetState() throws MageException;
List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException;
UUID serverGetMainRoomId() throws MageException;
List<MatchView> getFinishedMatches(UUID roomId) throws MageException;
List<RoomUsersView> roomGetUsers(UUID roomId) throws MageException;
Object getServerMessagesCompressed(String sessionId) throws MageException; // messages of the day
List<MatchView> roomGetFinishedMatches(UUID roomId) throws MageException;
// ping - extends session
boolean ping(String sessionId, String pingInfo) throws MageException;
TableView roomCreateTable(String sessionId, UUID roomId, MatchOptions matchOptions) throws MageException;
//table methods
TableView createTable(String sessionId, UUID roomId, MatchOptions matchOptions) throws MageException;
TableView roomCreateTournament(String sessionId, UUID roomId, TournamentOptions tournamentOptions) throws MageException;
TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions tournamentOptions) throws MageException;
boolean roomJoinTable(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
boolean roomJoinTournament(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws MageException, GameException;
boolean deckSubmit(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
void deckSave(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
void updateDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
boolean roomWatchTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
boolean roomWatchTournament(String sessionId, UUID tableId) throws MageException;
boolean watchTournamentTable(String sessionId, UUID tableId) throws MageException;
boolean roomLeaveTableOrTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
boolean leaveTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
void tableSwapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws MageException;
void swapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws MageException;
void tableRemove(String sessionId, UUID roomId, UUID tableId) throws MageException;
void removeTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
boolean tableIsOwner(String sessionId, UUID roomId, UUID tableId) throws MageException;
boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException;
TableView roomGetTableById(UUID roomId, UUID tableId) throws MageException;
TableView getTable(UUID roomId, UUID tableId) throws MageException;
List<TableView> roomGetAllTables(UUID roomId) throws MageException;
List<TableView> getTables(UUID roomId) throws MageException;
void chatSendMessage(UUID chatId, String userName, String message) throws MageException;
//chat methods
void sendChatMessage(UUID chatId, String userName, String message) throws MageException;
void chatJoin(UUID chatId, String sessionId, String userName) throws MageException;
void joinChat(UUID chatId, String sessionId, String userName) throws MageException;
void chatLeave(UUID chatId, String sessionId) throws MageException;
void leaveChat(UUID chatId, String sessionId) throws MageException;
UUID chatFindByGame(UUID gameId) throws MageException;
UUID getTableChatId(UUID tableId) throws MageException;
UUID chatFindByTable(UUID tableId) throws MageException;
UUID getGameChatId(UUID gameId) throws MageException;
UUID chatFindByTournament(UUID tournamentId) throws MageException;
UUID getRoomChatId(UUID roomId) throws MageException;
UUID chatFindByRoom(UUID roomId) throws MageException;
UUID getTournamentChatId(UUID tournamentId) throws MageException;
boolean matchStart(String sessionId, UUID roomId, UUID tableId) throws MageException;
//room methods
UUID getMainRoomId() throws MageException;
void matchQuit(UUID gameId, String sessionId) throws MageException;
//game methods
boolean startMatch(String sessionId, UUID roomId, UUID tableId) throws MageException;
void gameJoin(UUID gameId, String sessionId) throws MageException;
void joinGame(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 watchGame(UUID gameId, String sessionId) throws MageException;
boolean gameWatchStart(UUID gameId, String sessionId) throws MageException;
void stopWatching(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;
}

View file

@ -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);
}

View file

@ -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 {

View file

@ -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);
}