Better log handling & Forge-related fixes

This commit is contained in:
ME1312 2021-06-25 18:26:49 -04:00
parent 1533987bf5
commit 81d2d8b14e
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
23 changed files with 242 additions and 177 deletions

View File

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId> <artifactId>GalaxiUtil</artifactId>
<version>21w24a</version> <version>21w26a</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -34,7 +34,7 @@
<dependency> <dependency>
<groupId>net.ME1312.SubData</groupId> <groupId>net.ME1312.SubData</groupId>
<artifactId>Server</artifactId> <artifactId>Server</artifactId>
<version>21w08a</version> <version>21w26a</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -76,7 +76,7 @@ public class ExternalSubCreator extends SubCreator {
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display")); if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
} }
} catch (Exception e) { } 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(); e.printStackTrace();
} }
} }

View File

@ -74,17 +74,20 @@ public class ExternalSubLogger extends SubLogger {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void log(String type, String msg) { private void log(int type, String msg) {
if (started) { if (started) {
Level level; Level level;
// Determine LOG LEVEL // Determine LOG LEVEL
switch (type) { switch (type) {
case "WARN": case 80:
level = Level.FINE;
break;
case 40:
level = Level.WARNING; level = Level.WARNING;
break; break;
case "SEVERE": case 30:
case "ERROR": case 20:
level = Level.SEVERE; level = Level.SEVERE;
break; break;
default: default:

View File

@ -39,6 +39,8 @@ import java.security.MessageDigest;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static java.util.logging.Level.*;
/** /**
* Internal SubCreator Class * Internal SubCreator Class
*/ */
@ -90,35 +92,42 @@ public class InternalSubCreator extends SubCreator {
this.callback = callback; this.callback = callback;
} }
private ObjectMap<String> build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException { private ObjectMap<String> build(File dir, ServerTemplate template, List<ServerTemplate> history, List<ServerTemplate> stack) throws SubCreatorException {
ObjectMap<String> server = new ObjectMap<String>(); ObjectMap<String> server = new ObjectMap<String>();
Version version = this.version; Version version = this.version;
HashMap<String, String> var = new HashMap<String, String>(); HashMap<String, String> var = new HashMap<String, String>();
boolean error = false; boolean error = false;
if (history.contains(template)) throw new IllegalStateException("Template import loop detected"); if (stack.contains(template)) throw new IllegalStateException("Infinite template import loop detected");
history.add(template); stack.add(template);
for (String other : template.getBuildOptions().getStringList("Import", new ArrayList<String>())) { for (String other : template.getBuildOptions().getStringList("Import", new ArrayList<String>())) {
if (templates.keySet().contains(other.toLowerCase())) { if (templates.containsKey(other.toLowerCase())) {
if (templates.get(other.toLowerCase()).isEnabled()) { final ServerTemplate ot = templates.get(other.toLowerCase());
if (version != null || !templates.get(other.toLowerCase()).requiresVersion()) { if (ot.isEnabled()) {
if (update == null || templates.get(other.toLowerCase()).canUpdate()) { if (version != null || !ot.requiresVersion()) {
server.setAll(this.build(dir, templates.get(other.toLowerCase()), history)); 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 { } 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 { } 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 { } else {
Logger.get(prefix).warning("Skipping disabled template: " + other); log.log(WARNING, "Skipping disabled template: " + other);
} }
} else { } 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()); server.setAll(template.getConfigOptions());
try { 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)); updateDirectory(template.getDirectory(), dir, template.getBuildOptions().getBoolean("Update-Files", false));
for (ObjectMapValue<String> replacement : template.getBuildOptions().getMap("Replacements", new ObjectMap<>()).getValues()) if (!replacement.isNull()) { for (ObjectMapValue<String> replacement : template.getBuildOptions().getMap("Replacements", new ObjectMap<>()).getValues()) if (!replacement.isNull()) {
@ -142,7 +151,7 @@ public class InternalSubCreator extends SubCreator {
case SPONGE: case SPONGE:
case FORGE: case FORGE:
if (version != null) { if (version != null) {
Logger.get(prefix).info("Searching Versions..."); log.log(INFO, "Searching Versions...");
ObjectMap<String> spversionmanifest = new ObjectMap<String>(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<String> spversionmanifest = new ObjectMap<String>(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<String> spprofile = null; ObjectMap<String> spprofile = null;
@ -155,11 +164,11 @@ public class InternalSubCreator extends SubCreator {
} }
if (spversion == null) if (spversion == null)
throw new InvalidServerException("Cannot find Sponge version for Minecraft " + version.toString()); 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) { 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")); 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()); var.put("mcf_version", mcfversion.toString());
} }
@ -181,16 +190,16 @@ public class InternalSubCreator extends SubCreator {
var.put("source", dir.getAbsolutePath()); var.put("source", dir.getAbsolutePath());
try { 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); ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(gitBash, template.getBuildOptions().getRawString("Executable"))).directory(dir);
pb.environment().putAll(var); pb.environment().putAll(var);
process = pb.start();
log.file = new File(dir, "SubCreator-" + template.getName() + ((version != null)?"-"+version.toString():"") + ".log"); log.file = new File(dir, "SubCreator-" + template.getName() + ((version != null)?"-"+version.toString():"") + ".log");
process = pb.start();
log.process = process; log.process = process;
log.start(); log.start();
process.waitFor(); process.waitFor();
Thread.sleep(500); Thread.sleep(250);
if (process.exitValue() != 0) error = true; if (process.exitValue() != 0) error = true;
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -233,12 +242,15 @@ public class InternalSubCreator extends SubCreator {
ObjectMap<String> server = new ObjectMap<String>(); ObjectMap<String> server = new ObjectMap<String>();
ObjectMap<String> config; ObjectMap<String> config;
try { try {
config = build(dir, template, new LinkedList<>()); log.init();
config = build(dir, template, new LinkedList<>(), new LinkedList<>());
} catch (SubCreatorException e) { } catch (SubCreatorException e) {
config = null; config = null;
} catch (Exception e) { } catch (Exception e) {
config = null; config = null;
e.printStackTrace(); e.printStackTrace();
} finally {
log.destroy();
} }
declaration.run(); declaration.run();
@ -364,7 +376,7 @@ public class InternalSubCreator extends SubCreator {
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display")); if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
} }
} catch (Exception e) { } 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(); e.printStackTrace();
} }
} }

View File

@ -48,6 +48,16 @@ public class InternalSubLogger extends SubLogger {
this.file = file; this.file = file;
} }
void init() {
List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
filters.addAll(this.filters);
for (SubLogFilter filter : filters) try {
filter.start();
} catch (Throwable e) {
new InvocationTargetException(e, "Exception while running SubLogger Event").printStackTrace();
}
}
@Override @Override
public void start() { public void start() {
started = true; 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 (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(); if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), "SubServers.Bungee::Internal_Error_Spooler(" + name + ')')).start();
List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
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") @SuppressWarnings("deprecation")
@ -124,19 +127,7 @@ public class InternalSubLogger extends SubLogger {
level = Level.INFO; level = Level.INFO;
} }
// Filter Message log(level, msg);
boolean allow = (SubAPI.getInstance().getInternals().sudo == getHandler() && SubAPI.getInstance().getInternals().canSudo) || (log.value() && (SubAPI.getInstance().getInternals().sudo == null || !SubAPI.getInstance().getInternals().canSudo));
List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
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 to FILE // Log to FILE
if (writer != null) { 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<SubLogFilter> filters = new ArrayList<SubLogFilter>();
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 @Override
public void stop() { public void stop() {
try { try {
if (out != null) out.interrupt(); if (out != null) out.interrupt();
if (err != null) err.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) {} } 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 @Override
public void registerFilter(SubLogFilter filter) { public void registerFilter(SubLogFilter filter) {
if (Util.isNull(filter)) throw new NullPointerException(); if (Util.isNull(filter)) throw new NullPointerException();
@ -167,30 +199,6 @@ public class InternalSubLogger extends SubLogger {
Util.isException(() -> filters.remove(filter)); Util.isException(() -> filters.remove(filter));
} }
private void destroy() {
if (started) {
started = false;
List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
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 @Override
public Object getHandler() { public Object getHandler() {
return handle; return handle;

View File

@ -155,6 +155,7 @@ public class InternalSubServer extends SubServerImpl {
pb.environment().put("host", host.getName()); pb.environment().put("host", host.getName());
pb.environment().put("address", host.getAddress().getHostAddress()); pb.environment().put("address", host.getAddress().getHostAddress());
pb.environment().put("port", Integer.toString(getAddress().getPort())); pb.environment().put("port", Integer.toString(getAddress().getPort()));
logger.init();
process = pb.start(); process = pb.start();
Logger.get("SubServers").info("Now starting " + getName()); Logger.get("SubServers").info("Now starting " + getName());
logger.process = process; logger.process = process;
@ -174,6 +175,7 @@ public class InternalSubServer extends SubServerImpl {
allowrestart = false; allowrestart = false;
} }
logger.destroy();
Logger.get("SubServers").info(getName() + " has stopped"); Logger.get("SubServers").info(getName() + " has stopped");
process = null; process = null;
command = null; command = null;

View File

@ -23,11 +23,14 @@ public class PacketInExLogMessage implements PacketObjectIn<Integer> {
@Override @Override
public void receive(SubDataClient client, ObjectMap<Integer> data) { public void receive(SubDataClient client, ObjectMap<Integer> data) {
try { try {
if (data.contains(0x0000) && loggers.keySet().contains(data.getUUID(0x0000))) { if (data.contains(0x0000)) {
if (data.contains(0x0001) && data.contains(0x0002)) { if (data.contains(0x0002) && data.contains(0x0001)) {
Util.reflect(ExternalSubLogger.class.getDeclaredMethod("log", String.class, String.class), loggers.get(data.getUUID(0x0000)), data.getRawString(0x0001), data.getRawString(0x0002)); 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 { } else {
unregister(data.getUUID(0x0000)); unregister(data.getUUID(0x0000));
client.close();
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -58,6 +61,6 @@ public class PacketInExLogMessage implements PacketObjectIn<Integer> {
* @param id External Address * @param id External Address
*/ */
public static void unregister(UUID id) { public static void unregister(UUID id) {
loggers.remove(id).stop(); if (loggers.containsKey(id)) loggers.remove(id).stop();
} }
} }

View File

@ -16,6 +16,7 @@ import net.ME1312.SubServers.Client.Common.Network.Packet.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.HashMap; import java.util.HashMap;
@ -118,7 +119,7 @@ public class SubProtocol extends SubDataProtocol {
log.setUseParentHandlers(false); log.setUseParentHandlers(false);
log.addHandler(new Handler() { log.addHandler(new Handler() {
private boolean open = true; private boolean open = true;
private String prefix = "SubData" + ((channel != 0)?"/+"+channel:""); private String prefix = "SubData" + ((channel != 0)?File.separator+"+"+channel:"");
@Override @Override
public void publish(LogRecord record) { public void publish(LogRecord record) {

View File

@ -18,13 +18,13 @@
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId> <artifactId>GalaxiUtil</artifactId>
<version>21w24a</version> <version>21w26a</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.ME1312.SubData</groupId> <groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId> <artifactId>Client</artifactId>
<version>21w08a</version> <version>21w26a</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -18,6 +18,7 @@ import net.ME1312.SubServers.Client.Sponge.SubPlugin;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.HashMap; import java.util.HashMap;
@ -119,7 +120,7 @@ public class SubProtocol extends SubDataProtocol {
Logger log = Logger.getAnonymousLogger(); Logger log = Logger.getAnonymousLogger();
log.setUseParentHandlers(false); log.setUseParentHandlers(false);
log.addHandler(new Handler() { 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; private boolean open = true;
@Override @Override

View File

@ -15,7 +15,7 @@ function __DL() {
if [[ -x "$(command -v wget)" ]]; then if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $? wget -O "$1" "$2"; return $?
else else
curl -o "$1" "$2"; return $? curl -Lo "$1" "$2"; return $?
fi fi
} }
function __Restore() { function __Restore() {
@ -33,46 +33,72 @@ function __Restore() {
fi fi
} }
echo Downloading the Minecraft Forge Installer... 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 if [[ $__RETURN -eq 0 ]]; then
echo Installing Minecraft Forge... echo ""
"$java" -jar "forge-$mcf_version-installer.jar" --installServer; __RETURN=$? 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 if [[ $__RETURN -eq 0 ]]; then
echo Cleaning Up... echo Launching Minecraft Forge Installer Installer
if [[ ! -d "mods" ]]; then "$java" -jar "forge-installer-installer.jar" "forge-$mcf_version-installer.jar"; __RETURN=$?
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 if [[ $__RETURN -eq 0 ]]; then
echo Cleaning Up... rm -Rf "forge-installer-installer.jar"
rm -Rf "$0" echo Installing Minecraft Forge...
exit 0 "$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 else
echo ERROR: Failed downloading Sponge. Is SpongePowered.org down? rm -Rf "forge-$mcf_version-installer.jar"
__Restore rm -Rf "forge-installer-installer.jar"
rm -Rf "$0" rm -Rf "$0"
echo ERROR: The Forge Installer Installer exited with an error. Please try again
exit 5 exit 5
fi fi
else else
echo ERROR: The Installer exited with an error. Please try again echo ERROR: Failed downloading the Forge Installer Installer. Is ME1312.net down?
__Restore
rm -Rf "forge-$mcf_version-installer.jar" rm -Rf "forge-$mcf_version-installer.jar"
rm -Rf "forge-$mcf_version-installer.jar.log"
rm -Rf "$0" rm -Rf "$0"
exit 4 exit 4
fi fi
else else
echo ERROR: Failed downloading Forge. Is MinecraftForge.net down? echo ERROR: Failed downloading the Forge Installer. Is MinecraftForge.net down?
rm -Rf "$0" rm -Rf "$0"
exit 3 exit 3
fi fi

View File

@ -11,7 +11,7 @@ function __DL() {
if [[ -x "$(command -v wget)" ]]; then if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $? wget -O "$1" "$2"; return $?
else else
curl -o "$1" "$2"; return $? curl -Lo "$1" "$2"; return $?
fi fi
} }
function __Restore() { function __Restore() {

View File

@ -11,7 +11,7 @@ function __DL() {
if [[ -x "$(command -v wget)" ]]; then if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $? wget -O "$1" "$2"; return $?
else else
curl -o "$1" "$2"; return $? curl -Lo "$1" "$2"; return $?
fi fi
} }
function __Restore() { function __Restore() {

View File

@ -15,7 +15,7 @@ function __DL() {
if [[ -x "$(command -v wget)" ]]; then if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $? wget -O "$1" "$2"; return $?
else else
curl -o "$1" "$2"; return $? curl -Lo "$1" "$2"; return $?
fi fi
} }
if [[ -z "$cache" ]] || [[ ! -f "$cache/Spigot-$version.jar" ]] || [[ "$mode" == "UPDATE" && $(find "$cache/Spigot-$version.jar" -mtime +1 -print) ]]; then if [[ -z "$cache" ]] || [[ ! -f "$cache/Spigot-$version.jar" ]] || [[ "$mode" == "UPDATE" && $(find "$cache/Spigot-$version.jar" -mtime +1 -print) ]]; then

View File

@ -11,7 +11,7 @@ function __DL() {
if [[ -x "$(command -v wget)" ]]; then if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $? wget -O "$1" "$2"; return $?
else else
curl -o "$1" "$2"; return $? curl -Lo "$1" "$2"; return $?
fi fi
} }
function __Restore() { function __Restore() {

View File

@ -15,7 +15,7 @@ function __DL() {
if [[ -x "$(command -v wget)" ]]; then if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $? wget -O "$1" "$2"; return $?
else else
curl -o "$1" "$2"; return $? curl -Lo "$1" "$2"; return $?
fi fi
} }
if [[ -z "$cache" ]] || [[ ! -f "$cache/Vanilla-$version.jar" ]]; then if [[ -z "$cache" ]] || [[ ! -f "$cache/Vanilla-$version.jar" ]]; then

View File

@ -30,13 +30,13 @@
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId> <artifactId>GalaxiEngine</artifactId>
<version>21w24a</version> <version>21w26a</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUI</artifactId> <artifactId>GalaxiUI</artifactId>
<version>21w24a</version> <version>21w26a</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -293,19 +293,24 @@ public class SubCreatorImpl {
templates.putAll(host.templates); templates.putAll(host.templates);
} }
private ObjectMap<String> build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException { private ObjectMap<String> build(File dir, ServerTemplate template, List<ServerTemplate> history, List<ServerTemplate> stack) throws SubCreatorException {
ObjectMap<String> server = new ObjectMap<String>(); ObjectMap<String> server = new ObjectMap<String>();
Version version = this.version; Version version = this.version;
HashMap<String, String> var = new HashMap<String, String>(); HashMap<String, String> var = new HashMap<String, String>();
boolean error = false; boolean error = false;
if (history.contains(template)) throw new IllegalStateException("Template import loop detected"); if (stack.contains(template)) throw new IllegalStateException("Infinite template import loop detected");
history.add(template); stack.add(template);
for (String other : template.getBuildOptions().getStringList("Import", new ArrayList<String>())) { for (String other : template.getBuildOptions().getStringList("Import", new ArrayList<String>())) {
if (templates.keySet().contains(other.toLowerCase())) { if (templates.containsKey(other.toLowerCase())) {
if (templates.get(other.toLowerCase()).isEnabled()) { final ServerTemplate ot = templates.get(other.toLowerCase());
if (version != null || !templates.get(other.toLowerCase()).requiresVersion()) { if (ot.isEnabled()) {
if (update == null || templates.get(other.toLowerCase()).canUpdate()) { if (version != null || !ot.requiresVersion()) {
server.setAll(this.build(dir, templates.get(other.toLowerCase()), history)); 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 { } else {
log.logger.warn.println("Skipping template that cannot be run in update mode: " + other); 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); log.logger.warn.println("Skipping missing template: " + other);
} }
} }
history.add(template);
stack.remove(template);
server.setAll(template.getConfigOptions()); server.setAll(template.getConfigOptions());
try { try {
log.logger.info.println("Loading" + ((template.isDynamic())?" Dynamic":"") + " Template: " + template.getDisplayName()); 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..."); 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); ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.host.getRawString("Git-Bash"), template.getBuildOptions().getRawString("Executable"))).directory(dir);
pb.environment().putAll(var); pb.environment().putAll(var);
process = pb.start();
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + ((version != null)?"-"+version.toString():"") + ".log"); log.file = new File(dir, "SubCreator-" + template.getName() + "-" + ((version != null)?"-"+version.toString():"") + ".log");
process = pb.start();
log.process = process; log.process = process;
log.start(); log.start();
@ -434,12 +441,15 @@ public class SubCreatorImpl {
ObjectMap<String> config; ObjectMap<String> config;
try { try {
config = build(dir, template, new LinkedList<>()); log.init();
config = build(dir, template, new LinkedList<>(), new LinkedList<>());
} catch (SubCreatorException e) { } catch (SubCreatorException e) {
config = null; config = null;
} catch (Exception e) { } catch (Exception e) {
config = null; config = null;
log.logger.error.println(e); log.logger.error.println(e);
} finally {
log.destroy();
} }
declaration.run(); declaration.run();

View File

@ -40,7 +40,7 @@ public class SubLoggerImpl {
static boolean logc = true; static boolean logc = true;
File file; File file;
private SubDataClient channel = null; private SubDataClient channel = null;
private LinkedList<Pair<String, String>> ccache = null; private LinkedList<Pair<Byte, String>> ccache = null;
private PrintWriter writer = null; private PrintWriter writer = null;
private boolean started = false; private boolean started = false;
private Thread out = null; private Thread out = null;
@ -70,13 +70,13 @@ public class SubLoggerImpl {
if (logn) { if (logn) {
if (this.address != null && channel != null && !channel.isClosed()) { if (this.address != null && channel != null && !channel.isClosed()) {
if (ccache != null) { if (ccache != null) {
for (Pair<String, String> val : ccache) channel.sendPacket(new PacketOutExLogMessage(this.address, val.key(), val.value())); for (Pair<Byte, String> val : ccache) channel.sendPacket(new PacketOutExLogMessage(this.address, val.key(), val.value()));
ccache = null; ccache = null;
} }
channel.sendPacket(new PacketOutExLogMessage(this.address, stream.getLevel().getName(), message)); channel.sendPacket(new PacketOutExLogMessage(this.address, stream.getLevel().getID(), message));
} else { } else {
if (ccache == null) ccache = new LinkedList<Pair<String, String>>(); if (ccache == null) ccache = new LinkedList<Pair<Byte, String>>();
ccache.add(new ContainedPair<>(stream.getLevel().getName(), message)); ccache.add(new ContainedPair<>(stream.getLevel().getID(), message));
} }
} }
@ -85,23 +85,10 @@ public class SubLoggerImpl {
}); });
} }
/** @SuppressWarnings("deprecation")
* Start Logger void init() {
*/
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();
if (logn) Util.isException(() -> { if (logn) Util.isException(() -> {
ExHost host = SubAPI.getInstance().getInternals();
channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel(); channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel();
channel.on.closed(new Callback<Pair<DisconnectReason, DataClient>>() { channel.on.closed(new Callback<Pair<DisconnectReason, DataClient>>() {
@Override @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 (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(); if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), SubAPI.getInstance().getAppInfo().getName() + "::Error_Spooler(" + name + ')')).start();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void start(InputStream in, boolean isErr) { private void start(InputStream in, boolean isErr) {
try { try {
@ -213,29 +213,28 @@ public class SubLoggerImpl {
try { try {
if (out != null) out.interrupt(); if (out != null) out.interrupt();
if (err != null) err.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) {} } catch (NullPointerException e) {}
} }
private void destroy() { void destroy() {
if (started) { if (channel != null && !channel.isClosed()) {
started = false; channel.sendPacket(new PacketOutExLogMessage(address));
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;
} }
channel = null;
} }
/** /**

View File

@ -106,6 +106,7 @@ public class SubServerImpl {
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) pb.environment().put("host", SubAPI.getInstance().getName()); 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("address", host.config.get().getMap("Settings").getRawString("Server-Bind"));
pb.environment().put("port", Integer.toString(getPort())); pb.environment().put("port", Integer.toString(getPort()));
logger.init();
process = pb.start(); process = pb.start();
falsestart = false; falsestart = false;
host.log.info.println("Now starting " + name); 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 (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)); ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExEditServer(this, PacketExEditServer.UpdateType.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart));
}
host.log.info.println(name + " has stopped"); host.log.info.println(name + " has stopped");
process = null; process = null;
command = null; command = null;

View File

@ -11,31 +11,27 @@ import java.util.UUID;
*/ */
public class PacketOutExLogMessage implements PacketObjectOut<Integer> { public class PacketOutExLogMessage implements PacketObjectOut<Integer> {
private UUID address; private UUID address;
private String level, line; private Byte level;
private boolean terminate; private String line;
/** /**
* New PacketInExLogMessage (Out) * New PacketInExLogMessage (Out)
*/ */
public PacketOutExLogMessage(UUID address, String level, String line) { public PacketOutExLogMessage(UUID address, byte level, String line) {
this.address = address; this.address = address;
this.level = level; this.level = level;
this.line = line; this.line = line;
this.terminate = false;
} }
/** /**
* New PacketInExLogMessage (Out) * New PacketInExLogMessage (Reset)
*/ */
public PacketOutExLogMessage(UUID address) { public PacketOutExLogMessage(UUID address) {
this.address = address; this.address = address;
this.terminate = true;
} }
@Override @Override
public ObjectMap<Integer> send(SubDataSender client) throws Exception { public ObjectMap<Integer> send(SubDataSender client) throws Exception {
if (terminate) client.getConnection().close();
ObjectMap<Integer> data = new ObjectMap<Integer>(); ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, address); data.set(0x0000, address);
if (level != null) data.set(0x0001, level); if (level != null) data.set(0x0001, level);

View File

@ -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.api.config.ServerInfo;
import net.md_5.bungee.conf.Configuration; import net.md_5.bungee.conf.Configuration;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
@ -128,7 +129,7 @@ public class SubProtocol extends SubDataProtocol {
} }
private Logger getLogger(int channel) { 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 @Override