From a915d41b939ed67b7867e1a56a5271cb2a6a93f7 Mon Sep 17 00:00:00 2001 From: Gravita Date: Sun, 8 Aug 2021 16:10:07 +0700 Subject: [PATCH] [FIX] JsonAuthCoreProvider joinServer/checkServer --- .../auth/core/JsonCoreProvider.java | 45 +++++++++++++++++++ .../auth/core/MySQLCoreProvider.java | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/JsonCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/JsonCoreProvider.java index 25642b44..74b8ffc3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/JsonCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/JsonCoreProvider.java @@ -37,6 +37,8 @@ public class JsonCoreProvider extends AuthCoreProvider { public String verifyPasswordUrl; public String createOAuthSessionUrl; public String updateServerIdUrl; + public String joinServerUrl; + public String checkServerUrl; public String bearerToken; public PasswordVerifier passwordVerifier; private transient HttpClient client; @@ -159,8 +161,29 @@ public void init(LaunchServer server) { client = HttpClient.newBuilder().build(); } + @Override + public User checkServer(Client client, String username, String serverID) throws IOException { + if (checkServerUrl == null) { + return super.checkServer(client, username, serverID); + } + return jsonRequest(new JsonCheckServer(username, serverID), checkServerUrl, JsonUser.class); + } + + @Override + public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException { + if (joinServerUrl == null) { + return super.joinServer(client, username, accessToken, serverID); + } + return jsonRequest(new JsonJoinServer(username, accessToken, serverID), joinServerUrl, JsonSuccessResponse.class).success; + } + @Override protected boolean updateServerID(User user, String serverID) throws IOException { + JsonUser jsonUser = (JsonUser) user; + if (updateServerIdUrl == null) { + return false; + } + jsonUser.serverId = serverID; JsonSuccessResponse successResponse = jsonRequest(new JsonUpdateServerId(user.getUsername(), user.getUUID(), serverID), updateServerIdUrl, JsonSuccessResponse.class); if (successResponse == null) return false; return successResponse.success; @@ -183,6 +206,28 @@ public JsonGetUserByUsername(String username) { } } + public static class JsonCheckServer { + public String username; + public String serverId; + + public JsonCheckServer(String username, String serverId) { + this.username = username; + this.serverId = serverId; + } + } + + public static class JsonJoinServer { + public String username; + public String accessToken; + public String serverId; + + public JsonJoinServer(String username, String accessToken, String serverId) { + this.username = username; + this.accessToken = accessToken; + this.serverId = serverId; + } + } + public static class JsonGetUserByUUID { public UUID uuid; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java index 4d53b5cc..2046769e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java @@ -112,7 +112,7 @@ public void verifyAuth(AuthResponse.AuthContext context) throws AuthException { @Override public PasswordVerifyReport verifyPassword(User user, AuthRequest.AuthPasswordInterface password) { if (passwordVerifier.check(((MySQLUser) user).password, ((AuthPlainPassword) password).password)) { - return new PasswordVerifyReport(true); + return PasswordVerifyReport.OK; } else { return PasswordVerifyReport.FAILED; }