From 1e2363924f2332eabb437be71178a3621418f064 Mon Sep 17 00:00:00 2001 From: Ksenomorf <34306421+yKsenomorf@users.noreply.github.com> Date: Sat, 12 Jan 2019 23:04:50 +0300 Subject: [PATCH 01/10] Update ClientLauncherWrapper.java `Restart Launcher *witch* JavaAgent...`? --- .../src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index c8b4c21f..39a9633c 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -17,7 +17,7 @@ public class ClientLauncherWrapper { public static void main(String[] arguments) throws IOException, InterruptedException { LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); - LogHelper.info("Restart Launcher witch JavaAgent..."); + LogHelper.info("Restart Launcher with JavaAgent..."); LogHelper.info("If need debug output use -Dlauncher.debug=true"); JVMHelper.checkStackTrace(ClientLauncherWrapper.class); JVMHelper.verifySystemProperties(Launcher.class, true); From 3dd775807eb8319ee0d0a72e436533298a0c49ac Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Sun, 13 Jan 2019 18:51:39 +0300 Subject: [PATCH 02/10] =?UTF-8?q?[FIX][RUNTIME]=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D1=8B=D1=88?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=81=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BE=D0=B2=D0=B5=D1=80=D0=BB=D0=B5=D1=8F?= =?UTF-8?q?.=20(#140)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [UPD] Submodule `modules` updated. * [FIX] Profiles property: "info" + [FIX] Recenter mouse on stage. + [FIX] Auto-generating config generation (param: "isWarningMissArchJava"). * [FIXED] Access rules in ServerWrapper agent. * [FIX] Фикс ошибки мержа с master. * [FIX] AuthProvider в дефолтном конфиге. --- .../src/main/java/ru/gravit/launchserver/LaunchServer.java | 2 ++ .../resources/ru/gravit/launchserver/defaults/config.cfg | 5 +++-- Launcher/runtime/init.js | 1 - .../src/main/java/ru/gravit/launcher/server/ServerAgent.java | 4 ++-- modules | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 2c4be483..dfc6e4da 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -593,6 +593,8 @@ private void generateConfigIfNotExists() throws IOException { newConfig.enabledProGuard = true; newConfig.stripLineNumbers = true; newConfig.deleteTempFiles = true; + newConfig.isWarningMissArchJava = true; + // Set server address LogHelper.println("LaunchServer address: "); newConfig.setAddress(commandHandler.readLine()); diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg index 32a03972..85f9a164 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg @@ -51,11 +51,12 @@ "authRateLimitMilis": 0, "authRejectString": "Превышен лимит авторизаций", "whitelistRejectString": "Вас нет в белом списке", - "genMappings": false, + "genMappings": true, "isUsingWrapper": false, "isDownloadJava": false, - "isWarningMissArchJava": false, + "isWarningMissArchJava": true, "enabledProGuard": true, "stripLineNumbers": true, + "deleteTempFiles": true, "startScript": ".\\start.sh" } \ No newline at end of file diff --git a/Launcher/runtime/init.js b/Launcher/runtime/init.js index 34fca1c3..6763c970 100644 --- a/Launcher/runtime/init.js +++ b/Launcher/runtime/init.js @@ -52,7 +52,6 @@ function setCurrentScene(scene) { rootPane = scene.getRoot(); dimPane = rootPane.lookup("#mask"); stage.sizeToScene(); - stage.centerOnScreen(); stage.show(); } diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java index 2b248e36..e90e1f32 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java @@ -15,9 +15,9 @@ public class ServerAgent { private static boolean isAgentStarted = false; - public static Instrumentation inst; + public static Instrumentation inst = null; - public static final class StarterVisitor extends SimpleFileVisitor { + private static final class StarterVisitor extends SimpleFileVisitor { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.toFile().getName().endsWith(".jar")) addJVMClassPath(new JarFile(file.toFile())); diff --git a/modules b/modules index ee2f9e66..b582cd64 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit ee2f9e6646a8f1972ceda68d56e88e71ab74f78f +Subproject commit b582cd6405d45d4478e62ca11045a34378c96d9d From aa116cdd4a08044387963310d2272f865168a2e8 Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Mon, 14 Jan 2019 12:22:33 +0300 Subject: [PATCH 03/10] =?UTF-8?q?[ANY]=20=D0=9F=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20README.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 6e9356db..e786a5d3 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,3 @@ * Discord channel: https://discord.gg/aJK6nMN * [See license](LICENSE) * Changes: [ru-ru](docs/RU-changes.md#Изменения) [en-us](docs/EN-changes.md#changes) -* All administrators must go to our server discord, report Gravit server site and version of our launcher. From 302a606d22724404d2e93dd2201da3f33ea70b97 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 15 Jan 2019 09:23:27 +0700 Subject: [PATCH 04/10] =?UTF-8?q?[FEATURE]=20apiKey=20=D0=B2=20JsonHWIDHan?= =?UTF-8?q?dler=20=D0=B8=20JsonAuthProvider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/hwid/JsonHWIDHandler.java | 27 ++++++++++++++++--- .../auth/provider/JsonAuthProvider.java | 11 +++++++- modules | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index b218d1f2..0365ea7c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -21,6 +21,7 @@ public final class JsonHWIDHandler extends HWIDHandler { private URL urlBan; private URL urlUnBan; private URL urlGet; + private String apiKey; public class banRequest { public banRequest(OshiHWID hwid) { @@ -28,6 +29,12 @@ public banRequest(OshiHWID hwid) { } OshiHWID hwid; + String apiKey; + + public banRequest(OshiHWID hwid, String apiKey) { + this.hwid = hwid; + this.apiKey = apiKey; + } } public class checkRequest { @@ -38,7 +45,13 @@ public checkRequest(String username, OshiHWID hwid) { String username; OshiHWID hwid; + String apiKey; + public checkRequest(String username, OshiHWID hwid, String apiKey) { + this.username = username; + this.hwid = hwid; + this.apiKey = apiKey; + } } public class Result { @@ -56,12 +69,18 @@ public HWIDRequest(String username) { } String username; + String apiKey; + + public HWIDRequest(String username, String apiKey) { + this.username = username; + this.apiKey = apiKey; + } } @Override public void ban(List l_hwid) throws HWIDException { for (HWID hwid : l_hwid) { - banRequest request = new banRequest((OshiHWID) hwid); + banRequest request = new banRequest((OshiHWID) hwid, apiKey); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); Result r = gson.fromJson(result, Result.class); @@ -75,7 +94,7 @@ public void ban(List l_hwid) throws HWIDException { @Override public void check0(HWID hwid, String username) throws HWIDException { - checkRequest request = new checkRequest(username, (OshiHWID) hwid); + checkRequest request = new checkRequest(username, (OshiHWID) hwid, apiKey); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), url); BannedResult r = gson.fromJson(result, BannedResult.class); @@ -96,7 +115,7 @@ public void close() { @Override public List getHwid(String username) throws HWIDException { ArrayList hwids = new ArrayList<>(); - HWIDRequest request = new HWIDRequest(username); + HWIDRequest request = new HWIDRequest(username, apiKey); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlGet); OshiHWID[] r = gson.fromJson(result, OshiHWID[].class); @@ -111,7 +130,7 @@ public List getHwid(String username) throws HWIDException { @Override public void unban(List l_hwid) throws HWIDException { for (HWID hwid : l_hwid) { - banRequest request = new banRequest((OshiHWID) hwid); + banRequest request = new banRequest((OshiHWID) hwid, apiKey); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan); Result r = gson.fromJson(result, Result.class); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java index 26bd7a24..9db4f054 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java @@ -13,6 +13,7 @@ public final class JsonAuthProvider extends AuthProvider { private static Gson gson = new Gson(); private URL url; + private String apiKey; public class authResult { String username; @@ -27,14 +28,22 @@ public authRequest(String username, String password, String ip) { this.ip = ip; } + public authRequest(String username, String password, String ip, String apiKey) { + this.username = username; + this.password = password; + this.ip = ip; + this.apiKey = apiKey; + } + String username; String password; String ip; + String apiKey; } @Override public AuthProviderResult auth(String login, String password, String ip) throws IOException { - authRequest authRequest = new authRequest(login, password, ip); + authRequest authRequest = new authRequest(login, password, ip, apiKey); JsonElement request = gson.toJsonTree(authRequest); JsonElement content = HTTPRequest.jsonRequest(request, url); if (!content.isJsonObject()) diff --git a/modules b/modules index b582cd64..ee2f9e66 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit b582cd6405d45d4478e62ca11045a34378c96d9d +Subproject commit ee2f9e6646a8f1972ceda68d56e88e71ab74f78f From a2b3ac523b4eb02b85cb651647ab8687ddbe9c95 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 15 Jan 2019 10:32:46 +0700 Subject: [PATCH 05/10] [ANY] IDEA Code Cleanup --- .../launchserver/asm/ClassMetadataReader.java | 2 +- .../JsonFilePermissionsHandler.java | 2 +- .../auth/provider/RejectAuthProvider.java | 34 +++++------ .../launchserver/binary/tasks/TaskUtil.java | 16 ++--- .../command/service/ConfigListCommand.java | 2 +- .../command/service/ReloadListCommand.java | 2 +- .../command/service/ServerStatusCommand.java | 2 +- .../service/SwapAuthProviderCommand.java | 58 +++++++++---------- .../launchserver/manangers/MirrorManager.java | 2 +- .../manangers/ReconfigurableManager.java | 2 +- .../websocket/WebSocketFrameHandler.java | 2 +- .../socket/websocket/json/SimpleResponse.java | 2 +- .../json/admin/ExecCommandResponse.java | 2 +- .../json/auth/CheckServerResponse.java | 2 +- .../json/auth/JoinServerResponse.java | 2 +- .../json/update/LauncherResponse.java | 2 +- .../json/update/UpdateListResponse.java | 2 +- .../ru/gravit/launcher/client/DirBridge.java | 2 +- .../launcher/client/FunctionalBridge.java | 5 +- .../launcher/client/LauncherSettings.java | 2 +- .../request/update/LauncherRequest.java | 3 +- .../request/websockets/ClientJSONPoint.java | 2 +- .../gravit/launcher/server/ServerAgent.java | 2 +- .../launcher/profiles/ClientProfile.java | 12 ++-- modules | 2 +- 25 files changed, 73 insertions(+), 93 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java index fd6e8ca5..abc16cd6 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java @@ -98,7 +98,7 @@ public ArrayList getSuperClasses(String type) { } @Override - public void close() throws IOException { + public void close() { cp.stream().forEach(IOHelper::close); cp.clear(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java index 72aa37ca..efcc369b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -22,7 +22,7 @@ public class JsonFilePermissionsHandler extends PermissionsHandler implements Re public static Map map; @Override - public void reload() throws Exception { + public void reload() { map.clear(); Path path = Paths.get(filename); Type type = new TypeToken>(){}.getType(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java index efe8af0a..eeda33f8 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -40,24 +40,22 @@ public void close() { @Override public void reconfig(String action, String[] args) { - if(action.equals("message")) - { - message = args[0]; - LogHelper.info("New reject message: %s", message); - } - else if(action.equals("whitelist.add")) - { - if(whitelist == null) whitelist = new ArrayList<>(); - whitelist.add(args[0]); - } - else if(action.equals("whitelist.remove")) - { - if(whitelist == null) whitelist = new ArrayList<>(); - whitelist.remove(args[0]); - } - else if(action.equals("whitelist.clear")) - { - whitelist.clear(); + switch (action) { + case "message": + message = args[0]; + LogHelper.info("New reject message: %s", message); + break; + case "whitelist.add": + if (whitelist == null) whitelist = new ArrayList<>(); + whitelist.add(args[0]); + break; + case "whitelist.remove": + if (whitelist == null) whitelist = new ArrayList<>(); + whitelist.remove(args[0]); + break; + case "whitelist.clear": + whitelist.clear(); + break; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/TaskUtil.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/TaskUtil.java index 8175b7e1..0bc00498 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/TaskUtil.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/TaskUtil.java @@ -8,22 +8,14 @@ public final class TaskUtil { public static void addCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskAdd) { List indexes = new ArrayList<>(); - tasks.stream().filter(pred).forEach(e -> { - indexes.add(e); - }); - indexes.forEach(e -> { - tasks.add(tasks.indexOf(e)+count, taskAdd); - }); + tasks.stream().filter(pred).forEach(e -> indexes.add(e)); + indexes.forEach(e -> tasks.add(tasks.indexOf(e)+count, taskAdd)); } public static void replaceCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskRep) { List indexes = new ArrayList<>(); - tasks.stream().filter(pred).forEach(e -> { - indexes.add(e); - }); - indexes.forEach(e -> { - tasks.set(tasks.indexOf(e)+count, taskRep); - }); + tasks.stream().filter(pred).forEach(e -> indexes.add(e)); + indexes.forEach(e -> tasks.set(tasks.indexOf(e)+count, taskRep)); } public static void addPre(List tasks, Predicate pred, LauncherBuildTask taskAdd) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java index 186d0e1e..3e2a19e2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java @@ -19,7 +19,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { server.reconfigurableManager.printReconfigurables(); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadListCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadListCommand.java index e588a796..5273fdb5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadListCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadListCommand.java @@ -19,7 +19,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { server.reloadManager.printReloadables(); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java index 8978453b..d43e4026 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java @@ -22,7 +22,7 @@ public String getUsageDescription() { } @Override - public void invoke(String... args) throws Exception { + public void invoke(String... args) { LogHelper.info("Show server status"); LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(),JVMHelper.RUNTIME.maxMemory()); long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java index 6a69c785..b6d84a92 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java @@ -29,38 +29,34 @@ public void invoke(String... args) throws Exception { verifyArgs(args,2); if(providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length]; int index = Integer.valueOf(args[0]); - if(args[1].equals("accept")) - { - if(providersCache[index] == null) - { - AcceptAuthProvider provider = new AcceptAuthProvider(); - providersCache[index] = server.config.authProvider[index]; - server.config.authProvider[index] = provider; - LogHelper.info("AuthProvider[%d] is AcceptAuthProvider",index); - } - else LogHelper.error("Changes detected. Use undo"); - } else if(args[1].equals("reject")) - { - if(providersCache[index] == null) - { - RejectAuthProvider rejectAuthProvider; - if(args.length < 3) rejectAuthProvider = new RejectAuthProvider(); - else rejectAuthProvider = new RejectAuthProvider(args[2]); - providersCache[index] = server.config.authProvider[index]; - server.config.authProvider[index] = rejectAuthProvider; - LogHelper.info("AuthProvider[%d] is RejectAuthProvider",index); - } - else LogHelper.error("Changes detected. Use undo"); - } else if(args[1].equals("undo")) - { - if(providersCache[index] == null) LogHelper.error("Cache clean. Undo impossible"); - else - { - server.config.authProvider[index].close(); - server.config.authProvider[index] = providersCache[index]; - providersCache[index] = null; - } + switch (args[1]) { + case "accept": + if (providersCache[index] == null) { + AcceptAuthProvider provider = new AcceptAuthProvider(); + providersCache[index] = server.config.authProvider[index]; + server.config.authProvider[index] = provider; + LogHelper.info("AuthProvider[%d] is AcceptAuthProvider", index); + } else LogHelper.error("Changes detected. Use undo"); + break; + case "reject": + if (providersCache[index] == null) { + RejectAuthProvider rejectAuthProvider; + if (args.length < 3) rejectAuthProvider = new RejectAuthProvider(); + else rejectAuthProvider = new RejectAuthProvider(args[2]); + providersCache[index] = server.config.authProvider[index]; + server.config.authProvider[index] = rejectAuthProvider; + LogHelper.info("AuthProvider[%d] is RejectAuthProvider", index); + } else LogHelper.error("Changes detected. Use undo"); + break; + case "undo": + if (providersCache[index] == null) LogHelper.error("Cache clean. Undo impossible"); + else { + server.config.authProvider[index].close(); + server.config.authProvider[index] = providersCache[index]; + providersCache[index] = null; + } + break; } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java index 89633b36..8faf84a4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java @@ -34,7 +34,7 @@ public URL getClientsURL(String client) throws MalformedURLException { protected ArrayList list = new ArrayList<>(); private Mirror defaultMirror; - public void addMirror(String mirror) throws MalformedURLException { + public void addMirror(String mirror) { Mirror m = new Mirror(mirror); m.enabled = true; if (defaultMirror == null) defaultMirror = m; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java index 36a7cddd..ccaed96d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java @@ -19,7 +19,7 @@ public void printHelp(String name) { RECONFIGURABLE.get(name).printConfigHelp(); } - public void call(String name, String action, String[] args) throws Exception { + public void call(String name, String action, String[] args) { RECONFIGURABLE.get(name).reconfig(action,args); } public void printReconfigurables() diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java index 7f548c8d..670c4bf1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java @@ -31,7 +31,7 @@ public void channelActive(ChannelHandlerContext ctx) { } @Override - protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception { + protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) { // ping and pong frames already handled if (frame instanceof TextWebSocketFrame) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/SimpleResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/SimpleResponse.java index 8c6f34f7..7f78179d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/SimpleResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/SimpleResponse.java @@ -11,7 +11,7 @@ public String getType() { } @Override - public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) { } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/ExecCommandResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/ExecCommandResponse.java index e05ca52c..3ecd04d9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/ExecCommandResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/ExecCommandResponse.java @@ -15,7 +15,7 @@ public String getType() { } @Override - public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) { if (!client.isAuth) { service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java index c88c8486..db7940ce 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java @@ -18,7 +18,7 @@ public String getType() { } @Override - public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) { try { LaunchServer.server.config.authHandler.checkServer(username, serverID); } catch (AuthException e) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java index 0ece3b78..612c9e4a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java @@ -19,7 +19,7 @@ public String getType() { } @Override - public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) { boolean success; try { success = LaunchServer.server.config.authHandler.joinServer(username, accessToken, serverID); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java index a3003988..28cc86ad 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java @@ -24,7 +24,7 @@ public String getType() { } @Override - public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) { byte[] bytes = Base64.getDecoder().decode(hash); if (launcher_type == 1) // JAR { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateListResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateListResponse.java index ac7d68d1..520ec3b5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateListResponse.java @@ -16,7 +16,7 @@ public String getType() { } @Override - public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) { if (!client.isAuth) { service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); return; diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java index 0b3890b1..4d7b346d 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java @@ -61,7 +61,7 @@ public static Path getLauncherDir(String projectname) throws IOException { } @LauncherAPI - public static Path getLegacyLauncherDir(String projectname) throws IOException { + public static Path getLegacyLauncherDir(String projectname) { return IOHelper.HOME_DIR.resolve(projectname); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index 8b94f5fe..ddee8bdb 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.security.SignatureException; import java.util.concurrent.atomic.AtomicReference; public class FunctionalBridge { @@ -33,7 +32,7 @@ public class FunctionalBridge { public static Thread getHWID = null; @LauncherAPI - public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) throws Exception { + public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) { return () -> { if (hdir == null) { Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); @@ -44,7 +43,7 @@ public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, S } @LauncherAPI - public static LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, SignatureException { + public static LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException { if (settings.lastDigest == null || settings.lastProfiles.isEmpty()) { Request.requestError("Запуск в оффлайн-режиме невозможен"); } 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 49a079fd..89aef608 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java @@ -62,7 +62,7 @@ public void load() throws SignatureException { } @LauncherAPI - public void save() throws SignatureException { + public void save() { LogHelper.debug("Save settings file"); try { try (HOutput output = new HOutput(IOHelper.newOutput(file))) { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java index adf44662..f8ed16ff 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java @@ -14,7 +14,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.security.SignatureException; import java.util.ArrayList; import java.util.List; @@ -46,7 +45,7 @@ public byte[] getDigest() { public static final boolean EXE_BINARY = IOHelper.hasExtension(BINARY_PATH, "exe"); @LauncherAPI - public static void update(LauncherConfig config, Result result) throws SignatureException, IOException { + public static void update(LauncherConfig config, Result result) throws IOException { List args = new ArrayList<>(8); args.add(IOHelper.resolveJavaBin(null).toString()); if (LogHelper.isDebugEnabled()) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java index 070e61d8..eb4c9aa0 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -51,7 +51,7 @@ public void send(String js) throws IOException { session.getBasicRemote().sendText(js); } - public void sendAsync(String js) throws IOException { + public void sendAsync(String js) { session.getAsyncRemote().sendText(js); } } \ No newline at end of file diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java index e90e1f32..8727ca82 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java @@ -30,7 +30,7 @@ public static void addJVMClassPath(String path) throws IOException { inst.appendToSystemClassLoaderSearch(new JarFile(path)); } - public static void addJVMClassPath(JarFile file) throws IOException { + public static void addJVMClassPath(JarFile file) { LogHelper.debug("Load %s", file.getName()); inst.appendToSystemClassLoaderSearch(file); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index 93ab5517..f9e3c86d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -6,7 +6,6 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; -import java.io.IOException; import java.net.InetSocketAddress; import java.util.*; @@ -383,7 +382,7 @@ else if(f.dependenciesCount.size() <= 1) } } - public void pushOptional(HashedDir dir, boolean digest) throws IOException { + public void pushOptional(HashedDir dir, boolean digest) { for (OptionalFile opt : updateOptional) { if (!opt.mark) dir.removeR(opt.file); } @@ -592,10 +591,7 @@ public boolean equals(Object obj) { } else if (!version.equals(other.version)) return false; if (whitelist == null) { - if (other.whitelist != null) - return false; - } else if (!whitelist.equals(other.whitelist)) - return false; - return true; - } + return other.whitelist == null; + } else return whitelist.equals(other.whitelist); + } } diff --git a/modules b/modules index ee2f9e66..bb4430df 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit ee2f9e6646a8f1972ceda68d56e88e71ab74f78f +Subproject commit bb4430df933db257638191857577824820b18c4a From 9884730b1b5700a36782bd1093f737519641037d Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 15 Jan 2019 10:35:39 +0700 Subject: [PATCH 06/10] [ANY] IDEA Code Reformat --- .../ru/gravit/launchserver/LaunchServer.java | 216 +++++------- .../gravit/launchserver/Reconfigurable.java | 3 +- .../ru/gravit/launchserver/Reloadable.java | 1 + .../ru/gravit/launchserver/StarterAgent.java | 7 +- .../launchserver/asm/ClassMetadataReader.java | 21 +- .../launchserver/asm/SafeClassWriter.java | 4 +- .../gravit/launchserver/auth/AuthLimiter.java | 6 +- .../launchserver/auth/MySQLSourceConfig.java | 12 +- .../auth/handler/AuthHandler.java | 24 +- .../auth/handler/BinaryFileAuthHandler.java | 8 +- .../auth/handler/CachedAuthHandler.java | 20 +- .../auth/handler/FileAuthHandler.java | 22 +- .../auth/handler/MemoryAuthHandler.java | 6 +- .../auth/handler/MySQLAuthHandler.java | 23 +- .../auth/handler/NullAuthHandler.java | 6 +- .../auth/hwid/AcceptHWIDHandler.java | 4 +- .../launchserver/auth/hwid/HWIDHandler.java | 18 +- .../auth/hwid/JsonHWIDHandler.java | 15 +- .../auth/hwid/MysqlHWIDHandler.java | 32 +- .../permissions/ConfigPermissionsHandler.java | 1 + .../JsonFilePermissionsHandler.java | 51 ++- .../auth/permissions/PermissionsHandler.java | 22 +- .../auth/provider/AuthProvider.java | 26 +- .../auth/provider/JsonAuthProvider.java | 7 +- .../auth/provider/MojangAuthProvider.java | 11 +- .../auth/provider/MySQLAuthProvider.java | 16 +- .../auth/provider/NullAuthProvider.java | 4 +- .../auth/provider/RejectAuthProvider.java | 13 +- .../auth/provider/RequestAuthProvider.java | 17 +- .../launchserver/binary/BuildContext.java | 6 +- .../binary/EXEL4JLauncherBinary.java | 12 +- .../binary/EXELauncherBinary.java | 6 +- .../launchserver/binary/JAConfigurator.java | 11 +- .../binary/JARLauncherBinary.java | 68 ++-- .../launchserver/binary/LauncherBinary.java | 6 +- .../launchserver/binary/ProguardConf.java | 28 +- .../tasks/AdditionalFixesApplyTask.java | 121 ++++--- .../binary/tasks/AttachJarsTask.java | 126 +++---- .../binary/tasks/LauncherBuildTask.java | 2 + .../binary/tasks/MainBuildTask.java | 67 ++-- .../binary/tasks/PrepareBuildTask.java | 16 +- .../binary/tasks/ProGuardBuildTask.java | 46 +-- .../launchserver/binary/tasks/TaskUtil.java | 84 ++--- .../gravit/launchserver/command/Command.java | 4 +- .../command/auth/AuthCommand.java | 4 +- .../launchserver/command/auth/BanCommand.java | 4 +- .../command/auth/UUIDToUsernameCommand.java | 6 +- .../command/auth/UnbanCommand.java | 4 +- .../command/auth/UsernameToUUIDCommand.java | 6 +- .../command/basic/DebugCommand.java | 5 +- .../command/basic/HelpCommand.java | 4 +- .../command/basic/ProguardCleanCommand.java | 6 +- .../basic/RegenProguardDictCommand.java | 4 +- .../basic/RemoveMappingsProguardCommand.java | 6 +- .../command/basic/RestartCommand.java | 2 +- .../command/basic/TestCommand.java | 11 +- .../command/dump/DumpEntryCacheCommand.java | 48 ++- .../command/dump/DumpSessionsCommand.java | 44 ++- .../command/handler/CommandHandler.java | 52 +-- .../command/handler/JLineCommandHandler.java | 4 +- .../command/handler/StdCommandHandler.java | 6 +- .../command/hash/DownloadAssetCommand.java | 8 +- .../command/hash/DownloadClientCommand.java | 18 +- .../command/hash/IndexAssetCommand.java | 23 +- .../command/hash/SyncBinariesCommand.java | 4 +- .../command/hash/SyncProfilesCommand.java | 4 +- .../command/hash/SyncUpdatesCommand.java | 8 +- .../command/hash/UnindexAssetCommand.java | 19 +- .../command/modules/LoadModuleCommand.java | 6 +- .../command/service/ConfigCommand.java | 6 +- .../command/service/ConfigHelpCommand.java | 4 +- .../command/service/ReloadAllCommand.java | 2 +- .../command/service/ReloadCommand.java | 4 +- .../command/service/ServerStatusCommand.java | 13 +- .../service/SwapAuthProviderCommand.java | 7 +- .../config/AuthHandlerAdapter.java | 17 +- .../config/AuthProviderAdapter.java | 15 +- .../config/HWIDHandlerAdapter.java | 15 +- .../config/PermissionsHandlerAdapter.java | 15 +- .../config/TextureProviderAdapter.java | 15 +- .../ClosingChannelFutureListener.java | 4 +- .../fileserver/FileServerHandler.java | 52 +-- .../launchserver/manangers/MirrorManager.java | 4 +- .../manangers/ModulesManager.java | 7 +- .../manangers/ReconfigurableManager.java | 21 +- .../launchserver/manangers/ReloadManager.java | 25 +- .../manangers/SessionManager.java | 14 +- .../manangers/hook/AuthHookManager.java | 68 ++-- .../manangers/hook/BuildHookManager.java | 10 +- .../manangers/hook/SocketHookManager.java | 88 +++-- .../launchserver/response/PingResponse.java | 4 +- .../launchserver/response/Response.java | 21 +- .../response/admin/ExecCommandResponse.java | 8 +- .../response/auth/AuthResponse.java | 26 +- .../response/auth/AuthServerResponse.java | 14 +- .../response/auth/CheckServerResponse.java | 11 +- .../response/auth/JoinServerResponse.java | 9 +- .../response/auth/SetProfileResponse.java | 4 +- .../BatchProfileByUsernameResponse.java | 6 +- .../profile/ProfileByUUIDResponse.java | 6 +- .../profile/ProfileByUsernameResponse.java | 6 +- .../response/update/LauncherResponse.java | 6 +- .../update/LegacyLauncherResponse.java | 4 +- .../response/update/ProfilesResponse.java | 8 +- .../response/update/UpdateListResponse.java | 6 +- .../response/update/UpdateResponse.java | 19 +- .../socket/NettyServerSocketHandler.java | 52 ++- .../launchserver/socket/ResponseThread.java | 20 +- .../socket/ServerSocketHandler.java | 23 +- .../websocket/WebSocketFrameHandler.java | 1 - .../websocket/WebSocketIndexPageHandler.java | 25 +- .../socket/websocket/WebSocketService.java | 5 +- .../websocket/json/JsonResponseAdapter.java | 14 +- .../websocket/json/auth/AuthResponse.java | 4 +- .../json/update/LauncherResponse.java | 6 +- .../texture/NullTextureProvider.java | 6 +- .../texture/RequestTextureProvider.java | 8 +- .../launchserver/texture/TextureProvider.java | 18 +- .../texture/VoidTextureProvider.java | 4 +- .../ru/gravit/launcher/LauncherEngine.java | 20 +- .../launcher/client/ClientLauncher.java | 66 ++-- .../launcher/client/FunctionalBridge.java | 4 +- .../launcher/client/LauncherSettings.java | 4 +- .../launcher/gui/JSRuntimeProvider.java | 2 + .../gravit/launcher/gui/RuntimeProvider.java | 2 + .../launcher/hwid/OshiHWIDProvider.java | 29 +- .../ru/gravit/launcher/request/Request.java | 4 +- .../request/admin/ExecCommandRequest.java | 8 +- .../launcher/request/auth/AuthRequest.java | 2 +- .../request/update/LegacyLauncherRequest.java | 5 +- .../request/update/ProfilesRequest.java | 5 +- .../launcher/server/ModulesManager.java | 1 + .../gravit/launcher/server/ServerWrapper.java | 42 +-- .../ru/gravit/launcher/AutogenConfig.java | 2 +- .../ru/gravit/launcher/ClientPermissions.java | 3 + .../managers/ModulesConfigManager.java | 11 +- .../launcher/modules/ModuleContext.java | 1 + .../ModulesConfigManagerInterface.java | 1 + .../launcher/profiles/ClientProfile.java | 315 +++++++++--------- .../gravit/launcher/request/RequestType.java | 2 +- .../java/ru/gravit/utils/HTTPRequest.java | 2 +- 141 files changed, 1277 insertions(+), 1529 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index dfc6e4da..1677edfa 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -1,42 +1,7 @@ package ru.gravit.launchserver; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; -import java.lang.ProcessBuilder.Redirect; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.SocketAddress; -import java.nio.file.DirectoryStream; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.security.KeyPair; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.zip.CRC32; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.hasher.HashedDir; @@ -52,24 +17,12 @@ import ru.gravit.launchserver.auth.permissions.PermissionsHandler; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.RejectAuthProvider; -import ru.gravit.launchserver.binary.EXEL4JLauncherBinary; -import ru.gravit.launchserver.binary.EXELauncherBinary; -import ru.gravit.launchserver.binary.JARLauncherBinary; -import ru.gravit.launchserver.binary.LauncherBinary; -import ru.gravit.launchserver.binary.ProguardConf; +import ru.gravit.launchserver.binary.*; import ru.gravit.launchserver.command.handler.CommandHandler; import ru.gravit.launchserver.command.handler.JLineCommandHandler; import ru.gravit.launchserver.command.handler.StdCommandHandler; -import ru.gravit.launchserver.config.AuthHandlerAdapter; -import ru.gravit.launchserver.config.AuthProviderAdapter; -import ru.gravit.launchserver.config.HWIDHandlerAdapter; -import ru.gravit.launchserver.config.PermissionsHandlerAdapter; -import ru.gravit.launchserver.config.TextureProviderAdapter; -import ru.gravit.launchserver.manangers.MirrorManager; -import ru.gravit.launchserver.manangers.ModulesManager; -import ru.gravit.launchserver.manangers.ReconfigurableManager; -import ru.gravit.launchserver.manangers.ReloadManager; -import ru.gravit.launchserver.manangers.SessionManager; +import ru.gravit.launchserver.config.*; +import ru.gravit.launchserver.manangers.*; import ru.gravit.launchserver.manangers.hook.AuthHookManager; import ru.gravit.launchserver.manangers.hook.BuildHookManager; import ru.gravit.launchserver.manangers.hook.SocketHookManager; @@ -77,16 +30,32 @@ import ru.gravit.launchserver.socket.ServerSocketHandler; import ru.gravit.launchserver.texture.RequestTextureProvider; import ru.gravit.launchserver.texture.TextureProvider; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; +import ru.gravit.utils.helper.*; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.lang.ProcessBuilder.Redirect; +import java.net.InetSocketAddress; +import java.net.MalformedURLException; +import java.net.SocketAddress; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.security.KeyPair; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.time.Duration; +import java.time.Instant; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.zip.CRC32; public final class LaunchServer implements Runnable { public static final class Config { - public int port; + public int port; private String address; @@ -95,7 +64,7 @@ public static final class Config { public String projectName; public String[] mirrors; - + public String binaryName; public LauncherConfig.LauncherEnvironment env; @@ -104,7 +73,7 @@ public static final class Config { public AuthProvider[] authProvider; - public AuthHandler authHandler; + public AuthHandler authHandler; public PermissionsHandler permissionsHandler; @@ -138,10 +107,10 @@ public static final class Config { public boolean isWarningMissArchJava; public boolean enabledProGuard; public boolean stripLineNumbers; - public boolean deleteTempFiles; - public boolean enableRcon; - - public String startScript; + public boolean deleteTempFiles; + public boolean enableRcon; + + public String startScript; public String getAddress() { @@ -178,24 +147,19 @@ public void setAddress(String address) { public void verify() { VerifyHelper.verify(getAddress(), VerifyHelper.NOT_EMPTY, "LaunchServer address can't be empty"); - if(authHandler == null) - { + if (authHandler == null) { throw new NullPointerException("AuthHandler must not be null"); } - if(authProvider == null || authProvider[0] == null) - { + if (authProvider == null || authProvider[0] == null) { throw new NullPointerException("AuthProvider must not be null"); } - if(textureProvider == null) - { + if (textureProvider == null) { throw new NullPointerException("TextureProvider must not be null"); } - if(permissionsHandler == null) - { + if (permissionsHandler == null) { throw new NullPointerException("PermissionsHandler must not be null"); } - if(env == null) - { + if (env == null) { throw new NullPointerException("Env must not be null"); } } @@ -229,7 +193,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO // Read profile ClientProfile profile; try (BufferedReader reader = IOHelper.newReader(file)) { - profile = Launcher.gson.fromJson(reader,ClientProfile.class); + profile = Launcher.gson.fromJson(reader, ClientProfile.class); } profile.verify(); @@ -262,10 +226,10 @@ public static void main(String... args) throws Throwable { public final Path dir; - public final Path launcherLibraries; + public final Path launcherLibraries; + + public final List args; - public final List args; - public final Path configFile; public final Path publicKeyFile; @@ -273,7 +237,7 @@ public static void main(String... args) throws Throwable { public final Path privateKeyFile; public final Path updatesDir; - + public static LaunchServer server = null; public final Path profilesDir; @@ -333,8 +297,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE this.dir = dir; launcherLibraries = dir.resolve("launcher-libraries"); if (!Files.isDirectory(launcherLibraries)) { - Files.deleteIfExists(launcherLibraries); - Files.createDirectory(launcherLibraries); + Files.deleteIfExists(launcherLibraries); + Files.createDirectory(launcherLibraries); } this.args = Arrays.asList(args); configFile = dir.resolve("LaunchServer.conf"); @@ -400,11 +364,10 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE generateConfigIfNotExists(); LogHelper.info("Reading LaunchServer config file"); try (BufferedReader reader = IOHelper.newReader(configFile)) { - config = Launcher.gson.fromJson(reader,Config.class); + config = Launcher.gson.fromJson(reader, Config.class); } config.verify(); - for(AuthProvider provider : config.authProvider) - { + for (AuthProvider provider : config.authProvider) { provider.init(); } config.authHandler.init(); @@ -421,18 +384,17 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE authHookManager = new AuthHookManager(); GarbageManager.registerNeedGC(sessionManager); GarbageManager.registerNeedGC(limiter); - if(config.permissionsHandler instanceof Reloadable) - reloadManager.registerReloadable("permissionsHandler",(Reloadable) config.permissionsHandler); - if(config.authHandler instanceof Reloadable) - reloadManager.registerReloadable("authHandler",(Reloadable) config.authHandler); - for(int i=0;i { try { @@ -442,18 +404,17 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE } }); - if(config.permissionsHandler instanceof Reconfigurable) - reconfigurableManager.registerReconfigurable("permissionsHandler",(Reconfigurable) config.permissionsHandler); - if(config.authHandler instanceof Reconfigurable) - reconfigurableManager.registerReconfigurable("authHandler",(Reconfigurable) config.authHandler); - for(int i=0;i { try { @@ -469,7 +430,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // Set launcher EXE binary launcherBinary = new JARLauncherBinary(this); launcherEXEBinary = binary(); - + launcherBinary.init(); launcherEXEBinary.init(); syncLauncherBinaries(); @@ -492,9 +453,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE modulesManager.postInitModules(); } - public static void initGson() - { - if(Launcher.gson != null) return; + public static void initGson() { + if (Launcher.gson != null) return; Launcher.gsonBuilder = new GsonBuilder(); Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter()); Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter()); @@ -515,12 +475,12 @@ public static void initGson() } private LauncherBinary binary() { - try { - Class.forName("net.sf.launch4j.Builder"); + try { + Class.forName("net.sf.launch4j.Builder"); if (config.launch4j.enabled) return new EXEL4JLauncherBinary(this); - } catch (ClassNotFoundException ignored) { - LogHelper.warning("Launch4J isn't in classpath."); - } + } catch (ClassNotFoundException ignored) { + LogHelper.warning("Launch4J isn't in classpath."); + } return new EXELauncherBinary(this); } @@ -579,17 +539,17 @@ private void generateConfigIfNotExists() throws IOException { newConfig.hwidHandler = new AcceptHWIDHandler(); newConfig.authProvider = new AuthProvider[]{new RejectAuthProvider("Настройте authProvider")}; - newConfig.textureProvider = new RequestTextureProvider("http://example.com/skins/%username%.png","http://example.com/cloaks/%username%.png"); + newConfig.textureProvider = new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png"); newConfig.permissionsHandler = new JsonFilePermissionsHandler(); newConfig.port = 7240; newConfig.bindAddress = "0.0.0.0"; newConfig.authRejectString = "Превышен лимит авторизаций"; newConfig.binaryName = "Launcher"; newConfig.whitelistRejectString = "Вас нет в белом списке"; - + newConfig.threadCoreCount = 0; // on your own newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors(); - + newConfig.enabledProGuard = true; newConfig.stripLineNumbers = true; newConfig.deleteTempFiles = true; @@ -604,7 +564,7 @@ private void generateConfigIfNotExists() throws IOException { // Write LaunchServer config LogHelper.info("Writing LaunchServer config file"); try (BufferedWriter writer = IOHelper.newWriter(configFile)) { - LaunchServer.gson.toJson(newConfig,writer); + LaunchServer.gson.toJson(newConfig, writer); } } @@ -698,25 +658,25 @@ public void syncUpdatesDir(Collection dirs) throws IOException { } updatesDirMap = Collections.unmodifiableMap(newUpdatesDirMap); } - + public void restart() { - ProcessBuilder builder = new ProcessBuilder(); - List args = new ArrayList<>(); - if (config.startScript != null) args.add(config.startScript); - else throw new IllegalArgumentException ("Please create start script and link it as startScript in config."); + ProcessBuilder builder = new ProcessBuilder(); + List args = new ArrayList<>(); + if (config.startScript != null) args.add(config.startScript); + else throw new IllegalArgumentException("Please create start script and link it as startScript in config."); builder.directory(this.dir.toFile()); builder.inheritIO(); builder.redirectErrorStream(true); builder.redirectOutput(Redirect.PIPE); try { - builder.start(); - } catch (IOException e) { - LogHelper.error(e); - } + builder.start(); + } catch (IOException e) { + LogHelper.error(e); + } } - public void fullyRestart() { - restart(); + public void fullyRestart() { + restart(); JVMHelper.RUNTIME.exit(0); - } + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java b/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java index 0c83c2c8..2fd01db1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver; public interface Reconfigurable { - void reconfig(String action,String[] args); + void reconfig(String action, String[] args); + void printConfigHelp(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/Reloadable.java b/LaunchServer/src/main/java/ru/gravit/launchserver/Reloadable.java index 54492000..87a077ad 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/Reloadable.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/Reloadable.java @@ -1,4 +1,5 @@ package ru.gravit.launchserver; + @FunctionalInterface public interface Reloadable { void reload() throws Exception; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java index 9f6fb300..ed8b85c5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java @@ -2,12 +2,7 @@ import java.io.IOException; import java.lang.instrument.Instrumentation; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; +import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; import java.util.jar.JarFile; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java index abc16cd6..610f6925 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java @@ -1,5 +1,10 @@ package ru.gravit.launchserver.asm; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.Opcodes; +import ru.gravit.utils.helper.IOHelper; + import java.io.Closeable; import java.io.IOException; import java.io.InputStream; @@ -8,12 +13,6 @@ import java.util.List; import java.util.jar.JarFile; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.Opcodes; - -import ru.gravit.utils.helper.IOHelper; - /** * Позволяет искать методы внутри незагруженных классов и общие суперклассы для * чего угодно. Работает через поиск class-файлов в classpath. @@ -97,10 +96,10 @@ public ArrayList getSuperClasses(String type) { return superclasses; } - @Override - public void close() { - cp.stream().forEach(IOHelper::close); - cp.clear(); - } + @Override + public void close() { + cp.stream().forEach(IOHelper::close); + cp.clear(); + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/SafeClassWriter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/SafeClassWriter.java index d49ae26a..34ef1b44 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/SafeClassWriter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/SafeClassWriter.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.asm; -import java.util.ArrayList; - import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; +import java.util.ArrayList; + /** * ClassWriter с другой реализацией метода getCommonSuperClass: при его * использовании не происходит загрузки классов. 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 efdc5c6b..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,13 +1,13 @@ package ru.gravit.launchserver.auth; +import ru.gravit.launcher.NeedGarbageCollection; +import ru.gravit.launchserver.LaunchServer; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; -import ru.gravit.launcher.NeedGarbageCollection; -import ru.gravit.launchserver.LaunchServer; - public class AuthLimiter implements NeedGarbageCollection { static class AuthEntry { public int value; 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 2742bb06..95c16c79 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java @@ -1,17 +1,15 @@ package ru.gravit.launchserver.auth; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.DataSource; - import com.mysql.cj.jdbc.MysqlDataSource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; - import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + public final class MySQLSourceConfig implements AutoCloseable { public static final int TIMEOUT = VerifyHelper.verifyInt( @@ -22,7 +20,7 @@ public final class MySQLSourceConfig implements AutoCloseable { VerifyHelper.POSITIVE, "launcher.mysql.maxPoolSize can't be <= 0"); // Instance - private transient final String poolName; + private transient final String poolName; // Config private String address; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 362fd2ab..1f3e9dba 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -1,15 +1,15 @@ package ru.gravit.launchserver.auth.handler; +import ru.gravit.launchserver.auth.AuthException; +import ru.gravit.launchserver.auth.provider.AuthProviderResult; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.util.Map; import java.util.Objects; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import ru.gravit.launchserver.auth.AuthException; -import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.utils.helper.VerifyHelper; - public abstract class AuthHandler implements AutoCloseable { private static final Map> AUTH_HANDLERS = new ConcurrentHashMap<>(4); private static boolean registredHandl = false; @@ -25,15 +25,14 @@ public static void registerHandler(String name, Class ada VerifyHelper.putIfAbsent(AUTH_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"), String.format("Auth handler has been already registered: '%s'", name)); } - public static Class getHandlerClass(String name) - { + + public static Class getHandlerClass(String name) { return AUTH_HANDLERS.get(name); } - public static String getHandlerName(Class clazz) - { - for(Map.Entry> e: AUTH_HANDLERS.entrySet()) - { - if(e.getValue().equals(clazz)) return e.getKey(); + + public static String getHandlerName(Class clazz) { + for (Map.Entry> e : AUTH_HANDLERS.entrySet()) { + if (e.getValue().equals(clazz)) return e.getKey(); } return null; } @@ -66,8 +65,7 @@ public static void registerHandlers() { public abstract String uuidToUsername(UUID uuid) throws IOException; - public void init() - { + public void init() { } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java index 14385e80..820bfd0c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java @@ -1,14 +1,14 @@ package ru.gravit.launchserver.auth.handler; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.utils.helper.IOHelper; + import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.UUID; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.utils.helper.IOHelper; - public final class BinaryFileAuthHandler extends FileAuthHandler { @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java index 4f0f7fa9..82b598fd 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java @@ -1,17 +1,17 @@ package ru.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; - import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; + public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection { public static final class Entry { @@ -28,6 +28,7 @@ public Entry(UUID uuid, String username, String accessToken, String serverID) { this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); } } + private transient final Map entryCache = new HashMap<>(1024); private transient final Map usernamesCache = new HashMap<>(1024); @@ -114,12 +115,11 @@ public Map getUsernamesCache() { return usernamesCache; } - public void loadEntryCache(Map map) - { + public void loadEntryCache(Map map) { entryCache.putAll(map); } - public void loadUsernameCache(Map map) - { + + public void loadUsernameCache(Map map) { usernamesCache.putAll(map); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java index dd114a48..90dd12bf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java @@ -1,25 +1,17 @@ package ru.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.nio.file.Path; -import java.security.SecureRandom; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.locks.ReentrantReadWriteLock; - import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; +import ru.gravit.utils.helper.*; + +import java.io.IOException; +import java.nio.file.Path; +import java.security.SecureRandom; +import java.util.*; +import java.util.concurrent.locks.ReentrantReadWriteLock; public abstract class FileAuthHandler extends AuthHandler { public static final class Entry extends StreamObject { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MemoryAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MemoryAuthHandler.java index ba1c350f..792900ab 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MemoryAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MemoryAuthHandler.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.auth.handler; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.VerifyHelper; + import java.nio.ByteBuffer; import java.util.Arrays; import java.util.UUID; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.VerifyHelper; - public final class MemoryAuthHandler extends CachedAuthHandler { private static String toUsername(UUID uuid) { byte[] bytes = ByteBuffer.allocate(16). diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java index 41d65110..7c19b137 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java @@ -1,5 +1,8 @@ package ru.gravit.launchserver.auth.handler; +import ru.gravit.launchserver.auth.MySQLSourceConfig; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; @@ -7,9 +10,6 @@ import java.sql.SQLException; import java.util.UUID; -import ru.gravit.launchserver.auth.MySQLSourceConfig; -import ru.gravit.utils.helper.LogHelper; - public final class MySQLAuthHandler extends CachedAuthHandler { private MySQLSourceConfig mySQLHolder; private String uuidColumn; @@ -23,16 +23,16 @@ public final class MySQLAuthHandler extends CachedAuthHandler { private transient String queryByUsernameSQL; private transient String updateAuthSQL; private transient String updateServerIDSQL; + @Override - public void init() - { + public void init() { //Verify - if(mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null"); - if(uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null"); - if(usernameColumn == null) LogHelper.error("[Verify][AuthHandler] usernameColumn cannot be null"); - if(accessTokenColumn == null) LogHelper.error("[Verify][AuthHandler] accessTokenColumn cannot be null"); - if(serverIDColumn == null) LogHelper.error("[Verify][AuthHandler] serverIDColumn cannot be null"); - if(table == null) LogHelper.error("[Verify][AuthHandler] table cannot be null"); + if (mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null"); + if (uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null"); + if (usernameColumn == null) LogHelper.error("[Verify][AuthHandler] usernameColumn cannot be null"); + if (accessTokenColumn == null) LogHelper.error("[Verify][AuthHandler] accessTokenColumn cannot be null"); + if (serverIDColumn == null) LogHelper.error("[Verify][AuthHandler] serverIDColumn cannot be null"); + if (table == null) LogHelper.error("[Verify][AuthHandler] table cannot be null"); // Prepare SQL queries queryByUUIDSQL = String.format("SELECT %s, %s, %s, %s FROM %s WHERE %s=? LIMIT 1", uuidColumn, usernameColumn, accessTokenColumn, serverIDColumn, table, uuidColumn); @@ -43,6 +43,7 @@ public void init() updateServerIDSQL = String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1", table, serverIDColumn, uuidColumn); } + @Override public void close() { mySQLHolder.close(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/NullAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/NullAuthHandler.java index d49ee34f..c0d5ace1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/NullAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/NullAuthHandler.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.auth.handler; +import ru.gravit.launchserver.auth.provider.AuthProviderResult; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.util.Objects; import java.util.UUID; -import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.utils.helper.VerifyHelper; - public final class NullAuthHandler extends AuthHandler { private volatile AuthHandler handler; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java index a83a14d3..ee657875 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.auth.hwid; +import ru.gravit.launcher.HWID; + import java.util.ArrayList; import java.util.List; -import ru.gravit.launcher.HWID; - public class AcceptHWIDHandler extends HWIDHandler { @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java index 7846807c..5438e20b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.auth.hwid; +import ru.gravit.launcher.HWID; +import ru.gravit.utils.helper.VerifyHelper; + import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import ru.gravit.launcher.HWID; -import ru.gravit.utils.helper.VerifyHelper; - public abstract class HWIDHandler implements AutoCloseable { private static final Map> HW_HANDLERS = new ConcurrentHashMap<>(4); private static boolean registredHandl = false; @@ -44,15 +44,13 @@ public void check(HWID hwid, String username) throws HWIDException { public abstract void unban(List hwid) throws HWIDException; - public static Class getHandlerClass(String name) - { + public static Class getHandlerClass(String name) { return HW_HANDLERS.get(name); } - public static String getHandlerName(Class clazz) - { - for(Map.Entry> e: HW_HANDLERS.entrySet()) - { - if(e.getValue().equals(clazz)) return e.getKey(); + + public static String getHandlerName(Class clazz) { + for (Map.Entry> e : HW_HANDLERS.entrySet()) { + if (e.getValue().equals(clazz)) return e.getKey(); } return null; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index 0365ea7c..0b222231 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -1,19 +1,18 @@ package ru.gravit.launchserver.auth.hwid; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import ru.gravit.launcher.HWID; +import ru.gravit.launcher.OshiHWID; +import ru.gravit.utils.HTTPRequest; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import com.google.gson.Gson; -import com.google.gson.JsonElement; - -import ru.gravit.launcher.HWID; -import ru.gravit.launcher.OshiHWID; -import ru.gravit.utils.HTTPRequest; -import ru.gravit.utils.helper.LogHelper; - public final class JsonHWIDHandler extends HWIDHandler { private static final Gson gson = new Gson(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 63e3423b..e102f3b7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -1,5 +1,11 @@ package ru.gravit.launchserver.auth.hwid; +import ru.gravit.launcher.HWID; +import ru.gravit.launcher.OshiHWID; +import ru.gravit.launchserver.auth.MySQLSourceConfig; +import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.LogHelper; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -7,12 +13,6 @@ import java.util.ArrayList; import java.util.List; -import ru.gravit.launcher.HWID; -import ru.gravit.launcher.OshiHWID; -import ru.gravit.launchserver.auth.MySQLSourceConfig; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.LogHelper; - public class MysqlHWIDHandler extends HWIDHandler { private MySQLSourceConfig mySQLHolder; @@ -56,7 +56,7 @@ public class MysqlHWIDHandler extends HWIDHandler { @Override public void check0(HWID hwid, String username) throws HWIDException { - if(hwid instanceof OshiHWID) { + if (hwid instanceof OshiHWID) { OshiHWID oshiHWID = (OshiHWID) hwid; try { Connection c = mySQLHolder.getConnection(); @@ -68,9 +68,9 @@ public void check0(HWID hwid, String username) throws HWIDException { // Execute SQL query s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { - if(set.next()) { + if (set.next()) { int hwid_id = set.getInt(userFieldHwid); - if(hwid_id == 0) { + if (hwid_id == 0) { onUpdateInfo(oshiHWID, username, c); } else { onCheckInfo(oshiHWID, username, c); @@ -93,7 +93,7 @@ public void onUpdateInfo(OshiHWID hwid, String username, Connection c) throws HW ResultSet set = a.executeQuery(); PreparedStatement ps; - if(set.next()) { + if (set.next()) { int id = set.getInt("id"); boolean isBanned = set.getBoolean(hwidFieldBanned); @@ -105,7 +105,7 @@ public void onUpdateInfo(OshiHWID hwid, String username, Connection c) throws HW ps.setQueryTimeout(MySQLSourceConfig.TIMEOUT); ps.executeUpdate(); - if(isBanned) { + if (isBanned) { throw new HWIDException(banMessage); } } else { @@ -136,9 +136,9 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI a.setString(i + 1, CommonHelper.replace(paramsHwids[i], replaceParams)); } ResultSet set = a.executeQuery(); - if(set.next()) { + if (set.next()) { boolean isBanned = set.getBoolean(hwidFieldBanned); - if(isBanned) { + if (isBanned) { throw new HWIDException(banMessage); } } else { @@ -151,7 +151,7 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI public void setIsBanned(HWID hwid, boolean isBanned) { LogHelper.debug("%s Request HWID: %s", isBanned ? "Ban" : "UnBan", hwid.toString()); - if(hwid instanceof OshiHWID) { + if (hwid instanceof OshiHWID) { OshiHWID oshiHWID = (OshiHWID) hwid; Connection c = null; try { @@ -199,9 +199,9 @@ public List getHwid(String username) { s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { - if(set.next()) { + if (set.next()) { int hwid_id = set.getInt(userFieldHwid); - if(hwid_id != 0) { + if (hwid_id != 0) { s = c.prepareStatement(String.format("SELECT * FROM `%s` WHERE `id` = ? LIMIT 1", tableHwids)); s.setInt(1, hwid_id); ResultSet rs = s.executeQuery(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java index f7ff9ba4..a128e759 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java @@ -5,6 +5,7 @@ public class ConfigPermissionsHandler extends PermissionsHandler { public boolean isAdmin = false; public boolean isServer = false; + @Override public ClientPermissions getPermissions(String username) { ClientPermissions permissions = new ClientPermissions(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java index efcc369b..dce8df30 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -1,5 +1,12 @@ package ru.gravit.launchserver.auth.permissions; +import com.google.gson.reflect.TypeToken; +import ru.gravit.launcher.ClientPermissions; +import ru.gravit.launcher.Launcher; +import ru.gravit.launchserver.Reloadable; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.io.Reader; import java.io.Writer; @@ -9,57 +16,47 @@ import java.util.HashMap; import java.util.Map; -import com.google.gson.reflect.TypeToken; - -import ru.gravit.launcher.ClientPermissions; -import ru.gravit.launcher.Launcher; -import ru.gravit.launchserver.Reloadable; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; - public class JsonFilePermissionsHandler extends PermissionsHandler implements Reloadable { public String filename = "permissions.json"; - public static Map map; + public static Map map; @Override public void reload() { map.clear(); Path path = Paths.get(filename); - Type type = new TypeToken>(){}.getType(); - try(Reader reader = IOHelper.newReader(path)) - { - map = Launcher.gson.fromJson(reader,type); + Type type = new TypeToken>() { + }.getType(); + try (Reader reader = IOHelper.newReader(path)) { + map = Launcher.gson.fromJson(reader, type); } catch (IOException e) { LogHelper.error(e); } } - public static class Enity - { + public static class Enity { public String username; public ClientPermissions permissions; } + @Override - public ClientPermissions getPermissions(String username) - { - return map.getOrDefault(username,ClientPermissions.DEFAULT); + public ClientPermissions getPermissions(String username) { + return map.getOrDefault(username, ClientPermissions.DEFAULT); } + public JsonFilePermissionsHandler() { - Type type = new TypeToken>(){}.getType(); + Type type = new TypeToken>() { + }.getType(); Path path = Paths.get(filename); - if(!IOHelper.exists(path)) - { + if (!IOHelper.exists(path)) { map = new HashMap<>(); - try(Writer writer = IOHelper.newWriter(path)) - { - Launcher.gson.toJson(map,writer); + try (Writer writer = IOHelper.newWriter(path)) { + Launcher.gson.toJson(map, writer); } catch (IOException e) { LogHelper.error(e); } } - try(Reader reader = IOHelper.newReader(path)) - { - map = Launcher.gson.fromJson(reader,type); + try (Reader reader = IOHelper.newReader(path)) { + map = Launcher.gson.fromJson(reader, type); } catch (IOException e) { LogHelper.error(e); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java index 92d7a883..db00382a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java @@ -1,32 +1,33 @@ package ru.gravit.launchserver.auth.permissions; +import ru.gravit.launcher.ClientPermissions; +import ru.gravit.utils.helper.VerifyHelper; + import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import ru.gravit.launcher.ClientPermissions; -import ru.gravit.utils.helper.VerifyHelper; - public abstract class PermissionsHandler { private static final Map> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4); private static boolean registredHandl = false; + public static void registerHandler(String name, Class adapter) { VerifyHelper.verifyIDName(name); VerifyHelper.putIfAbsent(PERMISSIONS_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"), String.format("Auth handler has been already registered: '%s'", name)); } - public static Class getHandlerClass(String name) - { + + public static Class getHandlerClass(String name) { return PERMISSIONS_HANDLERS.get(name); } - public static String getHandlerName(Class clazz) - { - for(Map.Entry> e: PERMISSIONS_HANDLERS.entrySet()) - { - if(e.getValue().equals(clazz)) return e.getKey(); + + public static String getHandlerName(Class clazz) { + for (Map.Entry> e : PERMISSIONS_HANDLERS.entrySet()) { + if (e.getValue().equals(clazz)) return e.getKey(); } return null; } + public static void registerHandlers() { if (!registredHandl) { registerHandler("json", JsonFilePermissionsHandler.class); @@ -35,5 +36,6 @@ public static void registerHandlers() { registredHandl = true; } } + public abstract ClientPermissions getPermissions(String username); } 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 87d08685..1fa23fce 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 @@ -1,15 +1,15 @@ package ru.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + public abstract class AuthProvider implements AutoCloseable { private static final Map> AUTH_PROVIDERS = new ConcurrentHashMap<>(8); private static boolean registredProv = false; @@ -49,20 +49,18 @@ public AuthHandler getAccociateHandler(int this_position) { @Override public abstract void close() throws IOException; - public static Class getProviderClass(String name) - { + public static Class getProviderClass(String name) { return AUTH_PROVIDERS.get(name); } - public static String getProviderName(Class clazz) - { - for(Map.Entry> e: AUTH_PROVIDERS.entrySet()) - { - if(e.getValue().equals(clazz)) return e.getKey(); + + public static String getProviderName(Class clazz) { + for (Map.Entry> e : AUTH_PROVIDERS.entrySet()) { + if (e.getValue().equals(clazz)) return e.getKey(); } return null; } - public void init() - { + + public void init() { } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java index 9db4f054..e024282a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java @@ -1,15 +1,14 @@ package ru.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.net.URL; - import com.google.gson.Gson; import com.google.gson.JsonElement; - import ru.gravit.launcher.ClientPermissions; import ru.gravit.utils.HTTPRequest; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.net.URL; + public final class JsonAuthProvider extends AuthProvider { private static Gson gson = new Gson(); private URL url; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MojangAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MojangAuthProvider.java index 7e14c836..5305c26f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MojangAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MojangAuthProvider.java @@ -1,16 +1,15 @@ package ru.gravit.launchserver.auth.provider; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import ru.gravit.utils.HTTPRequest; + import java.net.MalformedURLException; import java.net.URL; import java.util.UUID; import java.util.regex.Pattern; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import ru.gravit.utils.HTTPRequest; - public final class MojangAuthProvider extends AuthProvider { private static final Pattern UUID_REGEX = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); private static final URL URL; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java index 9f2dcdb0..e3e0c6ae 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -1,10 +1,5 @@ package ru.gravit.launchserver.auth.provider; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - import ru.gravit.launcher.ClientPermissions; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.MySQLSourceConfig; @@ -12,6 +7,11 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + public final class MySQLAuthProvider extends AuthProvider { private MySQLSourceConfig mySQLHolder; private String query; @@ -21,9 +21,9 @@ public final class MySQLAuthProvider extends AuthProvider { @Override public void init() { - if(query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null"); - if(message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null"); - if(mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null"); + if (query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null"); + if (message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null"); + if (mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null"); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/NullAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/NullAuthProvider.java index 7b4819c7..92fa8ea5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/NullAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/NullAuthProvider.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.auth.provider; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.util.Objects; -import ru.gravit.utils.helper.VerifyHelper; - public final class NullAuthProvider extends AuthProvider { private volatile AuthProvider provider; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java index eeda33f8..6c880ab1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.auth.provider; -import java.util.ArrayList; - import ru.gravit.launchserver.Reconfigurable; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.util.ArrayList; + public final class RejectAuthProvider extends AuthProvider implements Reconfigurable { public RejectAuthProvider() { } @@ -20,12 +20,9 @@ public RejectAuthProvider(String message) { @Override public AuthProviderResult auth(String login, String password, String ip) throws AuthException { - if(whitelist != null) - { - for(String username : whitelist) - { - if(login.equals(username)) - { + if (whitelist != null) { + for (String username : whitelist) { + if (login.equals(username)) { return new AuthProviderResult(login, SecurityHelper.randomStringToken()); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java index 917ca21e..f11ed82e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java @@ -1,16 +1,16 @@ package ru.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.net.URL; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import ru.gravit.launcher.ClientPermissions; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public final class RequestAuthProvider extends AuthProvider { private String url; private transient Pattern pattern; @@ -18,10 +18,9 @@ public final class RequestAuthProvider extends AuthProvider { private boolean usePermission; @Override - public void init() - { - if(url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null"); - if(response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null"); + public void init() { + if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null"); + if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null"); pattern = Pattern.compile(response); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java index 11da8ad1..48bf2272 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java @@ -1,5 +1,8 @@ package ru.gravit.launchserver.binary; +import ru.gravit.launchserver.binary.tasks.MainBuildTask; +import ru.gravit.utils.helper.IOHelper; + import java.io.IOException; import java.io.InputStream; import java.util.HashSet; @@ -8,9 +11,6 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import ru.gravit.launchserver.binary.tasks.MainBuildTask; -import ru.gravit.utils.helper.IOHelper; - public class BuildContext { public final ZipOutputStream output; public final JAConfigurator config; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java index e69b17d0..8be92cf1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java @@ -1,20 +1,16 @@ package ru.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Path; - import net.sf.launch4j.Builder; import net.sf.launch4j.Log; -import net.sf.launch4j.config.Config; -import net.sf.launch4j.config.ConfigPersister; -import net.sf.launch4j.config.Jre; -import net.sf.launch4j.config.LanguageID; -import net.sf.launch4j.config.VersionInfo; +import net.sf.launch4j.config.*; import ru.gravit.launcher.Launcher; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Path; + public final class EXEL4JLauncherBinary extends LauncherBinary { private final static class Launch4JLog extends Log { private static final Launch4JLog INSTANCE = new Launch4JLog(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXELauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXELauncherBinary.java index 64520247..16c68a2d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXELauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXELauncherBinary.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Files; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Files; + public class EXELauncherBinary extends LauncherBinary { public EXELauncherBinary(LaunchServer server) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java index 26084680..cf300df7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java @@ -1,16 +1,11 @@ package ru.gravit.launchserver.binary; -import java.io.IOException; - -import javassist.CannotCompileException; -import javassist.ClassPool; -import javassist.CtClass; -import javassist.CtConstructor; -import javassist.CtMethod; -import javassist.NotFoundException; +import javassist.*; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launchserver.binary.tasks.MainBuildTask; +import java.io.IOException; + public class JAConfigurator implements AutoCloseable { public ClassPool pool; public CtClass ctClass; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java index 6d207969..5a113e71 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -1,5 +1,12 @@ package ru.gravit.launchserver.binary; +import ru.gravit.launcher.Launcher; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.binary.tasks.*; +import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -7,26 +14,14 @@ import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import ru.gravit.launcher.Launcher; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.binary.tasks.AttachJarsTask; -import ru.gravit.launchserver.binary.tasks.LauncherBuildTask; -import ru.gravit.launchserver.binary.tasks.MainBuildTask; -import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask; -import ru.gravit.launchserver.binary.tasks.AdditionalFixesApplyTask; -import ru.gravit.launchserver.binary.tasks.PrepareBuildTask; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; - public final class JARLauncherBinary extends LauncherBinary { - public final AtomicLong count; + public final AtomicLong count; public final Path runtimeDir; public final Path guardDir; public final Path buildDir; public List tasks; public List coreLibs; - + public JARLauncherBinary(LaunchServer server) throws IOException { super(server); count = new AtomicLong(0); @@ -37,8 +32,8 @@ public JARLauncherBinary(LaunchServer server) throws IOException { tasks = new ArrayList<>(); coreLibs = new ArrayList<>(); if (!Files.isDirectory(buildDir)) { - Files.deleteIfExists(buildDir); - Files.createDirectory(buildDir); + Files.deleteIfExists(buildDir); + Files.createDirectory(buildDir); } } @@ -50,7 +45,7 @@ public void init() { tasks.add(new AttachJarsTask(server)); tasks.add(new AdditionalFixesApplyTask(server)); } - + @Override public void build() throws IOException { LogHelper.info("Building launcher binary file"); @@ -59,9 +54,8 @@ public void build() throws IOException { boolean isNeedDelete = false; long time_start = System.currentTimeMillis(); long time_this = time_start; - for(LauncherBuildTask task : tasks) - { - LogHelper.subInfo("Task %s",task.getName()); + for (LauncherBuildTask task : tasks) { + LogHelper.subInfo("Task %s", task.getName()); Path oldPath = thisPath; thisPath = task.process(oldPath); long time_task_end = System.currentTimeMillis(); @@ -69,27 +63,27 @@ public void build() throws IOException { time_this = time_task_end; if (isNeedDelete && server.config.deleteTempFiles) Files.deleteIfExists(oldPath); isNeedDelete = task.allowDelete(); - LogHelper.subInfo("Task %s processed from %d millis",task.getName(), time_task); + LogHelper.subInfo("Task %s processed from %d millis", task.getName(), time_task); } long time_end = System.currentTimeMillis(); if (isNeedDelete && server.config.deleteTempFiles) IOHelper.move(thisPath, syncBinaryFile); else IOHelper.copy(thisPath, syncBinaryFile); - LogHelper.info("Build successful from %d millis",time_end - time_start); - } - - public String nextName(String taskName) { - return String.format("Launcher-%s-%d.jar", taskName, count.getAndIncrement()); - } - - public Path nextPath(String taskName) { - return buildDir.resolve(nextName(taskName)); - } - - public Path nextPath(LauncherBuildTask task) { - return nextPath(task.getName()); + LogHelper.info("Build successful from %d millis", time_end - time_start); } - public Path nextLowerPath(LauncherBuildTask task) { - return nextPath(CommonHelper.low(task.getName())); - } + public String nextName(String taskName) { + return String.format("Launcher-%s-%d.jar", taskName, count.getAndIncrement()); + } + + public Path nextPath(String taskName) { + return buildDir.resolve(nextName(taskName)); + } + + public Path nextPath(LauncherBuildTask task) { + return nextPath(task.getName()); + } + + public Path nextLowerPath(LauncherBuildTask task) { + return nextPath(CommonHelper.low(task.getName())); + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java index 15adcfe2..da9a9be4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Path; - import ru.gravit.launcher.serialize.signed.DigestBytesHolder; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.nio.file.Path; + public abstract class LauncherBinary { public final LaunchServer server; public Path syncBinaryFile; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java index d4cd0bea..add2373b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java @@ -1,21 +1,17 @@ package ru.gravit.launchserver.binary; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.List; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.List; + public class ProguardConf { private static final String charsFirst = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"; private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; @@ -40,17 +36,17 @@ public ProguardConf(LaunchServer srv) { words = proguard.resolve("random.pro"); this.srv = srv; } - public String[] buildConfig(Path inputJar, Path outputJar) - { - List confStrs = new ArrayList<>(); + + public String[] buildConfig(Path inputJar, Path outputJar) { + List confStrs = new ArrayList<>(); prepare(false); if (srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'"); confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'"); confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'"); srv.launcherBinary.coreLibs.stream() - .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") - .forEach(confStrs::add); + .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") + .forEach(confStrs::add); confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add(readConf()); return confStrs.toArray(new String[0]); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index 0b334cbd..1f7a9cc9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -1,5 +1,13 @@ package ru.gravit.launchserver.binary.tasks; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.tree.ClassNode; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.asm.ClassMetadataReader; +import ru.gravit.launchserver.asm.SafeClassWriter; +import ru.gravit.utils.helper.IOHelper; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.file.Path; @@ -8,71 +16,62 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.tree.ClassNode; - -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.asm.ClassMetadataReader; -import ru.gravit.launchserver.asm.SafeClassWriter; -import ru.gravit.utils.helper.IOHelper; - public class AdditionalFixesApplyTask implements LauncherBuildTask { - private final LaunchServer server; - - public AdditionalFixesApplyTask(LaunchServer server) { - this.server = server; - } + private final LaunchServer server; - @Override - public String getName() { - return "AdditionalFixesApply"; - } + public AdditionalFixesApplyTask(LaunchServer server) { + this.server = server; + } - @Override - public Path process(Path inputFile) throws IOException { - Path out = server.launcherBinary.nextPath("post-fixed"); - try (ClassMetadataReader reader = new ClassMetadataReader()) { - reader.getCp().add(new JarFile(inputFile.toFile())); - try (ZipInputStream input = IOHelper.newZipInput(inputFile); - ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) { - ZipEntry e = input.getNextEntry(); - while (e != null) { - if (e.isDirectory()) { - e = input.getNextEntry(); - continue; - } - String filename = e.getName(); - output.putNextEntry(IOHelper.newZipEntry(e)); - if (filename.endsWith(".class")) { - byte[] bytes = null; - try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { - IOHelper.transfer(input, outputStream); - bytes = outputStream.toByteArray(); - } - output.write(classFix(bytes, reader, server.config.stripLineNumbers)); - } else - IOHelper.transfer(input, output); - e = input.getNextEntry(); - } - } - } - return out; - } + @Override + public String getName() { + return "AdditionalFixesApply"; + } - private static byte[] classFix(byte[] bytes, ClassMetadataReader reader, boolean stripNumbers) { - ClassReader cr = new ClassReader(bytes); - ClassNode cn = new ClassNode(); - cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES); - - ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - cn.accept(cw); - return cw.toByteArray(); - } + @Override + public Path process(Path inputFile) throws IOException { + Path out = server.launcherBinary.nextPath("post-fixed"); + try (ClassMetadataReader reader = new ClassMetadataReader()) { + reader.getCp().add(new JarFile(inputFile.toFile())); + try (ZipInputStream input = IOHelper.newZipInput(inputFile); + ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) { + ZipEntry e = input.getNextEntry(); + while (e != null) { + if (e.isDirectory()) { + e = input.getNextEntry(); + continue; + } + String filename = e.getName(); + output.putNextEntry(IOHelper.newZipEntry(e)); + if (filename.endsWith(".class")) { + byte[] bytes = null; + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { + IOHelper.transfer(input, outputStream); + bytes = outputStream.toByteArray(); + } + output.write(classFix(bytes, reader, server.config.stripLineNumbers)); + } else + IOHelper.transfer(input, output); + e = input.getNextEntry(); + } + } + } + return out; + } - @Override - public boolean allowDelete() { - return true; - } + private static byte[] classFix(byte[] bytes, ClassMetadataReader reader, boolean stripNumbers) { + ClassReader cr = new ClassReader(bytes); + ClassNode cn = new ClassNode(); + cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES); + + ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + cn.accept(cw); + return cw.toByteArray(); + } + + @Override + public boolean allowDelete() { + return true; + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java index 0a880d37..e337495e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/AttachJarsTask.java @@ -1,5 +1,9 @@ package ru.gravit.launchserver.binary.tasks; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; @@ -8,75 +12,71 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; - public class AttachJarsTask implements LauncherBuildTask { - private final LaunchServer srv; - private final List jars; - private final List exclusions; + private final LaunchServer srv; + private final List jars; + private final List exclusions; - public AttachJarsTask(LaunchServer srv) { - this.srv = srv; - jars = new ArrayList<>(); - exclusions = new ArrayList<>(); - exclusions.add("META-INF"); - } + public AttachJarsTask(LaunchServer srv) { + this.srv = srv; + jars = new ArrayList<>(); + exclusions = new ArrayList<>(); + exclusions.add("META-INF"); + } - @Override - public String getName() { - return "AttachJars"; - } + @Override + public String getName() { + return "AttachJars"; + } - @Override - public Path process(Path inputFile) throws IOException { - Path outputFile = srv.launcherBinary.nextPath("attached"); - try (ZipInputStream input = IOHelper.newZipInput(inputFile); - ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputFile))) { - ZipEntry e = input.getNextEntry(); - while (e != null) { - if (e.isDirectory()) { - e = input.getNextEntry(); - continue; - } - output.putNextEntry(IOHelper.newZipEntry(e)); - IOHelper.transfer(input, output); - e = input.getNextEntry(); - } - attach(output, srv.launcherBinary.coreLibs); - attach(output, jars); - } - return outputFile; - } + @Override + public Path process(Path inputFile) throws IOException { + Path outputFile = srv.launcherBinary.nextPath("attached"); + try (ZipInputStream input = IOHelper.newZipInput(inputFile); + ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputFile))) { + ZipEntry e = input.getNextEntry(); + while (e != null) { + if (e.isDirectory()) { + e = input.getNextEntry(); + continue; + } + output.putNextEntry(IOHelper.newZipEntry(e)); + IOHelper.transfer(input, output); + e = input.getNextEntry(); + } + attach(output, srv.launcherBinary.coreLibs); + attach(output, jars); + } + return outputFile; + } - private void attach(ZipOutputStream output, List lst) throws IOException { - for (Path p : lst) { - LogHelper.debug("Attaching: " + p); - try (ZipInputStream input = IOHelper.newZipInput(p)) { - ZipEntry e = input.getNextEntry(); - while (e != null) { - String filename = e.getName(); - if (exclusions.stream().noneMatch(filename::startsWith) && !e.isDirectory()) { - output.putNextEntry(IOHelper.newZipEntry(e)); - IOHelper.transfer(input, output); - } - e = input.getNextEntry(); - } - } - } - } + private void attach(ZipOutputStream output, List lst) throws IOException { + for (Path p : lst) { + LogHelper.debug("Attaching: " + p); + try (ZipInputStream input = IOHelper.newZipInput(p)) { + ZipEntry e = input.getNextEntry(); + while (e != null) { + String filename = e.getName(); + if (exclusions.stream().noneMatch(filename::startsWith) && !e.isDirectory()) { + output.putNextEntry(IOHelper.newZipEntry(e)); + IOHelper.transfer(input, output); + } + e = input.getNextEntry(); + } + } + } + } - @Override - public boolean allowDelete() { - return true; - } + @Override + public boolean allowDelete() { + return true; + } - public List getJars() { - return jars; - } + public List getJars() { + return jars; + } - public List getExclusions() { - return exclusions; - } + public List getExclusions() { + return exclusions; + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/LauncherBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/LauncherBuildTask.java index 59d337ce..b99e1036 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/LauncherBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/LauncherBuildTask.java @@ -5,6 +5,8 @@ public interface LauncherBuildTask { String getName(); + Path process(Path inputFile) throws IOException; + boolean allowDelete(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java index 88a5f602..5acbad06 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -1,21 +1,5 @@ package ru.gravit.launchserver.binary.tasks; -import static ru.gravit.utils.helper.IOHelper.newZipEntry; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.HashMap; -import java.util.Map; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; - import javassist.CannotCompileException; import javassist.NotFoundException; import ru.gravit.launcher.AutogenConfig; @@ -30,9 +14,26 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.HashMap; +import java.util.Map; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +import static ru.gravit.utils.helper.IOHelper.newZipEntry; + public class MainBuildTask implements LauncherBuildTask { - private final LaunchServer server; - public final ClassMetadataReader reader; + private final LaunchServer server; + public final ClassMetadataReader reader; + private final class RuntimeDirVisitor extends SimpleFileVisitor { private final ZipOutputStream output; private final Map runtime; @@ -102,7 +103,7 @@ private static ZipEntry newGuardEntry(String fileName) { } public MainBuildTask(LaunchServer srv) { - server = srv; + server = srv; reader = new ClassMetadataReader(); } @@ -118,13 +119,13 @@ public Path process(Path inputJar) throws IOException { JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class.getName(), this)) { jaConfigurator.pool.insertClassPath(inputJar.toFile().getAbsolutePath()); server.launcherBinary.coreLibs.stream().map(e -> e.toFile().getAbsolutePath()) - .forEach(t -> { - try { - jaConfigurator.pool.appendClassPath(t); - } catch (NotFoundException e2) { - LogHelper.error(e2); - } - }); + .forEach(t -> { + try { + jaConfigurator.pool.appendClassPath(t); + } catch (NotFoundException e2) { + LogHelper.error(e2); + } + }); BuildContext context = new BuildContext(output, jaConfigurator, this); server.buildHookManager.hook(context); jaConfigurator.setAddress(server.config.getAddress()); @@ -138,12 +139,12 @@ public Path process(Path inputJar) throws IOException { server.buildHookManager.registerAllClientModuleClass(jaConfigurator); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { - try { - reader.getCp().add(new JarFile(e.toFile())); - } catch (IOException e1) { - LogHelper.error(e1); - } - }); + try { + reader.getCp().add(new JarFile(e.toFile())); + } catch (IOException e1) { + LogHelper.error(e1); + } + }); try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(inputJar))) { ZipEntry e = input.getNextEntry(); while (e != null) { @@ -169,7 +170,7 @@ public Path process(Path inputJar) throws IOException { } bytes = server.buildHookManager.classTransform(bytes, classname, this); output.write(bytes); - } else + } else IOHelper.transfer(input, output); context.fileList.add(filename); e = input.getNextEntry(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java index 61ec274c..9bf3f70d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java @@ -15,12 +15,12 @@ public class PrepareBuildTask implements LauncherBuildTask { private final LaunchServer server; - private final Path result; - + private final Path result; + public PrepareBuildTask(LaunchServer server) { - this.server = server; - result = server.launcherBinary.buildDir.resolve(server.config.binaryName + "-clean.jar"); - } + this.server = server; + result = server.launcherBinary.buildDir.resolve(server.config.binaryName + "-clean.jar"); + } @Override public String getName() { @@ -29,8 +29,8 @@ public String getName() { @Override public Path process(Path inputFile) throws IOException { - server.launcherBinary.coreLibs.clear(); - IOHelper.walk(server.launcherLibraries, new ListFileVisitor(server.launcherBinary.coreLibs), true); + server.launcherBinary.coreLibs.clear(); + IOHelper.walk(server.launcherLibraries, new ListFileVisitor(server.launcherBinary.coreLibs), true); UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), result); tryUnpack(); return result; @@ -46,7 +46,7 @@ public void tryUnpack() throws IOException { UnpackHelper.unpackZipNoCheck("guard.zip", server.launcherBinary.guardDir); UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir); } - + private static final class ListFileVisitor extends SimpleFileVisitor { private final List lst; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/ProGuardBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/ProGuardBuildTask.java index 9be2393d..ce086579 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/ProGuardBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/ProGuardBuildTask.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.binary.tasks; -import java.io.IOException; -import java.nio.file.Path; - import proguard.Configuration; import proguard.ConfigurationParser; import proguard.ParseException; @@ -11,38 +8,41 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Path; + public class ProGuardBuildTask implements LauncherBuildTask { private final LaunchServer server; public ProGuardBuildTask(LaunchServer server) { - this.server = server; + this.server = server; } - @Override + @Override public String getName() { return "ProGuard"; } @Override public Path process(Path inputFile) throws IOException { - if (server.config.enabledProGuard) { - Path outputJar = server.launcherBinary.nextLowerPath(this); - Configuration proguard_cfg = new Configuration(); - ConfigurationParser parser = new ConfigurationParser(server.proguardConf.buildConfig(inputFile, outputJar), - server.proguardConf.proguard.toFile(), System.getProperties()); - try { - parser.parse(proguard_cfg); - ProGuard proGuard = new ProGuard(proguard_cfg); - proGuard.execute(); - } catch (ParseException e) { - LogHelper.error(e); - } - return outputJar; - } else { - Path outputJar = server.launcherBinary.nextPath("non-obf"); - IOHelper.copy(inputFile, outputJar); - return outputJar; - } + if (server.config.enabledProGuard) { + Path outputJar = server.launcherBinary.nextLowerPath(this); + Configuration proguard_cfg = new Configuration(); + ConfigurationParser parser = new ConfigurationParser(server.proguardConf.buildConfig(inputFile, outputJar), + server.proguardConf.proguard.toFile(), System.getProperties()); + try { + parser.parse(proguard_cfg); + ProGuard proGuard = new ProGuard(proguard_cfg); + proGuard.execute(); + } catch (ParseException e) { + LogHelper.error(e); + } + return outputJar; + } else { + Path outputJar = server.launcherBinary.nextPath("non-obf"); + IOHelper.copy(inputFile, outputJar); + return outputJar; + } } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/TaskUtil.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/TaskUtil.java index 0bc00498..b5f99f16 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/TaskUtil.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/TaskUtil.java @@ -6,46 +6,46 @@ import java.util.stream.Collectors; public final class TaskUtil { - public static void addCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskAdd) { - List indexes = new ArrayList<>(); - tasks.stream().filter(pred).forEach(e -> indexes.add(e)); - indexes.forEach(e -> tasks.add(tasks.indexOf(e)+count, taskAdd)); - } - - public static void replaceCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskRep) { - List indexes = new ArrayList<>(); - tasks.stream().filter(pred).forEach(e -> indexes.add(e)); - indexes.forEach(e -> tasks.set(tasks.indexOf(e)+count, taskRep)); - } - - public static void addPre(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, -1, pred, taskAdd); - } - - public static void add(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, 0, pred, taskAdd); - } - - public static void addAfter(List tasks, Predicate pred, LauncherBuildTask taskAdd) { - addCounted(tasks, 1, pred, taskAdd); - } - - public static void replacePre(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, -1, pred, taskRep); - } - - public static void replace(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, 0, pred, taskRep); - } - - public static void replaceAfter(List tasks, Predicate pred, LauncherBuildTask taskRep) { - replaceCounted(tasks, 1, pred, taskRep); - } - - public static List getTaskByClass(List tasks, Class taskClass) { - return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).collect(Collectors.toList()); - } - - private TaskUtil() { - } + public static void addCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskAdd) { + List indexes = new ArrayList<>(); + tasks.stream().filter(pred).forEach(e -> indexes.add(e)); + indexes.forEach(e -> tasks.add(tasks.indexOf(e) + count, taskAdd)); + } + + public static void replaceCounted(List tasks, int count, Predicate pred, LauncherBuildTask taskRep) { + List indexes = new ArrayList<>(); + tasks.stream().filter(pred).forEach(e -> indexes.add(e)); + indexes.forEach(e -> tasks.set(tasks.indexOf(e) + count, taskRep)); + } + + public static void addPre(List tasks, Predicate pred, LauncherBuildTask taskAdd) { + addCounted(tasks, -1, pred, taskAdd); + } + + public static void add(List tasks, Predicate pred, LauncherBuildTask taskAdd) { + addCounted(tasks, 0, pred, taskAdd); + } + + public static void addAfter(List tasks, Predicate pred, LauncherBuildTask taskAdd) { + addCounted(tasks, 1, pred, taskAdd); + } + + public static void replacePre(List tasks, Predicate pred, LauncherBuildTask taskRep) { + replaceCounted(tasks, -1, pred, taskRep); + } + + public static void replace(List tasks, Predicate pred, LauncherBuildTask taskRep) { + replaceCounted(tasks, 0, pred, taskRep); + } + + public static void replaceAfter(List tasks, Predicate pred, LauncherBuildTask taskRep) { + replaceCounted(tasks, 1, pred, taskRep); + } + + public static List getTaskByClass(List tasks, Class taskClass) { + return tasks.stream().filter(taskClass::isInstance).map(taskClass::cast).collect(Collectors.toList()); + } + + private TaskUtil() { + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/Command.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/Command.java index 402444e5..a69b023a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/Command.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/Command.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.command; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.VerifyHelper; +import java.util.UUID; + public abstract class Command { protected static String parseUsername(String username) throws CommandException { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java index c5048a5b..5a34131e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.command.auth; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.LogHelper; +import java.util.UUID; + public final class AuthCommand extends Command { public AuthCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java index 3511028c..3cfad3be 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.auth; -import java.util.List; - import ru.gravit.launcher.HWID; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.util.List; + public class BanCommand extends Command { public BanCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java index 63738552..918a5e7f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.command.auth; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public final class UUIDToUsernameCommand extends Command { public UUIDToUsernameCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java index edfb3602..a0c801a3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.auth; -import java.util.List; - import ru.gravit.launcher.HWID; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.util.List; + public class UnbanCommand extends Command { public UnbanCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java index 571368a5..24d226ac 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.command.auth; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public final class UsernameToUUIDCommand extends Command { public UsernameToUUIDCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java index 89c6a12a..44ff49e3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java @@ -24,12 +24,11 @@ public void invoke(String... args) { boolean newValue, newTraceValue; if (args.length >= 1) { newValue = Boolean.parseBoolean(args[0]); - if(args.length >= 2) newTraceValue = Boolean.parseBoolean(args[1]); + if (args.length >= 2) newTraceValue = Boolean.parseBoolean(args[1]); else newTraceValue = newValue; LogHelper.setDebugEnabled(newValue); LogHelper.setStacktraceEnabled(newTraceValue); - } else - { + } else { newValue = LogHelper.isDebugEnabled(); newTraceValue = LogHelper.isStacktraceEnabled(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/HelpCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/HelpCommand.java index 364de723..34dd6282 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/HelpCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/HelpCommand.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.command.basic; -import java.util.Map.Entry; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; import ru.gravit.utils.helper.LogHelper; +import java.util.Map.Entry; + public final class HelpCommand extends Command { private static void printCommand(String name, Command command) { String args = command.getArgsDescription(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ProguardCleanCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ProguardCleanCommand.java index b2dd5014..0594b4a6 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ProguardCleanCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/ProguardCleanCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.basic; -import java.io.IOException; -import java.nio.file.Files; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.io.IOException; +import java.nio.file.Files; + public class ProguardCleanCommand extends Command { public ProguardCleanCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RegenProguardDictCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RegenProguardDictCommand.java index 047aadb7..c1cdb794 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RegenProguardDictCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RegenProguardDictCommand.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.command.basic; -import java.io.IOException; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.io.IOException; + public class RegenProguardDictCommand extends Command { public RegenProguardDictCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java index a08a47f0..ba069f28 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.basic; -import java.io.IOException; -import java.nio.file.Files; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.io.IOException; +import java.nio.file.Files; + public class RemoveMappingsProguardCommand extends Command { public RemoveMappingsProguardCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RestartCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RestartCommand.java index 34fbdb3e..6d03eeca 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RestartCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RestartCommand.java @@ -20,6 +20,6 @@ public String getUsageDescription() { @Override public void invoke(String... args) { - server.fullyRestart(); + server.fullyRestart(); } } \ No newline at end of file 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 da213930..6e3b7723 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 @@ -1,7 +1,5 @@ package ru.gravit.launchserver.command.basic; -import java.io.Writer; - import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; @@ -9,6 +7,8 @@ import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; +import java.io.Writer; + public class TestCommand extends Command { public TestCommand(LaunchServer server) { super(server); @@ -35,10 +35,9 @@ public void invoke(String... args) throws Exception { CommonHelper.newThread("Netty Server", true, handler).start(); } if (args[0].equals("profile")) { - 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(server.dir.resolve("profiles").resolve("Test.cfg"))) - { - LaunchServer.gson.toJson(profile,writer); + 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(server.dir.resolve("profiles").resolve("Test.cfg"))) { + LaunchServer.gson.toJson(profile, writer); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpEntryCacheCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpEntryCacheCommand.java index df3d81ca..2946fec7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpEntryCacheCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpEntryCacheCommand.java @@ -1,17 +1,17 @@ package ru.gravit.launchserver.command.dump; -import java.io.Reader; -import java.io.Writer; -import java.nio.file.Paths; -import java.util.Map; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.handler.CachedAuthHandler; import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.Reader; +import java.io.Writer; +import java.nio.file.Paths; +import java.util.Map; +import java.util.UUID; + public class DumpEntryCacheCommand extends Command { public DumpEntryCacheCommand(LaunchServer server) { super(server); @@ -29,43 +29,39 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,2); - if(!(server.config.authHandler instanceof CachedAuthHandler)) throw new UnsupportedOperationException("This command used only CachedAuthHandler"); + verifyArgs(args, 2); + if (!(server.config.authHandler instanceof CachedAuthHandler)) + throw new UnsupportedOperationException("This command used only CachedAuthHandler"); CachedAuthHandler authHandler = (CachedAuthHandler) server.config.authHandler; - if(args[0].equals("unload")) - { - LogHelper.info("CachedAuthHandler write to %s",args[1]); - Map entryCache = authHandler.getEntryCache(); + if (args[0].equals("unload")) { + LogHelper.info("CachedAuthHandler write to %s", args[1]); + Map entryCache = authHandler.getEntryCache(); Map usernamesCache = authHandler.getUsernamesCache(); EntryAndUsername serializable = new EntryAndUsername(); serializable.entryCache = entryCache; serializable.usernameCache = usernamesCache; - try(Writer writer = IOHelper.newWriter(Paths.get(args[1]))) - { - LaunchServer.gson.toJson(serializable,writer); + try (Writer writer = IOHelper.newWriter(Paths.get(args[1]))) { + LaunchServer.gson.toJson(serializable, writer); } - LogHelper.subInfo("Write %d entryCache, %d usernameCache",entryCache.size(),usernamesCache.size()); - } else if(args[0].equals("load")) - { - LogHelper.info("CachedAuthHandler read from %s",args[1]); + LogHelper.subInfo("Write %d entryCache, %d usernameCache", entryCache.size(), usernamesCache.size()); + } else if (args[0].equals("load")) { + LogHelper.info("CachedAuthHandler read from %s", args[1]); int size_entry = 0; int size_username = 0; - try(Reader reader = IOHelper.newReader(Paths.get(args[1]))) - { - EntryAndUsername entryAndUsername = LaunchServer.gson.fromJson(reader,EntryAndUsername.class); + try (Reader reader = IOHelper.newReader(Paths.get(args[1]))) { + EntryAndUsername entryAndUsername = LaunchServer.gson.fromJson(reader, EntryAndUsername.class); size_entry = entryAndUsername.entryCache.size(); size_username = entryAndUsername.usernameCache.size(); authHandler.loadEntryCache(entryAndUsername.entryCache); authHandler.loadUsernameCache(entryAndUsername.usernameCache); } - LogHelper.subInfo("Readed %d entryCache %d usernameCache",size_entry,size_username); + LogHelper.subInfo("Readed %d entryCache %d usernameCache", size_entry, size_username); } } - public class EntryAndUsername - { - public Map entryCache; + public class EntryAndUsername { + public Map entryCache; public Map usernameCache; } } 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 63e6c158..5d36a0db 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 @@ -1,5 +1,12 @@ package ru.gravit.launchserver.command.dump; +import com.google.gson.reflect.TypeToken; +import ru.gravit.launchserver.LaunchServer; +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; import java.lang.reflect.Type; @@ -7,14 +14,6 @@ import java.util.HashSet; import java.util.Set; -import com.google.gson.reflect.TypeToken; - -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; -import ru.gravit.launchserver.socket.Client; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; - public class DumpSessionsCommand extends Command { public DumpSessionsCommand(LaunchServer server) { super(server); @@ -32,28 +31,25 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,2); - if(args[0].equals("unload")) - { - LogHelper.info("Sessions write to %s",args[1]); + 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]))) - { - LaunchServer.gson.toJson(clientSet,writer); + try (Writer writer = IOHelper.newWriter(Paths.get(args[1]))) { + 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]); + 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(); - Set clientSet = LaunchServer.gson.fromJson(reader,setType); + try (Reader reader = IOHelper.newReader(Paths.get(args[1]))) { + Type setType = new TypeToken>() { + }.getType(); + Set clientSet = LaunchServer.gson.fromJson(reader, setType); size = clientSet.size(); server.sessionManager.loadSessions(clientSet); } - LogHelper.subInfo("Readed %d sessions",size); + LogHelper.subInfo("Readed %d sessions", size); } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index 51b125bd..1e610f6a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -1,53 +1,25 @@ package ru.gravit.launchserver.command.handler; -import java.io.IOException; -import java.time.Duration; -import java.time.Instant; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; -import ru.gravit.launchserver.command.auth.AuthCommand; -import ru.gravit.launchserver.command.auth.BanCommand; -import ru.gravit.launchserver.command.auth.UUIDToUsernameCommand; -import ru.gravit.launchserver.command.auth.UnbanCommand; -import ru.gravit.launchserver.command.auth.UsernameToUUIDCommand; -import ru.gravit.launchserver.command.basic.BuildCommand; -import ru.gravit.launchserver.command.basic.ClearCommand; -import ru.gravit.launchserver.command.basic.DebugCommand; -import ru.gravit.launchserver.command.basic.GCCommand; -import ru.gravit.launchserver.command.basic.HelpCommand; -import ru.gravit.launchserver.command.basic.LogConnectionsCommand; -import ru.gravit.launchserver.command.basic.ProguardCleanCommand; -import ru.gravit.launchserver.command.basic.RebindCommand; -import ru.gravit.launchserver.command.basic.RegenProguardDictCommand; -import ru.gravit.launchserver.command.basic.RemoveMappingsProguardCommand; -import ru.gravit.launchserver.command.basic.RestartCommand; -import ru.gravit.launchserver.command.basic.StopCommand; -import ru.gravit.launchserver.command.basic.TestCommand; -import ru.gravit.launchserver.command.basic.VersionCommand; +import ru.gravit.launchserver.command.auth.*; +import ru.gravit.launchserver.command.basic.*; import ru.gravit.launchserver.command.dump.DumpEntryCacheCommand; import ru.gravit.launchserver.command.dump.DumpSessionsCommand; -import ru.gravit.launchserver.command.hash.DownloadAssetCommand; -import ru.gravit.launchserver.command.hash.DownloadClientCommand; -import ru.gravit.launchserver.command.hash.IndexAssetCommand; -import ru.gravit.launchserver.command.hash.SyncBinariesCommand; -import ru.gravit.launchserver.command.hash.SyncProfilesCommand; -import ru.gravit.launchserver.command.hash.SyncUpdatesCommand; -import ru.gravit.launchserver.command.hash.UnindexAssetCommand; +import ru.gravit.launchserver.command.hash.*; import ru.gravit.launchserver.command.modules.LoadModuleCommand; import ru.gravit.launchserver.command.modules.ModulesCommand; import ru.gravit.launchserver.command.service.*; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.time.Duration; +import java.time.Instant; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + public abstract class CommandHandler implements Runnable { private static String[] parse(CharSequence line) throws CommandException { boolean quoted = false; @@ -140,9 +112,9 @@ protected CommandHandler(LaunchServer server) { registerCommand("dumpEntryCache", new DumpEntryCacheCommand(server)); //Register service commands - registerCommand("reload",new ReloadCommand(server)); - registerCommand("reloadAll",new ReloadAllCommand(server)); - registerCommand("reloadList",new ReloadListCommand(server)); + registerCommand("reload", new ReloadCommand(server)); + registerCommand("reloadAll", new ReloadAllCommand(server)); + registerCommand("reloadList", new ReloadListCommand(server)); registerCommand("config", new ConfigCommand(server)); registerCommand("configHelp", new ConfigHelpCommand(server)); registerCommand("configList", new ConfigListCommand(server)); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/JLineCommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/JLineCommandHandler.java index 8fdfef7e..7455b026 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/JLineCommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/JLineCommandHandler.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.command.handler; -import java.io.IOException; - import jline.console.ConsoleReader; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper.Output; +import java.io.IOException; + public final class JLineCommandHandler extends CommandHandler { private final class JLineOutput implements Output { @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java index 9e7c6c15..8593cccb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.handler; -import java.io.BufferedReader; -import java.io.IOException; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; +import java.io.BufferedReader; +import java.io.IOException; + public final class StdCommandHandler extends CommandHandler { private final BufferedReader reader; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadAssetCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadAssetCommand.java index 49a3770a..91c0aac7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadAssetCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadAssetCommand.java @@ -1,9 +1,5 @@ package ru.gravit.launchserver.command.hash; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; - import ru.gravit.launcher.profiles.ClientProfile.Version; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; @@ -11,6 +7,10 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + public final class DownloadAssetCommand extends Command { public DownloadAssetCommand(LaunchServer server) { 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 4652f1a6..2d0a5a88 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,12 +1,5 @@ package ru.gravit.launchserver.command.hash; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; - import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile.Version; import ru.gravit.launchserver.LaunchServer; @@ -16,6 +9,13 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + public final class DownloadClientCommand extends Command { public DownloadClientCommand(LaunchServer server) { @@ -52,13 +52,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 = LaunchServer.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"))) { - LaunchServer.gson.toJson(client,writer); + LaunchServer.gson.toJson(client, writer); } // Finished diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/IndexAssetCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/IndexAssetCommand.java index e54d3d67..4dfd6710 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/IndexAssetCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/IndexAssetCommand.java @@ -1,5 +1,15 @@ package ru.gravit.launchserver.command.hash; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.launchserver.command.CommandException; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.SecurityHelper; +import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm; + import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.FileVisitResult; @@ -9,17 +19,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; -import ru.gravit.launchserver.command.CommandException; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm; - public final class IndexAssetCommand extends Command { private static Gson gson = new Gson(); @@ -115,7 +114,7 @@ public void invoke(String... args) throws Exception { try (BufferedWriter writer = IOHelper.newWriter(resolveIndexFile(outputAssetDir, indexFileName))) { JsonObject result = new JsonObject(); - result.add("objects",objects); + result.add("objects", objects); writer.write(gson.toJson(result)); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncBinariesCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncBinariesCommand.java index 082c37ec..44326cd1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncBinariesCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncBinariesCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.hash; -import java.io.IOException; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; + public final class SyncBinariesCommand extends Command { public SyncBinariesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncProfilesCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncProfilesCommand.java index 423b3152..e31269ad 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncProfilesCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncProfilesCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.hash; -import java.io.IOException; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; + public final class SyncProfilesCommand extends Command { public SyncProfilesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncUpdatesCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncUpdatesCommand.java index e4dc8996..6b741c12 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncUpdatesCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncUpdatesCommand.java @@ -1,14 +1,14 @@ package ru.gravit.launchserver.command.hash; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; -import ru.gravit.utils.helper.LogHelper; - public final class SyncUpdatesCommand extends Command { public SyncUpdatesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/UnindexAssetCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/UnindexAssetCommand.java index a1f8523b..9bb0c797 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/UnindexAssetCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/UnindexAssetCommand.java @@ -1,21 +1,20 @@ package ru.gravit.launchserver.command.hash; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.launchserver.command.CommandException; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + import java.io.BufferedReader; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; import java.util.Map; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; -import ru.gravit.launchserver.command.CommandException; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; - public final class UnindexAssetCommand extends Command { private static JsonParser parser = new JsonParser(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/modules/LoadModuleCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/modules/LoadModuleCommand.java index 1ab8a23a..af69674b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/modules/LoadModuleCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/modules/LoadModuleCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.modules; -import java.net.URI; -import java.nio.file.Paths; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.net.URI; +import java.nio.file.Paths; + public class LoadModuleCommand extends Command { public LoadModuleCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java index f05601f7..a7cff15e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java @@ -21,10 +21,10 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,2); - LogHelper.info("Call %s module %s action",args[0],args[1]); + verifyArgs(args, 2); + LogHelper.info("Call %s module %s action", args[0], args[1]); String[] new_args = new String[args.length - 2]; System.arraycopy(args, 2, new_args, 0, args.length - 2); - server.reconfigurableManager.call(args[0],args[1],new_args); + server.reconfigurableManager.call(args[0], args[1], new_args); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java index 1e2f3d8c..277c162a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java @@ -21,8 +21,8 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,1); - LogHelper.info("Help %s module",args[0]); + verifyArgs(args, 1); + LogHelper.info("Help %s module", args[0]); server.reconfigurableManager.printHelp(args[0]); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadAllCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadAllCommand.java index 6cce4298..cd3ad504 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadAllCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadAllCommand.java @@ -21,7 +21,7 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,1); + verifyArgs(args, 1); LogHelper.info("Reload all config"); server.reloadManager.reloadAll(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadCommand.java index 86673668..4cefb231 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadCommand.java @@ -21,8 +21,8 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,1); - LogHelper.info("Reload %s config",args[0]); + verifyArgs(args, 1); + LogHelper.info("Reload %s config", args[0]); server.reloadManager.reload(args[0]); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java index d43e4026..960300cb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java @@ -24,18 +24,17 @@ public String getUsageDescription() { @Override public void invoke(String... args) { LogHelper.info("Show server status"); - LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(),JVMHelper.RUNTIME.maxMemory()); + LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(), JVMHelper.RUNTIME.maxMemory()); long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000; long second = uptime % 60; long min = (uptime / 60) % 60; long hour = (uptime / 60 / 60) % 24; long days = (uptime / 60 / 60 / 24); - LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds",days,hour,min,second); - LogHelper.info("Uptime (double): %f", (double)JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000); - LogHelper.info("Sessions: %d | Modules: %d | Commands: %d",server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), server.commandHandler.commandsMap().size()); - if(server.config.authHandler instanceof CachedAuthHandler) - { - LogHelper.info("AuthHandler: EntryCache: %d | usernameCache: %d",((CachedAuthHandler) server.config.authHandler).getEntryCache().size(),((CachedAuthHandler) server.config.authHandler).getUsernamesCache().size()); + LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds", days, hour, min, second); + LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000); + LogHelper.info("Sessions: %d | Modules: %d | Commands: %d", server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), server.commandHandler.commandsMap().size()); + if (server.config.authHandler instanceof CachedAuthHandler) { + LogHelper.info("AuthHandler: EntryCache: %d | usernameCache: %d", ((CachedAuthHandler) server.config.authHandler).getEntryCache().size(), ((CachedAuthHandler) server.config.authHandler).getUsernamesCache().size()); } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java index b6d84a92..34828895 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/SwapAuthProviderCommand.java @@ -9,6 +9,7 @@ public class SwapAuthProviderCommand extends Command { public AuthProvider[] providersCache; + public SwapAuthProviderCommand(LaunchServer server) { super(server); } @@ -24,10 +25,10 @@ public String getUsageDescription() { } @SuppressWarnings("resource") - @Override + @Override public void invoke(String... args) throws Exception { - verifyArgs(args,2); - if(providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length]; + verifyArgs(args, 2); + if (providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length]; int index = Integer.valueOf(args[0]); switch (args[1]) { case "accept": diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthHandlerAdapter.java index 4be07ec2..608b36ae 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthHandlerAdapter.java @@ -1,20 +1,13 @@ package ru.gravit.launchserver.config; +import com.google.gson.*; +import ru.gravit.launchserver.auth.handler.AuthHandler; + import java.lang.reflect.Type; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import ru.gravit.launchserver.auth.handler.AuthHandler; - public class AuthHandlerAdapter implements JsonSerializer, JsonDeserializer { private static final String PROP_NAME = "type"; + @Override public AuthHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); @@ -29,7 +22,7 @@ public JsonElement serialize(AuthHandler src, Type typeOfSrc, JsonSerializationC JsonObject jo = context.serialize(src).getAsJsonObject(); @SuppressWarnings("unchecked") - String classPath = AuthHandler.getHandlerName((Class) src.getClass()); + String classPath = AuthHandler.getHandlerName((Class) src.getClass()); jo.add(PROP_NAME, new JsonPrimitive(classPath)); return jo; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthProviderAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthProviderAdapter.java index 7c0609eb..a45c6e92 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthProviderAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthProviderAdapter.java @@ -1,20 +1,13 @@ package ru.gravit.launchserver.config; +import com.google.gson.*; +import ru.gravit.launchserver.auth.provider.AuthProvider; + import java.lang.reflect.Type; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import ru.gravit.launchserver.auth.provider.AuthProvider; - public class AuthProviderAdapter implements JsonSerializer, JsonDeserializer { private static final String PROP_NAME = "type"; + @Override public AuthProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/HWIDHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/HWIDHandlerAdapter.java index 07ee387d..bcc887b7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/HWIDHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/HWIDHandlerAdapter.java @@ -1,20 +1,13 @@ package ru.gravit.launchserver.config; +import com.google.gson.*; +import ru.gravit.launchserver.auth.hwid.HWIDHandler; + import java.lang.reflect.Type; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import ru.gravit.launchserver.auth.hwid.HWIDHandler; - public class HWIDHandlerAdapter implements JsonSerializer, JsonDeserializer { private static final String PROP_NAME = "type"; + @Override public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/PermissionsHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/PermissionsHandlerAdapter.java index d9bd985b..83dd21e9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/PermissionsHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/PermissionsHandlerAdapter.java @@ -1,20 +1,13 @@ package ru.gravit.launchserver.config; +import com.google.gson.*; +import ru.gravit.launchserver.auth.permissions.PermissionsHandler; + import java.lang.reflect.Type; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import ru.gravit.launchserver.auth.permissions.PermissionsHandler; - public class PermissionsHandlerAdapter implements JsonSerializer, JsonDeserializer { private static final String PROP_NAME = "type"; + @Override public PermissionsHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/TextureProviderAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/TextureProviderAdapter.java index 50277a63..e79041c8 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/TextureProviderAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/TextureProviderAdapter.java @@ -1,20 +1,13 @@ package ru.gravit.launchserver.config; +import com.google.gson.*; +import ru.gravit.launchserver.texture.TextureProvider; + import java.lang.reflect.Type; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import ru.gravit.launchserver.texture.TextureProvider; - public class TextureProviderAdapter implements JsonSerializer, JsonDeserializer { private static final String PROP_NAME = "type"; + @Override public TextureProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java index 9cd22a0c..6b29eed0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.fileserver; -import java.io.Closeable; - import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import ru.gravit.utils.helper.IOHelper; +import java.io.Closeable; + public class ClosingChannelFutureListener implements ChannelFutureListener { public final Closeable[] close; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java index c626b7fc..3b78e8ad 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java @@ -1,16 +1,14 @@ package ru.gravit.launchserver.fileserver; -import static io.netty.handler.codec.http.HttpMethod.GET; -import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; -import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; -import static io.netty.handler.codec.http.HttpResponseStatus.FOUND; -import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR; -import static io.netty.handler.codec.http.HttpResponseStatus.METHOD_NOT_ALLOWED; -import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND; -import static io.netty.handler.codec.http.HttpResponseStatus.NOT_MODIFIED; -import static io.netty.handler.codec.http.HttpResponseStatus.OK; -import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.*; +import io.netty.handler.codec.http.*; +import io.netty.handler.ssl.SslHandler; +import io.netty.handler.stream.ChunkedFile; +import io.netty.util.CharsetUtil; +import javax.activation.MimetypesFileTypeMap; import java.io.File; import java.io.FileNotFoundException; import java.io.RandomAccessFile; @@ -18,38 +16,12 @@ import java.net.URLDecoder; import java.nio.file.Path; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.TimeZone; +import java.util.*; import java.util.regex.Pattern; -import javax.activation.MimetypesFileTypeMap; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelProgressiveFuture; -import io.netty.channel.ChannelProgressiveFutureListener; -import io.netty.channel.DefaultFileRegion; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.DefaultHttpResponse; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpChunkedInput; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderValues; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpUtil; -import io.netty.handler.codec.http.LastHttpContent; -import io.netty.handler.ssl.SslHandler; -import io.netty.handler.stream.ChunkedFile; -import io.netty.util.CharsetUtil; +import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; public class FileServerHandler extends SimpleChannelInboundHandler { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java index 8faf84a4..671e8618 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.manangers; +import ru.gravit.utils.helper.IOHelper; + import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import ru.gravit.utils.helper.IOHelper; - public class MirrorManager { public class Mirror { URL url; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java index f20d7d90..a0314530 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.manangers; -import java.net.URL; -import java.util.ArrayList; - import ru.gravit.launcher.managers.ModulesConfigManager; import ru.gravit.launcher.managers.SimpleModuleManager; import ru.gravit.launchserver.LaunchServer; @@ -10,8 +7,12 @@ import ru.gravit.launchserver.modules.LaunchServerModuleContext; import ru.gravit.utils.PublicURLClassLoader; +import java.net.URL; +import java.util.ArrayList; + public class ModulesManager extends SimpleModuleManager { public ModulesConfigManager configManager; + public ModulesManager(LaunchServer lsrv) { modules = new ArrayList<>(1); configManager = new ModulesConfigManager(lsrv.dir.resolve("config")); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java index ccaed96d..4805f590 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java @@ -1,29 +1,30 @@ package ru.gravit.launchserver.manangers; -import java.util.HashMap; -import java.util.Objects; - import ru.gravit.launchserver.Reconfigurable; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.util.HashMap; +import java.util.Objects; + public class ReconfigurableManager { private final HashMap RECONFIGURABLE = new HashMap<>(); - public void registerReconfigurable(String name, Reconfigurable reconfigurable) - { + + public void registerReconfigurable(String name, Reconfigurable reconfigurable) { VerifyHelper.verifyIDName(name); VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"), String.format("Reloadable has been already registered: '%s'", name)); } - public void printHelp(String name) - { + + public void printHelp(String name) { RECONFIGURABLE.get(name).printConfigHelp(); } + public void call(String name, String action, String[] args) { - RECONFIGURABLE.get(name).reconfig(action,args); + RECONFIGURABLE.get(name).reconfig(action, args); } - public void printReconfigurables() - { + + public void printReconfigurables() { LogHelper.info("Print reconfigurables"); RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k)); LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java index 3ef953ee..b57f0f17 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java @@ -1,23 +1,23 @@ package ru.gravit.launchserver.manangers; -import java.util.HashMap; -import java.util.Objects; - import ru.gravit.launchserver.Reloadable; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.util.HashMap; +import java.util.Objects; + public class ReloadManager { - private final HashMap RELOADABLES = new HashMap<>(); - public void registerReloadable(String name,Reloadable reloadable) - { + private final HashMap RELOADABLES = new HashMap<>(); + + public void registerReloadable(String name, Reloadable reloadable) { VerifyHelper.verifyIDName(name); VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"), String.format("Reloadable has been already registered: '%s'", name)); } - public void reloadAll() - { - RELOADABLES.forEach((k,v) -> { + + public void reloadAll() { + RELOADABLES.forEach((k, v) -> { try { v.reload(); } catch (Exception e) { @@ -25,13 +25,14 @@ public void reloadAll() } }); } + public void reload(String name) throws Exception { RELOADABLES.get(name).reload(); } - public void printReloadables() - { + + public void printReloadables() { LogHelper.info("Print reloadables"); - RELOADABLES.forEach((k,v) -> LogHelper.subInfo(k)); + RELOADABLES.forEach((k, v) -> LogHelper.subInfo(k)); LogHelper.info("Found %d reloadables", RELOADABLES.size()); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/SessionManager.java index 71c5a8e2..1a051cfc 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/SessionManager.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.manangers; -import java.util.HashSet; -import java.util.Set; - import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launchserver.socket.Client; +import java.util.HashSet; +import java.util.Set; + public class SessionManager implements NeedGarbageCollection { public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут @@ -51,12 +51,12 @@ public void updateClient(long session) { Client newClient = new Client(session); clientSet.add(newClient); } - public Set getSessions() - { + + public Set getSessions() { return clientSet; } - public void loadSessions(Set set) - { + + public void loadSessions(Set set) { clientSet.addAll(set); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/AuthHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/AuthHookManager.java index 273e2437..f60b9f78 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/AuthHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/AuthHookManager.java @@ -1,77 +1,73 @@ package ru.gravit.launchserver.manangers.hook; -import java.util.HashSet; -import java.util.Set; - import ru.gravit.launchserver.response.auth.AuthResponse; import ru.gravit.launchserver.socket.Client; +import java.util.HashSet; +import java.util.Set; + public class AuthHookManager { private Set PRE_HOOKS = new HashSet<>(); private Set POST_HOOKS = new HashSet<>(); private Set CHECKSERVER_HOOKS = new HashSet<>(); private Set JOINSERVER_HOOKS = new HashSet<>(); + @FunctionalInterface - public interface AuthPreHook - { + public interface AuthPreHook { void preAuthHook(AuthResponse.AuthContext context, Client client); } + @FunctionalInterface - public interface AuthPostHook - { + public interface AuthPostHook { void postAuthHook(AuthResponse.AuthContext context, Client client); } + @FunctionalInterface - public interface CheckServerHook - { + public interface CheckServerHook { void checkServerHook(String username, String serverID); } + @FunctionalInterface - public interface JoinServerHook - { + public interface JoinServerHook { void joinServerHook(String username, String accessToken, String serverID); } - public void registerPostHook(AuthPostHook hook) - { + + public void registerPostHook(AuthPostHook hook) { POST_HOOKS.add(hook); } - public void registerJoinServerHook(JoinServerHook hook) - { + + public void registerJoinServerHook(JoinServerHook hook) { JOINSERVER_HOOKS.add(hook); } - public void registerCheckServerHook(CheckServerHook hook) - { + + public void registerCheckServerHook(CheckServerHook hook) { CHECKSERVER_HOOKS.add(hook); } - public void registerPreHook(AuthPreHook hook) - { + + public void registerPreHook(AuthPreHook hook) { PRE_HOOKS.add(hook); } - public void preHook(AuthResponse.AuthContext context, Client client) - { - for(AuthPreHook preHook : PRE_HOOKS) - { - preHook.preAuthHook(context,client); + + public void preHook(AuthResponse.AuthContext context, Client client) { + for (AuthPreHook preHook : PRE_HOOKS) { + preHook.preAuthHook(context, client); } } - public void checkServerHook(String username, String serverID) - { - for(CheckServerHook hook : CHECKSERVER_HOOKS) - { + + public void checkServerHook(String username, String serverID) { + for (CheckServerHook hook : CHECKSERVER_HOOKS) { hook.checkServerHook(username, serverID); } } - public void joinServerHook(String username, String accessToken, String serverID) - { - for(JoinServerHook hook : JOINSERVER_HOOKS) - { + + public void joinServerHook(String username, String accessToken, String serverID) { + for (JoinServerHook hook : JOINSERVER_HOOKS) { hook.joinServerHook(username, accessToken, serverID); } } - public void postHook(AuthResponse.AuthContext context, Client client) - { - for(AuthPostHook postHook : POST_HOOKS) - { + + public void postHook(AuthResponse.AuthContext context, Client client) { + for (AuthPostHook postHook : POST_HOOKS) { postHook.postAuthHook(context, client); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java index 00bd4e05..703caeeb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java @@ -1,16 +1,16 @@ package ru.gravit.launchserver.manangers.hook; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - import ru.gravit.launcher.AutogenConfig; import ru.gravit.launcher.modules.TestClientModule; import ru.gravit.launchserver.binary.BuildContext; import ru.gravit.launchserver.binary.JAConfigurator; import ru.gravit.launchserver.binary.tasks.MainBuildTask; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + public class BuildHookManager { @FunctionalInterface diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/SocketHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/SocketHookManager.java index ecba8769..df510189 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/SocketHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/SocketHookManager.java @@ -1,89 +1,85 @@ package ru.gravit.launchserver.manangers.hook; +import ru.gravit.launcher.request.RequestException; +import ru.gravit.launchserver.socket.SocketContext; + import java.net.Socket; import java.util.HashSet; import java.util.Set; -import ru.gravit.launcher.request.RequestException; -import ru.gravit.launchserver.socket.SocketContext; - public class SocketHookManager { @FunctionalInterface - public interface SocketPreHook - { + public interface SocketPreHook { boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку } + @FunctionalInterface - public interface SocketPostHook - { + public interface SocketPostHook { void postHook(SocketContext context); } + @FunctionalInterface - public interface SocketErrorHook - { + public interface SocketErrorHook { boolean errorHook(SocketContext context, RequestException e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку } + @FunctionalInterface - public interface SocketFatalErrorHook - { + public interface SocketFatalErrorHook { boolean fatalErrorHook(Socket socket, Exception e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку } + private Set POST_HOOKS; private Set PRE_HOOKS; private Set ERROR_HOOKS; private Set FATALERROR_HOOKS; - public void registerPostHook(SocketPostHook hook) - { - if(POST_HOOKS == null) POST_HOOKS = new HashSet<>(); + + public void registerPostHook(SocketPostHook hook) { + if (POST_HOOKS == null) POST_HOOKS = new HashSet<>(); POST_HOOKS.add(hook); } - public void registerPreHook(SocketPreHook hook) - { - if(PRE_HOOKS == null) PRE_HOOKS = new HashSet<>(); + + public void registerPreHook(SocketPreHook hook) { + if (PRE_HOOKS == null) PRE_HOOKS = new HashSet<>(); PRE_HOOKS.add(hook); } - public void registerErrorHook(SocketErrorHook hook) - { - if(ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>(); + + public void registerErrorHook(SocketErrorHook hook) { + if (ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>(); ERROR_HOOKS.add(hook); } - public void registerFatalErrorHook(SocketFatalErrorHook hook) - { - if(FATALERROR_HOOKS == null) FATALERROR_HOOKS = new HashSet<>(); + + public void registerFatalErrorHook(SocketFatalErrorHook hook) { + if (FATALERROR_HOOKS == null) FATALERROR_HOOKS = new HashSet<>(); FATALERROR_HOOKS.add(hook); } - public boolean preHook(SocketContext context) - { - if(PRE_HOOKS == null) return true; - for(SocketPreHook preHook : PRE_HOOKS) - { - if(!preHook.preHook(context)) return false; + + public boolean preHook(SocketContext context) { + if (PRE_HOOKS == null) return true; + for (SocketPreHook preHook : PRE_HOOKS) { + if (!preHook.preHook(context)) return false; } return true; } - public void postHook(SocketContext context) - { - if(POST_HOOKS == null) return; - for(SocketPostHook postHook : POST_HOOKS) - { + + public void postHook(SocketContext context) { + if (POST_HOOKS == null) return; + for (SocketPostHook postHook : POST_HOOKS) { postHook.postHook(context); } } - public boolean errorHook(SocketContext context, RequestException e) - { - if(ERROR_HOOKS == null) return true; - for(SocketErrorHook errorHook : ERROR_HOOKS) - { - if(!errorHook.errorHook(context,e)) return false; + + public boolean errorHook(SocketContext context, RequestException e) { + if (ERROR_HOOKS == null) return true; + for (SocketErrorHook errorHook : ERROR_HOOKS) { + if (!errorHook.errorHook(context, e)) return false; } return true; } - public boolean fatalErrorHook(Socket socket, Exception e) - { - if(FATALERROR_HOOKS == null) return true; - for(SocketFatalErrorHook errorHook : FATALERROR_HOOKS) - { - if(!errorHook.fatalErrorHook(socket,e)) return false; + + public boolean fatalErrorHook(Socket socket, Exception e) { + if (FATALERROR_HOOKS == null) return true; + for (SocketFatalErrorHook errorHook : FATALERROR_HOOKS) { + if (!errorHook.fatalErrorHook(socket, e)) return false; } return true; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/PingResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/PingResponse.java index 0982768f..74b78222 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/PingResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/PingResponse.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.response; -import java.io.IOException; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launchserver.LaunchServer; +import java.io.IOException; + public final class PingResponse extends Response { public PingResponse(LaunchServer server, long id, HInput input, HOutput output, String ip) { super(server, id, input, output, ip); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java index 8101a2a4..68b3078b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java @@ -1,31 +1,22 @@ package ru.gravit.launchserver.response; -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.admin.ExecCommandResponse; -import ru.gravit.launchserver.response.auth.AuthResponse; -import ru.gravit.launchserver.response.auth.AuthServerResponse; -import ru.gravit.launchserver.response.auth.ChangeServerResponse; -import ru.gravit.launchserver.response.auth.CheckServerResponse; -import ru.gravit.launchserver.response.auth.JoinServerResponse; -import ru.gravit.launchserver.response.auth.SetProfileResponse; +import ru.gravit.launchserver.response.auth.*; import ru.gravit.launchserver.response.profile.BatchProfileByUsernameResponse; import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse; -import ru.gravit.launchserver.response.update.LauncherResponse; -import ru.gravit.launchserver.response.update.LegacyLauncherResponse; -import ru.gravit.launchserver.response.update.ProfilesResponse; -import ru.gravit.launchserver.response.update.UpdateListResponse; -import ru.gravit.launchserver.response.update.UpdateResponse; +import ru.gravit.launchserver.response.update.*; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + public abstract class Response { @FunctionalInterface public interface Factory { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/admin/ExecCommandResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/admin/ExecCommandResponse.java index 7aae8b8b..2e633828 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/admin/ExecCommandResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/admin/ExecCommandResponse.java @@ -18,7 +18,8 @@ public ExecCommandResponse(LaunchServer server, long session, HInput input, HOut @Override public void reply() throws Exception { Client clientData = server.sessionManager.getClient(session); - if(!clientData.isAuth || !clientData.permissions.canAdmin || !server.config.enableRcon) requestError("Access denied"); + if (!clientData.isAuth || !clientData.permissions.canAdmin || !server.config.enableRcon) + requestError("Access denied"); writeNoError(output); String cmd = input.readString(SerializeLimits.MAX_COMMAND); LogHelper.Output loutput = message -> { @@ -30,9 +31,8 @@ public void reply() throws Exception { } }; LogHelper.addOutput(loutput); - try - { - server.commandHandler.eval(cmd,false); + try { + server.commandHandler.eval(cmd, false); output.writeBoolean(false); } finally { LogHelper.removeOutput(loutput); 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 5a0dfa35..97ef55db 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 @@ -1,12 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.util.Arrays; -import java.util.Collection; -import java.util.UUID; - -import javax.crypto.BadPaddingException; -import javax.crypto.IllegalBlockSizeException; - import ru.gravit.launcher.OshiHWID; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; @@ -25,6 +18,12 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import java.util.Arrays; +import java.util.Collection; +import java.util.UUID; + public final class AuthResponse extends Response { private static String echo(int length) { char[] chars = new char[length]; @@ -35,8 +34,8 @@ private static String echo(int length) { public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { super(server, session, input, output, ip); } - public static class AuthContext - { + + public static class AuthContext { public AuthContext(long session, String login, int password_lenght, String client, String hwid, boolean isServerAuth) { this.session = session; this.login = login; @@ -53,6 +52,7 @@ public AuthContext(long session, String login, int password_lenght, String clien public String hwid; public boolean isServerAuth; } + @Override public void reply() throws Exception { String login = input.readString(SerializeLimits.MAX_LOGIN); @@ -80,9 +80,9 @@ public void reply() throws Exception { AuthProvider provider = server.config.authProvider[auth_id]; Client clientData = server.sessionManager.getClient(session); clientData.type = Client.Type.USER; - AuthContext context = new AuthContext(session,login,password.length(),client,hwid_str,false); + AuthContext context = new AuthContext(session, login, password.length(), client, hwid_str, false); try { - server.authHookManager.preHook(context,clientData); + server.authHookManager.preHook(context, clientData); if (server.limiter.isLimit(ip)) { AuthProvider.authError(server.config.authRejectString); return; @@ -110,9 +110,9 @@ public void reply() throws Exception { } } server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str, OshiHWID.class), result.username); - server.authHookManager.postHook(context,clientData); + server.authHookManager.postHook(context, clientData); } catch (AuthException | HWIDException e) { - if(e.getMessage() == null) LogHelper.error(e); + if (e.getMessage() == null) LogHelper.error(e); requestError(e.getMessage()); return; } catch (Exception e) { 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 1423faba..08370200 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 @@ -1,11 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.util.Arrays; -import java.util.Collection; - -import javax.crypto.BadPaddingException; -import javax.crypto.IllegalBlockSizeException; - import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -22,6 +16,11 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import java.util.Arrays; +import java.util.Collection; + public final class AuthServerResponse extends Response { private static String echo(int length) { char[] chars = new char[length]; @@ -74,8 +73,7 @@ public void reply() throws Exception { throw new AuthException("Your profile is not found"); } clientData.permissions = server.config.permissionsHandler.getPermissions(login); - if(!clientData.permissions.canServer) - { + if (!clientData.permissions.canServer) { throw new AuthException("Your account cannot be a server"); } clientData.type = Client.Type.SERVER; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java index b853872b..dbdd2b44 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -14,6 +11,9 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.UUID; + public final class CheckServerResponse extends Response { public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { @@ -27,15 +27,14 @@ public void reply() throws IOException { String client = input.readString(SerializeLimits.MAX_CLIENT); debug("Username: %s, Server ID: %s", username, serverID); Client clientData = server.sessionManager.getClient(session); - if(!clientData.isAuth || clientData.type != Client.Type.SERVER) - { + if (!clientData.isAuth || clientData.type != Client.Type.SERVER) { requestError("Assess denied"); return; } // Try check server with auth handler UUID uuid; try { - server.authHookManager.checkServerHook(username,serverID); + server.authHookManager.checkServerHook(username, serverID); uuid = server.config.authHandler.checkServer(username, serverID); } catch (AuthException e) { requestError(e.getMessage()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java index 2bee7a78..dd5d9463 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java @@ -1,7 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.io.IOException; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -13,6 +11,8 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class JoinServerResponse extends Response { public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { @@ -25,8 +25,7 @@ public void reply() throws IOException { String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); String serverID = VerifyHelper.verifyServerID(input.readASCII(SerializeLimits.MAX_SERVERID)); // With minus sign Client clientData = server.sessionManager.getClient(session); - if(!clientData.isAuth || clientData.type != Client.Type.USER) - { + if (!clientData.isAuth || clientData.type != Client.Type.USER) { requestError("Assess denied"); return; } @@ -34,7 +33,7 @@ public void reply() throws IOException { debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID); boolean success; try { - server.authHookManager.joinServerHook(username,accessToken,serverID); + server.authHookManager.joinServerHook(username, accessToken, serverID); success = server.config.authHandler.joinServer(username, accessToken, serverID); } catch (AuthException e) { requestError(e.getMessage()); 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 787d5a91..33b30d83 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 @@ -1,7 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.util.Collection; - import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -10,6 +8,8 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.Client; +import java.util.Collection; + public class SetProfileResponse extends Response { public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { super(server, session, input, output, ip); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java index 00966979..8d9f5181 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.profile; -import java.io.IOException; -import java.util.Arrays; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Arrays; + public final class BatchProfileByUsernameResponse extends Response { public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java index 34f0506f..0aeeca44 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.profile; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.serialize.HInput; @@ -12,6 +9,9 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public final class ProfileByUUIDResponse extends Response { public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java index e2b45680..859ada26 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.profile; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.UUID; + public final class ProfileByUsernameResponse extends Response { public static void writeProfile(LaunchServer server, HOutput output, String username, String client) throws IOException { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java index e48c91ed..411be0d3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.io.IOException; -import java.util.Arrays; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -11,6 +8,9 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.Client; +import java.io.IOException; +import java.util.Arrays; + public final class LauncherResponse extends Response { public LauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java index 6af47d77..92aba4d6 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java @@ -1,7 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.io.IOException; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launchserver.LaunchServer; @@ -9,6 +7,8 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; + public final class LegacyLauncherResponse extends Response { public LegacyLauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { 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 eb672145..039e018b 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,8 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.io.IOException; -import java.util.Collection; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; @@ -12,6 +9,9 @@ import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.Collection; + public final class ProfilesResponse extends Response { public ProfilesResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { @@ -33,7 +33,7 @@ public void reply() throws IOException { output.writeLength(profiles.size(), 0); for (ClientProfile profile : profiles) { LogHelper.debug("Writted profile: %s", profile.getTitle()); - output.writeString(Launcher.gson.toJson(profile),0); + output.writeString(Launcher.gson.toJson(profile), 0); } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java index 75426575..ffb1dddf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.util.Map.Entry; -import java.util.Set; - import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.Response; +import java.util.Map.Entry; +import java.util.Set; + public final class UpdateListResponse extends Response { public UpdateListResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { 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 925700da..530b489d 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 @@ -1,13 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Path; -import java.util.Deque; -import java.util.LinkedList; -import java.util.zip.DeflaterOutputStream; - import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.hasher.HashedEntry.Type; @@ -22,6 +14,14 @@ import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.IOHelper; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Path; +import java.util.Deque; +import java.util.LinkedList; +import java.util.zip.DeflaterOutputStream; + public final class UpdateResponse extends Response { public UpdateResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { @@ -42,8 +42,7 @@ public void reply() throws IOException { requestError("Assess denied"); return; } - if(!clientData.permissions.canAdmin) - { + if (!clientData.permissions.canAdmin) { for (ClientProfile p : server.getProfiles()) { if (!clientData.profile.getTitle().equals(p.getTitle())) continue; if (!p.isWhitelistContains(clientData.username)) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java index 0a23981d..9e4542c8 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java @@ -1,34 +1,5 @@ package ru.gravit.launchserver.socket; -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLServerSocketFactory; -import javax.net.ssl.TrustManager; - import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; @@ -53,6 +24,29 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLServerSocketFactory; +import javax.net.ssl.TrustManager; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.security.*; +import java.security.cert.CertificateException; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + @SuppressWarnings({"unused", "rawtypes"}) public final class NettyServerSocketHandler implements Runnable, AutoCloseable { private static final String WEBSOCKET_PATH = "/api"; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java index b1f4d20d..6d6922a3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java @@ -1,10 +1,5 @@ package ru.gravit.launchserver.socket; -import java.io.IOException; -import java.math.BigInteger; -import java.net.Socket; -import java.net.SocketException; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.serialize.HInput; @@ -17,6 +12,11 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.math.BigInteger; +import java.net.Socket; +import java.net.SocketException; + public final class ResponseThread implements Runnable { class Handshake { int type; @@ -117,23 +117,21 @@ public void run() { context.type = handshake.type; // Start response - if(socketHookManager.preHook(context)) - { + if (socketHookManager.preHook(context)) { try { respond(handshake.type, input, output, handshake.session, context.ip); socketHookManager.postHook(context); } catch (RequestException e) { - if(server.socketHookManager.errorHook(context,e)) - { + if (server.socketHookManager.errorHook(context, e)) { LogHelper.subDebug(String.format("#%d Request error: %s", handshake.session, e.getMessage())); - if(e.getMessage() == null) LogHelper.error(e); + if (e.getMessage() == null) LogHelper.error(e); output.writeString(e.getMessage(), 0); } } } } catch (Exception e) { savedError = e; - if(server.socketHookManager.fatalErrorHook(socket,e)) + if (server.socketHookManager.fatalErrorHook(socket, e)) LogHelper.error(e); } finally { IOHelper.close(socket); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java index 93fb1ce3..7d62dc1b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java @@ -1,23 +1,19 @@ package ru.gravit.launchserver.socket; -import java.io.IOException; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; - import ru.gravit.launcher.managers.GarbageManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.manangers.SessionManager; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + public final class ServerSocketHandler implements Runnable, AutoCloseable { public interface Listener { @@ -100,8 +96,7 @@ public void run() { // Invoke pre-connect listener long id = idCounter.incrementAndGet(); - if (listener != null && !listener.onConnect(socket.getInetAddress())) - { + if (listener != null && !listener.onConnect(socket.getInetAddress())) { socket.close(); continue; // Listener didn't accepted this connection } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java index 670c4bf1..522e46bf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java @@ -1,7 +1,6 @@ package ru.gravit.launchserver.socket.websocket; import com.google.gson.GsonBuilder; - import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.group.DefaultChannelGroup; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketIndexPageHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketIndexPageHandler.java index 6e31a384..b65f25a7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketIndexPageHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketIndexPageHandler.java @@ -1,28 +1,17 @@ package ru.gravit.launchserver.socket.websocket; -import static io.netty.handler.codec.http.HttpMethod.GET; -import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; -import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; -import static io.netty.handler.codec.http.HttpResponseStatus.OK; -import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; -import static io.netty.handler.codec.rtsp.RtspResponseStatuses.NOT_FOUND; - import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpUtil; +import io.netty.channel.*; +import io.netty.handler.codec.http.*; import io.netty.handler.ssl.SslHandler; import io.netty.util.CharsetUtil; +import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; +import static io.netty.handler.codec.rtsp.RtspResponseStatuses.NOT_FOUND; + public class WebSocketIndexPageHandler extends SimpleChannelInboundHandler { private final String websocketPath; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java index a18ff095..31d5a726 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java @@ -1,10 +1,7 @@ package ru.gravit.launchserver.socket.websocket; -import java.util.HashMap; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -24,6 +21,8 @@ import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse; import ru.gravit.utils.helper.LogHelper; +import java.util.HashMap; + @SuppressWarnings({"unused", "rawtypes"}) public class WebSocketService { public final ChannelGroup channels; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java index 2358ad31..f967c952 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java @@ -1,18 +1,10 @@ package ru.gravit.launchserver.socket.websocket.json; -import java.lang.reflect.Type; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - +import com.google.gson.*; import ru.gravit.launchserver.socket.websocket.WebSocketService; +import java.lang.reflect.Type; + public class JsonResponseAdapter implements JsonSerializer, JsonDeserializer { private final WebSocketService service; private static final String PROP_NAME = "type"; 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 e0c8f0ae..bb6fc899 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 @@ -1,7 +1,5 @@ package ru.gravit.launchserver.socket.websocket.json.auth; -import java.util.Collection; - import io.netty.channel.ChannelHandlerContext; import ru.gravit.launcher.HWID; import ru.gravit.launcher.profiles.ClientProfile; @@ -16,6 +14,8 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.util.Collection; + public class AuthResponse implements JsonResponseInterface { public String login; public String client; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java index 28cc86ad..4eab94ae 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.socket.websocket.json.update; -import java.util.Arrays; -import java.util.Base64; - import io.netty.channel.ChannelHandlerContext; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.socket.Client; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.utils.Version; +import java.util.Arrays; +import java.util.Base64; + public class LauncherResponse implements JsonResponseInterface { public Version version; public String hash; 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 a4293a41..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,12 +1,12 @@ package ru.gravit.launchserver.texture; +import ru.gravit.launcher.profiles.Texture; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.util.Objects; import java.util.UUID; -import ru.gravit.launcher.profiles.Texture; -import ru.gravit.utils.helper.VerifyHelper; - public final class NullTextureProvider extends TextureProvider { private volatile TextureProvider 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 0f05a421..4c663126 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java @@ -1,15 +1,15 @@ package ru.gravit.launchserver.texture; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.profiles.Texture; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.UUID; + public final class RequestTextureProvider extends TextureProvider { public RequestTextureProvider() { } 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 51829465..16c9be50 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java @@ -1,14 +1,14 @@ package ru.gravit.launchserver.texture; +import ru.gravit.launcher.profiles.Texture; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.util.Map; import java.util.Objects; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import ru.gravit.launcher.profiles.Texture; -import ru.gravit.utils.helper.VerifyHelper; - public abstract class TextureProvider implements AutoCloseable { private static final Map> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2); private static boolean registredProv = false; @@ -39,15 +39,13 @@ public static void registerProviders() { public abstract Texture getSkinTexture(UUID uuid, String username, String client) throws IOException; - public static Class getProviderClass(String name) - { + public static Class getProviderClass(String name) { return TEXTURE_PROVIDERS.get(name); } - public static String getProviderName(Class clazz) - { - for(Map.Entry> e: TEXTURE_PROVIDERS.entrySet()) - { - if(e.getValue().equals(clazz)) return e.getKey(); + + public static String getProviderName(Class clazz) { + for (Map.Entry> e : TEXTURE_PROVIDERS.entrySet()) { + if (e.getValue().equals(clazz)) return e.getKey(); } return null; } 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 ed5af330..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,9 +1,9 @@ package ru.gravit.launchserver.texture; -import java.util.UUID; - import ru.gravit.launcher.profiles.Texture; +import java.util.UUID; + public final class VoidTextureProvider extends TextureProvider { @Override diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 9061e389..f05970ed 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -1,10 +1,16 @@ package ru.gravit.launcher; import com.google.gson.GsonBuilder; -import ru.gravit.launcher.client.*; +import ru.gravit.launcher.client.ClientModuleManager; +import ru.gravit.launcher.client.DirBridge; +import ru.gravit.launcher.client.FunctionalBridge; +import ru.gravit.launcher.client.LauncherSettings; import ru.gravit.launcher.gui.JSRuntimeProvider; import ru.gravit.launcher.gui.RuntimeProvider; -import ru.gravit.utils.helper.*; +import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.EnvHelper; +import ru.gravit.utils.helper.JVMHelper; +import ru.gravit.utils.helper.LogHelper; import java.time.Duration; import java.time.Instant; @@ -34,9 +40,8 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Launcher started in %dms", Duration.between(start, end).toMillis()); } - public static void initGson() - { - if(Launcher.gson != null) return; + public static void initGson() { + if (Launcher.gson != null) return; Launcher.gsonBuilder = new GsonBuilder(); Launcher.gson = Launcher.gsonBuilder.create(); } @@ -50,14 +55,13 @@ private LauncherEngine() { } - @LauncherAPI public void start(String... args) throws Throwable { LogHelper.debug("%d", LauncherSettings.settingsMagic); Launcher.modulesManager = new ClientModuleManager(this); LauncherConfig.getAutogenConfig().initModules(); //INIT Launcher.modulesManager.preInitModules(); - if(runtimeProvider == null) runtimeProvider = new JSRuntimeProvider(); + if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider(); runtimeProvider.init(false); Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) @@ -67,7 +71,7 @@ public void start(String... args) throws Throwable { runtimeProvider.preLoad(); FunctionalBridge.worker = new RequestWorker(); CommonHelper.newThread("FX Task Worker", true, FunctionalBridge.worker).start(); - FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread",true, FunctionalBridge::getHWID); + FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID); FunctionalBridge.getHWID.start(); LogHelper.debug("Dir: %s", DirBridge.dir); runtimeProvider.run(args); 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 00ba27d6..c80c41c3 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -98,13 +98,11 @@ public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfil for (ClientProfile.OptionalFile s : Launcher.profile.getOptional()) { if (s.mark) updateOptional.add(s); } - for(ClientProfile.OptionalArgs s : Launcher.profile.getOptionalClientArgs()) - { - if(s.mark) optionalClientArgs.add(s); + for (ClientProfile.OptionalArgs s : Launcher.profile.getOptionalClientArgs()) { + if (s.mark) optionalClientArgs.add(s); } - for(ClientProfile.OptionalArgs s : Launcher.profile.getOptionalClassPath()) - { - if(s.mark) optionalClassPath.add(s); + for (ClientProfile.OptionalArgs s : Launcher.profile.getOptionalClassPath()) { + if (s.mark) optionalClassPath.add(s); } // Client paths this.assetDir = assetDir; @@ -141,7 +139,7 @@ public Params(HInput input) throws Exception { int len2 = input.readLength(16); boolean mark = input.readBoolean(); String[] optArgs = new String[len]; - for(int j=0;j args, ClientProfile profile, Params params) { PlayerProfile pp = params.pp; @@ -278,9 +275,8 @@ private static void addClientArgs(Collection args, ClientProfile profile Collections.addAll(args, "--server", profile.getServerAddress()); Collections.addAll(args, "--port", Integer.toString(profile.getServerPort())); } - for(ClientProfile.OptionalArgs optionalArgs : params.optionalClientArgs) - { - if(optionalArgs.mark) Collections.addAll(args,optionalArgs.args); + for (ClientProfile.OptionalArgs optionalArgs : params.optionalClientArgs) { + if (optionalArgs.mark) Collections.addAll(args, optionalArgs.args); } // Add window size args if (params.fullScreen) @@ -380,7 +376,7 @@ public static Process launch( } try (HOutput output = new HOutput(client.getOutputStream())) { params.write(output); - output.writeString(Launcher.gson.toJson(profile),0); + output.writeString(Launcher.gson.toJson(profile), 0); assetHDir.write(output); clientHDir.write(output); } @@ -427,11 +423,9 @@ public static Process launch( // Add classpath and main class String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); Collections.addAll(args, profile.getJvmArgs()); - if(profile.getOptionalJVMArgs() != null) - { - for(ClientProfile.OptionalArgs addArgs : profile.getOptionalJVMArgs()) - { - if(addArgs.mark) Collections.addAll(args,addArgs.args); + if (profile.getOptionalJVMArgs() != null) { + for (ClientProfile.OptionalArgs addArgs : profile.getOptionalJVMArgs()) { + if (addArgs.mark) Collections.addAll(args, addArgs.args); } } Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path @@ -478,7 +472,7 @@ public static void main(String... args) throws Throwable { EnvHelper.checkDangerousParams(); JVMHelper.checkStackTrace(ClientLauncher.class); LogHelper.printVersion("Client Launcher"); - if(engine.runtimeProvider == null) engine.runtimeProvider = new JSRuntimeProvider(); + if (engine.runtimeProvider == null) engine.runtimeProvider = new JSRuntimeProvider(); engine.runtimeProvider.init(true); engine.runtimeProvider.preLoad(); // Read and delete params file @@ -492,7 +486,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 = gson.fromJson(input.readString(0),ClientProfile.class); + profile = gson.fromJson(input.readString(0), ClientProfile.class); // Read hdirs assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); @@ -515,9 +509,8 @@ public static void main(String... args) throws Throwable { for (Path classpathURL : classPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } - for(ClientProfile.OptionalArgs optionalArgs : params.optionalClassPath) - { - if(!optionalArgs.mark) continue; + for (ClientProfile.OptionalArgs optionalArgs : params.optionalClassPath) { + if (!optionalArgs.mark) continue; LinkedList optionalClassPath = resolveClassPathList(params.clientDir, optionalArgs.args); for (Path classpathURL : optionalClassPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); @@ -618,9 +611,8 @@ private static LinkedList resolveClassPathList(Path clientDir, String... c return result; } - public static void initGson() - { - if(Launcher.gson != null) return; + public static void initGson() { + if (Launcher.gson != null) return; Launcher.gsonBuilder = new GsonBuilder(); Launcher.gson = Launcher.gsonBuilder.create(); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index ddee8bdb..882855e0 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -29,7 +29,7 @@ public class FunctionalBridge { @LauncherAPI public static AtomicReference hwid = new AtomicReference<>(); @LauncherAPI - public static Thread getHWID = null; + public static Thread getHWID = null; @LauncherAPI public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) { @@ -74,7 +74,7 @@ public static void startTask(@SuppressWarnings("rawtypes") Task task) { @LauncherAPI public static HWID getHWID() { HWID hhwid = hwid.get(); - if(hhwid == null) hwid.set(hwidProvider.getHWID()); + if (hhwid == null) hwid.set(hwidProvider.getHWID()); return hhwid; } 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 89aef608..9b2f4e54 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java @@ -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(Launcher.gson.fromJson(input.readString(0),ClientProfile.class)); + lastProfiles.add(Launcher.gson.fromJson(input.readString(0), ClientProfile.class)); } lastHDirs.clear(); int lastHDirsCount = input.readLength(0); @@ -150,7 +150,7 @@ public void write(HOutput output) throws IOException { } output.writeLength(lastProfiles.size(), 0); for (ClientProfile profile : lastProfiles) { - output.writeString(Launcher.gson.toJson(profile),0); + output.writeString(Launcher.gson.toJson(profile), 0); } output.writeLength(lastHDirs.size(), 0); for (Map.Entry> entry : lastHDirs.entrySet()) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java index ec550573..bcd63969 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java @@ -47,6 +47,7 @@ public class JSRuntimeProvider implements RuntimeProvider { private final ScriptEngine engine = CommonHelper.newScriptEngine(); + @LauncherAPI public static void addLauncherClassBindings(Map bindings) { bindings.put("LauncherClass", Launcher.class); @@ -123,6 +124,7 @@ public static void addLauncherClassBindings(Map bindings) { LogHelper.warning("JavaFX API isn't available"); } } + @LauncherAPI public Object loadScript(String path) throws IOException, ScriptException { URL url = Launcher.getResourceURL(path); diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/RuntimeProvider.java b/Launcher/src/main/java/ru/gravit/launcher/gui/RuntimeProvider.java index ff5a33af..d53f2fde 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/RuntimeProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/RuntimeProvider.java @@ -2,6 +2,8 @@ public interface RuntimeProvider { void run(String[] args) throws Exception; + void preLoad() throws Exception; + void init(boolean clientInstance) throws Exception; } diff --git a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java index 872bb4a7..01909b20 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java @@ -11,13 +11,12 @@ public class OshiHWIDProvider implements LauncherHWIDInterface { public SystemInfo systemInfo; public HardwareAbstractionLayer hardware; public boolean noHWID; - public OshiHWIDProvider() - { + + public OshiHWIDProvider() { try { systemInfo = new SystemInfo(); noHWID = false; - } catch(Throwable e) - { + } catch (Throwable e) { LogHelper.error(e); noHWID = true; } @@ -25,7 +24,7 @@ public OshiHWIDProvider() public String getSerial() { try { - if(hardware == null) hardware = systemInfo.getHardware(); + if (hardware == null) hardware = systemInfo.getHardware(); return hardware.getComputerSystem().getSerialNumber(); } catch (Exception e) { LogHelper.error(e); @@ -36,7 +35,7 @@ public String getSerial() { public String getProcessorID() { try { - if(hardware == null) hardware = systemInfo.getHardware(); + if (hardware == null) hardware = systemInfo.getHardware(); return hardware.getProcessor().getProcessorID(); } catch (Exception e) { LogHelper.error(e); @@ -47,7 +46,7 @@ public String getProcessorID() { public String getHWDisk() { try { - if(hardware == null) hardware = systemInfo.getHardware(); + if (hardware == null) hardware = systemInfo.getHardware(); HWDiskStore store = null; long size = 0; for (HWDiskStore s : hardware.getDiskStores()) { @@ -64,21 +63,20 @@ public String getHWDisk() { } public long getTotalMemory() { - if(noHWID) return -1; - if(hardware == null) hardware = systemInfo.getHardware(); + if (noHWID) return -1; + if (hardware == null) hardware = systemInfo.getHardware(); return hardware.getMemory().getTotal(); } public long getAvailableMemory() { - if(noHWID) return -1; - if(hardware == null) hardware = systemInfo.getHardware(); + if (noHWID) return -1; + if (hardware == null) hardware = systemInfo.getHardware(); return hardware.getMemory().getAvailable(); } public void printHardwareInformation() { - try - { - if(hardware == null) hardware = systemInfo.getHardware(); + try { + if (hardware == null) hardware = systemInfo.getHardware(); ComputerSystem computerSystem = hardware.getComputerSystem(); LogHelper.debug("ComputerSystem Model: %s Serial: %s", computerSystem.getModel(), computerSystem.getSerialNumber()); for (HWDiskStore s : hardware.getDiskStores()) { @@ -89,8 +87,7 @@ public void printHardwareInformation() { } CentralProcessor processor = hardware.getProcessor(); LogHelper.debug("Processor Model: %s ID: %s", processor.getModel(), processor.getProcessorID()); - } catch (Throwable e) - { + } catch (Throwable e) { LogHelper.error(e); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java index e75f0be8..496b314a 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java @@ -18,8 +18,8 @@ public abstract class Request { public static void setSession(long session) { Request.session = session; } - public static long getSession() - { + + public static long getSession() { return Request.session; } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/admin/ExecCommandRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/admin/ExecCommandRequest.java index 2b4a0e01..a929591d 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/admin/ExecCommandRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/admin/ExecCommandRequest.java @@ -26,13 +26,11 @@ protected Boolean requestDo(HInput input, HOutput output) throws Exception { readError(input); output.writeString(cmd, SerializeLimits.MAX_COMMAND); boolean isContinue = true; - while (isContinue) - { + while (isContinue) { isContinue = input.readBoolean(); - if(isContinue) - { + if (isContinue) { String log = input.readString(SerializeLimits.MAX_COMMAND); - if(loutput != null) loutput.println(log); + if (loutput != null) loutput.println(log); } } readError(input); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java index 578bd659..27521e73 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java @@ -87,6 +87,6 @@ protected Result requestDo(HInput input, HOutput output) throws IOException { PlayerProfile pp = new PlayerProfile(input); String accessToken = input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH); ClientPermissions permissions = new ClientPermissions(input); - return new Result(pp, accessToken,permissions); + return new Result(pp, accessToken, permissions); } } 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 c387c5b6..7fd08e96 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 @@ -115,10 +115,9 @@ protected Result requestDo(HInput input, HOutput output) throws Exception { // Read clients profiles list int count = input.readLength(0); List profiles = new ArrayList<>(count); - for (int i = 0; i < count; i++) - { + for (int i = 0; i < count; i++) { String prof = input.readString(0); - profiles.add(Launcher.gson.fromJson(prof,ClientProfile.class)); + profiles.add(Launcher.gson.fromJson(prof, ClientProfile.class)); } // Return request result 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 111cfd13..9c0d079d 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 @@ -47,10 +47,9 @@ 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++) - { + for (int i = 0; i < count; i++) { String prof = input.readString(0); - profiles.add(Launcher.gson.fromJson(prof,ClientProfile.class)); + profiles.add(Launcher.gson.fromJson(prof, ClientProfile.class)); } // Return request result return new Result(profiles); diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java index f8702148..edbacbfd 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java @@ -10,6 +10,7 @@ public class ModulesManager extends SimpleModuleManager { public ModulesConfigManager modulesConfigManager; + public ModulesManager(ServerWrapper wrapper) { modules = new ArrayList<>(); modulesConfigManager = new ModulesConfigManager(Paths.get("modules-config")); diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index e9aad99d..2baf6264 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -9,9 +9,14 @@ import ru.gravit.launcher.request.auth.AuthServerRequest; import ru.gravit.launcher.request.update.ProfilesRequest; import ru.gravit.utils.PublicURLClassLoader; -import ru.gravit.utils.helper.*; +import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.SecurityHelper; -import java.io.*; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; @@ -48,14 +53,14 @@ public static boolean auth(ServerWrapper wrapper) { break; } } - if(wrapper.profile == null) { + if (wrapper.profile == null) { LogHelper.error("Your profile not found"); - if(ServerWrapper.config.stopOnError) System.exit(-1); + if (ServerWrapper.config.stopOnError) System.exit(-1); } return true; } catch (Throwable e) { LogHelper.error(e); - if(ServerWrapper.config.stopOnError) System.exit(-1); + if (ServerWrapper.config.stopOnError) System.exit(-1); return false; } @@ -78,9 +83,8 @@ public static boolean loopAuth(ServerWrapper wrapper, int count, int sleeptime) return false; } - public static void initGson() - { - if(Launcher.gson != null) return; + public static void initGson() { + if (Launcher.gson != null) return; Launcher.gsonBuilder = new GsonBuilder(); Launcher.gson = Launcher.gsonBuilder.create(); } @@ -99,13 +103,12 @@ public static void main(String... args) throws Throwable { gson = gsonBuiler.create(); initGson(); generateConfigIfNotExists(); - try(Reader reader = IOHelper.newReader(configFile)) - { - config = gson.fromJson(reader,Config.class); + try (Reader reader = IOHelper.newReader(configFile)) { + config = gson.fromJson(reader, Config.class); } LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); Launcher.setConfig(cfg); - if(config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile),true)); + if (config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile), true)); if (config.syncAuth) auth(wrapper); else CommonHelper.newThread("Server Auth Thread", true, () -> ServerWrapper.loopAuth(wrapper, config.reconnectCount, config.reconnectSleep)); @@ -113,11 +116,12 @@ public static void main(String... args) throws Throwable { String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; if (classname.length() == 0) { LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.cfg or first commandline argument"); - if(config.stopOnError) System.exit(-1); + if (config.stopOnError) System.exit(-1); } Class mainClass; if (config.customClassPath) { - if(config.classpath == null) throw new UnsupportedOperationException("classpath is null, customClassPath not available"); + if (config.classpath == null) + throw new UnsupportedOperationException("classpath is null, customClassPath not available"); String[] cp = config.classpath.split(":"); if (!ServerAgent.isAgentStarted()) { LogHelper.warning("JavaAgent not found. Using URLClassLoader"); @@ -135,7 +139,8 @@ public static void main(String... args) throws Throwable { if (!ServerAgent.isAgentStarted()) { throw new UnsupportedOperationException("JavaAgent not found, autoloadLibraries not available"); } - if(config.librariesDir == null) throw new UnsupportedOperationException("librariesDir is null, autoloadLibraries not available"); + if (config.librariesDir == null) + throw new UnsupportedOperationException("librariesDir is null, autoloadLibraries not available"); Path librariesDir = Paths.get(config.librariesDir); LogHelper.info("Load libraries"); ServerAgent.loadLibraries(librariesDir); @@ -159,7 +164,7 @@ private static void generateConfigIfNotExists() throws IOException { // Create new config LogHelper.info("Creating ServerWrapper config"); - Config newConfig= new Config(); + Config newConfig = new Config(); newConfig.title = "Your profile title"; newConfig.projectname = "MineCraft"; newConfig.address = "localhost"; @@ -180,9 +185,8 @@ private static void generateConfigIfNotExists() throws IOException { // Write LaunchServer config LogHelper.info("Writing ServerWrapper config file"); - try(Writer writer = IOHelper.newWriter(configFile)) - { - gson.toJson(newConfig,writer); + try (Writer writer = IOHelper.newWriter(configFile)) { + gson.toJson(newConfig, writer); } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java index ffbd4ff1..aa64bb0b 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java @@ -6,7 +6,7 @@ public class AutogenConfig { public int port; public int clientPort; @SuppressWarnings("unused") - private boolean isInitModules; + private boolean isInitModules; public boolean isUsingWrapper; public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части public String secretKeyClient; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java b/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java index 36118532..9ab91c20 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java @@ -11,10 +11,12 @@ public class ClientPermissions { public boolean canAdmin; @LauncherAPI public boolean canServer; + public ClientPermissions(HInput input) throws IOException { canAdmin = input.readBoolean(); canServer = input.readBoolean(); } + public ClientPermissions() { canAdmin = false; canServer = false; @@ -31,6 +33,7 @@ public static ClientPermissions getSuperuserAccount() { perm.canAdmin = true; return perm; } + public void write(HOutput output) throws IOException { output.writeBoolean(canAdmin); output.writeBoolean(canServer); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java index 80d55ab0..f8561247 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java @@ -15,9 +15,8 @@ public ModulesConfigManager(Path configDir) { this.configDir = configDir; } - public Path getModuleConfig(String moduleName) - { - if(!IOHelper.isDir(configDir)) { + public Path getModuleConfig(String moduleName) { + if (!IOHelper.isDir(configDir)) { try { Files.createDirectories(configDir); } catch (IOException e) { @@ -26,9 +25,9 @@ public Path getModuleConfig(String moduleName) } return configDir.resolve(moduleName.concat("Config.json")); } - public Path getModuleConfigDir(String moduleName) - { - if(!IOHelper.isDir(configDir)) { + + public Path getModuleConfigDir(String moduleName) { + if (!IOHelper.isDir(configDir)) { try { Files.createDirectories(configDir); } catch (IOException e) { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java index a79601bb..3161434a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java @@ -8,5 +8,6 @@ enum Type { Type getType(); ModulesManagerInterface getModulesManager(); + ModulesConfigManagerInterface getModulesConfigManager(); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java index 052857ac..f49e4406 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java @@ -4,5 +4,6 @@ public interface ModulesConfigManagerInterface { Path getModuleConfig(String moduleName); + Path getModuleConfigDir(String moduleName); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index f9e3c86d..ffbfb5bb 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -10,7 +10,7 @@ import java.util.*; public final class ClientProfile implements Comparable { - public ClientProfile(String version, String assetIndex, int sortIndex, String title, String serverAddress, int serverPort, boolean updateFastCheck, boolean useWhitelist, String mainClass) { + public ClientProfile(String version, String assetIndex, int sortIndex, String title, String serverAddress, int serverPort, boolean updateFastCheck, boolean useWhitelist, String mainClass) { this.version = version; this.assetIndex = assetIndex; this.sortIndex = sortIndex; @@ -142,8 +142,8 @@ public int hashCode() { return Objects.hash(file); } } - public static class OptionalArgs - { + + public static class OptionalArgs { @LauncherAPI public boolean mark; @LauncherAPI @@ -212,10 +212,12 @@ public String[] getClassPath() { public List getOptionalJVMArgs() { return optionalJVMArgs; } + @LauncherAPI public List getOptionalClientArgs() { return optionalClientArgs; } + @LauncherAPI public List getOptionalClassPath() { return optionalClassPath; @@ -225,6 +227,7 @@ public List getOptionalClassPath() { public String[] getClientArgs() { return clientArgs.toArray(new String[0]); } + @LauncherAPI public String getDir() { return dir; @@ -233,6 +236,7 @@ public String getDir() { public void setDir(String dir) { this.dir = dir; } + @LauncherAPI public String getAssetDir() { return assetDir; @@ -274,24 +278,19 @@ public String getServerAddress() { public Set getOptional() { return updateOptional; } + @LauncherAPI - public void updateOptionalGraph() - { - for(OptionalFile file : updateOptional) - { - if(file.dependenciesFile != null) - { + public void updateOptionalGraph() { + for (OptionalFile file : updateOptional) { + if (file.dependenciesFile != null) { file.dependencies = new OptionalFile[file.dependenciesFile.length]; - for(int i=0;i(); + if (file.dependencies != null) { + for (OptionalFile dep : file.dependencies) { + if (dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>(); dep.dependenciesCount.add(file); markOptional(dep); } } - if(file.conflict != null) - { - for(OptionalFile conflict : file.conflict) - { + if (file.conflict != null) { + for (OptionalFile conflict : file.conflict) { unmarkOptional(conflict); } } @@ -349,31 +343,24 @@ public void unmarkOptional(String opt) { OptionalFile file = getOptionalFile(opt); unmarkOptional(file); } + @LauncherAPI - public void unmarkOptional(OptionalFile file) - { - if(!file.mark) return; + public void unmarkOptional(OptionalFile file) { + if (!file.mark) return; file.mark = false; - if(file.dependenciesCount != null) - { - for(OptionalFile f : file.dependenciesCount) - { + if (file.dependenciesCount != null) { + for (OptionalFile f : file.dependenciesCount) { unmarkOptional(f); } file.dependenciesCount.clear(); file.dependenciesCount = null; } - if(file.dependencies != null) - { - for(OptionalFile f : file.dependencies) - { - if(!f.mark) continue; - if(f.dependenciesCount == null) - { + if (file.dependencies != null) { + for (OptionalFile f : file.dependencies) { + if (!f.mark) continue; + if (f.dependenciesCount == null) { unmarkOptional(f); - } - else if(f.dependenciesCount.size() <= 1) - { + } else if (f.dependenciesCount.size() <= 1) { f.dependenciesCount.clear(); f.dependenciesCount = null; unmarkOptional(f); @@ -464,89 +451,89 @@ public void verify() { // Client launcher VerifyHelper.verify(getTitle(), VerifyHelper.NOT_EMPTY, "Main class can't be empty"); } - + @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((assetDir == null) ? 0 : assetDir.hashCode()); - result = prime * result + ((assetIndex == null) ? 0 : assetIndex.hashCode()); - result = prime * result + ((classPath == null) ? 0 : classPath.hashCode()); - result = prime * result + ((clientArgs == null) ? 0 : clientArgs.hashCode()); - result = prime * result + ((dir == null) ? 0 : dir.hashCode()); - result = prime * result + ((jvmArgs == null) ? 0 : jvmArgs.hashCode()); - result = prime * result + ((mainClass == null) ? 0 : mainClass.hashCode()); - result = prime * result + ((serverAddress == null) ? 0 : serverAddress.hashCode()); - result = prime * result + serverPort; - result = prime * result + sortIndex; + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((assetDir == null) ? 0 : assetDir.hashCode()); + result = prime * result + ((assetIndex == null) ? 0 : assetIndex.hashCode()); + result = prime * result + ((classPath == null) ? 0 : classPath.hashCode()); + result = prime * result + ((clientArgs == null) ? 0 : clientArgs.hashCode()); + result = prime * result + ((dir == null) ? 0 : dir.hashCode()); + result = prime * result + ((jvmArgs == null) ? 0 : jvmArgs.hashCode()); + result = prime * result + ((mainClass == null) ? 0 : mainClass.hashCode()); + result = prime * result + ((serverAddress == null) ? 0 : serverAddress.hashCode()); + result = prime * result + serverPort; + result = prime * result + sortIndex; result = prime * result + ((title == null) ? 0 : title.hashCode()); result = prime * result + ((info == null) ? 0 : info.hashCode()); - result = prime * result + ((update == null) ? 0 : update.hashCode()); - result = prime * result + ((updateExclusions == null) ? 0 : updateExclusions.hashCode()); - result = prime * result + (updateFastCheck ? 1231 : 1237); - result = prime * result + ((updateOptional == null) ? 0 : updateOptional.hashCode()); - result = prime * result + ((updateShared == null) ? 0 : updateShared.hashCode()); - result = prime * result + ((updateVerify == null) ? 0 : updateVerify.hashCode()); - result = prime * result + (useWhitelist ? 1231 : 1237); - result = prime * result + ((version == null) ? 0 : version.hashCode()); - result = prime * result + ((whitelist == null) ? 0 : whitelist.hashCode()); - return result; - } + result = prime * result + ((update == null) ? 0 : update.hashCode()); + result = prime * result + ((updateExclusions == null) ? 0 : updateExclusions.hashCode()); + result = prime * result + (updateFastCheck ? 1231 : 1237); + result = prime * result + ((updateOptional == null) ? 0 : updateOptional.hashCode()); + result = prime * result + ((updateShared == null) ? 0 : updateShared.hashCode()); + result = prime * result + ((updateVerify == null) ? 0 : updateVerify.hashCode()); + result = prime * result + (useWhitelist ? 1231 : 1237); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + result = prime * result + ((whitelist == null) ? 0 : whitelist.hashCode()); + return result; + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ClientProfile other = (ClientProfile) obj; - if (assetDir == null) { - if (other.assetDir != null) - return false; - } else if (!assetDir.equals(other.assetDir)) - return false; - if (assetIndex == null) { - if (other.assetIndex != null) - return false; - } else if (!assetIndex.equals(other.assetIndex)) - return false; - if (classPath == null) { - if (other.classPath != null) - return false; - } else if (!classPath.equals(other.classPath)) - return false; - if (clientArgs == null) { - if (other.clientArgs != null) - return false; - } else if (!clientArgs.equals(other.clientArgs)) - return false; - if (dir == null) { - if (other.dir != null) - return false; - } else if (!dir.equals(other.dir)) - return false; - if (jvmArgs == null) { - if (other.jvmArgs != null) - return false; - } else if (!jvmArgs.equals(other.jvmArgs)) - return false; - if (mainClass == null) { - if (other.mainClass != null) - return false; - } else if (!mainClass.equals(other.mainClass)) - return false; - if (serverAddress == null) { - if (other.serverAddress != null) - return false; - } else if (!serverAddress.equals(other.serverAddress)) - return false; - if (serverPort != other.serverPort) - return false; - if (sortIndex != other.sortIndex) - return false; - if (title == null) { + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ClientProfile other = (ClientProfile) obj; + if (assetDir == null) { + if (other.assetDir != null) + return false; + } else if (!assetDir.equals(other.assetDir)) + return false; + if (assetIndex == null) { + if (other.assetIndex != null) + return false; + } else if (!assetIndex.equals(other.assetIndex)) + return false; + if (classPath == null) { + if (other.classPath != null) + return false; + } else if (!classPath.equals(other.classPath)) + return false; + if (clientArgs == null) { + if (other.clientArgs != null) + return false; + } else if (!clientArgs.equals(other.clientArgs)) + return false; + if (dir == null) { + if (other.dir != null) + return false; + } else if (!dir.equals(other.dir)) + return false; + if (jvmArgs == null) { + if (other.jvmArgs != null) + return false; + } else if (!jvmArgs.equals(other.jvmArgs)) + return false; + if (mainClass == null) { + if (other.mainClass != null) + return false; + } else if (!mainClass.equals(other.mainClass)) + return false; + if (serverAddress == null) { + if (other.serverAddress != null) + return false; + } else if (!serverAddress.equals(other.serverAddress)) + return false; + if (serverPort != other.serverPort) + return false; + if (sortIndex != other.sortIndex) + return false; + if (title == null) { if (other.title != null) return false; } else if (!title.equals(other.title)) @@ -556,42 +543,42 @@ public boolean equals(Object obj) { return false; } else if (!info.equals(other.info)) return false; - if (update == null) { - if (other.update != null) - return false; - } else if (!update.equals(other.update)) - return false; - if (updateExclusions == null) { - if (other.updateExclusions != null) - return false; - } else if (!updateExclusions.equals(other.updateExclusions)) - return false; - if (updateFastCheck != other.updateFastCheck) - return false; - if (updateOptional == null) { - if (other.updateOptional != null) - return false; - } else if (!updateOptional.equals(other.updateOptional)) - return false; - if (updateShared == null) { - if (other.updateShared != null) - return false; - } else if (!updateShared.equals(other.updateShared)) - return false; - if (updateVerify == null) { - if (other.updateVerify != null) - return false; - } else if (!updateVerify.equals(other.updateVerify)) - return false; - if (useWhitelist != other.useWhitelist) - return false; - if (version == null) { - if (other.version != null) - return false; - } else if (!version.equals(other.version)) - return false; - if (whitelist == null) { + if (update == null) { + if (other.update != null) + return false; + } else if (!update.equals(other.update)) + return false; + if (updateExclusions == null) { + if (other.updateExclusions != null) + return false; + } else if (!updateExclusions.equals(other.updateExclusions)) + return false; + if (updateFastCheck != other.updateFastCheck) + return false; + if (updateOptional == null) { + if (other.updateOptional != null) + return false; + } else if (!updateOptional.equals(other.updateOptional)) + return false; + if (updateShared == null) { + if (other.updateShared != null) + return false; + } else if (!updateShared.equals(other.updateShared)) + return false; + if (updateVerify == null) { + if (other.updateVerify != null) + return false; + } else if (!updateVerify.equals(other.updateVerify)) + return false; + if (useWhitelist != other.useWhitelist) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + if (whitelist == null) { return other.whitelist == null; - } else return whitelist.equals(other.whitelist); + } else return whitelist.equals(other.whitelist); } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java b/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java index 74cecc0d..06fc497a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java @@ -11,7 +11,7 @@ public enum RequestType implements EnumSerializer.Itf { LEGACYLAUNCHER(1), UPDATE(2), UPDATE_LIST(3), // Update requests AUTH(4), JOIN_SERVER(5), CHECK_SERVER(6), // Auth requests PROFILE_BY_USERNAME(7), PROFILE_BY_UUID(8), BATCH_PROFILE_BY_USERNAME(9), // Profile requests - PROFILES(10), SERVERAUTH(11), SETPROFILE(12), LAUNCHER(13), CHANGESERVER(14),EXECCOMMAND(15), + PROFILES(10), SERVERAUTH(11), SETPROFILE(12), LAUNCHER(13), CHANGESERVER(14), EXECCOMMAND(15), CUSTOM(255); // Custom requests private static final EnumSerializer SERIALIZER = new EnumSerializer<>(RequestType.class); diff --git a/libLauncher/src/main/java/ru/gravit/utils/HTTPRequest.java b/libLauncher/src/main/java/ru/gravit/utils/HTTPRequest.java index 20eb5292..dacf0164 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/HTTPRequest.java +++ b/libLauncher/src/main/java/ru/gravit/utils/HTTPRequest.java @@ -61,7 +61,7 @@ public static JsonElement jsonRequest(JsonElement request, URL url) throws IOExc JsonElement content = parser.parse(reader); return content; } - + private HTTPRequest() { } } From 9b7dec73604956f1d995f9dcc1560637169ecdad Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 15 Jan 2019 10:38:30 +0700 Subject: [PATCH 07/10] =?UTF-8?q?[ANY]=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20gradlew=20wrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle/wrapper/gradle-wrapper.properties | 3 +-- modules | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 488effa9..75b8c7c8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Jan 02 17:51:09 GMT+07:00 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip diff --git a/modules b/modules index bb4430df..df8b9228 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit bb4430df933db257638191857577824820b18c4a +Subproject commit df8b92281a93046b4959fc82c98c2eeab4fd5933 From aceb06bc9dbb5970d4795da97bd468f20757464f Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 15 Jan 2019 10:48:20 +0700 Subject: [PATCH 08/10] =?UTF-8?q?[FEATURE]=20=D0=92=D0=B2=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D1=8F=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F:=20dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 17 +++--------- .../gravit/launcher/server/ServerWrapper.java | 4 +++ .../java/ru/gravit/launcher/Launcher.java | 24 +++++++++++++++++ .../ru/gravit/launcher/LauncherConfig.java | 8 +----- .../ru/gravit/utils/helper/LogHelper.java | 27 ++++++++++++++++++- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 1677edfa..376db65e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -367,6 +367,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE config = Launcher.gson.fromJson(reader, Config.class); } config.verify(); + Launcher.applyLauncherEnv(config.env); for (AuthProvider provider : config.authProvider) { provider.init(); } @@ -396,13 +397,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE if (config.textureProvider instanceof Reloadable) reloadManager.registerReloadable("textureProvider", (Reloadable) config.textureProvider); - Arrays.stream(config.mirrors).forEach(s -> { - try { - mirrorManager.addMirror(s); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - }); + Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror); if (config.permissionsHandler instanceof Reconfigurable) reconfigurableManager.registerReconfigurable("permissionsHandler", (Reconfigurable) config.permissionsHandler); @@ -416,13 +411,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE if (config.textureProvider instanceof Reconfigurable) reconfigurableManager.registerReconfigurable("textureProvider", (Reconfigurable) config.textureProvider); - Arrays.stream(config.mirrors).forEach(s -> { - try { - mirrorManager.addMirror(s); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - }); + Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror); // init modules modulesManager.initModules(); diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 2baf6264..d46e36cf 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -108,6 +108,8 @@ public static void main(String... args) throws Throwable { } LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); Launcher.setConfig(cfg); + if(config.env != null) Launcher.applyLauncherEnv(config.env); + else Launcher.applyLauncherEnv(LauncherConfig.LauncherEnvironment.STD); if (config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile), true)); if (config.syncAuth) auth(wrapper); else @@ -176,6 +178,7 @@ private static void generateConfigIfNotExists() throws IOException { newConfig.stopOnError = true; newConfig.reconnectCount = 10; newConfig.reconnectSleep = 1000; + newConfig.env = LauncherConfig.LauncherEnvironment.STD; //try(Reader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launcher/server/ServerWrapper.cfg"))) //{ // newConfig = gson.fromJson(reader,Config.class); @@ -207,6 +210,7 @@ public static final class Config { public String mainclass; public String login; public String password; + public LauncherConfig.LauncherEnvironment env; } public ClientProfile profile; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index ec40c3a1..fe399fbf 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -8,6 +8,7 @@ import ru.gravit.utils.Version; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.JVMHelper; +import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; import java.io.IOException; @@ -130,4 +131,27 @@ public static Version getVersion() { public static boolean isUsingAvanguard() { return JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE && useAvanguard; } + + public static void applyLauncherEnv(LauncherConfig.LauncherEnvironment env) + { + switch (env) + { + case DEV: + LogHelper.setDevEnabled(true); + LogHelper.setStacktraceEnabled(true); + LogHelper.setDebugEnabled(true); + break; + case DEBUG: + LogHelper.setDebugEnabled(true); + LogHelper.setStacktraceEnabled(true); + break; + case STD: + break; + case PROD: + LogHelper.setStacktraceEnabled(false); + LogHelper.setDebugEnabled(false); + LogHelper.setDevEnabled(false); + break; + } + } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index 067df7a0..ea50ef9d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -60,13 +60,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException else if (config.env == 2) env = LauncherEnvironment.STD; else if (config.env == 3) env = LauncherEnvironment.PROD; else env = LauncherEnvironment.STD; - if (env == LauncherEnvironment.PROD) { - LogHelper.setStacktraceEnabled(false); - LogHelper.setDebugEnabled(false); - } - if (env == LauncherEnvironment.DEV || env == LauncherEnvironment.DEBUG) { - LogHelper.setDebugEnabled(true); - } + Launcher.applyLauncherEnv(env); // Read signed runtime int count = input.readLength(0); Map localResources = new HashMap<>(count); diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java index 47acb689..4e76fa66 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java @@ -22,6 +22,8 @@ public final class LogHelper { @LauncherAPI public static final String DEBUG_PROPERTY = "launcher.debug"; @LauncherAPI + public static final String DEV_PROPERTY = "launcher.dev"; + @LauncherAPI public static final String STACKTRACE_PROPERTY = "launcher.stacktrace"; @LauncherAPI public static final String NO_JANSI_PROPERTY = "launcher.noJAnsi"; @@ -32,6 +34,7 @@ public final class LogHelper { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss", Locale.US); private static final AtomicBoolean DEBUG_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEBUG_PROPERTY)); private static final AtomicBoolean STACKTRACE_ENABLED = new AtomicBoolean(Boolean.getBoolean(STACKTRACE_PROPERTY)); + private static final AtomicBoolean DEV_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEV_PROPERTY)); private static final Set OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2)); private static final Output STD_OUTPUT; @@ -64,11 +67,23 @@ public static void debug(String message) { } } + @LauncherAPI + public static void dev(String message) { + if (isDevEnabled()) { + log(Level.DEV, message, false); + } + } + @LauncherAPI public static void debug(String format, Object... args) { debug(String.format(format, args)); } + @LauncherAPI + public static void dev(String format, Object... args) { + debug(String.format(format, args)); + } + @LauncherAPI public static void error(Throwable exc) { error(isStacktraceEnabled() ? toString(exc) : exc.toString()); @@ -109,11 +124,21 @@ public static boolean isStacktraceEnabled() { return STACKTRACE_ENABLED.get(); } + @LauncherAPI + public static boolean isDevEnabled() { + return DEV_ENABLED.get(); + } + @LauncherAPI public static void setStacktraceEnabled(boolean stacktraceEnabled) { STACKTRACE_ENABLED.set(stacktraceEnabled); } + @LauncherAPI + public static void setDevEnabled(boolean stacktraceEnabled) { + DEV_ENABLED.set(stacktraceEnabled); + } + @LauncherAPI public static void log(Level level, String message, boolean sub) { String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now()); @@ -318,7 +343,7 @@ public interface Output { @LauncherAPI public enum Level { - DEBUG("DEBUG"), INFO("INFO"), WARNING("WARN"), ERROR("ERROR"); + DEV("DEV"),DEBUG("DEBUG"), INFO("INFO"), WARNING("WARN"), ERROR("ERROR"); public final String name; Level(String name) { From 6db5d818b0eea5381c6356a42091ec8c6920df0d Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 15 Jan 2019 11:05:24 +0700 Subject: [PATCH 09/10] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=83=D1=80=D0=BE=D0=B2=D0=BD?= =?UTF-8?q?=D0=B8=20=D0=BB=D0=BE=D0=B3=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=B5=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D1=85=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launcher/client/ClientLauncher.java | 1 + .../java/ru/gravit/launcher/hasher/DirWatcher.java | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) 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 c80c41c3..251cc728 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -409,6 +409,7 @@ public static Process launch( } args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); + args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()))); if (LauncherConfig.ADDRESS_OVERRIDE != null) args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE)); if (JVMHelper.OS_TYPE == OS.MUSTDIE) { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java index 582e7955..e4353e75 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java @@ -34,7 +34,6 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { FileVisitResult result = super.preVisitDirectory(dir, attrs); if (DirWatcher.this.dir.equals(dir)) { - LogHelper.subInfo("DirWatcher register V1 %s %s", dir.toString(), result.toString()); dir.register(service, KINDS); return result; } @@ -42,12 +41,10 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th // Maybe it's unnecessary to go deeper path.add(IOHelper.getFileName(dir)); if (matcher != null && !matcher.shouldVerify(path)) { - LogHelper.subInfo("DirWatcher skipped %s %s", dir.toString(), result.toString()); return FileVisitResult.SKIP_SUBTREE; } // Register - LogHelper.subInfo("DirWatcher register V2 %s %s", dir.toString(), result.toString()); dir.register(service, KINDS); return result; } @@ -124,7 +121,7 @@ private void processKey(WatchKey key) throws IOException { // Resolve paths and verify is not exclusion Path path = watchDir.resolve((Path) event.context()); - LogHelper.subInfo("DirWatcher event %s", path.toString()); + LogHelper.debug("DirWatcher event %s", path.toString()); Deque stringPath = toPath(dir.relativize(path)); if (matcher != null && !matcher.shouldVerify(stringPath)) continue; // Exclusion; should not be verified @@ -143,10 +140,10 @@ private void processKey(WatchKey key) throws IOException { } private void processLoop() throws IOException, InterruptedException { - LogHelper.info("WatchService start processing"); + LogHelper.debug("WatchService start processing"); while (!Thread.interrupted()) processKey(service.take()); - LogHelper.info("WatchService closed"); + LogHelper.debug("WatchService closed"); } @Override @@ -155,7 +152,7 @@ public void run() { try { processLoop(); } catch (InterruptedException | ClosedWatchServiceException ignored) { - LogHelper.info("WatchService closed 2"); + LogHelper.debug("WatchService closed 2"); // Do nothing (closed etc) } catch (Throwable exc) { handleError(exc); From b3c3ccea90402987655b563d17d0741f683e8c25 Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Wed, 16 Jan 2019 11:52:47 +0300 Subject: [PATCH 10/10] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B7=D0=B0=D0=BF=D1=83?= =?UTF-8?q?=D1=81=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ru/gravit/launchserver/LaunchServer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 376db65e..5a4e2849 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -650,8 +650,7 @@ public void syncUpdatesDir(Collection dirs) throws IOException { public void restart() { ProcessBuilder builder = new ProcessBuilder(); - List args = new ArrayList<>(); - if (config.startScript != null) args.add(config.startScript); + if (config.startScript != null) builder.command(Collections.singletonList(config.startScript)); else throw new IllegalArgumentException("Please create start script and link it as startScript in config."); builder.directory(this.dir.toFile()); builder.inheritIO();