From b5e62583530a7103acf6bf4202ecff5c7dce7f55 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 31 Dec 2018 15:06:50 +0700 Subject: [PATCH] checkServerHook joinServerHook --- .../auth/handler/AuthHandler.java | 2 + .../auth/provider/AuthProvider.java | 2 +- .../manangers/hook/AuthHookManager.java | 37 ++++++++++++++++++- .../response/auth/CheckServerResponse.java | 1 + .../response/auth/JoinServerResponse.java | 1 + modules | 2 +- 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 362fd2ab..974f7ddd 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -6,6 +6,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.utils.helper.VerifyHelper; @@ -13,6 +14,7 @@ public abstract class AuthHandler implements AutoCloseable { private static final Map> AUTH_HANDLERS = new ConcurrentHashMap<>(4); private static boolean registredHandl = false; + private transient LaunchServer server = LaunchServer.server; public static UUID authError(String message) throws AuthException { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java index 7f01bf0a..3607206e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java @@ -13,7 +13,7 @@ public abstract class AuthProvider implements AutoCloseable { private static final Map> AUTH_PROVIDERS = new ConcurrentHashMap<>(8); private static boolean registredProv = false; - private transient LaunchServer server = LaunchServer.server; + protected transient LaunchServer server = LaunchServer.server; public static AuthProviderResult authError(String message) throws AuthException { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/AuthHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/AuthHookManager.java index f6eb866e..729ae1f6 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/AuthHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/AuthHookManager.java @@ -9,23 +9,42 @@ public class AuthHookManager { private Set PRE_HOOKS = new HashSet<>(); private Set POST_HOOKS = new HashSet<>(); + private Set CHECKSERVER_HOOKS = new HashSet<>(); + private Set JOINSERVER_HOOKS = new HashSet<>(); @FunctionalInterface public interface AuthPreHook { void preAuthHook(AuthResponse.AuthContext context, Client client); } + @FunctionalInterface public interface AuthPostHook { void postAuthHook(AuthResponse.AuthContext context, Client client); } + @FunctionalInterface + public interface CheckServerHook + { + void checkServerHook(String username, String serverID); + } + @FunctionalInterface + public interface JoinServerHook + { + void joinServerHook(String username, String accessToken, String serverID); + } public void registerPostHook(AuthPostHook hook) { - if(POST_HOOKS == null) POST_HOOKS = new HashSet<>(); POST_HOOKS.add(hook); } + public void registerJoinServerHook(JoinServerHook hook) + { + JOINSERVER_HOOKS.add(hook); + } + public void registerCheckServerHook(CheckServerHook hook) + { + CHECKSERVER_HOOKS.add(hook); + } public void registerPreHook(AuthPreHook hook) { - if(PRE_HOOKS == null) PRE_HOOKS = new HashSet<>(); PRE_HOOKS.add(hook); } public void preHook(AuthResponse.AuthContext context, Client client) @@ -35,6 +54,20 @@ public void preHook(AuthResponse.AuthContext context, Client client) preHook.preAuthHook(context,client); } } + public void checkServerHook(String username, String serverID) + { + for(CheckServerHook hook : CHECKSERVER_HOOKS) + { + hook.checkServerHook(username, serverID); + } + } + public void joinServerHook(String username, String accessToken, String serverID) + { + for(JoinServerHook hook : JOINSERVER_HOOKS) + { + hook.joinServerHook(username, accessToken, serverID); + } + } public void postHook(AuthResponse.AuthContext context, Client client) { for(AuthPostHook postHook : POST_HOOKS) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java index a3b4dfa7..797168b3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java @@ -31,6 +31,7 @@ public void reply() throws IOException { // Try check server with auth handler UUID uuid; try { + server.authHookManager.checkServerHook(username,serverID); uuid = server.config.authHandler.checkServer(username, serverID); } catch (AuthException e) { requestError(e.getMessage()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java index 1184654e..dd5a9ee2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java @@ -28,6 +28,7 @@ public void reply() throws IOException { debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID); boolean success; try { + server.authHookManager.joinServerHook(username,accessToken,serverID); success = server.config.authHandler.joinServer(username, accessToken, serverID); } catch (AuthException e) { requestError(e.getMessage()); diff --git a/modules b/modules index 2dd4ced9..4bb1abd9 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 2dd4ced9a703d3b891446b4a380d78254c7771fb +Subproject commit 4bb1abd9c5fa1f36d04c03d6c4eaae707ceb1652