Merge branch 'release/4.4.0'

This commit is contained in:
Gravit 2019-03-08 16:48:45 +07:00
commit 7050e0e9ac
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
24 changed files with 198 additions and 77 deletions

View file

@ -185,8 +185,10 @@ public class NettyConfig
{ {
public String bindAddress; public String bindAddress;
public int port; public int port;
public boolean clientEnabled;
public String launcherURL; public String launcherURL;
public String launcherEXEURL; public String launcherEXEURL;
public String address;
} }
public class GuardLicenseConf public class GuardLicenseConf
{ {
@ -542,7 +544,7 @@ private void generateConfigIfNotExists() throws IOException {
// Create new config // Create new config
LogHelper.info("Creating LaunchServer config"); LogHelper.info("Creating LaunchServer config");
Config newConfig = new 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 = new ExeConf();
newConfig.launch4j.copyright = "© GravitLauncher Team"; newConfig.launch4j.copyright = "© GravitLauncher Team";
newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Launcher.getVersion().getVersionString()); newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Launcher.getVersion().getVersionString());
@ -567,6 +569,11 @@ private void generateConfigIfNotExists() throws IOException {
newConfig.binaryName = "Launcher"; newConfig.binaryName = "Launcher";
newConfig.whitelistRejectString = "Вас нет в белом списке"; 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.threadCoreCount = 0; // on your own
newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors(); newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors();

View file

@ -70,6 +70,11 @@ public void setAddress(String address) {
body.append(address); body.append(address);
body.append("\";"); body.append("\";");
} }
public void setNettyAddress(String address) {
body.append("this.nettyAddress = \"");
body.append(address);
body.append("\";");
}
public void setProjectName(String name) { public void setProjectName(String name) {
body.append("this.projectname = \""); body.append("this.projectname = \"");
@ -134,6 +139,11 @@ public void setDownloadJava(boolean b) {
body.append(b ? "true" : "false"); body.append(b ? "true" : "false");
body.append(";"); body.append(";");
} }
public void setNettyEnabled(boolean b) {
body.append("this.isNettyEnabled = ");
body.append(b ? "true" : "false");
body.append(";");
}
public void setWarningMissArchJava(boolean b) { public void setWarningMissArchJava(boolean b) {
body.append("this.isWarningMissArchJava = "); body.append("this.isWarningMissArchJava = ");

View file

@ -130,14 +130,19 @@ public Path process(Path inputJar) throws IOException {
server.buildHookManager.hook(context); server.buildHookManager.hook(context);
jaConfigurator.setAddress(server.config.getAddress()); jaConfigurator.setAddress(server.config.getAddress());
jaConfigurator.setPort(server.config.port); 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.setNettyPort(server.config.netty.port);
jaConfigurator.setNettyAddress(server.config.netty.address);
}
if(server.config.guardLicense != null) if(server.config.guardLicense != null)
jaConfigurator.setGuardLicense(server.config.guardLicense.name, server.config.guardLicense.key, server.config.guardLicense.encryptKey); jaConfigurator.setGuardLicense(server.config.guardLicense.name, server.config.guardLicense.key, server.config.guardLicense.encryptKey);
jaConfigurator.setProjectName(server.config.projectName); jaConfigurator.setProjectName(server.config.projectName);
jaConfigurator.setSecretKey(SecurityHelper.randomStringAESKey()); jaConfigurator.setSecretKey(SecurityHelper.randomStringAESKey());
jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512)); jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512));
jaConfigurator.setUsingWrapper(server.config.isUsingWrapper); jaConfigurator.setUsingWrapper(server.config.isUsingWrapper);
jaConfigurator.setWarningMissArchJava(server.config.isWarningMissArchJava);
jaConfigurator.setDownloadJava(server.config.isDownloadJava); jaConfigurator.setDownloadJava(server.config.isDownloadJava);
jaConfigurator.setEnv(server.config.env); jaConfigurator.setEnv(server.config.env);
server.buildHookManager.registerAllClientModuleClass(jaConfigurator); server.buildHookManager.registerAllClientModuleClass(jaConfigurator);

View file

