Интеграция с сервером

This commit is contained in:
Gravit 2018-09-25 20:43:12 +07:00
parent f83afcd8e1
commit b71df6ca01

View file

@ -9,6 +9,7 @@
import java.lang.invoke.MethodType;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherConfig;
@ -17,6 +18,7 @@
import ru.gravit.launcher.serialize.config.TextConfigWriter;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry;
import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry;
import ru.gravit.launcher.serialize.config.entry.StringConfigEntry;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
@ -24,6 +26,8 @@
import ru.gravit.launcher.request.update.ProfilesRequest;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.utils.helper.SecurityHelper;
import sun.security.rsa.RSAPublicKeyImpl;
public class ServerWrapper {
public static ModulesManager modulesManager;
@ -34,13 +38,13 @@ public static void main(String[] args) throws Throwable {
modulesManager = new ModulesManager(wrapper);
modulesManager.autoload(Paths.get("modules"));
Launcher.modulesManager = modulesManager;
LauncherConfig cfg = new LauncherConfig(new HInput(IOHelper.newInput(IOHelper.getResourceURL(Launcher.CONFIG_FILE))));
configFile = Paths.get("ServerWrapper.cfg");
modulesManager.preInitModules();
generateConfigIfNotExists();
try (BufferedReader reader = IOHelper.newReader(configFile)) {
config = new Config(TextConfigReader.read(reader, true));
}
LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(Paths.get("public.key"))),new HashMap<>(),config.projectname);
ProfilesRequest.Result result = new ProfilesRequest(cfg).request();
for (SignedObjectHolder<ClientProfile> p : result.profiles) {
LogHelper.debug("Get profile: %s", p.object.getTitle());
@ -88,12 +92,18 @@ private static void generateConfigIfNotExists() throws IOException {
}
public static final class Config extends ConfigObject {
public String title;
public String projectname;
public String address;
public int port;
public boolean customClassLoader;
public String classloader;
public String mainclass;
protected Config(BlockConfigEntry block) {
super(block);
title = block.getEntryValue("title",StringConfigEntry.class);
address = block.getEntryValue("address",StringConfigEntry.class);
projectname = block.getEntryValue("projectName",StringConfigEntry.class);
port = block.getEntryValue("port", IntegerConfigEntry.class);
customClassLoader = block.getEntryValue("customClassLoader", BooleanConfigEntry.class);
if(customClassLoader)
classloader = block.getEntryValue("classloader",StringConfigEntry.class);