From b21b6c23624bc4319bcefdf0a90de353dfaec12c Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Mon, 3 Jun 2019 11:50:28 +0300 Subject: [PATCH] =?UTF-8?q?[FEATURE][EXP][NEEDS=20TEST]=20=D0=9E=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=20=D0=BE=D1=82=20=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B8=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B2=20LaunchServer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 31 ++++++++++--------- .../launchserver/auth/AuthProviderPair.java | 5 +-- .../auth/provider/AcceptAuthProvider.java | 2 +- .../auth/provider/AuthProvider.java | 7 +++-- .../auth/provider/AuthProviderResult.java | 4 +-- .../auth/provider/MySQLAuthProvider.java | 5 +-- .../auth/provider/RejectAuthProvider.java | 2 +- .../auth/provider/RequestAuthProvider.java | 5 +-- .../launchserver/binary/ProguardConf.java | 2 +- .../command/basic/TestCommand.java | 3 +- .../command/handler/CommandHandler.java | 3 +- .../command/service/GetModulusCommand.java | 2 +- .../components/CommandRemoverComponent.java | 5 +-- .../gravit/launchserver/socket/Client.java | 6 ++-- .../websocket/LauncherNettyServer.java | 14 +++++---- .../websocket/NettyServerSocketHandler.java | 14 ++++----- .../websocket/WebSocketFrameHandler.java | 10 +++--- .../json/admin/ExecCommandResponse.java | 3 +- .../websocket/json/auth/AuthResponse.java | 27 ++++++++-------- .../json/auth/CheckServerResponse.java | 3 +- .../auth/GetAvailabilityAuthResponse.java | 3 +- .../json/auth/JoinServerResponse.java | 3 +- .../websocket/json/auth/ProfilesResponse.java | 3 +- .../json/auth/RestoreSessionResponse.java | 3 +- .../json/auth/SetProfileResponse.java | 5 ++- .../json/profile/BatchProfileByUsername.java | 5 ++- .../json/profile/ProfileByUUIDResponse.java | 4 +-- .../json/profile/ProfileByUsername.java | 5 ++- .../json/secure/GetSecureTokenResponse.java | 3 +- .../secure/VerifySecureTokenResponse.java | 3 +- .../json/update/LauncherResponse.java | 20 +++++------- .../json/update/UpdateListResponse.java | 3 +- .../websocket/json/update/UpdateResponse.java | 6 ++-- 33 files changed, 106 insertions(+), 113 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index eb8f3e8a..3f0f0010 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -97,11 +97,13 @@ public void reload() throws Exception { try (BufferedReader reader = IOHelper.newReader(configFile)) { config = Launcher.gsonManager.gson.fromJson(reader, Config.class); } + config.server = this; config.verify(); config.init(); } public static final class Config { + private transient LaunchServer server = null; public int legacyPort; private String legacyAddress; @@ -236,30 +238,30 @@ public void verify() { public void init() { Launcher.applyLauncherEnv(env); for (AuthProviderPair provider : auth) { - provider.init(); + provider.init(server); } permissionsHandler.init(); hwidHandler.init(); if (protectHandler != null) { protectHandler.checkLaunchServerLicense(); } - LaunchServer.server.registerObject("permissionsHandler", permissionsHandler); + server.registerObject("permissionsHandler", permissionsHandler); for (AuthProviderPair pair : auth) { - LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); - LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); - LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); + server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); + server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); + server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); } - Arrays.stream(mirrors).forEach(LaunchServer.server.mirrorManager::addMirror); + Arrays.stream(mirrors).forEach(server.mirrorManager::addMirror); } public void close() { try { - LaunchServer.server.unregisterObject("permissionsHandler", permissionsHandler); + server.unregisterObject("permissionsHandler", permissionsHandler); for (AuthProviderPair pair : auth) { - LaunchServer.server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider); - LaunchServer.server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler); - LaunchServer.server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); + server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider); + server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler); + server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); } } catch (Exception e) { LogHelper.error(e); @@ -426,7 +428,7 @@ public static void main(String... args) throws Throwable { public final Path updatesDir; - public static LaunchServer server = null; + //public static LaunchServer server = null; public final Path profilesDir; // Server config @@ -509,7 +511,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException Response.registerResponses(); Component.registerComponents(); ProtectHandler.registerHandlers(); - LaunchServer.server = this; + //LaunchServer.server = this; // Set command handler CommandHandler localCommandHandler; @@ -526,7 +528,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException localCommandHandler = new StdCommandHandler(true); LogHelper.warning("JLine2 isn't in classpath, using std"); } - pro.gravit.launchserver.command.handler.CommandHandler.registerCommands(localCommandHandler); + pro.gravit.launchserver.command.handler.CommandHandler.registerCommands(localCommandHandler, this); commandHandler = localCommandHandler; // Set key pair @@ -568,6 +570,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException try (BufferedReader reader = IOHelper.newReader(configFile)) { config = Launcher.gsonManager.gson.fromJson(reader, Config.class); } + config.server = this; if (!Files.exists(runtimeConfigFile)) { LogHelper.info("Reset LaunchServer runtime config file"); runtime = new LaunchServerRuntimeConfig(); @@ -582,7 +585,7 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException config.verify(); Launcher.applyLauncherEnv(config.env); for (AuthProviderPair provider : config.auth) { - provider.init(); + provider.init(this); } config.permissionsHandler.init(); config.hwidHandler.init(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 334240df..82be2450 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -2,6 +2,7 @@ import java.io.IOException; +import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.provider.AuthProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -21,8 +22,8 @@ public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvi this.name = name; } - public void init() { - provider.init(); + public void init(LaunchServer srv) { + provider.init(srv); handler.init(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java index e471a35f..44dd7c64 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AcceptAuthProvider.java @@ -6,7 +6,7 @@ public final class AcceptAuthProvider extends AuthProvider { @Override public AuthProviderResult auth(String login, String password, String ip) { - return new AuthProviderResult(login, SecurityHelper.randomStringToken()); // Same as login + return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); // Same as login } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java index 54cec6ca..c19e9742 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProvider.java @@ -2,13 +2,14 @@ import java.io.IOException; +import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.utils.ProviderMap; public abstract class AuthProvider implements AutoCloseable { public static ProviderMap providers = new ProviderMap<>("AuthProvider"); private static boolean registredProv = false; - + protected transient LaunchServer srv = null; public static AuthProviderResult authError(String message) throws AuthException { throw new AuthException(message); } @@ -34,7 +35,7 @@ public void preAuth(String login, String password, String customText, String ip) @Override public abstract void close() throws IOException; - public void init() { - + public void init(LaunchServer srv) { + this.srv = srv; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java index b2502668..291835a1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/AuthProviderResult.java @@ -9,10 +9,10 @@ public class AuthProviderResult { public final String accessToken; public final ClientPermissions permissions; - public AuthProviderResult(String username, String accessToken) { + public AuthProviderResult(String username, String accessToken, LaunchServer server) { this.username = username; this.accessToken = accessToken; - permissions = LaunchServer.server.config.permissionsHandler.getPermissions(username); + permissions = server.config.permissionsHandler.getPermissions(username); } public AuthProviderResult(String username, String accessToken, ClientPermissions permissions) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java index 227d5562..cac22613 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -21,7 +21,8 @@ public final class MySQLAuthProvider extends AuthProvider { private boolean usePermission; @Override - public void init() { + public void init(LaunchServer srv) { + super.init(srv); if (query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null"); if (message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null"); if (mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null"); @@ -38,7 +39,7 @@ public AuthProviderResult auth(String login, String password, String ip) throws // Execute SQL query s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { - return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : LaunchServer.server.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message); + return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : srv.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java index 52aebcac..4a707288 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -23,7 +23,7 @@ public AuthProviderResult auth(String login, String password, String ip) throws if (whitelist != null) { for (String username : whitelist) { if (login.equals(username)) { - return new AuthProviderResult(login, SecurityHelper.randomStringToken()); + return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv); } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java index 103aa33c..97211b83 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/RequestAuthProvider.java @@ -19,7 +19,8 @@ public final class RequestAuthProvider extends AuthProvider { private boolean usePermission; @Override - public void init() { + public void init(LaunchServer srv) { + super.init(srv); if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null"); if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null"); pattern = Pattern.compile(response); @@ -32,7 +33,7 @@ public AuthProviderResult auth(String login, String password, String ip) throws // Match username Matcher matcher = pattern.matcher(currentResponse); return matcher.matches() && matcher.groupCount() >= 1 ? - new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(Long.getLong(matcher.group("permission"))) : LaunchServer.server.config.permissionsHandler.getPermissions(login)) : + new AuthProviderResult(matcher.group("username"), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(Long.getLong(matcher.group("permission"))) : srv.config.permissionsHandler.getPermissions(login)) : authError(currentResponse); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java index 5b683d03..c4149bd8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java @@ -71,7 +71,7 @@ public void genWords(boolean force) throws IOException { SecureRandom rand = SecurityHelper.newRandom(); rand.setSeed(SecureRandom.getSeed(32)); try (PrintWriter out = new PrintWriter(new OutputStreamWriter(IOHelper.newOutput(words), IOHelper.UNICODE_CHARSET))) { - String projectName = LaunchServer.server.config.projectName.replaceAll("\\W", ""); + String projectName = srv.config.projectName.replaceAll("\\W", ""); String lowName = projectName.toLowerCase(); String upName = projectName.toUpperCase(); for (int i = 0; i < Short.MAX_VALUE; i++) out.println(generateString(rand, lowName, upName, 3)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java index 26d9407a..7acf72b9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/TestCommand.java @@ -4,7 +4,6 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.websocket.NettyServerSocketHandler; -import pro.gravit.launchserver.websocket.WebSocketFrameHandler; import pro.gravit.utils.helper.CommonHelper; public class TestCommand extends Command { @@ -36,7 +35,7 @@ public void invoke(String... args) throws Exception { handler.close(); } if (args[0].equals("eventAll")) { - WebSocketFrameHandler.service.sendObjectAll(new PingEvent()); + handler.nettyServer.frameHandler.service.sendObjectAll(new PingEvent()); } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index 8e28daf8..43a307ab 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -48,8 +48,7 @@ import pro.gravit.utils.command.basic.HelpCommand; public abstract class CommandHandler extends pro.gravit.utils.command.CommandHandler { - public static void registerCommands(pro.gravit.utils.command.CommandHandler handler) { - LaunchServer server = LaunchServer.server; + public static void registerCommands(pro.gravit.utils.command.CommandHandler handler, LaunchServer server) { BaseCommandCategory basic = new BaseCommandCategory(); // Register basic commands basic.registerCommand("help", new HelpCommand(handler)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java index c4e1310d..c40eda10 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java @@ -21,6 +21,6 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - LogHelper.info("You publickey modulus: %s", LaunchServer.server.publicKey.getModulus().toString(16)); + LogHelper.info("You publickey modulus: %s", server.publicKey.getModulus().toString(16)); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java index c5a3297c..3332444e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java @@ -9,10 +9,11 @@ public class CommandRemoverComponent extends Component implements AutoCloseable { public String[] removeList = new String[]{}; public transient Map commandsList = new HashMap<>(); + private transient LaunchServer server = null; @Override public void preInit(LaunchServer launchServer) { - + server = launchServer; } @Override @@ -32,7 +33,7 @@ public void postInit(LaunchServer launchServer) { @Override public void close() { for (Map.Entry e : commandsList.entrySet()) { - LaunchServer.server.commandHandler.registerCommand(e.getKey(), e.getValue()); + server.commandHandler.registerCommand(e.getKey(), e.getValue()); } } } 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 b1b423e5..b845d644 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -38,10 +38,10 @@ public void up() { timestamp = System.currentTimeMillis(); } - public void updateAuth() { + public void updateAuth(LaunchServer server) { if (!isAuth) return; - if (auth_id.isEmpty()) auth = LaunchServer.server.config.getAuthProviderPair(); - else auth = LaunchServer.server.config.getAuthProviderPair(auth_id); + if (auth_id.isEmpty()) auth = server.config.getAuthProviderPair(); + else auth = server.config.getAuthProviderPair(auth_id); } public enum Type { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/LauncherNettyServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/LauncherNettyServer.java index 1248eafc..d127069e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/LauncherNettyServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/LauncherNettyServer.java @@ -26,10 +26,11 @@ public class LauncherNettyServer implements AutoCloseable { public final ServerBootstrap serverBootstrap; public final EventLoopGroup bossGroup; public final EventLoopGroup workerGroup; + public WebSocketFrameHandler frameHandler = null; private static final String WEBSOCKET_PATH = "/api"; - public LauncherNettyServer() { - LaunchServer.NettyConfig config = LaunchServer.server.config.netty; + public LauncherNettyServer(LaunchServer server) { + LaunchServer.NettyConfig config = server.config.netty; bossGroup = new NioEventLoopGroup(config.performance.bossThread); workerGroup = new NioEventLoopGroup(config.performance.workerThread); serverBootstrap = new ServerBootstrap(); @@ -44,13 +45,14 @@ public void initChannel(NioSocketChannel ch) { //p.addLast(new LoggingHandler(LogLevel.INFO)); pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); - if (LaunchServer.server.config.netty.ipForwarding) + if (server.config.netty.ipForwarding) pipeline.addLast(new NettyIpForwardHandler(context)); pipeline.addLast(new WebSocketServerCompressionHandler()); pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true)); - if (LaunchServer.server.config.netty.fileServerEnabled) - pipeline.addLast(new FileServerHandler(LaunchServer.server.updatesDir, true)); - pipeline.addLast(new WebSocketFrameHandler(context)); + if (server.config.netty.fileServerEnabled) + pipeline.addLast(new FileServerHandler(server.updatesDir, true)); + frameHandler = new WebSocketFrameHandler(context, server); + pipeline.addLast(frameHandler); } }); if (config.proxy != null && config.proxy.enabled) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/NettyServerSocketHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/NettyServerSocketHandler.java index 3ca93366..79e7c791 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/NettyServerSocketHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/NettyServerSocketHandler.java @@ -33,11 +33,11 @@ @SuppressWarnings({"unused", "rawtypes"}) public final class NettyServerSocketHandler implements Runnable, AutoCloseable { - private static SSLServerSocketFactory ssf; + private SSLServerSocketFactory ssf; public volatile boolean logConnections = Boolean.getBoolean("launcher.logConnections"); - public static LauncherNettyServer nettyServer; + public LauncherNettyServer nettyServer; private final AtomicReference serverSocket = new AtomicReference<>(); @@ -47,9 +47,10 @@ public final class NettyServerSocketHandler implements Runnable, AutoCloseable { private Set sockets; private volatile Listener listener; + private transient final LaunchServer server; + public NettyServerSocketHandler(LaunchServer server) { - // Instance - LaunchServer server1 = server; + this.server = server; } @Override @@ -109,9 +110,8 @@ public void run() { LogHelper.info("Starting netty server socket thread"); //SSLEngine engine = sc.createSSLEngine(); //engine.setUseClientMode(false); - WebSocketFrameHandler.server = LaunchServer.server; - nettyServer = new LauncherNettyServer(); - for (LaunchServer.NettyBindAddress address : LaunchServer.server.config.netty.binds) { + nettyServer = new LauncherNettyServer(server); + for (LaunchServer.NettyBindAddress address : server.config.netty.binds) { nettyServer.bind(new InetSocketAddress(address.address, address.port)); } /* diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/WebSocketFrameHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/WebSocketFrameHandler.java index 54fa7bfb..01cbd1b8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/WebSocketFrameHandler.java @@ -20,19 +20,21 @@ import pro.gravit.utils.helper.LogHelper; public class WebSocketFrameHandler extends SimpleChannelInboundHandler { - public static LaunchServer server; + public final LaunchServer srv; public static GsonBuilder builder = CommonHelper.newBuilder(); - public static WebSocketService service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), LaunchServer.server, builder); + public final WebSocketService service; public NettyConnectContext context; - public WebSocketFrameHandler(NettyConnectContext context) { + public WebSocketFrameHandler(NettyConnectContext context, LaunchServer srv) { this.context = context; + this.srv = srv; + service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), srv, builder); + service.registerResponses(); } private Client client; static { - service.registerResponses(); } public void setClient(Client client) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/admin/ExecCommandResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/admin/ExecCommandResponse.java index 37a44d66..1af1f411 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/admin/ExecCommandResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/admin/ExecCommandResponse.java @@ -2,7 +2,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.ExecCommandRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -20,7 +19,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { sendError("Access denied"); return; } - LaunchServer.server.commandHandler.eval(cmd, false); + server.commandHandler.eval(cmd, false); sendResult(new ExecCommandRequestEvent(true)); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/AuthResponse.java index d6162bb1..4e8bdbfa 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/AuthResponse.java @@ -12,7 +12,6 @@ import pro.gravit.launcher.OshiHWID; import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.hwid.HWIDException; @@ -68,13 +67,13 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti } if (password == null) { try { - password = IOHelper.decode(SecurityHelper.newRSADecryptCipher(LaunchServer.server.privateKey). + password = IOHelper.decode(SecurityHelper.newRSADecryptCipher(server.privateKey). doFinal(encryptedPassword)); } catch (IllegalBlockSizeException | BadPaddingException ignored) { throw new AuthException("Password decryption error"); } } - clientData.permissions = LaunchServer.server.config.permissionsHandler.getPermissions(login); + clientData.permissions = server.config.permissionsHandler.getPermissions(login); if (authType == ConnectTypes.BOT && !clientData.permissions.canBot) { AuthProvider.authError("authType: BOT not allowed for this account"); } @@ -82,22 +81,22 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti AuthProvider.authError("authType: SERVER not allowed for this account"); } AuthProviderPair pair; - if (auth_id.isEmpty()) pair = LaunchServer.server.config.getAuthProviderPair(); - else pair = LaunchServer.server.config.getAuthProviderPair(auth_id); + if (auth_id.isEmpty()) pair = server.config.getAuthProviderPair(); + else pair = server.config.getAuthProviderPair(auth_id); AuthContext context = new AuthContext(0, login, password.length(), customText, client, ip, null, false); AuthProvider provider = pair.provider; - LaunchServer.server.authHookManager.preHook.hook(context, clientData); + server.authHookManager.preHook.hook(context, clientData); provider.preAuth(login, password, customText, ip); AuthProviderResult aresult = provider.auth(login, password, ip); if (!VerifyHelper.isValidUsername(aresult.username)) { AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username)); return; } - Collection profiles = LaunchServer.server.getProfiles(); + Collection profiles = server.getProfiles(); for (ClientProfile p : profiles) { if (p.getTitle().equals(client)) { if (!p.isWhitelistContains(login)) { - throw new AuthException(LaunchServer.server.config.whitelistRejectString); + throw new AuthException(server.config.whitelistRejectString); } clientData.profile = p; } @@ -106,18 +105,18 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti // throw new AuthException("You profile not found"); //} if (authType == ConnectTypes.CLIENT) - LaunchServer.server.config.hwidHandler.check(hwid, aresult.username); - LaunchServer.server.authHookManager.postHook.hook(context, clientData); + server.config.hwidHandler.check(hwid, aresult.username); + server.authHookManager.postHook.hook(context, clientData); clientData.isAuth = true; clientData.permissions = aresult.permissions; clientData.auth_id = auth_id; - clientData.updateAuth(); + clientData.updateAuth(server); result.accessToken = aresult.accessToken; result.permissions = clientData.permissions; if (getSession) { if (clientData.session == 0) { clientData.session = random.nextLong(); - LaunchServer.server.sessionManager.addClient(clientData); + server.sessionManager.addClient(clientData); } result.session = clientData.session; } @@ -125,9 +124,9 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti if (!clientData.permissions.canProxy) throw new AuthException("initProxy not allow"); clientData.proxy = true; } - if (LaunchServer.server.config.protectHandler.allowGetAccessToken(context)) { + if (server.config.protectHandler.allowGetAccessToken(context)) { UUID uuid = pair.handler.auth(aresult); - result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, aresult.username, client, clientData.auth.textureProvider); + result.playerProfile = ProfileByUUIDResponse.getProfile(server, uuid, aresult.username, client, clientData.auth.textureProvider); LogHelper.debug("Auth: %s accessToken %s uuid: %s", login, result.accessToken, uuid.toString()); } sendResult(result); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/CheckServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/CheckServerResponse.java index 30436894..02f65056 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/CheckServerResponse.java @@ -2,7 +2,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.CheckServerRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -27,7 +26,7 @@ public void execute(ChannelHandlerContext ctx, Client pClient) { server.authHookManager.checkServerHook.hook(this, pClient); result.uuid = pClient.auth.handler.checkServer(username, serverID); if (result.uuid != null) - result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, result.uuid, username, client, pClient.auth.textureProvider); + result.playerProfile = ProfileByUUIDResponse.getProfile(server, result.uuid, username, client, pClient.auth.textureProvider); LogHelper.debug("checkServer: %s uuid: %s serverID: %s", result.playerProfile.username, result.uuid.toString(), serverID); } catch (AuthException | HookException e) { sendError(e.getMessage()); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/GetAvailabilityAuthResponse.java index b6efefbe..5a855a60 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/GetAvailabilityAuthResponse.java @@ -5,7 +5,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -19,7 +18,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { List list = new ArrayList<>(); - for (AuthProviderPair pair : LaunchServer.server.config.auth) { + for (AuthProviderPair pair : server.config.auth) { list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName)); } sendResult(new GetAvailabilityAuthRequestEvent(list)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/JoinServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/JoinServerResponse.java index d0471bbe..24e814c3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/JoinServerResponse.java @@ -2,7 +2,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.JoinServerRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -26,7 +25,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { server.authHookManager.joinServerHook.hook(this, client); if (client.auth == null) { LogHelper.warning("Client auth is null. Using default."); - success = LaunchServer.server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID); + success = server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID); } else success = client.auth.handler.joinServer(username, accessToken, serverID); LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID); } catch (AuthException | HookException e) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/ProfilesResponse.java index 9174f8f2..dfff2930 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/ProfilesResponse.java @@ -3,7 +3,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launcher.events.request.ProfilesRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -19,6 +18,6 @@ public void execute(ChannelHandlerContext ctx, Client client) { service.sendObject(ctx, new ErrorRequestEvent("Access denied")); return; } - sendResult(new ProfilesRequestEvent(LaunchServer.server.getProfiles())); + sendResult(new ProfilesRequestEvent(server.getProfiles())); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/RestoreSessionResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/RestoreSessionResponse.java index ce214fe6..bff4b6ab 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/RestoreSessionResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/RestoreSessionResponse.java @@ -3,7 +3,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.RestoreSessionRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.WebSocketFrameHandler; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -19,7 +18,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - Client rClient = LaunchServer.server.sessionManager.getClient(session); + Client rClient = server.sessionManager.getClient(session); if (rClient == null) { sendError("Session invalid"); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/SetProfileResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/SetProfileResponse.java index 77e3fce7..206ac069 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/SetProfileResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/auth/SetProfileResponse.java @@ -5,7 +5,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.SetProfileRequestEvent; import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; import pro.gravit.utils.HookException; @@ -29,11 +28,11 @@ public void execute(ChannelHandlerContext ctx, Client client) { } catch (HookException e) { sendError(e.getMessage()); } - Collection profiles = LaunchServer.server.getProfiles(); + Collection profiles = server.getProfiles(); for (ClientProfile p : profiles) { if (p.getTitle().equals(this.client)) { if (!p.isWhitelistContains(client.username)) { - sendError(LaunchServer.server.config.whitelistRejectString); + sendError(server.config.whitelistRejectString); return; } client.profile = p; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/BatchProfileByUsername.java index 99612ac4..7e8e86ad 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/BatchProfileByUsername.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/BatchProfileByUsername.java @@ -5,7 +5,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; import pro.gravit.utils.helper.LogHelper; @@ -31,9 +30,9 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { UUID uuid; if (client.auth == null) { LogHelper.warning("Client auth is null. Using default."); - uuid = LaunchServer.server.config.getAuthProviderPair().handler.usernameToUUID(list[i].username); + uuid = server.config.getAuthProviderPair().handler.usernameToUUID(list[i].username); } else uuid = client.auth.handler.usernameToUUID(list[i].username); - result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, list[i].username, list[i].client, client.auth.textureProvider); + result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(server, uuid, list[i].username, list[i].client, client.auth.textureProvider); } sendResult(result); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/ProfileByUUIDResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/ProfileByUUIDResponse.java index 232dba9f..d2a23b7d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/ProfileByUUIDResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/ProfileByUUIDResponse.java @@ -50,8 +50,8 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { String username; if (client.auth == null) { LogHelper.warning("Client auth is null. Using default."); - username = LaunchServer.server.config.getAuthProviderPair().handler.uuidToUsername(uuid); + username = server.config.getAuthProviderPair().handler.uuidToUsername(uuid); } else username = client.auth.handler.uuidToUsername(uuid); - sendResult(new ProfileByUUIDRequestEvent(getProfile(LaunchServer.server, uuid, username, this.client, client.auth.textureProvider))); + sendResult(new ProfileByUUIDRequestEvent(getProfile(server, uuid, username, this.client, client.auth.textureProvider))); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/ProfileByUsername.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/ProfileByUsername.java index 315ab55e..e50d5b9f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/ProfileByUsername.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/profile/ProfileByUsername.java @@ -4,7 +4,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; import pro.gravit.utils.helper.LogHelper; @@ -23,8 +22,8 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { UUID uuid; if (client.auth == null) { LogHelper.warning("Client auth is null. Using default."); - uuid = LaunchServer.server.config.getAuthProviderPair().handler.usernameToUUID(username); + uuid = server.config.getAuthProviderPair().handler.usernameToUUID(username); } else uuid = client.auth.handler.usernameToUUID(username); - sendResult(new ProfileByUsernameRequestEvent(ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, username, this.client, client.auth.textureProvider))); + sendResult(new ProfileByUsernameRequestEvent(ProfileByUUIDResponse.getProfile(server, uuid, username, this.client, client.auth.textureProvider))); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/secure/GetSecureTokenResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/secure/GetSecureTokenResponse.java index 3b44fbea..238683ca 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/secure/GetSecureTokenResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/secure/GetSecureTokenResponse.java @@ -2,7 +2,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.GetSecureTokenRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -14,7 +13,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - String secureToken = LaunchServer.server.config.protectHandler.generateClientSecureToken(); + String secureToken = server.config.protectHandler.generateClientSecureToken(); client.verifyToken = secureToken; sendResult(new GetSecureTokenRequestEvent(secureToken)); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/secure/VerifySecureTokenResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/secure/VerifySecureTokenResponse.java index abf582a6..44adff98 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/secure/VerifySecureTokenResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/secure/VerifySecureTokenResponse.java @@ -2,7 +2,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.VerifySecureTokenRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -16,7 +15,7 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) { - boolean success = LaunchServer.server.config.protectHandler.verifyClientSecureToken(secureToken, client.verifyToken); + boolean success = server.config.protectHandler.verifyClientSecureToken(secureToken, client.verifyToken); if (success) client.isSecure = true; sendResult(new VerifySecureTokenRequestEvent(success)); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/LauncherResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/LauncherResponse.java index c3eabfc7..d029228f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/LauncherResponse.java @@ -5,7 +5,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.LauncherRequestEvent; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; import pro.gravit.utils.Version; @@ -15,9 +14,6 @@ public class LauncherResponse extends SimpleResponse { public String hash; public byte[] digest; public int launcher_type; - //REPLACED TO REAL URL - public static final String JAR_URL = LaunchServer.server.config.netty.launcherURL; - public static final String EXE_URL = LaunchServer.server.config.netty.launcherEXEURL; @Override public String getType() { @@ -33,23 +29,23 @@ public void execute(ChannelHandlerContext ctx, Client client) { bytes = digest; if (launcher_type == 1) // JAR { - byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest(); - if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, JAR_URL)); + byte[] hash = server.launcherBinary.getBytes().getDigest(); + if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, server.config.netty.launcherURL)); if (Arrays.equals(bytes, hash)) { client.checkSign = true; - sendResult(new LauncherRequestEvent(false, JAR_URL)); + sendResult(new LauncherRequestEvent(false, server.config.netty.launcherURL)); } else { - sendResultAndClose(new LauncherRequestEvent(true, JAR_URL)); + sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherURL)); } } else if (launcher_type == 2) //EXE { - byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest(); - if (hash == null) sendResultAndClose(new LauncherRequestEvent(true, EXE_URL)); + byte[] hash = server.launcherEXEBinary.getBytes().getDigest(); + if (hash == null) sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL)); if (Arrays.equals(bytes, hash)) { client.checkSign = true; - sendResult(new LauncherRequestEvent(false, EXE_URL)); + sendResult(new LauncherRequestEvent(false, server.config.netty.launcherEXEURL)); } else { - sendResultAndClose(new LauncherRequestEvent(true, EXE_URL)); + sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL)); } } else sendError("Request launcher type error"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/UpdateListResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/UpdateListResponse.java index 00a5e83d..59ab9b44 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/UpdateListResponse.java @@ -7,7 +7,6 @@ import pro.gravit.launcher.events.request.UpdateListRequestEvent; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.serialize.signed.SignedObjectHolder; -import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.websocket.json.SimpleResponse; @@ -25,7 +24,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { return; } HashSet set = new HashSet<>(); - for (Map.Entry> entry : LaunchServer.server.updatesDirMap.entrySet()) + for (Map.Entry> entry : server.updatesDirMap.entrySet()) set.add(entry.getKey()); sendResult(new UpdateListRequestEvent(set)); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/UpdateResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/UpdateResponse.java index 4bf21082..029181db 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/json/update/UpdateResponse.java @@ -25,7 +25,7 @@ public void execute(ChannelHandlerContext ctx, Client client) { return; } if (!client.permissions.canAdmin) { - for (ClientProfile p : LaunchServer.server.getProfiles()) { + for (ClientProfile p : server.getProfiles()) { if (!client.profile.getTitle().equals(p.getTitle())) continue; if (!p.isWhitelistContains(client.username)) { service.sendObject(ctx, new ErrorRequestEvent("You don't download this folder")); @@ -33,12 +33,12 @@ public void execute(ChannelHandlerContext ctx, Client client) { } } } - SignedObjectHolder dir = LaunchServer.server.updatesDirMap.get(dirName); + SignedObjectHolder dir = server.updatesDirMap.get(dirName); if (dir == null) { service.sendObject(ctx, new ErrorRequestEvent(String.format("Directory %s not found", dirName))); return; } - String url = LaunchServer.server.config.netty.downloadURL.replace("%dirname%", dirName); + String url = server.config.netty.downloadURL.replace("%dirname%", dirName); boolean zip = false; if (server.config.netty.bindings.get(dirName) != null) { LaunchServer.NettyUpdatesBind bind = server.config.netty.bindings.get(dirName);