@ -124,6 +124,7 @@ protected CommandHandler(LaunchServer server) {
registerCommand("serverStatus", new ServerStatusCommand(server)); registerCommand("serverStatus", new ServerStatusCommand(server));
registerCommand("checkInstall", new CheckInstallCommand(server)); registerCommand("checkInstall", new CheckInstallCommand(server));
registerCommand("multi", new MultiCommand(server)); registerCommand("multi", new MultiCommand(server));
registerCommand("getModulus", new GetModulusCommand(server));
} }

View file

@ -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));
}
}

View file

@ -21,6 +21,7 @@
import ru.gravit.launchserver.socket.websocket.json.auth.*; 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.LauncherResponse;
import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse; 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 ru.gravit.utils.helper.LogHelper;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -79,6 +80,7 @@ public void registerResponses() {
registerResponse("cmdExec", ExecCommandResponse.class); registerResponse("cmdExec", ExecCommandResponse.class);
registerResponse("setProfile", SetProfileResponse.class); registerResponse("setProfile", SetProfileResponse.class);
registerResponse("addLogListener", AddLogListenerResponse.class); registerResponse("addLogListener", AddLogListenerResponse.class);
registerResponse("update", UpdateResponse.class);
} }
public void sendObject(ChannelHandlerContext ctx, Object obj) { public void sendObject(ChannelHandlerContext ctx, Object obj) {

View file

@ -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));
}
}

View file

