added MageVersionException - needed for automatic client download

This commit is contained in:
BetaSteward 2011-08-31 11:32:59 -04:00
parent f9cb39ea7e
commit 50a2edf80c
3 changed files with 56 additions and 1 deletions

View file

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

View file

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

View file

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