diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 4c11c536..2437fcd9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -290,7 +290,6 @@ public class NettyConfig { public NettyPerformanceConfig performance; public NettyBindAddress[] binds; public LogLevel logLevel = LogLevel.DEBUG; - public NettyProxyConfig proxy = new NettyProxyConfig(); } public class NettyPerformanceConfig { @@ -299,15 +298,6 @@ public class NettyPerformanceConfig { public int workerThread; } - public class NettyProxyConfig { - public boolean enabled; - public String address = "ws://localhost:9275/api"; - public String login = "login"; - public String password = "password"; - public String auth_id = "std"; - public ArrayList requests = new ArrayList<>(); - } - public class NettyBindAddress { public String address; public int port; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java index b845d644..13e60a5d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -8,7 +8,6 @@ public class Client { public long session; - public boolean proxy; public String auth_id; public long timestamp; public Type type; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java index c0b5b205..0c2e3578 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java @@ -22,6 +22,8 @@ import pro.gravit.launchserver.socket.handlers.NettyIpForwardHandler; import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler; import pro.gravit.launchserver.socket.handlers.fileserver.FileServerHandler; +import pro.gravit.utils.BiHookSet; +import pro.gravit.utils.HookSet; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; @@ -30,6 +32,7 @@ public class LauncherNettyServer implements AutoCloseable { public final EventLoopGroup bossGroup; public final EventLoopGroup workerGroup; public final WebSocketService service; + public final BiHookSet pipelineHook = new BiHookSet<>(); private static final String WEBSOCKET_PATH = "/api"; public LauncherNettyServer(LaunchServer server) { @@ -65,19 +68,9 @@ public void initChannel(SocketChannel ch) { if (server.config.netty.fileServerEnabled) pipeline.addLast(new FileServerHandler(server.updatesDir, true)); pipeline.addLast(new WebSocketFrameHandler(context, server, service)); + pipelineHook.hook(context, ch); } }); - if (config.proxy != null && config.proxy.enabled) { - LogHelper.info("Connect to main server %s"); - Request.service = StandartClientWebSocketService.initWebSockets(config.proxy.address, false); - AuthRequest authRequest = new AuthRequest(config.proxy.login, config.proxy.password, config.proxy.auth_id, AuthRequest.ConnectTypes.PROXY); - authRequest.initProxy = true; - try { - authRequest.request(); - } catch (Exception e) { - LogHelper.error(e); - } - } } public ChannelFuture bind(InetSocketAddress address) { 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 98539d6d..8b3cffbd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -2,8 +2,6 @@ import java.lang.reflect.Type; import java.util.HashMap; -import java.util.Random; -import java.util.UUID; import com.google.gson.Gson; @@ -15,18 +13,13 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.events.ExceptionEvent; import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.events.request.ErrorRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.WebSocketEvent; -import pro.gravit.launcher.request.admin.ProxyRequest; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.admin.AddLogListenerResponse; import pro.gravit.launchserver.socket.response.admin.ExecCommandResponse; -import pro.gravit.launchserver.socket.response.admin.ProxyCommandResponse; import pro.gravit.launchserver.socket.response.auth.*; import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; @@ -61,58 +54,6 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) { public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { String request = frame.text(); WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class); - if (server.config.netty.proxy.enabled) { - if (server.config.netty.proxy.requests.contains(response.getType())) { - - UUID origRequestUUID = null; - if (response instanceof SimpleResponse) { - SimpleResponse simpleResponse = (SimpleResponse) response; - simpleResponse.server = server; - simpleResponse.service = this; - simpleResponse.ctx = ctx; - if (ip != null) simpleResponse.ip = ip; - else simpleResponse.ip = IOHelper.getIP(ctx.channel().remoteAddress()); - origRequestUUID = simpleResponse.requestUUID; - } - LogHelper.debug("Proxy %s request", response.getType()); - if (client.session == 0) client.session = new Random().nextLong(); - ProxyRequest proxyRequest = new ProxyRequest(response, client.session); - if (response instanceof SimpleResponse) { - ((SimpleResponse) response).requestUUID = proxyRequest.requestUUID; - } - proxyRequest.isCheckSign = client.checkSign; - try { - WebSocketEvent result = proxyRequest.request(); - if (result instanceof AuthRequestEvent) { - LogHelper.debug("Client auth params get successful"); - AuthRequestEvent authRequestEvent = (AuthRequestEvent) result; - client.isAuth = true; - client.session = authRequestEvent.session; - if (authRequestEvent.playerProfile != null) - client.username = authRequestEvent.playerProfile.username; - } - if (result instanceof Request && response instanceof SimpleResponse) { - ((Request) result).requestUUID = origRequestUUID; - } - sendObject(ctx, result); - } catch (RequestException e) { - sendObject(ctx, new ErrorRequestEvent(e.getMessage())); - } catch (Exception e) { - LogHelper.error(e); - RequestEvent event; - if (server.config.netty.sendExceptionEnabled) { - event = new ExceptionEvent(e); - } else { - event = new ErrorRequestEvent("Fatal server error. Contact administrator"); - } - if (response instanceof SimpleResponse) { - event.requestUUID = ((SimpleResponse) response).requestUUID; - } - sendObject(ctx, event); - } - return; - } - } process(ctx, response, client, ip); } @@ -168,7 +109,6 @@ public static void registerResponses() { providers.register("getSecureToken", GetSecureTokenResponse.class); providers.register("verifySecureToken", VerifySecureTokenResponse.class); providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class); - providers.register("proxy", ProxyCommandResponse.class); providers.register("register", RegisterResponse.class); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ProxyCommandResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ProxyCommandResponse.java deleted file mode 100644 index 16e53c88..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ProxyCommandResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package pro.gravit.launchserver.socket.response.admin; - -import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launchserver.socket.Client; -import pro.gravit.launchserver.socket.response.WebSocketServerResponse; -import pro.gravit.launchserver.socket.response.SimpleResponse; - -public class ProxyCommandResponse extends SimpleResponse { - public WebSocketServerResponse response; - public long session; - public boolean isCheckSign; - - @Override - public void execute(ChannelHandlerContext ctx, Client client) throws Exception { - if (!client.proxy) { - sendError("Proxy server error"); - return; - } - Client real_client = server.sessionManager.getOrNewClient(session); - real_client.checkSign = isCheckSign; - response.execute(ctx, real_client); - } - - @Override - public String getType() { - return "proxy"; - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 1e1a2594..32f07b0b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -45,12 +45,11 @@ public AuthResponse(String login, String password, String auth_id, OshiHWID hwid } public String auth_id; - public boolean initProxy; public ConnectTypes authType; public HWID hwid; public enum ConnectTypes { - SERVER, CLIENT, BOT, API + SERVER, CLIENT, API } @Override @@ -111,9 +110,6 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti clientData.username = login; result.accessToken = aresult.accessToken; result.permissions = clientData.permissions; - if (authType == ConnectTypes.BOT && !clientData.permissions.canBot) { - AuthProvider.authError("authType: BOT not allowed for this account"); - } if (authType == ConnectTypes.SERVER && !clientData.permissions.canServer) { AuthProvider.authError("authType: SERVER not allowed for this account"); } @@ -124,10 +120,6 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti } result.session = clientData.session; } - if (initProxy) { - if (!clientData.permissions.canProxy) throw new AuthException("initProxy not allow"); - clientData.proxy = true; - } if (authType != ConnectTypes.API && server.config.protectHandler.allowGetAccessToken(context)) { UUID uuid = pair.handler.auth(aresult); result.playerProfile = ProfileByUUIDResponse.getProfile(uuid, aresult.username, client, clientData.auth.textureProvider); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java b/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java index cd055343..fc6bbe6e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java @@ -20,8 +20,6 @@ public class ClientPermissions { public boolean canUSR3; @LauncherAPI public boolean canBot; - @LauncherAPI - public boolean canProxy; public ClientPermissions(HInput input) throws IOException { this(input.readLong()); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ProxyRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ProxyRequest.java deleted file mode 100644 index ecbc8784..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ProxyRequest.java +++ /dev/null @@ -1,21 +0,0 @@ -package pro.gravit.launcher.request.admin; - -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.WebSocketEvent; -import pro.gravit.launcher.request.websockets.WebSocketRequest; - -public class ProxyRequest extends Request implements WebSocketRequest { - public WebSocketRequest response; - public long session; - public boolean isCheckSign; - - public ProxyRequest(WebSocketRequest response, long session) { - this.response = response; - this.session = session; - } - - @Override - public String getType() { - return "proxy"; - } -}