diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index f837656..5ab8cc6 100755 --- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -8,6 +8,7 @@ import java.time.LocalDateTime; import java.util.Arrays; import java.util.HashSet; import java.util.logging.Logger; +import java.util.regex.Pattern; import javax.persistence.NoResultException; @@ -38,9 +39,8 @@ public final class LoginCredentialProcessor implements ObjectProcessor\\d).(?\\d)(?:-(?\\w+))?"); + private static final Logger logger = EnvoyLog.getLogger(LoginCredentialProcessor.class); + private static final Pattern versionPattern = Pattern.compile("(?\\d).(?\\d)(?:-(?\\w+))?"); @Override public void process(LoginCredentials credentials, long socketID, ObjectWriteProxy writeProxy) throws IOException { @@ -49,10 +49,10 @@ public final class LoginCredentialProcessor implements ObjectProcessor= 0) { - // writeProxy.write(socketID, new HandshakeRejectionEvent("Wrong version")); - // return; + if (!verifyCompatibility(credentials.getClientVersion())) { + logger.info("The client has the wrong version."); + writeProxy.write(socketID, new HandshakeRejection("Wrong version")); + return; } // Acquire a user object (or reject the handshake if that's impossible) @@ -125,6 +125,57 @@ public final class LoginCredentialProcessor implements ObjectProcessor maxSuffix) return false; + } + + // Compare major + { + final var currentMajor = Integer.parseInt(currentMatcher.group("major")); + final var minMajor = Integer.parseInt(minMatcher.group("major")); + final var maxMajor = Integer.parseInt(maxMatcher.group("major")); + + if (currentMajor < minMajor || currentMajor > maxMajor) return false; + } + + // Compare minor + { + final var currentMinor = Integer.parseInt(currentMatcher.group("minor")); + final var minMinor = Integer.parseInt(minMatcher.group("minor")); + final var maxMinor = Integer.parseInt(maxMatcher.group("minor")); + + if (currentMinor < minMinor || currentMinor > maxMinor) return false; + } + + return true; + } + + private int convertSuffix(String suffix) { + switch (suffix == null ? "" : suffix) { + case "alpha": + return 0; + case "beta": + return 1; + default: + return 2; + } + } + @Override public Class getInputClass() { return LoginCredentials.class; } }