diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index d03cc45d..f9d16e6c 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -13,6 +13,13 @@ maven { url "https://jitpack.io/" } + maven { + url 'https://maven.gravit-support.ru/repository/jitpack' + credentials { + username = 'gravitlauncher' + password = 'gravitlauncher' + } + } } sourceCompatibility = '21' diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index a117dd48..f0f7c790 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -21,6 +21,7 @@ import pro.gravit.launchserver.modules.events.*; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.SocketCommandServer; import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler; import pro.gravit.launchserver.socket.response.auth.ProfilesResponse; import pro.gravit.launchserver.socket.response.auth.RestoreResponse; @@ -85,6 +86,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab public final Path modulesDir; public final Path launcherModulesDir; public final Path librariesDir; + public final Path controlFile; /** * This object contains runtime configuration */ @@ -113,6 +115,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab // Server public final CommandHandler commandHandler; public final NettyServerSocketHandler nettyServerSocketHandler; + public final SocketCommandServer socketCommandServer; public final ScheduledExecutorService service; public final AtomicBoolean started = new AtomicBoolean(false); public final LauncherModuleLoader launcherModuleLoader; @@ -139,6 +142,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La modulesDir = directories.modules; launcherModulesDir = directories.launcherModules; librariesDir = directories.librariesDir; + controlFile = directories.controlFile; this.shardId = shardId; if(!Files.isDirectory(launcherPack)) { Files.createDirectories(launcherPack); @@ -190,6 +194,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La } launcherModuleLoader.init(); nettyServerSocketHandler = new NettyServerSocketHandler(this); + socketCommandServer = new SocketCommandServer(commandHandler, controlFile); if(config.sign.checkCertificateExpired) { checkCertificateExpired(); service.scheduleAtFixedRate(this::checkCertificateExpired, 24, 24, TimeUnit.HOURS); @@ -353,6 +358,7 @@ public void run() { } })); CommonHelper.newThread("Command Thread", true, commandHandler).start(); + CommonHelper.newThread("Socket Command Thread", true, socketCommandServer).start(); // Sync updates dir CommonHelper.newThread("Profiles and updates sync", true, () -> { try { @@ -461,7 +467,7 @@ public interface LaunchServerConfigManager { public static class LaunchServerDirectories { public static final String UPDATES_NAME = "updates", TRUSTSTORE_NAME = "truststore", LAUNCHERLIBRARIES_NAME = "launcher-libraries", - LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys", MODULES = "modules", LAUNCHER_MODULES = "launcher-modules", LIBRARIES = "libraries"; + LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys", MODULES = "modules", LAUNCHER_MODULES = "launcher-modules", LIBRARIES = "libraries", CONTROL_FILE = "control-file"; public Path updatesDir; public Path librariesDir; public Path launcherLibrariesDir; @@ -473,6 +479,7 @@ public static class LaunchServerDirectories { public Path tmpDir; public Path modules; public Path launcherModules; + public Path controlFile; public void collect() { if (updatesDir == null) updatesDir = getPath(UPDATES_NAME); @@ -486,6 +493,7 @@ public void collect() { if (modules == null) modules = getPath(MODULES); if (launcherModules == null) launcherModules = getPath(LAUNCHER_MODULES); if (librariesDir == null) librariesDir = getPath(LIBRARIES); + if (controlFile == null) controlFile = getPath(CONTROL_FILE); if (tmpDir == null) tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("launchserver-%s".formatted(SecurityHelper.randomStringToken())); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/SocketCommandServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/SocketCommandServer.java new file mode 100644 index 00000000..d6a04a38 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/SocketCommandServer.java @@ -0,0 +1,96 @@ +package pro.gravit.launchserver.socket; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import pro.gravit.launchserver.config.log4j.LogAppender; +import pro.gravit.utils.command.CommandHandler; + +import java.io.IOException; +import java.net.StandardProtocolFamily; +import java.net.UnixDomainSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +public class SocketCommandServer implements Runnable { + private final Logger logger = LogManager.getLogger(SocketCommandServer.class); + private ServerSocketChannel channel; + private Path path; + private UnixDomainSocketAddress address; + private ServerSocketChannel serverChannel; + private CommandHandler commandHandler; + private transient SocketChannel clientChannel; + + public SocketCommandServer(CommandHandler commandHandler, Path path) { + this.commandHandler = commandHandler; + this.path = path; + } + + private void runCommand(SocketChannel channel, String command) { + logger.info("Command '{}' from socket", command); + clientChannel = channel; + try { + commandHandler.evalNative(command, false); + } catch (Throwable e) { + logger.error("Error when execute command", e); + } finally { + clientChannel = null; + + } + } + + @Override + public void run() { + try { + Files.deleteIfExists(path); + this.address = UnixDomainSocketAddress.of(path); + serverChannel = ServerSocketChannel.open(StandardProtocolFamily.UNIX); + serverChannel.configureBlocking(true); + serverChannel.bind(address); + LogAppender.getInstance().addListener((logEvent -> { + if(clientChannel != null && clientChannel.isOpen()) { + try { + String s = logEvent.getMessage().getFormattedMessage()+"\n"; + byte[] bytes = s.getBytes(StandardCharsets.UTF_8); + ByteBuffer buffer = ByteBuffer.wrap(bytes); + clientChannel.write(buffer); + } catch (Throwable ignored) { + } + } + })); + ByteBuffer buffer = ByteBuffer.allocate(1024); + while (true) { + SocketChannel channel = serverChannel.accept(); + channel.configureBlocking(true); + String command = null; + try { + mark: + while (true) { + int bytesRead = channel.read(buffer); + if (bytesRead < 0) { + break; + } + for (var i=0;i System.currentTimeMillis() || params.timestamp + 30*1000 < System.currentTimeMillis() ) { - LogHelper.error("Timestamp failed. Exit"); + LogHelper.error("Timestamp failed: current %d | params %d | diff %d", System.currentTimeMillis(), params.timestamp, System.currentTimeMillis() - params.timestamp); ClientLauncherMethods.exitLauncher(-662); return; } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 65e30118..f5632187 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -6,7 +6,7 @@ public final class Version implements Comparable { public static final int MAJOR = 5; public static final int MINOR = 6; - public static final int PATCH = 8; + public static final int PATCH = 9; public static final int BUILD = 1; public static final Version.Type RELEASE = Type.STABLE; public final int major; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java index b72e4eec..a49e9ab4 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/CommandHandler.java @@ -10,8 +10,18 @@ import java.util.Map; public abstract class CommandHandler implements Runnable { - private final List categories = new ArrayList<>(); - private final CommandCategory baseCategory = new BaseCommandCategory(); + protected final List categories; + protected final CommandCategory baseCategory; + + public CommandHandler() { + this.categories = new ArrayList<>(); + this.baseCategory = new BaseCommandCategory(); + } + + protected CommandHandler(List categories, CommandCategory baseCategory) { + this.categories = categories; + this.baseCategory = baseCategory; + } public void eval(String line, boolean bell) { LogHelper.info("Command '%s'", line); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/command/StdCommandHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/command/StdCommandHandler.java index 5bb297aa..257ceecb 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/command/StdCommandHandler.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/command/StdCommandHandler.java @@ -5,6 +5,8 @@ import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.util.List; public class StdCommandHandler extends CommandHandler { private final BufferedReader reader; @@ -14,6 +16,31 @@ public StdCommandHandler(boolean readCommands) { reader = readCommands ? IOHelper.newReader(System.in) : null; } + public StdCommandHandler(InputStream stream) { + super(); + this.reader = IOHelper.newReader(stream); + } + + public StdCommandHandler(BufferedReader reader) { + super(); + this.reader = reader; + } + + protected StdCommandHandler(List categories, CommandCategory baseCategory, boolean readCommands) { + super(categories, baseCategory); + this.reader = readCommands ? IOHelper.newReader(System.in) : null; + } + + protected StdCommandHandler(List categories, CommandCategory baseCategory, InputStream stream) { + super(categories, baseCategory); + this.reader = IOHelper.newReader(stream); + } + + protected StdCommandHandler(List categories, CommandCategory baseCategory, BufferedReader reader) { + super(categories, baseCategory); + this.reader = reader; + } + @Override public void bell() { } @@ -37,4 +64,16 @@ public void clear() throws IOException { public String readLine() throws IOException { return reader == null ? null : reader.readLine(); } + + public StdCommandHandler ofHandler(CommandHandler commandHandler, boolean readCommands) { + return new StdCommandHandler(commandHandler.categories, commandHandler.baseCategory, readCommands); + } + + public StdCommandHandler ofHandler(CommandHandler commandHandler, InputStream stream) { + return new StdCommandHandler(commandHandler.categories, commandHandler.baseCategory, stream); + } + + public StdCommandHandler ofHandler(CommandHandler commandHandler, BufferedReader reader) { + return new StdCommandHandler(commandHandler.categories, commandHandler.baseCategory, reader); + } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java index a7511ad9..7be6eda4 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java @@ -123,6 +123,9 @@ protected Class findClass(String name) throws ClassNotFoundException { @Override public String findLibrary(String name) { + if(nativePath == null) { + return null; + } return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(JVMHelper.NATIVE_PREFIX).concat(name).concat(JVMHelper.NATIVE_EXTENSION); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java index d83e3c44..ca1e8bb7 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java @@ -262,6 +262,9 @@ protected Class findClass(String moduleName, String name) { @Override public String findLibrary(String name) { + if(nativePath == null) { + return null; + } return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(JVMHelper.NATIVE_PREFIX).concat(name).concat(JVMHelper.NATIVE_EXTENSION); } diff --git a/build.gradle b/build.gradle index 1a1f5a77..43de18a3 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.1.0' apply false } group = 'pro.gravit.launcher' -version = '5.6.8' +version = '5.6.9' apply from: 'props.gradle' @@ -30,6 +30,13 @@ maven { url "https://jitpack.io/" } + maven { + url 'https://maven.gravit-support.ru/repository/jitpack' + credentials { + username = 'gravitlauncher' + password = 'gravitlauncher' + } + } } jar { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 2c352119..a4b76b95 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index dedd5d1e..79eb9d00 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/modules b/modules index 65f882bd..bf37c686 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 65f882bd90623aa1581ad24cfa4f52563ea95bc0 +Subproject commit bf37c6860a80acfd516ee533494d64b226d89309 diff --git a/props.gradle b/props.gradle index 3d5fc90f..99b9aa98 100644 --- a/props.gradle +++ b/props.gradle @@ -1,18 +1,18 @@ project.ext { - verAsm = '9.7' - verNetty = '4.1.111.Final' - verOshiCore = '6.6.4' - verJunit = '5.10.2' + verAsm = '9.7.1' + verNetty = '4.1.114.Final' + verOshiCore = '6.6.5' + verJunit = '5.11.2' verJansi = '2.4.1' verJline = '3.26.3' - verJwt = '0.12.5' + verJwt = '0.12.6' verGson = '2.11.0' verBcpkix = '1.78.1' - verSlf4j = '2.0.13' - verLog4j = '2.23.1' + verSlf4j = '2.0.16' + verLog4j = '2.24.1' verMySQLConn = '9.0.0' - verMariaDBConn = '3.4.0' + verMariaDBConn = '3.4.1' verPostgreSQLConn = '42.7.4' verH2Conn = '2.3.232' - verProguard = '7.5.0' + verProguard = '7.6.0' }