diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 9a54691d..024d1644 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -21,6 +21,7 @@ import pro.gravit.launchserver.socket.response.cabinet.AssetUploadInfoResponse; import pro.gravit.launchserver.socket.response.cabinet.GetAssetUploadInfoResponse; import pro.gravit.launchserver.socket.response.management.FeaturesResponse; +import pro.gravit.launchserver.socket.response.management.GetConnectUUIDResponse; import pro.gravit.launchserver.socket.response.management.GetPublicKeyResponse; import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; @@ -94,6 +95,7 @@ public static void registerResponses() { providers.register("getPublicKey", GetPublicKeyResponse.class); providers.register("getAssetUploadUrl", GetAssetUploadInfoResponse.class); providers.register("assetUploadInfo", AssetUploadInfoResponse.class); + providers.register("getConnectUUID", GetConnectUUIDResponse.class); } public static String getIPFromContext(ChannelHandlerContext ctx) { @@ -121,9 +123,9 @@ public void forEachActiveChannels(BiConsumer cal } } - public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { + public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip, UUID connectUUID) { String request = frame.text(); - WebSocketRequestContext context = new WebSocketRequestContext(ctx, request, client, ip); + WebSocketRequestContext context = new WebSocketRequestContext(ctx, request, client, ip, connectUUID); if(hookBeforeParsing.hook(context)) { return; } @@ -183,6 +185,7 @@ void process(WebSocketRequestContext context, WebSocketServerResponse response, simpleResponse.ctx = ctx; if (ip != null) simpleResponse.ip = ip; else simpleResponse.ip = IOHelper.getIP(ctx.channel().remoteAddress()); + simpleResponse.connectUUID = context.connectUUID; } try { response.execute(ctx, client); @@ -333,14 +336,16 @@ public static class WebSocketRequestContext { public final String text; public final Client client; public final String ip; + public final UUID connectUUID; public WebSocketServerResponse response; public Throwable exception; - public WebSocketRequestContext(ChannelHandlerContext context, String text, Client client, String ip) { + public WebSocketRequestContext(ChannelHandlerContext context, String text, Client client, String ip, UUID connectUUID) { this.context = context; this.text = text; this.client = client; this.ip = ip; + this.connectUUID = connectUUID; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java index 9d2c8dcd..c4260949 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java @@ -68,7 +68,7 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) { logger.trace("Message from {}: {}", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip, textWebSocketFrame.text()); } try { - service.process(ctx, textWebSocketFrame, client, context.ip); + service.process(ctx, textWebSocketFrame, client, context.ip, connectUUID); } catch (Throwable ex) { logger.warn("Client {} send invalid request. Connection force closed.", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip); if (logger.isTraceEnabled()) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java index 28738232..97b097cd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java @@ -13,6 +13,7 @@ public abstract class SimpleResponse implements WebSocketServerResponse { public transient LaunchServer server; public transient WebSocketService service; public transient ChannelHandlerContext ctx; + public transient UUID connectUUID; public transient String ip; public void sendResult(RequestEvent result) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetConnectUUIDResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetConnectUUIDResponse.java new file mode 100644 index 00000000..b4f05dcb --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetConnectUUIDResponse.java @@ -0,0 +1,18 @@ +package pro.gravit.launchserver.socket.response.management; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.base.events.request.GetConnectUUIDRequestEvent; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class GetConnectUUIDResponse extends SimpleResponse { + @Override + public String getType() { + return "getConnectUUID"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + sendResult(new GetConnectUUIDRequestEvent(connectUUID)); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetConnectUUIDRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetConnectUUIDRequestEvent.java new file mode 100644 index 00000000..81594ded --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetConnectUUIDRequestEvent.java @@ -0,0 +1,18 @@ +package pro.gravit.launcher.base.events.request; + +import pro.gravit.launcher.base.events.RequestEvent; + +import java.util.UUID; + +public class GetConnectUUIDRequestEvent extends RequestEvent { + public UUID connectUUID; + + public GetConnectUUIDRequestEvent(UUID connectUUID) { + this.connectUUID = connectUUID; + } + + @Override + public String getType() { + return "getConnectUUID"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/GetConnectUUIDRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/GetConnectUUIDRequest.java new file mode 100644 index 00000000..a56bf98e --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/GetConnectUUIDRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.base.request.management; + +import pro.gravit.launcher.base.events.request.GetConnectUUIDRequestEvent; +import pro.gravit.launcher.base.request.Request; + +public class GetConnectUUIDRequest extends Request { + @Override + public String getType() { + return "getConnectUUID"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientWebSocketService.java index e5564f37..11fd7493 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientWebSocketService.java @@ -113,6 +113,7 @@ public void registerResults() { results.register("getPublicKey", GetPublicKeyRequestEvent.class); results.register("getAssetUploadUrl", GetAssetUploadUrlRequestEvent.class); results.register("assetUploadInfo", AssetUploadInfoRequestEvent.class); + results.register("getConnectUUID", GetConnectUUIDRequestEvent.class); resultsRegistered = true; } }