mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
Merge branch 'release/4.4.0'
This commit is contained in:
commit
7050e0e9ac
24 changed files with 198 additions and 77 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 = ");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<HashedDir> assetHDir, SignedObjectHolder<HashedDir> 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<HashedDir> 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<HashedDir> assetHDir, SignedObjectHolder<HashedDir> 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<HashedDir> 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
|
||||
|
|
|
@ -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<ClientProfile> lastProfiles = new LinkedList<>();
|
||||
@LauncherAPI
|
||||
public Map<String, SignedObjectHolder<HashedDir>> lastHDirs = new HashMap<>(16);
|
||||
public Map<String, HashedDir> 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<String, SignedObjectHolder<HashedDir>> entry : lastHDirs.entrySet()) {
|
||||
for (Map.Entry<String, HashedDir> entry : lastHDirs.entrySet()) {
|
||||
output.writeString(entry.getKey(), 0);
|
||||
entry.getValue().write(output);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<SignedObjectHolder<HashedDir>> {
|
||||
public final class UpdateRequest extends Request<UpdateRequestEvent> implements RequestInterface {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "update";
|
||||
}
|
||||
|
||||
public static final class State {
|
||||
@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
|
||||
private final String dirName;
|
||||
|
@ -290,16 +303,9 @@ public Integer getLegacyType() {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SignedObjectHolder<HashedDir> 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<HashedDir> requestDo(HInput input, HOutput output) throws IOException, SignatureException {
|
||||
// Write update dir name
|
||||
output.writeString(dirName, 255);
|
||||
output.flush();
|
||||
|
@ -365,7 +371,7 @@ protected SignedObjectHolder<HashedDir> requestDo(HInput input, HOutput output)
|
|||
|
||||
// Write update completed packet
|
||||
deleteExtraDir(dir, diff.extra, diff.extra.flag);
|
||||
return remoteHDirHolder;
|
||||
return new UpdateRequestEvent(remoteHDirHolder.object);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
|
|
@ -22,8 +22,8 @@ public class ClientWebSocketService extends ClientJSONPoint {
|
|||
private HashMap<String, Class<? extends ResultInterface>> results;
|
||||
private HashSet<EventHandler> 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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Stri
|
|||
isUsingWrapper = true;
|
||||
isDownloadJava = false;
|
||||
isWarningMissArchJava = true;
|
||||
isNettyEnabled = false;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -114,6 +119,7 @@ public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<Stri
|
|||
isUsingWrapper = true;
|
||||
isDownloadJava = false;
|
||||
isWarningMissArchJava = true;
|
||||
isNettyEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -40,9 +40,9 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
|
|||
|
||||
// Maybe it's unnecessary to go deeper
|
||||
path.add(IOHelper.getFileName(dir));
|
||||
if (matcher != null && !matcher.shouldVerify(path)) {
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
}
|
||||
//if (matcher != null && !matcher.shouldVerify(path)) {
|
||||
// return FileVisitResult.SKIP_SUBTREE;
|
||||
//}
|
||||
|
||||
// Register
|
||||
dir.register(service, KINDS);
|
||||
|
@ -121,11 +121,10 @@ private void processKey(WatchKey key) throws IOException {
|
|||
|
||||
// Resolve paths and verify is not exclusion
|
||||
Path path = watchDir.resolve((Path) event.context());
|
||||
LogHelper.debug("DirWatcher event %s", path.toString());
|
||||
Deque<String> 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);
|
||||
|
|
|
@ -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<String> 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
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit 90a3b3eac726659a64410ea3134f8bc22893de32
|
||||
Subproject commit d4320ce29b8a142a75b86237139e92a72e00b481
|
|
@ -1,4 +1,4 @@
|
|||
rootProject.name = 'Launcher'
|
||||
rootProject.name = 'GravitLauncher'
|
||||
|
||||
include 'Launcher'
|
||||
include 'libLauncher'
|
||||
|
|
Loading…
Reference in a new issue