mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
checkServerHook joinServerHook
This commit is contained in:
parent
edaf4d2ad6
commit
b5e6258353
6 changed files with 41 additions and 4 deletions
|
@ -6,6 +6,7 @@
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
public abstract class AuthHandler implements AutoCloseable {
|
public abstract class AuthHandler implements AutoCloseable {
|
||||||
private static final Map<String, Class<? extends AuthHandler>> AUTH_HANDLERS = new ConcurrentHashMap<>(4);
|
private static final Map<String, Class<? extends AuthHandler>> AUTH_HANDLERS = new ConcurrentHashMap<>(4);
|
||||||
private static boolean registredHandl = false;
|
private static boolean registredHandl = false;
|
||||||
|
private transient LaunchServer server = LaunchServer.server;
|
||||||
|
|
||||||
|
|
||||||
public static UUID authError(String message) throws AuthException {
|
public static UUID authError(String message) throws AuthException {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
public abstract class AuthProvider implements AutoCloseable {
|
public abstract class AuthProvider implements AutoCloseable {
|
||||||
private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
|
private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
|
||||||
private static boolean registredProv = false;
|
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 {
|
public static AuthProviderResult authError(String message) throws AuthException {
|
||||||
|
|
|
@ -9,23 +9,42 @@
|
||||||
public class AuthHookManager {
|
public class AuthHookManager {
|
||||||
private Set<AuthPreHook> PRE_HOOKS = new HashSet<>();
|
private Set<AuthPreHook> PRE_HOOKS = new HashSet<>();
|
||||||
private Set<AuthPostHook> POST_HOOKS = new HashSet<>();
|
private Set<AuthPostHook> POST_HOOKS = new HashSet<>();
|
||||||
|
private Set<CheckServerHook> CHECKSERVER_HOOKS = new HashSet<>();
|
||||||
|
private Set<JoinServerHook> JOINSERVER_HOOKS = new HashSet<>();
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface AuthPreHook
|
public interface AuthPreHook
|
||||||
{
|
{
|
||||||
void preAuthHook(AuthResponse.AuthContext context, Client client);
|
void preAuthHook(AuthResponse.AuthContext context, Client client);
|
||||||
}
|
}
|
||||||
|
@FunctionalInterface
|
||||||
public interface AuthPostHook
|
public interface AuthPostHook
|
||||||
{
|
{
|
||||||
void postAuthHook(AuthResponse.AuthContext context, Client client);
|
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)
|
public void registerPostHook(AuthPostHook hook)
|
||||||
{
|
{
|
||||||
if(POST_HOOKS == null) POST_HOOKS = new HashSet<>();
|
|
||||||
POST_HOOKS.add(hook);
|
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)
|
public void registerPreHook(AuthPreHook hook)
|
||||||
{
|
{
|
||||||
if(PRE_HOOKS == null) PRE_HOOKS = new HashSet<>();
|
|
||||||
PRE_HOOKS.add(hook);
|
PRE_HOOKS.add(hook);
|
||||||
}
|
}
|
||||||
public void preHook(AuthResponse.AuthContext context, Client client)
|
public void preHook(AuthResponse.AuthContext context, Client client)
|
||||||
|
@ -35,6 +54,20 @@ public void preHook(AuthResponse.AuthContext context, Client client)
|
||||||
preHook.preAuthHook(context,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)
|
public void postHook(AuthResponse.AuthContext context, Client client)
|
||||||
{
|
{
|
||||||
for(AuthPostHook postHook : POST_HOOKS)
|
for(AuthPostHook postHook : POST_HOOKS)
|
||||||
|
|
|
@ -31,6 +31,7 @@ public void reply() throws IOException {
|
||||||
// Try check server with auth handler
|
// Try check server with auth handler
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
try {
|
try {
|
||||||
|
server.authHookManager.checkServerHook(username,serverID);
|
||||||
uuid = server.config.authHandler.checkServer(username, serverID);
|
uuid = server.config.authHandler.checkServer(username, serverID);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
requestError(e.getMessage());
|
requestError(e.getMessage());
|
||||||
|
|
|
@ -28,6 +28,7 @@ public void reply() throws IOException {
|
||||||
debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
|
debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
|
||||||
boolean success;
|
boolean success;
|
||||||
try {
|
try {
|
||||||
|
server.authHookManager.joinServerHook(username,accessToken,serverID);
|
||||||
success = server.config.authHandler.joinServer(username, accessToken, serverID);
|
success = server.config.authHandler.joinServer(username, accessToken, serverID);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
requestError(e.getMessage());
|
requestError(e.getMessage());
|
||||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
||||||
Subproject commit 2dd4ced9a703d3b891446b4a380d78254c7771fb
|
Subproject commit 4bb1abd9c5fa1f36d04c03d6c4eaae707ceb1652
|
Loading…
Reference in a new issue