[FIX] HWID banned users

This commit is contained in:
Gravit 2020-05-18 19:57:12 +07:00
parent 3baffcafb5
commit fb00adb129
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 29 additions and 2 deletions

View file

@ -8,6 +8,7 @@
import pro.gravit.launchserver.auth.protect.hwid.HWIDException; import pro.gravit.launchserver.auth.protect.hwid.HWIDException;
import pro.gravit.launchserver.auth.protect.hwid.HWIDProvider; import pro.gravit.launchserver.auth.protect.hwid.HWIDProvider;
import pro.gravit.launchserver.auth.protect.interfaces.HardwareProtectHandler; 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.auth.protect.interfaces.SecureProtectHandler;
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.auth.AuthResponse; import pro.gravit.launchserver.socket.response.auth.AuthResponse;
@ -18,7 +19,7 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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 boolean enableHardwareFeature;
public HWIDProvider provider; public HWIDProvider provider;
@ -56,6 +57,7 @@ public void onHardwareReport(HardwareReportResponse response, Client client) {
LogHelper.debug("[HardwareInfo] HardwareInfo needCreate: %s", needCreate ? "true" : "false"); LogHelper.debug("[HardwareInfo] HardwareInfo needCreate: %s", needCreate ? "true" : "false");
if(needCreate) if(needCreate)
provider.createHardwareInfo(response.hardware, client.trustLevel.publicKey); provider.createHardwareInfo(response.hardware, client.trustLevel.publicKey);
client.trustLevel.hardwareInfo = response.hardware;
} catch (HWIDException e) { } catch (HWIDException e) {
throw new SecurityException(e.getMessage()); throw new SecurityException(e.getMessage());
} }
@ -94,4 +96,9 @@ public Map<String, Command> getCommands() {
} }
return commands; return commands;
} }
@Override
public boolean onJoinServer(String serverID, String username, Client client) {
return !enableHardwareFeature || client.trustLevel.hardwareInfo != null;
}
} }

View file

@ -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;
}
}

View file

@ -3,6 +3,7 @@
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import pro.gravit.launcher.events.request.JoinServerRequestEvent; import pro.gravit.launcher.events.request.JoinServerRequestEvent;
import pro.gravit.launchserver.auth.AuthException; 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.Client;
import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.SimpleResponse;
import pro.gravit.utils.HookException; import pro.gravit.utils.HookException;
@ -27,6 +28,15 @@ public void execute(ChannelHandlerContext ctx, Client client) {
boolean success; boolean success;
try { try {
server.authHookManager.joinServerHook.hook(this, client); 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) { if (client.auth == null) {
LogHelper.warning("Client auth is null. Using default."); LogHelper.warning("Client auth is null. Using default.");
success = server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID); success = server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID);
@ -34,7 +44,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
if (LogHelper.isDebugEnabled()) { if (LogHelper.isDebugEnabled()) {
LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID); LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID);
} }
} catch (AuthException | HookException e) { } catch (AuthException | HookException | SecurityException e) {
sendError(e.getMessage()); sendError(e.getMessage());
return; return;
} catch (Exception e) { } catch (Exception e) {