@ -198,9 +198,9 @@ function verifyLauncher(e) {
} }
overlay.swap(0, processing.overlay, function(event) makeProfilesRequest(function(result) { overlay.swap(0, processing.overlay, function(event) makeProfilesRequest(function(result) {
settings.lastProfiles = result.profiles; settings.lastProfiles = result.profiles;
options.load();
// Update profiles list and hide overlay // Update profiles list and hide overlay
updateProfilesList(result.profiles); updateProfilesList(result.profiles);
options.load();
overlay.hide(0, function() { overlay.hide(0, function() {
if (cliParams.autoLogin) { if (cliParams.autoLogin) {
goAuth(null); goAuth(null);
@ -237,7 +237,7 @@ var digest = profile.isUpdateFastCheck();
makeSetProfileRequest(profile, function() { makeSetProfileRequest(profile, function() {
ClientLauncher.setProfile(profile); ClientLauncher.setProfile(profile);
makeUpdateRequest(assetDirName, assetDir, assetMatcher, digest, function(assetHDir) { makeUpdateRequest(assetDirName, assetDir, assetMatcher, digest, function(assetHDir) {
settings.lastHDirs.put(assetDirName, assetHDir); settings.lastHDirs.put(assetDirName, assetHDir.hdir);
// Update client dir // Update client dir
update.resetOverlay("Обновление файлов клиента"); update.resetOverlay("Обновление файлов клиента");
@ -245,8 +245,8 @@ var digest = profile.isUpdateFastCheck();
var clientDir = settings.updatesDir.resolve(clientDirName); var clientDir = settings.updatesDir.resolve(clientDirName);
var clientMatcher = profile.getClientUpdateMatcher(); var clientMatcher = profile.getClientUpdateMatcher();
makeUpdateRequest(clientDirName, clientDir, clientMatcher, digest, function(clientHDir) { makeUpdateRequest(clientDirName, clientDir, clientMatcher, digest, function(clientHDir) {
settings.lastHDirs.put(clientDirName, clientHDir); settings.lastHDirs.put(clientDirName, clientHDir.hdir);
doLaunchClient(assetDir, assetHDir, clientDir, clientHDir, profile, pp, accessToken); doLaunchClient(assetDir, assetHDir.hdir, clientDir, clientHDir.hdir, profile, pp, accessToken);
}); });
}); });
}); });

View file

@ -100,7 +100,7 @@ var options = {
var checkBoxList = new java.util.ArrayList; var checkBoxList = new java.util.ArrayList;
list.forEach(function(modFile) { list.forEach(function(modFile) {
var modName = modFile.name, modDescription = "", subLevel = 1; var modName = modFile.name, modDescription = "", subLevel = 1;
if(!modFile.isVisible) if(!modFile.visible)
{ {
LogHelper.debug("optionalMod %s hidden",modFile.name); LogHelper.debug("optionalMod %s hidden",modFile.name);
return; return;

View file

@ -14,7 +14,6 @@
import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.update.LegacyLauncherRequest;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.launcher.serialize.stream.StreamObject;
import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.PublicURLClassLoader;
import ru.gravit.utils.helper.*; import ru.gravit.utils.helper.*;
@ -298,7 +297,7 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl
@LauncherAPI @LauncherAPI
public static Process launch( public static Process launch(
SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir, HashedDir assetHDir, HashedDir clientHDir,
ClientProfile profile, Params params, boolean pipeOutput) throws Throwable { ClientProfile profile, Params params, boolean pipeOutput) throws Throwable {
// Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars) // Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars)
LogHelper.debug("Writing ClientLauncher params"); LogHelper.debug("Writing ClientLauncher params");
@ -411,8 +410,7 @@ public static void main(String... args) throws Throwable {
LogHelper.debug("Reading ClientLauncher params"); LogHelper.debug("Reading ClientLauncher params");
Params params; Params params;
ClientProfile profile; ClientProfile profile;
SignedObjectHolder<HashedDir> assetHDir, clientHDir; HashedDir assetHDir, clientHDir;
RSAPublicKey publicKey = Launcher.getConfig().publicKey;
try { try {
try (Socket socket = IOHelper.newSocket()) { try (Socket socket = IOHelper.newSocket()) {
socket.connect(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT)); 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); profile = gson.fromJson(input.readString(0), ClientProfile.class);
// Read hdirs // Read hdirs
assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); assetHDir = new HashedDir(input);
clientHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); clientHDir = new HashedDir(input);
} }
} }
} catch (IOException ex) { } catch (IOException ex) {
@ -457,28 +455,27 @@ public static void main(String... args) throws Throwable {
LogHelper.debug("Starting JVM and client WatchService"); LogHelper.debug("Starting JVM and client WatchService");
FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
FileNameMatcher clientMatcher = profile.getClientUpdateMatcher(); FileNameMatcher clientMatcher = profile.getClientUpdateMatcher();
try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir.object, assetMatcher, digest); try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir, assetMatcher, digest);
DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir.object, clientMatcher, digest)) { DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir, clientMatcher, digest)) {
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object;
//for (OptionalFile s : Launcher.profile.getOptional()) { //for (OptionalFile s : Launcher.profile.getOptional()) {
// if (params.updateOptional.contains(s)) s.mark = true; // if (params.updateOptional.contains(s)) s.mark = true;
// else hdir.removeR(s.file); // else hdir.removeR(s.file);
//} //}
Launcher.profile.pushOptionalFile(hdir,false); Launcher.profile.pushOptionalFile(clientHDir,false);
verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest);
verifyHDir(params.clientDir, hdir, clientMatcher, digest);
Launcher.modulesManager.postInitModules(); Launcher.modulesManager.postInitModules();
// Start WatchService, and only then client // Start WatchService, and only then client
CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start();
CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start();
verifyHDir(params.assetDir, assetHDir, assetMatcher, digest);
verifyHDir(params.clientDir, clientHDir, clientMatcher, digest);
launch(profile, params); launch(profile, params);
} }
} }
@LauncherAPI @LauncherAPI
public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHolder<HashedDir> clientHDir, public void launchLocal(HashedDir assetHDir, HashedDir clientHDir,
ClientProfile profile, Params params) throws Throwable { ClientProfile profile, Params params) throws Throwable {
RSAPublicKey publicKey = Launcher.getConfig().publicKey; RSAPublicKey publicKey = Launcher.getConfig().publicKey;
LogHelper.debug("Verifying ClientLauncher sign and classpath"); LogHelper.debug("Verifying ClientLauncher sign and classpath");
@ -497,17 +494,17 @@ public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHol
LogHelper.debug("Starting JVM and client WatchService"); LogHelper.debug("Starting JVM and client WatchService");
FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
FileNameMatcher clientMatcher = profile.getClientUpdateMatcher(); FileNameMatcher clientMatcher = profile.getClientUpdateMatcher();
try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir.object, assetMatcher, digest); try (DirWatcher assetWatcher = new DirWatcher(params.assetDir, assetHDir, assetMatcher, digest);
DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir.object, clientMatcher, digest)) { DirWatcher clientWatcher = new DirWatcher(params.clientDir, clientHDir, clientMatcher, digest)) {
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; HashedDir hdir = clientHDir;
//for (OptionalFile s : Launcher.profile.getOptional()) { //for (OptionalFile s : Launcher.profile.getOptional()) {
// if (params.updateOptional.contains(s)) s.mark = true; // if (params.updateOptional.contains(s)) s.mark = true;
// else hdir.removeR(s.file); // else hdir.removeR(s.file);
//} //}
Launcher.profile.pushOptionalFile(hdir,false); Launcher.profile.pushOptionalFile(hdir,false);
verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); verifyHDir(params.assetDir, assetHDir, assetMatcher, digest);
verifyHDir(params.clientDir, hdir, clientMatcher, digest); verifyHDir(params.clientDir, hdir, clientMatcher, digest);
Launcher.modulesManager.postInitModules(); Launcher.modulesManager.postInitModules();
// Start WatchService, and only then client // Start WatchService, and only then client

View file

@ -6,7 +6,6 @@
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.utils.helper.*; import ru.gravit.utils.helper.*;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
@ -14,14 +13,13 @@
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.SignatureException; import java.security.SignatureException;
import java.security.interfaces.RSAPublicKey;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class LauncherSettings { public class LauncherSettings {
public static int settingsMagic = 0xc0de9; public static int settingsMagic = 0xc0dea;
@LauncherAPI @LauncherAPI
public Path file = DirBridge.dir.resolve("settings.bin"); public Path file = DirBridge.dir.resolve("settings.bin");
@LauncherAPI @LauncherAPI
@ -46,7 +44,7 @@ public class LauncherSettings {
@LauncherAPI @LauncherAPI
public List<ClientProfile> lastProfiles = new LinkedList<>(); public List<ClientProfile> lastProfiles = new LinkedList<>();
@LauncherAPI @LauncherAPI
public Map<String, SignedObjectHolder<HashedDir>> lastHDirs = new HashMap<>(16); public Map<String, HashedDir> lastHDirs = new HashMap<>(16);
@LauncherAPI @LauncherAPI
public void load() throws SignatureException { public void load() throws SignatureException {
@ -103,7 +101,6 @@ public void read(HInput input) throws IOException, SignatureException {
setRAM(input.readLength(JVMHelper.RAM)); setRAM(input.readLength(JVMHelper.RAM));
// Offline cache // Offline cache
RSAPublicKey publicKey = Launcher.getConfig().publicKey;
lastDigest = input.readBoolean() ? input.readByteArray(0) : null; lastDigest = input.readBoolean() ? input.readByteArray(0) : null;
lastProfiles.clear(); lastProfiles.clear();
int lastProfilesCount = input.readLength(0); int lastProfilesCount = input.readLength(0);
@ -114,8 +111,8 @@ public void read(HInput input) throws IOException, SignatureException {
int lastHDirsCount = input.readLength(0); int lastHDirsCount = input.readLength(0);
for (int i = 0; i < lastHDirsCount; i++) { for (int i = 0; i < lastHDirsCount; i++) {
String name = IOHelper.verifyFileName(input.readString(255)); String name = IOHelper.verifyFileName(input.readString(255));
VerifyHelper.putIfAbsent(lastHDirs, name, new SignedObjectHolder<>(input, publicKey, HashedDir::new), HashedDir hdir = new HashedDir(input);
java.lang.String.format("Duplicate offline hashed dir: '%s'", name)); lastHDirs.put(name,hdir);
} }
} }
@ -153,7 +150,7 @@ public void write(HOutput output) throws IOException {
output.writeString(Launcher.gson.toJson(profile), 0); output.writeString(Launcher.gson.toJson(profile), 0);
} }
output.writeLength(lastHDirs.size(), 0); output.writeLength(lastHDirs.size(), 0);
for (Map.Entry<String, SignedObjectHolder<HashedDir>> entry : lastHDirs.entrySet()) { for (Map.Entry<String, HashedDir> entry : lastHDirs.entrySet()) {
output.writeString(entry.getKey(), 0); output.writeString(entry.getKey(), 0);
entry.getValue().write(output); entry.getValue().write(output);
} }

View file

@ -58,7 +58,7 @@ public R request() throws Exception {
if (!started.compareAndSet(false, true)) if (!started.compareAndSet(false, true))
throw new IllegalStateException("Request already started"); throw new IllegalStateException("Request already started");
R wsResult = null; R wsResult = null;
if(config.nettyPort != 0) if(config.isNettyEnabled)
wsResult = requestWebSockets(); wsResult = requestWebSockets();
if(wsResult != null) return wsResult; if(wsResult != null) return wsResult;
// Make request to LaunchServer // Make request to LaunchServer

View file

@ -3,6 +3,7 @@
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.events.request.UpdateRequestEvent;
import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.hasher.HashedEntry;
@ -11,6 +12,8 @@
import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.UpdateAction; import ru.gravit.launcher.request.UpdateAction;
import ru.gravit.launcher.request.update.UpdateRequest.State.Callback; 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.HInput;
import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launcher.serialize.SerializeLimits;
@ -35,7 +38,12 @@
import java.util.Queue; import java.util.Queue;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
public final class UpdateRequest extends Request<SignedObjectHolder<HashedDir>> { public final class UpdateRequest extends Request<UpdateRequestEvent> implements RequestInterface {
@Override
public String getType() {
return "update";
}
public static final class State { public static final class State {
@FunctionalInterface @FunctionalInterface
@ -189,6 +197,11 @@ private static void fillActionsQueue(Queue<UpdateAction> queue, HashedDir mismat
} }
} }
} }
@Override
public UpdateRequestEvent requestWebSockets() throws Exception
{
return (UpdateRequestEvent) LegacyRequestBridge.sendRequest(this);
}
// Instance // Instance
private final String dirName; private final String dirName;
@ -290,16 +303,9 @@ public Integer getLegacyType() {
} }
@Override @Override
public SignedObjectHolder<HashedDir> request() throws Exception { protected UpdateRequestEvent requestDo(HInput input, HOutput output) throws IOException, SignatureException {
Files.createDirectories(dir); Files.createDirectories(dir);
localDir = new HashedDir(dir, matcher, false, digest); localDir = new HashedDir(dir, matcher, false, digest);
// Start request
return super.request();
}
@Override
protected SignedObjectHolder<HashedDir> requestDo(HInput input, HOutput output) throws IOException, SignatureException {
// Write update dir name // Write update dir name
output.writeString(dirName, 255); output.writeString(dirName, 255);
output.flush(); output.flush();
@ -365,7 +371,7 @@ protected SignedObjectHolder<HashedDir> requestDo(HInput input, HOutput output)
// Write update completed packet // Write update completed packet
deleteExtraDir(dir, diff.extra, diff.extra.flag); deleteExtraDir(dir, diff.extra, diff.extra.flag);
return remoteHDirHolder; return new UpdateRequestEvent(remoteHDirHolder.object);
} }
@LauncherAPI @LauncherAPI

View file

@ -22,8 +22,8 @@ public class ClientWebSocketService extends ClientJSONPoint {
private HashMap<String, Class<? extends ResultInterface>> results; private HashMap<String, Class<? extends ResultInterface>> results;
private HashSet<EventHandler> handlers; private HashSet<EventHandler> handlers;
public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int port, int i) { public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) {
super(createURL(address, port), Collections.emptyMap(), i); super(createURL(address), Collections.emptyMap(), i);
requests = new HashMap<>(); requests = new HashMap<>();
results = new HashMap<>(); results = new HashMap<>();
handlers = new HashSet<>(); handlers = new HashSet<>();
@ -33,9 +33,9 @@ public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int port,
this.gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
this.gson = gsonBuilder.create(); this.gson = gsonBuilder.create();
} }
private static URI createURL(String address, int port) { private static URI createURL(String address) {
try { try {
URI u = new URI("ws://".concat(address).concat(":").concat(String.valueOf(port)).concat("/api")); URI u = new URI(address);
return u; return u;
} catch (Throwable e) { } catch (Throwable e) {
LogHelper.error(e); LogHelper.error(e);
@ -88,6 +88,7 @@ public void registerResults() {
registerResult("setProfile", SetProfileRequestEvent.class); registerResult("setProfile", SetProfileRequestEvent.class);
registerResult("updateList", UpdateListRequestEvent.class); registerResult("updateList", UpdateListRequestEvent.class);
registerResult("error", ErrorRequestEvent.class); registerResult("error", ErrorRequestEvent.class);
registerResult("update", UpdateRequestEvent.class);
} }
public void registerHandler(EventHandler eventHandler) public void registerHandler(EventHandler eventHandler)

View file

@ -33,21 +33,21 @@ public static ResultInterface sendRequest(RequestInterface request) throws IOExc
} }
return result; 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.registerResults();
service.registerRequests(); service.registerRequests();
service.registerHandler(waitEventHandler); service.registerHandler(waitEventHandler);
try { try {
if(!service.connectBlocking()) LogHelper.error("Error connecting"); if(!service.connectBlocking()) LogHelper.error("Error connecting");
LogHelper.debug("Connect to %s:%d",address,port); LogHelper.debug("Connect to %s",address);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
static { static {
if(Launcher.getConfig().nettyPort != 0) if(Launcher.getConfig().nettyPort != 0)
initWebSockets(Launcher.getConfig().address.getHostName(),Launcher.getConfig().nettyPort); initWebSockets(Launcher.getConfig().nettyAddress);
} }
} }

View file

@ -1,9 +1,6 @@
allprojects { configure(subprojects.findAll {it.name != 'modules'}) {
apply plugin: 'eclipse'
apply plugin: 'idea' apply plugin: 'idea'
} apply plugin: 'eclipse'
subprojects {
apply plugin: 'java' apply plugin: 'java'
repositories { repositories {
@ -29,7 +26,7 @@
} }
wrapper { wrapper {
distributionType = Wrapper.DistributionType.ALL distributionType = Wrapper.DistributionType.ALL
} }
defaultTasks 'build' defaultTasks 'build'

View file

@ -3,6 +3,7 @@
public class AutogenConfig { public class AutogenConfig {
public String projectname; public String projectname;
public String address; public String address;
public String nettyAddress;
public int port; public int port;
public int nettyPort; public int nettyPort;
public int clientPort; public int clientPort;
@ -10,6 +11,7 @@ public class AutogenConfig {
private boolean isInitModules; private boolean isInitModules;
public boolean isUsingWrapper; public boolean isUsingWrapper;
public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части
public boolean isNettyEnabled;
public String secretKeyClient; public String secretKeyClient;
public String guardLicenseName; public String guardLicenseName;
public String guardLicenseKey; public String guardLicenseKey;

View file

@ -59,9 +59,9 @@ public final class Launcher {
private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL);
public static final int MAJOR = 4; public static final int MAJOR = 4;
public static final int MINOR = 3; public static final int MINOR = 4;
public static final int PATCH = 3; public static final int PATCH = 0;
public static final int BUILD = 2; public static final int BUILD = 1;
public static final Version.Type RELEASE = Version.Type.STABLE; public static final Version.Type RELEASE = Version.Type.STABLE;
public static GsonBuilder gsonBuilder; public static GsonBuilder gsonBuilder;
public static Gson gson; public static Gson gson;

View file

@ -28,6 +28,7 @@ public static AutogenConfig getAutogenConfig() {
// Instance // Instance
@LauncherAPI @LauncherAPI
public InetSocketAddress address; public InetSocketAddress address;
public String nettyAddress;
public int nettyPort; public int nettyPort;
@LauncherAPI @LauncherAPI
public final String projectname; public final String projectname;
@ -42,6 +43,7 @@ public static AutogenConfig getAutogenConfig() {
public final boolean isUsingWrapper; public final boolean isUsingWrapper;
public final boolean isDownloadJava; public final boolean isDownloadJava;
public final boolean isWarningMissArchJava; public final boolean isWarningMissArchJava;
public final boolean isNettyEnabled;
public final String guardLicenseName; public final String guardLicenseName;
public final String guardLicenseKey; public final String guardLicenseKey;
@ -63,6 +65,8 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
guardLicenseKey = config.guardLicenseKey; guardLicenseKey = config.guardLicenseKey;
guardLicenseName = config.guardLicenseName; guardLicenseName = config.guardLicenseName;
nettyPort = config.nettyPort; nettyPort = config.nettyPort;
nettyAddress = config.nettyAddress;
isNettyEnabled = config.isNettyEnabled;
LauncherEnvironment env; LauncherEnvironment env;
if (config.env == 0) env = LauncherEnvironment.DEV; if (config.env == 0) env = LauncherEnvironment.DEV;
else if (config.env == 1) env = LauncherEnvironment.DEBUG; else if (config.env == 1) env = LauncherEnvironment.DEBUG;
@ -99,6 +103,7 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<Stri
isUsingWrapper = true; isUsingWrapper = true;
isDownloadJava = false; isDownloadJava = false;
isWarningMissArchJava = true; isWarningMissArchJava = true;
isNettyEnabled = false;
} }
@LauncherAPI @LauncherAPI
@ -114,6 +119,7 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<Stri
isUsingWrapper = true; isUsingWrapper = true;
isDownloadJava = false; isDownloadJava = false;
isWarningMissArchJava = true; isWarningMissArchJava = true;
isNettyEnabled = false;
} }
@Override @Override

View file

@ -0,0 +1,18 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.LauncherNetworkAPI;
import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.request.ResultInterface;
public class UpdateRequestEvent implements ResultInterface {
@LauncherNetworkAPI
public HashedDir hdir;
@Override
public String getType() {
return "update";
}
public UpdateRequestEvent(HashedDir hdir) {
this.hdir = hdir;
}
}

View file

@ -40,9 +40,9 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
// Maybe it's unnecessary to go deeper // Maybe it's unnecessary to go deeper
path.add(IOHelper.getFileName(dir)); path.add(IOHelper.getFileName(dir));
if (matcher != null && !matcher.shouldVerify(path)) { //if (matcher != null && !matcher.shouldVerify(path)) {
return FileVisitResult.SKIP_SUBTREE; // return FileVisitResult.SKIP_SUBTREE;
} //}
// Register // Register
dir.register(service, KINDS); dir.register(service, KINDS);
@ -121,11 +121,10 @@ private void processKey(WatchKey key) throws IOException {
// Resolve paths and verify is not exclusion // Resolve paths and verify is not exclusion
Path path = watchDir.resolve((Path) event.context()); Path path = watchDir.resolve((Path) event.context());
LogHelper.debug("DirWatcher event %s", path.toString());
Deque<String> stringPath = toPath(dir.relativize(path)); Deque<String> stringPath = toPath(dir.relativize(path));
LogHelper.debug("DirWatcher event %s", String.join("/", stringPath));
if (matcher != null && !matcher.shouldVerify(stringPath)) if (matcher != null && !matcher.shouldVerify(stringPath))
continue; // Exclusion; should not be verified continue; // Exclusion; should not be verified
// Verify is REALLY modified (not just attributes) // Verify is REALLY modified (not just attributes)
if (kind.equals(StandardWatchEventKinds.ENTRY_MODIFY)) { if (kind.equals(StandardWatchEventKinds.ENTRY_MODIFY)) {
HashedEntry entry = hdir.resolve(stringPath); HashedEntry entry = hdir.resolve(stringPath);

View file

@ -1,22 +1,32 @@
package ru.gravit.launcher.hasher; package ru.gravit.launcher.hasher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
public final class FileNameMatcher { public final class FileNameMatcher {
private static final String[] NO_ENTRIES = new String[0]; private static final String[] NO_ENTRIES = new String[0];
private static boolean anyMatch(String[] entries, Collection<String> path) { private static boolean anyMatch(String[] entries, Collection<String> path) {
return path.stream().anyMatch(e -> Arrays.stream(entries).anyMatch(p -> p.endsWith(e))); //return path.stream().anyMatch(e -> Arrays.stream(entries).anyMatch(p -> p.endsWith(e)));
//for(String p : path) String jpath = String.join("/", path);
//{ for(String e : entries)
// for(String e : entries) {
// { /*String[] split = e.split("/");
// if(p.endsWith(e)) return true; //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 // Instance

@ -1 +1 @@
Subproject commit 90a3b3eac726659a64410ea3134f8bc22893de32 Subproject commit d4320ce29b8a142a75b86237139e92a72e00b481

View file

@ -1,4 +1,4 @@
rootProject.name = 'Launcher' rootProject.name = 'GravitLauncher'
include 'Launcher' include 'Launcher'
include 'libLauncher' include 'libLauncher'