mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] GetConnectUUIDRequest
This commit is contained in:
parent
80176ff1e1
commit
3152758d31
7 changed files with 58 additions and 4 deletions
|
@ -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<Channel, WebSocketFrameHandler> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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<GetConnectUUIDRequestEvent> {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "getConnectUUID";
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue