From 79891d711e77232b1b9bb9119ca7c99b43dd6792 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 23 Dec 2018 23:22:19 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=BE=D0=B2=20=D0=BD=D0=B0?= =?UTF-8?q?=20Json=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=203=20=D0=9A=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=BB=D0=B8=D1=80=D1=83=D0=B5=D1=82=D1=81=D1=8F,?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launchserver/auth/AuthLimiter.java | 4 +- .../launchserver/auth/MySQLSourceConfig.java | 38 +++++-------------- .../auth/provider/AuthProvider.java | 1 - .../command/hash/DownloadClientCommand.java | 10 ++--- .../response/auth/AuthResponse.java | 10 ++--- .../response/auth/AuthServerResponse.java | 10 ++--- .../response/auth/SetProfileResponse.java | 10 ++--- .../response/update/ProfilesResponse.java | 9 +++-- .../response/update/UpdateResponse.java | 7 ++-- .../websocket/json/auth/AuthResponse.java | 10 ++--- .../texture/NullTextureProvider.java | 5 --- .../texture/RequestTextureProvider.java | 16 +------- .../launchserver/texture/TextureProvider.java | 27 +++---------- .../texture/VoidTextureProvider.java | 4 -- .../ru/gravit/launcher/LauncherEngine.java | 16 -------- .../launcher/client/ClientLauncher.java | 38 +++++++++---------- .../launcher/client/LauncherSettings.java | 8 ++-- .../request/update/LegacyLauncherRequest.java | 11 ++++-- .../request/update/ProfilesRequest.java | 7 +++- 19 files changed, 85 insertions(+), 156 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java index 6e141fb0..40122c15 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.auth; import ru.gravit.launcher.NeedGarbageCollection; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launchserver.LaunchServer; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -60,7 +60,7 @@ public AuthLimiter(LaunchServer srv) { map = new HashMap<>(); excludeIps = new ArrayList<>(); if (srv.config.authLimitExclusions != null) - srv.config.authLimitExclusions.stream(StringConfigEntry.class).forEach(excludeIps::add); + excludeIps.addAll(Arrays.asList(srv.config.authLimitExclusions)); rateLimit = srv.config.authRateLimit; rateLimitMilis = srv.config.authRateLimitMilis; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java index 03fc48fe..8c58cb34 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java @@ -3,11 +3,6 @@ import com.mysql.cj.jdbc.MysqlDataSource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import ru.gravit.launcher.serialize.config.ConfigObject; -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.LogHelper; import ru.gravit.utils.helper.VerifyHelper; @@ -15,7 +10,7 @@ import java.sql.Connection; import java.sql.SQLException; -public final class MySQLSourceConfig extends ConfigObject implements AutoCloseable { +public final class MySQLSourceConfig implements AutoCloseable { public static final int TIMEOUT = VerifyHelper.verifyInt( Integer.parseUnsignedInt(System.getProperty("launcher.mysql.idleTimeout", Integer.toString(5000))), @@ -28,13 +23,13 @@ public final class MySQLSourceConfig extends ConfigObject implements AutoCloseab private final String poolName; // Config - private final String address; - private final int port; - private final boolean useSSL; - private final boolean verifyCertificates; - private final String username; - private final String password; - private final String database; + private String address; + private int port; + private boolean useSSL; + private boolean verifyCertificates; + private String username; + private String password; + private String database; private String timeZone; // Cache @@ -42,23 +37,8 @@ public final class MySQLSourceConfig extends ConfigObject implements AutoCloseab private boolean hikari; - public MySQLSourceConfig(String poolName, BlockConfigEntry block) { - super(block); + public MySQLSourceConfig(String poolName) { this.poolName = poolName; - address = VerifyHelper.verify(block.getEntryValue("address", StringConfigEntry.class), - VerifyHelper.NOT_EMPTY, "MySQL address can't be empty"); - port = VerifyHelper.verifyInt(block.getEntryValue("port", IntegerConfigEntry.class), - VerifyHelper.range(0, 65535), "Illegal MySQL port"); - username = VerifyHelper.verify(block.getEntryValue("username", StringConfigEntry.class), - VerifyHelper.NOT_EMPTY, "MySQL username can't be empty"); - password = block.getEntryValue("password", StringConfigEntry.class); - database = VerifyHelper.verify(block.getEntryValue("database", StringConfigEntry.class), - VerifyHelper.NOT_EMPTY, "MySQL database can't be empty"); - timeZone = block.hasEntry("timezone") ? VerifyHelper.verify(block.getEntryValue("timezone", StringConfigEntry.class), - VerifyHelper.NOT_EMPTY, "MySQL time zone can't be empty") : null; - // Password shouldn't be verified - useSSL = block.hasEntry("useSSL") ? block.getEntryValue("useSSL", BooleanConfigEntry.class) : true; - verifyCertificates = block.hasEntry("verifyCertificates") ? block.getEntryValue("verifyCertificates", BooleanConfigEntry.class) : false; } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java index d6a98415..df3842f4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java @@ -35,7 +35,6 @@ public static void registerProviders() { // Auth providers that doesn't do nothing :D registerProvider("com.mojang", MojangAuthProvider.class); registerProvider("mysql", MySQLAuthProvider.class); - registerProvider("file", FileAuthProvider.class); registerProvider("request", RequestAuthProvider.class); registerProvider("json", JsonAuthProvider.class); registredProv = true; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java index c0ff1538..d44b2c07 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -1,10 +1,8 @@ package ru.gravit.launchserver.command.hash; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile.Version; -import ru.gravit.launcher.serialize.config.TextConfigReader; -import ru.gravit.launcher.serialize.config.TextConfigWriter; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; @@ -55,14 +53,12 @@ public void invoke(String... args) throws IOException, CommandException { ClientProfile client; String profilePath = String.format("ru/gravit/launchserver/defaults/profile%s.cfg", version.name); try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) { - client = new ClientProfile(TextConfigReader.read(reader, false)); + client = Launcher.gson.fromJson(reader,ClientProfile.class); } client.setTitle(dirName); - client.block.getEntry("dir", StringConfigEntry.class).setValue(dirName); - client.block.getEntry("title", StringConfigEntry.class).setValue(dirName); try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, dirName, "cfg"))) { - TextConfigWriter.write(client.block, writer, true); + Launcher.gson.toJson(client,writer); } // Finished diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index 61ea5a5a..f404209d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -77,13 +77,13 @@ public void reply() throws Exception { return; } if (isClient) { - Collection> profiles = server.getProfiles(); - for (SignedObjectHolder p : profiles) { - if (p.object.getTitle().equals(client)) { - if (!p.object.isWhitelistContains(login)) { + Collection profiles = server.getProfiles(); + for (ClientProfile p : profiles) { + if (p.getTitle().equals(client)) { + if (!p.isWhitelistContains(login)) { throw new AuthException(server.config.whitelistRejectString); } - clientData.profile = p.object; + clientData.profile = p; } } if (clientData.profile == null) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java index 87b19a89..1d2c8cb4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java @@ -64,13 +64,13 @@ public void reply() throws Exception { AuthProvider.authError(String.format("Illegal result: '%s'", result.username)); return; } - Collection> profiles = server.getProfiles(); - for (SignedObjectHolder p : profiles) { - if (p.object.getTitle().equals(client)) { - if (!p.object.isWhitelistContains(login)) { + Collection profiles = server.getProfiles(); + for (ClientProfile p : profiles) { + if (p.getTitle().equals(client)) { + if (!p.isWhitelistContains(login)) { throw new AuthException(server.config.whitelistRejectString); } - clientData.profile = p.object; + clientData.profile = p; } } if (clientData.profile == null) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java index 313eac85..6da93ecd 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java @@ -21,14 +21,14 @@ public void reply() throws Exception { String client = input.readString(SerializeLimits.MAX_CLIENT); Client clientData = server.sessionManager.getClient(session); if (!clientData.isAuth) requestError("You not auth"); - Collection> profiles = server.getProfiles(); - for (SignedObjectHolder p : profiles) { - if (p.object.getTitle().equals(client)) { - if (!p.object.isWhitelistContains(clientData.username)) { + Collection profiles = server.getProfiles(); + for (ClientProfile p : profiles) { + if (p.getTitle().equals(client)) { + if (!p.isWhitelistContains(clientData.username)) { requestError(server.config.whitelistRejectString); return; } - clientData.profile = p.object; + clientData.profile = p; writeNoError(output); output.writeBoolean(true); break; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java index 54a2aceb..be29c45f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java @@ -1,5 +1,6 @@ package ru.gravit.launchserver.response.update; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -29,11 +30,11 @@ public void reply() throws IOException { return; } writeNoError(output); - Collection> profiles = server.getProfiles(); + Collection profiles = server.getProfiles(); output.writeLength(profiles.size(), 0); - for (SignedObjectHolder profile : profiles) { - LogHelper.debug("Writted profile: %s", profile.object.getTitle()); - profile.write(output); + for (ClientProfile profile : profiles) { + LogHelper.debug("Writted profile: %s", profile.getTitle()); + output.writeString(Launcher.gson.toJson(profile),0); } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java index d348c95c..de273442 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java @@ -42,10 +42,9 @@ public void reply() throws IOException { requestError("Assess denied"); return; } - for (SignedObjectHolder p : server.getProfiles()) { - ClientProfile profile = p.object; - if (!clientData.profile.getTitle().equals(profile.getTitle())) continue; - if (!profile.isWhitelistContains(clientData.username)) { + for (ClientProfile p : server.getProfiles()) { + if (!clientData.profile.getTitle().equals(p.getTitle())) continue; + if (!p.isWhitelistContains(clientData.username)) { requestError("You don't download this folder"); return; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index a9b4eab3..14fb7b9a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -56,13 +56,13 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client AuthProvider.authError(String.format("Illegal result: '%s'", result.username)); return; } - Collection> profiles = LaunchServer.server.getProfiles(); - for (SignedObjectHolder p : profiles) { - if (p.object.getTitle().equals(client)) { - if (!p.object.isWhitelistContains(login)) { + Collection profiles = LaunchServer.server.getProfiles(); + for (ClientProfile p : profiles) { + if (p.getTitle().equals(client)) { + if (!p.isWhitelistContains(login)) { throw new AuthException(LaunchServer.server.config.whitelistRejectString); } - clientData.profile = p.object; + clientData.profile = p; } } if (clientData.profile == null) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/NullTextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/NullTextureProvider.java index 7e34b258..e1a855e7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/NullTextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/NullTextureProvider.java @@ -1,7 +1,6 @@ package ru.gravit.launchserver.texture; import ru.gravit.launcher.profiles.Texture; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException; @@ -11,10 +10,6 @@ public final class NullTextureProvider extends TextureProvider { private volatile TextureProvider provider; - public NullTextureProvider(BlockConfigEntry block) { - super(block); - } - @Override public void close() throws IOException { TextureProvider provider = this.provider; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java index 47ccad09..39cb3dd0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java @@ -2,8 +2,6 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launcher.profiles.Texture; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -32,19 +30,9 @@ private static String getTextureURL(String url, UUID uuid, String username, Stri } // Instance - private final String skinURL; + private String skinURL; - private final String cloakURL; - - public RequestTextureProvider(BlockConfigEntry block) { - super(block); - skinURL = block.getEntryValue("skinsURL", StringConfigEntry.class); - cloakURL = block.getEntryValue("cloaksURL", StringConfigEntry.class); - - // Verify - IOHelper.verifyURL(getTextureURL(skinURL, ZERO_UUID, "skinUsername", "")); - IOHelper.verifyURL(getTextureURL(cloakURL, ZERO_UUID, "cloakUsername", "")); - } + private String cloakURL; @Override public void close() { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java index 016cfd38..d443db56 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java @@ -1,8 +1,6 @@ package ru.gravit.launchserver.texture; import ru.gravit.launcher.profiles.Texture; -import ru.gravit.launcher.serialize.config.ConfigObject; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException; @@ -11,40 +9,27 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -public abstract class TextureProvider extends ConfigObject implements AutoCloseable { - private static final Map> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2); +public abstract class TextureProvider implements AutoCloseable { + private static final Map TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2); private static boolean registredProv = false; - public static TextureProvider newProvider(String name, BlockConfigEntry block) { - VerifyHelper.verifyIDName(name); - Adapter authHandlerAdapter = VerifyHelper.getMapValue(TEXTURE_PROVIDERS, name, - String.format("Unknown texture provider: '%s'", name)); - return authHandlerAdapter.convert(block); - } - - - public static void registerProvider(String name, Adapter adapter) { + public static void registerProvider(String name, Class adapter) { VerifyHelper.putIfAbsent(TEXTURE_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"), String.format("Texture provider has been already registered: '%s'", name)); } public static void registerProviders() { if (!registredProv) { - registerProvider("null", NullTextureProvider::new); - registerProvider("void", VoidTextureProvider::new); + registerProvider("null", NullTextureProvider.class); + registerProvider("void", VoidTextureProvider.class); // Auth providers that doesn't do nothing :D - registerProvider("request", RequestTextureProvider::new); + registerProvider("request", RequestTextureProvider.class); registredProv = true; } } - - protected TextureProvider(BlockConfigEntry block) { - super(block); - } - @Override public abstract void close() throws IOException; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/VoidTextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/VoidTextureProvider.java index a167da04..0b77312e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/VoidTextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/VoidTextureProvider.java @@ -1,14 +1,10 @@ package ru.gravit.launchserver.texture; import ru.gravit.launcher.profiles.Texture; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import java.util.UUID; public final class VoidTextureProvider extends TextureProvider { - public VoidTextureProvider(BlockConfigEntry block) { - super(block); - } @Override public void close() { diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index cdcaf295..3d96d21b 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -27,10 +27,6 @@ import ru.gravit.launcher.request.uuid.ProfileByUsernameRequest; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launcher.serialize.config.ConfigObject; -import ru.gravit.launcher.serialize.config.TextConfigReader; -import ru.gravit.launcher.serialize.config.TextConfigWriter; -import ru.gravit.launcher.serialize.config.entry.*; import ru.gravit.launcher.serialize.signed.SignedBytesHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.stream.EnumSerializer; @@ -96,18 +92,6 @@ public static void addLauncherClassBindings(Map bindings) { bindings.put("SignedObjectHolderClass", SignedObjectHolder.class); bindings.put("EnumSerializerClass", EnumSerializer.class); - // Set config serialization class bindings - bindings.put("ConfigObjectClass", ConfigObject.class); - bindings.put("ConfigObjectAdapterClass", ConfigObject.Adapter.class); - bindings.put("BlockConfigEntryClass", BlockConfigEntry.class); - bindings.put("BooleanConfigEntryClass", BooleanConfigEntry.class); - bindings.put("IntegerConfigEntryClass", IntegerConfigEntry.class); - bindings.put("ListConfigEntryClass", ListConfigEntry.class); - bindings.put("StringConfigEntryClass", StringConfigEntry.class); - bindings.put("ConfigEntryTypeClass", ConfigEntry.Type.class); - bindings.put("TextConfigReaderClass", TextConfigReader.class); - bindings.put("TextConfigWriterClass", TextConfigWriter.class); - // Set helper class bindings bindings.put("CommonHelperClass", CommonHelper.class); bindings.put("IOHelperClass", IOHelper.class); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index e5f7d2c4..51ab3e29 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -292,7 +292,7 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl @LauncherAPI public static Process launch( SignedObjectHolder assetHDir, SignedObjectHolder clientHDir, - SignedObjectHolder 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) LogHelper.debug("Writing ClientLauncher params"); CommonHelper.newThread("Client params writter", false, () -> @@ -314,7 +314,7 @@ public static Process launch( } try (HOutput output = new HOutput(client.getOutputStream())) { params.write(output); - profile.write(output); + output.writeString(Launcher.gson.toJson(profile),0); assetHDir.write(output); clientHDir.write(output); } @@ -363,7 +363,7 @@ public static Process launch( } // Add classpath and main class String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); - Collections.addAll(args, profile.object.getJvmArgs()); + Collections.addAll(args, profile.getJvmArgs()); Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path Collections.addAll(args, "-javaagent:".concat(pathLauncher)); if (wrapper) @@ -412,7 +412,7 @@ public static void main(String... args) throws Throwable { // Read and delete params file LogHelper.debug("Reading ClientLauncher params"); Params params; - SignedObjectHolder profile; + ClientProfile profile; SignedObjectHolder assetHDir, clientHDir; RSAPublicKey publicKey = Launcher.getConfig().publicKey; try { @@ -420,7 +420,7 @@ public static void main(String... args) throws Throwable { socket.connect(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT)); try (HInput input = new HInput(socket.getInputStream())) { params = new Params(input); - profile = new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER); + profile = gson.fromJson(input.readString(0),ClientProfile.class); // Read hdirs assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); @@ -432,26 +432,26 @@ public static void main(String... args) throws Throwable { System.exit(-98); return; } - Launcher.profile = profile.object; + Launcher.profile = profile; Launcher.modulesManager.initModules(); // Verify ClientLauncher sign and classpath LogHelper.debug("Verifying ClientLauncher sign and classpath"); //TODO: GO TO DIGEST //SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, publicKey); - LinkedList classPath = resolveClassPathList(params.clientDir, profile.object.getClassPath()); + LinkedList classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); for (Path classpathURL : classPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } - URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath()); + URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString(); PublicURLClassLoader.systemclassloader = classLoader; // Start client with WatchService monitoring - boolean digest = !profile.object.isUpdateFastCheck(); + boolean digest = !profile.isUpdateFastCheck(); LogHelper.debug("Starting JVM and client WatchService"); - FileNameMatcher assetMatcher = profile.object.getAssetUpdateMatcher(); - FileNameMatcher clientMatcher = profile.object.getClientUpdateMatcher(); + 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)) { // Verify current state of all dirs @@ -467,30 +467,30 @@ public static void main(String... args) throws Throwable { // Start WatchService, and only then client CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); - launch(profile.object, params); + launch(profile, params); } } @LauncherAPI public void launchLocal(SignedObjectHolder assetHDir, SignedObjectHolder clientHDir, - SignedObjectHolder profile, Params params) throws Throwable { + ClientProfile profile, Params params) throws Throwable { RSAPublicKey publicKey = Launcher.getConfig().publicKey; LogHelper.debug("Verifying ClientLauncher sign and classpath"); SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, publicKey); - LinkedList classPath = resolveClassPathList(params.clientDir, profile.object.getClassPath()); + LinkedList classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); for (Path classpathURL : classPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } - URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath()); + URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString(); PublicURLClassLoader.systemclassloader = classLoader; // Start client with WatchService monitoring - boolean digest = !profile.object.isUpdateFastCheck(); + boolean digest = !profile.isUpdateFastCheck(); LogHelper.debug("Starting JVM and client WatchService"); - FileNameMatcher assetMatcher = profile.object.getAssetUpdateMatcher(); - FileNameMatcher clientMatcher = profile.object.getClientUpdateMatcher(); + 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)) { // Verify current state of all dirs @@ -506,7 +506,7 @@ public void launchLocal(SignedObjectHolder assetHDir, SignedObjectHol // Start WatchService, and only then client CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start(); CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start(); - launch(profile.object, params); + launch(profile, params); } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java index b63197c6..ec223381 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java @@ -44,7 +44,7 @@ public class LauncherSettings { @LauncherAPI public byte[] lastDigest; @LauncherAPI - public List> lastProfiles = new LinkedList<>(); + public List lastProfiles = new LinkedList<>(); @LauncherAPI public Map> lastHDirs = new HashMap<>(16); @@ -108,7 +108,7 @@ public void read(HInput input) throws IOException, SignatureException { lastProfiles.clear(); int lastProfilesCount = input.readLength(0); for (int i = 0; i < lastProfilesCount; i++) { - lastProfiles.add(new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER)); + lastProfiles.add(Launcher.gson.fromJson(input.readString(0),ClientProfile.class)); } lastHDirs.clear(); int lastHDirsCount = input.readLength(0); @@ -149,8 +149,8 @@ public void write(HOutput output) throws IOException { output.writeByteArray(lastDigest, 0); } output.writeLength(lastProfiles.size(), 0); - for (SignedObjectHolder profile : lastProfiles) { - profile.write(output); + for (ClientProfile profile : lastProfiles) { + output.writeString(Launcher.gson.toJson(profile),0); } output.writeLength(lastHDirs.size(), 0); for (Map.Entry> entry : lastHDirs.entrySet()) { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java index 2999b754..49a6e5ff 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java @@ -26,11 +26,11 @@ public final class LegacyLauncherRequest extends Request { public static final class Result { @LauncherAPI - public final List> profiles; + public final List profiles; private final byte[] binary; private final byte[] sign; - public Result(byte[] binary, byte[] sign, List> profiles) { + public Result(byte[] binary, byte[] sign, List profiles) { this.binary = binary == null ? null : binary.clone(); this.sign = sign.clone(); this.profiles = Collections.unmodifiableList(profiles); @@ -116,9 +116,12 @@ protected Result requestDo(HInput input, HOutput output) throws Exception { // Read clients profiles list int count = input.readLength(0); - List> profiles = new ArrayList<>(count); + List profiles = new ArrayList<>(count); for (int i = 0; i < count; i++) - profiles.add(new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER)); + { + String prof = input.readString(0); + profiles.add(Launcher.gson.fromJson(prof,ClientProfile.class)); + } // Return request result return new Result(null, sign, profiles); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java index c15f06f3..32c675e0 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java @@ -1,5 +1,6 @@ package ru.gravit.launcher.request.update; +import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.profiles.ClientProfile; @@ -48,8 +49,10 @@ protected Result requestDo(HInput input, HOutput output) throws Exception { int count = input.readLength(0); List profiles = new ArrayList<>(count); for (int i = 0; i < count; i++) - profiles.add(new SignedObjectHolder<>(input, config.publicKey, ClientProfile.RO_ADAPTER)); - + { + String prof = input.readString(0); + profiles.add(Launcher.gson.fromJson(prof,ClientProfile.class)); + } // Return request result return new Result(profiles); }