mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-02-16 19:51:26 +01:00
Remove the archaic Executable type
Since it was virually no different from one, this has been replaced by a String. Additionally, the interpreter for start scripts can now be changed from cmd.exe to git bash on windows systems by using the `bash` or `sh` commands.
This commit is contained in:
parent
eafacf75c3
commit
1845e9d8f9
@ -1,75 +1,30 @@
|
|||||||
package net.ME1312.SubServers.Bungee.Host;
|
package net.ME1312.SubServers.Bungee.Host;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executable Variable Class
|
* Executable String Handler Class
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
public class Executable {
|
||||||
public class Executable implements Serializable {
|
private Executable() {}
|
||||||
private boolean isFile;
|
|
||||||
private File File;
|
|
||||||
private String Str;
|
|
||||||
/**
|
/**
|
||||||
* New Executable
|
* Format a command to be executed
|
||||||
*
|
*
|
||||||
* @param exe Executable String or File Path
|
* @param gitbash Git Bash location (optional)
|
||||||
|
* @param exec Executable String
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public Executable(String exe) {
|
public static String[] parse(String gitbash, String exec) {
|
||||||
if (Util.isNull(exe)) throw new NullPointerException();
|
String[] cmd;
|
||||||
if (new File(exe).exists()) {
|
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
|
||||||
isFile = true;
|
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
|
||||||
File = new File(exe);
|
exec = "\"" + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lic \"" +
|
||||||
Str = exe;
|
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + "\"";
|
||||||
|
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
||||||
} else {
|
} else {
|
||||||
isFile = false;
|
cmd = new String[]{"sh", "-lic", exec};
|
||||||
File = null;
|
|
||||||
Str = exe;
|
|
||||||
}
|
}
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* New Executable
|
|
||||||
*
|
|
||||||
* @param path File Path
|
|
||||||
*/
|
|
||||||
public Executable(File path) {
|
|
||||||
if (Util.isNull(path)) throw new NullPointerException();
|
|
||||||
isFile = true;
|
|
||||||
File = path;
|
|
||||||
Str = path.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String String;
|
|
||||||
if (isFile) {
|
|
||||||
String = File.toString();
|
|
||||||
} else {
|
|
||||||
String = Str;
|
|
||||||
}
|
|
||||||
return String;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the Executable String is a file
|
|
||||||
*
|
|
||||||
* @return File Status
|
|
||||||
*/
|
|
||||||
public boolean isFile() {
|
|
||||||
return isFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Executable File
|
|
||||||
*
|
|
||||||
* @return File or Null if Executable isn't a file
|
|
||||||
*/
|
|
||||||
public File toFile() {
|
|
||||||
return File;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package net.ME1312.SubServers.Bungee.Host.External;
|
|||||||
|
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
||||||
import net.ME1312.SubServers.Bungee.Host.Executable;
|
|
||||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||||
@ -144,7 +143,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
||||||
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
|
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
|
||||||
SubServer server = new ExternalSubServer(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
SubServer server = new ExternalSubServer(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
||||||
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
||||||
|
@ -110,7 +110,7 @@ public class ExternalSubCreator extends SubCreator {
|
|||||||
server.setAll(config);
|
server.setAll(config);
|
||||||
|
|
||||||
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), fport, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"),
|
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), fport, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"),
|
||||||
new Executable(server.getRawString("Executable")), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
|
server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
|
||||||
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
|
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
|
||||||
for (String group : server.getStringList("Group")) subserver.addGroup(group);
|
for (String group : server.getStringList("Group")) subserver.addGroup(group);
|
||||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||||
|
@ -28,7 +28,7 @@ public class ExternalSubServer extends SubServerContainer {
|
|||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private Container<Boolean> log;
|
private Container<Boolean> log;
|
||||||
private String dir;
|
private String dir;
|
||||||
protected Executable exec;
|
protected String exec;
|
||||||
private String stopcmd;
|
private String stopcmd;
|
||||||
private StopAction stopaction;
|
private StopAction stopaction;
|
||||||
private LinkedList<LoggedCommand> history;
|
private LinkedList<LoggedCommand> history;
|
||||||
@ -52,7 +52,7 @@ public class ExternalSubServer extends SubServerContainer {
|
|||||||
* @param restricted Restricted Status
|
* @param restricted Restricted Status
|
||||||
* @throws InvalidServerException
|
* @throws InvalidServerException
|
||||||
*/
|
*/
|
||||||
public ExternalSubServer(ExternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
public ExternalSubServer(ExternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
||||||
super(host, name, port, motd, hidden, restricted);
|
super(host, name, port, motd, hidden, restricted);
|
||||||
if (Util.isNull(host, name, enabled, port, motd, log, stopcmd, hidden, restricted)) throw new NullPointerException();
|
if (Util.isNull(host, name, enabled, port, motd, log, stopcmd, hidden, restricted)) throw new NullPointerException();
|
||||||
this.host = host;
|
this.host = host;
|
||||||
@ -319,7 +319,7 @@ public class ExternalSubServer extends SubServerContainer {
|
|||||||
case "exec":
|
case "exec":
|
||||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||||
waitFor(() -> host.getSubServer(getName()), null);
|
waitFor(() -> host.getSubServer(getName()), null);
|
||||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), new Executable(value.asRawString()), getStopCommand(), isHidden(), isRestricted());
|
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), value.asRawString(), getStopCommand(), isHidden(), isRestricted());
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", value.asRawString());
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", value.asRawString());
|
||||||
@ -506,7 +506,7 @@ public class ExternalSubServer extends SubServerContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Executable getExecutable() {
|
public String getExecutable() {
|
||||||
return exec;
|
return exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,14 +241,14 @@ public abstract class Host implements ExtraDataHandler {
|
|||||||
* @param motd Motd of the Server
|
* @param motd Motd of the Server
|
||||||
* @param log Logging Status
|
* @param log Logging Status
|
||||||
* @param directory Directory
|
* @param directory Directory
|
||||||
* @param executable Executable
|
* @param executable Executable String
|
||||||
* @param stopcmd Command to Stop the Server
|
* @param stopcmd Command to Stop the Server
|
||||||
* @param hidden if the server should be hidden from players
|
* @param hidden if the server should be hidden from players
|
||||||
* @param restricted Players will need a permission to join if true
|
* @param restricted Players will need a permission to join if true
|
||||||
* @return The SubServer
|
* @return The SubServer
|
||||||
* @throws InvalidServerException
|
* @throws InvalidServerException
|
||||||
*/
|
*/
|
||||||
public abstract SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException;
|
public abstract SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a SubServer
|
* Adds a SubServer
|
||||||
@ -259,14 +259,14 @@ public abstract class Host implements ExtraDataHandler {
|
|||||||
* @param motd Motd of the Server
|
* @param motd Motd of the Server
|
||||||
* @param log Logging Status
|
* @param log Logging Status
|
||||||
* @param directory Directory
|
* @param directory Directory
|
||||||
* @param executable Executable
|
* @param executable Executable String
|
||||||
* @param stopcmd Command to Stop the Server
|
* @param stopcmd Command to Stop the Server
|
||||||
* @param hidden if the server should be hidden from players
|
* @param hidden if the server should be hidden from players
|
||||||
* @param restricted Players will need a permission to join if true
|
* @param restricted Players will need a permission to join if true
|
||||||
* @return The SubServer
|
* @return The SubServer
|
||||||
* @throws InvalidServerException
|
* @throws InvalidServerException
|
||||||
*/
|
*/
|
||||||
public SubServer addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
public SubServer addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
||||||
return addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
return addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package net.ME1312.SubServers.Bungee.Host.Internal;
|
|||||||
import com.dosse.upnp.UPnP;
|
import com.dosse.upnp.UPnP;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
||||||
import net.ME1312.SubServers.Bungee.Host.Executable;
|
|
||||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||||
@ -98,7 +97,7 @@ public class InternalHost extends Host {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
||||||
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
|
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
|
||||||
SubServer server = new InternalSubServer(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
SubServer server = new InternalSubServer(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
||||||
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
||||||
|
@ -58,6 +58,7 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException {
|
private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException {
|
||||||
YAMLSection server = new YAMLSection();
|
YAMLSection server = new YAMLSection();
|
||||||
Version version = this.version;
|
Version version = this.version;
|
||||||
|
List<String> args = new LinkedList<String>();
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
if (history.contains(template)) throw new IllegalStateException("Template Import loop detected");
|
if (history.contains(template)) throw new IllegalStateException("Template Import loop detected");
|
||||||
history.add(template);
|
history.add(template);
|
||||||
@ -81,28 +82,34 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
try {
|
try {
|
||||||
System.out.println(name + File.separator + "Creator > Loading Template: " + template.getDisplayName());
|
System.out.println(name + File.separator + "Creator > Loading Template: " + template.getDisplayName());
|
||||||
Util.copyDirectory(template.getDirectory(), dir);
|
Util.copyDirectory(template.getDirectory(), dir);
|
||||||
if (template.getType() == ServerType.FORGE || template.getType() == ServerType.SPONGE) {
|
switch (template.getType()) {
|
||||||
System.out.println(name + File.separator + "Creator > Searching Versions...");
|
case SPONGE:
|
||||||
YAMLSection spversionmanifest = new YAMLSection(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));
|
case FORGE:
|
||||||
|
System.out.println(name + File.separator + "Creator > Searching Versions...");
|
||||||
|
YAMLSection spversionmanifest = new YAMLSection(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));
|
||||||
|
|
||||||
YAMLSection spprofile = null;
|
YAMLSection spprofile = null;
|
||||||
Version spversion = null;
|
Version spversion = null;
|
||||||
for (YAMLSection profile : spversionmanifest.getSectionList("versions")) {
|
for (YAMLSection profile : spversionmanifest.getSectionList("versions")) {
|
||||||
if (profile.getSection("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
|
if (profile.getSection("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
|
||||||
spprofile = profile;
|
spprofile = profile;
|
||||||
spversion = new Version(profile.getRawString("version"));
|
spversion = new Version(profile.getRawString("version"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
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());
|
System.out.println(name + File.separator + "Creator > Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"');
|
||||||
System.out.println(name + File.separator + "Creator > 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.getSection("dependencies").getRawString("minecraft") + '-' + spprofile.getSection("dependencies").getRawString("forge"));
|
Version mcfversion = new Version(spprofile.getSection("dependencies").getRawString("minecraft") + '-' + spprofile.getSection("dependencies").getRawString("forge"));
|
||||||
System.out.println(name + File.separator + "Creator > Found \"forge-" + mcfversion.toString() + '"');
|
System.out.println(name + File.separator + "Creator > Found \"forge-" + mcfversion.toString() + '"');
|
||||||
|
|
||||||
version = new Version(mcfversion.toString() + " " + spversion.toString());
|
args.add(mcfversion.toString());
|
||||||
} else version = new Version(spversion.toString());
|
}
|
||||||
|
args.add(spversion.toString());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
args.add(version.toString());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -113,15 +120,15 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
if (template.getBuildOptions().getBoolean("Use-Cache", true)) {
|
if (template.getBuildOptions().getBoolean("Use-Cache", true)) {
|
||||||
cache = new UniversalFile(host.plugin.dir, "SubServers:Cache:Templates:" + template.getName());
|
cache = new UniversalFile(host.plugin.dir, "SubServers:Cache:Templates:" + template.getName());
|
||||||
cache.mkdirs();
|
cache.mkdirs();
|
||||||
|
args.add('\"' + cache.toString().replace(File.separatorChar, '/') + '\"');
|
||||||
} else {
|
} else {
|
||||||
cache = null;
|
cache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String command = "bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + ((cache == null)?"":" \""+cache.toString().replace(File.separatorChar, '/')+'\"');
|
String command = "bash \"" + template.getBuildOptions().getRawString("Shell-Location") + '\"';
|
||||||
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
|
for (String arg : args) command += ' ' + arg;
|
||||||
String bash = InternalSubCreator.this.gitBash + ((InternalSubCreator.this.gitBash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe";
|
|
||||||
command = "cmd.exe /c \"\"" + bash + "\" --login -i -c \"" + command.replace("\"", "\\\"") + "\"\"";
|
if (System.getProperty("os.name").toLowerCase().indexOf("win") < 0 && template.getBuildOptions().contains("Permission")) {
|
||||||
} else if (template.getBuildOptions().contains("Permission")) {
|
|
||||||
try {
|
try {
|
||||||
Process process = Runtime.getRuntime().exec("chmod " + template.getBuildOptions().getRawString("Permission") + ' ' + template.getBuildOptions().getRawString("Shell-Location"), null, dir);
|
Process process = Runtime.getRuntime().exec("chmod " + template.getBuildOptions().getRawString("Permission") + ' ' + template.getBuildOptions().getRawString("Shell-Location"), null, dir);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
@ -136,7 +143,7 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println(name + File.separator + "Creator > Launching " + template.getBuildOptions().getRawString("Shell-Location"));
|
System.out.println(name + File.separator + "Creator > Launching " + template.getBuildOptions().getRawString("Shell-Location"));
|
||||||
process = Runtime.getRuntime().exec(command, null, dir);
|
process = Runtime.getRuntime().exec(Executable.parse(gitBash, command), null, dir);
|
||||||
log.log.set(host.plugin.config.get().getSection("Settings").getBoolean("Log-Creator"));
|
log.log.set(host.plugin.config.get().getSection("Settings").getBoolean("Log-Creator"));
|
||||||
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString().replace(" ", "@") + ".log");
|
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString().replace(" ", "@") + ".log");
|
||||||
log.process = process;
|
log.process = process;
|
||||||
@ -210,7 +217,7 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
server.setAll(config);
|
server.setAll(config);
|
||||||
|
|
||||||
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"),
|
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"),
|
||||||
new Executable(server.getRawString("Executable")), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
|
server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
|
||||||
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
|
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
|
||||||
for (String group : server.getStringList("Group")) subserver.addGroup(group);
|
for (String group : server.getStringList("Group")) subserver.addGroup(group);
|
||||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||||
@ -266,6 +273,7 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
if (Util.isNull(host, gitBash)) throw new NullPointerException();
|
if (Util.isNull(host, gitBash)) throw new NullPointerException();
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.gitBash = (System.getenv("ProgramFiles(x86)") == null)?Pattern.compile("%(ProgramFiles)\\(x86\\)%", Pattern.CASE_INSENSITIVE).matcher(gitBash).replaceAll("%$1%"):gitBash;
|
this.gitBash = (System.getenv("ProgramFiles(x86)") == null)?Pattern.compile("%(ProgramFiles)\\(x86\\)%", Pattern.CASE_INSENSITIVE).matcher(gitBash).replaceAll("%$1%"):gitBash;
|
||||||
|
if (this.gitBash.endsWith(File.pathSeparator)) this.gitBash = this.gitBash.substring(0, this.gitBash.length() - 1);
|
||||||
this.thread = new TreeMap<String, CreatorTask>();
|
this.thread = new TreeMap<String, CreatorTask>();
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class InternalSubServer extends SubServerContainer {
|
|||||||
private Container<Boolean> log;
|
private Container<Boolean> log;
|
||||||
private String dir;
|
private String dir;
|
||||||
private File directory;
|
private File directory;
|
||||||
private Executable executable;
|
private String executable;
|
||||||
private String stopcmd;
|
private String stopcmd;
|
||||||
private StopAction stopaction;
|
private StopAction stopaction;
|
||||||
private LinkedList<LoggedCommand> history;
|
private LinkedList<LoggedCommand> history;
|
||||||
@ -58,7 +58,7 @@ public class InternalSubServer extends SubServerContainer {
|
|||||||
* @param restricted Restricted Status
|
* @param restricted Restricted Status
|
||||||
* @throws InvalidServerException
|
* @throws InvalidServerException
|
||||||
*/
|
*/
|
||||||
public InternalSubServer(InternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
public InternalSubServer(InternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
||||||
super(host, name, port, motd, hidden, restricted);
|
super(host, name, port, motd, hidden, restricted);
|
||||||
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted)) throw new NullPointerException();
|
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted)) throw new NullPointerException();
|
||||||
this.host = host;
|
this.host = host;
|
||||||
@ -118,7 +118,7 @@ public class InternalSubServer extends SubServerContainer {
|
|||||||
private void run() {
|
private void run() {
|
||||||
allowrestart = true;
|
allowrestart = true;
|
||||||
try {
|
try {
|
||||||
process = Runtime.getRuntime().exec(executable.toString(), null, directory);
|
process = Runtime.getRuntime().exec(Executable.parse(host.getCreator().getBashDirectory(), executable), null, directory);
|
||||||
System.out.println("SubServers > Now starting " + getName());
|
System.out.println("SubServers > Now starting " + getName());
|
||||||
logger.process = process;
|
logger.process = process;
|
||||||
logger.start();
|
logger.start();
|
||||||
@ -394,7 +394,7 @@ public class InternalSubServer extends SubServerContainer {
|
|||||||
stop(player);
|
stop(player);
|
||||||
waitFor();
|
waitFor();
|
||||||
}
|
}
|
||||||
executable = new Executable(value.asRawString());
|
executable = value.asRawString();
|
||||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", value.asRawString());
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", value.asRawString());
|
||||||
this.host.plugin.config.save();
|
this.host.plugin.config.save();
|
||||||
@ -570,7 +570,7 @@ public class InternalSubServer extends SubServerContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Executable getExecutable() {
|
public String getExecutable() {
|
||||||
return executable;
|
return executable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ public interface SubServer extends Server {
|
|||||||
*
|
*
|
||||||
* @return Executable String
|
* @return Executable String
|
||||||
*/
|
*/
|
||||||
Executable getExecutable();
|
String getExecutable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grab the Command to Stop the Server
|
* Grab the Command to Stop the Server
|
||||||
|
@ -124,7 +124,7 @@ public abstract class SubServerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Executable getExecutable() {
|
public String getExecutable() {
|
||||||
return SubServerController.this.getExecutable();
|
return SubServerController.this.getExecutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ public abstract class SubServerController {
|
|||||||
*
|
*
|
||||||
* @return Executable String
|
* @return Executable String
|
||||||
*/
|
*/
|
||||||
public abstract Executable getExecutable();
|
public abstract String getExecutable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grab the Command to Stop the Server
|
* Grab the Command to Stop the Server
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Bungee.Host.Executable;
|
|
||||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||||
import net.ME1312.SubServers.Bungee.Library.Callback;
|
import net.ME1312.SubServers.Bungee.Library.Callback;
|
||||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||||
@ -22,7 +21,7 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
private int port;
|
private int port;
|
||||||
private boolean log;
|
private boolean log;
|
||||||
private String directory;
|
private String directory;
|
||||||
private Executable executable;
|
private String executable;
|
||||||
private String stopcmd;
|
private String stopcmd;
|
||||||
private UUID running;
|
private UUID running;
|
||||||
private String id;
|
private String id;
|
||||||
@ -42,7 +41,7 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
* @param executable Executable
|
* @param executable Executable
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketExAddServer(String name, boolean enabled, int port, boolean log, String directory, Executable executable, String stopcmd, UUID running, Callback<YAMLSection>... callback) {
|
public PacketExAddServer(String name, boolean enabled, int port, boolean log, String directory, String executable, String stopcmd, UUID running, Callback<YAMLSection>... callback) {
|
||||||
if (Util.isNull(name, enabled, log, directory, executable, callback)) throw new NullPointerException();
|
if (Util.isNull(name, enabled, log, directory, executable, callback)) throw new NullPointerException();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
@ -66,7 +65,7 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
server.set("port", port);
|
server.set("port", port);
|
||||||
server.set("log", log);
|
server.set("log", log);
|
||||||
server.set("dir", directory);
|
server.set("dir", directory);
|
||||||
server.set("exec", executable.toString());
|
server.set("exec", executable);
|
||||||
server.set("stopcmd", stopcmd);
|
server.set("stopcmd", stopcmd);
|
||||||
if (running != null) server.set("running", running.toString());
|
if (running != null) server.set("running", running.toString());
|
||||||
data.set("server", server);
|
data.set("server", server);
|
||||||
|
@ -419,7 +419,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
edits.set("log", config.get().getSection("Servers").getSection(name).getBoolean("Log"));
|
edits.set("log", config.get().getSection("Servers").getSection(name).getBoolean("Log"));
|
||||||
if (!config.get().getSection("Servers").getSection(name).getRawString("Directory").equals(server.getPath()))
|
if (!config.get().getSection("Servers").getSection(name).getRawString("Directory").equals(server.getPath()))
|
||||||
edits.set("dir", config.get().getSection("Servers").getSection(name).getRawString("Directory"));
|
edits.set("dir", config.get().getSection("Servers").getSection(name).getRawString("Directory"));
|
||||||
if (!new Executable(config.get().getSection("Servers").getSection(name).getRawString("Executable")).toString().equals(server.getExecutable().toString()))
|
if (!config.get().getSection("Servers").getSection(name).getRawString("Executable").equals(server.getExecutable()))
|
||||||
edits.set("exec", config.get().getSection("Servers").getSection(name).getRawString("Executable"));
|
edits.set("exec", config.get().getSection("Servers").getSection(name).getRawString("Executable"));
|
||||||
if (!config.get().getSection("Servers").getSection(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
if (!config.get().getSection("Servers").getSection(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||||
edits.set("stop-cmd", config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"));
|
edits.set("stop-cmd", config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"));
|
||||||
@ -441,12 +441,12 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
!config.get().getSection("Servers").getSection(name).getString("Host").equalsIgnoreCase(server.getHost().getName()) ||
|
!config.get().getSection("Servers").getSection(name).getString("Host").equalsIgnoreCase(server.getHost().getName()) ||
|
||||||
config.get().getSection("Servers").getSection(name).getInt("Port") != server.getAddress().getPort() ||
|
config.get().getSection("Servers").getSection(name).getInt("Port") != server.getAddress().getPort() ||
|
||||||
!config.get().getSection("Servers").getSection(name).getRawString("Directory").equals(server.getPath()) ||
|
!config.get().getSection("Servers").getSection(name).getRawString("Directory").equals(server.getPath()) ||
|
||||||
!new Executable(config.get().getSection("Servers").getSection(name).getRawString("Executable")).toString().equals(server.getExecutable().toString())
|
!config.get().getSection("Servers").getSection(name).getRawString("Executable").equals(server.getExecutable())
|
||||||
) {
|
) {
|
||||||
if (server != null) server.getHost().forceRemoveSubServer(name);
|
if (server != null) server.getHost().forceRemoveSubServer(name);
|
||||||
server = this.hosts.get(config.get().getSection("Servers").getSection(name).getString("Host").toLowerCase()).addSubServer(name, config.get().getSection("Servers").getSection(name).getBoolean("Enabled"),
|
server = this.hosts.get(config.get().getSection("Servers").getSection(name).getString("Host").toLowerCase()).addSubServer(name, config.get().getSection("Servers").getSection(name).getBoolean("Enabled"),
|
||||||
config.get().getSection("Servers").getSection(name).getInt("Port"), config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&'), config.get().getSection("Servers").getSection(name).getBoolean("Log"),
|
config.get().getSection("Servers").getSection(name).getInt("Port"), config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&'), config.get().getSection("Servers").getSection(name).getBoolean("Log"),
|
||||||
config.get().getSection("Servers").getSection(name).getRawString("Directory"), new Executable(config.get().getSection("Servers").getSection(name).getRawString("Executable")), config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"),
|
config.get().getSection("Servers").getSection(name).getRawString("Directory"), config.get().getSection("Servers").getSection(name).getRawString("Executable"), config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"),
|
||||||
config.get().getSection("Servers").getSection(name).getBoolean("Hidden"), config.get().getSection("Servers").getSection(name).getBoolean("Restricted"));
|
config.get().getSection("Servers").getSection(name).getBoolean("Hidden"), config.get().getSection("Servers").getSection(name).getBoolean("Restricted"));
|
||||||
} else { // Server doesn't need to reset
|
} else { // Server doesn't need to reset
|
||||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Enabled") != server.isEnabled())
|
if (config.get().getSection("Servers").getSection(name).getBoolean("Enabled") != server.isEnabled())
|
||||||
|
@ -1,75 +1,30 @@
|
|||||||
package net.ME1312.SubServers.Host.Executable;
|
package net.ME1312.SubServers.Host.Executable;
|
||||||
|
|
||||||
import net.ME1312.Galaxi.Library.Util;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executable Variable Class
|
* Executable String Handler Class
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
public class Executable {
|
||||||
public class Executable implements Serializable {
|
private Executable() {}
|
||||||
private boolean isFile;
|
|
||||||
private File File;
|
|
||||||
private String Str;
|
|
||||||
/**
|
/**
|
||||||
* New Executable
|
* Format a command to be executed
|
||||||
*
|
*
|
||||||
* @param exe Executable String or File Path
|
* @param gitbash Git Bash location (optional)
|
||||||
|
* @param exec Executable String
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public Executable(String exe) {
|
public static String[] parse(String gitbash, String exec) {
|
||||||
if (Util.isNull(exe)) throw new NullPointerException();
|
String[] cmd;
|
||||||
if (new File(exe).exists()) {
|
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
|
||||||
isFile = true;
|
if (gitbash != null && (exec.startsWith("bash ") || exec.startsWith("sh ")))
|
||||||
File = new File(exe);
|
exec = "\"" + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lic \"" +
|
||||||
Str = exe;
|
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + "\"";
|
||||||
|
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
||||||
} else {
|
} else {
|
||||||
isFile = false;
|
cmd = new String[]{"sh", "-lic", exec};
|
||||||
File = null;
|
|
||||||
Str = exe;
|
|
||||||
}
|
}
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* New Executable
|
|
||||||
*
|
|
||||||
* @param path File Path
|
|
||||||
*/
|
|
||||||
public Executable(File path) {
|
|
||||||
if (Util.isNull(path)) throw new NullPointerException();
|
|
||||||
isFile = true;
|
|
||||||
File = path;
|
|
||||||
Str = path.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String String;
|
|
||||||
if (isFile) {
|
|
||||||
String = File.toString();
|
|
||||||
} else {
|
|
||||||
String = Str;
|
|
||||||
}
|
|
||||||
return String;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the Executable String is a file
|
|
||||||
*
|
|
||||||
* @return File Status
|
|
||||||
*/
|
|
||||||
public boolean isFile() {
|
|
||||||
return isFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Executable File
|
|
||||||
*
|
|
||||||
* @return File or Null if Executable isn't a file
|
|
||||||
*/
|
|
||||||
public File toFile() {
|
|
||||||
return File;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -202,6 +202,7 @@ public class SubCreator {
|
|||||||
private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException {
|
private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException {
|
||||||
YAMLSection server = new YAMLSection();
|
YAMLSection server = new YAMLSection();
|
||||||
Version version = this.version;
|
Version version = this.version;
|
||||||
|
List<String> args = new LinkedList<String>();
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
if (history.contains(template)) throw new IllegalStateException("Template Import loop detected");
|
if (history.contains(template)) throw new IllegalStateException("Template Import loop detected");
|
||||||
history.add(template);
|
history.add(template);
|
||||||
@ -228,31 +229,37 @@ public class SubCreator {
|
|||||||
log.logger.info.println("Loading Template: " + template.getDisplayName());
|
log.logger.info.println("Loading Template: " + template.getDisplayName());
|
||||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Loading Template: " + template.getDisplayName()));
|
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Loading Template: " + template.getDisplayName()));
|
||||||
Util.copyDirectory(template.getDirectory(), dir);
|
Util.copyDirectory(template.getDirectory(), dir);
|
||||||
if (template.getType() == ServerType.FORGE || template.getType() == ServerType.SPONGE) {
|
switch (template.getType()) {
|
||||||
log.logger.info.println("Searching Versions...");
|
case SPONGE:
|
||||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Searching Versions..."));
|
case FORGE:
|
||||||
YAMLSection spversionmanifest = new YAMLSection(new JSONObject("{\"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")))) + '}'));
|
log.logger.info.println("Searching Versions...");
|
||||||
|
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Searching Versions..."));
|
||||||
|
YAMLSection spversionmanifest = new YAMLSection(new JSONObject("{\"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")))) + '}'));
|
||||||
|
|
||||||
YAMLSection spprofile = null;
|
YAMLSection spprofile = null;
|
||||||
Version spversion = null;
|
Version spversion = null;
|
||||||
for (YAMLSection profile : spversionmanifest.getSectionList("versions")) {
|
for (YAMLSection profile : spversionmanifest.getSectionList("versions")) {
|
||||||
if (profile.getSection("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
|
if (profile.getSection("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
|
||||||
spprofile = profile;
|
spprofile = profile;
|
||||||
spversion = new Version(profile.getRawString("version"));
|
spversion = new Version(profile.getRawString("version"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
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());
|
log.logger.info.println("Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"');
|
||||||
log.logger.info.println("Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"');
|
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"'));
|
||||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "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.getSection("dependencies").getRawString("minecraft") + '-' + spprofile.getSection("dependencies").getRawString("forge"));
|
Version mcfversion = new Version(spprofile.getSection("dependencies").getRawString("minecraft") + '-' + spprofile.getSection("dependencies").getRawString("forge"));
|
||||||
log.logger.info.println("Found \"forge-" + mcfversion.toString() + '"');
|
log.logger.info.println("Found \"forge-" + mcfversion.toString() + '"');
|
||||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Found \"forge-" + mcfversion.toString() + '"'));
|
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Found \"forge-" + mcfversion.toString() + '"'));
|
||||||
|
|
||||||
version = new Version(mcfversion.toString() + " " + spversion.toString());
|
args.add(mcfversion.toString());
|
||||||
} else version = new Version(spversion.toString());
|
}
|
||||||
|
args.add(spversion.toString());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
args.add(version.toString());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.logger.error.println(e);
|
log.logger.error.println(e);
|
||||||
@ -263,15 +270,15 @@ public class SubCreator {
|
|||||||
if (template.getBuildOptions().getBoolean("Use-Cache", true)) {
|
if (template.getBuildOptions().getBoolean("Use-Cache", true)) {
|
||||||
cache = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Cache:Templates:" + template.getName());
|
cache = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Cache:Templates:" + template.getName());
|
||||||
cache.mkdirs();
|
cache.mkdirs();
|
||||||
|
args.add("\"" + cache.toString().replace(File.separatorChar, '/') + '\"');
|
||||||
} else {
|
} else {
|
||||||
cache = null;
|
cache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String command = "bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + ((cache == null)?"":" \""+cache.toString().replace(File.separatorChar, '/')+'\"');
|
String command = "bash \"" + template.getBuildOptions().getRawString("Shell-Location") + '\"';
|
||||||
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
|
for (String arg : args) command += ' ' + arg;
|
||||||
String bash = host.host.getRawString("Git-Bash") + ((host.host.getRawString("Git-Bash").endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe";
|
|
||||||
command = "cmd.exe /c \"\"" + bash + "\" --login -i -c \"" + command.replace("\"", "\\\"") + "\"\"";
|
if (System.getProperty("os.name").toLowerCase().indexOf("win") < 0 && template.getBuildOptions().contains("Permission")) {
|
||||||
} else if (template.getBuildOptions().contains("Permission")) {
|
|
||||||
try {
|
try {
|
||||||
Process process = Runtime.getRuntime().exec("chmod " + template.getBuildOptions().getRawString("Permission") + ' ' + template.getBuildOptions().getRawString("Shell-Location"), null, dir);
|
Process process = Runtime.getRuntime().exec("chmod " + template.getBuildOptions().getRawString("Permission") + ' ' + template.getBuildOptions().getRawString("Shell-Location"), null, dir);
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
@ -289,7 +296,7 @@ public class SubCreator {
|
|||||||
try {
|
try {
|
||||||
log.logger.info.println("Launching " + template.getBuildOptions().getRawString("Shell-Location"));
|
log.logger.info.println("Launching " + template.getBuildOptions().getRawString("Shell-Location"));
|
||||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Launching " + template.getBuildOptions().getRawString("Shell-Location")));
|
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Launching " + template.getBuildOptions().getRawString("Shell-Location")));
|
||||||
process = Runtime.getRuntime().exec(command, null, dir);
|
process = Runtime.getRuntime().exec(Executable.parse(host.host.getRawString("Git-Bash"), command), null, dir);
|
||||||
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString().replace(" ", "@") + ".log");
|
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString().replace(" ", "@") + ".log");
|
||||||
log.process = process;
|
log.process = process;
|
||||||
log.start();
|
log.start();
|
||||||
|
@ -26,7 +26,7 @@ public class SubServer {
|
|||||||
private Container<Boolean> log;
|
private Container<Boolean> log;
|
||||||
private String dir;
|
private String dir;
|
||||||
private File directory;
|
private File directory;
|
||||||
private Executable executable;
|
private String executable;
|
||||||
private Process process;
|
private Process process;
|
||||||
private SubLogger logger;
|
private SubLogger logger;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
@ -47,7 +47,7 @@ public class SubServer {
|
|||||||
* @param stopcmd Stop Command
|
* @param stopcmd Stop Command
|
||||||
* @throws InvalidServerException
|
* @throws InvalidServerException
|
||||||
*/
|
*/
|
||||||
public SubServer(ExHost host, String name, boolean enabled, int port, boolean log, String directory, Executable executable, String stopcmd) throws InvalidServerException {
|
public SubServer(ExHost host, String name, boolean enabled, int port, boolean log, String directory, String executable, String stopcmd) throws InvalidServerException {
|
||||||
if (Util.isNull(host, name, enabled, log, directory, executable)) throw new NullPointerException();
|
if (Util.isNull(host, name, enabled, log, directory, executable)) throw new NullPointerException();
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -107,7 +107,7 @@ public class SubServer {
|
|||||||
boolean falsestart = true;
|
boolean falsestart = true;
|
||||||
allowrestart = true;
|
allowrestart = true;
|
||||||
try {
|
try {
|
||||||
process = Runtime.getRuntime().exec(executable.toString(), null, directory);
|
process = Runtime.getRuntime().exec(Executable.parse(host.host.getRawString("Git-Bash"), executable), null, directory);
|
||||||
falsestart = false;
|
falsestart = false;
|
||||||
host.log.info.println("Now starting " + name);
|
host.log.info.println("Now starting " + name);
|
||||||
logger.process = process;
|
logger.process = process;
|
||||||
|
@ -5,7 +5,6 @@ import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
|||||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||||
import net.ME1312.Galaxi.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.Galaxi.Library.Version.Version;
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
import net.ME1312.SubServers.Host.Executable.Executable;
|
|
||||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||||
@ -71,7 +70,7 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
host.subdata.sendPacket(new PacketExAddServer(0, "Server Already Added", (data.contains("id"))?data.getRawString("id"):null));
|
host.subdata.sendPacket(new PacketExAddServer(0, "Server Already Added", (data.contains("id"))?data.getRawString("id"):null));
|
||||||
} else {
|
} else {
|
||||||
SubServer server = new SubServer(host, data.getSection("server").getRawString("name"), data.getSection("server").getBoolean("enabled"), data.getSection("server").getInt("port"), data.getSection("server").getBoolean("log"),
|
SubServer server = new SubServer(host, data.getSection("server").getRawString("name"), data.getSection("server").getBoolean("enabled"), data.getSection("server").getInt("port"), data.getSection("server").getBoolean("log"),
|
||||||
data.getSection("server").getRawString("dir"), new Executable(data.getSection("server").getRawString("exec")), data.getSection("server").getRawString("stopcmd"));
|
data.getSection("server").getRawString("dir"), data.getSection("server").getRawString("exec"), data.getSection("server").getRawString("stopcmd"));
|
||||||
host.servers.put(data.getSection("server").getRawString("name").toLowerCase(), server);
|
host.servers.put(data.getSection("server").getRawString("name").toLowerCase(), server);
|
||||||
if (UPnP.isUPnPAvailable() && host.config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getPort());
|
if (UPnP.isUPnPAvailable() && host.config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getPort());
|
||||||
log.info.println("Added SubServer: " + data.getSection("server").getRawString("name"));
|
log.info.println("Added SubServer: " + data.getSection("server").getRawString("name"));
|
||||||
|
Loading…
Reference in New Issue
Block a user