From 8df7d148da424ce0005d4700bd534a2fb00134a4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 24 Dec 2018 17:10:53 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D1=87=D0=B5=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D0=BA=D0=BE=D1=87=D0=B8=D1=82=D0=B0=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=D0=B9=20gson=20=D0=B8=20=D0=BC=D0=B0=D1=88=D0=B8=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 16 ++++++++++++++-- .../launchserver/command/basic/TestCommand.java | 2 +- .../command/dump/DumpSessionsCommand.java | 13 +++++++++++-- .../command/hash/DownloadClientCommand.java | 4 ++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 6d9eaf82..71e71149 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -1,5 +1,6 @@ package ru.gravit.launchserver; +import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; import ru.gravit.launcher.Launcher; @@ -262,6 +263,9 @@ public static void main(String... args) throws Throwable { public volatile Map> updatesDirMap; + public static Gson gson; + public static GsonBuilder gsonBuilder; + public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { // Setup config locations this.dir = dir; @@ -380,12 +384,20 @@ public static void initGson() { if(Launcher.gson != null) return; Launcher.gsonBuilder = new GsonBuilder(); - Launcher.gsonBuilder.setPrettyPrinting(); Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter()); Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter()); Launcher.gsonBuilder.registerTypeAdapter(AuthHandler.class, new AuthHandlerAdapter()); Launcher.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new HWIDHandlerAdapter()); Launcher.gson = Launcher.gsonBuilder.create(); + + //Human readable + LaunchServer.gsonBuilder = new GsonBuilder(); + LaunchServer.gsonBuilder.setPrettyPrinting(); + LaunchServer.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter()); + LaunchServer.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter()); + LaunchServer.gsonBuilder.registerTypeAdapter(AuthHandler.class, new AuthHandlerAdapter()); + LaunchServer.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new HWIDHandlerAdapter()); + LaunchServer.gson = LaunchServer.gsonBuilder.create(); } private LauncherBinary binary() { @@ -454,7 +466,7 @@ private void generateConfigIfNotExists() throws IOException { // Write LaunchServer config LogHelper.info("Writing LaunchServer config file"); try (BufferedWriter writer = IOHelper.newWriter(configFile)) { - Launcher.gson.toJson(newConfig,writer); + LaunchServer.gson.toJson(newConfig,writer); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java index 6e70173b..3e7edfd1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java @@ -39,7 +39,7 @@ public void invoke(String... args) throws Exception { ClientProfile profile = new ClientProfile("1.7.10","asset1.7.10",0,"Test1.7.10","localhost",25565,true,false,"net.minecraft.launchwrapper.Launch"); try(Writer writer = IOHelper.newWriter(LaunchServer.server.dir.resolve("profiles").resolve("Test.cfg"))) { - Launcher.gson.toJson(profile,writer); + LaunchServer.gson.toJson(profile,writer); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpSessionsCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpSessionsCommand.java index e42f4cb1..9ef36b43 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpSessionsCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpSessionsCommand.java @@ -7,6 +7,7 @@ import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; import java.io.Reader; import java.io.Writer; @@ -35,17 +36,25 @@ public void invoke(String... args) throws Exception { verifyArgs(args,2); if(args[0].equals("unload")) { + LogHelper.info("Sessions write to %s",args[1]); + Set clientSet = server.sessionManager.getSessions(); try(Writer writer = IOHelper.newWriter(Paths.get(args[1]))) { - Launcher.gson.toJson(server.sessionManager.getSessions(),writer); + LaunchServer.gson.toJson(clientSet,writer); } + LogHelper.subInfo("Write %d sessions",clientSet.size()); } else if(args[0].equals("load")) { + LogHelper.info("Sessions read from %s",args[1]); + int size = 0; try(Reader reader = IOHelper.newReader(Paths.get(args[1]))) { Type setType = new TypeToken>(){}.getType(); - server.sessionManager.loadSessions(Launcher.gson.fromJson(reader,setType)); + Set clientSet = LaunchServer.gson.fromJson(reader,setType); + size = clientSet.size(); + server.sessionManager.loadSessions(clientSet); } + LogHelper.subInfo("Readed %d sessions",size); } } } 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 7b3fb300..1fc38297 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 @@ -53,13 +53,13 @@ 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 = Launcher.gson.fromJson(reader,ClientProfile.class); + client = LaunchServer.gson.fromJson(reader,ClientProfile.class); } client.setTitle(dirName); client.setDir(dirName); try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, dirName, "cfg"))) { - Launcher.gson.toJson(client,writer); + LaunchServer.gson.toJson(client,writer); } // Finished