diff --git a/Mage.Client/src/main/java/mage/client/remote/Session.java b/Mage.Client/src/main/java/mage/client/remote/Session.java index d68bcf17c74..c406d1c6c26 100644 --- a/Mage.Client/src/main/java/mage/client/remote/Session.java +++ b/Mage.Client/src/main/java/mage/client/remote/Session.java @@ -37,6 +37,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -53,11 +54,14 @@ import mage.remote.method.*; import mage.client.tournament.TournamentPanel; import mage.game.GameException; import mage.MageException; +import mage.cards.decks.InvalidDeckException; import mage.game.match.MatchOptions; import mage.game.tournament.TournamentOptions; import mage.interfaces.ServerState; import mage.interfaces.callback.CallbackClientDaemon; import mage.remote.Connection; +import mage.remote.RMIClientDaemon; +import mage.remote.RemoteMethodCallQueue; import mage.remote.ServerCache; import mage.remote.ServerUnavailable; import mage.utils.MageVersion; @@ -92,12 +96,15 @@ public class Session { private Map drafts = new HashMap(); private Map tournaments = new HashMap(); private CallbackClientDaemon callbackDaemon; + private RMIClientDaemon rmiDaemon; + private RemoteMethodCallQueue q = new RemoteMethodCallQueue(); private ScheduledFuture future; private MageUI ui = new MageUI(); private Connection connection; public Session(MageFrame frame) { this.frame = frame; + rmiDaemon = new RMIClientDaemon(q); } public synchronized boolean connect(Connection connection) { @@ -190,7 +197,8 @@ public class Session { public boolean ping() { Ping method = new Ping(connection, sessionId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -201,13 +209,21 @@ public class Session { private UUID registerClient(String userName, UUID clientId, MageVersion version) throws MageException, ServerUnavailable { RegisterClient method = new RegisterClient(connection, userName, clientId, version); - return method.makeCall(); + try { + q.callMethod(method); + return method.getReturnVal(); + } catch (ServerUnavailable ex) { + handleServerUnavailable(ex); + } catch (MageException ex) { + logger.fatal("registerClient error", ex); + } + return null; } private void deregisterClient() throws MageException { DeregisterClient method = new DeregisterClient(connection, sessionId); try { - method.makeCall(); + q.callMethod(method); } catch (ServerUnavailable ex) { logger.fatal("server unavailable - ", ex); } @@ -216,7 +232,8 @@ public class Session { private ServerState getServerState() { GetServerState method = new GetServerState(connection); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -281,7 +298,8 @@ public class Session { public UUID getMainRoomId() { GetMainRoomId method = new GetMainRoomId(connection); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -293,7 +311,8 @@ public class Session { public UUID getRoomChatId(UUID roomId) { GetRoomChatId method = new GetRoomChatId(connection, roomId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -305,7 +324,8 @@ public class Session { public UUID getTableChatId(UUID tableId) { GetTableChatId method = new GetTableChatId(connection, tableId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -317,7 +337,8 @@ public class Session { public UUID getGameChatId(UUID gameId) { GetGameChatId method = new GetGameChatId(connection, gameId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -329,7 +350,8 @@ public class Session { public TableView getTable(UUID roomId, UUID tableId) { GetTable method = new GetTable(connection, roomId, tableId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -341,7 +363,8 @@ public class Session { public boolean watchTable(UUID roomId, UUID tableId) { WatchTable method = new WatchTable(connection, sessionId, roomId, tableId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -353,11 +376,14 @@ public class Session { public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList) { JoinTable method = new JoinTable(connection, sessionId, roomId, tableId, playerName, playerType, skill, deckList); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (GameException ex) { handleGameException(ex); + } catch (InvalidDeckException ex) { + handleInvalidDeckException(ex); } catch (MageException ex) { logger.fatal("JoinTable error", ex); } @@ -367,7 +393,8 @@ public class Session { public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill) { JoinTournamentTable method = new JoinTournamentTable(connection, sessionId, roomId, tableId, playerName, playerType, skill); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (GameException ex) { @@ -381,7 +408,8 @@ public class Session { public Collection getTables(UUID roomId) throws MageRemoteException { GetTables method = new GetTables(connection, roomId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -393,7 +421,8 @@ public class Session { public Collection getConnectedPlayers(UUID roomId) throws MageRemoteException { GetConnectedPlayers method = new GetConnectedPlayers(connection, roomId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -405,7 +434,8 @@ public class Session { public TournamentView getTournament(UUID tournamentId) throws MageRemoteException { GetTournament method = new GetTournament(connection, tournamentId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -417,7 +447,8 @@ public class Session { public UUID getTournamentChatId(UUID tournamentId) { GetTournamentChatId method = new GetTournamentChatId(connection, tournamentId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -429,7 +460,7 @@ public class Session { public boolean sendPlayerUUID(UUID gameId, UUID data) { SendPlayerUUID method = new SendPlayerUUID(connection, sessionId, gameId, data); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -442,7 +473,7 @@ public class Session { public boolean sendPlayerBoolean(UUID gameId, boolean data) { SendPlayerBoolean method = new SendPlayerBoolean(connection, sessionId, gameId, data); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -455,7 +486,7 @@ public class Session { public boolean sendPlayerInteger(UUID gameId, int data) { SendPlayerInteger method = new SendPlayerInteger(connection, sessionId, gameId, data); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -468,7 +499,7 @@ public class Session { public boolean sendPlayerString(UUID gameId, String data) { SendPlayerString method = new SendPlayerString(connection, sessionId, gameId, data); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -481,7 +512,8 @@ public class Session { public DraftPickView sendCardPick(UUID draftId, UUID cardId) { SendCardPick method = new SendCardPick(connection, sessionId, draftId, cardId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -493,7 +525,7 @@ public class Session { public boolean joinChat(UUID chatId, ChatPanel chat) { JoinChat method = new JoinChat(connection, sessionId, chatId, userName); try { - method.makeCall(); + q.callMethod(method); chats.put(chatId, chat); return true; } catch (ServerUnavailable ex) { @@ -507,7 +539,7 @@ public class Session { public boolean leaveChat(UUID chatId) { LeaveChat method = new LeaveChat(connection, sessionId, chatId); try { - method.makeCall(); + q.callMethod(method); chats.remove(chatId); return true; } catch (ServerUnavailable ex) { @@ -521,7 +553,7 @@ public class Session { public boolean sendChatMessage(UUID chatId, String message) { SendChatMessage method = new SendChatMessage(connection, chatId, message, userName); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -534,7 +566,7 @@ public class Session { public boolean joinGame(UUID gameId) { JoinGame method = new JoinGame(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -547,7 +579,7 @@ public class Session { public boolean joinDraft(UUID draftId) { JoinDraft method = new JoinDraft(connection, sessionId, draftId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -560,7 +592,7 @@ public class Session { public boolean joinTournament(UUID tournamentId) { JoinTournament method = new JoinTournament(connection, sessionId, tournamentId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -573,7 +605,7 @@ public class Session { public boolean watchGame(UUID gameId) { WatchGame method = new WatchGame(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -586,7 +618,7 @@ public class Session { public boolean replayGame(UUID gameId) { ReplayGame method = new ReplayGame(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -599,7 +631,8 @@ public class Session { public TableView createTable(UUID roomId, MatchOptions matchOptions) { CreateTable method = new CreateTable(connection, sessionId, roomId, matchOptions); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -611,7 +644,8 @@ public class Session { public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) { CreateTournamentTable method = new CreateTournamentTable(connection, sessionId, roomId, tournamentOptions); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -623,7 +657,8 @@ public class Session { public boolean isTableOwner(UUID roomId, UUID tableId) { IsTableOwner method = new IsTableOwner(connection, sessionId, roomId, tableId); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); } catch (MageException ex) { @@ -635,7 +670,7 @@ public class Session { public boolean removeTable(UUID roomId, UUID tableId) { RemoveTable method = new RemoveTable(connection, sessionId, roomId, tableId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -648,7 +683,7 @@ public class Session { public boolean swapSeats(UUID roomId, UUID tableId, int seatNum1, int seatNum2) { SwapSeats method = new SwapSeats(connection, sessionId, roomId, tableId, seatNum1, seatNum2); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -661,7 +696,7 @@ public class Session { public boolean leaveTable(UUID roomId, UUID tableId) { LeaveTable method = new LeaveTable(connection, sessionId, roomId, tableId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -674,7 +709,7 @@ public class Session { public boolean startGame(UUID roomId, UUID tableId) { StartGame method = new StartGame(connection, sessionId, roomId, tableId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -687,7 +722,7 @@ public class Session { public boolean startTournament(UUID roomId, UUID tableId) { StartTournament method = new StartTournament(connection, sessionId, roomId, tableId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -700,7 +735,7 @@ public class Session { public boolean startChallenge(UUID roomId, UUID tableId, UUID challengeId) { StartChallenge method = new StartChallenge(connection, sessionId, roomId, tableId, challengeId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -713,9 +748,12 @@ public class Session { public boolean submitDeck(UUID tableId, DeckCardLists deck) { SubmitDeck method = new SubmitDeck(connection, sessionId, tableId, deck); try { - return method.makeCall(); + q.callMethod(method); + return method.getReturnVal(); } catch (ServerUnavailable ex) { handleServerUnavailable(ex); + } catch (InvalidDeckException ex) { + handleInvalidDeckException(ex); } catch (GameException ex) { handleGameException(ex); } catch (MageException ex) { @@ -727,7 +765,7 @@ public class Session { public boolean concedeGame(UUID gameId) { ConcedeGame method = new ConcedeGame(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -740,7 +778,7 @@ public class Session { public boolean stopWatching(UUID gameId) { StopWatching method = new StopWatching(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -753,7 +791,7 @@ public class Session { public boolean startReplay(UUID gameId) { StartReplay method = new StartReplay(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -766,7 +804,7 @@ public class Session { public boolean stopReplay(UUID gameId) { StopReplay method = new StopReplay(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -779,7 +817,7 @@ public class Session { public boolean nextPlay(UUID gameId) { NextPlay method = new NextPlay(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -792,7 +830,7 @@ public class Session { public boolean previousPlay(UUID gameId) { PreviousPlay method = new PreviousPlay(connection, sessionId, gameId); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -805,7 +843,7 @@ public class Session { public boolean cheat(UUID gameId, UUID playerId, DeckCardLists deckList) { Cheat method = new Cheat(connection, sessionId, gameId, playerId, deckList); try { - method.makeCall(); + q.callMethod(method); return true; } catch (ServerUnavailable ex) { handleServerUnavailable(ex); @@ -835,6 +873,15 @@ public class Session { JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } + private void handleInvalidDeckException(InvalidDeckException ex) { + StringBuilder sbMessage = new StringBuilder(); + logger.warn(ex.getMessage()); + sbMessage.append(ex.getMessage()).append("\n"); + for (Entry entry: ex.getInvalid().entrySet()) { + sbMessage.append(entry.getKey()).append(":").append(entry.getValue()).append("\n"); + } + JOptionPane.showMessageDialog(MageFrame.getDesktop(), sbMessage.toString(), "Invalid Deck", JOptionPane.ERROR_MESSAGE); + } public String getUserName() { return userName; diff --git a/Mage.Common/src/mage/interfaces/callback/CallbackClientDaemon.java b/Mage.Common/src/mage/interfaces/callback/CallbackClientDaemon.java index ab8d1282b57..f1da51619bc 100644 --- a/Mage.Common/src/mage/interfaces/callback/CallbackClientDaemon.java +++ b/Mage.Common/src/mage/interfaces/callback/CallbackClientDaemon.java @@ -64,7 +64,7 @@ public class CallbackClientDaemon extends Thread { while(!end) { try { Callback callbackMethod = new Callback(connection, id); - final ClientCallback callback = callbackMethod.makeCall(); + final ClientCallback callback = callbackMethod.makeDirectCall(); Ack ackMethod = new Ack(connection, id, callback.getMessageId()); ackMethod.makeCall(); callbackExecutor.submit( diff --git a/Mage.Common/src/mage/interfaces/callback/CallbackException.java b/Mage.Common/src/mage/interfaces/callback/CallbackException.java index 1d0b973602c..c388f3cfe61 100644 --- a/Mage.Common/src/mage/interfaces/callback/CallbackException.java +++ b/Mage.Common/src/mage/interfaces/callback/CallbackException.java @@ -27,11 +27,13 @@ */ package mage.interfaces.callback; +import mage.MageException; + /** * * @author BetaSteward_at_googlemail.com */ -public class CallbackException extends Exception { +public class CallbackException extends MageException { public CallbackException(String message) { super(message); diff --git a/Mage.Common/src/mage/remote/AbstractRemoteMethodCall.java b/Mage.Common/src/mage/remote/AbstractRemoteMethodCall.java index 1eb97d7ef70..6116a83bfda 100644 --- a/Mage.Common/src/mage/remote/AbstractRemoteMethodCall.java +++ b/Mage.Common/src/mage/remote/AbstractRemoteMethodCall.java @@ -37,14 +37,15 @@ package mage.remote; * @author BetaSteward_at_googlemail.com */ import java.rmi.*; +import mage.MageException; import mage.interfaces.Server; import org.apache.log4j.Logger; -public abstract class AbstractRemoteMethodCall { +public abstract class AbstractRemoteMethodCall { private final static Logger logger = Logger.getLogger(AbstractRemoteMethodCall.class); - public T makeCall() throws ServerUnavailable, E { + public T makeCall() throws ServerUnavailable, MageException { RetryStrategy strategy = getRetryStrategy(); while (strategy.shouldRetry()) { Server server = getServer(); @@ -84,7 +85,7 @@ public abstract class AbstractRemoteMethodCall { performRemoteCall is a template method which actually makes the remote method invocation. */ - protected abstract T performRemoteCall(Server server) throws RemoteException, E; + protected abstract T performRemoteCall(Server server) throws RemoteException, MageException; protected RetryStrategy getRetryStrategy() { diff --git a/Mage.Common/src/mage/remote/RMIClientDaemon.java b/Mage.Common/src/mage/remote/RMIClientDaemon.java new file mode 100644 index 00000000000..9ab08294f89 --- /dev/null +++ b/Mage.Common/src/mage/remote/RMIClientDaemon.java @@ -0,0 +1,62 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.remote; + +import java.util.concurrent.LinkedBlockingQueue; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class RMIClientDaemon extends Thread { + + private final RemoteMethodCallQueue q; + + public RMIClientDaemon(RemoteMethodCallQueue q) { + this.q = q; + setDaemon(true); + start(); + } + + @Override + public void run() { + try { + while (true) { + RemoteMethodCall call = q.take(); + call.makeCall(); + synchronized (call) { + call.notify(); + } + } + } + catch (InterruptedException ex) { + + } + } +} diff --git a/Mage.Common/src/mage/remote/RemoteMethodCall.java b/Mage.Common/src/mage/remote/RemoteMethodCall.java index 177b1841175..60cec5e8e8e 100644 --- a/Mage.Common/src/mage/remote/RemoteMethodCall.java +++ b/Mage.Common/src/mage/remote/RemoteMethodCall.java @@ -28,6 +28,7 @@ package mage.remote; import java.rmi.*; +import mage.MageException; import mage.interfaces.Server; import org.apache.log4j.Logger; @@ -41,19 +42,40 @@ import org.apache.log4j.Logger; * @author BetaSteward_at_googlemail.com */ -public abstract class RemoteMethodCall extends AbstractRemoteMethodCall { +public abstract class RemoteMethodCall extends AbstractRemoteMethodCall { protected final static Logger logger = Logger.getLogger(RemoteMethodCall.class); protected Connection connection; + protected T returnVal; + protected boolean exception = false; + protected MageException ex; public RemoteMethodCall(Connection connection){ this.connection = connection; } @Override - public T makeCall() throws ServerUnavailable, E { - T returnValue = null; + public T makeCall() { + returnVal = null; + try { + returnVal = super.makeCall(); + } + catch (ServerUnavailable e) { + this.exception = true; + } + catch (MageException e) { + this.exception = true; + this.ex = e; + } + finally { + ServerCache.noLongerUsingServer(connection); + } + return returnVal; + } + + public T makeDirectCall() throws ServerUnavailable, MageException { + T returnValue = null; try { returnValue = super.makeCall(); } @@ -78,4 +100,16 @@ public abstract class RemoteMethodCall extends AbstractR protected void remoteExceptionOccured(RemoteException remoteException) { ServerCache.removeServerFromCache(connection); } + + public T getReturnVal() { + return returnVal; + } + + public MageException getException() { + return ex; + } + + public boolean isException() { + return exception; + } } diff --git a/Mage.Common/src/mage/remote/RemoteMethodCallQueue.java b/Mage.Common/src/mage/remote/RemoteMethodCallQueue.java new file mode 100644 index 00000000000..54a316dc1bd --- /dev/null +++ b/Mage.Common/src/mage/remote/RemoteMethodCallQueue.java @@ -0,0 +1,57 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.remote; + +import java.util.concurrent.LinkedBlockingQueue; +import mage.MageException; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class RemoteMethodCallQueue extends LinkedBlockingQueue { + + public void callMethod(RemoteMethodCall call) throws ServerUnavailable, MageException { + synchronized (call) { + try { + this.put(call); + call.wait(); + if (call.isException()) { + if (call.getException() != null) + throw call.getException(); + else + throw new ServerUnavailable(); + } + } catch (InterruptedException ex) { + + } + } + } + +} diff --git a/Mage.Common/src/mage/remote/RetryStrategy.java b/Mage.Common/src/mage/remote/RetryStrategy.java index 58274d402c5..20e0f3565ff 100644 --- a/Mage.Common/src/mage/remote/RetryStrategy.java +++ b/Mage.Common/src/mage/remote/RetryStrategy.java @@ -27,6 +27,8 @@ */ package mage.remote; +import org.apache.log4j.Logger; + /** * Adopted from the code by William Grosso, author of Java RMI * 10/17/2001 @@ -39,6 +41,7 @@ package mage.remote; public abstract class RetryStrategy { public static final int DEFAULT_NUMBER_OF_RETRIES = 3; private int _numberOfTriesLeft; + private final static Logger logger = Logger.getLogger(RetryStrategy.class); public RetryStrategy() { this(DEFAULT_NUMBER_OF_RETRIES); @@ -64,6 +67,7 @@ public abstract class RetryStrategy { private void waitUntilNextTry() { long timeToWait = getTimeToWait(); + logger.warn("Error calling server, waiting " + timeToWait + "ms before retrying"); try { Thread.sleep(timeToWait ); } diff --git a/Mage.Common/src/mage/remote/method/Ack.java b/Mage.Common/src/mage/remote/method/Ack.java index 4f0bae2d572..4c6cc32cfbe 100644 --- a/Mage.Common/src/mage/remote/method/Ack.java +++ b/Mage.Common/src/mage/remote/method/Ack.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class Ack extends RemoteMethodCall { +public class Ack extends RemoteMethodCall { private UUID sessionId; private int messageId; diff --git a/Mage.Common/src/mage/remote/method/Callback.java b/Mage.Common/src/mage/remote/method/Callback.java index 69efea0cd92..ebb860ad1c2 100644 --- a/Mage.Common/src/mage/remote/method/Callback.java +++ b/Mage.Common/src/mage/remote/method/Callback.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class Callback extends RemoteMethodCall { +public class Callback extends RemoteMethodCall { private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/Cheat.java b/Mage.Common/src/mage/remote/method/Cheat.java index d643174aca8..008162e9f82 100644 --- a/Mage.Common/src/mage/remote/method/Cheat.java +++ b/Mage.Common/src/mage/remote/method/Cheat.java @@ -40,7 +40,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class Cheat extends RemoteMethodCall { +public class Cheat extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/ConcedeGame.java b/Mage.Common/src/mage/remote/method/ConcedeGame.java index 2913061b0b4..2d7844bc06d 100644 --- a/Mage.Common/src/mage/remote/method/ConcedeGame.java +++ b/Mage.Common/src/mage/remote/method/ConcedeGame.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class ConcedeGame extends RemoteMethodCall { +public class ConcedeGame extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/CreateTable.java b/Mage.Common/src/mage/remote/method/CreateTable.java index 09ef9d06c14..6cafce13a30 100644 --- a/Mage.Common/src/mage/remote/method/CreateTable.java +++ b/Mage.Common/src/mage/remote/method/CreateTable.java @@ -40,7 +40,7 @@ import mage.view.TableView; * * @author BetaSteward_at_googlemail.com */ -public class CreateTable extends RemoteMethodCall { +public class CreateTable extends RemoteMethodCall { private UUID roomId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/CreateTournamentTable.java b/Mage.Common/src/mage/remote/method/CreateTournamentTable.java index f3b0ea13397..d799e481f96 100644 --- a/Mage.Common/src/mage/remote/method/CreateTournamentTable.java +++ b/Mage.Common/src/mage/remote/method/CreateTournamentTable.java @@ -40,7 +40,7 @@ import mage.view.TableView; * * @author BetaSteward_at_googlemail.com */ -public class CreateTournamentTable extends RemoteMethodCall { +public class CreateTournamentTable extends RemoteMethodCall { private UUID roomId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/DeregisterClient.java b/Mage.Common/src/mage/remote/method/DeregisterClient.java index 84ec4427f6a..183555a9b89 100644 --- a/Mage.Common/src/mage/remote/method/DeregisterClient.java +++ b/Mage.Common/src/mage/remote/method/DeregisterClient.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class DeregisterClient extends RemoteMethodCall { +public class DeregisterClient extends RemoteMethodCall { private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/GetConnectedPlayers.java b/Mage.Common/src/mage/remote/method/GetConnectedPlayers.java index cf9143e3ca2..330bfcb1996 100644 --- a/Mage.Common/src/mage/remote/method/GetConnectedPlayers.java +++ b/Mage.Common/src/mage/remote/method/GetConnectedPlayers.java @@ -40,7 +40,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class GetConnectedPlayers extends RemoteMethodCall, MageException> { +public class GetConnectedPlayers extends RemoteMethodCall> { private UUID roomId; diff --git a/Mage.Common/src/mage/remote/method/GetGameChatId.java b/Mage.Common/src/mage/remote/method/GetGameChatId.java index 72161114399..bd5059897f2 100644 --- a/Mage.Common/src/mage/remote/method/GetGameChatId.java +++ b/Mage.Common/src/mage/remote/method/GetGameChatId.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class GetGameChatId extends RemoteMethodCall { +public class GetGameChatId extends RemoteMethodCall { private UUID gameId; diff --git a/Mage.Common/src/mage/remote/method/GetMainRoomId.java b/Mage.Common/src/mage/remote/method/GetMainRoomId.java index 0df86815232..7dd354aa5ab 100644 --- a/Mage.Common/src/mage/remote/method/GetMainRoomId.java +++ b/Mage.Common/src/mage/remote/method/GetMainRoomId.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class GetMainRoomId extends RemoteMethodCall { +public class GetMainRoomId extends RemoteMethodCall { public GetMainRoomId(Connection connection) { diff --git a/Mage.Common/src/mage/remote/method/GetRoomChatId.java b/Mage.Common/src/mage/remote/method/GetRoomChatId.java index bb0ee926ec5..f7a37e59e52 100644 --- a/Mage.Common/src/mage/remote/method/GetRoomChatId.java +++ b/Mage.Common/src/mage/remote/method/GetRoomChatId.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class GetRoomChatId extends RemoteMethodCall { +public class GetRoomChatId extends RemoteMethodCall { private UUID roomId; diff --git a/Mage.Common/src/mage/remote/method/GetServerState.java b/Mage.Common/src/mage/remote/method/GetServerState.java index ea180c2aab6..861e31c8430 100644 --- a/Mage.Common/src/mage/remote/method/GetServerState.java +++ b/Mage.Common/src/mage/remote/method/GetServerState.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class GetServerState extends RemoteMethodCall { +public class GetServerState extends RemoteMethodCall { public GetServerState(Connection connection) { super(connection); diff --git a/Mage.Common/src/mage/remote/method/GetTable.java b/Mage.Common/src/mage/remote/method/GetTable.java index 348aa43aa30..215b4ca1db3 100644 --- a/Mage.Common/src/mage/remote/method/GetTable.java +++ b/Mage.Common/src/mage/remote/method/GetTable.java @@ -39,7 +39,7 @@ import mage.view.TableView; * * @author BetaSteward_at_googlemail.com */ -public class GetTable extends RemoteMethodCall { +public class GetTable extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/GetTableChatId.java b/Mage.Common/src/mage/remote/method/GetTableChatId.java index 6aaa48354e6..83f06a63c74 100644 --- a/Mage.Common/src/mage/remote/method/GetTableChatId.java +++ b/Mage.Common/src/mage/remote/method/GetTableChatId.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class GetTableChatId extends RemoteMethodCall { +public class GetTableChatId extends RemoteMethodCall { private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/GetTables.java b/Mage.Common/src/mage/remote/method/GetTables.java index 04e8cd7f35e..eaa10748414 100644 --- a/Mage.Common/src/mage/remote/method/GetTables.java +++ b/Mage.Common/src/mage/remote/method/GetTables.java @@ -41,7 +41,7 @@ import mage.view.TableView; * * @author BetaSteward_at_googlemail.com */ -public class GetTables extends RemoteMethodCall, MageException> { +public class GetTables extends RemoteMethodCall> { private UUID roomId; diff --git a/Mage.Common/src/mage/remote/method/GetTournament.java b/Mage.Common/src/mage/remote/method/GetTournament.java index a0282fcf465..1231b42bccc 100644 --- a/Mage.Common/src/mage/remote/method/GetTournament.java +++ b/Mage.Common/src/mage/remote/method/GetTournament.java @@ -39,7 +39,7 @@ import mage.view.TournamentView; * * @author BetaSteward_at_googlemail.com */ -public class GetTournament extends RemoteMethodCall { +public class GetTournament extends RemoteMethodCall { private UUID tournamentId; diff --git a/Mage.Common/src/mage/remote/method/GetTournamentChatId.java b/Mage.Common/src/mage/remote/method/GetTournamentChatId.java index 18443da53ea..b23d0ba8211 100644 --- a/Mage.Common/src/mage/remote/method/GetTournamentChatId.java +++ b/Mage.Common/src/mage/remote/method/GetTournamentChatId.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class GetTournamentChatId extends RemoteMethodCall { +public class GetTournamentChatId extends RemoteMethodCall { private UUID tournamentId; diff --git a/Mage.Common/src/mage/remote/method/IsTableOwner.java b/Mage.Common/src/mage/remote/method/IsTableOwner.java index 79754068bf4..a5b497d6ffb 100644 --- a/Mage.Common/src/mage/remote/method/IsTableOwner.java +++ b/Mage.Common/src/mage/remote/method/IsTableOwner.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class IsTableOwner extends RemoteMethodCall { +public class IsTableOwner extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/JoinChat.java b/Mage.Common/src/mage/remote/method/JoinChat.java index a69cc9a2f9c..b02fae379f8 100644 --- a/Mage.Common/src/mage/remote/method/JoinChat.java +++ b/Mage.Common/src/mage/remote/method/JoinChat.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class JoinChat extends RemoteMethodCall { +public class JoinChat extends RemoteMethodCall { private UUID chatId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/JoinDraft.java b/Mage.Common/src/mage/remote/method/JoinDraft.java index 507b786cbbf..7be2e6132b9 100644 --- a/Mage.Common/src/mage/remote/method/JoinDraft.java +++ b/Mage.Common/src/mage/remote/method/JoinDraft.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class JoinDraft extends RemoteMethodCall { +public class JoinDraft extends RemoteMethodCall { private UUID draftId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/JoinGame.java b/Mage.Common/src/mage/remote/method/JoinGame.java index 01a1a6b2fe1..c0f472d0c69 100644 --- a/Mage.Common/src/mage/remote/method/JoinGame.java +++ b/Mage.Common/src/mage/remote/method/JoinGame.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class JoinGame extends RemoteMethodCall { +public class JoinGame extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/JoinTable.java b/Mage.Common/src/mage/remote/method/JoinTable.java index 057036262bf..3bddb2ff99e 100644 --- a/Mage.Common/src/mage/remote/method/JoinTable.java +++ b/Mage.Common/src/mage/remote/method/JoinTable.java @@ -40,7 +40,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class JoinTable extends RemoteMethodCall { +public class JoinTable extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/JoinTournament.java b/Mage.Common/src/mage/remote/method/JoinTournament.java index 35a8f272a4a..aaec71600d9 100644 --- a/Mage.Common/src/mage/remote/method/JoinTournament.java +++ b/Mage.Common/src/mage/remote/method/JoinTournament.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class JoinTournament extends RemoteMethodCall { +public class JoinTournament extends RemoteMethodCall { private UUID tournamentId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/JoinTournamentTable.java b/Mage.Common/src/mage/remote/method/JoinTournamentTable.java index b7a0107cf6b..56800cbbedc 100644 --- a/Mage.Common/src/mage/remote/method/JoinTournamentTable.java +++ b/Mage.Common/src/mage/remote/method/JoinTournamentTable.java @@ -40,7 +40,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class JoinTournamentTable extends RemoteMethodCall { +public class JoinTournamentTable extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/LeaveChat.java b/Mage.Common/src/mage/remote/method/LeaveChat.java index f111fab30ee..1ea3bc44503 100644 --- a/Mage.Common/src/mage/remote/method/LeaveChat.java +++ b/Mage.Common/src/mage/remote/method/LeaveChat.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class LeaveChat extends RemoteMethodCall { +public class LeaveChat extends RemoteMethodCall { private UUID chatId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/LeaveTable.java b/Mage.Common/src/mage/remote/method/LeaveTable.java index be0f3ec66f7..8b9fdbcb346 100644 --- a/Mage.Common/src/mage/remote/method/LeaveTable.java +++ b/Mage.Common/src/mage/remote/method/LeaveTable.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class LeaveTable extends RemoteMethodCall { +public class LeaveTable extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/NextPlay.java b/Mage.Common/src/mage/remote/method/NextPlay.java index 24a747096da..aef8b388e5e 100644 --- a/Mage.Common/src/mage/remote/method/NextPlay.java +++ b/Mage.Common/src/mage/remote/method/NextPlay.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class NextPlay extends RemoteMethodCall { +public class NextPlay extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/Ping.java b/Mage.Common/src/mage/remote/method/Ping.java index f164368b6f5..0f7c093b418 100644 --- a/Mage.Common/src/mage/remote/method/Ping.java +++ b/Mage.Common/src/mage/remote/method/Ping.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class Ping extends RemoteMethodCall { +public class Ping extends RemoteMethodCall { private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/PreviousPlay.java b/Mage.Common/src/mage/remote/method/PreviousPlay.java index b40a2f0f43e..e4a611b9c98 100644 --- a/Mage.Common/src/mage/remote/method/PreviousPlay.java +++ b/Mage.Common/src/mage/remote/method/PreviousPlay.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class PreviousPlay extends RemoteMethodCall { +public class PreviousPlay extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/RegisterClient.java b/Mage.Common/src/mage/remote/method/RegisterClient.java index 8dcd4490cee..096090c3bca 100644 --- a/Mage.Common/src/mage/remote/method/RegisterClient.java +++ b/Mage.Common/src/mage/remote/method/RegisterClient.java @@ -40,7 +40,7 @@ import mage.utils.MageVersion; * * @author BetaSteward_at_googlemail.com */ -public class RegisterClient extends RemoteMethodCall { +public class RegisterClient extends RemoteMethodCall { private String userName; private UUID clientId; diff --git a/Mage.Common/src/mage/remote/method/RemoveTable.java b/Mage.Common/src/mage/remote/method/RemoveTable.java index 2067b56ecf1..feb58447ba0 100644 --- a/Mage.Common/src/mage/remote/method/RemoveTable.java +++ b/Mage.Common/src/mage/remote/method/RemoveTable.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class RemoveTable extends RemoteMethodCall { +public class RemoveTable extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/ReplayGame.java b/Mage.Common/src/mage/remote/method/ReplayGame.java index ab9627630c2..773145865ab 100644 --- a/Mage.Common/src/mage/remote/method/ReplayGame.java +++ b/Mage.Common/src/mage/remote/method/ReplayGame.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class ReplayGame extends RemoteMethodCall { +public class ReplayGame extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/SendCardPick.java b/Mage.Common/src/mage/remote/method/SendCardPick.java index 673d216e81c..80ec1485e7d 100644 --- a/Mage.Common/src/mage/remote/method/SendCardPick.java +++ b/Mage.Common/src/mage/remote/method/SendCardPick.java @@ -39,7 +39,7 @@ import mage.view.DraftPickView; * * @author BetaSteward_at_googlemail.com */ -public class SendCardPick extends RemoteMethodCall { +public class SendCardPick extends RemoteMethodCall { private UUID sessionId; private UUID draftId; diff --git a/Mage.Common/src/mage/remote/method/SendChatMessage.java b/Mage.Common/src/mage/remote/method/SendChatMessage.java index c73355c8e01..f3b7729c43c 100644 --- a/Mage.Common/src/mage/remote/method/SendChatMessage.java +++ b/Mage.Common/src/mage/remote/method/SendChatMessage.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class SendChatMessage extends RemoteMethodCall { +public class SendChatMessage extends RemoteMethodCall { private UUID chatId; private String message; diff --git a/Mage.Common/src/mage/remote/method/SendPlayerBoolean.java b/Mage.Common/src/mage/remote/method/SendPlayerBoolean.java index 572227fae97..5b573e64b38 100644 --- a/Mage.Common/src/mage/remote/method/SendPlayerBoolean.java +++ b/Mage.Common/src/mage/remote/method/SendPlayerBoolean.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class SendPlayerBoolean extends RemoteMethodCall { +public class SendPlayerBoolean extends RemoteMethodCall { private UUID sessionId; private UUID gameId; diff --git a/Mage.Common/src/mage/remote/method/SendPlayerInteger.java b/Mage.Common/src/mage/remote/method/SendPlayerInteger.java index 97e9fa1e1d7..2b1978468a3 100644 --- a/Mage.Common/src/mage/remote/method/SendPlayerInteger.java +++ b/Mage.Common/src/mage/remote/method/SendPlayerInteger.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class SendPlayerInteger extends RemoteMethodCall { +public class SendPlayerInteger extends RemoteMethodCall { private UUID sessionId; private UUID gameId; diff --git a/Mage.Common/src/mage/remote/method/SendPlayerString.java b/Mage.Common/src/mage/remote/method/SendPlayerString.java index 0925961e722..04c2d2a5950 100644 --- a/Mage.Common/src/mage/remote/method/SendPlayerString.java +++ b/Mage.Common/src/mage/remote/method/SendPlayerString.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class SendPlayerString extends RemoteMethodCall { +public class SendPlayerString extends RemoteMethodCall { private UUID sessionId; private UUID gameId; diff --git a/Mage.Common/src/mage/remote/method/SendPlayerUUID.java b/Mage.Common/src/mage/remote/method/SendPlayerUUID.java index ed7c7ad0451..c69bfdc6fb4 100644 --- a/Mage.Common/src/mage/remote/method/SendPlayerUUID.java +++ b/Mage.Common/src/mage/remote/method/SendPlayerUUID.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class SendPlayerUUID extends RemoteMethodCall { +public class SendPlayerUUID extends RemoteMethodCall { private UUID sessionId; private UUID gameId; diff --git a/Mage.Common/src/mage/remote/method/StartChallenge.java b/Mage.Common/src/mage/remote/method/StartChallenge.java index c9120c13fc0..62fcc3ab514 100644 --- a/Mage.Common/src/mage/remote/method/StartChallenge.java +++ b/Mage.Common/src/mage/remote/method/StartChallenge.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class StartChallenge extends RemoteMethodCall { +public class StartChallenge extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/StartGame.java b/Mage.Common/src/mage/remote/method/StartGame.java index 9390289d5b7..1c1d07a5ba0 100644 --- a/Mage.Common/src/mage/remote/method/StartGame.java +++ b/Mage.Common/src/mage/remote/method/StartGame.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class StartGame extends RemoteMethodCall { +public class StartGame extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/StartReplay.java b/Mage.Common/src/mage/remote/method/StartReplay.java index 88aa4b95038..5b33a897e6b 100644 --- a/Mage.Common/src/mage/remote/method/StartReplay.java +++ b/Mage.Common/src/mage/remote/method/StartReplay.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class StartReplay extends RemoteMethodCall { +public class StartReplay extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/StartTournament.java b/Mage.Common/src/mage/remote/method/StartTournament.java index ab0a28bc7a7..1c308ed0add 100644 --- a/Mage.Common/src/mage/remote/method/StartTournament.java +++ b/Mage.Common/src/mage/remote/method/StartTournament.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class StartTournament extends RemoteMethodCall { +public class StartTournament extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/StopReplay.java b/Mage.Common/src/mage/remote/method/StopReplay.java index 3e9e425d9c5..6ee96b80ec5 100644 --- a/Mage.Common/src/mage/remote/method/StopReplay.java +++ b/Mage.Common/src/mage/remote/method/StopReplay.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class StopReplay extends RemoteMethodCall { +public class StopReplay extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/StopWatching.java b/Mage.Common/src/mage/remote/method/StopWatching.java index 2ce2158e52d..569b7f1efd2 100644 --- a/Mage.Common/src/mage/remote/method/StopWatching.java +++ b/Mage.Common/src/mage/remote/method/StopWatching.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class StopWatching extends RemoteMethodCall { +public class StopWatching extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/SubmitDeck.java b/Mage.Common/src/mage/remote/method/SubmitDeck.java index 74eed5cbb5c..d2fc31ab8a7 100644 --- a/Mage.Common/src/mage/remote/method/SubmitDeck.java +++ b/Mage.Common/src/mage/remote/method/SubmitDeck.java @@ -40,7 +40,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class SubmitDeck extends RemoteMethodCall { +public class SubmitDeck extends RemoteMethodCall { private UUID tableId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/SwapSeats.java b/Mage.Common/src/mage/remote/method/SwapSeats.java index 206b1322186..47a5e83fc56 100644 --- a/Mage.Common/src/mage/remote/method/SwapSeats.java +++ b/Mage.Common/src/mage/remote/method/SwapSeats.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class SwapSeats extends RemoteMethodCall { +public class SwapSeats extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Common/src/mage/remote/method/WatchGame.java b/Mage.Common/src/mage/remote/method/WatchGame.java index cfcd75b3e0f..db747b28628 100644 --- a/Mage.Common/src/mage/remote/method/WatchGame.java +++ b/Mage.Common/src/mage/remote/method/WatchGame.java @@ -39,7 +39,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class WatchGame extends RemoteMethodCall { +public class WatchGame extends RemoteMethodCall { private UUID gameId; private UUID sessionId; diff --git a/Mage.Common/src/mage/remote/method/WatchTable.java b/Mage.Common/src/mage/remote/method/WatchTable.java index 5446507d9b0..252493c4bda 100644 --- a/Mage.Common/src/mage/remote/method/WatchTable.java +++ b/Mage.Common/src/mage/remote/method/WatchTable.java @@ -38,7 +38,7 @@ import mage.remote.RemoteMethodCall; * * @author BetaSteward_at_googlemail.com */ -public class WatchTable extends RemoteMethodCall { +public class WatchTable extends RemoteMethodCall { private UUID roomId; private UUID tableId; diff --git a/Mage.Server/src/main/java/mage/server/ServerImpl.java b/Mage.Server/src/main/java/mage/server/ServerImpl.java index 4d138babd35..7f1f8e8be35 100644 --- a/Mage.Server/src/main/java/mage/server/ServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/ServerImpl.java @@ -42,6 +42,7 @@ import java.util.logging.Level; import mage.cards.decks.DeckCardLists; import mage.game.GameException; import mage.MageException; +import mage.cards.decks.InvalidDeckException; import mage.game.match.MatchOptions; import mage.game.tournament.TournamentOptions; import mage.interfaces.Server; @@ -211,6 +212,9 @@ public class ServerImpl extends RemoteServer implements Server { return ret; } } + catch (InvalidDeckException ex) { + throw ex; + } catch (GameException ex) { throw ex; } diff --git a/Mage.Server/src/main/java/mage/server/TableController.java b/Mage.Server/src/main/java/mage/server/TableController.java index 2f7ea01c880..463f7b2db02 100644 --- a/Mage.Server/src/main/java/mage/server/TableController.java +++ b/Mage.Server/src/main/java/mage/server/TableController.java @@ -57,6 +57,7 @@ import org.apache.log4j.Logger; import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import mage.cards.decks.InvalidDeckException; /** * @@ -143,7 +144,7 @@ public class TableController { return true; } - public synchronized boolean joinTable(UUID sessionId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException { + public synchronized boolean joinTable(UUID sessionId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException { if (table.getState() != TableState.WAITING) { return false; } @@ -152,8 +153,8 @@ public class TableController { throw new GameException("No available seats."); } Deck deck = Deck.load(deckList); - if (!Main.server.isTestMode() && !validDeck(deck)) { - throw new GameException(name + " has an invalid deck for this format"); + if (!Main.server.isTestMode() && !table.getValidator().validate(deck)) { + throw new InvalidDeckException(name + " has an invalid deck for this format", table.getValidator().getInvalid()); } Player player = createPlayer(name, seat.getPlayerType(), skill); @@ -183,13 +184,13 @@ public class TableController { } } - public synchronized boolean submitDeck(UUID sessionId, DeckCardLists deckList) throws GameException { + public synchronized boolean submitDeck(UUID sessionId, DeckCardLists deckList) throws MageException { if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) { return false; } Deck deck = Deck.load(deckList); - if (!Main.server.isTestMode() && !validDeck(deck)) { - throw new GameException("Invalid deck for this format"); + if (!Main.server.isTestMode() && !table.getValidator().validate(deck)) { + throw new InvalidDeckException("Invalid deck for this format", table.getValidator().getInvalid()); } submitDeck(sessionId, deck); return true; @@ -225,10 +226,6 @@ public class TableController { return true; } - private boolean validDeck(Deck deck) { - return table.getValidator().validate(deck); - } - private Player createPlayer(String name, String playerType, int skill) { Player player; if (options == null) { diff --git a/Mage.Server/src/main/java/mage/server/TableManager.java b/Mage.Server/src/main/java/mage/server/TableManager.java index 048c8db729c..2f7421d6c3b 100644 --- a/Mage.Server/src/main/java/mage/server/TableManager.java +++ b/Mage.Server/src/main/java/mage/server/TableManager.java @@ -95,7 +95,7 @@ public class TableManager { return tables.values(); } - public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException { + public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException { if (controllers.containsKey(tableId)) return controllers.get(tableId).joinTable(sessionId, name, playerType, skill, deckList); return false; @@ -107,7 +107,7 @@ public class TableManager { return false; } - public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException { + public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws MageException { if (controllers.containsKey(tableId)) return controllers.get(tableId).submitDeck(sessionId, deckList); return false; diff --git a/Mage.Server/src/main/java/mage/server/game/GamesRoom.java b/Mage.Server/src/main/java/mage/server/game/GamesRoom.java index 0785a83b780..4c11cafaf75 100644 --- a/Mage.Server/src/main/java/mage/server/game/GamesRoom.java +++ b/Mage.Server/src/main/java/mage/server/game/GamesRoom.java @@ -45,7 +45,7 @@ import mage.view.TableView; public interface GamesRoom extends Room { public List getTables(); - public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException; + public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException; public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType, int skill) throws GameException; public TableView createTable(UUID sessionId, MatchOptions options); public TableView createTournamentTable(UUID sessionId, TournamentOptions options); diff --git a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java index 881328a0a8a..26e6a8dede4 100644 --- a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java +++ b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java @@ -64,7 +64,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable { } @Override - public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws GameException { + public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException { if (tables.containsKey(tableId)) { return TableManager.getInstance().joinTable(sessionId, tableId, name, playerType, skill, deckList); } else { diff --git a/Mage/src/mage/cards/decks/InvalidDeckException.java b/Mage/src/mage/cards/decks/InvalidDeckException.java new file mode 100644 index 00000000000..23502e112e1 --- /dev/null +++ b/Mage/src/mage/cards/decks/InvalidDeckException.java @@ -0,0 +1,50 @@ +/* +* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + +package mage.cards.decks; + +import java.util.Map; +import mage.MageException; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class InvalidDeckException extends MageException { + + Map invalid; + + public InvalidDeckException (String message, Map invalid) { + super(message); + this.invalid = invalid; + } + + public Map getInvalid() { + return invalid; + } +}