Merge branch 'dev' of github.com:GravitLauncher/Launcher into dev

This commit is contained in:
Zaxar163 2019-09-23 15:42:34 +02:00
commit 833cc9ae8e
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B
15 changed files with 280 additions and 110 deletions

View file

@ -1,41 +1,49 @@
image: frekele/java image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
CI_VERSION: '6.6.$CI_PIPELINE_IID'
stages: stages:
- build - build
- test - test
- deploy
before_script:
# - echo `pwd` # debug
# - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug
- export GRADLE_USER_HOME=`pwd`/.gradle
- apt-get update -qq && apt-get install -y -qq git git-core
cache:
key: ${CI_COMMIT_REF_NAME}
paths:
- .gradle/wrapper
- .gradle/caches
build: build:
image: frekele/java
stage: build stage: build
script: before_script:
- apt-get -y update
- apt-get -y install zip git
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x gradlew
- sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules
- git submodule sync - git submodule sync
- git submodule update --init --recursive - git submodule update --init --recursive
script:
- ./gradlew assemble - ./gradlew assemble
- mv LaunchServer/build/libs/*.jar LaunchServer after_script:
- mv ServerWrapper/build/libs/*.jar ServerWrapper - mkdir -p artifacts/modules
- mv modules/*_module/build/libs/*.jar modules - cd LaunchServer/build/libs/
artifacts: - zip -r -9 ../../../artifacts/libraries.zip * -x "LaunchServer.jar" -x "LaunchServer-clean.jar"
- mv LaunchServer.jar ../../../artifacts/LaunchServer.jar
- cd ../../../ServerWrapper/build/libs
- mv ServerWrapper.jar ../../../artifacts/ServerWrapper.jar
- cd ../../../
- mv modules/*_module/build/libs/*.jar artifacts/modules
- mv modules/*_swmodule/build/libs/*.jar artifacts/modules
- mv modules/*_lmodule/build/libs/*.jar artifacts/modules
cache:
paths: paths:
- LaunchServer/*.jar - .gradle
- ServerWrapper/*.jar artifacts:
- modules/*.jar expire_in: 6 week
paths:
- artifacts
test: test:
image: frekele/java
stage: test stage: test
script: script:
- ./gradlew check - ./gradlew check
after_script:
- echo "End CI"

View file

@ -31,9 +31,9 @@ public void invoke(String... args) throws Exception {
return; return;
} }
LogHelper.info("[%s] UUID: %s", user.username, user.uuid.toString()); LogHelper.info("[%s] UUID: %s", user.username, user.uuid.toString());
for(UserHWID hwid : user.hwids) //for(UserHWID hwid : user.hwids)
{ //{
LogHelper.info("[%s] HWID: memory: %d | serial %s | hwdiskserial: %s | processorID %s | macAddr %s", user.username, hwid.totalMemory, hwid.serialNumber, hwid.HWDiskSerial, hwid.processorID, hwid.macAddr); // LogHelper.info("[%s] HWID: memory: %d | serial %s | hwdiskserial: %s | processorID %s | macAddr %s", user.username, hwid.totalMemory, hwid.serialNumber, hwid.HWDiskSerial, hwid.processorID, hwid.macAddr);
} //}
} }
} }

View file

@ -39,12 +39,6 @@ public class User {
public String serverID; public String serverID;
private String password_salt; private String password_salt;
public long permissions; public long permissions;
//TODO: заменить EAGER на LASY и придумать способ сохранить сессию
// [ERROR] org.hibernate.LazyInitializationException:
// failed to lazily initialize a collection of role: pro.gravit.launchserver.dao.User.hwids, could not initialize proxy - no Session
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
public Collection<UserHWID> hwids;
public void setPassword(String password) public void setPassword(String password)
{ {
password_salt = SecurityHelper.randomStringAESKey(); password_salt = SecurityHelper.randomStringAESKey();

View file

@ -20,9 +20,9 @@
-keepattributes Signature -keepattributes Signature
-adaptresourcefilecontents META-INF/MANIFEST.MF -adaptresourcefilecontents META-INF/MANIFEST.MF
-keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.client.api.** -keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.**
-keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.client.api.** { -keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.** {
*; *;
} }

View file

@ -34,7 +34,9 @@
import pro.gravit.launcher.LauncherEngine; import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.api.AuthService;
import pro.gravit.launcher.api.ClientService; import pro.gravit.launcher.api.ClientService;
import pro.gravit.launcher.client.events.ClientLaunchPhase;
import pro.gravit.launcher.client.events.ClientLauncherInitPhase; import pro.gravit.launcher.client.events.ClientLauncherInitPhase;
import pro.gravit.launcher.client.events.ClientLauncherPostInitPhase;
import pro.gravit.launcher.guard.LauncherGuardManager; import pro.gravit.launcher.guard.LauncherGuardManager;
import pro.gravit.launcher.gui.JSRuntimeProvider; import pro.gravit.launcher.gui.JSRuntimeProvider;
import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.FileNameMatcher;
@ -436,6 +438,21 @@ public static Process launch(
clientStarted = false; clientStarted = false;
return process; return process;
} }
public static class ClientLaunchContext
{
public final Params params;
public final ClientProfile profile;
public final HashedDir assetHDir, clientHDir;
public DirWatcher assetWatcher, clientWatcher;
public ClientLaunchContext(Params params, ClientProfile profile, HashedDir assetHDir, HashedDir clientHDir) {
this.params = params;
this.profile = profile;
this.assetHDir = assetHDir;
this.clientHDir = clientHDir;
}
}
@LauncherAPI @LauncherAPI
public static void main(String... args) throws Throwable { public static void main(String... args) throws Throwable {
@ -476,11 +493,12 @@ public static void main(String... args) throws Throwable {
System.exit(-98); System.exit(-98);
return; return;
} }
ClientLaunchContext context = new ClientLaunchContext(params, profile, assetHDir, clientHDir);
Launcher.profile = profile; Launcher.profile = profile;
playerProfile = params.pp; playerProfile = params.pp;
Request.setSession(params.session); Request.setSession(params.session);
checkJVMBitsAndVersion(); checkJVMBitsAndVersion();
LauncherEngine.modulesManager.invokeEvent(new ClientLauncherInitPhase()); LauncherEngine.modulesManager.invokeEvent(new ClientLauncherInitPhase(context));
// Verify ClientLauncher sign and classpath // Verify ClientLauncher sign and classpath
LogHelper.debug("Verifying ClientLauncher sign and classpath"); LogHelper.debug("Verifying ClientLauncher sign and classpath");
LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.getClassPath());
@ -536,13 +554,16 @@ public static void main(String... args) throws Throwable {
// 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);
//} //}
context.assetWatcher = assetWatcher;
context.clientWatcher = clientWatcher;
Launcher.profile.pushOptionalFile(clientHDir, false); Launcher.profile.pushOptionalFile(clientHDir, false);
LauncherEngine.modulesManager.invokeEvent(new PostInitPhase()); LauncherEngine.modulesManager.invokeEvent(new ClientLauncherPostInitPhase(context));
// 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.assetDir, assetHDir, assetMatcher, digest);
verifyHDir(params.clientDir, clientHDir, clientMatcher, digest); verifyHDir(params.clientDir, clientHDir, clientMatcher, digest);
LauncherEngine.modulesManager.invokeEvent(new ClientLaunchPhase(context));
launch(profile, params); launch(profile, params);
} }
} }

View file

@ -0,0 +1,12 @@
package pro.gravit.launcher.client.events;
import pro.gravit.launcher.client.ClientLauncher;
import pro.gravit.launcher.modules.LauncherModule;
public class ClientLaunchPhase extends LauncherModule.Event {
public final ClientLauncher.ClientLaunchContext context;
public ClientLaunchPhase(ClientLauncher.ClientLaunchContext context) {
this.context = context;
}
}

View file

@ -1,6 +1,12 @@
package pro.gravit.launcher.client.events; package pro.gravit.launcher.client.events;
import pro.gravit.launcher.client.ClientLauncher;
import pro.gravit.launcher.modules.events.InitPhase; import pro.gravit.launcher.modules.events.InitPhase;
public class ClientLauncherInitPhase extends InitPhase { public class ClientLauncherInitPhase extends InitPhase {
public final ClientLauncher.ClientLaunchContext context;
public ClientLauncherInitPhase(ClientLauncher.ClientLaunchContext context) {
this.context = context;
}
} }

View file

@ -0,0 +1,12 @@
package pro.gravit.launcher.client.events;
import pro.gravit.launcher.client.ClientLauncher;
import pro.gravit.launcher.modules.events.PostInitPhase;
public class ClientLauncherPostInitPhase extends PostInitPhase {
public final ClientLauncher.ClientLaunchContext context;
public ClientLauncherPostInitPhase(ClientLauncher.ClientLaunchContext context) {
this.context = context;
}
}

View file

@ -102,9 +102,4 @@ public void loadHDirStore() throws IOException {
public void saveHDirStore() throws IOException { public void saveHDirStore() throws IOException {
saveHDirStore(DirBridge.dirProjectStore); saveHDirStore(DirBridge.dirProjectStore);
} }
@Override
public void setType(Type type) {
super.setType(type);
}
} }

View file

@ -11,19 +11,9 @@
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
public abstract class JsonConfigurable<T> { public abstract class JsonConfigurable<T> implements JsonConfigurableInterface<T> {
private Type type; private transient final Type type;
protected Path configPath; protected transient final Path configPath;
@LauncherAPI
public void saveConfig() throws IOException {
saveConfig(configPath);
}
@LauncherAPI
public void loadConfig() throws IOException {
loadConfig(configPath);
}
@LauncherAPI @LauncherAPI
public JsonConfigurable(Type type, Path configPath) { public JsonConfigurable(Type type, Path configPath) {
@ -31,55 +21,14 @@ public JsonConfigurable(Type type, Path configPath) {
this.configPath = configPath; this.configPath = configPath;
} }
@LauncherAPI @Override
public void saveConfig(Path configPath) throws IOException { public Path getPath() {
try (BufferedWriter writer = IOHelper.newWriter(configPath)) { return configPath;
Launcher.gsonManager.configGson.toJson(getConfig(), type, writer);
}
} }
@LauncherAPI @Override
public void loadConfig(Path configPath) throws IOException { public Type getType() {
if (generateConfigIfNotExists(configPath)) return; return type;
try (BufferedReader reader = IOHelper.newReader(configPath)) {
setConfig(Launcher.gsonManager.configGson.fromJson(reader, type));
} catch (Exception e)
{
LogHelper.error(e);
resetConfig(configPath);
}
}
@LauncherAPI
public void resetConfig() throws IOException {
setConfig(getDefaultConfig());
saveConfig();
}
@LauncherAPI
public void resetConfig(Path newPath) throws IOException {
setConfig(getDefaultConfig());
saveConfig(newPath);
}
@LauncherAPI
public boolean generateConfigIfNotExists(Path path) throws IOException {
if (IOHelper.isFile(path))
return false;
resetConfig(path);
return true;
}
@LauncherAPI
public boolean generateConfigIfNotExists() throws IOException {
if (IOHelper.isFile(configPath))
return false;
resetConfig();
return true;
}
protected void setType(Type type) {
this.type = type;
} }
@LauncherAPI @LauncherAPI

View file

@ -0,0 +1,82 @@
package pro.gravit.launcher.config;
import com.google.gson.Gson;
import pro.gravit.launcher.Launcher;
import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.file.Path;
public interface JsonConfigurableInterface<T> {
default void saveConfig() throws IOException {
saveConfig(getPath());
}
default void loadConfig() throws IOException {
loadConfig(getPath());
}
default void saveConfig(Gson gson, Path configPath) throws IOException {
try (BufferedWriter writer = IOHelper.newWriter(configPath)) {
gson.toJson(getConfig(), getType(), writer);
}
}
default void loadConfig(Gson gson, Path configPath) throws IOException {
if (generateConfigIfNotExists(configPath)) return;
try (BufferedReader reader = IOHelper.newReader(configPath)) {
setConfig(gson.fromJson(reader, getType()));
} catch (Exception e)
{
LogHelper.error(e);
resetConfig(configPath);
}
}
default void saveConfig(Path configPath) throws IOException {
saveConfig(Launcher.gsonManager.configGson, configPath);
}
default void loadConfig(Path configPath) throws IOException {
loadConfig(Launcher.gsonManager.configGson, configPath);
}
default void resetConfig() throws IOException {
setConfig(getDefaultConfig());
saveConfig();
}
default void resetConfig(Path newPath) throws IOException {
setConfig(getDefaultConfig());
saveConfig(newPath);
}
default boolean generateConfigIfNotExists(Path path) throws IOException {
if (IOHelper.isFile(path))
return false;
resetConfig(path);
return true;
}
default boolean generateConfigIfNotExists() throws IOException {
if (IOHelper.isFile(getPath()))
return false;
resetConfig();
return true;
}
T getConfig();
T getDefaultConfig();
void setConfig(T config);
Path getPath();
Type getType();
}

View file

@ -0,0 +1,39 @@
package pro.gravit.launcher.config;
import java.lang.reflect.Type;
import java.nio.file.Path;
public abstract class SimpleConfig<T> implements JsonConfigurableInterface<T> {
private transient final Class<T> type;
protected transient final Path configPath;
protected SimpleConfig(Class<T> type, Path configPath) {
this.type = type;
this.configPath = configPath;
}
@SuppressWarnings("unchecked")
@Override
public T getConfig() {
return (T) this;
}
@Override
public T getDefaultConfig() {
try {
return type.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
return null;
}
}
@Override
public Path getPath() {
return configPath;
}
@Override
public Type getType() {
return type;
}
}

View file

@ -0,0 +1,32 @@
package pro.gravit.launcher.config;
import java.nio.file.Path;
public class SimpleConfigurable<T> extends JsonConfigurable<T> {
public T config;
private final Class<T> tClass;
public SimpleConfigurable(Class<T> type, Path configPath) {
super(type, configPath);
tClass = type;
}
@Override
public T getConfig() {
return config;
}
@Override
public T getDefaultConfig() {
try {
return tClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
return null;
}
}
@Override
public void setConfig(T config) {
this.config = config;
}
}

View file

@ -4,6 +4,7 @@
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import pro.gravit.launcher.config.SimpleConfigurable;
import pro.gravit.launcher.modules.ModulesConfigManager; import pro.gravit.launcher.modules.ModulesConfigManager;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
@ -34,4 +35,9 @@ public Path getModuleConfigDir(String moduleName) {
} }
return configDir.resolve(moduleName); return configDir.resolve(moduleName);
} }
@Override
public <T> SimpleConfigurable<T> getConfigurable(Class<T> tClass, Path configPath) {
return new SimpleConfigurable<>(tClass, configPath);
}
} }

View file

@ -1,5 +1,7 @@
package pro.gravit.launcher.modules; package pro.gravit.launcher.modules;
import pro.gravit.launcher.config.SimpleConfigurable;
import java.nio.file.Path; import java.nio.file.Path;
public interface ModulesConfigManager { public interface ModulesConfigManager {
@ -8,4 +10,16 @@ public interface ModulesConfigManager {
Path getModuleConfig(String moduleName, String configName); Path getModuleConfig(String moduleName, String configName);
Path getModuleConfigDir(String moduleName); Path getModuleConfigDir(String moduleName);
<T> SimpleConfigurable<T> getConfigurable(Class<T> tClass, Path configPath);
default <T> SimpleConfigurable<T> getConfigurable(Class<T> tClass, String moduleName)
{
return getConfigurable(tClass, getModuleConfig(moduleName));
}
default <T> SimpleConfigurable<T> getConfigurable(Class<T> tClass, String moduleName, String configName)
{
return getConfigurable(tClass, getModuleConfig(moduleName, configName));
}
} }