diff --git a/Mage.Common/src/mage/remote/MageVersionException.java b/Mage.Common/src/mage/remote/MageVersionException.java new file mode 100644 index 00000000000..b098da6eb77 --- /dev/null +++ b/Mage.Common/src/mage/remote/MageVersionException.java @@ -0,0 +1,49 @@ +/* + * 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 mage.MageException; +import mage.utils.MageVersion; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class MageVersionException extends MageException { + + private MageVersion serverVersion; + + public MageVersionException(MageVersion clientVersion, MageVersion serverVersion) { + super("Wrong client version " + clientVersion + ", expecting version " + serverVersion); + this.serverVersion = serverVersion; + } + + public MageVersion getServerVersion() { + return serverVersion; + } +} diff --git a/Mage.Common/src/mage/remote/Session.java b/Mage.Common/src/mage/remote/Session.java index 7e8cdc6525e..bd266cab681 100644 --- a/Mage.Common/src/mage/remote/Session.java +++ b/Mage.Common/src/mage/remote/Session.java @@ -169,6 +169,9 @@ public class Session { } catch (MalformedURLException ex) { logger.fatal("", ex); client.showMessage("Unable to connect to server. " + ex.getMessage()); + } catch (MageVersionException ex) { + client.showMessage("Unable to connect to server. " + ex.getMessage()); + // TODO: download client that matches server version } catch (Throwable t) { logger.fatal("Unable to connect to server - ", t); disconnect(false); diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index c9dc2284001..95689d7da69 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -40,6 +40,7 @@ import mage.game.tournament.TournamentOptions; import mage.interfaces.MageServer; //import mage.interfaces.Server; import mage.interfaces.ServerState; +import mage.remote.MageVersionException; import mage.server.game.DeckValidatorFactory; import mage.server.draft.DraftManager; import mage.server.game.GameFactory; @@ -85,9 +86,11 @@ public class MageServerImpl implements MageServer { try { if (version.compareTo(Main.getVersion()) != 0) - throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion()); + throw new MageVersionException(version, Main.getVersion()); return SessionManager.getInstance().registerUser(sessionId, userName); } catch (Exception ex) { + if (ex instanceof MageVersionException) + throw (MageVersionException)ex; handleException(ex); } return false;