mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-29 05:36:13 +01:00
Make Log-Creator
a per-host option
This commit is contained in:
parent
eb70ebaeea
commit
4792e5f8b1
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Host.External;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
@ -32,7 +33,6 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
private InetAddress address;
|
||||
private SubCreator creator;
|
||||
private String directory;
|
||||
protected NamedContainer<Integer, Integer> range;
|
||||
protected NamedContainer<Boolean, Client> client;
|
||||
private LinkedList<PacketOut> queue;
|
||||
private boolean clean;
|
||||
@ -41,24 +41,24 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
/**
|
||||
* Creates an External Host
|
||||
*
|
||||
* @param plugin Plugin
|
||||
* @param name Name
|
||||
* @param enabled Enabled Status
|
||||
* @param address Address
|
||||
* @param directory Directory
|
||||
* @param gitBash Git Bash Location
|
||||
* @param plugin SubServers Internals
|
||||
* @param name The Name of your Host
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
||||
* @param enabled If your host is Enabled
|
||||
* @param address The address of your Host
|
||||
* @param directory The runtime directory of your Host
|
||||
* @param gitBash The Git Bash directory
|
||||
*/
|
||||
public ExternalHost(SubPlugin plugin, String name, Boolean enabled, InetAddress address, String directory, NamedContainer<Integer, Integer> range, String gitBash) {
|
||||
super(plugin, name, enabled, address, directory, range, gitBash);
|
||||
if (Util.isNull(plugin, name, enabled, address, directory, gitBash)) throw new NullPointerException();
|
||||
public ExternalHost(SubPlugin plugin, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) {
|
||||
super(plugin, name, enabled, ports, log, address, directory, gitBash);
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
this.address = address;
|
||||
this.client = new NamedContainer<Boolean, Client>(false, null);
|
||||
this.creator = new ExternalSubCreator(this, gitBash);
|
||||
this.creator = new ExternalSubCreator(this, ports, log, gitBash);
|
||||
this.directory = directory;
|
||||
this.range = range;
|
||||
this.queue = new LinkedList<PacketOut>();
|
||||
this.clean = false;
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package net.ME1312.SubServers.Bungee.Host.External;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Host.Internal.InternalSubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Library.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLConfig;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExConfigureHost;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExCreateServer;
|
||||
@ -23,6 +25,8 @@ import java.util.*;
|
||||
public class ExternalSubCreator extends SubCreator {
|
||||
private HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
|
||||
private ExternalHost host;
|
||||
private Range<Integer> ports;
|
||||
private Container<Boolean> log;
|
||||
private String gitBash;
|
||||
private TreeMap<String, NamedContainer<Integer, ExternalSubLogger>> thread;
|
||||
|
||||
@ -30,11 +34,16 @@ public class ExternalSubCreator extends SubCreator {
|
||||
* Creates an External SubCreator
|
||||
*
|
||||
* @param host Host
|
||||
* @param gitBash Git Bash
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether SubCreator should log to console
|
||||
* @param gitBash The Git Bash directory
|
||||
*/
|
||||
public ExternalSubCreator(ExternalHost host, String gitBash) {
|
||||
if (Util.isNull(host, gitBash)) throw new NullPointerException();
|
||||
public ExternalSubCreator(ExternalHost host, Range<Integer> ports, boolean log, String gitBash) {
|
||||
if (!ports.hasLowerBound() || !ports.hasUpperBound()) throw new IllegalArgumentException("Port range is not bound");
|
||||
if (Util.isNull(host, ports, log, gitBash)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.ports = ports;
|
||||
this.log = new Container<Boolean>(log);
|
||||
this.gitBash = gitBash;
|
||||
this.thread = new TreeMap<String, NamedContainer<Integer, ExternalSubLogger>>();
|
||||
reload();
|
||||
@ -66,14 +75,16 @@ public class ExternalSubCreator extends SubCreator {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
|
||||
if (port == null) {
|
||||
Container<Integer> i = new Container<Integer>(host.range.name() - 1);
|
||||
Container<Integer> i = new Container<Integer>(ports.lowerEndpoint() - 1);
|
||||
port = Util.getNew(getAllReservedAddresses(), () -> {
|
||||
do {
|
||||
i.set(i.get() + 1);
|
||||
if (i.get() > host.range.get()) throw new IllegalStateException("There are no more ports available between " + host.range.name() + " and " + host.range.get());
|
||||
if (i.get() > ports.upperEndpoint()) throw new IllegalStateException("There are no more ports available in range: " + ports.toString());
|
||||
} while (!ports.contains(i.get()));
|
||||
return new InetSocketAddress(host.getAddress(), i.get());
|
||||
}).getPort();
|
||||
}
|
||||
ExternalSubLogger logger = new ExternalSubLogger(this, name + File.separator + "Creator", new Container<Boolean>(host.plugin.config.get().getSection("Settings").getBoolean("Log-Creator")), null);
|
||||
ExternalSubLogger logger = new ExternalSubLogger(this, name + File.separator + "Creator", log, null);
|
||||
thread.put(name.toLowerCase(), new NamedContainer<>(port, logger));
|
||||
|
||||
final int fport = port;
|
||||
@ -206,6 +217,17 @@ public class ExternalSubCreator extends SubCreator {
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Range getPortRange() {
|
||||
return ports;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPortRange(Range<Integer> value) {
|
||||
if (!value.hasLowerBound() || !value.hasUpperBound()) throw new IllegalArgumentException("Port range is not bound");
|
||||
ports = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBashDirectory() {
|
||||
return gitBash;
|
||||
@ -227,6 +249,17 @@ public class ExternalSubCreator extends SubCreator {
|
||||
return this.thread.get(name.toLowerCase()).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogging() {
|
||||
return log.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogging(boolean value) {
|
||||
if (Util.isNull(value)) throw new NullPointerException();
|
||||
log.set(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getReservedNames() {
|
||||
return new ArrayList<String>(thread.keySet());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLValue;
|
||||
@ -29,14 +30,17 @@ public abstract class Host implements ExtraDataHandler {
|
||||
*
|
||||
* @param plugin SubServers Internals
|
||||
* @param name The Name of your Host
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
||||
* @param enabled If your host is Enabled
|
||||
* @param address The address of your Host
|
||||
* @param directory The runtime directory of your Host
|
||||
* @param range The range of ports to auto-select from
|
||||
* @param gitBash The Git Bash directory
|
||||
*/
|
||||
public Host(SubPlugin plugin, String name, Boolean enabled, InetAddress address, String directory, NamedContainer<Integer, Integer> range, String gitBash) {
|
||||
public Host(SubPlugin plugin, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) {
|
||||
if (name.contains(" ")) throw new InvalidHostException("Host names cannot have spaces: " + name);
|
||||
if (!ports.hasLowerBound() || !ports.hasUpperBound()) throw new InvalidHostException("Port range is not bound");
|
||||
if (Util.isNull(plugin, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
|
||||
signature = plugin.api.signAnonymousObject();
|
||||
SubDataServer.allowConnection(address.getHostAddress());
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.ME1312.SubServers.Bungee.Host.Internal;
|
||||
|
||||
import com.dosse.upnp.UPnP;
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
@ -8,7 +9,6 @@ import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
@ -29,30 +29,29 @@ public class InternalHost extends Host {
|
||||
private InetAddress address;
|
||||
private SubCreator creator;
|
||||
private String directory;
|
||||
protected NamedContainer<Integer, Integer> range;
|
||||
protected SubPlugin plugin;
|
||||
|
||||
/**
|
||||
* Creates an Internal Host
|
||||
*
|
||||
* @param plugin Plugin
|
||||
* @param name Name
|
||||
* @param enabled Enabled Status
|
||||
* @param address Address
|
||||
* @param directory Directory
|
||||
* @param gitBash Git Bash Location
|
||||
* @param plugin SubServers Internals
|
||||
* @param name The Name of your Host
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
||||
* @param enabled If your host is Enabled
|
||||
* @param address The address of your Host
|
||||
* @param directory The runtime directory of your Host
|
||||
* @param gitBash The Git Bash directory
|
||||
*/
|
||||
public InternalHost(SubPlugin plugin, String name, Boolean enabled, InetAddress address, String directory, NamedContainer<Integer, Integer> range, String gitBash) {
|
||||
super(plugin, name, enabled, address, directory, range, gitBash);
|
||||
public InternalHost(SubPlugin plugin, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) {
|
||||
super(plugin, name, enabled, ports, log, address, directory, gitBash);
|
||||
if (!DRM_ALLOW) throw new IllegalStateException("SubServers' hosting capabilities have been disabled by your provider");
|
||||
if (Util.isNull(plugin, name, enabled, address, directory, gitBash)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
this.address = address;
|
||||
this.creator = new InternalSubCreator(this, gitBash);
|
||||
this.creator = new InternalSubCreator(this, ports, log, gitBash);
|
||||
this.directory = directory;
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Host.Internal;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
@ -32,6 +33,8 @@ import java.util.regex.Pattern;
|
||||
public class InternalSubCreator extends SubCreator {
|
||||
private HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
|
||||
private InternalHost host;
|
||||
private Range<Integer> ports;
|
||||
private Container<Boolean> log;
|
||||
private String gitBash;
|
||||
private TreeMap<String, CreatorTask> thread;
|
||||
|
||||
@ -51,7 +54,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.log = new InternalSubLogger(null, this, name + File.separator + "Creator", new Container<Boolean>(false), null);
|
||||
this.log = new InternalSubLogger(null, this, name + File.separator + "Creator", InternalSubCreator.this.log, null);
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@ -144,8 +147,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
try {
|
||||
System.out.println(name + File.separator + "Creator > Launching " + template.getBuildOptions().getRawString("Shell-Location"));
|
||||
process = Runtime.getRuntime().exec(Executable.parse(gitBash, command), null, dir);
|
||||
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() + ".log");
|
||||
log.process = process;
|
||||
log.start();
|
||||
|
||||
@ -267,11 +269,16 @@ public class InternalSubCreator extends SubCreator {
|
||||
* Creates an Internal SubCreator
|
||||
*
|
||||
* @param host Host
|
||||
* @param gitBash Git Bash
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether SubCreator should log to console
|
||||
* @param gitBash The Git Bash directory
|
||||
*/
|
||||
public InternalSubCreator(InternalHost host, String gitBash) {
|
||||
if (Util.isNull(host, gitBash)) throw new NullPointerException();
|
||||
public InternalSubCreator(InternalHost host, Range<Integer> ports, boolean log, String gitBash) {
|
||||
if (!ports.hasLowerBound() || !ports.hasUpperBound()) throw new IllegalArgumentException("Port range is not bound");
|
||||
if (Util.isNull(host, ports, log, gitBash)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.ports = ports;
|
||||
this.log = new Container<Boolean>(log);
|
||||
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>();
|
||||
@ -305,10 +312,12 @@ public class InternalSubCreator extends SubCreator {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
|
||||
if (port == null) {
|
||||
Container<Integer> i = new Container<Integer>(host.range.name() - 1);
|
||||
Container<Integer> i = new Container<Integer>(ports.lowerEndpoint() - 1);
|
||||
port = Util.getNew(getAllReservedAddresses(), () -> {
|
||||
do {
|
||||
i.set(i.get() + 1);
|
||||
if (i.get() > host.range.get()) throw new IllegalStateException("There are no more ports available between " + host.range.name() + " and " + host.range.get());
|
||||
if (i.get() > ports.upperEndpoint()) throw new IllegalStateException("There are no more ports available in range: " + ports.toString());
|
||||
} while (!ports.contains(i.get()));
|
||||
return new InetSocketAddress(host.getAddress(), i.get());
|
||||
}).getPort();
|
||||
}
|
||||
@ -388,6 +397,17 @@ public class InternalSubCreator extends SubCreator {
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Range getPortRange() {
|
||||
return ports;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPortRange(Range<Integer> value) {
|
||||
if (!value.hasLowerBound() || !value.hasUpperBound()) throw new IllegalArgumentException("Port range is not bound");
|
||||
ports = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBashDirectory() {
|
||||
return gitBash;
|
||||
@ -409,6 +429,17 @@ public class InternalSubCreator extends SubCreator {
|
||||
return this.thread.get(name.toLowerCase()).log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogging() {
|
||||
return log.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogging(boolean value) {
|
||||
if (Util.isNull(value)) throw new NullPointerException();
|
||||
log.set(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getReservedNames() {
|
||||
return new ArrayList<String>(thread.keySet());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.SubServers.Bungee.Library.Callback;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidTemplateException;
|
||||
@ -259,6 +260,20 @@ public abstract class SubCreator {
|
||||
*/
|
||||
public abstract Host getHost();
|
||||
|
||||
/**
|
||||
* Get the range of available port numbers
|
||||
*
|
||||
* @return Port Range
|
||||
*/
|
||||
public abstract Range getPortRange();
|
||||
|
||||
/**
|
||||
* Get the range of available port numbers
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public abstract void setPortRange(Range<Integer> value);
|
||||
|
||||
/**
|
||||
* Gets the Git Bash install directory
|
||||
*
|
||||
@ -281,6 +296,20 @@ public abstract class SubCreator {
|
||||
*/
|
||||
public abstract SubLogger getLogger(String thread);
|
||||
|
||||
/**
|
||||
* If the Creator is Logging to console
|
||||
*
|
||||
* @return Logging Status
|
||||
*/
|
||||
public abstract boolean isLogging();
|
||||
|
||||
/**
|
||||
* Set if the Creator is Logging
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public abstract void setLogging(boolean value);
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of currently reserved Server names
|
||||
|
@ -1,6 +1,5 @@
|
||||
Settings:
|
||||
Version: '2.11.2a+'
|
||||
Log-Creator: true
|
||||
Override-Bungee-Commands: true
|
||||
UPnP:
|
||||
Forward-Proxy: true
|
||||
@ -21,6 +20,7 @@ Hosts:
|
||||
Port-Range: '25500-25559'
|
||||
Directory: './SubServers/Servers'
|
||||
Git-Bash: '%ProgramFiles%\Git'
|
||||
Log-Creator: true
|
||||
|
||||
Servers:
|
||||
'Example':
|
||||
|
@ -66,6 +66,25 @@ public class Client {
|
||||
MessageUnpacker in = MessagePack.newDefaultUnpacker(socket.getInputStream());
|
||||
Value input;
|
||||
while ((input = in.unpackValue()) != null) {
|
||||
recievePacket(input);
|
||||
}
|
||||
try {
|
||||
subdata.removeClient(Client.this);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
subdata.removeClient(Client.this);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void recievePacket(Value input) {
|
||||
try {
|
||||
YAMLSection data = subdata.getCipher().decrypt(subdata.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input);
|
||||
for (PacketIn packet : SubDataServer.decodePacket(this, data)) {
|
||||
@ -106,32 +125,6 @@ public class Client {
|
||||
new InvocationTargetException(e, getAddress().toString() + ": Exception while decoding packet").printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
subdata.removeClient(Client.this);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
subdata.removeClient(Client.this);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorize Connection
|
||||
*/
|
||||
public void authorize() {
|
||||
if (authorized != null) {
|
||||
authorized.cancel();
|
||||
System.out.println("SubData > " + socket.getRemoteSocketAddress().toString() + " logged in");
|
||||
}
|
||||
authorized = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Packet to Client
|
||||
@ -148,6 +141,17 @@ public class Client {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorize Connection
|
||||
*/
|
||||
public void authorize() {
|
||||
if (authorized != null) {
|
||||
authorized.cancel();
|
||||
System.out.println("SubData > " + socket.getRemoteSocketAddress().toString() + " logged in");
|
||||
}
|
||||
authorized = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Raw Connection
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddHostEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveHostEvent;
|
||||
@ -133,20 +134,21 @@ public final class SubAPI {
|
||||
* Add a Host to the Network
|
||||
*
|
||||
* @param driver Driver to initiate
|
||||
* @param name Name of the Host
|
||||
* @param enabled Enabled Status
|
||||
* @param address Address of the Host
|
||||
* @param directory Directory of the Host
|
||||
* @param range The range of ports to auto-select from
|
||||
* @param gitBash Git Bash Directory
|
||||
* @param name The Name of your Host
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
||||
* @param enabled If your host is Enabled
|
||||
* @param address The address of your Host
|
||||
* @param directory The runtime directory of your Host
|
||||
* @param gitBash The Git Bash directory
|
||||
* @return The Host
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Host addHost(String driver, String name, boolean enabled, InetAddress address, String directory, NamedContainer<Integer, Integer> range, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
return addHost(null, driver, name, enabled, address, directory, range, gitBash);
|
||||
public Host addHost(String driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
return addHost(null, driver, name, enabled, ports, log, address, directory, gitBash);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,42 +156,44 @@ public final class SubAPI {
|
||||
*
|
||||
* @param player Player who added
|
||||
* @param driver Driver to initiate
|
||||
* @param name Name of the Host
|
||||
* @param enabled Enabled Status
|
||||
* @param address Address of the Host
|
||||
* @param directory Directory of the Host
|
||||
* @param range The range of ports to auto-select from
|
||||
* @param gitBash Git Bash Directory
|
||||
* @param name The Name of your Host
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
||||
* @param enabled If your host is Enabled
|
||||
* @param address The address of your Host
|
||||
* @param directory The runtime directory of your Host
|
||||
* @param gitBash The Git Bash directory
|
||||
* @return The Host
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Host addHost(UUID player, String driver, String name, boolean enabled, InetAddress address, String directory, NamedContainer<Integer, Integer> range, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
if (Util.isNull(driver, name, enabled, address, directory, range, gitBash)) throw new NullPointerException();
|
||||
public Host addHost(UUID player, String driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
if (Util.isNull(driver, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
|
||||
if (!getHostDrivers().contains(driver.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new InvalidHostException("Invalid Driver for host: " + name);
|
||||
return addHost(player, plugin.hostDrivers.get(driver.toUpperCase().replace('-', '_').replace(' ', '_')), name, enabled, address, directory, range, gitBash);
|
||||
return addHost(player, plugin.hostDrivers.get(driver.toUpperCase().replace('-', '_').replace(' ', '_')), name, enabled, ports, log, address, directory, gitBash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Host with a potentially unregistered driver to the Network
|
||||
*
|
||||
* @param driver Driver to initiate
|
||||
* @param name Name of the Host
|
||||
* @param enabled Enabled Status
|
||||
* @param address Address of the Host
|
||||
* @param directory Directory of the Host
|
||||
* @param range The range of ports to auto-select from
|
||||
* @param gitBash Git Bash Directory
|
||||
* @param name The Name of your Host
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
||||
* @param enabled If your host is Enabled
|
||||
* @param address The address of your Host
|
||||
* @param directory The runtime directory of your Host
|
||||
* @param gitBash The Git Bash directory
|
||||
* @return The Host
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Host addHost(Class<? extends Host> driver, String name, boolean enabled, InetAddress address, String directory, NamedContainer<Integer, Integer> range, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
return addHost(null, driver, name, enabled, address, directory, range, gitBash);
|
||||
public Host addHost(Class<? extends Host> driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
return addHost(null, driver, name, enabled, ports, log, address, directory, gitBash);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,21 +201,22 @@ public final class SubAPI {
|
||||
*
|
||||
* @param player Player who added
|
||||
* @param driver Driver to initiate
|
||||
* @param name Name of the Host
|
||||
* @param enabled Enabled Status
|
||||
* @param address Address of the Host
|
||||
* @param directory Directory of the Host
|
||||
* @param range The range of ports to auto-select from
|
||||
* @param gitBash Git Bash Directory
|
||||
* @param name The Name of your Host
|
||||
* @param ports The range of ports to auto-select from
|
||||
* @param log Whether apps like SubCreator should log to console (does not apply to servers)
|
||||
* @param enabled If your host is Enabled
|
||||
* @param address The address of your Host
|
||||
* @param directory The runtime directory of your Host
|
||||
* @param gitBash The Git Bash directory
|
||||
* @return The Host
|
||||
* @throws NoSuchMethodException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InvocationTargetException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
public Host addHost(UUID player, Class<? extends Host> driver, String name, boolean enabled, InetAddress address, String directory, NamedContainer<Integer, Integer> range, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
if (Util.isNull(driver, name, enabled, address, directory, range, gitBash)) throw new NullPointerException();
|
||||
Host host = driver.getConstructor(SubPlugin.class, String.class, Boolean.class, InetAddress.class, String.class, NamedContainer.class, String.class).newInstance(plugin, name, (Boolean) enabled, address, directory, range, gitBash);
|
||||
public Host addHost(UUID player, Class<? extends Host> driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
if (Util.isNull(driver, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
|
||||
Host host = driver.getConstructor(SubPlugin.class, String.class, boolean.class, Range.class, boolean.class, InetAddress.class, String.class, String.class).newInstance(plugin, name, enabled, ports, log, address, directory, gitBash);
|
||||
return addHost(player, host)?host:null;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.ME1312.SubServers.Bungee;
|
||||
|
||||
import com.dosse.upnp.UPnP;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddProxyEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveProxyEvent;
|
||||
@ -316,15 +317,20 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
!hostDrivers.get(config.get().getSection("Hosts").getSection(name).getRawString("Driver").toUpperCase().replace('-', '_').replace(' ', '_')).equals(host.getClass()) ||
|
||||
!config.get().getSection("Hosts").getSection(name).getRawString("Address").equals(host.getAddress().getHostAddress()) ||
|
||||
!config.get().getSection("Hosts").getSection(name).getRawString("Directory").equals(host.getPath()) ||
|
||||
!config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").equals(prevconfig.getSection("Hosts", new YAMLSection()).getSection(name, new YAMLSection()).getRawString("Port-Range", "25500-25559")) ||
|
||||
!config.get().getSection("Hosts").getSection(name).getRawString("Git-Bash").equals(host.getCreator().getBashDirectory())
|
||||
) {
|
||||
if (host != null) api.forceRemoveHost(name);
|
||||
host = api.addHost(config.get().getSection("Hosts").getSection(name).getRawString("Driver").toLowerCase(), name, config.get().getSection("Hosts").getSection(name).getBoolean("Enabled"), InetAddress.getByName(config.get().getSection("Hosts").getSection(name).getRawString("Address")), config.get().getSection("Hosts").getSection(name).getRawString("Directory"),
|
||||
new NamedContainer<>(Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[0]), Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[1])), config.get().getSection("Hosts").getSection(name).getRawString("Git-Bash"));
|
||||
host = api.addHost(config.get().getSection("Hosts").getSection(name).getRawString("Driver").toLowerCase(), name, config.get().getSection("Hosts").getSection(name).getBoolean("Enabled"),
|
||||
Range.closed(Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[0]), Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[1])),
|
||||
config.get().getSection("Hosts").getSection(name).getBoolean("Log-Creator", true), InetAddress.getByName(config.get().getSection("Hosts").getSection(name).getRawString("Address")),
|
||||
config.get().getSection("Hosts").getSection(name).getRawString("Directory"), config.get().getSection("Hosts").getSection(name).getRawString("Git-Bash"));
|
||||
} else { // Host wasn't reset, so check for these changes
|
||||
if (config.get().getSection("Hosts").getSection(name).getBoolean("Enabled") != host.isEnabled())
|
||||
host.setEnabled(config.get().getSection("Hosts").getSection(name).getBoolean("Enabled"));
|
||||
if (!config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").equals(prevconfig.getSection("Hosts", new YAMLSection()).getSection(name, new YAMLSection()).getRawString("Port-Range", "25500-25559")))
|
||||
host.getCreator().setPortRange(Range.closed(Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[0]), Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[1])));
|
||||
if (config.get().getSection("Hosts").getSection(name).getBoolean("Log-Creator", true) != host.getCreator().isLogging())
|
||||
host.getCreator().setLogging(config.get().getSection("Hosts").getSection(name).getBoolean("Log-Creator", true));
|
||||
} // Check for other changes
|
||||
if (config.get().getSection("Hosts").getSection(name).getKeys().contains("Display") && ((config.get().getSection("Hosts").getSection(name).getString("Display").length() == 0 && !host.getDisplayName().equals(host.getName())) || !config.get().getSection("Hosts").getSection(name).getString("Display").equals(host.getDisplayName())))
|
||||
host.setDisplayName(config.get().getSection("Hosts").getSection(name).getString("Display"));
|
||||
|
@ -138,6 +138,25 @@ public final class SubDataClient {
|
||||
MessageUnpacker in = MessagePack.newDefaultUnpacker(socket.get().getInputStream());
|
||||
Value input;
|
||||
while ((input = in.unpackValue()) != null) {
|
||||
recieve(input);
|
||||
}
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void recieve(Value input) {
|
||||
try {
|
||||
YAMLSection data = cipher.decrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input);
|
||||
for (PacketIn packet : decodePacket(data)) {
|
||||
@ -157,21 +176,6 @@ public final class SubDataClient {
|
||||
new InvocationTargetException(e, "Exception while decoding packet").printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Assigned Server Name
|
||||
|
@ -142,6 +142,25 @@ public final class SubDataClient {
|
||||
MessageUnpacker in = MessagePack.newDefaultUnpacker(socket.get().getInputStream());
|
||||
Value input;
|
||||
while ((input = in.unpackValue()) != null) {
|
||||
recieve(input);
|
||||
}
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).submit(plugin);
|
||||
}
|
||||
|
||||
private void recieve(Value input) {
|
||||
try {
|
||||
YAMLSection data = getCipher().decrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input);
|
||||
for (PacketIn packet : decodePacket(data)) {
|
||||
@ -161,21 +180,6 @@ public final class SubDataClient {
|
||||
new InvocationTargetException(e, "Exception while decoding packet").printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).submit(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Assigned Server Name
|
||||
|
@ -162,6 +162,25 @@ public final class SubDataClient {
|
||||
MessageUnpacker in = MessagePack.newDefaultUnpacker(socket.get().getInputStream());
|
||||
Value input;
|
||||
while ((input = in.unpackValue()) != null) {
|
||||
recieve(input);
|
||||
}
|
||||
try {
|
||||
destroy(host.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
log.error.println(e1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) log.error.println(e);
|
||||
try {
|
||||
destroy(host.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
log.error.println(e1);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void recieve(Value input) {
|
||||
try {
|
||||
YAMLSection data = cipher.decrypt(host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input);
|
||||
for (PacketIn packet : decodePacket(data)) {
|
||||
@ -179,21 +198,6 @@ public final class SubDataClient {
|
||||
log.error.println(new InvocationTargetException(e, "Exception while decoding packet"));
|
||||
}
|
||||
}
|
||||
try {
|
||||
destroy(host.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
log.error.println(e1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) log.error.println(e);
|
||||
try {
|
||||
destroy(host.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
log.error.println(e1);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Assigned Host Name
|
||||
|
@ -174,6 +174,25 @@ public final class SubDataClient {
|
||||
MessageUnpacker in = MessagePack.newDefaultUnpacker(socket.get().getInputStream());
|
||||
Value input;
|
||||
while ((input = in.unpackValue()) != null) {
|
||||
recieve(input);
|
||||
}
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void recieve(Value input) {
|
||||
try {
|
||||
YAMLSection data = cipher.decrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input);
|
||||
for (PacketIn packet : decodePacket(data)) {
|
||||
@ -191,21 +210,6 @@ public final class SubDataClient {
|
||||
new InvocationTargetException(e, "Exception while decoding packet").printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Assigned Proxy Name
|
||||
|
Loading…
Reference in New Issue
Block a user