Added new client-server incompatible checks:

* added strict mode (client and server versions must be same, see MAGE_VERSION_MINOR_PATCH_MUST_BE_SAME);
 * you must enable string mode after github code changes in serializeable classes (see #4459);
 * added client-side version checks;
 * added error message on wrong version disconnects.
This commit is contained in:
Oleg Agafonov 2019-01-18 13:32:37 +04:00
parent fa0e295932
commit f223bdab31
6 changed files with 52 additions and 13 deletions

View file

@ -61,6 +61,7 @@ public class SessionImpl implements Session {
private boolean canceled = false;
private boolean jsonLogActive = false;
private String lastError = "";
static {
debugMode = System.getProperty("debug.mage") != null;
@ -195,20 +196,29 @@ public class SessionImpl implements Session {
&& handleRemotingTaskExceptions(new RemotingTask() {
@Override
public boolean run() throws Throwable {
setLastError("");
logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort());
boolean registerResult;
if (connection.getAdminPassword() == null) {
// for backward compatibility. don't remove twice call - first one does nothing but for version checking
registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion(), connection.getUserIdStr());
if (registerResult) {
server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr());
}
} else {
registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion());
}
if (registerResult) {
serverState = server.getServerState();
// client side check for incompatible versions
if (client.getVersion().compareTo(serverState.getVersion()) != 0) {
String err = "Client and server versions are incompatible.";
setLastError(err);
logger.info(err);
disconnect(false);
return false;
}
if (!connection.getUsername().equals("Admin")) {
server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr());
updateDatabase(connection.isForceDBComparison(), serverState);
}
logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort());
@ -1621,6 +1631,15 @@ public class SessionImpl implements Session {
this.jsonLogActive = jsonLogActive;
}
private void setLastError(String error) {
lastError = error;
}
@Override
public String getLastError() {
return lastError;
}
}
class MageAuthenticator extends Authenticator {

View file

@ -1,4 +1,3 @@
package mage.remote.interfaces;
import mage.remote.Connection;
@ -37,10 +36,12 @@ public interface Connect {
boolean muteUserChat(String userName, long durationMinute);
boolean setActivation(String userName, boolean active);
boolean toggleActivation(String userName);
boolean lockUser(String userName, long durationMinute);
String getSessionId();
String getLastError();
}

View file

@ -16,7 +16,9 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
public final static int MAGE_VERSION_MINOR = 4;
public final static int MAGE_VERSION_PATCH = 33;
public final static String MAGE_EDITION_INFO = ""; // set "-beta" for 1.4.32-betaV0
public final static String MAGE_VERSION_MINOR_PATCH = "V0";
public final static String MAGE_VERSION_MINOR_PATCH = "V1"; // default V0
// strict mode
private final static boolean MAGE_VERSION_MINOR_PATCH_MUST_BE_SAME = true; // set true on uncompatible github changes, set false after new major release (after MAGE_VERSION_PATCH changes)
private final int major;
private final int minor;
@ -74,7 +76,9 @@ public class MageVersion implements Serializable, Comparable<MageVersion> {
if (patch != o.patch) {
return patch - o.patch;
}
if (MAGE_VERSION_MINOR_PATCH_MUST_BE_SAME && !minorPatch.equals(o.minorPatch)) {
return minorPatch.compareTo(o.minorPatch);
}
return editionInfo.compareTo(o.editionInfo);
}
}