From 81d2d8b14effc3194fb7311cec6245b41ea4115a Mon Sep 17 00:00:00 2001 From: ME1312 Date: Fri, 25 Jun 2021 18:26:49 -0400 Subject: [PATCH] Better log handling & Forge-related fixes --- SubServers.Bungee/common/pom.xml | 2 +- SubServers.Bungee/pom.xml | 2 +- .../Host/External/ExternalSubCreator.java | 2 +- .../Host/External/ExternalSubLogger.java | 11 ++- .../Host/Internal/InternalSubCreator.java | 54 ++++++---- .../Host/Internal/InternalSubLogger.java | 98 ++++++++++--------- .../Host/Internal/InternalSubServer.java | 2 + .../Network/Packet/PacketInExLogMessage.java | 11 ++- .../Client/Bukkit/Network/SubProtocol.java | 3 +- SubServers.Client/Common/pom.xml | 4 +- .../Client/Sponge/Network/SubProtocol.java | 3 +- SubServers.Creator/Forge/build.sh | 82 ++++++++++------ SubServers.Creator/Paper/build.sh | 2 +- SubServers.Creator/Purpur/build.sh | 2 +- SubServers.Creator/Spigot/build.sh | 2 +- SubServers.Creator/Sponge/build.sh | 2 +- SubServers.Creator/Vanilla/build.sh | 2 +- SubServers.Host/pom.xml | 4 +- .../Host/Executable/SubCreatorImpl.java | 30 ++++-- .../Host/Executable/SubLoggerImpl.java | 81 ++++++++------- .../Host/Executable/SubServerImpl.java | 5 +- .../Network/Packet/PacketOutExLogMessage.java | 12 +-- .../SubServers/Sync/Network/SubProtocol.java | 3 +- 23 files changed, 242 insertions(+), 177 deletions(-) diff --git a/SubServers.Bungee/common/pom.xml b/SubServers.Bungee/common/pom.xml index d510ac56..989c7439 100644 --- a/SubServers.Bungee/common/pom.xml +++ b/SubServers.Bungee/common/pom.xml @@ -28,7 +28,7 @@ net.ME1312.Galaxi GalaxiUtil - 21w24a + 21w26a compile diff --git a/SubServers.Bungee/pom.xml b/SubServers.Bungee/pom.xml index 666438b9..b67778bb 100644 --- a/SubServers.Bungee/pom.xml +++ b/SubServers.Bungee/pom.xml @@ -34,7 +34,7 @@ net.ME1312.SubData Server - 21w08a + 21w26a compile diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java index 2df2537f..6185814d 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java @@ -76,7 +76,7 @@ public class ExternalSubCreator extends SubCreator { if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display")); } } catch (Exception e) { - System.out.println(host.getName() + "/Creator > Couldn't load template: " + file.getName()); + Logger.get(host.getName()).severe("Couldn't load template: " + file.getName()); e.printStackTrace(); } } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubLogger.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubLogger.java index f5b63160..b4fc7a1d 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubLogger.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubLogger.java @@ -74,17 +74,20 @@ public class ExternalSubLogger extends SubLogger { } @SuppressWarnings("deprecation") - private void log(String type, String msg) { + private void log(int type, String msg) { if (started) { Level level; // Determine LOG LEVEL switch (type) { - case "WARN": + case 80: + level = Level.FINE; + break; + case 40: level = Level.WARNING; break; - case "SEVERE": - case "ERROR": + case 30: + case 20: level = Level.SEVERE; break; default: diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java index 0c2ddf48..884db26f 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java @@ -39,6 +39,8 @@ import java.security.MessageDigest; import java.util.*; import java.util.regex.Pattern; +import static java.util.logging.Level.*; + /** * Internal SubCreator Class */ @@ -90,35 +92,42 @@ public class InternalSubCreator extends SubCreator { this.callback = callback; } - private ObjectMap build(File dir, ServerTemplate template, List history) throws SubCreatorException { + private ObjectMap build(File dir, ServerTemplate template, List history, List stack) throws SubCreatorException { ObjectMap server = new ObjectMap(); Version version = this.version; HashMap var = new HashMap(); boolean error = false; - if (history.contains(template)) throw new IllegalStateException("Template import loop detected"); - history.add(template); + if (stack.contains(template)) throw new IllegalStateException("Infinite template import loop detected"); + stack.add(template); for (String other : template.getBuildOptions().getStringList("Import", new ArrayList())) { - if (templates.keySet().contains(other.toLowerCase())) { - if (templates.get(other.toLowerCase()).isEnabled()) { - if (version != null || !templates.get(other.toLowerCase()).requiresVersion()) { - if (update == null || templates.get(other.toLowerCase()).canUpdate()) { - server.setAll(this.build(dir, templates.get(other.toLowerCase()), history)); + if (templates.containsKey(other.toLowerCase())) { + final ServerTemplate ot = templates.get(other.toLowerCase()); + if (ot.isEnabled()) { + if (version != null || !ot.requiresVersion()) { + if (update == null || ot.canUpdate()) { + if (!history.contains(ot)) { + server.setAll(this.build(dir, ot, history, stack)); + } else { + log.log(WARNING, "Skipping template that is already loaded: " + other); + } } else { - Logger.get(prefix).warning("Skipping template that cannot be run in update mode: " + other); + log.log(WARNING, "Skipping template that cannot be run in update mode: " + other); } } else { - Logger.get(prefix).warning("Skipping template that requires extra versioning information: " + other); + log.log(WARNING, "Skipping template that requires extra versioning information: " + other); } } else { - Logger.get(prefix).warning("Skipping disabled template: " + other); + log.log(WARNING, "Skipping disabled template: " + other); } } else { - Logger.get(prefix).warning("Skipping missing template: " + other); + log.log(WARNING, "Skipping missing template: " + other); } } + history.add(template); + stack.remove(template); server.setAll(template.getConfigOptions()); try { - Logger.get(prefix).info("Loading" + ((template.isDynamic())?" Dynamic":"") + " Template: " + template.getDisplayName()); + log.log(INFO, "Loading" + ((template.isDynamic())?" Dynamic":"") + " Template: " + template.getDisplayName()); updateDirectory(template.getDirectory(), dir, template.getBuildOptions().getBoolean("Update-Files", false)); for (ObjectMapValue replacement : template.getBuildOptions().getMap("Replacements", new ObjectMap<>()).getValues()) if (!replacement.isNull()) { @@ -142,7 +151,7 @@ public class InternalSubCreator extends SubCreator { case SPONGE: case FORGE: if (version != null) { - Logger.get(prefix).info("Searching Versions..."); + log.log(INFO, "Searching Versions..."); ObjectMap spversionmanifest = new ObjectMap(new Gson().fromJson("{\"versions\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://dl-api.spongepowered.org/v1/org.spongepowered/sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "/downloads?type=stable&minecraft=" + version).openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); ObjectMap spprofile = null; @@ -155,11 +164,11 @@ public class InternalSubCreator extends SubCreator { } if (spversion == null) throw new InvalidServerException("Cannot find Sponge version for Minecraft " + version.toString()); - Logger.get(prefix).info("Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"'); + log.log(INFO, "Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"'); if (template.getType() == ServerType.FORGE) { Version mcfversion = new Version(((spprofile.getMap("dependencies").getRawString("forge").contains("-"))?"":spprofile.getMap("dependencies").getRawString("minecraft") + '-') + spprofile.getMap("dependencies").getRawString("forge")); - Logger.get(prefix).info("Found \"forge-" + mcfversion.toString() + '"'); + log.log(INFO, "Found \"forge-" + mcfversion.toString() + '"'); var.put("mcf_version", mcfversion.toString()); } @@ -181,16 +190,16 @@ public class InternalSubCreator extends SubCreator { var.put("source", dir.getAbsolutePath()); try { - Logger.get(prefix).info("Launching Build Script..."); + log.log(INFO, "Launching Build Script..."); ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(gitBash, template.getBuildOptions().getRawString("Executable"))).directory(dir); pb.environment().putAll(var); - process = pb.start(); log.file = new File(dir, "SubCreator-" + template.getName() + ((version != null)?"-"+version.toString():"") + ".log"); + process = pb.start(); log.process = process; log.start(); process.waitFor(); - Thread.sleep(500); + Thread.sleep(250); if (process.exitValue() != 0) error = true; } catch (InterruptedException e) { @@ -233,12 +242,15 @@ public class InternalSubCreator extends SubCreator { ObjectMap server = new ObjectMap(); ObjectMap config; try { - config = build(dir, template, new LinkedList<>()); + log.init(); + config = build(dir, template, new LinkedList<>(), new LinkedList<>()); } catch (SubCreatorException e) { config = null; } catch (Exception e) { config = null; e.printStackTrace(); + } finally { + log.destroy(); } declaration.run(); @@ -364,7 +376,7 @@ public class InternalSubCreator extends SubCreator { if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display")); } } catch (Exception e) { - Logger.get(host.getName() + File.separator + "Creator").info("Couldn't load template: " + file.getName()); + Logger.get(host.getName()).severe("Couldn't load template: " + file.getName()); e.printStackTrace(); } } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java index d712ff6b..f452b975 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubLogger.java @@ -48,6 +48,16 @@ public class InternalSubLogger extends SubLogger { this.file = file; } + void init() { + List filters = new ArrayList(); + filters.addAll(this.filters); + for (SubLogFilter filter : filters) try { + filter.start(); + } catch (Throwable e) { + new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace(); + } + } + @Override public void start() { started = true; @@ -62,13 +72,6 @@ public class InternalSubLogger extends SubLogger { } if (out == null) (out = new Thread(() -> start(process.getInputStream(), false), "SubServers.Bungee::Internal_Log_Spooler(" + name + ')')).start(); if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), "SubServers.Bungee::Internal_Error_Spooler(" + name + ')')).start(); - List filters = new ArrayList(); - filters.addAll(this.filters); - for (SubLogFilter filter : filters) try { - filter.start(); - } catch (Throwable e) { - new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace(); - } } @SuppressWarnings("deprecation") @@ -124,19 +127,7 @@ public class InternalSubLogger extends SubLogger { level = Level.INFO; } - // Filter Message - boolean allow = (SubAPI.getInstance().getInternals().sudo == getHandler() && SubAPI.getInstance().getInternals().canSudo) || (log.value() && (SubAPI.getInstance().getInternals().sudo == null || !SubAPI.getInstance().getInternals().canSudo)); - List filters = new ArrayList(); - filters.addAll(this.filters); - for (SubLogFilter filter : filters) - try { - allow = (filter.log(level, msg) && allow); - } catch (Throwable e) { - new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace(); - } - - // Log to CONSOLE - if (allow) Logger.get(name).log(level, msg); + log(level, msg); // Log to FILE if (writer != null) { @@ -146,15 +137,56 @@ public class InternalSubLogger extends SubLogger { } } + void log(Level level, String message) { + // Filter Message + boolean allow = (SubAPI.getInstance().getInternals().sudo == getHandler() && SubAPI.getInstance().getInternals().canSudo) || (log.value() && (SubAPI.getInstance().getInternals().sudo == null || !SubAPI.getInstance().getInternals().canSudo)); + List filters = new ArrayList(); + filters.addAll(this.filters); + for (SubLogFilter filter : filters) { + try { + allow = (filter.log(level, message) && allow); + } catch (Throwable e) { + new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace(); + } + } + + // Log to CONSOLE + if (allow || !started) { + Logger.get(name).log(level, message); + } + } + @Override public void stop() { try { if (out != null) out.interrupt(); if (err != null) err.interrupt(); - destroy(); + if (started) { + started = false; + if (writer != null) { + PrintWriter writer = this.writer; + this.writer = null; + int l = (int) Math.floor((("---------- LOG START \u2014 " + name + " ----------").length() - 9) / 2); + String s = ""; + while (s.length() < l) s += '-'; + if (writer != null) { + writer.println(s + " LOG END " + s); + writer.close(); + } + } + } } catch (NullPointerException e) {} } + void destroy() { + filters.addAll(this.filters); + for (SubLogFilter filter : filters) try { + filter.stop(); + } catch (Throwable e) { + new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace(); + } + } + @Override public void registerFilter(SubLogFilter filter) { if (Util.isNull(filter)) throw new NullPointerException(); @@ -167,30 +199,6 @@ public class InternalSubLogger extends SubLogger { Util.isException(() -> filters.remove(filter)); } - private void destroy() { - if (started) { - started = false; - List filters = new ArrayList(); - filters.addAll(this.filters); - for (SubLogFilter filter : filters) try { - filter.stop(); - } catch (Throwable e) { - new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace(); - } - if (writer != null) { - PrintWriter writer = this.writer; - this.writer = null; - int l = (int) Math.floor((("---------- LOG START \u2014 " + name + " ----------").length() - 9) / 2); - String s = ""; - while (s.length() < l) s += '-'; - if (writer != null) { - writer.println(s + " LOG END " + s); - writer.close(); - } - } - } - } - @Override public Object getHandler() { return handle; diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java index 871666bd..0bbbe196 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java @@ -155,6 +155,7 @@ public class InternalSubServer extends SubServerImpl { pb.environment().put("host", host.getName()); pb.environment().put("address", host.getAddress().getHostAddress()); pb.environment().put("port", Integer.toString(getAddress().getPort())); + logger.init(); process = pb.start(); Logger.get("SubServers").info("Now starting " + getName()); logger.process = process; @@ -174,6 +175,7 @@ public class InternalSubServer extends SubServerImpl { allowrestart = false; } + logger.destroy(); Logger.get("SubServers").info(getName() + " has stopped"); process = null; command = null; diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketInExLogMessage.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketInExLogMessage.java index ec6fcd31..57282d20 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketInExLogMessage.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketInExLogMessage.java @@ -23,11 +23,14 @@ public class PacketInExLogMessage implements PacketObjectIn { @Override public void receive(SubDataClient client, ObjectMap data) { try { - if (data.contains(0x0000) && loggers.keySet().contains(data.getUUID(0x0000))) { - if (data.contains(0x0001) && data.contains(0x0002)) { - Util.reflect(ExternalSubLogger.class.getDeclaredMethod("log", String.class, String.class), loggers.get(data.getUUID(0x0000)), data.getRawString(0x0001), data.getRawString(0x0002)); + if (data.contains(0x0000)) { + if (data.contains(0x0002) && data.contains(0x0001)) { + if (loggers.containsKey(data.getUUID(0x0000))) { + Util.reflect(ExternalSubLogger.class.getDeclaredMethod("log", int.class, String.class), loggers.get(data.getUUID(0x0000)), data.getInt(0x0001), data.getRawString(0x0002)); + } } else { unregister(data.getUUID(0x0000)); + client.close(); } } } catch (Exception e) { @@ -58,6 +61,6 @@ public class PacketInExLogMessage implements PacketObjectIn { * @param id External Address */ public static void unregister(UUID id) { - loggers.remove(id).stop(); + if (loggers.containsKey(id)) loggers.remove(id).stop(); } } diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubProtocol.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubProtocol.java index 8b3cf394..6e317190 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubProtocol.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/SubProtocol.java @@ -16,6 +16,7 @@ import net.ME1312.SubServers.Client.Common.Network.Packet.*; import org.bukkit.Bukkit; +import java.io.File; import java.io.IOException; import java.net.InetAddress; import java.util.HashMap; @@ -118,7 +119,7 @@ public class SubProtocol extends SubDataProtocol { log.setUseParentHandlers(false); log.addHandler(new Handler() { private boolean open = true; - private String prefix = "SubData" + ((channel != 0)?"/+"+channel:""); + private String prefix = "SubData" + ((channel != 0)?File.separator+"+"+channel:""); @Override public void publish(LogRecord record) { diff --git a/SubServers.Client/Common/pom.xml b/SubServers.Client/Common/pom.xml index c8430b6b..26da353b 100644 --- a/SubServers.Client/Common/pom.xml +++ b/SubServers.Client/Common/pom.xml @@ -18,13 +18,13 @@ net.ME1312.Galaxi GalaxiUtil - 21w24a + 21w26a compile net.ME1312.SubData Client - 21w08a + 21w26a compile diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/SubProtocol.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/SubProtocol.java index d7973e0a..dbbdbcc8 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/SubProtocol.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/SubProtocol.java @@ -18,6 +18,7 @@ import net.ME1312.SubServers.Client.Sponge.SubPlugin; import org.slf4j.LoggerFactory; import org.spongepowered.api.Sponge; +import java.io.File; import java.io.IOException; import java.net.InetAddress; import java.util.HashMap; @@ -119,7 +120,7 @@ public class SubProtocol extends SubDataProtocol { Logger log = Logger.getAnonymousLogger(); log.setUseParentHandlers(false); log.addHandler(new Handler() { - private org.slf4j.Logger log = LoggerFactory.getLogger("SubData" + ((channel != 0)? "/+"+channel:"")); + private org.slf4j.Logger log = LoggerFactory.getLogger("SubData" + ((channel != 0)?File.separator+"+"+channel:"")); private boolean open = true; @Override diff --git a/SubServers.Creator/Forge/build.sh b/SubServers.Creator/Forge/build.sh index 5b3a8aaa..77d2e9b4 100644 --- a/SubServers.Creator/Forge/build.sh +++ b/SubServers.Creator/Forge/build.sh @@ -15,7 +15,7 @@ function __DL() { if [[ -x "$(command -v wget)" ]]; then wget -O "$1" "$2"; return $? else - curl -o "$1" "$2"; return $? + curl -Lo "$1" "$2"; return $? fi } function __Restore() { @@ -33,46 +33,72 @@ function __Restore() { fi } echo Downloading the Minecraft Forge Installer... -__DL "forge-$mcf_version-installer.jar" "http://files.minecraftforge.net/maven/net/minecraftforge/forge/$mcf_version/forge-$mcf_version-installer.jar"; __RETURN=$? +__DL "forge-$mcf_version-installer.jar" "https://files.minecraftforge.net/maven/net/minecraftforge/forge/$mcf_version/forge-$mcf_version-installer.jar"; __RETURN=$? if [[ $__RETURN -eq 0 ]]; then - echo Installing Minecraft Forge... - "$java" -jar "forge-$mcf_version-installer.jar" --installServer; __RETURN=$? + echo "" + echo Downloading the Minecraft Forge Installer Installer... + __DL "forge-installer-installer.jar" "https://dev.me1312.net/jenkins/job/Forge%20Installer%20Installer/lastSuccessfulBuild/artifact/artifacts/forge-installer-installer.jar"; __RETURN=$? if [[ $__RETURN -eq 0 ]]; then - echo Cleaning Up... - if [[ ! -d "mods" ]]; then - mkdir mods - fi - rm -Rf "forge-$mcf_version-installer.jar" - rm -Rf "forge-$mcf_version-installer.jar.log" - mv -f "forge-$mcf_version-universal.jar" Forge.jar - echo Downloading SpongeForge... - if [[ -f "mods/Sponge.jar" ]]; then - if [[ -f "mods/Sponge.old.jar.x" ]]; then - rm -Rf mods/Sponge.old.jar.x - fi - mv mods/Sponge.jar mods/Sponge.old.jar.x - fi - __DL mods/Sponge.jar "https://repo.spongepowered.org/maven/org/spongepowered/spongeforge/$sp_version/spongeforge-$sp_version.jar"; __RETURN=$? + echo Launching Minecraft Forge Installer Installer + "$java" -jar "forge-installer-installer.jar" "forge-$mcf_version-installer.jar"; __RETURN=$? if [[ $__RETURN -eq 0 ]]; then - echo Cleaning Up... - rm -Rf "$0" - exit 0 + rm -Rf "forge-installer-installer.jar" + echo Installing Minecraft Forge... + "$java" -jar "forge-$mcf_version-installer.jar" --installServer; __RETURN=$? + if [[ $__RETURN -ne 0 ]]; then + echo "" + echo Retrying... + "$java" -jar "forge-$mcf_version-installer.jar" --installServer --offline; __RETURN=$? + fi + if [[ $__RETURN -eq 0 ]]; then + echo Cleaning Up... + if [[ ! -d "mods" ]]; then + mkdir mods + fi + rm -Rf "forge-$mcf_version-installer.jar" + rm -Rf "forge-$mcf_version-installer.jar.log" + mv -f "forge-$mcf_version-universal.jar" Forge.jar + echo Downloading SpongeForge... + if [[ -f "mods/Sponge.jar" ]]; then + if [[ -f "mods/Sponge.old.jar.x" ]]; then + rm -Rf mods/Sponge.old.jar.x + fi + mv mods/Sponge.jar mods/Sponge.old.jar.x + fi + __DL mods/Sponge.jar "https://repo.spongepowered.org/maven/org/spongepowered/spongeforge/$sp_version/spongeforge-$sp_version.jar"; __RETURN=$? + if [[ $__RETURN -eq 0 ]]; then + echo Cleaning Up... + rm -Rf "$0" + exit 0 + else + echo ERROR: Failed downloading Sponge. Is SpongePowered.org down? + __Restore + rm -Rf "$0" + exit 7 + fi + else + echo ERROR: The Forge Installer exited with an error. Please try again + __Restore + rm -Rf "forge-$mcf_version-installer.jar" + rm -Rf "forge-$mcf_version-installer.jar.log" + rm -Rf "$0" + exit 6 + fi else - echo ERROR: Failed downloading Sponge. Is SpongePowered.org down? - __Restore + rm -Rf "forge-$mcf_version-installer.jar" + rm -Rf "forge-installer-installer.jar" rm -Rf "$0" + echo ERROR: The Forge Installer Installer exited with an error. Please try again exit 5 fi else - echo ERROR: The Installer exited with an error. Please try again - __Restore + echo ERROR: Failed downloading the Forge Installer Installer. Is ME1312.net down? rm -Rf "forge-$mcf_version-installer.jar" - rm -Rf "forge-$mcf_version-installer.jar.log" rm -Rf "$0" exit 4 fi else - echo ERROR: Failed downloading Forge. Is MinecraftForge.net down? + echo ERROR: Failed downloading the Forge Installer. Is MinecraftForge.net down? rm -Rf "$0" exit 3 fi diff --git a/SubServers.Creator/Paper/build.sh b/SubServers.Creator/Paper/build.sh index cd090642..584a4c30 100644 --- a/SubServers.Creator/Paper/build.sh +++ b/SubServers.Creator/Paper/build.sh @@ -11,7 +11,7 @@ function __DL() { if [[ -x "$(command -v wget)" ]]; then wget -O "$1" "$2"; return $? else - curl -o "$1" "$2"; return $? + curl -Lo "$1" "$2"; return $? fi } function __Restore() { diff --git a/SubServers.Creator/Purpur/build.sh b/SubServers.Creator/Purpur/build.sh index 8da8019e..e73ae1bd 100644 --- a/SubServers.Creator/Purpur/build.sh +++ b/SubServers.Creator/Purpur/build.sh @@ -11,7 +11,7 @@ function __DL() { if [[ -x "$(command -v wget)" ]]; then wget -O "$1" "$2"; return $? else - curl -o "$1" "$2"; return $? + curl -Lo "$1" "$2"; return $? fi } function __Restore() { diff --git a/SubServers.Creator/Spigot/build.sh b/SubServers.Creator/Spigot/build.sh index d9866ca8..3731ae2b 100644 --- a/SubServers.Creator/Spigot/build.sh +++ b/SubServers.Creator/Spigot/build.sh @@ -15,7 +15,7 @@ function __DL() { if [[ -x "$(command -v wget)" ]]; then wget -O "$1" "$2"; return $? else - curl -o "$1" "$2"; return $? + curl -Lo "$1" "$2"; return $? fi } if [[ -z "$cache" ]] || [[ ! -f "$cache/Spigot-$version.jar" ]] || [[ "$mode" == "UPDATE" && $(find "$cache/Spigot-$version.jar" -mtime +1 -print) ]]; then diff --git a/SubServers.Creator/Sponge/build.sh b/SubServers.Creator/Sponge/build.sh index 1797186f..1994cd94 100644 --- a/SubServers.Creator/Sponge/build.sh +++ b/SubServers.Creator/Sponge/build.sh @@ -11,7 +11,7 @@ function __DL() { if [[ -x "$(command -v wget)" ]]; then wget -O "$1" "$2"; return $? else - curl -o "$1" "$2"; return $? + curl -Lo "$1" "$2"; return $? fi } function __Restore() { diff --git a/SubServers.Creator/Vanilla/build.sh b/SubServers.Creator/Vanilla/build.sh index 86b78f88..c16464fe 100644 --- a/SubServers.Creator/Vanilla/build.sh +++ b/SubServers.Creator/Vanilla/build.sh @@ -15,7 +15,7 @@ function __DL() { if [[ -x "$(command -v wget)" ]]; then wget -O "$1" "$2"; return $? else - curl -o "$1" "$2"; return $? + curl -Lo "$1" "$2"; return $? fi } if [[ -z "$cache" ]] || [[ ! -f "$cache/Vanilla-$version.jar" ]]; then diff --git a/SubServers.Host/pom.xml b/SubServers.Host/pom.xml index 8cbaf63c..2ced8f81 100644 --- a/SubServers.Host/pom.xml +++ b/SubServers.Host/pom.xml @@ -30,13 +30,13 @@ net.ME1312.Galaxi GalaxiEngine - 21w24a + 21w26a compile net.ME1312.Galaxi GalaxiUI - 21w24a + 21w26a runtime diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubCreatorImpl.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubCreatorImpl.java index a4b37d9c..6e35d82b 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubCreatorImpl.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubCreatorImpl.java @@ -293,19 +293,24 @@ public class SubCreatorImpl { templates.putAll(host.templates); } - private ObjectMap build(File dir, ServerTemplate template, List history) throws SubCreatorException { + private ObjectMap build(File dir, ServerTemplate template, List history, List stack) throws SubCreatorException { ObjectMap server = new ObjectMap(); Version version = this.version; HashMap var = new HashMap(); boolean error = false; - if (history.contains(template)) throw new IllegalStateException("Template import loop detected"); - history.add(template); + if (stack.contains(template)) throw new IllegalStateException("Infinite template import loop detected"); + stack.add(template); for (String other : template.getBuildOptions().getStringList("Import", new ArrayList())) { - if (templates.keySet().contains(other.toLowerCase())) { - if (templates.get(other.toLowerCase()).isEnabled()) { - if (version != null || !templates.get(other.toLowerCase()).requiresVersion()) { - if (update == null || templates.get(other.toLowerCase()).canUpdate()) { - server.setAll(this.build(dir, templates.get(other.toLowerCase()), history)); + if (templates.containsKey(other.toLowerCase())) { + final ServerTemplate ot = templates.get(other.toLowerCase()); + if (ot.isEnabled()) { + if (version != null || !ot.requiresVersion()) { + if (update == null || ot.canUpdate()) { + if (!history.contains(ot)) { + server.setAll(this.build(dir, ot, history, stack)); + } else { + log.logger.warn.println("Skipping template that's already loaded: " + other); + } } else { log.logger.warn.println("Skipping template that cannot be run in update mode: " + other); } @@ -319,6 +324,8 @@ public class SubCreatorImpl { log.logger.warn.println("Skipping missing template: " + other); } } + history.add(template); + stack.remove(template); server.setAll(template.getConfigOptions()); try { log.logger.info.println("Loading" + ((template.isDynamic())?" Dynamic":"") + " Template: " + template.getDisplayName()); @@ -386,8 +393,8 @@ public class SubCreatorImpl { log.logger.info.println("Launching Build Script..."); ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.host.getRawString("Git-Bash"), template.getBuildOptions().getRawString("Executable"))).directory(dir); pb.environment().putAll(var); - process = pb.start(); log.file = new File(dir, "SubCreator-" + template.getName() + "-" + ((version != null)?"-"+version.toString():"") + ".log"); + process = pb.start(); log.process = process; log.start(); @@ -434,12 +441,15 @@ public class SubCreatorImpl { ObjectMap config; try { - config = build(dir, template, new LinkedList<>()); + log.init(); + config = build(dir, template, new LinkedList<>(), new LinkedList<>()); } catch (SubCreatorException e) { config = null; } catch (Exception e) { config = null; log.logger.error.println(e); + } finally { + log.destroy(); } declaration.run(); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubLoggerImpl.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubLoggerImpl.java index b861d887..9b6267f6 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubLoggerImpl.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubLoggerImpl.java @@ -40,7 +40,7 @@ public class SubLoggerImpl { static boolean logc = true; File file; private SubDataClient channel = null; - private LinkedList> ccache = null; + private LinkedList> ccache = null; private PrintWriter writer = null; private boolean started = false; private Thread out = null; @@ -70,13 +70,13 @@ public class SubLoggerImpl { if (logn) { if (this.address != null && channel != null && !channel.isClosed()) { if (ccache != null) { - for (Pair val : ccache) channel.sendPacket(new PacketOutExLogMessage(this.address, val.key(), val.value())); + for (Pair val : ccache) channel.sendPacket(new PacketOutExLogMessage(this.address, val.key(), val.value())); ccache = null; } - channel.sendPacket(new PacketOutExLogMessage(this.address, stream.getLevel().getName(), message)); + channel.sendPacket(new PacketOutExLogMessage(this.address, stream.getLevel().getID(), message)); } else { - if (ccache == null) ccache = new LinkedList>(); - ccache.add(new ContainedPair<>(stream.getLevel().getName(), message)); + if (ccache == null) ccache = new LinkedList>(); + ccache.add(new ContainedPair<>(stream.getLevel().getID(), message)); } } @@ -85,23 +85,10 @@ public class SubLoggerImpl { }); } - /** - * Start Logger - */ - public void start() { - started = true; - if (file != null && writer == null) { - try { - this.writer = new PrintWriter(file, "UTF-8"); - this.writer.println("---------- LOG START \u2014 " + name + " ----------"); - this.writer.flush(); - } catch (IOException e) { - logger.error.println(e); - } - } - Process process = this.process; - ExHost host = SubAPI.getInstance().getInternals(); + @SuppressWarnings("deprecation") + void init() { if (logn) Util.isException(() -> { + ExHost host = SubAPI.getInstance().getInternals(); channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel(); channel.on.closed(new Callback>() { @Override @@ -131,11 +118,24 @@ public class SubLoggerImpl { } }); }); + } + + public void start() { + started = true; + if (file != null && writer == null) { + try { + this.writer = new PrintWriter(file, "UTF-8"); + this.writer.println("---------- LOG START \u2014 " + name + " ----------"); + this.writer.flush(); + } catch (IOException e) { + logger.error.println(e); + } + } + Process process = this.process; if (out == null) (out = new Thread(() -> start(process.getInputStream(), false), SubAPI.getInstance().getAppInfo().getName() + "::Log_Spooler(" + name + ')')).start(); if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), SubAPI.getInstance().getAppInfo().getName() + "::Error_Spooler(" + name + ')')).start(); } - @SuppressWarnings("deprecation") private void start(InputStream in, boolean isErr) { try { @@ -213,29 +213,28 @@ public class SubLoggerImpl { try { if (out != null) out.interrupt(); if (err != null) err.interrupt(); - destroy(); + if (started) { + started = false; + if (writer != null) { + PrintWriter writer = this.writer; + this.writer = null; + int l = (int) Math.floor((("---------- LOG START \u2014 " + name + " ----------").length() - 9) / 2); + String s = ""; + while (s.length() < l) s += '-'; + if (writer != null) { + writer.println(s + " LOG END " + s); + writer.close(); + } + } + } } catch (NullPointerException e) {} } - private void destroy() { - if (started) { - started = false; - if (writer != null) { - PrintWriter writer = this.writer; - this.writer = null; - int l = (int) Math.floor((("---------- LOG START \u2014 " + name + " ----------").length() - 9) / 2); - String s = ""; - while (s.length() < l) s += '-'; - if (writer != null) { - writer.println(s + " LOG END " + s); - writer.close(); - } - } - if (channel != null && !channel.isClosed()) { - channel.sendPacket(new PacketOutExLogMessage(address)); - } - channel = null; + void destroy() { + if (channel != null && !channel.isClosed()) { + channel.sendPacket(new PacketOutExLogMessage(address)); } + channel = null; } /** diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServerImpl.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServerImpl.java index dbc9d733..d09ae761 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServerImpl.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServerImpl.java @@ -106,6 +106,7 @@ public class SubServerImpl { if (SubAPI.getInstance().getSubDataNetwork()[0] != null) pb.environment().put("host", SubAPI.getInstance().getName()); pb.environment().put("address", host.config.get().getMap("Settings").getRawString("Server-Bind")); pb.environment().put("port", Integer.toString(getPort())); + logger.init(); process = pb.start(); falsestart = false; host.log.info.println("Now starting " + name); @@ -126,8 +127,10 @@ public class SubServerImpl { if (falsestart) ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExEditServer(this, PacketExEditServer.UpdateType.LAUNCH_EXCEPTION)); } - if (SubAPI.getInstance().getSubDataNetwork()[0] != null) + logger.destroy(); + if (SubAPI.getInstance().getSubDataNetwork()[0] != null) { ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExEditServer(this, PacketExEditServer.UpdateType.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart)); + } host.log.info.println(name + " has stopped"); process = null; command = null; diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketOutExLogMessage.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketOutExLogMessage.java index 6e1af852..5671d69b 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketOutExLogMessage.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketOutExLogMessage.java @@ -11,31 +11,27 @@ import java.util.UUID; */ public class PacketOutExLogMessage implements PacketObjectOut { private UUID address; - private String level, line; - private boolean terminate; + private Byte level; + private String line; /** * New PacketInExLogMessage (Out) */ - public PacketOutExLogMessage(UUID address, String level, String line) { + public PacketOutExLogMessage(UUID address, byte level, String line) { this.address = address; this.level = level; this.line = line; - this.terminate = false; } /** - * New PacketInExLogMessage (Out) + * New PacketInExLogMessage (Reset) */ public PacketOutExLogMessage(UUID address) { this.address = address; - this.terminate = true; } @Override public ObjectMap send(SubDataSender client) throws Exception { - if (terminate) client.getConnection().close(); - ObjectMap data = new ObjectMap(); data.set(0x0000, address); if (level != null) data.set(0x0001, level); diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubProtocol.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubProtocol.java index 7b8bc943..7a5ced8c 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubProtocol.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubProtocol.java @@ -23,6 +23,7 @@ import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.conf.Configuration; +import java.io.File; import java.io.IOException; import java.net.InetAddress; import java.util.ArrayList; @@ -128,7 +129,7 @@ public class SubProtocol extends SubDataProtocol { } private Logger getLogger(int channel) { - return net.ME1312.SubServers.Bungee.Library.Compatibility.Logger.get("SubData" + ((channel != 0)?"/+"+channel:"")); + return net.ME1312.SubServers.Bungee.Library.Compatibility.Logger.get("SubData" + ((channel != 0)?File.separator+"+"+channel:"")); } @Override