diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java index 3317e18b..f633c0b8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java @@ -8,6 +8,7 @@ import pro.gravit.launchserver.auth.protect.hwid.HWIDException; import pro.gravit.launchserver.auth.protect.hwid.HWIDProvider; import pro.gravit.launchserver.auth.protect.interfaces.HardwareProtectHandler; +import pro.gravit.launchserver.auth.protect.interfaces.JoinServerProtectHandler; import pro.gravit.launchserver.auth.protect.interfaces.SecureProtectHandler; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; @@ -18,7 +19,7 @@ import java.util.HashMap; import java.util.Map; -public class AdvancedProtectHandler extends StdProtectHandler implements SecureProtectHandler, HardwareProtectHandler, Reconfigurable { +public class AdvancedProtectHandler extends StdProtectHandler implements SecureProtectHandler, HardwareProtectHandler, JoinServerProtectHandler, Reconfigurable { public boolean enableHardwareFeature; public HWIDProvider provider; @@ -56,6 +57,7 @@ public void onHardwareReport(HardwareReportResponse response, Client client) { LogHelper.debug("[HardwareInfo] HardwareInfo needCreate: %s", needCreate ? "true" : "false"); if(needCreate) provider.createHardwareInfo(response.hardware, client.trustLevel.publicKey); + client.trustLevel.hardwareInfo = response.hardware; } catch (HWIDException e) { throw new SecurityException(e.getMessage()); } @@ -94,4 +96,9 @@ public Map getCommands() { } return commands; } + + @Override + public boolean onJoinServer(String serverID, String username, Client client) { + return !enableHardwareFeature || client.trustLevel.hardwareInfo != null; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/JoinServerProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/JoinServerProtectHandler.java new file mode 100644 index 00000000..dafedbe1 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/JoinServerProtectHandler.java @@ -0,0 +1,10 @@ +package pro.gravit.launchserver.auth.protect.interfaces; + +import pro.gravit.launchserver.socket.Client; + +public interface JoinServerProtectHandler { + default boolean onJoinServer(String serverID, String username, Client client) + { + return true; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java index 46a5542a..1fd65dc0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java @@ -3,6 +3,7 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.JoinServerRequestEvent; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.auth.protect.interfaces.JoinServerProtectHandler; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.HookException; @@ -27,6 +28,15 @@ public void execute(ChannelHandlerContext ctx, Client client) { boolean success; try { server.authHookManager.joinServerHook.hook(this, client); + if(server.config.protectHandler instanceof JoinServerProtectHandler) + { + success = ((JoinServerProtectHandler) server.config.protectHandler).onJoinServer(serverID, username, client); + if(!success) + { + sendResult(new JoinServerRequestEvent(false)); + return; + } + } if (client.auth == null) { LogHelper.warning("Client auth is null. Using default."); success = server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID); @@ -34,7 +44,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { if (LogHelper.isDebugEnabled()) { LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID); } - } catch (AuthException | HookException e) { + } catch (AuthException | HookException | SecurityException e) { sendError(e.getMessage()); return; } catch (Exception e) {