diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index df4cb8c7..8631d732 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -185,8 +185,10 @@ public class NettyConfig { public String bindAddress; public int port; + public boolean clientEnabled; public String launcherURL; public String launcherEXEURL; + public String address; } public class GuardLicenseConf { @@ -542,7 +544,7 @@ private void generateConfigIfNotExists() throws IOException { // Create new config LogHelper.info("Creating LaunchServer config"); Config newConfig = new Config(); - newConfig.mirrors = new String[]{"http://mirror.gravitlauncher.ml/"}; + newConfig.mirrors = new String[]{"http://mirror.gravitlauncher.ml/","https://mirror.gravit.pro/"}; newConfig.launch4j = new ExeConf(); newConfig.launch4j.copyright = "© GravitLauncher Team"; newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Launcher.getVersion().getVersionString()); @@ -567,6 +569,11 @@ private void generateConfigIfNotExists() throws IOException { newConfig.binaryName = "Launcher"; newConfig.whitelistRejectString = "Вас нет в белом списке"; + newConfig.netty = new NettyConfig(); + newConfig.netty.address = "ws://localhost:9274/api"; + newConfig.netty.clientEnabled = false; + newConfig.netty.port = 9274; + newConfig.threadCoreCount = 0; // on your own newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java index 70d40735..d6d683c0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java @@ -70,6 +70,11 @@ public void setAddress(String address) { body.append(address); body.append("\";"); } + public void setNettyAddress(String address) { + body.append("this.nettyAddress = \""); + body.append(address); + body.append("\";"); + } public void setProjectName(String name) { body.append("this.projectname = \""); @@ -134,6 +139,11 @@ public void setDownloadJava(boolean b) { body.append(b ? "true" : "false"); body.append(";"); } + public void setNettyEnabled(boolean b) { + body.append("this.isNettyEnabled = "); + body.append(b ? "true" : "false"); + body.append(";"); + } public void setWarningMissArchJava(boolean b) { body.append("this.isWarningMissArchJava = "); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java index e61e297b..7c152f26 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -130,14 +130,19 @@ public Path process(Path inputJar) throws IOException { server.buildHookManager.hook(context); jaConfigurator.setAddress(server.config.getAddress()); jaConfigurator.setPort(server.config.port); - if(server.config.netty != null) + jaConfigurator.setNettyEnabled(server.config.netty.clientEnabled); + if(server.config.netty.clientEnabled) + { jaConfigurator.setNettyPort(server.config.netty.port); + jaConfigurator.setNettyAddress(server.config.netty.address); + } if(server.config.guardLicense != null) jaConfigurator.setGuardLicense(server.config.guardLicense.name, server.config.guardLicense.key, server.config.guardLicense.encryptKey); jaConfigurator.setProjectName(server.config.projectName); jaConfigurator.setSecretKey(SecurityHelper.randomStringAESKey()); jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512)); jaConfigurator.setUsingWrapper(server.config.isUsingWrapper); + jaConfigurator.setWarningMissArchJava(server.config.isWarningMissArchJava); jaConfigurator.setDownloadJava(server.config.isDownloadJava); jaConfigurator.setEnv(server.config.env); server.buildHookManager.registerAllClientModuleClass(jaConfigurator); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index c3d18b6c..1da94327 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -124,6 +124,7 @@ protected CommandHandler(LaunchServer server) { registerCommand("serverStatus", new ServerStatusCommand(server)); registerCommand("checkInstall", new CheckInstallCommand(server)); registerCommand("multi", new MultiCommand(server)); + registerCommand("getModulus", new GetModulusCommand(server)); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetModulusCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetModulusCommand.java new file mode 100644 index 00000000..3696791f --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetModulusCommand.java @@ -0,0 +1,27 @@ +package ru.gravit.launchserver.command.service; + +import io.netty.handler.codec.base64.Base64; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class GetModulusCommand extends Command { + public GetModulusCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return null; + } + + @Override + public void invoke(String... args) throws Exception { + LogHelper.info("You publickey modulus: ", LaunchServer.server.publicKey.getModulus().toString(16)); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java index ffebe4cc..e9b5db5e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java @@ -21,6 +21,7 @@ import ru.gravit.launchserver.socket.websocket.json.auth.*; import ru.gravit.launchserver.socket.websocket.json.update.LauncherResponse; import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse; +import ru.gravit.launchserver.socket.websocket.json.update.UpdateResponse; import ru.gravit.utils.helper.LogHelper; import java.lang.reflect.Type; @@ -79,6 +80,7 @@ public void registerResponses() { registerResponse("cmdExec", ExecCommandResponse.class); registerResponse("setProfile", SetProfileResponse.class); registerResponse("addLogListener", AddLogListenerResponse.class); + registerResponse("update", UpdateResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java new file mode 100644 index 00000000..6c0502c6 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java @@ -0,0 +1,36 @@ +package ru.gravit.launchserver.socket.websocket.json.update; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.ErrorRequestEvent; +import ru.gravit.launcher.events.request.UpdateRequestEvent; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +public class UpdateResponse implements JsonResponseInterface { + public String dir; + @Override + public String getType() { + return "update"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + if (!client.isAuth || client.type != Client.Type.USER || client.profile == null) { + service.sendObject(ctx,new ErrorRequestEvent("Assess denied")); + return; + } + if (!client.permissions.canAdmin) { + for (ClientProfile p : LaunchServer.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")); + return; + } + } + } + service.sendObject(ctx,new UpdateRequestEvent(LaunchServer.server.updatesDirMap.get(dir).object)); + } +} diff --git a/Launcher/runtime/dialog/dialog.js b/Launcher/runtime/dialog/dialog.js index 3007dea9..dfa26435 100644 --- a/Launcher/runtime/dialog/dialog.js +++ b/Launcher/runtime/dialog/dialog.js @@ -198,9 +198,9 @@ function verifyLauncher(e) { } overlay.swap(0, processing.overlay, function(event) makeProfilesRequest(function(result) { settings.lastProfiles = result.profiles; - options.load(); // Update profiles list and hide overlay updateProfilesList(result.profiles); + options.load(); overlay.hide(0, function() { if (cliParams.autoLogin) { goAuth(null); @@ -237,7 +237,7 @@ var digest = profile.isUpdateFastCheck(); makeSetProfileRequest(profile, function() { ClientLauncher.setProfile(profile); makeUpdateRequest(assetDirName, assetDir, assetMatcher, digest, function(assetHDir) { - settings.lastHDirs.put(assetDirName, assetHDir); + settings.lastHDirs.put(assetDirName, assetHDir.hdir); // Update client dir update.resetOverlay("Обновление файлов клиента"); @@ -245,8 +245,8 @@ var digest = profile.isUpdateFastCheck(); var clientDir = settings.updatesDir.resolve(clientDirName); var clientMatcher = profile.getClientUpdateMatcher(); makeUpdateRequest(clientDirName, clientDir, clientMatcher, digest, function(clientHDir) { - settings.lastHDirs.put(clientDirName, clientHDir); - doLaunchClient(assetDir, assetHDir, clientDir, clientHDir, profile, pp, accessToken); + settings.lastHDirs.put(clientDirName, clientHDir.hdir); + doLaunchClient(assetDir, assetHDir.hdir, clientDir, clientHDir.hdir, profile, pp, accessToken); }); }); }); diff --git a/Launcher/runtime/dialog/overlay/options/options.js b/Launcher/runtime/dialog/overlay/options/options.js index 336c99b8..6430b1f7 100644 --- a/Launcher/runtime/dialog/overlay/options/options.js +++ b/Launcher/runtime/dialog/overlay/options/options.js @@ -100,7 +100,7 @@ var options = { var checkBoxList = new java.util.ArrayList; list.forEach(function(modFile) { var modName = modFile.name, modDescription = "", subLevel = 1; - if(!modFile.isVisible) + if(!modFile.visible) { LogHelper.debug("optionalMod %s hidden",modFile.name); return; diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index ac486aee..840f51ff 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -14,7 +14,6 @@ import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.*; @@ -298,7 +297,7 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl @LauncherAPI public static Process launch( - SignedObjectHolder assetHDir, SignedObjectHolder clientHDir, + HashedDir assetHDir, HashedDir clientHDir, ClientProfile profile, Params params, boolean pipeOutput) throws Throwable { // Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars) LogHelper.debug("Writing ClientLauncher params"); @@ -411,8 +410,7 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Reading ClientLauncher params"); Params params; ClientProfile profile; - SignedObjectHolder assetHDir, clientHDir; - RSAPublicKey publicKey = Launcher.getConfig().publicKey; + HashedDir assetHDir, clientHDir; try { try (Socket socket = IOHelper.newSocket()) { socket.connect(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT)); @@ -421,8 +419,8 @@ public static void main(String... args) throws Throwable { profile = gson.fromJson(input.readString(0), ClientProfile.class); // Read hdirs - assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); - clientHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); + assetHDir = new HashedDir(input); + clientHDir = new HashedDir(input); } } } catch (IOException ex) { @@ -457,28 +455,27 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Starting JVM and client WatchService"); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); FileNameMatcher clientMatcher = profile.getClientUpdateMatcher(); - try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir.object, assetMatcher, digest); - DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir.object, clientMatcher, digest)) { + try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir, assetMatcher, digest); + DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir, clientMatcher, digest)) { // Verify current state of all dirs //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); - HashedDir hdir = clientHDir.object; //for (OptionalFile s : Launcher.profile.getOptional()) { // if (params.updateOptional.contains(s)) s.mark = true; // else hdir.removeR(s.file); //} - Launcher.profile.pushOptionalFile(hdir,false); - verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); - verifyHDir(params.clientDir, hdir, clientMatcher, digest); + Launcher.profile.pushOptionalFile(clientHDir,false); Launcher.modulesManager.postInitModules(); // Start WatchService, and only then client CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); + verifyHDir(params.assetDir, assetHDir, assetMatcher, digest); + verifyHDir(params.clientDir, clientHDir, clientMatcher, digest); launch(profile, params); } } @LauncherAPI - public void launchLocal(SignedObjectHolder assetHDir, SignedObjectHolder clientHDir, + public void launchLocal(HashedDir assetHDir, HashedDir clientHDir, ClientProfile profile, Params params) throws Throwable { RSAPublicKey publicKey = Launcher.getConfig().publicKey; LogHelper.debug("Verifying ClientLauncher sign and classpath"); @@ -497,17 +494,17 @@ public void launchLocal(SignedObjectHolder assetHDir, SignedObjectHol LogHelper.debug("Starting JVM and client WatchService"); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); FileNameMatcher clientMatcher = profile.getClientUpdateMatcher(); - try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir.object, assetMatcher, digest); - DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir.object, clientMatcher, digest)) { + try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir, assetMatcher, digest); + DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir, clientMatcher, digest)) { // Verify current state of all dirs //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); - HashedDir hdir = clientHDir.object; + HashedDir hdir = clientHDir; //for (OptionalFile s : Launcher.profile.getOptional()) { // if (params.updateOptional.contains(s)) s.mark = true; // else hdir.removeR(s.file); //} Launcher.profile.pushOptionalFile(hdir,false); - verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); + verifyHDir(params.assetDir, assetHDir, assetMatcher, digest); verifyHDir(params.clientDir, hdir, clientMatcher, digest); Launcher.modulesManager.postInitModules(); // Start WatchService, and only then client diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java index 1921204c..84d63efd 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java @@ -6,7 +6,6 @@ import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.utils.helper.*; import javax.crypto.BadPaddingException; @@ -14,14 +13,13 @@ import java.io.IOException; import java.nio.file.Path; import java.security.SignatureException; -import java.security.interfaces.RSAPublicKey; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; public class LauncherSettings { - public static int settingsMagic = 0xc0de9; + public static int settingsMagic = 0xc0dea; @LauncherAPI public Path file = DirBridge.dir.resolve("settings.bin"); @LauncherAPI @@ -46,7 +44,7 @@ public class LauncherSettings { @LauncherAPI public List lastProfiles = new LinkedList<>(); @LauncherAPI - public Map> lastHDirs = new HashMap<>(16); + public Map lastHDirs = new HashMap<>(16); @LauncherAPI public void load() throws SignatureException { @@ -103,7 +101,6 @@ public void read(HInput input) throws IOException, SignatureException { setRAM(input.readLength(JVMHelper.RAM)); // Offline cache - RSAPublicKey publicKey = Launcher.getConfig().publicKey; lastDigest = input.readBoolean() ? input.readByteArray(0) : null; lastProfiles.clear(); int lastProfilesCount = input.readLength(0); @@ -114,8 +111,8 @@ public void read(HInput input) throws IOException, SignatureException { int lastHDirsCount = input.readLength(0); for (int i = 0; i < lastHDirsCount; i++) { String name = IOHelper.verifyFileName(input.readString(255)); - VerifyHelper.putIfAbsent(lastHDirs, name, new SignedObjectHolder<>(input, publicKey, HashedDir::new), - java.lang.String.format("Duplicate offline hashed dir: '%s'", name)); + HashedDir hdir = new HashedDir(input); + lastHDirs.put(name,hdir); } } @@ -153,7 +150,7 @@ public void write(HOutput output) throws IOException { output.writeString(Launcher.gson.toJson(profile), 0); } output.writeLength(lastHDirs.size(), 0); - for (Map.Entry> entry : lastHDirs.entrySet()) { + for (Map.Entry entry : lastHDirs.entrySet()) { output.writeString(entry.getKey(), 0); entry.getValue().write(output); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java index 8d1dce9e..5eeba121 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java @@ -58,7 +58,7 @@ public R request() throws Exception { if (!started.compareAndSet(false, true)) throw new IllegalStateException("Request already started"); R wsResult = null; - if(config.nettyPort != 0) + if(config.isNettyEnabled) wsResult = requestWebSockets(); if(wsResult != null) return wsResult; // Make request to LaunchServer diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java index 687c656a..80352243 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java @@ -3,6 +3,7 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.events.request.UpdateRequestEvent; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedEntry; @@ -11,6 +12,8 @@ import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.request.UpdateAction; import ru.gravit.launcher.request.update.UpdateRequest.State.Callback; +import ru.gravit.launcher.request.websockets.LegacyRequestBridge; +import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -35,7 +38,12 @@ import java.util.Queue; import java.util.zip.InflaterInputStream; -public final class UpdateRequest extends Request> { +public final class UpdateRequest extends Request implements RequestInterface { + + @Override + public String getType() { + return "update"; + } public static final class State { @FunctionalInterface @@ -189,6 +197,11 @@ private static void fillActionsQueue(Queue queue, HashedDir mismat } } } + @Override + public UpdateRequestEvent requestWebSockets() throws Exception + { + return (UpdateRequestEvent) LegacyRequestBridge.sendRequest(this); + } // Instance private final String dirName; @@ -290,16 +303,9 @@ public Integer getLegacyType() { } @Override - public SignedObjectHolder request() throws Exception { + protected UpdateRequestEvent requestDo(HInput input, HOutput output) throws IOException, SignatureException { Files.createDirectories(dir); localDir = new HashedDir(dir, matcher, false, digest); - - // Start request - return super.request(); - } - - @Override - protected SignedObjectHolder requestDo(HInput input, HOutput output) throws IOException, SignatureException { // Write update dir name output.writeString(dirName, 255); output.flush(); @@ -365,7 +371,7 @@ protected SignedObjectHolder requestDo(HInput input, HOutput output) // Write update completed packet deleteExtraDir(dir, diff.extra, diff.extra.flag); - return remoteHDirHolder; + return new UpdateRequestEvent(remoteHDirHolder.object); } @LauncherAPI diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java index 98629b59..e49fb003 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -22,8 +22,8 @@ public class ClientWebSocketService extends ClientJSONPoint { private HashMap> results; private HashSet handlers; - public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int port, int i) { - super(createURL(address, port), Collections.emptyMap(), i); + public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) { + super(createURL(address), Collections.emptyMap(), i); requests = new HashMap<>(); results = new HashMap<>(); handlers = new HashSet<>(); @@ -33,9 +33,9 @@ public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int port, this.gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gson = gsonBuilder.create(); } - private static URI createURL(String address, int port) { + private static URI createURL(String address) { try { - URI u = new URI("ws://".concat(address).concat(":").concat(String.valueOf(port)).concat("/api")); + URI u = new URI(address); return u; } catch (Throwable e) { LogHelper.error(e); @@ -88,6 +88,7 @@ public void registerResults() { registerResult("setProfile", SetProfileRequestEvent.class); registerResult("updateList", UpdateListRequestEvent.class); registerResult("error", ErrorRequestEvent.class); + registerResult("update", UpdateRequestEvent.class); } public void registerHandler(EventHandler eventHandler) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java index 72728fcb..bae9f897 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java @@ -33,21 +33,21 @@ public static ResultInterface sendRequest(RequestInterface request) throws IOExc } return result; } - public static void initWebSockets(String address, int port) + public static void initWebSockets(String address) { - service = new ClientWebSocketService(new GsonBuilder(), address, port, 5000); + service = new ClientWebSocketService(new GsonBuilder(), address, 5000); service.registerResults(); service.registerRequests(); service.registerHandler(waitEventHandler); try { if(!service.connectBlocking()) LogHelper.error("Error connecting"); - LogHelper.debug("Connect to %s:%d",address,port); + LogHelper.debug("Connect to %s",address); } catch (InterruptedException e) { e.printStackTrace(); } } static { if(Launcher.getConfig().nettyPort != 0) - initWebSockets(Launcher.getConfig().address.getHostName(),Launcher.getConfig().nettyPort); + initWebSockets(Launcher.getConfig().nettyAddress); } } diff --git a/build.gradle b/build.gradle index feb4e53f..3d42a735 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,6 @@ -allprojects { - apply plugin: 'eclipse' +configure(subprojects.findAll {it.name != 'modules'}) { apply plugin: 'idea' -} - -subprojects { + apply plugin: 'eclipse' apply plugin: 'java' repositories { @@ -29,7 +26,7 @@ } wrapper { - distributionType = Wrapper.DistributionType.ALL + distributionType = Wrapper.DistributionType.ALL } defaultTasks 'build' diff --git a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java index 1845aaf5..508333fa 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java @@ -3,6 +3,7 @@ public class AutogenConfig { public String projectname; public String address; + public String nettyAddress; public int port; public int nettyPort; public int clientPort; @@ -10,6 +11,7 @@ public class AutogenConfig { private boolean isInitModules; public boolean isUsingWrapper; public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части + public boolean isNettyEnabled; public String secretKeyClient; public String guardLicenseName; public String guardLicenseKey; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index 4aba4d31..ccca5eaa 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -59,9 +59,9 @@ public final class Launcher { private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); public static final int MAJOR = 4; - public static final int MINOR = 3; - public static final int PATCH = 3; - public static final int BUILD = 2; + public static final int MINOR = 4; + public static final int PATCH = 0; + public static final int BUILD = 1; public static final Version.Type RELEASE = Version.Type.STABLE; public static GsonBuilder gsonBuilder; public static Gson gson; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index 6d21dfec..77dfebdc 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -28,6 +28,7 @@ public static AutogenConfig getAutogenConfig() { // Instance @LauncherAPI public InetSocketAddress address; + public String nettyAddress; public int nettyPort; @LauncherAPI public final String projectname; @@ -42,6 +43,7 @@ public static AutogenConfig getAutogenConfig() { public final boolean isUsingWrapper; public final boolean isDownloadJava; public final boolean isWarningMissArchJava; + public final boolean isNettyEnabled; public final String guardLicenseName; public final String guardLicenseKey; @@ -63,6 +65,8 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException guardLicenseKey = config.guardLicenseKey; guardLicenseName = config.guardLicenseName; nettyPort = config.nettyPort; + nettyAddress = config.nettyAddress; + isNettyEnabled = config.isNettyEnabled; LauncherEnvironment env; if (config.env == 0) env = LauncherEnvironment.DEV; else if (config.env == 1) env = LauncherEnvironment.DEBUG; @@ -99,6 +103,7 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map stringPath = toPath(dir.relativize(path)); + LogHelper.debug("DirWatcher event %s", String.join("/", stringPath)); if (matcher != null && !matcher.shouldVerify(stringPath)) continue; // Exclusion; should not be verified - // Verify is REALLY modified (not just attributes) if (kind.equals(StandardWatchEventKinds.ENTRY_MODIFY)) { HashedEntry entry = hdir.resolve(stringPath); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/FileNameMatcher.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/FileNameMatcher.java index 223cc365..956e2bee 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/FileNameMatcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/FileNameMatcher.java @@ -1,22 +1,32 @@ package ru.gravit.launcher.hasher; import ru.gravit.launcher.LauncherAPI; - -import java.util.Arrays; import java.util.Collection; public final class FileNameMatcher { private static final String[] NO_ENTRIES = new String[0]; private static boolean anyMatch(String[] entries, Collection path) { - return path.stream().anyMatch(e -> Arrays.stream(entries).anyMatch(p -> p.endsWith(e))); - //for(String p : path) - //{ - // for(String e : entries) - // { - // if(p.endsWith(e)) return true; - // } - //} + //return path.stream().anyMatch(e -> Arrays.stream(entries).anyMatch(p -> p.endsWith(e))); + String jpath = String.join("/", path); + for(String e : entries) + { + /*String[] split = e.split("/"); + //int index = 0; + //for(String p : path) + //{ + // if(index>=split.length) + { + return true; + } + if(!p.equals(split[index])) { + break; + } + index++; + }*/ + if(jpath.startsWith(e)) return true; + } + return false; } // Instance diff --git a/modules b/modules index 90a3b3ea..d4320ce2 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 90a3b3eac726659a64410ea3134f8bc22893de32 +Subproject commit d4320ce29b8a142a75b86237139e92a72e00b481 diff --git a/settings.gradle b/settings.gradle index 5b0fea68..0ef17ca5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ -rootProject.name = 'Launcher' +rootProject.name = 'GravitLauncher' include 'Launcher' include 'libLauncher'