mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-25 11:46:50 +01:00
Mirror changes in SubServers.Host
This commit is contained in:
parent
9ef878ba12
commit
61ee89cfe3
@ -30,13 +30,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w19c</version>
|
||||
<version>19w20a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Server</artifactId>
|
||||
<version>19w19f</version>
|
||||
<version>19w20f</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -188,7 +188,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
getSubServer(server).waitFor();
|
||||
}
|
||||
queue(new PacketExRemoveServer(server, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) {
|
||||
servers.remove(server.toLowerCase());
|
||||
}
|
||||
}));
|
||||
@ -207,7 +207,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
getSubServer(server).terminate();
|
||||
}
|
||||
queue(new PacketExRemoveServer(server, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) {
|
||||
servers.remove(server.toLowerCase());
|
||||
}
|
||||
}));
|
||||
@ -242,7 +242,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
|
||||
System.out.println("SubServers > Moving Files...");
|
||||
queue(new PacketExDeleteServer(server, info, true, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) {
|
||||
servers.remove(server.toLowerCase());
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
} else {
|
||||
@ -279,7 +279,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
|
||||
System.out.println("SubServers > Moving Files...");
|
||||
queue(new PacketExDeleteServer(server, info, true, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) {
|
||||
for (String group : getSubServer(server).getGroups()) getSubServer(server).removeGroup(group);
|
||||
servers.remove(server.toLowerCase());
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
@ -318,7 +318,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
|
||||
System.out.println("SubServers > Removing Files...");
|
||||
queue(new PacketExDeleteServer(server, info, false, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) {
|
||||
servers.remove(server.toLowerCase());
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
} else {
|
||||
@ -355,7 +355,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
|
||||
System.out.println("SubServers > Removing Files...");
|
||||
queue(new PacketExDeleteServer(server, info, false, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) {
|
||||
for (String group : getSubServer(server).getGroups()) getSubServer(server).removeGroup(group);
|
||||
servers.remove(server.toLowerCase());
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
|
@ -114,7 +114,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
server.set("Port", fport);
|
||||
server.set("Motd", "Some SubServer");
|
||||
server.set("Log", true);
|
||||
server.set("Directory", "." + File.separatorChar + name);
|
||||
server.set("Directory", "./" + name);
|
||||
server.set("Executable", "java -Xmx1024M -jar " + template.getType().toString() + ".jar");
|
||||
server.set("Stop-Command", "stop");
|
||||
server.set("Stop-Action", "NONE");
|
||||
|
@ -241,15 +241,9 @@ public class InternalHost extends Host {
|
||||
File from = new File(getPath(), servers.get(server.toLowerCase()).getPath());
|
||||
if (removeSubServer(player, server)) {
|
||||
new Thread(() -> {
|
||||
UniversalFile to = new UniversalFile(plugin.dir, "SubServers:Recently Deleted:" + server.toLowerCase());
|
||||
try {
|
||||
if (from.exists()) {
|
||||
System.out.println("SubServers > Removing Files...");
|
||||
if (to.exists()) {
|
||||
if (to.isDirectory()) Util.deleteDirectory(to);
|
||||
else to.delete();
|
||||
}
|
||||
to.mkdirs();
|
||||
Util.deleteDirectory(from);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -257,18 +251,11 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.servers.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"));
|
||||
writer.write(info.toJSON().toString());
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -285,16 +272,9 @@ public class InternalHost extends Host {
|
||||
File from = new File(getPath(), servers.get(server.toLowerCase()).getPath());
|
||||
if (forceRemoveSubServer(player, server)) {
|
||||
new Thread(() -> {
|
||||
UniversalFile to = new UniversalFile(plugin.dir, "SubServers:Recently Deleted:" + server.toLowerCase());
|
||||
try {
|
||||
if (from.exists()) {
|
||||
System.out.println("SubServers > Removing Files...");
|
||||
if (to.exists()) {
|
||||
if (to.isDirectory()) Util.deleteDirectory(to);
|
||||
else to.delete();
|
||||
}
|
||||
to.mkdirs();
|
||||
Util.copyDirectory(from, to);
|
||||
Util.deleteDirectory(from);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -302,18 +282,11 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.servers.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"), false);
|
||||
writer.write(info.toJSON().toString());
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
server.set("Port", port);
|
||||
server.set("Motd", "Some SubServer");
|
||||
server.set("Log", true);
|
||||
server.set("Directory", "." + File.separatorChar + name);
|
||||
server.set("Directory", "./" + name);
|
||||
server.set("Executable", "java -Xmx1024M -jar " + template.getType().toString() + ".jar");
|
||||
server.set("Stop-Command", "stop");
|
||||
server.set("Stop-Action", "NONE");
|
||||
|
@ -43,7 +43,7 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExCreateServer(String name, SubCreator.ServerTemplate template, Version version, int port, UUID log, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, template, version, port, log, callback)) throw new NullPointerException();
|
||||
if (Util.isNull(name, template, port, log, callback)) throw new NullPointerException();
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
@ -64,7 +64,7 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
|
||||
data.set(0x0003, template.getName());
|
||||
data.set(0x0004, version);
|
||||
data.set(0x0005, port);
|
||||
data.set(0x0006, log.toString());
|
||||
data.set(0x0006, log);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ public class PacketExDownloadTemplates implements PacketIn, PacketStreamOut {
|
||||
public void send(SubDataClient client, OutputStream stream) throws Throwable {
|
||||
try {
|
||||
Util.zip(new UniversalFile(plugin.dir, "SubServers:Templates"), stream);
|
||||
stream.close();
|
||||
} catch (Exception e) {
|
||||
System.out.println("SubData > Problem encoding template files for Host: " + host.getName());
|
||||
e.printStackTrace();
|
||||
|
@ -21,6 +21,7 @@ import java.util.Map;
|
||||
public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* New PacketLinkExHost (In)
|
||||
@ -36,15 +37,19 @@ public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>,
|
||||
* New PacketLinkExHost (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketLinkExHost(int response) {
|
||||
public PacketLinkExHost(int response, String message) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0001, response);
|
||||
if (message != null) data.set(0x0002, message);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -59,20 +64,20 @@ public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>,
|
||||
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(ExternalHost.class.getDeclaredField("subdata"), host), null);
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
|
||||
((ExternalHost) host).setSubData(client, channel);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Host: " + host.getName() + ((channel > 0)?" (Sub "+channel+")":""));
|
||||
client.sendPacket(new PacketLinkExHost(0));
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Host: " + host.getName() + ((channel > 0)?" (Sub-"+channel+")":""));
|
||||
client.sendPacket(new PacketLinkExHost(0, null));
|
||||
setReady(client, true);
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkExHost(3));
|
||||
client.sendPacket(new PacketLinkExHost(3, "Host already linked"));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkExHost(4));
|
||||
client.sendPacket(new PacketLinkExHost(4, "That host does not support a network interface"));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkExHost(2));
|
||||
client.sendPacket(new PacketLinkExHost(2, "There is no host with name: " + data.getRawString(0x0000)));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketLinkExHost(1));
|
||||
client.sendPacket(new PacketLinkExHost(1, null));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import java.util.Map;
|
||||
public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
@ -39,9 +40,10 @@ public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>,
|
||||
* @param name The name that was generated
|
||||
* @param response Response ID
|
||||
*/
|
||||
public PacketLinkProxy(String name, int response) {
|
||||
public PacketLinkProxy(String name, int response, String message) {
|
||||
this.name = name;
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,6 +51,7 @@ public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>,
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, name);
|
||||
json.set(0x0001, response);
|
||||
if (message != null) json.set(0x0002, message);
|
||||
return json;
|
||||
}
|
||||
|
||||
@ -69,15 +72,15 @@ public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>,
|
||||
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(Proxy.class.getDeclaredField("subdata"), proxy), null);
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
|
||||
proxy.setSubData(client, channel);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Proxy: " + proxy.getName() + ((channel > 0)?" (Sub "+channel+")":""));
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 0));
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Proxy: " + proxy.getName() + ((channel > 0)?" (Sub-"+channel+")":""));
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 0, null));
|
||||
setReady(client, true);
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 2));
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 2, "Proxy already linked"));
|
||||
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketLinkProxy(null, 1));
|
||||
client.sendPacket(new PacketLinkProxy(null, 1, null));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
|
||||
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(ServerContainer.class.getDeclaredField("subdata"), server), null);
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
|
||||
server.setSubData(client, channel);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as " + ((server instanceof SubServer) ? "SubServer" : "Server") + ": " + server.getName() + ((channel > 0)?" (Sub "+channel+")":""));
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as " + ((server instanceof SubServer) ? "SubServer" : "Server") + ": " + server.getName() + ((channel > 0)?" (Sub-"+channel+")":""));
|
||||
if (server instanceof SubServer && !((SubServer) server).isRunning()) {
|
||||
System.out.println("SubServers > Sending shutdown signal to rogue SubServer: " + server.getName());
|
||||
client.sendPacket(new PacketOutExReset("Rogue SubServer Detected"));
|
||||
|
@ -285,7 +285,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage(" -> Address: " + ChatColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
|
||||
if (server instanceof SubServer) sender.sendMessage(" -> Running: " + ((((SubServer) server).isRunning())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||
sender.sendMessage(" -> Connected: " + ((server.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((server.getSubData().length > 1)?ChatColor.AQUA+" +"+(server.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Connected: " + ((server.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((server.getSubData().length > 1)?ChatColor.AQUA+" +"+(server.getSubData().length-1)+" subchannel"+((server.getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Players: " + ChatColor.AQUA + server.getPlayers().size() + " online");
|
||||
}
|
||||
sender.sendMessage(" -> MOTD: " + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
|
||||
@ -330,7 +330,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage(" -> Available: " + ((host.isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Address: " + ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host instanceof ClientHandler) sender.sendMessage(" -> Connected: " + ((((ClientHandler) host).getSubData()[0] != null)?ChatColor.GREEN+"yes"+((((ClientHandler) host).getSubData().length > 1)?ChatColor.AQUA+" +"+(((ClientHandler) host).getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
if (host instanceof ClientHandler) sender.sendMessage(" -> Connected: " + ((((ClientHandler) host).getSubData()[0] != null)?ChatColor.GREEN+"yes"+((((ClientHandler) host).getSubData().length > 1)?ChatColor.AQUA+" +"+(((ClientHandler) host).getSubData().length-1)+" subchannel"+((((ClientHandler) host).getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" - " + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
@ -349,7 +349,7 @@ public final class SubCommand extends CommandX {
|
||||
if (proxy != null) {
|
||||
sender.sendMessage("SubServers > Info on Proxy: " + ChatColor.WHITE + proxy.getDisplayName());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + proxy.getName());
|
||||
sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + proxy.getSignature());
|
||||
|
@ -48,13 +48,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w19c</version>
|
||||
<version>19w20a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w19f</version>
|
||||
<version>19w20f</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -234,7 +234,7 @@ public class Metrics {
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
|
||||
data.put("plugins", pluginData);
|
||||
data.put("Plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(new Runnable() {
|
||||
|
@ -15,7 +15,7 @@ import java.util.Calendar;
|
||||
/**
|
||||
* Download Lang Packet
|
||||
*/
|
||||
public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
|
||||
/**
|
||||
@ -33,11 +33,6 @@ public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketObject
|
||||
*/
|
||||
public PacketDownloadLang() {}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient subDataClient) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
|
@ -23,7 +23,6 @@ import java.util.logging.Logger;
|
||||
|
||||
public class SubProtocol extends SubDataProtocol {
|
||||
private static SubProtocol instance;
|
||||
private static Logger log;
|
||||
private SubProtocol() {}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -32,33 +31,6 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance = new SubProtocol();
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
private boolean open = true;
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (open) {
|
||||
if (plugin.isEnabled()) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getLogger().log(record.getLevel(), "SubData > " + record.getMessage(), record.getParameters()));
|
||||
} else {
|
||||
Bukkit.getLogger().log(record.getLevel(), "SubData > " + record.getMessage(), record.getParameters());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
|
||||
instance.setName("SubServers 2");
|
||||
instance.addVersion(new Version("2.14a+"));
|
||||
|
||||
@ -125,16 +97,50 @@ public class SubProtocol extends SubDataProtocol {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private Logger getLogger(int channel) {
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
Logger log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
private boolean open = true;
|
||||
private String prefix = "SubData" + ((channel != 0)? "/Sub-"+channel:"");
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (open) {
|
||||
if (plugin.isEnabled()) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getLogger().log(record.getLevel(), prefix + " > " + record.getMessage(), record.getParameters()));
|
||||
} else {
|
||||
Bukkit.getLogger().log(record.getLevel(), prefix + " > " + record.getMessage(), record.getParameters());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SubDataClient sub(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin), null);
|
||||
|
||||
int channel = 1;
|
||||
while (map.keySet().contains(channel)) channel++;
|
||||
final int fc = channel;
|
||||
|
||||
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port);
|
||||
map.put(fc, subdata);
|
||||
subdata.sendPacket(new PacketLinkServer(plugin, fc));
|
||||
subdata.on.closed(client -> map.remove(fc));
|
||||
@ -193,6 +199,6 @@ public class SubProtocol extends SubDataProtocol {
|
||||
}
|
||||
|
||||
public SubDataClient open(InetAddress address, int port) throws IOException {
|
||||
return open(log, address, port);
|
||||
return open(getLogger(0), address, port);
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
else sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port") + ChatColor.AQUA.toString() + server.getAddress().getPort());
|
||||
if (server instanceof SubServer) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running") + ((((SubServer) server).isRunning())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((server.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((server.getSubData().length > 1)?ChatColor.AQUA+" +"+(server.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((server.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((server.getSubData().length > 1)?ChatColor.AQUA+" +"+(server.getSubData().length-1)+" subchannel"+((server.getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + server.getPlayers().size() + " online");
|
||||
}
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "MOTD") + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
|
||||
@ -280,7 +280,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Available") + ((host.isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host.getSubData().length > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((host.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((host.getSubData().length > 1)?ChatColor.AQUA+" +"+(host.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
if (host.getSubData().length > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((host.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((host.getSubData().length > 1)?ChatColor.AQUA+" +"+(host.getSubData().length-1)+" subchannel"+((host.getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "SubServers") + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Templates") + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
@ -298,7 +298,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
if (proxy != null) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Proxy") + ChatColor.WHITE + proxy.getDisplayName());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name") + ChatColor.WHITE + proxy.getName());
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis") + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + proxy.getSignature());
|
||||
|
@ -30,13 +30,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w19c</version>
|
||||
<version>19w20a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w19f</version>
|
||||
<version>19w20f</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -30,7 +30,7 @@ public class SubCreateEvent extends AbstractEvent implements SubEvent {
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port) {
|
||||
if (Util.isNull(host, name, template, version, port)) throw new NullPointerException();
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
|
@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
||||
|
||||
@ -14,7 +15,7 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
* Download Lang Packet
|
||||
*/
|
||||
public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
|
||||
/**
|
||||
@ -32,11 +33,6 @@ public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketObject
|
||||
*/
|
||||
public PacketDownloadLang() {}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient subDataClient) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||
|
@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.spongepowered.api.GameState;
|
||||
import org.spongepowered.api.Sponge;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
@ -28,7 +29,6 @@ import static java.util.logging.Level.*;
|
||||
|
||||
public class SubProtocol extends SubDataProtocol {
|
||||
private static SubProtocol instance;
|
||||
private static Logger log;
|
||||
private SubProtocol() {}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -38,40 +38,6 @@ public class SubProtocol extends SubDataProtocol {
|
||||
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
private org.slf4j.Logger log = LoggerFactory.getLogger("SubData");
|
||||
private boolean open = true;
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (open) {
|
||||
if (record.getLevel().intValue() == OFF.intValue()) {
|
||||
// do nothing
|
||||
} else if (record.getLevel().intValue() == FINE.intValue() || record.getLevel().intValue() == FINER.intValue() || record.getLevel().intValue() == FINEST.intValue()) {
|
||||
log.debug(record.getMessage());
|
||||
} else if (record.getLevel().intValue() == ALL.intValue() || record.getLevel().intValue() == CONFIG.intValue() || record.getLevel().intValue() == INFO.intValue()) {
|
||||
log.info(record.getMessage());
|
||||
} else if (record.getLevel().intValue() == WARNING.intValue()) {
|
||||
log.warn(record.getMessage());
|
||||
} else if (record.getLevel().intValue() == SEVERE.intValue()) {
|
||||
log.error(record.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
|
||||
instance.setName("SubServers 2");
|
||||
instance.addVersion(new Version("2.14a+"));
|
||||
|
||||
@ -138,16 +104,54 @@ public class SubProtocol extends SubDataProtocol {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Logger getLogger(int channel) {
|
||||
Logger log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
private org.slf4j.Logger log = LoggerFactory.getLogger("SubData" + ((channel != 0)? "/Sub-"+channel:""));
|
||||
private boolean open = true;
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (open) {
|
||||
if (record.getLevel().intValue() == OFF.intValue()) {
|
||||
// do nothing
|
||||
} else if (record.getLevel().intValue() == FINE.intValue() || record.getLevel().intValue() == FINER.intValue() || record.getLevel().intValue() == FINEST.intValue()) {
|
||||
log.debug(record.getMessage());
|
||||
} else if (record.getLevel().intValue() == ALL.intValue() || record.getLevel().intValue() == CONFIG.intValue() || record.getLevel().intValue() == INFO.intValue()) {
|
||||
log.info(record.getMessage());
|
||||
} else if (record.getLevel().intValue() == WARNING.intValue()) {
|
||||
log.warn(record.getMessage());
|
||||
} else if (record.getLevel().intValue() == SEVERE.intValue()) {
|
||||
log.error(record.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SubDataClient sub(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin), null);
|
||||
|
||||
int channel = 1;
|
||||
while (map.keySet().contains(channel)) channel++;
|
||||
final int fc = channel;
|
||||
|
||||
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port);
|
||||
map.put(fc, subdata);
|
||||
subdata.sendPacket(new PacketLinkServer(plugin, fc));
|
||||
subdata.on.closed(client -> map.remove(fc));
|
||||
@ -159,9 +163,9 @@ public class SubProtocol extends SubDataProtocol {
|
||||
@Override
|
||||
public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin), null);
|
||||
|
||||
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||
subdata.sendPacket(new PacketLinkServer(plugin, 0));
|
||||
subdata.sendPacket(new PacketDownloadLang());
|
||||
subdata.on.ready(client -> Sponge.getEventManager().post(new SubNetworkConnectEvent((SubDataClient) client)));
|
||||
@ -205,6 +209,6 @@ public class SubProtocol extends SubDataProtocol {
|
||||
}
|
||||
|
||||
public SubDataClient open(InetAddress address, int port) throws IOException {
|
||||
return open(log, address, port);
|
||||
return open(getLogger(0), address, port);
|
||||
}
|
||||
}
|
||||
|
@ -526,7 +526,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
else sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port")).toBuilder().append(Text.builder(Integer.toString(server.getAddress().getPort())).color(TextColors.AQUA).build()).build());
|
||||
if (server instanceof SubServer) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running")).toBuilder().append(Text.builder((((SubServer) server).isRunning())?"yes":"no").color((((SubServer) server).isRunning())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((server.getSubData()[0] != null)?"yes":"no").color((server.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((server.getSubData().length > 1)?" +"+(server.getSubData().length-1):"").color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((server.getSubData()[0] != null)?"yes":"no").color((server.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((server.getSubData().length > 1)?" +"+(server.getSubData().length-1)+" subchannel"+((server.getSubData().length == 2)?"":"s"):"").color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(server.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
|
||||
}
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "MOTD")).toBuilder().append(Text.builder(server.getMotd().replaceAll("\\u00A7[0-9a-fA-Fk-oK-ORr]", "")).color(TextColors.WHITE).build()).build());
|
||||
@ -569,7 +569,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Available")).toBuilder().append(Text.builder((host.isAvailable())?"yes":"no").color((host.isAvailable())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).toBuilder().append(Text.builder((host.isEnabled())?"yes":"no").color((host.isEnabled())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(host.getAddress().getHostAddress()).color(TextColors.WHITE).build()).build());
|
||||
if (host.getSubData().length > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((host.getSubData()[0] != null)?"yes":"no").color((host.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((host.getSubData().length > 1)?" +"+(host.getSubData().length-1):"").color(TextColors.AQUA).build()).build());
|
||||
if (host.getSubData().length > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((host.getSubData()[0] != null)?"yes":"no").color((host.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((host.getSubData().length > 1)?" +"+(host.getSubData().length-1)+" subchannel"+((host.getSubData().length == 2)?"":"s"):"").color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "SubServers")).toBuilder().append(Text.builder((host.getSubServers().keySet().size() <= 0)?"(none)":Integer.toString(host.getSubServers().keySet().size())).color((host.getSubServers().keySet().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')')).color((subserver.isEnabled())?TextColors.WHITE:TextColors.GRAY).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Templates")).toBuilder().append(Text.builder((host.getCreator().getTemplates().keySet().size() <= 0)?"(none)":Integer.toString(host.getCreator().getTemplates().keySet().size())).color((host.getCreator().getTemplates().keySet().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
|
||||
@ -587,7 +587,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (proxy != null) {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Proxy")).toBuilder().append(Text.builder(proxy.getDisplayName()).color(TextColors.WHITE).build()).build());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(proxy.getName()).color(TextColors.WHITE ).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((proxy.getSubData()[0] != null)?"yes":"no").color((proxy.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((proxy.getSubData().length > 1)?" +"+(proxy.getSubData().length-1):"").color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((proxy.getSubData()[0] != null)?"yes":"no").color((proxy.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((proxy.getSubData().length > 1)?" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):"").color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis") ).toBuilder().append(Text.builder(((proxy.isRedis())?"":"un") + "available").color((proxy.isRedis())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||
if (proxy.isRedis()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(proxy.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature")).toBuilder().append(Text.builder(proxy.getSignature()).color(TextColors.AQUA).build()).build());
|
||||
|
@ -57,7 +57,6 @@ public final class SubPlugin {
|
||||
@Inject public Game game;
|
||||
|
||||
private boolean reconnect = false;
|
||||
private boolean scheduling = false;
|
||||
|
||||
@Listener
|
||||
public void setup(GamePreInitializationEvent event) {
|
||||
@ -94,7 +93,6 @@ public final class SubPlugin {
|
||||
Files.move(new UniversalFile(new File(System.getProperty("user.dir")), "subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
|
||||
}
|
||||
|
||||
scheduling = true;
|
||||
subprotocol = SubProtocol.get();
|
||||
reload(false);
|
||||
|
||||
@ -196,7 +194,6 @@ public final class SubPlugin {
|
||||
*/
|
||||
@Listener
|
||||
public void disable(GameStoppingEvent event) {
|
||||
scheduling = false;
|
||||
if (subdata != null) try {
|
||||
reconnect = false;
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
Settings:
|
||||
Version: '2.11.2a+'
|
||||
Ingame-Access: true
|
||||
Show-Addresses: false
|
||||
Use-Title-Messages: true
|
||||
SubData:
|
||||
Address: '127.0.0.1:4391'
|
||||
Password: 'default'
|
||||
Encryption: 'AES'
|
@ -1,4 +1,4 @@
|
||||
name: SubServers-Console
|
||||
main: net.ME1312.SubServers.Console.ConsolePlugin
|
||||
version: 2.13.2b
|
||||
version: 2.14a
|
||||
author: ME1312
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Console;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.ExceptionReturnRunnable;
|
||||
import net.ME1312.Galaxi.Library.Callback.ExceptionRunnable;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubLogFilter;
|
||||
@ -46,6 +47,8 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
private int findO = 0;
|
||||
private int findI = 0;
|
||||
private boolean open = false;
|
||||
private boolean running = true;
|
||||
private LinkedList<Object> messages = new LinkedList<Object>();
|
||||
private SubLogger logger;
|
||||
private int fontSize = 12;
|
||||
private File file = null;
|
||||
@ -564,6 +567,7 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
logger.registerFilter(this);
|
||||
log.setText(RESET_VALUE);
|
||||
loadContent();
|
||||
log();
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keys);
|
||||
}
|
||||
private void hScroll() {
|
||||
@ -579,9 +583,7 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
|
||||
public void log(Date date, String message) {
|
||||
try {
|
||||
byte[] msg = ('\u00A0' + new SimpleDateFormat("hh:mm:ss").format(date) + ' ' + message + "\u00A0\n").getBytes("UTF-8");
|
||||
filewriter.write(msg);
|
||||
stream.write(msg);
|
||||
messages.add(('\u00A0' + new SimpleDateFormat("hh:mm:ss").format(date) + ' ' + message + "\u00A0\n").getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -598,6 +600,33 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
return !open;
|
||||
}
|
||||
|
||||
private void log() {
|
||||
new Thread("SubServers.Console::Log_Spooler(" + logger.getName() + ")") {
|
||||
@Override
|
||||
public void run() {
|
||||
while (running) {
|
||||
while (running && messages.size() > 0) try {
|
||||
byte[] msg = (byte[]) Util.getDespiteException(new ExceptionReturnRunnable<Object>() {
|
||||
@Override
|
||||
public Object run() throws Throwable {
|
||||
return messages.get(0);
|
||||
}
|
||||
}, null);
|
||||
if (msg != null) {
|
||||
filewriter.write(msg);
|
||||
stream.write(msg);
|
||||
}
|
||||
try { ConsoleWindow.this.messages.remove(0); } catch (Throwable e) {}
|
||||
} catch (Throwable e) {
|
||||
try { ConsoleWindow.this.messages.remove(0); } catch (Throwable ex) {}
|
||||
e.printStackTrace();
|
||||
}
|
||||
try { Thread.sleep(32); } catch (Throwable e) {}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
log.setText(RESET_VALUE);
|
||||
hScroll();
|
||||
@ -650,6 +679,7 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
|
||||
public void destroy() {
|
||||
close();
|
||||
running = false;
|
||||
logger.unregisterFilter(this);
|
||||
if (filewriter != null) try {
|
||||
filewriter.close();
|
||||
|
@ -20,13 +20,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>19w04c</version>
|
||||
<version>19w20a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.msgpack</groupId>
|
||||
<artifactId>msgpack-core</artifactId>
|
||||
<version>0.8.16</version>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w20f</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -28,7 +28,7 @@ public class SubCreateEvent extends Event {
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port) {
|
||||
if (Util.isNull(host, name, template, version, port)) throw new NullPointerException();
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Host.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLValue;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.Event.Event;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
@ -14,7 +14,7 @@ import java.util.UUID;
|
||||
public class SubEditServerEvent extends Event {
|
||||
private UUID player;
|
||||
private String server;
|
||||
private NamedContainer<String, YAMLValue> edit;
|
||||
private NamedContainer<String, ObjectMapValue<String>> edit;
|
||||
private boolean perm;
|
||||
|
||||
/**
|
||||
@ -27,11 +27,11 @@ public class SubEditServerEvent extends Event {
|
||||
*/
|
||||
public SubEditServerEvent(UUID player, String server, NamedContainer<String, ?> edit, boolean permanent) {
|
||||
if (Util.isNull(server, edit)) throw new NullPointerException();
|
||||
YAMLSection section = new YAMLSection();
|
||||
ObjectMap<String> section = new ObjectMap<String>();
|
||||
section.set(".", edit.get());
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.edit = new NamedContainer<String, YAMLValue>(edit.name(), section.get("."));
|
||||
this.edit = new NamedContainer<String, ObjectMapValue<String>>(edit.name(), section.get("."));
|
||||
this.perm = permanent;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public class SubEditServerEvent extends Event {
|
||||
*
|
||||
* @return Edit to be made
|
||||
*/
|
||||
public NamedContainer<String, YAMLValue> getEdit() {
|
||||
public NamedContainer<String, ObjectMapValue<String>> getEdit() {
|
||||
return edit;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Host.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Event.Event;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
/**
|
||||
* SubData Network Connect Event
|
||||
|
@ -1,8 +1,41 @@
|
||||
package net.ME1312.SubServers.Host.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Event.Event;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.DataClient;
|
||||
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||
|
||||
/**
|
||||
* SubData Network Disconnect Event
|
||||
*/
|
||||
public class SubNetworkDisconnectEvent extends Event {}
|
||||
public class SubNetworkDisconnectEvent extends Event {
|
||||
private DataClient network;
|
||||
private DisconnectReason reason;
|
||||
|
||||
/**
|
||||
* SubData Network Disconnect Event
|
||||
*/
|
||||
public SubNetworkDisconnectEvent(DataClient network, DisconnectReason reason) {
|
||||
if (Util.isNull(network, reason)) throw new NullPointerException();
|
||||
this.network = network;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SubData network
|
||||
*
|
||||
* @return SubData Network
|
||||
*/
|
||||
public DataClient getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reason the client disconnected
|
||||
*
|
||||
* @return Disconnect Reason
|
||||
*/
|
||||
public DisconnectReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import net.ME1312.Galaxi.Event.GalaxiReloadEvent;
|
||||
import net.ME1312.Galaxi.Galaxi;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
@ -15,12 +16,16 @@ import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.Library.Version.VersionType;
|
||||
import net.ME1312.Galaxi.Plugin.Plugin;
|
||||
import net.ME1312.Galaxi.Plugin.PluginInfo;
|
||||
import net.ME1312.SubData.Client.Encryption.AES;
|
||||
import net.ME1312.SubData.Client.Encryption.RSA;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubCreator;
|
||||
import net.ME1312.SubServers.Host.Executable.SubLogger;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||
import net.ME1312.SubServers.Host.Library.*;
|
||||
import net.ME1312.SubServers.Host.Network.Cipher;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Library.Updates.ConfigUpdater;
|
||||
import net.ME1312.SubServers.Host.Network.SubProtocol;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
@ -38,6 +43,7 @@ import java.util.jar.Manifest;
|
||||
*/
|
||||
@Plugin(name = "SubServers.Host", version = "2.14a", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
|
||||
public final class ExHost {
|
||||
protected HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
public HashMap<String, SubCreator.ServerTemplate> templates = new HashMap<String, SubCreator.ServerTemplate>();
|
||||
public HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||
@ -47,11 +53,12 @@ public final class ExHost {
|
||||
public PluginInfo info;
|
||||
public GalaxiEngine engine;
|
||||
public YAMLConfig config;
|
||||
public YAMLSection host = null;
|
||||
public SubDataClient subdata = null;
|
||||
public ObjectMap<String> host = null;
|
||||
public SubProtocol subprotocol;
|
||||
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
|
||||
private boolean reconnect = true;
|
||||
private boolean running = false;
|
||||
|
||||
/**
|
||||
@ -136,15 +143,8 @@ public final class ExHost {
|
||||
info.setIcon(ExHost.class.getResourceAsStream("/net/ME1312/SubServers/Host/Library/Files/icon.png"));
|
||||
engine = GalaxiEngine.init(info);
|
||||
log.info.println("Loading SubServers.Host v" + info.getVersion().toString() + " Libraries");
|
||||
if (!(new UniversalFile(engine.getRuntimeDirectory(), "config.yml").exists())) {
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(engine.getRuntimeDirectory(), "config.yml").getPath());
|
||||
log.info.println("Created ./config.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"))).get().getSection("Settings").getVersion("Version", new Version(0)).compareTo(new Version("2.11.2a+"))) != 0) {
|
||||
Files.move(new UniversalFile(engine.getRuntimeDirectory(), "config.yml").toPath(), new UniversalFile(engine.getRuntimeDirectory(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(engine.getRuntimeDirectory(), "config.yml").getPath());
|
||||
log.info.println("Updated ./config.yml");
|
||||
}
|
||||
ConfigUpdater.updateConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"));
|
||||
config = new YAMLConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"));
|
||||
|
||||
if (!(new UniversalFile(engine.getRuntimeDirectory(), "Templates").exists())) {
|
||||
@ -191,34 +191,16 @@ public final class ExHost {
|
||||
}
|
||||
}
|
||||
|
||||
Util.reflect(SubLogger.class.getDeclaredField("logn"), null, config.get().getSection("Settings").getBoolean("Network-Log", true));
|
||||
Util.reflect(SubLogger.class.getDeclaredField("logc"), null, config.get().getSection("Settings").getBoolean("Console-Log", true));
|
||||
Util.reflect(SubLogger.class.getDeclaredField("logn"), null, config.get().getMap("Settings").getBoolean("Network-Log", true));
|
||||
Util.reflect(SubLogger.class.getDeclaredField("logc"), null, config.get().getMap("Settings").getBoolean("Console-Log", true));
|
||||
|
||||
engine.getPluginManager().loadPlugins(new UniversalFile(engine.getRuntimeDirectory(), "Plugins"));
|
||||
|
||||
running = true;
|
||||
Cipher cipher = null;
|
||||
if (!config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE").equalsIgnoreCase("NONE")) {
|
||||
if (config.get().getSection("Settings").getSection("SubData").getString("Password", "").length() == 0) {
|
||||
log.info.println("Cannot encrypt connection without a password");
|
||||
} else if (!SubDataClient.getCiphers().keySet().contains(config.get().getSection("Settings").getSection("SubData").getRawString("Encryption").toUpperCase().replace('-', '_').replace(' ', '_'))) {
|
||||
log.info.println("Unknown encryption type: " + config.get().getSection("Settings").getSection("SubData").getRawString("Encryption"));
|
||||
} else {
|
||||
cipher = SubDataClient.getCipher(config.get().getSection("Settings").getSection("SubData").getRawString("Encryption"));
|
||||
}
|
||||
}
|
||||
subdata = new SubDataClient(this, config.get().getSection("Settings").getSection("SubData").getString("Name", "undefined"),
|
||||
InetAddress.getByName(config.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||
Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
if (running) {
|
||||
log.warn.println("Received request from system to shutdown");
|
||||
engine.stop();
|
||||
}
|
||||
}, SubAPI.getInstance().getAppInfo().getName() + "::System_Shutdown"));
|
||||
creator = new SubCreator(this);
|
||||
|
||||
subprotocol = SubProtocol.get();
|
||||
loadDefaults();
|
||||
reload(false);
|
||||
|
||||
new Metrics(this);
|
||||
info.setUpdateChecker(() -> {
|
||||
@ -228,7 +210,7 @@ public final class ExHost {
|
||||
|
||||
Version updversion = info.getVersion();
|
||||
int updcount = 0;
|
||||
for (YAMLSection tag : tags.getSectionList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
|
||||
for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
|
||||
Collections.sort(versions);
|
||||
for (Version version : versions) {
|
||||
if (version.compareTo(updversion) > 0) {
|
||||
@ -251,40 +233,63 @@ public final class ExHost {
|
||||
}
|
||||
}
|
||||
|
||||
public void reload() throws IOException {
|
||||
if (subdata != null)
|
||||
subdata.destroy(0);
|
||||
|
||||
config.reload();
|
||||
|
||||
try {
|
||||
Util.reflect(SubLogger.class.getDeclaredField("logn"), null, config.get().getSection("Settings").getBoolean("Network-Log", true));
|
||||
Util.reflect(SubLogger.class.getDeclaredField("logc"), null, config.get().getSection("Settings").getBoolean("Console-Log", true));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Cipher cipher = null;
|
||||
if (!config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE").equalsIgnoreCase("NONE")) {
|
||||
if (config.get().getSection("Settings").getSection("SubData").getString("Password", "").length() == 0) {
|
||||
log.info.println("Cannot encrypt connection without a password");
|
||||
} else if (!SubDataClient.getCiphers().keySet().contains(config.get().getSection("Settings").getSection("SubData").getRawString("Encryption").toUpperCase().replace('-', '_').replace(' ', '_'))) {
|
||||
log.info.println("Unknown encryption type: " + config.get().getSection("Settings").getSection("SubData").getRawString("Encryption"));
|
||||
} else {
|
||||
cipher = SubDataClient.getCipher(config.get().getSection("Settings").getSection("SubData").getRawString("Encryption"));
|
||||
}
|
||||
}
|
||||
subdata = new SubDataClient(this, config.get().getSection("Settings").getSection("SubData").getString("Name", "undefined"),
|
||||
InetAddress.getByName(config.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||
Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
|
||||
|
||||
engine.getPluginManager().executeEvent(new GalaxiReloadEvent(engine));
|
||||
}
|
||||
|
||||
private void loadDefaults() {
|
||||
SubCommand.load(this);
|
||||
}
|
||||
|
||||
public void reload(boolean notifyPlugins) throws IOException {
|
||||
reconnect = false;
|
||||
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
|
||||
tmp.addAll(subdata.values());
|
||||
for (SubDataClient client : tmp) if (client != null) {
|
||||
client.close();
|
||||
Util.isException(client::waitFor);
|
||||
}
|
||||
subdata.clear();
|
||||
subdata.put(0, null);
|
||||
|
||||
ConfigUpdater.updateConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"));
|
||||
config.reload();
|
||||
|
||||
subprotocol.unregisterCipher("AES");
|
||||
subprotocol.unregisterCipher("AES-128");
|
||||
subprotocol.unregisterCipher("AES-192");
|
||||
subprotocol.unregisterCipher("AES-256");
|
||||
subprotocol.unregisterCipher("RSA");
|
||||
api.name = config.get().getMap("Settings").getMap("SubData").getString("Name", null);
|
||||
Logger log = new Logger("SubData");
|
||||
|
||||
if (config.get().getMap("Settings").getMap("SubData").getRawString("Password", "").length() > 0) {
|
||||
subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||
subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||
subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||
subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||
|
||||
log.info.println("AES Encryption Available");
|
||||
}
|
||||
if (new UniversalFile(engine.getRuntimeDirectory(), "subdata.rsa.key").exists()) {
|
||||
try {
|
||||
subprotocol.registerCipher("RSA", new RSA(new UniversalFile(engine.getRuntimeDirectory(), "subdata.rsa.key")));
|
||||
log.info.println("RSA Encryption Available");
|
||||
} catch (Exception e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
reconnect = true;
|
||||
log.info.println();
|
||||
connect();
|
||||
|
||||
if (notifyPlugins) {
|
||||
engine.getPluginManager().executeEvent(new GalaxiReloadEvent(engine));
|
||||
}
|
||||
}
|
||||
|
||||
private void connect() throws IOException {
|
||||
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
if (running) {
|
||||
log.info.println("Shutting down...");
|
||||
@ -318,7 +323,20 @@ public final class ExHost {
|
||||
} catch (Exception e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
if (subdata != null) Util.isException(() -> subdata.destroy(0));
|
||||
|
||||
reconnect = false;
|
||||
try {
|
||||
ArrayList<SubDataClient> temp = new ArrayList<SubDataClient>();
|
||||
temp.addAll(subdata.values());
|
||||
for (SubDataClient client : temp) if (client != null) {
|
||||
client.close();
|
||||
client.waitFor();
|
||||
}
|
||||
subdata.clear();
|
||||
subdata.put(0, null);
|
||||
} catch (Exception e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
|
||||
if (new File(engine.getRuntimeDirectory(), "Templates").exists()) Util.deleteDirectory(new File(engine.getRuntimeDirectory(), "Templates"));
|
||||
}
|
||||
|
@ -2,11 +2,12 @@ package net.ME1312.SubServers.Host.Executable;
|
||||
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Host.Library.Exception.InvalidTemplateException;
|
||||
import net.ME1312.SubServers.Host.Library.Exception.SubCreatorException;
|
||||
@ -16,15 +17,11 @@ import net.ME1312.SubServers.Host.Network.Packet.PacketOutExLogMessage;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
import org.json.JSONObject;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -41,8 +38,8 @@ public class SubCreator {
|
||||
private String icon;
|
||||
private File directory;
|
||||
private ServerType type;
|
||||
private YAMLSection build;
|
||||
private YAMLSection options;
|
||||
private ObjectMap<String> build;
|
||||
private ObjectMap<String> options;
|
||||
|
||||
/**
|
||||
* Create a SubCreator Template
|
||||
@ -52,7 +49,7 @@ public class SubCreator {
|
||||
* @param build Build Options
|
||||
* @param options Configuration Options
|
||||
*/
|
||||
public ServerTemplate(String name, boolean enabled, String icon, File directory, YAMLSection build, YAMLSection options) {
|
||||
public ServerTemplate(String name, boolean enabled, String icon, File directory, ObjectMap<String> build, ObjectMap<String> options) {
|
||||
super(toRaw(name, enabled, icon, directory, build, options));
|
||||
if (name.contains(" ")) throw new InvalidTemplateException("Template names cannot have spaces: " + name);
|
||||
this.name = name;
|
||||
@ -150,12 +147,21 @@ public class SubCreator {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this Template requires the Version argument
|
||||
*
|
||||
* @return Version Requirement
|
||||
*/
|
||||
public boolean requiresVersion() {
|
||||
return getBuildOptions().getBoolean("Require-Version", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Build Options for this Template
|
||||
*
|
||||
* @return Build Options
|
||||
*/
|
||||
public YAMLSection getBuildOptions() {
|
||||
public ObjectMap<String> getBuildOptions() {
|
||||
return build;
|
||||
}
|
||||
|
||||
@ -164,13 +170,13 @@ public class SubCreator {
|
||||
*
|
||||
* @return Configuration Options
|
||||
*/
|
||||
public YAMLSection getConfigOptions() {
|
||||
public ObjectMap<String> getConfigOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
private static YAMLSection toRaw(String name, boolean enabled, String icon, File directory, YAMLSection build, YAMLSection options) {
|
||||
private static ObjectMap<String> toRaw(String name, boolean enabled, String icon, File directory, ObjectMap<String> build, ObjectMap<String> options) {
|
||||
if (Util.isNull(name, enabled, directory, build, options)) throw new NullPointerException();
|
||||
YAMLSection tinfo = new YAMLSection();
|
||||
ObjectMap<String> tinfo = new ObjectMap<String>();
|
||||
tinfo.set("enabled", enabled);
|
||||
tinfo.set("name", name);
|
||||
tinfo.set("display", name);
|
||||
@ -186,11 +192,11 @@ public class SubCreator {
|
||||
private final Version version;
|
||||
private final int port;
|
||||
private final UUID address;
|
||||
private final String id;
|
||||
private final UUID tracker;
|
||||
private final SubLogger log;
|
||||
private Process process;
|
||||
|
||||
private CreatorTask(String name, ServerTemplate template, Version version, int port, UUID address, String id) {
|
||||
private CreatorTask(String name, ServerTemplate template, Version version, int port, UUID address, UUID tracker) {
|
||||
super(SubAPI.getInstance().getAppInfo().getName() + "::SubCreator_Process_Handler(" + name + ')');
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
@ -198,11 +204,11 @@ public class SubCreator {
|
||||
this.port = port;
|
||||
this.log = new SubLogger(null, this, name + File.separator + "Creator", address, new Container<Boolean>(true), null);
|
||||
this.address = address;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException {
|
||||
YAMLSection server = new YAMLSection();
|
||||
private ObjectMap<String> build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException {
|
||||
ObjectMap<String> server = new ObjectMap<String>();
|
||||
Version version = this.version;
|
||||
HashMap<String, String> var = new HashMap<String, String>();
|
||||
boolean error = false;
|
||||
@ -211,44 +217,50 @@ public class SubCreator {
|
||||
for (String other : template.getBuildOptions().getStringList("Import", new ArrayList<String>())) {
|
||||
if (host.templates.keySet().contains(other.toLowerCase())) {
|
||||
if (host.templates.get(other.toLowerCase()).isEnabled()) {
|
||||
YAMLSection config = build(dir, host.templates.get(other.toLowerCase()), history);
|
||||
if (version != null || !host.templates.get(other.toLowerCase()).requiresVersion()) {
|
||||
ObjectMap<String> config = build(dir, host.templates.get(other.toLowerCase()), history);
|
||||
if (config == null) {
|
||||
throw new SubCreatorException();
|
||||
} else {
|
||||
server.setAll(config);
|
||||
}
|
||||
} else {
|
||||
log.logger.warn.println("Skipping template that requires extra versioning: " + other);
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Skipping template that requires extra versioning: " + other));
|
||||
}
|
||||
} else {
|
||||
log.logger.warn.println("Skipping disabled template: " + other);
|
||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Skipping disabled template: " + other));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Skipping disabled template: " + other));
|
||||
}
|
||||
} else {
|
||||
log.logger.warn.println("Skipping missing template: " + other);
|
||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Skipping missing template: " + other));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Skipping missing template: " + other));
|
||||
}
|
||||
}
|
||||
server.setAll(template.getConfigOptions());
|
||||
try {
|
||||
log.logger.info.println("Loading Template: " + template.getDisplayName());
|
||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Loading Template: " + template.getDisplayName()));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Loading Template: " + template.getDisplayName()));
|
||||
Util.copyDirectory(template.getDirectory(), dir);
|
||||
var.put("name", name);
|
||||
if (host.subdata != null) var.put("host", host.subdata.getName());
|
||||
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) var.put("host", SubAPI.getInstance().getName());
|
||||
var.put("template", template.getName());
|
||||
var.put("type", template.getType().toString().toUpperCase());
|
||||
var.put("version", version.toString());
|
||||
var.put("address", host.config.get().getSection("Settings").getRawString("Server-Bind"));
|
||||
if (version != null) var.put("version", version.toString());
|
||||
var.put("address", host.config.get().getMap("Settings").getRawString("Server-Bind"));
|
||||
var.put("port", Integer.toString(port));
|
||||
switch (template.getType()) {
|
||||
case SPONGE:
|
||||
case FORGE:
|
||||
if (version != null) {
|
||||
log.logger.info.println("Searching Versions...");
|
||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Searching Versions..."));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).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;
|
||||
ObjectMap<String> spprofile = null;
|
||||
Version spversion = null;
|
||||
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)) {
|
||||
for (ObjectMap<String> profile : spversionmanifest.getMapList("versions")) {
|
||||
if (profile.getMap("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
|
||||
spprofile = profile;
|
||||
spversion = new Version(profile.getRawString("version"));
|
||||
}
|
||||
@ -256,16 +268,17 @@ public class SubCreator {
|
||||
if (spversion == null)
|
||||
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() + '"');
|
||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"'));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"'));
|
||||
|
||||
if (template.getType() == ServerType.FORGE) {
|
||||
Version mcfversion = new Version(((spprofile.getSection("dependencies").getRawString("forge").contains("-"))?"":spprofile.getSection("dependencies").getRawString("minecraft") + '-') + spprofile.getSection("dependencies").getRawString("forge"));
|
||||
Version mcfversion = new Version(((spprofile.getMap("dependencies").getRawString("forge").contains("-"))?"":spprofile.getMap("dependencies").getRawString("minecraft") + '-') + spprofile.getMap("dependencies").getRawString("forge"));
|
||||
log.logger.info.println("Found \"forge-" + mcfversion.toString() + '"');
|
||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Found \"forge-" + mcfversion.toString() + '"'));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Found \"forge-" + mcfversion.toString() + '"'));
|
||||
|
||||
var.put("mcf_version", mcfversion.toString());
|
||||
}
|
||||
var.put("sp_version", spversion.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -287,11 +300,11 @@ public class SubCreator {
|
||||
|
||||
try {
|
||||
log.logger.info.println("Launching Build Script...");
|
||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Launching Build Script..."));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Launching Build Script..."));
|
||||
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.host.getRawString("Git-Bash"), template.getBuildOptions().getRawString("Executable"))).directory(dir);
|
||||
pb.environment().putAll(var);
|
||||
process = pb.start();
|
||||
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString().replace(" ", "@") + ".log");
|
||||
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + ((version != null)?"-"+version.toString():"") + ".log");
|
||||
log.process = process;
|
||||
log.start();
|
||||
|
||||
@ -323,7 +336,7 @@ public class SubCreator {
|
||||
public void run() {
|
||||
UniversalFile dir = new UniversalFile(new File(host.host.getRawString("Directory")), name);
|
||||
dir.mkdirs();
|
||||
YAMLSection server;
|
||||
ObjectMap<String> server;
|
||||
try {
|
||||
server = build(dir, template, new LinkedList<>());
|
||||
generateProperties(dir, port);
|
||||
@ -334,13 +347,13 @@ public class SubCreator {
|
||||
server = null;
|
||||
log.logger.error.println(e);
|
||||
}
|
||||
YAMLSection config = template.getConfigOptions().clone();
|
||||
config.set("\033address", host.config.get().getSection("Settings").getRawString("Server-Bind"));
|
||||
ObjectMap<String> config = template.getConfigOptions().clone();
|
||||
config.set("\033address", host.config.get().getMap("Settings").getRawString("Server-Bind"));
|
||||
if (server != null) {
|
||||
host.subdata.sendPacket(new PacketExCreateServer(0, "Created Server Successfully", config, id));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExCreateServer(0, null, config, tracker));
|
||||
} else {
|
||||
log.logger.info.println("Couldn't build the server jar. Check the SubCreator logs for more detail.");
|
||||
host.subdata.sendPacket(new PacketExCreateServer(-1, "Couldn't build the server jar. Check the SubCreator logs for more detail.", config, id));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExCreateServer(-1, "Couldn't build the server jar. Check the SubCreator logs for more detail.", config, tracker));
|
||||
}
|
||||
SubCreator.this.thread.remove(name.toLowerCase());
|
||||
}
|
||||
@ -357,9 +370,9 @@ public class SubCreator {
|
||||
this.thread = new TreeMap<>();
|
||||
}
|
||||
|
||||
public boolean create(String name, ServerTemplate template, Version version, int port, UUID address, String id) {
|
||||
if (Util.isNull(name, template, version, port, address)) throw new NullPointerException();
|
||||
CreatorTask task = new CreatorTask(name, template, version, port, address, id);
|
||||
public boolean create(String name, ServerTemplate template, Version version, int port, UUID address, UUID tracker) {
|
||||
if (Util.isNull(name, template, port, address)) throw new NullPointerException();
|
||||
CreatorTask task = new CreatorTask(name, template, version, port, address, tracker);
|
||||
this.thread.put(name.toLowerCase(), task);
|
||||
task.start();
|
||||
return true;
|
||||
@ -414,6 +427,7 @@ public class SubCreator {
|
||||
|
||||
private void generateClient(File dir, ServerType type, String name) throws IOException {
|
||||
if (new UniversalFile(dir, "subservers.client").exists()) {
|
||||
Files.delete(new UniversalFile(dir, "subservers.client").toPath());
|
||||
if (type == ServerType.SPIGOT) {
|
||||
if (!new UniversalFile(dir, "plugins").exists()) new UniversalFile(dir, "plugins").mkdirs();
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/client.jar", new UniversalFile(dir, "plugins:SubServers.Client.jar").getPath());
|
||||
@ -422,20 +436,23 @@ public class SubCreator {
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/client.jar", new UniversalFile(dir, "mods:SubServers.Client.jar").getPath());
|
||||
}
|
||||
JSONObject config = new JSONObject();
|
||||
FileWriter writer = new FileWriter(new UniversalFile(dir, "subservers.client"), false);
|
||||
FileWriter writer = new FileWriter(new UniversalFile(dir, "subdata.json"), false);
|
||||
config.put("Name", name);
|
||||
config.put("Address", host.config.get().getSection("Settings").getSection("SubData").getRawString("Address"));
|
||||
config.put("Password", host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"));
|
||||
config.put("Encryption", host.config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE"));
|
||||
config.put("Address", host.config.get().getMap("Settings").getMap("SubData").getRawString("Address"));
|
||||
if (host.config.get().getMap("Settings").getMap("SubData").getRawString("Password", "").length() > 0) config.put("Password", host.config.get().getMap("Settings").getMap("SubData").getRawString("Password"));
|
||||
config.write(writer);
|
||||
writer.close();
|
||||
|
||||
if (new UniversalFile("subdata.rsa.key").exists()) {
|
||||
Files.copy(new UniversalFile("subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
private void generateProperties(File dir, int port) throws IOException {
|
||||
File file = new File(dir, "server.properties");
|
||||
if (!file.exists()) file.createNewFile();
|
||||
FileInputStream is = new FileInputStream(file);
|
||||
String content = Util.readAll(new BufferedReader(new InputStreamReader(is))).replaceAll("server-port=.*(\r?\n)", "server-port=" + port + "$1").replaceAll("server-ip=.*(\r?\n)", "server-ip=" + host.config.get().getSection("Settings").getRawString("Server-Bind") + "$1");
|
||||
String content = Util.readAll(new BufferedReader(new InputStreamReader(is))).replaceAll("server-port=.*(\r?\n)", "server-port=" + port + "$1").replaceAll("server-ip=.*(\r?\n)", "server-ip=" + host.config.get().getMap("Settings").getRawString("Server-Bind") + "$1");
|
||||
is.close();
|
||||
file.delete();
|
||||
PrintWriter writer = new PrintWriter(file, "UTF-8");
|
||||
|
@ -1,9 +1,11 @@
|
||||
package net.ME1312.SubServers.Host.Executable;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.Log.LogStream;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Library.TextColor;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketOutExLogMessage;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
@ -26,6 +28,7 @@ public class SubLogger {
|
||||
protected static boolean logn = true;
|
||||
protected static boolean logc = true;
|
||||
protected File file;
|
||||
private SubDataClient channel = null;
|
||||
private PrintWriter writer = null;
|
||||
private boolean started = false;
|
||||
private Thread out = null;
|
||||
@ -56,12 +59,13 @@ public class SubLogger {
|
||||
*/
|
||||
public void start() {
|
||||
started = true;
|
||||
if (logn) Util.isException(() -> channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel());
|
||||
if (file != null && writer == null) {
|
||||
try {
|
||||
this.writer = new PrintWriter(file, "UTF-8");
|
||||
this.writer.println("---------- LOG START \u2014 " + name + " ----------");
|
||||
this.writer.flush();
|
||||
} catch (UnsupportedEncodingException | FileNotFoundException e) {
|
||||
} catch (IOException e) {
|
||||
logger.error.println(e);
|
||||
}
|
||||
}
|
||||
@ -121,7 +125,7 @@ public class SubLogger {
|
||||
}
|
||||
|
||||
// Log to NETWORK
|
||||
if (log.get() && logn) SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketOutExLogMessage(address, line));
|
||||
if (log.get() && channel != null && !channel.isClosed()) channel.sendPacket(new PacketOutExLogMessage(address, line));
|
||||
|
||||
// Log to CONSOLE
|
||||
if (log.get() && logc) level.println(TextColor.convertColor(msg));
|
||||
@ -157,6 +161,10 @@ public class SubLogger {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
if (channel != null && !channel.isClosed()) {
|
||||
channel.sendPacket(new PacketOutExLogMessage(address, true));
|
||||
}
|
||||
channel = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketExUpdateServer;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
@ -110,8 +111,8 @@ public class SubServer {
|
||||
try {
|
||||
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.host.getRawString("Git-Bash"), executable)).directory(directory);
|
||||
pb.environment().put("name", getName());
|
||||
if (host.subdata != null) pb.environment().put("host", host.subdata.getName());
|
||||
pb.environment().put("address", host.config.get().getSection("Settings").getRawString("Server-Bind"));
|
||||
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) pb.environment().put("host", SubAPI.getInstance().getName());
|
||||
pb.environment().put("address", host.config.get().getMap("Settings").getRawString("Server-Bind"));
|
||||
pb.environment().put("port", Integer.toString(getPort()));
|
||||
process = pb.start();
|
||||
falsestart = false;
|
||||
@ -130,10 +131,10 @@ public class SubServer {
|
||||
} catch (IOException | InterruptedException e) {
|
||||
host.log.error.println(e);
|
||||
allowrestart = false;
|
||||
if (falsestart) host.subdata.sendPacket(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.LAUNCH_EXCEPTION));
|
||||
if (falsestart) ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.LAUNCH_EXCEPTION));
|
||||
}
|
||||
|
||||
host.subdata.sendPacket(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart));
|
||||
host.log.info.println(name + " has stopped");
|
||||
process = null;
|
||||
command = null;
|
||||
|
@ -1,11 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Library.Exception;
|
||||
|
||||
/**
|
||||
* Illegal Packet Exception
|
||||
*/
|
||||
public class IllegalPacketException extends IllegalStateException {
|
||||
public IllegalPacketException() {}
|
||||
public IllegalPacketException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
Settings:
|
||||
Version: '2.11.2a+'
|
||||
Console-Log: true
|
||||
Network-Log: true
|
||||
Server-Bind: '127.0.0.1'
|
||||
UPnP:
|
||||
Forward-Servers: false
|
||||
SubData:
|
||||
Name: 'undefined'
|
||||
Address: '127.0.0.1:4391'
|
||||
Password: 'default'
|
||||
Encryption: 'AES'
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Host.Library;
|
||||
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
@ -69,7 +69,7 @@ public class Metrics {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
YAMLSection configuration = new YAMLConfig(configFile).get();
|
||||
ObjectMap<String> configuration = new YAMLConfig(configFile).get();
|
||||
|
||||
// Load configuration
|
||||
enabled = configuration.getBoolean("enabled", true);
|
||||
|
@ -0,0 +1,81 @@
|
||||
package net.ME1312.SubServers.Host.Library.Updates;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* SubServers Configuration Updater
|
||||
*/
|
||||
public class ConfigUpdater {
|
||||
private static final Version UNSIGNED = new Version(new SimpleDateFormat("yy'w'ww'zz'").format(Calendar.getInstance().getTime()));
|
||||
|
||||
/**
|
||||
* Update SubServers' config.yml
|
||||
*
|
||||
* @param file File to bring up-to-date
|
||||
*/
|
||||
public static void updateConfig(File file) throws IOException {
|
||||
YAMLConfig config = new YAMLConfig(file);
|
||||
YAMLSection existing = config.get().clone();
|
||||
YAMLSection updated = existing.clone();
|
||||
YAMLSection rewritten = new YAMLSection();
|
||||
|
||||
Version was = existing.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
|
||||
Version now = SubAPI.getInstance().getAppInfo().getSignature();
|
||||
|
||||
int i = 0;
|
||||
if (now == null) now = UNSIGNED;
|
||||
if (!existing.contains("Settings") || !existing.getMap("Settings").contains("Version")) {
|
||||
|
||||
i++;
|
||||
SubAPI.getInstance().getAppInfo().getLogger().info.println("SubServers > Created ./config.yml");
|
||||
} else {
|
||||
if (was.compareTo(new Version("19w17a")) <= 0) {
|
||||
if (existing.getMap("Settings", new YAMLSection()).contains("Log")) {
|
||||
updated.getMap("Settings").safeSet("Console-Log", existing.getMap("Settings").getBoolean("Log"));
|
||||
updated.getMap("Settings").safeSet("Network-Log", existing.getMap("Settings").getBoolean("Log"));
|
||||
}
|
||||
|
||||
existing = updated.clone();
|
||||
i++;
|
||||
}// if (was.compareTo(new Version("99w99a")) <= 0) {
|
||||
// // do something
|
||||
// i++
|
||||
//}
|
||||
|
||||
if (i > 0) SubAPI.getInstance().getAppInfo().getLogger().info.println("Updated ./config.yml (" + i + " pass" + ((i != 1)?"es":"") + ")");
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
YAMLSection settings = new YAMLSection();
|
||||
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
|
||||
settings.set("Console-Log", updated.getMap("Settings", new YAMLSection()).getBoolean("Console-Log", true));
|
||||
settings.set("Network-Log", updated.getMap("Settings", new YAMLSection()).getBoolean("Network-Log", true));
|
||||
settings.set("Server-Bind", updated.getMap("Settings", new YAMLSection()).getRawString("Server-Bind", "127.0.0.1"));
|
||||
|
||||
YAMLSection upnp = new YAMLSection();
|
||||
upnp.set("Forward-Servers", updated.getMap("Settings", new YAMLSection()).getMap("UPnP", new YAMLSection()).getBoolean("Forward-Servers", false));
|
||||
settings.set("UPnP", upnp);
|
||||
|
||||
YAMLSection subdata = new YAMLSection();
|
||||
subdata.set("Name", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Name", "undefined"));
|
||||
subdata.set("Address", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Address", "127.0.0.1:4391"));
|
||||
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Password")) subdata.set("Password", updated.getMap("Settings").getMap("SubData").getRawString("Password"));
|
||||
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Reconnect")) subdata.set("Reconnect", updated.getMap("Settings").getMap("SubData").getInt("Reconnect"));
|
||||
settings.set("SubData", subdata);
|
||||
|
||||
rewritten.set("Settings", settings);
|
||||
|
||||
config.set(rewritten);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,17 @@
|
||||
package net.ME1312.SubServers.Host.Network.API;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLValue;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketAddServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDeleteServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketRemoveServer;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
@ -13,7 +19,7 @@ import java.util.*;
|
||||
public class Host {
|
||||
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||
private SubCreator creator;
|
||||
YAMLSection raw;
|
||||
ObjectMap<String> raw;
|
||||
long timestamp;
|
||||
|
||||
/**
|
||||
@ -21,7 +27,7 @@ public class Host {
|
||||
*
|
||||
* @param raw Raw representation of the Host
|
||||
*/
|
||||
public Host(YAMLSection raw) {
|
||||
public Host(ObjectMap<String> raw) {
|
||||
load(raw);
|
||||
}
|
||||
|
||||
@ -30,14 +36,14 @@ public class Host {
|
||||
return obj instanceof Host && getSignature().equals(((Host) obj).getSignature());
|
||||
}
|
||||
|
||||
private void load(YAMLSection raw) {
|
||||
private void load(ObjectMap<String> raw) {
|
||||
this.raw = raw;
|
||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||
|
||||
servers.clear();
|
||||
this.creator = new SubCreator(this, raw.getSection("creator"));
|
||||
for (String server : raw.getSection("servers").getKeys()) {
|
||||
servers.put(server.toLowerCase(), new SubServer(this, raw.getSection("servers").getSection(server)));
|
||||
this.creator = new SubCreator(this, raw.getMap("creator"));
|
||||
for (String server : raw.getMap("servers").getKeys()) {
|
||||
servers.put(server.toLowerCase(), new SubServer(this, raw.getMap("servers").getMap(server)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,16 +52,16 @@ public class Host {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getSection("hosts").getSection(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client Address
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client Address (or null if unlinked/unsupported)
|
||||
* @return SubData Client Channel ID Array (may be empty if unsupported)
|
||||
*/
|
||||
public String getSubData() {
|
||||
return raw.getRawString("subdata", null);
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,6 +238,380 @@ public class Host {
|
||||
return getSubServers().get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
*
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param response Response Code
|
||||
* @return The SubServer
|
||||
*/
|
||||
public void addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||
addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
*
|
||||
* @param player Player adding
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param response Response Code
|
||||
* @return The SubServer
|
||||
*/
|
||||
public void addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketAddServer(player, name, enabled, getName(), port, motd, log, directory, executable, stopcmd, hidden, restricted, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
*
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @return The SubServer
|
||||
*/
|
||||
public void addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) {
|
||||
addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
*
|
||||
* @param player Player adding
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @return The SubServer
|
||||
*/
|
||||
public void addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) {
|
||||
addSubServer(player, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void removeSubServer(String name) throws InterruptedException {
|
||||
removeSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void removeSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeSubServer(player, name, false, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void forceRemoveSubServer(String name) throws InterruptedException {
|
||||
forceRemoveSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void forceRemoveSubServer(UUID player, String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeSubServer(player, name, true, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void removeSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
removeSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void removeSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeSubServer(player, name, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRemoveSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
forceRemoveSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRemoveSubServer(UUID player, String name, Callback<Integer> response) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeSubServer(player, name, true, response);
|
||||
}
|
||||
|
||||
private void removeSubServer(UUID player, String name, boolean force, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void recycleSubServer(String name) throws InterruptedException {
|
||||
recycleSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void recycleSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, true, false, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void forceRecycleSubServer(String name) throws InterruptedException {
|
||||
forceRecycleSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void forceRecycleSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, true, true, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void recycleSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
recycleSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void recycleSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, true, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRecycleSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
forceRecycleSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRecycleSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, true, true, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void deleteSubServer(String name) throws InterruptedException {
|
||||
deleteSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void deleteSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, false, false, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void forceDeleteSubServer(String name) throws InterruptedException {
|
||||
forceDeleteSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void forceDeleteSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, false, true, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void deleteSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
deleteSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void deleteSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, false, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void forceDeleteSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
forceDeleteSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void forceDeleteSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, false, true, response);
|
||||
}
|
||||
|
||||
private void deleteSubServer(UUID player, String name, boolean recycle, boolean force, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Signature of this Object
|
||||
*
|
||||
@ -258,7 +638,7 @@ public class Host {
|
||||
*/
|
||||
public boolean hasExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return raw.getSection("extra").getKeys().contains(handle);
|
||||
return raw.getMap("extra").getKeys().contains(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,9 +647,9 @@ public class Host {
|
||||
* @param handle Handle
|
||||
* @return Value
|
||||
*/
|
||||
public YAMLValue getExtra(String handle) {
|
||||
public ObjectMapValue<String> getExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return raw.getSection("extra").get(handle);
|
||||
return raw.getMap("extra").get(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -277,8 +657,8 @@ public class Host {
|
||||
*
|
||||
* @return Extra Value Section
|
||||
*/
|
||||
public YAMLSection getExtra() {
|
||||
return raw.getSection("extra").clone();
|
||||
public ObjectMap<String> getExtra() {
|
||||
return raw.getMap("extra").clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,13 +666,7 @@ public class Host {
|
||||
*
|
||||
* @return Raw Host
|
||||
*/
|
||||
public YAMLSection getRaw() {
|
||||
public ObjectMap<String> getRaw() {
|
||||
return raw.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
return raw.toJSON().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
package net.ME1312.SubServers.Host.Network.API;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLValue;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadProxyInfo;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Proxy {
|
||||
YAMLSection raw;
|
||||
ObjectMap<String> raw;
|
||||
long timestamp;
|
||||
|
||||
/**
|
||||
@ -18,7 +19,7 @@ public class Proxy {
|
||||
*
|
||||
* @param raw Raw representation of the Proxy
|
||||
*/
|
||||
public Proxy(YAMLSection raw) {
|
||||
public Proxy(ObjectMap<String> raw) {
|
||||
load(raw);
|
||||
}
|
||||
|
||||
@ -27,7 +28,7 @@ public class Proxy {
|
||||
return obj instanceof Proxy && getSignature().equals(((Proxy) obj).getSignature());
|
||||
}
|
||||
|
||||
private void load(YAMLSection raw) {
|
||||
private void load(ObjectMap<String> raw) {
|
||||
this.raw = raw;
|
||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||
}
|
||||
@ -37,16 +38,16 @@ public class Proxy {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getSection("proxies").getSection(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client (or null if not linked)
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public String getSubData() {
|
||||
return raw.getRawString("subdata", null);
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,8 +84,8 @@ public class Proxy {
|
||||
*/
|
||||
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
for (String id : raw.getSection("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(raw.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
||||
for (String id : raw.getMap("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
@ -115,7 +116,7 @@ public class Proxy {
|
||||
*/
|
||||
public boolean hasExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return raw.getSection("extra").getKeys().contains(handle);
|
||||
return raw.getMap("extra").getKeys().contains(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,9 +125,9 @@ public class Proxy {
|
||||
* @param handle Handle
|
||||
* @return Value
|
||||
*/
|
||||
public YAMLValue getExtra(String handle) {
|
||||
public ObjectMapValue<String> getExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return raw.getSection("extra").get(handle);
|
||||
return raw.getMap("extra").get(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,8 +135,8 @@ public class Proxy {
|
||||
*
|
||||
* @return Extra Value Section
|
||||
*/
|
||||
public YAMLSection getExtra() {
|
||||
return raw.getSection("extra").clone();
|
||||
public ObjectMap<String> getExtra() {
|
||||
return raw.getMap("extra").clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,13 +144,7 @@ public class Proxy {
|
||||
*
|
||||
* @return Raw Proxy
|
||||
*/
|
||||
public YAMLSection getRaw() {
|
||||
public ObjectMap<String> getRaw() {
|
||||
return raw.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
return raw.toJSON().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package net.ME1312.SubServers.Host.Network.API;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadServerInfo;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
@ -9,7 +10,7 @@ import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
|
||||
public class Server {
|
||||
YAMLSection raw;
|
||||
ObjectMap<String> raw;
|
||||
long timestamp;
|
||||
|
||||
/**
|
||||
@ -17,7 +18,7 @@ public class Server {
|
||||
*
|
||||
* @param raw Raw representation of the Server
|
||||
*/
|
||||
public Server(YAMLSection raw) {
|
||||
public Server(ObjectMap<String> raw) {
|
||||
load(raw);
|
||||
}
|
||||
|
||||
@ -26,7 +27,7 @@ public class Server {
|
||||
return obj instanceof Server && getSignature().equals(((Server) obj).getSignature());
|
||||
}
|
||||
|
||||
void load(YAMLSection raw) {
|
||||
void load(ObjectMap<String> raw) {
|
||||
this.raw = raw;
|
||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||
}
|
||||
@ -36,16 +37,16 @@ public class Server {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getSection("servers").getSection(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client Address
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client Address (or null if not linked)
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public String getSubData() {
|
||||
return raw.getRawString("subdata", null);
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,8 +91,8 @@ public class Server {
|
||||
*/
|
||||
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
for (String id : raw.getSection("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(raw.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
||||
for (String id : raw.getMap("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
@ -165,13 +166,7 @@ public class Server {
|
||||
*
|
||||
* @return Raw Server
|
||||
*/
|
||||
public YAMLSection getRaw() {
|
||||
public ObjectMap<String> getRaw() {
|
||||
return raw.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
return raw.toJSON().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package net.ME1312.SubServers.Host.Network.API;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketCreateServer;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
@ -16,14 +17,14 @@ import java.util.UUID;
|
||||
public class SubCreator {
|
||||
HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
|
||||
Host host;
|
||||
YAMLSection raw;
|
||||
ObjectMap<String> raw;
|
||||
|
||||
SubCreator(Host host, YAMLSection raw) {
|
||||
SubCreator(Host host, ObjectMap<String> raw) {
|
||||
this.host = host;
|
||||
this.raw = raw;
|
||||
|
||||
for (String template : raw.getSection("templates").getKeys()) {
|
||||
templates.put(template.toLowerCase(), new ServerTemplate(raw.getSection("templates").getSection(template)));
|
||||
for (String template : raw.getMap("templates").getKeys()) {
|
||||
templates.put(template.toLowerCase(), new ServerTemplate(raw.getMap("templates").getMap(template)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,10 +34,10 @@ public class SubCreator {
|
||||
}
|
||||
|
||||
public static class ServerTemplate {
|
||||
private YAMLSection raw;
|
||||
private ObjectMap<String> raw;
|
||||
private ServerType type;
|
||||
|
||||
public ServerTemplate(YAMLSection raw) {
|
||||
public ServerTemplate(ObjectMap<String> raw) {
|
||||
this.raw = raw;
|
||||
this.type = (Util.isException(() -> ServerType.valueOf(raw.getRawString("type").toUpperCase())))? ServerType.valueOf(raw.getRawString("type").toUpperCase()): ServerType.CUSTOM;
|
||||
}
|
||||
@ -86,15 +87,13 @@ public class SubCreator {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
YAMLSection tinfo = new YAMLSection();
|
||||
tinfo.set("enabled", isEnabled());
|
||||
tinfo.set("name", getName());
|
||||
tinfo.set("display", getDisplayName());
|
||||
tinfo.set("icon", getIcon());
|
||||
tinfo.set("type", getType().toString());
|
||||
return tinfo.toJSON().toString();
|
||||
/**
|
||||
* Get whether this Template requires the Version argument
|
||||
*
|
||||
* @return Version Requirement
|
||||
*/
|
||||
public boolean requiresVersion() {
|
||||
return raw.getBoolean("version-req");
|
||||
}
|
||||
}
|
||||
public enum ServerType {
|
||||
@ -116,16 +115,16 @@ public class SubCreator {
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -139,8 +138,8 @@ public class SubCreator {
|
||||
*
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
@ -153,8 +152,8 @@ public class SubCreator {
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port) {
|
||||
create(player, name, template, version, port, i -> {});
|
||||
@ -165,8 +164,8 @@ public class SubCreator {
|
||||
*
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port) {
|
||||
create(name, template, version, port, i -> {});
|
||||
@ -200,10 +199,4 @@ public class SubCreator {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getTemplates().get(name.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
return raw.toJSON().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package net.ME1312.SubServers.Host.Network.API;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketCommandServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketEditServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketStartServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
@ -24,6 +26,7 @@ public class SubServer extends Server {
|
||||
NONE,
|
||||
RESTART,
|
||||
REMOVE_SERVER,
|
||||
RECYCLE_SERVER,
|
||||
DELETE_SERVER;
|
||||
|
||||
@Override
|
||||
@ -37,7 +40,7 @@ public class SubServer extends Server {
|
||||
*
|
||||
* @param raw JSON representation of the Server
|
||||
*/
|
||||
public SubServer(YAMLSection raw) {
|
||||
public SubServer(ObjectMap<String> raw) {
|
||||
super(raw);
|
||||
}
|
||||
|
||||
@ -47,7 +50,7 @@ public class SubServer extends Server {
|
||||
* @param host Host
|
||||
* @param raw JSON representation of the Server
|
||||
*/
|
||||
SubServer(Host host, YAMLSection raw) {
|
||||
SubServer(Host host, ObjectMap<String> raw) {
|
||||
super(raw);
|
||||
this.host = host;
|
||||
}
|
||||
@ -73,9 +76,9 @@ public class SubServer extends Server {
|
||||
public void start(UUID player, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStartServer(player, getName(), data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(player, getName(), data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -118,9 +121,9 @@ public class SubServer extends Server {
|
||||
public void stop(UUID player, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStopServer(player, getName(), false, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), false, data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -163,9 +166,9 @@ public class SubServer extends Server {
|
||||
public void terminate(UUID player, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStopServer(player, getName(), true, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), true, data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -209,9 +212,9 @@ public class SubServer extends Server {
|
||||
public void command(UUID player, String command, Callback<Integer> response) {
|
||||
if (Util.isNull(command, response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketCommandServer(player, getName(), command, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(player, getName(), command, data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -249,6 +252,104 @@ public class SubServer extends Server {
|
||||
command(command, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param edit Edits
|
||||
* @param response Negative Response Code -or- Positive Success Status
|
||||
*/
|
||||
public void edit(UUID player, ObjectMap<String> edit, Callback<Integer> response) {
|
||||
edit(player, edit, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server
|
||||
*
|
||||
* @param edit Edits
|
||||
* @param response Negative Response Code -or- Positive Success Status
|
||||
*/
|
||||
public void edit(ObjectMap<String> edit, Callback<Integer> response) {
|
||||
edit(null, edit, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param edit Edits
|
||||
*/
|
||||
public void edit(UUID player, ObjectMap<String> edit) {
|
||||
edit(player, edit, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server
|
||||
*
|
||||
* @param edit Edits
|
||||
*/
|
||||
public void edit(ObjectMap<String> edit) {
|
||||
edit(null, edit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server (& Saves Changes)
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param edit Edits
|
||||
* @param response Negative Response Code -or- Positive Success Status
|
||||
*/
|
||||
public void permaEdit(UUID player, ObjectMap<String> edit, Callback<Integer> response) {
|
||||
edit(player, edit, true, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server (& Saves Changes)
|
||||
*
|
||||
* @param edit Edits
|
||||
* @param response Negative Response Code -or- Positive Success Status
|
||||
*/
|
||||
public void permaEdit(ObjectMap<String> edit, Callback<Integer> response) {
|
||||
permaEdit(null, edit, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server (& Saves Changes)
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param edit Edits
|
||||
*/
|
||||
public void permaEdit(UUID player, ObjectMap<String> edit) {
|
||||
permaEdit(player, edit, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server (& Saves Changes)
|
||||
*
|
||||
* @param edit Edits
|
||||
*/
|
||||
public void permaEdit(ObjectMap<String> edit) {
|
||||
permaEdit(null, edit);
|
||||
}
|
||||
|
||||
private void edit(UUID player, ObjectMap<String> edit, boolean perma, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketEditServer(player, getName(), edit, perma, data -> {
|
||||
try {
|
||||
if (data.getInt(0x0001) != 0) {
|
||||
response.run(data.getInt(0x0001) * -1);
|
||||
} else {
|
||||
response.run(data.getInt(0x0002));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Server is Running
|
||||
*
|
||||
@ -304,6 +405,31 @@ public class SubServer extends Server {
|
||||
return raw.getBoolean("enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Server is Enabled
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setEnabled(boolean value) {
|
||||
setEnabled(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Server is Enabled
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setEnabled(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("enabled", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("enabled", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Server is accepting requests to edit()
|
||||
*
|
||||
@ -322,6 +448,31 @@ public class SubServer extends Server {
|
||||
return raw.getBoolean("log");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Server is Logging
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setLogging(boolean value) {
|
||||
setLogging(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Server is Logging
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setLogging(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("log", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("log", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Directory Path
|
||||
*
|
||||
@ -349,6 +500,31 @@ public class SubServer extends Server {
|
||||
return raw.getRawString("stop-cmd");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Command that Stops the Server
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setStopCommand(String value) {
|
||||
setStopCommand(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Command that Stops the Server
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setStopCommand(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("stop-cmd", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("stop-cmd", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action the Server will take when it stops
|
||||
*
|
||||
@ -358,6 +534,31 @@ public class SubServer extends Server {
|
||||
return Util.getDespiteException(() -> StopAction.valueOf(raw.getRawString("stop-action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action the Server will take when it stops
|
||||
*
|
||||
* @param action Stop Action
|
||||
*/
|
||||
public void setStopAction(StopAction action) {
|
||||
setStopAction(action, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action the Server will take when it stops
|
||||
*
|
||||
* @param action Stop Action
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setStopAction(StopAction action, Callback<Boolean> response) {
|
||||
if (Util.isNull(action, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("stop-action", action.toString());
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("stop-action", action.toString());
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Server is compatible
|
||||
*
|
||||
|
@ -1,34 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import org.msgpack.value.Value;
|
||||
|
||||
/**
|
||||
* SubData Cipher Layout Class
|
||||
*/
|
||||
public interface Cipher {
|
||||
/**
|
||||
* Get the name of this Cipher
|
||||
*
|
||||
* @return Cipher Name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Encrypt JSON Data
|
||||
*
|
||||
* @param key Key to Encrypt Data with
|
||||
* @param data Data to Encrypt
|
||||
* @return Encrypted Data Array
|
||||
*/
|
||||
Value encrypt(String key, YAMLSection data) throws Exception;
|
||||
|
||||
/**
|
||||
* Decrypt Encrypted JSON Data
|
||||
*
|
||||
* @param key Key to Decrypt Data with
|
||||
* @param data Encrypted Data Array
|
||||
* @return JSON Data
|
||||
*/
|
||||
YAMLSection decrypt(String key, Value data) throws Exception;
|
||||
}
|
@ -1,333 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Network.Encryption;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import org.json.JSONObject;
|
||||
import org.msgpack.core.MessagePack;
|
||||
import org.msgpack.core.MessagePacker;
|
||||
import org.msgpack.value.Value;
|
||||
import org.msgpack.value.ValueFactory;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.InvalidParameterSpecException;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* A class to perform password-based AES encryption and decryption in CBC mode.
|
||||
* 128, 192, and 256-bit encryption are supported, provided that the latter two
|
||||
* are permitted by the Java runtime's jurisdiction policy files.
|
||||
* <br/>
|
||||
* The public interface for this class consists of the static methods
|
||||
* {@link #encrypt} and {@link #decrypt}, which encrypt and decrypt arbitrary
|
||||
* streams of data, respectively.
|
||||
*
|
||||
* @author dweymouth@gmail.com
|
||||
*/
|
||||
public final class AES implements net.ME1312.SubServers.Host.Network.Cipher {
|
||||
|
||||
// AES specification
|
||||
private static final String CIPHER_SPEC = "AES/CBC/PKCS5Padding";
|
||||
|
||||
// Key derivation specification
|
||||
private static final String KEYGEN_SPEC = "PBKDF2WithHmacSHA1";
|
||||
private static final int SALT_LENGTH = 16; // in bytes
|
||||
private static final int AUTH_KEY_LENGTH = 8; // in bytes
|
||||
private static final int ITERATIONS = 32768;
|
||||
|
||||
// Process input/output streams in chunks
|
||||
private static final int BUFFER_SIZE = 1024;
|
||||
|
||||
// Hold Data for use by SubData Cipher methods
|
||||
private final int keyLength;
|
||||
|
||||
/**
|
||||
* Constructor for use as a SubData Cipher
|
||||
*/
|
||||
public AES(int keyLength) {
|
||||
this.keyLength = keyLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new pseudorandom salt of the specified length
|
||||
*/
|
||||
private static byte[] generateSalt(int length) {
|
||||
Random r = new SecureRandom();
|
||||
byte[] salt = new byte[length];
|
||||
r.nextBytes(salt);
|
||||
return salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive an AES encryption key and authentication key from given password and salt,
|
||||
* using PBKDF2 key stretching. The authentication key is 64 bits long.
|
||||
* @param keyLength
|
||||
* length of the AES key in bits (128, 192, or 256)
|
||||
* @param password
|
||||
* the password from which to derive the keys
|
||||
* @param salt
|
||||
* the salt from which to derive the keys
|
||||
* @return a Keys object containing the two generated keys
|
||||
*/
|
||||
private static Keys keygen(int keyLength, char[] password, byte[] salt) {
|
||||
SecretKeyFactory factory;
|
||||
try {
|
||||
factory = SecretKeyFactory.getInstance(KEYGEN_SPEC);
|
||||
} catch (NoSuchAlgorithmException impossible) { return null; }
|
||||
// derive a longer key, then split into AES key and authentication key
|
||||
KeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, keyLength + AUTH_KEY_LENGTH * 8);
|
||||
SecretKey tmp = null;
|
||||
try {
|
||||
tmp = factory.generateSecret(spec);
|
||||
} catch (InvalidKeySpecException impossible) { }
|
||||
byte[] fullKey = tmp.getEncoded();
|
||||
SecretKey authKey = new SecretKeySpec( // key for password authentication
|
||||
Arrays.copyOfRange(fullKey, 0, AUTH_KEY_LENGTH), "AES");
|
||||
SecretKey encKey = new SecretKeySpec( // key for AES encryption
|
||||
Arrays.copyOfRange(fullKey, AUTH_KEY_LENGTH, fullKey.length), "AES");
|
||||
return new Keys(encKey, authKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts a stream of data. The encrypted stream consists of a header
|
||||
* followed by the raw AES data. The header is broken down as follows:<br/>
|
||||
* <ul>
|
||||
* <li><b>keyLength</b>: AES key length in bytes (valid for 16, 24, 32) (1 byte)</li>
|
||||
* <li><b>salt</b>: pseudorandom salt used to derive keys from password (16 bytes)</li>
|
||||
* <li><b>authentication key</b> (derived from password and salt, used to
|
||||
* check validity of password upon decryption) (8 bytes)</li>
|
||||
* <li><b>IV</b>: pseudorandom AES initialization vector (16 bytes)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param keyLength
|
||||
* key length to use for AES encryption (must be 128, 192, or 256)
|
||||
* @param password
|
||||
* password to use for encryption
|
||||
* @param input
|
||||
* an arbitrary byte stream to encrypt
|
||||
* @param output
|
||||
* stream to which encrypted data will be written
|
||||
* @throws AES.InvalidKeyLengthException
|
||||
* if keyLength is not 128, 192, or 256
|
||||
* @throws AES.StrongEncryptionNotAvailableException
|
||||
* if keyLength is 192 or 256, but the Java runtime's jurisdiction
|
||||
* policy files do not allow 192- or 256-bit encryption
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void encrypt(int keyLength, String password, InputStream input, OutputStream output)
|
||||
throws InvalidKeyLengthException, StrongEncryptionNotAvailableException, IOException {
|
||||
// Check validity of key length
|
||||
if (keyLength != 128 && keyLength != 192 && keyLength != 256) {
|
||||
throw new InvalidKeyLengthException(keyLength);
|
||||
}
|
||||
|
||||
// generate salt and derive keys for authentication and encryption
|
||||
byte[] salt = generateSalt(SALT_LENGTH);
|
||||
Keys keys = keygen(keyLength, password.toCharArray(), salt);
|
||||
|
||||
// initialize AES encryption
|
||||
Cipher encrypt = null;
|
||||
try {
|
||||
encrypt = Cipher.getInstance(CIPHER_SPEC);
|
||||
encrypt.init(Cipher.ENCRYPT_MODE, keys.encryption);
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException impossible) { }
|
||||
catch (InvalidKeyException e) { // 192 or 256-bit AES not available
|
||||
throw new StrongEncryptionNotAvailableException(keyLength);
|
||||
}
|
||||
|
||||
// get initialization vector
|
||||
byte[] iv = null;
|
||||
try {
|
||||
iv = encrypt.getParameters().getParameterSpec(IvParameterSpec.class).getIV();
|
||||
} catch (InvalidParameterSpecException impossible) { }
|
||||
|
||||
// write authentication and AES initialization data
|
||||
output.write(keyLength / 8);
|
||||
output.write(salt);
|
||||
output.write(keys.authentication.getEncoded());
|
||||
output.write(iv);
|
||||
|
||||
// read data from input into buffer, encrypt and write to output
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int numRead;
|
||||
byte[] encrypted = null;
|
||||
while ((numRead = input.read(buffer)) > 0) {
|
||||
encrypted = encrypt.update(buffer, 0, numRead);
|
||||
if (encrypted != null) {
|
||||
output.write(encrypted);
|
||||
}
|
||||
}
|
||||
try { // finish encryption - do final block
|
||||
encrypted = encrypt.doFinal();
|
||||
} catch (IllegalBlockSizeException | BadPaddingException impossible) { }
|
||||
if (encrypted != null) {
|
||||
output.write(encrypted);
|
||||
}
|
||||
output.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls to {@link #encrypt(int, String, InputStream, OutputStream)}, simplified for the {@link net.ME1312.SubServers.Host.Network.Cipher} interface.
|
||||
*
|
||||
* @param key Key to Encrypt Data with
|
||||
* @param data Data to Encrypt
|
||||
* @return Encrypted Data Array
|
||||
*/
|
||||
public Value encrypt(String key, YAMLSection data) throws Exception {
|
||||
ByteArrayOutputStream unencrypted = new ByteArrayOutputStream();
|
||||
MessagePacker packer = MessagePack.newDefaultPacker(unencrypted);
|
||||
packer.packValue(SubDataClient.convert(data));
|
||||
packer.close();
|
||||
|
||||
ByteArrayOutputStream encrypted = new ByteArrayOutputStream();
|
||||
encrypt(keyLength, key, new ByteArrayInputStream(unencrypted.toByteArray()), encrypted);
|
||||
return ValueFactory.newBinary(encrypted.toByteArray(), true);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "AES_" + keyLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a stream of data that was encrypted by {@link #encrypt}.
|
||||
* @param password
|
||||
* the password used to encrypt/decrypt the stream
|
||||
* @param input
|
||||
* stream of encrypted data to be decrypted
|
||||
* @param output
|
||||
* stream to which decrypted data will be written
|
||||
* @return the key length for the decrypted stream (128, 192, or 256)
|
||||
* @throws AES.InvalidPasswordException
|
||||
* if the given password was not used to encrypt the data
|
||||
* @throws AES.InvalidAESStreamException
|
||||
* if the given input stream is not a valid AES-encrypted stream
|
||||
* @throws AES.StrongEncryptionNotAvailableException
|
||||
* if the stream is 192 or 256-bit encrypted, and the Java runtime's
|
||||
* jurisdiction policy files do not allow for AES-192 or 256
|
||||
* @throws IOException
|
||||
*/
|
||||
public static int decrypt(String password, InputStream input, OutputStream output)
|
||||
throws InvalidPasswordException, InvalidAESStreamException, IOException,
|
||||
StrongEncryptionNotAvailableException {
|
||||
int keyLength = input.read() * 8;
|
||||
// Check validity of key length
|
||||
if (keyLength != 128 && keyLength != 192 && keyLength != 256) {
|
||||
throw new InvalidAESStreamException();
|
||||
}
|
||||
|
||||
// read salt, generate keys, and authenticate password
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
input.read(salt);
|
||||
Keys keys = keygen(keyLength, password.toCharArray(), salt);
|
||||
byte[] authRead = new byte[AUTH_KEY_LENGTH];
|
||||
input.read(authRead);
|
||||
if (!Arrays.equals(keys.authentication.getEncoded(), authRead)) {
|
||||
throw new InvalidPasswordException();
|
||||
}
|
||||
|
||||
// initialize AES decryption
|
||||
byte[] iv = new byte[16]; // 16-byte I.V. regardless of key size
|
||||
input.read(iv);
|
||||
Cipher decrypt = null;
|
||||
try {
|
||||
decrypt = Cipher.getInstance(CIPHER_SPEC);
|
||||
decrypt.init(Cipher.DECRYPT_MODE, keys.encryption, new IvParameterSpec(iv));
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException
|
||||
| InvalidAlgorithmParameterException impossible) { }
|
||||
catch (InvalidKeyException e) { // 192 or 256-bit AES not available
|
||||
throw new StrongEncryptionNotAvailableException(keyLength);
|
||||
}
|
||||
|
||||
// read data from input into buffer, decrypt and write to output
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int numRead;
|
||||
byte[] decrypted;
|
||||
while ((numRead = input.read(buffer)) > 0) {
|
||||
decrypted = decrypt.update(buffer, 0, numRead);
|
||||
if (decrypted != null) {
|
||||
output.write(decrypted);
|
||||
}
|
||||
}
|
||||
try { // finish decryption - do final block
|
||||
decrypted = decrypt.doFinal();
|
||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||
throw new InvalidAESStreamException(e);
|
||||
}
|
||||
if (decrypted != null) {
|
||||
output.write(decrypted);
|
||||
}
|
||||
|
||||
output.flush();
|
||||
return keyLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls to {@link #decrypt(String, InputStream, OutputStream)}), simplified for the {@link net.ME1312.SubServers.Host.Network.Cipher} interface.
|
||||
*
|
||||
* @param key Key to Decrypt Data with
|
||||
* @param data Encrypted Data Array
|
||||
* @return JSON Data
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public YAMLSection decrypt(String key, Value data) throws Exception {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
decrypt(key, new ByteArrayInputStream(data.asBinaryValue().asByteArray()), bytes);
|
||||
return SubDataClient.convert(MessagePack.newDefaultUnpacker(bytes.toByteArray()).unpackValue().asMapValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* A tuple of encryption and authentication keys returned by {@link #keygen}
|
||||
*/
|
||||
private static class Keys {
|
||||
public final SecretKey encryption, authentication;
|
||||
public Keys(SecretKey encryption, SecretKey authentication) {
|
||||
this.encryption = encryption;
|
||||
this.authentication = authentication;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown if an attempt is made to decrypt a stream with an incorrect password.
|
||||
*/
|
||||
public static class InvalidPasswordException extends Exception { }
|
||||
|
||||
/**
|
||||
* Thrown if an attempt is made to encrypt a stream with an invalid AES key length.
|
||||
*/
|
||||
public static class InvalidKeyLengthException extends Exception {
|
||||
InvalidKeyLengthException(int length) {
|
||||
super("Invalid AES key length: " + length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown if 192- or 256-bit AES encryption or decryption is attempted,
|
||||
* but not available on the particular Java platform.
|
||||
*/
|
||||
public static class StrongEncryptionNotAvailableException extends Exception {
|
||||
public StrongEncryptionNotAvailableException(int keySize) {
|
||||
super(keySize + "-bit AES encryption is not available on this Java platform.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown if an attempt is made to decrypt an invalid AES stream.
|
||||
*/
|
||||
public static class InvalidAESStreamException extends Exception {
|
||||
public InvalidAESStreamException() { super(); };
|
||||
public InvalidAESStreamException(Exception e) { super(e); }
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Add Server Packet
|
||||
*/
|
||||
public class PacketAddServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String name;
|
||||
private ObjectMap<String> opt;
|
||||
private boolean subserver;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketAddServer (In)
|
||||
*/
|
||||
public PacketAddServer() {}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer [Server] (Out)
|
||||
*
|
||||
* @param player Player who added
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden If the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketAddServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, ip, port, motd, hidden, restricted)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.subserver = false;
|
||||
|
||||
ObjectMap<String> opt = new ObjectMap<String>();
|
||||
opt.set("address", ip.getHostAddress() + ':' + port);
|
||||
opt.set("motd", motd);
|
||||
opt.set("restricted", restricted);
|
||||
opt.set("hidden", hidden);
|
||||
this.opt = opt;
|
||||
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketAddServer [SubServer] (Out)
|
||||
*
|
||||
* @param player Player who Added
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param host Host of Server
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketAddServer(UUID player, String name, boolean enabled, String host, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.subserver = true;
|
||||
|
||||
ObjectMap<String> opt = new ObjectMap<String>();
|
||||
opt.set("enabled", enabled);
|
||||
opt.set("host", host);
|
||||
opt.set("port", port);
|
||||
opt.set("motd", motd);
|
||||
opt.set("log", log);
|
||||
opt.set("dir", directory);
|
||||
opt.set("exec", executable);
|
||||
opt.set("stop-cmd", stopcmd);
|
||||
opt.set("restricted", restricted);
|
||||
opt.set("hidden", hidden);
|
||||
this.opt = opt;
|
||||
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, name);
|
||||
data.set(0x0002, subserver);
|
||||
data.set(0x0003, opt);
|
||||
if (player != null) data.set(0x0004, player);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Authorization Packet
|
||||
*/
|
||||
public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
private ExHost host;
|
||||
private Logger log = null;
|
||||
|
||||
/**
|
||||
* New PacketAuthorization
|
||||
*
|
||||
* @param host SubServers.Host
|
||||
*/
|
||||
public PacketAuthorization(ExHost host) {
|
||||
if (Util.isNull(host)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("password", host.config.get().getSection("Settings").getSection("SubData").getString("Password"));
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
try {
|
||||
if (data.getInt("r") == 0) {
|
||||
Util.isException(() -> Util.reflect(SubDataClient.class.getDeclaredMethod("sendPacket", NamedContainer.class), host.subdata, new NamedContainer<String, PacketOut>(null, new PacketLinkExHost(host))));
|
||||
} else {
|
||||
log.info.println("Could not authorize SubData connection: " + data.getRawString("m"));
|
||||
host.subdata.destroy(0);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Packet Check Permission
|
||||
*/
|
||||
public class PacketCheckPermission implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<Boolean>[]> callbacks = new HashMap<UUID, Callback<Boolean>[]>();
|
||||
private String name;
|
||||
private UUID player;
|
||||
private String permission;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCheckPermission (In)
|
||||
*/
|
||||
public PacketCheckPermission() {}
|
||||
|
||||
/**
|
||||
* New PacketCheckPermission (Out)
|
||||
*
|
||||
* @param player Player to check on
|
||||
* @param permission Permission to check
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCheckPermission(UUID player, String permission, Callback<Boolean>... callback) {
|
||||
this(null, player, permission, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketCheckPermission (Out)
|
||||
*
|
||||
* @param server Server to check on
|
||||
* @param player Player to check on
|
||||
* @param permission Permission to check
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCheckPermission(String server, UUID player, String permission, Callback<Boolean>... callback) {
|
||||
this.name = server;
|
||||
this.player = player;
|
||||
this.permission = permission;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) throws Throwable {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, player);
|
||||
data.set(0x0002, permission);
|
||||
if (name != null) data.set(0x0003, name);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) throws Throwable {
|
||||
for (Callback<Boolean> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data.getBoolean(0x0001));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -12,12 +13,12 @@ import java.util.UUID;
|
||||
/**
|
||||
* Command Server Packet
|
||||
*/
|
||||
public class PacketCommandServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String command;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCommandServer (In)
|
||||
@ -33,33 +34,33 @@ public class PacketCommandServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCommandServer(UUID player, String server, String command, Callback<YAMLSection>... callback) {
|
||||
public PacketCommandServer(UUID player, String server, String command, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, command, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.command = command;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
data.set("server", server);
|
||||
data.set("command", command);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, command);
|
||||
if (player != null) data.set(0x0003, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,15 +14,16 @@ import java.util.UUID;
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketCreateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String name;
|
||||
private String host;
|
||||
private String template;
|
||||
private Version version;
|
||||
private Integer port;
|
||||
private String id;
|
||||
private boolean waitfor;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (In)
|
||||
@ -40,41 +42,58 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(name, host, template, version, callback)) throw new NullPointerException();
|
||||
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, Callback<ObjectMap<Integer>>... callback) {
|
||||
this(player, name, host, template, version, port, false, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @param host Host to use
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port
|
||||
* @param waitfor Wait until completion to send callback
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, host, template, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.host = host;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.waitfor = waitfor;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
YAMLSection creator = new YAMLSection();
|
||||
creator.set("name", name);
|
||||
creator.set("host", host);
|
||||
creator.set("template", template);
|
||||
creator.set("version", version);
|
||||
if (port != null) creator.set("port", port);
|
||||
data.set("creator", creator);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, name);
|
||||
data.set(0x0002, host);
|
||||
data.set(0x0003, template);
|
||||
if (version != null) data.set(0x0004, version);
|
||||
if (port != null) data.set(0x0005, port);
|
||||
if (player != null) data.set(0x0006, player);
|
||||
if (waitfor) data.set(0x0007, true);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Delete Server Packet
|
||||
*/
|
||||
public class PacketDeleteServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private boolean recycle;
|
||||
private boolean force;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDeleteServer (In)
|
||||
*/
|
||||
public PacketDeleteServer() {}
|
||||
|
||||
/**
|
||||
* New PacketDeleteServer (Out)
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param server Server
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDeleteServer(UUID player, String server, boolean recycle, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.recycle = recycle;
|
||||
this.force = force;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, recycle);
|
||||
data.set(0x0003, force);
|
||||
if (player != null) data.set(0x0004, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,22 +1,23 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Group Info Packet
|
||||
*/
|
||||
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketDownloadGroupInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private String group;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (In)
|
||||
@ -30,29 +31,30 @@ public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadGroupInfo(String group, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadGroupInfo(String group, Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.group = group;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (group != null) json.set("group", group);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
if (group != null) json.set(0x0001, group);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Host Info Packet
|
||||
*/
|
||||
public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String host;
|
||||
private String id;
|
||||
public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private String group;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadHostInfo (In)
|
||||
@ -26,33 +27,34 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadHostInfo (Out)
|
||||
*
|
||||
* @param host Host name (or null for all)
|
||||
* @param group Host name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadHostInfo(String host, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadHostInfo(String group, Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.group = group;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (host != null) json.set("host", host);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
if (group != null) json.set(0x0001, group);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +1,51 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Calendar;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
/**
|
||||
* Download Lang Packet
|
||||
*/
|
||||
public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketOut {
|
||||
private ExHost host;
|
||||
private Logger log = null;
|
||||
|
||||
public PacketDownloadLang() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadLang (In)
|
||||
*
|
||||
* @param host ExHost
|
||||
*/
|
||||
public PacketDownloadLang(ExHost host) {
|
||||
if (Util.isNull(host)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* New PacketDownloadLang (Out)
|
||||
*/
|
||||
public PacketDownloadLang() {}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||
try {
|
||||
Util.reflect(ExHost.class.getDeclaredField("lang"), host, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getSection("Lang").get()));
|
||||
log.info.println("Lang Settings Downloaded");
|
||||
Util.reflect(ExHost.class.getDeclaredField("lang"), host, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
|
||||
log.info("Lang Settings Downloaded");
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
log.error.println(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Network List Packet
|
||||
*/
|
||||
public class PacketDownloadNetworkList implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadNetworkList (In)
|
||||
*/
|
||||
public PacketDownloadNetworkList() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadNetworkList (Out)
|
||||
*
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadNetworkList(Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
if (id != null) {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -1,49 +1,50 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Platform Info Packet
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String id;
|
||||
|
||||
public class PacketDownloadPlatformInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private UUID tracker;
|
||||
/**
|
||||
* New PacketDownloadPlatformInfo
|
||||
*
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadPlatformInfo(Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadPlatformInfo(Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
return data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +1,51 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Player List Packet
|
||||
*/
|
||||
public class PacketDownloadPlayerList implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String id;
|
||||
public class PacketDownloadPlayerList implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlayerList (In)
|
||||
*/
|
||||
public PacketDownloadPlayerList() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlayerList (Out)
|
||||
* New PacketDownloadPlayerList
|
||||
*
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadPlayerList(Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadPlayerList(Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
if (id != null) {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,24 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketDownloadProxyInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, NamedContainer<Boolean, Callback<ObjectMap<String>>[]>> callbacks = new HashMap<UUID, NamedContainer<Boolean, Callback<ObjectMap<String>>[]>>();
|
||||
private String proxy;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo (In)
|
||||
@ -30,29 +32,35 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadProxyInfo(String proxy, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadProxyInfo(String proxy, Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.proxy = proxy;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, new NamedContainer<>(proxy != null && proxy.length() <= 0, callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (proxy != null) json.set("proxy", proxy);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
if (proxy != null) json.set(0x0001, proxy);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
boolean mode = callbacks.get(data.getUUID(0x0000)).name();
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000)).get()) {
|
||||
if (mode) {
|
||||
callback.run((data.contains(0x0002))?new ObjectMap<String>((Map<String, ?>) data.getObject(0x0002)):null);
|
||||
} else callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
}
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Server Info Packet
|
||||
*/
|
||||
public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketDownloadServerInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerInfo (In)
|
||||
@ -30,29 +31,30 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerInfo(String server, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadServerInfo(String server, Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (server != null) json.set("server", server);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
if (server != null) json.set(0x0001, server);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Edit Server Packet
|
||||
*/
|
||||
public class PacketEditServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private ObjectMap<String> edit;
|
||||
private boolean perma;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketEditServer (In)
|
||||
*/
|
||||
public PacketEditServer() {}
|
||||
|
||||
/**
|
||||
* New PacketEditServer (Out)
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param server Server
|
||||
* @param edit Edits
|
||||
* @param perma Save Changes
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketEditServer(UUID player, String server, ObjectMap<String> edit, boolean perma, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.edit = edit;
|
||||
this.perma = perma;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, edit);
|
||||
data.set(0x0003, perma);
|
||||
if (player != null) data.set(0x0004, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,85 +1,87 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import com.dosse.upnp.UPnP;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketExAddServer implements PacketIn, PacketOut {
|
||||
public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
private Logger log = null;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketExAddServer (In)
|
||||
*
|
||||
* @param host SubPlugin
|
||||
* @param host ExHost
|
||||
*/
|
||||
public PacketExAddServer(ExHost host) {
|
||||
if (Util.isNull(host)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExAddServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketExAddServer(int response, String message, String id) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketExAddServer(int response, UUID tracker) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, response);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
Logger logger = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
if (host.servers.keySet().contains(data.getSection("server").getRawString("name").toLowerCase())) {
|
||||
host.subdata.sendPacket(new PacketExAddServer(0, "Server Already Added", (data.contains("id"))?data.getRawString("id"):null));
|
||||
String name = data.getRawString(0x0001);
|
||||
boolean enabled = data.getBoolean(0x0002);
|
||||
int port = data.getInt(0x0003);
|
||||
boolean log = data.getBoolean(0x0004);
|
||||
String dir = data.getRawString(0x0005);
|
||||
String exec = data.getRawString(0x0006);
|
||||
String stopcmd = data.getRawString(0x0007);
|
||||
UUID running = data.contains(0x0008)?data.getUUID(0x0008):null;
|
||||
|
||||
if (host.servers.keySet().contains(name.toLowerCase())) {
|
||||
client.sendPacket(new PacketExAddServer(1, tracker));
|
||||
} 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"),
|
||||
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);
|
||||
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"));
|
||||
if (data.getSection("server").contains("running")) server.start(data.getSection("server").getUUID("running"));
|
||||
host.subdata.sendPacket(new PacketExAddServer(0, "Server Added Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
||||
SubServer server = new SubServer(host, name, enabled, port, log, dir, exec, stopcmd);
|
||||
host.servers.put(name.toLowerCase(), server);
|
||||
if (UPnP.isUPnPAvailable() && host.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getPort());
|
||||
logger.info("Added SubServer: " + name);
|
||||
if (running != null) server.start(running);
|
||||
client.sendPacket(new PacketExAddServer(0, tracker));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
host.subdata.sendPacket(new PacketExAddServer(1, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketExAddServer(2, tracker));
|
||||
host.log.error.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13.1b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,74 +1,69 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.Initial.InitialPacket;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubCreator;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import org.msgpack.value.Value;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* External Host Configuration Packet
|
||||
*/
|
||||
public class PacketExConfigureHost implements PacketIn, PacketOut {
|
||||
public class PacketExConfigureHost implements PacketObjectIn<Integer>, PacketOut {
|
||||
private static boolean first = false;
|
||||
private ExHost host;
|
||||
private Logger log = null;
|
||||
|
||||
/**
|
||||
* New PacketExConfigureHost
|
||||
*/
|
||||
public PacketExConfigureHost(ExHost host) {
|
||||
this.host = host;
|
||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
public void sending(SubDataClient client) {
|
||||
host.log.info.println("Downloading Host Settings...");
|
||||
first = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
host.host = data.getSection("host").clone();
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
host.host = new ObjectMap<>((Map<String, ?>) data.getObject(0x0000));
|
||||
for (SubCreator.ServerTemplate template : host.templates.values()) {
|
||||
Util.deleteDirectory(template.getDirectory());
|
||||
}
|
||||
host.templates.clear();
|
||||
UniversalFile templates = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates");
|
||||
Util.deleteDirectory(templates);
|
||||
templates.mkdirs();
|
||||
for (String name : data.getSection("templates").getKeys()) {
|
||||
UniversalFile templatedir = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates");
|
||||
ObjectMap<String> templates = new ObjectMap<>((Map<String, ?>) data.getObject(0x0001));
|
||||
Util.deleteDirectory(templatedir);
|
||||
templatedir.mkdirs();
|
||||
for (String name : templates.getKeys()) {
|
||||
try {
|
||||
UniversalFile dir = new UniversalFile(templates, name);
|
||||
dir.mkdirs();
|
||||
Util.unzip(new ByteArrayInputStream(((Value) data.getSection("templates").getSection(name).getObject("files")).asBinaryValue().asByteArray()), dir);
|
||||
SubCreator.ServerTemplate template = new SubCreator.ServerTemplate(name, data.getSection("templates").getSection(name).getBoolean("enabled"), data.getSection("templates").getSection(name).getRawString("icon"), dir,
|
||||
data.getSection("templates").getSection(name).getSection("build").clone(), data.getSection("templates").getSection(name).getSection("settings").clone());
|
||||
UniversalFile dir = new UniversalFile(templatedir, name);
|
||||
SubCreator.ServerTemplate template = new SubCreator.ServerTemplate(name, templates.getMap(name).getBoolean("enabled"), templates.getMap(name).getRawString("icon"), dir,
|
||||
templates.getMap(name).getMap("build").clone(), templates.getMap(name).getMap("settings").clone());
|
||||
host.templates.put(name.toLowerCase(), template);
|
||||
if (!data.getSection("templates").getSection(name).getRawString("display").equals(name)) template.setDisplayName(data.getSection("templates").getSection(name).getRawString("display"));
|
||||
if (!templates.getMap(name).getRawString("display").equals(name)) template.setDisplayName(templates.getMap(name).getRawString("display"));
|
||||
} catch (Exception e) {
|
||||
host.log.error.println("Couldn't load template: " + name);
|
||||
host.log.error.println(e);
|
||||
}
|
||||
}
|
||||
log.info.println(((first)?"":"New ") + "Host Settings Downloaded");
|
||||
host.log.info.println(((first)?"":"New ") + "Host Settings Downloaded");
|
||||
first = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -12,17 +13,17 @@ import java.util.UUID;
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketExCreateServer implements PacketIn, PacketOut {
|
||||
public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private int response;
|
||||
private String message;
|
||||
private YAMLSection info;
|
||||
private String id;
|
||||
private ObjectMap<String> info;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketExCreateServer (In)
|
||||
*
|
||||
* @param host SubPlugin
|
||||
* @param host ExHost
|
||||
*/
|
||||
public PacketExCreateServer(ExHost host) {
|
||||
if (Util.isNull(host)) throw new NullPointerException();
|
||||
@ -35,44 +36,54 @@ public class PacketExCreateServer implements PacketIn, PacketOut {
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param info Creator Info
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketExCreateServer(int response, String message, YAMLSection info, String id) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketExCreateServer(int response, String message, ObjectMap<String> info, UUID tracker) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.info = info;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
data.set("c", info);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, response);
|
||||
data.set(0x0002, info);
|
||||
if (message != null) data.set(0x0003, message);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
host.creator.create(data.getSection("creator").getRawString("name"), host.templates.get(data.getSection("creator").getRawString("template").toLowerCase()), data.getSection("creator").getVersion("version"),
|
||||
data.getSection("creator").getInt("port"), data.getSection("creator").getUUID("log"), (data.contains("id"))?data.getRawString("id"):null);
|
||||
} catch (Throwable e) {
|
||||
if (data.contains("thread")) {
|
||||
host.creator.terminate(data.getRawString("thread").toLowerCase());
|
||||
if (data.contains(0x0001)) {
|
||||
if (data.contains(0x0001)) {
|
||||
host.creator.terminate(data.getRawString(0x0001).toLowerCase());
|
||||
} else {
|
||||
host.creator.terminate();
|
||||
}
|
||||
host.subdata.sendPacket(new PacketExCreateServer(1, e.getClass().getCanonicalName() + ": " + e.getMessage(), null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketExCreateServer(1, null, null, tracker));
|
||||
} else {
|
||||
String name = data.getRawString(0x0002);
|
||||
String template = data.getRawString(0x0003);
|
||||
Version version = (data.contains(0x0004)?data.getVersion(0x0004):null);
|
||||
Integer port = data.getInt(0x0005);
|
||||
UUID log = data.getUUID(0x0006);
|
||||
|
||||
host.creator.create(name, host.templates.get(template.toLowerCase()), version,
|
||||
port, log, tracker);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
host.log.error.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -3,115 +3,120 @@ package net.ME1312.SubServers.Host.Network.Packet;
|
||||
import com.dosse.upnp.UPnP;
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketExDeleteServer implements PacketIn, PacketOut {
|
||||
public class PacketExDeleteServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
private Logger log = null;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketExDeleteServer (In)
|
||||
*
|
||||
* @param host SubPlugin
|
||||
* @param host ExHost
|
||||
*/
|
||||
public PacketExDeleteServer(ExHost host) {
|
||||
if (Util.isNull(host)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExDeleteServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketExDeleteServer(int response, String message, String id) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketExDeleteServer(int response, UUID tracker) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, response);
|
||||
return data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
if (!host.servers.keySet().contains(data.getRawString("server").toLowerCase())) {
|
||||
host.subdata.sendPacket(new PacketExDeleteServer(0, "Server Didn't Exist", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (host.servers.get(data.getRawString("server").toLowerCase()).isRunning()) {
|
||||
host.subdata.sendPacket(new PacketExDeleteServer(2, "That server is still running.", (data.contains("id"))?data.getRawString("id"):null));
|
||||
String name = data.getRawString(0x0001);
|
||||
YAMLSection info = new YAMLSection((Map<String, ?>) data.getObject(0x0002));
|
||||
boolean recycle = data.getBoolean(0x0003, false);
|
||||
|
||||
if (!host.servers.keySet().contains(name.toLowerCase())) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExDeleteServer(1, tracker));
|
||||
} else if (host.servers.get(name.toLowerCase()).isRunning()) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExDeleteServer(3, tracker));
|
||||
} else {
|
||||
SubServer server = host.servers.get(data.getRawString("server").toLowerCase());
|
||||
host.servers.remove(data.getRawString("server").toLowerCase());
|
||||
SubServer server = host.servers.get(name.toLowerCase());
|
||||
host.servers.remove(name.toLowerCase());
|
||||
new Thread(() -> {
|
||||
UniversalFile to = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Recently Deleted:" + server.getName().toLowerCase());
|
||||
try {
|
||||
File from = new File(host.host.getRawString("Directory"), server.getDirectory());
|
||||
if (from.exists()) {
|
||||
log.info.println("Removing Files...");
|
||||
log.info("Removing Files...");
|
||||
if (recycle) {
|
||||
if (to.exists()) {
|
||||
if (to.isDirectory()) Util.deleteDirectory(to);
|
||||
else to.delete();
|
||||
}
|
||||
to.mkdirs();
|
||||
Util.copyDirectory(from, to);
|
||||
}
|
||||
Util.deleteDirectory(from);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error.println(e);
|
||||
SubAPI.getInstance().getAppInfo().getLogger().error.println(e);
|
||||
}
|
||||
|
||||
log.info.println("Saving...");
|
||||
try {
|
||||
log.info("Saving...");
|
||||
if (recycle) try {
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"));
|
||||
data.getSection("info").toJSON().write(writer);
|
||||
info.toJSON().write(writer);
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
log.error.println(e);
|
||||
SubAPI.getInstance().getAppInfo().getLogger().error.println(e);
|
||||
}
|
||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(server.getPort())) UPnP.closePortTCP(server.getPort());
|
||||
log.info.println("Deleted SubServer: " + data.getRawString("server"));
|
||||
host.subdata.sendPacket(new PacketExDeleteServer(0, "Server Deleted Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
||||
log.info("Deleted SubServer: " + name);
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExDeleteServer(0, tracker));
|
||||
}, SubAPI.getInstance().getAppInfo().getName() + "::Server_Deletion(" + server.getName() + ')').start();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
host.subdata.sendPacket(new PacketExDeleteServer(1, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id"))?data.getRawString("id"):null));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExDeleteServer(2, tracker));
|
||||
host.log.error.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketStreamIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* External Host Template Download Packet
|
||||
*/
|
||||
public class PacketExDownloadTemplates implements PacketOut, PacketStreamIn {
|
||||
private ExHost host;
|
||||
|
||||
/**
|
||||
* New PacketExDownloadTemplates
|
||||
*/
|
||||
public PacketExDownloadTemplates(ExHost host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sending(SubDataClient client) throws Throwable {
|
||||
UniversalFile dir = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates");
|
||||
if (dir.exists()) Util.deleteDirectory(dir);
|
||||
host.log.info.println("Downloading Template Files...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, InputStream stream) {
|
||||
try {
|
||||
Util.unzip(stream, new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates"));
|
||||
host.log.info.println("Template Files Downloaded");
|
||||
} catch (Exception e) {
|
||||
SubAPI.getInstance().getAppInfo().getLogger().error.println("Problem decoding template files");
|
||||
SubAPI.getInstance().getAppInfo().getLogger().error.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,83 +1,81 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import com.dosse.upnp.UPnP;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketExRemoveServer implements PacketIn, PacketOut {
|
||||
public class PacketExRemoveServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
private Logger log = null;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketExRemoveServer (In)
|
||||
*
|
||||
* @param host SubPlugin
|
||||
* @param host ExHost
|
||||
*/
|
||||
public PacketExRemoveServer(ExHost host) {
|
||||
if (Util.isNull(host)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExRemoveServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketExRemoveServer(int response, String message, String id) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketExRemoveServer(int response, UUID tracker) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, response);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
if (!host.servers.keySet().contains(data.getRawString("server").toLowerCase())) {
|
||||
host.subdata.sendPacket(new PacketExRemoveServer(0, "Server Didn't Exist", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (host.servers.get(data.getRawString("server").toLowerCase()).isRunning()) {
|
||||
host.subdata.sendPacket(new PacketExRemoveServer(2, "That server is still running.", (data.contains("id"))?data.getRawString("id"):null));
|
||||
String name = data.getRawString(0x0001);
|
||||
if (!host.servers.keySet().contains(name.toLowerCase())) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExRemoveServer(1, tracker));
|
||||
} else if (host.servers.get(name.toLowerCase()).isRunning()) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExRemoveServer(3, tracker));
|
||||
} else {
|
||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(host.servers.get(data.getRawString("server").toLowerCase()).getPort()))
|
||||
UPnP.closePortTCP(host.servers.get(data.getRawString("server").toLowerCase()).getPort());
|
||||
host.servers.remove(data.getRawString("server").toLowerCase());
|
||||
log.info.println("Removed SubServer: " + data.getRawString("server"));
|
||||
host.subdata.sendPacket(new PacketExRemoveServer(0, "Server Removed Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(host.servers.get(name.toLowerCase()).getPort()))
|
||||
UPnP.closePortTCP(host.servers.get(name.toLowerCase()).getPort());
|
||||
host.servers.remove(name.toLowerCase());
|
||||
log.info("Removed SubServer: " + name);
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExRemoveServer(0, tracker));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
host.subdata.sendPacket(new PacketExRemoveServer(1, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id"))?data.getRawString("id"):null));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExRemoveServer(2, tracker));
|
||||
host.log.error.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -13,7 +14,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* Update Server Packet
|
||||
*/
|
||||
public class PacketExUpdateServer implements PacketIn, PacketOut {
|
||||
public class PacketExUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private SubServer server;
|
||||
private UpdateType type;
|
||||
@ -43,7 +44,7 @@ public class PacketExUpdateServer implements PacketIn, PacketOut {
|
||||
|
||||
/**
|
||||
* New PacketExUpdateServer (In)
|
||||
* @param host SubPlugin
|
||||
* @param host ExHost
|
||||
*/
|
||||
public PacketExUpdateServer(ExHost host) {
|
||||
this.host = host;
|
||||
@ -68,27 +69,27 @@ public class PacketExUpdateServer implements PacketIn, PacketOut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("server", server.getName());
|
||||
data.set("type", type.getValue());
|
||||
data.set("args", Arrays.asList(args));
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, server.getName());
|
||||
data.set(0x0001, type.getValue());
|
||||
data.set(0x0002, Arrays.asList(args));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
SubServer server = host.servers.get(data.getString("server").toLowerCase());
|
||||
switch (data.getInt("type")) {
|
||||
SubServer server = host.servers.get(data.getString(0x0000).toLowerCase());
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 0:
|
||||
server.setEnabled(data.getList("args").get(0).asBoolean());
|
||||
server.setEnabled(data.getList(0x0002).get(0).asBoolean());
|
||||
break;
|
||||
case 1:
|
||||
server.start(data.getList("args").get(0).asUUID());
|
||||
server.start(data.getList(0x0002).get(0).asUUID());
|
||||
break;
|
||||
case 2:
|
||||
server.command(data.getList("args").get(0).asRawString());
|
||||
server.command(data.getList(0x0002).get(0).asRawString());
|
||||
break;
|
||||
case 3:
|
||||
server.stop();
|
||||
@ -97,10 +98,10 @@ public class PacketExUpdateServer implements PacketIn, PacketOut {
|
||||
server.terminate();
|
||||
break;
|
||||
case 5:
|
||||
server.setLogging(data.getList("args").get(0).asBoolean());
|
||||
server.setLogging(data.getList(0x0002).get(0).asBoolean());
|
||||
break;
|
||||
case 6:
|
||||
server.setStopCommand(data.getList("args").get(0).asRawString());
|
||||
server.setStopCommand(data.getList(0x0002).get(0).asRawString());
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -109,7 +110,7 @@ public class PacketExUpdateServer implements PacketIn, PacketOut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Reload Packet
|
||||
*/
|
||||
public class PacketInExReload implements PacketObjectIn<Integer> {
|
||||
private ExHost host;
|
||||
|
||||
/**
|
||||
* New PacketInExReload
|
||||
*
|
||||
* @param host Plugin
|
||||
*/
|
||||
public PacketInExReload(ExHost host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||
if (data != null && data.contains(0x0000)) log.warning("Received request for a plugin reload: " + data.getString(0x0000));
|
||||
else log.warning("Received request for a plugin reload");
|
||||
new Thread(() -> {
|
||||
try {
|
||||
host.reload(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, "SubServers.Host::Network_Reload_Handler").start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -11,15 +11,15 @@ import java.util.List;
|
||||
/**
|
||||
* Reset Packet
|
||||
*/
|
||||
public class PacketInReset implements PacketIn {
|
||||
public class PacketInExReset implements PacketObjectIn<Integer> {
|
||||
private ExHost host;
|
||||
|
||||
public PacketInReset(ExHost host) {
|
||||
public PacketInExReset(ExHost host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
List<String> subservers = new ArrayList<String>();
|
||||
subservers.addAll(host.servers.keySet());
|
||||
|
||||
@ -43,7 +43,7 @@ public class PacketInReset implements PacketIn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,135 +1,135 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Event.*;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Run Event Packet
|
||||
*/
|
||||
public class PacketInRunEvent implements PacketIn {
|
||||
private static HashMap<String, List<Callback<YAMLSection>>> callbacks = new HashMap<String, List<Callback<YAMLSection>>>();
|
||||
public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
private static HashMap<String, List<Callback<ObjectMap<String>>>> callbacks = new HashMap<String, List<Callback<ObjectMap<String>>>>();
|
||||
|
||||
/**
|
||||
* New PacketInRunEvent
|
||||
*/
|
||||
public PacketInRunEvent() {
|
||||
callback("SubAddHostEvent", new Callback<YAMLSection>() {
|
||||
public PacketInExRunEvent() {
|
||||
callback("SubAddHostEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubAddHostEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host")));
|
||||
callback("SubAddHostEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubAddProxyEvent", new Callback<YAMLSection>() {
|
||||
callback("SubAddProxyEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubAddProxyEvent(data.getRawString("proxy")));
|
||||
callback("SubAddProxyEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubAddServerEvent", new Callback<YAMLSection>() {
|
||||
callback("SubAddServerEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubAddServerEvent((data.contains("player"))?data.getUUID("player"):null, (data.contains("host"))?data.getRawString("host"):null, data.getRawString("server")));
|
||||
callback("SubAddServerEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubCreateEvent", new Callback<YAMLSection>() {
|
||||
callback("SubCreateEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host"), data.getRawString("name"),
|
||||
data.getRawString("template"), data.getVersion("version"), data.getInt("port")));
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubSendCommandEvent", new Callback<YAMLSection>() {
|
||||
callback("SubSendCommandEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), data.getRawString("command")));
|
||||
callback("SubSendCommandEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubEditServerEvent", new Callback<YAMLSection>() {
|
||||
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new NamedContainer<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
|
||||
callback("SubEditServerEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStartEvent", new Callback<YAMLSection>() {
|
||||
callback("SubStartEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubStartEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server")));
|
||||
callback("SubStartEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStopEvent", new Callback<YAMLSection>() {
|
||||
callback("SubStopEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubStopEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), data.getBoolean("force")));
|
||||
callback("SubStopEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStoppedEvent", new Callback<YAMLSection>() {
|
||||
callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubStoppedEvent(data.getRawString("server")));
|
||||
callback("SubStoppedEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubRemoveServerEvent", new Callback<YAMLSection>() {
|
||||
callback("SubRemoveServerEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubRemoveServerEvent((data.contains("player"))?data.getUUID("player"):null, (data.contains("host"))?data.getRawString("host"):null, data.getRawString("server")));
|
||||
callback("SubRemoveServerEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubRemoveProxyEvent", new Callback<YAMLSection>() {
|
||||
callback("SubRemoveProxyEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubAddProxyEvent(data.getRawString("proxy")));
|
||||
callback("SubRemoveProxyEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubRemoveHostEvent", new Callback<YAMLSection>() {
|
||||
callback("SubRemoveHostEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubRemoveHostEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host")));
|
||||
callback("SubRemoveHostEvent", this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
if (callbacks.keySet().contains(data.getRawString("type"))) {
|
||||
List<Callback<YAMLSection>> callbacks = PacketInRunEvent.callbacks.get(data.getRawString("type"));
|
||||
PacketInRunEvent.callbacks.remove(data.getRawString("type"));
|
||||
for (Callback<YAMLSection> callback : callbacks) {
|
||||
callback.run(data.getSection("args"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
if (callbacks.keySet().contains(data.getString(0x0000))) {
|
||||
List<Callback<ObjectMap<String>>> callbacks = PacketInExRunEvent.callbacks.get(data.getString(0x0000));
|
||||
PacketInExRunEvent.callbacks.remove(data.getString(0x0000));
|
||||
for (Callback<ObjectMap<String>> callback : callbacks) {
|
||||
callback.run(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
|
||||
public static void callback(String event, Callback<YAMLSection> callback) {
|
||||
List<Callback<YAMLSection>> callbacks = (PacketInRunEvent.callbacks.keySet().contains(event))?PacketInRunEvent.callbacks.get(event):new ArrayList<Callback<YAMLSection>>();
|
||||
public static void callback(String event, Callback<ObjectMap<String>> callback) {
|
||||
List<Callback<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.keySet().contains(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Callback<ObjectMap<String>>>();
|
||||
callbacks.add(callback);
|
||||
PacketInRunEvent.callbacks.put(event, callbacks);
|
||||
PacketInExRunEvent.callbacks.put(event, callbacks);
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Reload Packet
|
||||
*/
|
||||
public class PacketInReload implements PacketIn {
|
||||
private ExHost host;
|
||||
private Logger log;
|
||||
|
||||
public PacketInReload(ExHost host) {
|
||||
this.host = host;
|
||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
try {
|
||||
host.reload();
|
||||
} catch (IOException e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -1,55 +1,69 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubData.Client.Protocol.Initial.InitialPacket;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Link Host Packet
|
||||
*/
|
||||
public class PacketLinkExHost implements PacketIn, PacketOut {
|
||||
public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private Logger log;
|
||||
private int channel;
|
||||
|
||||
/**
|
||||
* New PacketLinkHost
|
||||
* New PacketLinkHost (In)
|
||||
*
|
||||
* @param host SubServers.Host
|
||||
*/
|
||||
public PacketLinkExHost(ExHost host) {
|
||||
if (Util.isNull(host)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketLinkHost (Out)
|
||||
*
|
||||
* @param host SubServers.Host
|
||||
*/
|
||||
public PacketLinkExHost(ExHost host, int channel) {
|
||||
if (Util.isNull(host)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("name", host.subdata.getName());
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, host.api.getName());
|
||||
data.set(0x0001, channel);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
if (data.getInt("r") == 0) {
|
||||
Util.isException(() -> Util.reflect(SubDataClient.class.getDeclaredMethod("init"), host.subdata));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) throws Throwable {
|
||||
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
setReady(client, true);
|
||||
} else {
|
||||
log.info.println("Could not link name with host: " + data.getRawString("m"));
|
||||
log.info("Could not link name with host" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
|
||||
GalaxiEngine.getInstance().stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Message Log External Host Packet
|
||||
*/
|
||||
public class PacketOutExLogMessage implements PacketOut {
|
||||
public class PacketOutExLogMessage implements PacketObjectOut<Integer> {
|
||||
private UUID address;
|
||||
private String line;
|
||||
private boolean terminate;
|
||||
|
||||
/**
|
||||
* New PacketInExLogMessage (Out)
|
||||
@ -19,18 +21,30 @@ public class PacketOutExLogMessage implements PacketOut {
|
||||
public PacketOutExLogMessage(UUID address, String line) {
|
||||
this.address = address;
|
||||
this.line = line;
|
||||
this.terminate = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketInExLogMessage (Out)
|
||||
*/
|
||||
public PacketOutExLogMessage(UUID address, boolean terminate) {
|
||||
this.address = address;
|
||||
this.line = null;
|
||||
this.terminate = terminate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("h", address.toString());
|
||||
data.set("m", line);
|
||||
public ObjectMap<Integer> send(SubDataClient client) throws Exception {
|
||||
if (terminate) client.close();
|
||||
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, address);
|
||||
if (line != null) data.set(0x0001, line);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketOut;
|
||||
|
||||
/**
|
||||
* Queue Request Packet
|
||||
@ -15,13 +13,9 @@ public class PacketOutExRequestQueue implements PacketOut {
|
||||
public PacketOutExRequestQueue() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Remove Server Packet
|
||||
*/
|
||||
public class PacketRemoveServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private boolean force;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketRemoveServer (In)
|
||||
*/
|
||||
public PacketRemoveServer() {}
|
||||
|
||||
/**
|
||||
* New PacketRemoveServer (Out)
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param server Server
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketRemoveServer(UUID player, String server, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.force = force;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, force);
|
||||
if (player != null) data.set(0x0003, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,11 +13,11 @@ import java.util.UUID;
|
||||
/**
|
||||
* Restart Server Packet
|
||||
*/
|
||||
public class PacketRestartServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketRestartServer (In)
|
||||
@ -32,31 +32,31 @@ public class PacketRestartServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketRestartServer(UUID player, String server, Callback<YAMLSection>... callback) {
|
||||
public PacketRestartServer(UUID player, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
data.set("server", server);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
if (player != null) data.set(0x0002, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,11 +13,11 @@ import java.util.UUID;
|
||||
/**
|
||||
* Start Server Packet
|
||||
*/
|
||||
public class PacketStartServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketStartServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketStartServer (In)
|
||||
@ -32,31 +32,31 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketStartServer(UUID player, String server, Callback<YAMLSection>... callback) {
|
||||
public PacketStartServer(UUID player, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
data.set("server", server);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
if (player != null) data.set(0x0002, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,12 +13,12 @@ import java.util.UUID;
|
||||
/**
|
||||
* Stop Server Packet
|
||||
*/
|
||||
public class PacketStopServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketStopServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private boolean force;
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID id;
|
||||
|
||||
/**
|
||||
* New PacketStopServer (In)
|
||||
@ -34,33 +34,33 @@ public class PacketStopServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketStopServer(UUID player, String server, boolean force, Callback<YAMLSection>... callback) {
|
||||
public PacketStopServer(UUID player, String server, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, force, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.force = force;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
data.set("server", server);
|
||||
data.set("force", force);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, id);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, force);
|
||||
if (player != null) data.set(0x0003, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
|
||||
/**
|
||||
* PacketIn Layout Class
|
||||
*/
|
||||
public interface PacketIn {
|
||||
/**
|
||||
* Execute Incoming Packet
|
||||
*
|
||||
* @param data Incoming Data
|
||||
*/
|
||||
void execute(YAMLSection data) throws Throwable;
|
||||
|
||||
/**
|
||||
* Get Packet Version
|
||||
*
|
||||
* @return Packet Version
|
||||
*/
|
||||
Version getVersion();
|
||||
|
||||
/**
|
||||
* Check Compatibility with oncoming packet
|
||||
*
|
||||
* @param version Version of oncoming packet
|
||||
* @return Compatibility Status
|
||||
*/
|
||||
default boolean isCompatible(Version version) {
|
||||
return getVersion().equals(version);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
|
||||
/**
|
||||
* PacketOut Layout Class
|
||||
*/
|
||||
public interface PacketOut {
|
||||
/**
|
||||
* Generate JSON Packet Contents
|
||||
*
|
||||
* @return Packet Contents
|
||||
*/
|
||||
YAMLSection generate() throws Throwable;
|
||||
|
||||
/**
|
||||
* Get Packet Version
|
||||
*
|
||||
* @return Packet Version
|
||||
*/
|
||||
Version getVersion();
|
||||
}
|
@ -1,578 +0,0 @@
|
||||
package net.ME1312.SubServers.Host.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Host.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Host.Library.Exception.IllegalPacketException;
|
||||
import net.ME1312.SubServers.Host.Network.Encryption.AES;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import org.json.JSONException;
|
||||
import org.msgpack.core.MessageInsufficientBufferException;
|
||||
import org.msgpack.core.MessagePack;
|
||||
import org.msgpack.core.MessagePacker;
|
||||
import org.msgpack.core.MessageUnpacker;
|
||||
import org.msgpack.value.MapValue;
|
||||
import org.msgpack.value.Value;
|
||||
import org.msgpack.value.ValueFactory;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* SubData Direct Client Class
|
||||
*/
|
||||
public final class SubDataClient {
|
||||
private static HashMap<Class<? extends PacketOut>, NamedContainer<String, String>> pOut = new HashMap<Class<? extends PacketOut>, NamedContainer<String, String>>();
|
||||
private static HashMap<String, HashMap<String, List<PacketIn>>> pIn = new HashMap<String, HashMap<String, List<PacketIn>>>();
|
||||
private static HashMap<String, Cipher> ciphers = new HashMap<String, Cipher>();
|
||||
private static boolean defaults = false;
|
||||
protected static Logger log;
|
||||
private MessagePacker out;
|
||||
private NamedContainer<Boolean, Socket> socket;
|
||||
private String name;
|
||||
private Cipher cipher;
|
||||
private ExHost host;
|
||||
private LinkedList<NamedContainer<String, PacketOut>> queue;
|
||||
|
||||
/**
|
||||
* SubServers Client Instance
|
||||
*
|
||||
* @param host SubServers.Host
|
||||
* @param name Name of Host
|
||||
* @param address Address
|
||||
* @param port Port
|
||||
* @param cipher Cipher
|
||||
* @throws IOException
|
||||
*/
|
||||
public SubDataClient(ExHost host, String name, InetAddress address, int port, Cipher cipher) throws IOException {
|
||||
if (Util.isNull(host, name, address, port)) throw new NullPointerException();
|
||||
socket = new NamedContainer<>(false, new Socket(address, port));
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream());
|
||||
this.queue = new LinkedList<NamedContainer<String, PacketOut>>();
|
||||
this.cipher = (cipher != null)?cipher:new Cipher() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "NONE";
|
||||
}
|
||||
@Override
|
||||
public Value encrypt(String key, YAMLSection data) {
|
||||
return convert(data);
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public YAMLSection decrypt(String key, Value data) {
|
||||
return convert(data.asMapValue());
|
||||
}
|
||||
};
|
||||
|
||||
if (!defaults) loadDefaults();
|
||||
loop();
|
||||
|
||||
sendPacket(new NamedContainer<>(null, new PacketAuthorization(host)));
|
||||
}
|
||||
|
||||
private void init() {
|
||||
sendPacket(new PacketExConfigureHost(host));
|
||||
sendPacket(new PacketDownloadLang());
|
||||
sendPacket(new PacketOutExRequestQueue());
|
||||
while (queue.size() != 0) {
|
||||
sendPacket(queue.get(0));
|
||||
queue.remove(0);
|
||||
}
|
||||
socket.rename(true);
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubNetworkConnectEvent(host.subdata));
|
||||
}
|
||||
|
||||
static {
|
||||
addCipher("AES", new AES(128));
|
||||
addCipher("AES_128", new AES(128));
|
||||
addCipher("AES_192", new AES(192));
|
||||
addCipher("AES_256", new AES(256));
|
||||
} private void loadDefaults() {
|
||||
defaults = true;
|
||||
log = new Logger("SubData");
|
||||
|
||||
registerPacket(new PacketAuthorization(host), "SubData", "Authorization");
|
||||
registerPacket(new PacketCommandServer(), "SubServers", "CommandServer");
|
||||
registerPacket(new PacketCreateServer(), "SubServers", "CreateServer");
|
||||
registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(new PacketDownloadHostInfo(), "SubServers", "DownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(host), "SubServers", "DownloadLang");
|
||||
registerPacket(new PacketDownloadNetworkList(), "SubServers", "DownloadNetworkList");
|
||||
registerPacket(new PacketDownloadPlatformInfo(), "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(new PacketDownloadPlayerList(), "SubServers", "DownloadPlayerList");
|
||||
registerPacket(new PacketDownloadProxyInfo(), "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(new PacketDownloadServerInfo(), "SubServers", "DownloadServerInfo");
|
||||
registerPacket(new PacketExAddServer(host), "SubServers", "ExAddServer");
|
||||
registerPacket(new PacketExConfigureHost(host), "SubServers", "ExConfigureHost");
|
||||
registerPacket(new PacketExCreateServer(host), "SubServers", "ExCreateServer");
|
||||
registerPacket(new PacketExDeleteServer(host), "SubServers", "ExDeleteServer");
|
||||
registerPacket(new PacketExRemoveServer(host), "SubServers", "ExRemoveServer");
|
||||
registerPacket(new PacketExUpdateServer(host), "SubServers", "ExUpdateServer");
|
||||
registerPacket(new PacketInReload(host), "SubServers", "Reload");
|
||||
registerPacket(new PacketInReset(host), "SubServers", "Reset");
|
||||
registerPacket(new PacketInRunEvent(), "SubServers", "RunEvent");
|
||||
registerPacket(new PacketLinkExHost(host), "SubServers", "LinkExHost");
|
||||
registerPacket(new PacketRestartServer(), "SubServers", "RestartServer");
|
||||
registerPacket(new PacketStartServer(), "SubServers", "StartServer");
|
||||
registerPacket(new PacketStopServer(), "SubServers", "StopServer");
|
||||
|
||||
|
||||
registerPacket(PacketAuthorization.class, "SubData", "Authorization");
|
||||
registerPacket(PacketCommandServer.class, "SubServers", "CommandServer");
|
||||
registerPacket(PacketCreateServer.class, "SubServers", "CreateServer");
|
||||
registerPacket(PacketDownloadGroupInfo.class, "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(PacketDownloadHostInfo.class, "SubServers", "DownloadHostInfo");
|
||||
registerPacket(PacketDownloadLang.class, "SubServers", "DownloadLang");
|
||||
registerPacket(PacketDownloadNetworkList.class, "SubServers", "DownloadNetworkList");
|
||||
registerPacket(PacketDownloadPlatformInfo.class, "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(PacketDownloadPlayerList.class, "SubServers", "DownloadPlayerList");
|
||||
registerPacket(PacketDownloadProxyInfo.class, "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(PacketDownloadServerInfo.class, "SubServers", "DownloadServerInfo");
|
||||
registerPacket(PacketExAddServer.class, "SubServers", "ExAddServer");
|
||||
registerPacket(PacketExConfigureHost.class, "SubServers", "ExConfigureHost");
|
||||
registerPacket(PacketExCreateServer.class, "SubServers", "ExCreateServer");
|
||||
registerPacket(PacketExDeleteServer.class, "SubServers", "ExDeleteServer");
|
||||
registerPacket(PacketExRemoveServer.class, "SubServers", "ExRemoveServer");
|
||||
registerPacket(PacketExUpdateServer.class, "SubServers", "ExUpdateServer");
|
||||
registerPacket(PacketLinkExHost.class, "SubServers", "LinkExHost");
|
||||
registerPacket(PacketOutExLogMessage.class, "SubServers", "ExLogMessage");
|
||||
registerPacket(PacketOutExRequestQueue.class, "SubServers", "ExRequestQueue");
|
||||
registerPacket(PacketRestartServer.class, "SubServers", "RestartServer");
|
||||
registerPacket(PacketStartServer.class, "SubServers", "StartServer");
|
||||
registerPacket(PacketStopServer.class, "SubServers", "StopServer");
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}, SubAPI.getInstance().getAppInfo().getName() + "::SubData_Packet_Listener").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)) {
|
||||
try {
|
||||
packet.execute((data.contains("c"))?data.getSection("c"):null);
|
||||
} catch (Throwable e) {
|
||||
log.error.println(new InvocationTargetException(e, "Exception while executing PacketIn"));
|
||||
}
|
||||
}
|
||||
} catch (JSONException | YAMLException e) {
|
||||
log.error.println(new IllegalPacketException("Unknown Packet Format: " + input));
|
||||
} catch (IllegalPacketException e) {
|
||||
log.error.println(e);
|
||||
} catch (Exception e) {
|
||||
log.error.println(new InvocationTargetException(e, "Exception while decoding packet"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Assigned Host Name
|
||||
*
|
||||
* @return Host Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Client Socket
|
||||
*
|
||||
* @return Client Socket
|
||||
*/
|
||||
public Socket getClient() {
|
||||
return socket.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Cipher for use by SubData
|
||||
*
|
||||
* @param cipher Cipher to Add
|
||||
* @param handle Handle to Bind
|
||||
*/
|
||||
public static void addCipher(String handle, Cipher cipher) {
|
||||
if (Util.isNull(cipher)) throw new NullPointerException();
|
||||
if (ciphers.keySet().contains(handle.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new IllegalStateException("Cipher already exists: " + handle);
|
||||
ciphers.put(handle.toUpperCase().replace('-', '_').replace(' ', '_'), cipher);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Ciphers
|
||||
*
|
||||
* @return Cipher Map
|
||||
*/
|
||||
public static Map<String, Cipher> getCiphers() {
|
||||
return new TreeMap<>(ciphers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Client's Cipher
|
||||
*
|
||||
* @return Cipher
|
||||
*/
|
||||
public Cipher getCipher() {
|
||||
return cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Cipher by Handle
|
||||
*
|
||||
* @param handle Handle
|
||||
* @return Cipher
|
||||
*/
|
||||
public static Cipher getCipher(String handle) {
|
||||
return getCiphers().get(handle.toUpperCase().replace('-', '_').replace(' ', '_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register PacketIn to the Network
|
||||
*
|
||||
* @param packet PacketIn to register
|
||||
* @param channel Packet Channel
|
||||
* @param handle Handle to Bind
|
||||
*/
|
||||
public static void registerPacket(PacketIn packet, String channel, String handle) {
|
||||
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
|
||||
HashMap<String, List<PacketIn>> map = (pIn.keySet().contains(channel.toLowerCase()))?pIn.get(channel.toLowerCase()):new HashMap<String, List<PacketIn>>();
|
||||
List<PacketIn> list = (map.keySet().contains(handle))?map.get(handle):new ArrayList<PacketIn>();
|
||||
if (!list.contains(packet)) {
|
||||
list.add(packet);
|
||||
map.put(handle, list);
|
||||
pIn.put(channel.toLowerCase(), map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister PacketIn from the Network
|
||||
*
|
||||
* @param channel Packet Channel
|
||||
* @param packet PacketIn to unregister
|
||||
*/
|
||||
public static void unregisterPacket(String channel, PacketIn packet) {
|
||||
if (Util.isNull(channel, packet)) throw new NullPointerException();
|
||||
if (pIn.keySet().contains(channel.toLowerCase())) {
|
||||
List<String> search = new ArrayList<String>();
|
||||
search.addAll(pIn.get(channel.toLowerCase()).keySet());
|
||||
for (String handle : search) if (pIn.get(channel.toLowerCase()).get(handle).contains(packet)) {
|
||||
List<PacketIn> list = pIn.get(channel.toLowerCase()).get(handle);
|
||||
list.remove(packet);
|
||||
if (list.isEmpty()) {
|
||||
pIn.get(channel.toLowerCase()).remove(handle);
|
||||
if (pIn.get(channel.toLowerCase()).isEmpty()) pIn.remove(channel.toLowerCase());
|
||||
} else {
|
||||
pIn.get(channel.toLowerCase()).put(handle, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register PacketOut to the Network
|
||||
*
|
||||
* @param packet PacketOut to register
|
||||
* @param channel Packet Channel
|
||||
* @param handle Handle to bind
|
||||
*/
|
||||
public static void registerPacket(Class<? extends PacketOut> packet, String channel, String handle) {
|
||||
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
|
||||
pOut.put(packet, new NamedContainer<String, String>(channel.toLowerCase(), handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister PacketOut to the Network
|
||||
*
|
||||
* @param channel Packet Channel
|
||||
* @param packet PacketOut to unregister
|
||||
*/
|
||||
public static void unregisterPacket(String channel, Class<? extends PacketOut> packet) {
|
||||
if (Util.isNull(channel, packet)) throw new NullPointerException();
|
||||
if (pOut.keySet().contains(packet) && pOut.get(packet).name().equalsIgnoreCase(channel)) pOut.remove(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab PacketIn Instances via handle
|
||||
*
|
||||
* @param channel Packet Channel
|
||||
* @param handle Handle
|
||||
* @return PacketIn
|
||||
*/
|
||||
public static List<? extends PacketIn> getPacket(String channel, String handle) {
|
||||
if (Util.isNull(channel, handle)) throw new NullPointerException();
|
||||
return new ArrayList<PacketIn>(pIn.get(channel.toLowerCase()).get(handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Packet to Client
|
||||
*
|
||||
* @param packet Packet to send
|
||||
*/
|
||||
public void sendPacket(PacketOut packet) {
|
||||
if (Util.isNull(packet)) throw new NullPointerException();
|
||||
if (socket.get() == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(null, packet));
|
||||
} else {
|
||||
sendPacket(new NamedContainer<>(null, packet));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(NamedContainer<String, PacketOut> packet) {
|
||||
try {
|
||||
YAMLSection data = encodePacket(packet.get());
|
||||
if (packet.name() != null) data.set("f", packet.name());
|
||||
out.packValue(getCipher().encrypt(host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), data));
|
||||
out.flush();
|
||||
} catch (Throwable e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Forward Packet to Server
|
||||
*
|
||||
* @param packet Packet to send
|
||||
* @param location Where to send
|
||||
*/
|
||||
public void forwardPacket(PacketOut packet, String location) {
|
||||
if (Util.isNull(packet, location)) throw new NullPointerException();
|
||||
if (socket == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(location, packet));
|
||||
} else {
|
||||
sendPacket(new NamedContainer<>(location, packet));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast packet to all Clients
|
||||
*
|
||||
* @param packet Packet to send
|
||||
*/
|
||||
public void broadcastPacket(PacketOut packet) {
|
||||
forwardPacket(packet, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a YAMLSection to a MessagePack Map
|
||||
*
|
||||
* @param config YAMLSection
|
||||
* @return MessagePack Map
|
||||
*/
|
||||
public static MapValue convert(YAMLSection config) {
|
||||
return (MapValue) msgPack(config.get());
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Value msgPack(Object value) {
|
||||
if (value == null) {
|
||||
return ValueFactory.newNil();
|
||||
} else if (value instanceof Value) {
|
||||
return (Value) value;
|
||||
} else if (value instanceof Map) {
|
||||
ValueFactory.MapBuilder map = ValueFactory.newMapBuilder();
|
||||
for (String key : ((Map<String, ?>) value).keySet()) {
|
||||
Value v = msgPack(((Map<String, ?>) value).get(key));
|
||||
if (v != null) map.put(ValueFactory.newString(key), v);
|
||||
}
|
||||
return map.build();
|
||||
} else if (value instanceof Collection) {
|
||||
LinkedList<Value> values = new LinkedList<Value>();
|
||||
for (Object object : (Collection<?>) value) {
|
||||
Value v = msgPack(object);
|
||||
if (v != null) values.add(v);
|
||||
}
|
||||
return ValueFactory.newArray(values);
|
||||
} else if (value instanceof Boolean) {
|
||||
return ValueFactory.newBoolean((boolean) value);
|
||||
} else if (value instanceof Number) {
|
||||
if (((Number) value).doubleValue() == (double)(int) ((Number) value).doubleValue()) {
|
||||
return ValueFactory.newInteger(((Number) value).longValue());
|
||||
} else {
|
||||
return ValueFactory.newFloat(((Number) value).doubleValue());
|
||||
}
|
||||
} else if (value instanceof String) {
|
||||
return ValueFactory.newString((String) value);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a MessagePack Map to a YAMLSection
|
||||
*
|
||||
* @param msgpack MessagePack Map
|
||||
* @return YAMLSection
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static YAMLSection convert(MapValue msgpack) {
|
||||
YAMLSection section = new YAMLSection();
|
||||
|
||||
boolean warned = false;
|
||||
Map<Value, Value> map = msgpack.map();
|
||||
for (Value key : map.keySet()) {
|
||||
if (key.isStringValue()) {
|
||||
section.set(key.asStringValue().asString(), simplify(map.get(key)));
|
||||
} else if (!warned) {
|
||||
new IllegalStateException("MessagePack contains non-string key(s)").printStackTrace();
|
||||
warned = true;
|
||||
}
|
||||
}
|
||||
|
||||
return section;
|
||||
}
|
||||
private static Object simplify(Value value) {
|
||||
Object simple = value;
|
||||
if (value.isNilValue()) {
|
||||
simple = null;
|
||||
} else if (value.isMapValue()) {
|
||||
Map<Value, Value> map = value.asMapValue().map();
|
||||
simple = convert(value.asMapValue());
|
||||
} else if (value.isArrayValue()) {
|
||||
simple = value.asArrayValue().list();
|
||||
} else if (value.isBooleanValue()) {
|
||||
simple = value.asBooleanValue().getBoolean();
|
||||
} else if (value.isFloatValue()) {
|
||||
if (value.asFloatValue().toDouble() == (double)(float) value.asFloatValue().toDouble()) {
|
||||
simple = value.asFloatValue().toFloat();
|
||||
} else {
|
||||
simple = value.asFloatValue().toDouble();
|
||||
}
|
||||
} else if (value.isIntegerValue()) {
|
||||
if (value.asIntegerValue().isInByteRange()) {
|
||||
simple = value.asIntegerValue().asByte();
|
||||
} else if (value.asIntegerValue().isInShortRange()) {
|
||||
simple = value.asIntegerValue().asShort();
|
||||
} else if (value.asIntegerValue().isInIntRange()) {
|
||||
simple = value.asIntegerValue().asInt();
|
||||
} else if (value.asIntegerValue().isInLongRange()) {
|
||||
simple = value.asIntegerValue().asLong();
|
||||
} else {
|
||||
simple = value.asIntegerValue().asBigInteger();
|
||||
}
|
||||
} else if (value.isStringValue()) {
|
||||
simple = value.asStringValue().asString();
|
||||
}
|
||||
|
||||
return simple;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode PacketOut
|
||||
*
|
||||
* @param packet PacketOut
|
||||
* @return JSON Formatted Packet
|
||||
* @throws IllegalPacketException
|
||||
*/
|
||||
private static YAMLSection encodePacket(PacketOut packet) throws IllegalPacketException, InvocationTargetException {
|
||||
YAMLSection json = new YAMLSection();
|
||||
|
||||
if (!pOut.keySet().contains(packet.getClass())) throw new IllegalPacketException("Unknown PacketOut Channel: " + packet.getClass().getCanonicalName());
|
||||
if (packet.getVersion() == null) throw new NullPointerException("PacketOut Version cannot be null: " + packet.getClass().getCanonicalName());
|
||||
|
||||
try {
|
||||
YAMLSection contents = packet.generate();
|
||||
json.set("n", pOut.get(packet.getClass()).name());
|
||||
json.set("h", pOut.get(packet.getClass()).get());
|
||||
json.set("v", packet.getVersion());
|
||||
if (contents != null) json.set("c", contents);
|
||||
} catch (Throwable e) {
|
||||
throw new InvocationTargetException(e, "Exception while encoding packet");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode PacketIn
|
||||
*
|
||||
* @param data Data to Decode
|
||||
* @return PacketIn
|
||||
* @throws IllegalPacketException
|
||||
* @throws InvocationTargetException
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private static List<PacketIn> decodePacket(YAMLSection data) throws IllegalPacketException, InvocationTargetException {
|
||||
if (!data.contains("n") || !data.contains("h") || !data.contains("v")) throw new IllegalPacketException("Unknown Packet Format: " + data.toString());
|
||||
if (!pIn.keySet().contains(data.getRawString("n")) || !pIn.get(data.getRawString("n")).keySet().contains(data.getRawString("h"))) throw new IllegalPacketException("Unknown PacketIn Channel: " + data.getRawString("n") + ':' + data.getRawString("h"));
|
||||
|
||||
List<PacketIn> list = new ArrayList<PacketIn>();
|
||||
for (PacketIn packet : pIn.get(data.getRawString("n")).get(data.getRawString("h"))) {
|
||||
if (packet.isCompatible(data.getVersion("v"))) {
|
||||
list.add(packet);
|
||||
} else {
|
||||
SubAPI.getInstance().getInternals().log.error.println(new IllegalPacketException("Packet Version Mismatch in " + data.getRawString("h") + ": " + data.getRawString("v") + " -> " + packet.getVersion().toFullString()));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops All Connections and Stops the SubData Listener
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void destroy(int reconnect) throws IOException {
|
||||
if (Util.isNull(reconnect)) throw new NullPointerException();
|
||||
if (socket.get() != null) {
|
||||
final Socket socket = this.socket.get();
|
||||
this.socket.set(null);
|
||||
if (!socket.isClosed()) socket.close();
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubNetworkDisconnectEvent());
|
||||
log.info.println("The SubData Connection was closed");
|
||||
if (reconnect > 0) {
|
||||
log.info.println("Attempting to reconnect in " + reconnect + " seconds");
|
||||
Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::SubData_Reconnect_Handler");
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
host.subdata = new SubDataClient(host, name, socket.getInetAddress(), socket.getPort(), cipher);
|
||||
timer.cancel();
|
||||
while (queue.size() != 0) {
|
||||
if (queue.get(0).name() != null) {
|
||||
host.subdata.forwardPacket(queue.get(0).get(), queue.get(0).name());
|
||||
} else {
|
||||
host.subdata.sendPacket(queue.get(0).get());
|
||||
}
|
||||
queue.remove(0);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.warn.println("Connection was unsuccessful, retrying in " + reconnect + " seconds");
|
||||
}
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,192 @@
|
||||
package net.ME1312.SubServers.Host.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubData.Client.SubDataProtocol;
|
||||
import net.ME1312.SubServers.Host.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Host.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SubProtocol extends SubDataProtocol {
|
||||
private static SubProtocol instance;
|
||||
private SubProtocol() {}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static SubProtocol get() {
|
||||
if (instance == null) {
|
||||
instance = new SubProtocol();
|
||||
|
||||
ExHost host = SubAPI.getInstance().getInternals();
|
||||
|
||||
instance.setName("SubServers 2");
|
||||
instance.addVersion(new Version("2.14a+"));
|
||||
|
||||
|
||||
// 00-09: Object Link Packets
|
||||
instance.registerPacket(0x0001, PacketLinkExHost.class);
|
||||
|
||||
instance.registerPacket(0x0001, new PacketLinkExHost(host));
|
||||
|
||||
|
||||
// 10-29: Download Packets
|
||||
instance.registerPacket(0x0010, PacketDownloadLang.class);
|
||||
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
|
||||
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
|
||||
instance.registerPacket(0x0013, PacketDownloadHostInfo.class);
|
||||
instance.registerPacket(0x0014, PacketDownloadGroupInfo.class);
|
||||
instance.registerPacket(0x0015, PacketDownloadServerInfo.class);
|
||||
instance.registerPacket(0x0016, PacketDownloadPlayerList.class);
|
||||
instance.registerPacket(0x0017, PacketCheckPermission.class);
|
||||
|
||||
instance.registerPacket(0x0010, new PacketDownloadLang(host));
|
||||
instance.registerPacket(0x0011, new PacketDownloadPlatformInfo());
|
||||
instance.registerPacket(0x0012, new PacketDownloadProxyInfo());
|
||||
instance.registerPacket(0x0013, new PacketDownloadHostInfo());
|
||||
instance.registerPacket(0x0014, new PacketDownloadGroupInfo());
|
||||
instance.registerPacket(0x0015, new PacketDownloadServerInfo());
|
||||
instance.registerPacket(0x0016, new PacketDownloadPlayerList());
|
||||
instance.registerPacket(0x0017, new PacketCheckPermission());
|
||||
|
||||
|
||||
// 30-49: Control Packets
|
||||
instance.registerPacket(0x0030, PacketCreateServer.class);
|
||||
instance.registerPacket(0x0031, PacketAddServer.class);
|
||||
instance.registerPacket(0x0032, PacketStartServer.class);
|
||||
instance.registerPacket(0x0033, PacketEditServer.class);
|
||||
instance.registerPacket(0x0034, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0035, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0036, PacketStopServer.class);
|
||||
instance.registerPacket(0x0037, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0038, PacketDeleteServer.class);
|
||||
|
||||
instance.registerPacket(0x0030, new PacketCreateServer());
|
||||
instance.registerPacket(0x0031, new PacketAddServer());
|
||||
instance.registerPacket(0x0032, new PacketStartServer());
|
||||
instance.registerPacket(0x0033, new PacketEditServer());
|
||||
instance.registerPacket(0x0034, new PacketRestartServer());
|
||||
instance.registerPacket(0x0035, new PacketCommandServer());
|
||||
instance.registerPacket(0x0036, new PacketStopServer());
|
||||
instance.registerPacket(0x0037, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0038, new PacketDeleteServer());
|
||||
|
||||
|
||||
// 50-69: External Host Packets
|
||||
instance.registerPacket(0x0050, PacketExConfigureHost.class);
|
||||
instance.registerPacket(0x0051, PacketExDownloadTemplates.class);
|
||||
instance.registerPacket(0x0052, PacketOutExRequestQueue.class);
|
||||
instance.registerPacket(0x0053, PacketExCreateServer.class);
|
||||
instance.registerPacket(0x0054, PacketExAddServer.class);
|
||||
instance.registerPacket(0x0055, PacketExUpdateServer.class);
|
||||
instance.registerPacket(0x0056, PacketOutExLogMessage.class);
|
||||
instance.registerPacket(0x0057, PacketExDeleteServer.class);
|
||||
instance.registerPacket(0x0058, PacketExRemoveServer.class);
|
||||
|
||||
instance.registerPacket(0x0050, new PacketExConfigureHost(host));
|
||||
instance.registerPacket(0x0051, new PacketExDownloadTemplates(host));
|
||||
//instance.registerPacket(0x0052, new PacketOutExRequestQueue(host));
|
||||
instance.registerPacket(0x0053, new PacketExCreateServer(host));
|
||||
instance.registerPacket(0x0054, new PacketExAddServer(host));
|
||||
instance.registerPacket(0x0055, new PacketExUpdateServer(host));
|
||||
//instance.registerPacket(0x0056, new PacketOutExLogMessage());
|
||||
instance.registerPacket(0x0057, new PacketExDeleteServer(host));
|
||||
instance.registerPacket(0x0058, new PacketExRemoveServer(host));
|
||||
|
||||
|
||||
// 70-79: External Misc Packets
|
||||
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
|
||||
//instance.registerPacket(0x0071, PacketInExReset.class);
|
||||
//instance.registerPacket(0x0072, PacketInExReload.class);
|
||||
|
||||
instance.registerPacket(0x0070, new PacketInExRunEvent());
|
||||
instance.registerPacket(0x0071, new PacketInExReset(host));
|
||||
instance.registerPacket(0x0072, new PacketInExReload(host));
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Logger getLogger(int channel) {
|
||||
return new net.ME1312.Galaxi.Library.Log.Logger("SubData" + ((channel != 0)?File.separator+"Sub-"+channel:"")).toPrimitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SubDataClient sub(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||
ExHost host = SubAPI.getInstance().getInternals();
|
||||
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("subdata"), host), null);
|
||||
|
||||
int channel = 1;
|
||||
while (map.keySet().contains(channel)) channel++;
|
||||
final int fc = channel;
|
||||
|
||||
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port);
|
||||
map.put(fc, subdata);
|
||||
subdata.sendPacket(new PacketLinkExHost(host, fc));
|
||||
subdata.on.closed(client -> map.remove(fc));
|
||||
|
||||
return subdata;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||
ExHost host = SubAPI.getInstance().getInternals();
|
||||
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("subdata"), host), null);
|
||||
|
||||
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||
subdata.sendPacket(new PacketLinkExHost(host, 0));
|
||||
subdata.sendPacket(new PacketExConfigureHost(host));
|
||||
subdata.sendPacket(new PacketExDownloadTemplates(host));
|
||||
subdata.sendPacket(new PacketDownloadLang());
|
||||
subdata.sendPacket(new PacketOutExRequestQueue());
|
||||
subdata.on.ready(client -> host.engine.getPluginManager().executeEvent(new SubNetworkConnectEvent((SubDataClient) client)));
|
||||
subdata.on.closed(client -> {
|
||||
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
|
||||
host.engine.getPluginManager().executeEvent(event);
|
||||
map.put(0, null);
|
||||
|
||||
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
|
||||
int reconnect = host.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
|
||||
if (Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("reconnect"), host), false) && reconnect > 0
|
||||
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
|
||||
log.info("Attempting reconnect in " + reconnect + " seconds");
|
||||
Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::SubData_Reconnect_Handler");
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Util.reflect(ExHost.class.getDeclaredMethod("connect"), host);
|
||||
timer.cancel();
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getTargetException() instanceof IOException) {
|
||||
log.info("Connection was unsuccessful, retrying in " + reconnect + " seconds");
|
||||
} else e.printStackTrace();
|
||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
|
||||
}
|
||||
});
|
||||
|
||||
return subdata;
|
||||
}
|
||||
|
||||
public SubDataClient open(InetAddress address, int port) throws IOException {
|
||||
return open(getLogger(0), address, port);
|
||||
}
|
||||
}
|
@ -1,17 +1,19 @@
|
||||
package net.ME1312.SubServers.Host;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Plugin.PluginInfo;
|
||||
import net.ME1312.SubData.Client.DataClient;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Network.API.Host;
|
||||
import net.ME1312.SubServers.Host.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Host.Network.API.Server;
|
||||
import net.ME1312.SubServers.Host.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -20,6 +22,7 @@ import java.util.*;
|
||||
public final class SubAPI {
|
||||
private final ExHost host;
|
||||
private static SubAPI api;
|
||||
String name;
|
||||
|
||||
protected SubAPI(ExHost host) {
|
||||
this.host = host;
|
||||
@ -38,14 +41,23 @@ public final class SubAPI {
|
||||
/**
|
||||
* Gets the SubServers Internals
|
||||
*
|
||||
* @return SubServers.Host Internals
|
||||
* @deprecated Use SubAPI Methods when available
|
||||
* @return SubPlugin Internals
|
||||
*/
|
||||
@Deprecated
|
||||
public ExHost getInternals() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Name
|
||||
*
|
||||
* @return Server Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Hosts
|
||||
*
|
||||
@ -54,10 +66,10 @@ public final class SubAPI {
|
||||
public void getHosts(Callback<Map<String, Host>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadHostInfo(null, data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(null, data -> {
|
||||
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
hosts.put(host.toLowerCase(), new Host(data.getSection("hosts").getSection(host)));
|
||||
for (String host : data.getKeys()) {
|
||||
hosts.put(host.toLowerCase(), new Host(data.getMap(host)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -65,7 +77,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -79,10 +91,10 @@ public final class SubAPI {
|
||||
public void getHost(String name, Callback<Host> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadHostInfo(name, data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(name, data -> {
|
||||
Host host = null;
|
||||
if (data.getSection("hosts").getKeys().size() > 0) {
|
||||
host = new Host(data.getSection("hosts").getSection(new LinkedList<String>(data.getSection("hosts").getKeys()).getFirst()));
|
||||
if (data.getKeys().size() > 0) {
|
||||
host = new Host(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -90,7 +102,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
this.host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -103,15 +115,15 @@ public final class SubAPI {
|
||||
public void getGroups(Callback<Map<String, List<Server>>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
||||
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
for (String group : data.getKeys()) {
|
||||
ArrayList<Server> servers = new ArrayList<Server>();
|
||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getSection("groups").getSection(group).getSection(server)));
|
||||
for (String server : data.getMap(group).getKeys()) {
|
||||
if (data.getMap(group).getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getMap(group).getMap(server)));
|
||||
} else {
|
||||
servers.add(new Server(data.getSection("groups").getSection(group).getSection(server)));
|
||||
servers.add(new Server(data.getMap(group).getMap(server)));
|
||||
}
|
||||
}
|
||||
if (servers.size() > 0) groups.put(group, servers);
|
||||
@ -122,7 +134,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -152,16 +164,16 @@ public final class SubAPI {
|
||||
public void getGroup(String name, Callback<List<Server>> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
||||
List<Server> servers = null;
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("groups").getKeys()).getFirst();
|
||||
if (data.getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getKeys()).getFirst();
|
||||
servers = new ArrayList<Server>();
|
||||
for (String server : data.getSection("groups").getSection(key).getKeys()) {
|
||||
if (data.getSection("groups").getSection(key).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getSection("groups").getSection(key).getSection(server)));
|
||||
for (String server : data.getMap(key).getKeys()) {
|
||||
if (data.getMap(key).getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getMap(key).getMap(server)));
|
||||
} else {
|
||||
servers.add(new Server(data.getSection("groups").getSection(key).getSection(server)));
|
||||
servers.add(new Server(data.getMap(key).getMap(server)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,7 +183,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -184,13 +196,13 @@ public final class SubAPI {
|
||||
public void getServers(Callback<Map<String, Server>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadServerInfo(null, data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(null, data -> {
|
||||
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
if (data.getSection("servers").getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.put(server.toLowerCase(), new SubServer(data.getSection("servers").getSection(server)));
|
||||
for (String server : data.getKeys()) {
|
||||
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.put(server.toLowerCase(), new SubServer(data.getMap(server)));
|
||||
} else {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
servers.put(server.toLowerCase(), new Server(data.getMap(server)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +211,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -213,14 +225,14 @@ public final class SubAPI {
|
||||
public void getServer(String name, Callback<Server> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadServerInfo(name, data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(name, data -> {
|
||||
Server server = null;
|
||||
if (data.getSection("servers").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("servers").getKeys()).getFirst();
|
||||
if (data.getSection("servers").getSection(key).getRawString("type", "Server").equals("SubServer")) {
|
||||
server = new SubServer(data.getSection("servers").getSection(key));
|
||||
if (data.getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getKeys()).getFirst();
|
||||
if (data.getMap(key).getRawString("type", "Server").equals("SubServer")) {
|
||||
server = new SubServer(data.getMap(key));
|
||||
} else {
|
||||
server = new Server(data.getSection("servers").getSection(key));
|
||||
server = new Server(data.getMap(key));
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +241,175 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Server to the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void addServer(String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||
addServer(null, name, ip, port, motd, hidden, restricted, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Server to the Network
|
||||
*
|
||||
* @param player Player who added
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden If the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketAddServer(player, name, ip, port, motd, hidden, restricted, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Server to the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
*/
|
||||
public void addServer(String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
||||
addServer(null, name, ip, port, motd, hidden, restricted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Server to the Network
|
||||
*
|
||||
* @param player Player who added
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden If the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
*/
|
||||
public void addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
||||
addServer(player, name, ip, port, motd, hidden, restricted, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Server from the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void removeServer(String name, Callback<Integer> response) {
|
||||
removeServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Server from the Network
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name Name of the Server
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void removeServer(UUID player, String name, Callback<Integer> response) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeServer(player, name, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Server from the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
*/
|
||||
public void removeServer(String name) {
|
||||
removeServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Server from the Network
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name Name of the Server
|
||||
*/
|
||||
public void removeServer(UUID player, String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeServer(player, name, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Force Remove a Server from the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRemoveServer(String name, Callback<Integer> response) {
|
||||
forceRemoveServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force Remove a Server from the Network
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name Name of the Server
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRemoveServer(UUID player, String name, Callback<Integer> response) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeServer(player, name, true, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force Remove a Server from the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
*/
|
||||
public void forceRemoveServer(String name) {
|
||||
forceRemoveServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force Remove a Server from the Network
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name Name of the Server
|
||||
*/
|
||||
public void forceRemoveServer(UUID player, String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
forceRemoveServer(player, name, i -> {});
|
||||
}
|
||||
|
||||
private void removeServer(UUID player, String name, boolean force, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -269,10 +449,10 @@ public final class SubAPI {
|
||||
public void getProxies(Callback<Map<String, Proxy>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
||||
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getSection("proxies").getSection(proxy)));
|
||||
for (String proxy : data.getKeys()) {
|
||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getMap(proxy)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -280,7 +460,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -294,10 +474,10 @@ public final class SubAPI {
|
||||
public void getProxy(String name, Callback<Proxy> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
proxy = new Proxy(data.getSection("proxies").getSection(new LinkedList<String>(data.getSection("proxies").getKeys()).getFirst()));
|
||||
if (data.getKeys().size() > 0) {
|
||||
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -305,7 +485,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -318,10 +498,10 @@ public final class SubAPI {
|
||||
public void getMasterProxy(Callback<Proxy> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getKeys().contains("master")) {
|
||||
proxy = new Proxy(data.getSection("master"));
|
||||
if (data != null) {
|
||||
proxy = new Proxy(data);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -329,7 +509,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -343,10 +523,10 @@ public final class SubAPI {
|
||||
public void getGlobalPlayers(Callback<Collection<NamedContainer<String, UUID>>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadPlayerList(data -> {
|
||||
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerList(data -> {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
for (String id : data.getSection("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(data.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
||||
for (String id : data.getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(data.getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -354,7 +534,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -364,8 +544,12 @@ public final class SubAPI {
|
||||
*
|
||||
* @return SubData Network Manager
|
||||
*/
|
||||
public SubDataClient getSubDataNetwork() {
|
||||
return host.subdata;
|
||||
public DataClient[] getSubDataNetwork() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(host.subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(host.subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,9 @@
|
||||
package net.ME1312.SubServers.Host;
|
||||
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
@ -10,6 +11,7 @@ import net.ME1312.Galaxi.Plugin.Command.Command;
|
||||
import net.ME1312.Galaxi.Plugin.Command.CommandSender;
|
||||
import net.ME1312.Galaxi.Plugin.Command.CompletionHandler;
|
||||
import net.ME1312.Galaxi.Plugin.PluginManager;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Library.TextColor;
|
||||
import net.ME1312.SubServers.Host.Network.API.*;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.*;
|
||||
@ -103,7 +105,7 @@ public class SubCommand {
|
||||
if (!(server instanceof SubServer)) {
|
||||
message += TextColor.WHITE;
|
||||
} else if (((SubServer) server).isRunning()) {
|
||||
if (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||
if (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.RECYCLE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||
message += TextColor.AQUA;
|
||||
} else {
|
||||
message += TextColor.GREEN;
|
||||
@ -136,7 +138,7 @@ public class SubCommand {
|
||||
for (SubServer subserver : host.getSubServers().values()) {
|
||||
if (i != 0) message += div;
|
||||
if (subserver.isRunning()) {
|
||||
if (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||
if (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.RECYCLE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||
message += TextColor.AQUA;
|
||||
} else {
|
||||
message += TextColor.GREEN;
|
||||
@ -169,9 +171,9 @@ public class SubCommand {
|
||||
message = " (master)";
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message += div;
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message += TextColor.GREEN;
|
||||
} else if (proxy.getSubData() != null) {
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
message += TextColor.AQUA;
|
||||
} else if (proxy.isRedis()) {
|
||||
message += TextColor.WHITE;
|
||||
@ -212,7 +214,7 @@ public class SubCommand {
|
||||
sender.sendMessage(" -> Address: " + TextColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
|
||||
if (server instanceof SubServer) sender.sendMessage(" -> Running: " + ((((SubServer) server).isRunning())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||
sender.sendMessage(" -> Connected: " + ((server.getSubData() != null)?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Connected: " + ((server.getSubData()[0] != null)?TextColor.GREEN+"yes"+((server.getSubData().length > 1)?TextColor.AQUA+" +"+(server.getSubData().length-1)+" subchannel"+((server.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Players: " + TextColor.AQUA + server.getPlayers().size() + " online");
|
||||
}
|
||||
sender.sendMessage(" -> MOTD: " + TextColor.WHITE + TextColor.stripColor(server.getMotd()));
|
||||
@ -255,7 +257,7 @@ public class SubCommand {
|
||||
sender.sendMessage(" -> Available: " + ((host.isAvailable())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((host.isEnabled())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Address: " + TextColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host.getSubData() != null) sender.sendMessage(" -> Connected: " + TextColor.GREEN + "yes");
|
||||
if (host.getSubData().length > 0) sender.sendMessage(" -> Connected: " + ((host.getSubData()[0] != null)?TextColor.GREEN+"yes"+((host.getSubData().length > 1)?TextColor.AQUA+" +"+(host.getSubData().length-1)+" subchannel"+((host.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" - " + ((subserver.isEnabled())?TextColor.WHITE:TextColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
@ -273,7 +275,7 @@ public class SubCommand {
|
||||
if (proxy != null) {
|
||||
sender.sendMessage("SubServers > Info on Proxy: " + TextColor.WHITE + proxy.getDisplayName());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + proxy.getName());
|
||||
sender.sendMessage(" -> Connected: " + ((proxy.getSubData() != null)?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?TextColor.GREEN+"yes"+((proxy.getSubData().length > 1)?TextColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?TextColor.GREEN:TextColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + TextColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Signature: " + TextColor.AQUA + proxy.getSignature());
|
||||
@ -433,8 +435,8 @@ public class SubCommand {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
host.subdata.sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||
switch (data.getInt("r")) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
@ -454,10 +456,8 @@ public class SubCommand {
|
||||
sender.sendMessage("That SubServer is already running");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("That SubServer cannot start while these server(s) are running:", data.getRawString("m").split(":\\s")[1]);
|
||||
sender.sendMessage("That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
break;
|
||||
default:
|
||||
host.log.warn.println("PacketStartServer(null, " + args[0] + ") responded with: " + data.getRawString("m"));
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was started successfully");
|
||||
@ -502,8 +502,8 @@ public class SubCommand {
|
||||
TimerTask starter = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
host.subdata.sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||
switch (data.getInt("r")) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
case 4:
|
||||
sender.sendMessage("Could not restart server: That SubServer has disappeared");
|
||||
@ -518,10 +518,8 @@ public class SubCommand {
|
||||
sender.sendMessage("Could not restart server: That SubServer is no longer enabled");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("Could not restart server: That SubServer cannot start while these server(s) are running:", data.getRawString("m").split(":\\s")[1]);
|
||||
sender.sendMessage("Could not restart server: That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
break;
|
||||
default:
|
||||
host.log.warn.println("PacketStartServer(null, " + args[0] + ") responded with: " + data.getRawString("m"));
|
||||
case 8:
|
||||
case 0:
|
||||
case 1:
|
||||
@ -533,12 +531,12 @@ public class SubCommand {
|
||||
};
|
||||
|
||||
final Container<Boolean> listening = new Container<Boolean>(true);
|
||||
PacketInRunEvent.callback("SubStoppedEvent", new Callback<YAMLSection>() {
|
||||
PacketInExRunEvent.callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection json) {
|
||||
public void run(ObjectMap<String> json) {
|
||||
try {
|
||||
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(args[0])) {
|
||||
PacketInRunEvent.callback("SubStoppedEvent", this);
|
||||
PacketInExRunEvent.callback("SubStoppedEvent", this);
|
||||
} else {
|
||||
new Timer(SubAPI.getInstance().getAppInfo().getName() + "::Server_Restart_Command_Handler(" + args[0] + ')').schedule(starter, 100);
|
||||
}
|
||||
@ -546,9 +544,9 @@ public class SubCommand {
|
||||
}
|
||||
});
|
||||
|
||||
host.subdata.sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||
if (data.getInt("r") != 0) listening.set(false);
|
||||
switch (data.getInt("r")) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||
if (data.getInt(0x0001) != 0) listening.set(false);
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
@ -558,8 +556,6 @@ public class SubCommand {
|
||||
case 5:
|
||||
starter.run();
|
||||
break;
|
||||
default:
|
||||
host.log.warn.println("PacketStopServer(null, " + args[0] + ", false) responded with: " + data.getRawString("m"));
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was stopped successfully");
|
||||
@ -585,8 +581,8 @@ public class SubCommand {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
host.subdata.sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||
switch (data.getInt("r")) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
@ -600,10 +596,6 @@ public class SubCommand {
|
||||
case 1:
|
||||
sender.sendMessage("Server was stopped successfully");
|
||||
break;
|
||||
default:
|
||||
host.log.warn.println("PacketStopServer(null, " + args[0] + ", false) responded with: " + data.getRawString("m"));
|
||||
sender.sendMessage("Server was stopped successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
@ -625,8 +617,8 @@ public class SubCommand {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
host.subdata.sendPacket(new PacketStopServer(null, args[0], true, data -> {
|
||||
switch (data.getInt("r")) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], true, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
@ -636,8 +628,6 @@ public class SubCommand {
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer is not running");
|
||||
break;
|
||||
default:
|
||||
host.log.warn.println("PacketStopServer(null, " + args[0] + ", true) responded with: " + data.getRawString("m"));
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was terminated successfully");
|
||||
@ -672,8 +662,8 @@ public class SubCommand {
|
||||
} while ((i + 1) != args.length);
|
||||
}
|
||||
final String cmd = str;
|
||||
host.subdata.sendPacket(new PacketCommandServer(null, args[0], cmd, data -> {
|
||||
switch (data.getInt("r")) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(null, args[0], cmd, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
@ -683,8 +673,6 @@ public class SubCommand {
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer is not running");
|
||||
break;
|
||||
default:
|
||||
host.log.warn.println("PacketCommandServer(null, " + args[0] + ", /" + cmd + ") responded with: " + data.getRawString("m"));
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Command was sent successfully");
|
||||
@ -715,8 +703,8 @@ public class SubCommand {
|
||||
if (args.length > 4 && Util.isException(() -> Integer.parseInt(args[4]))) {
|
||||
sender.sendMessage("Invalid Port Number");
|
||||
} else {
|
||||
host.subdata.sendPacket(new PacketCreateServer(null, args[0], args[1], args[2], new Version(args[3]), (args.length > 4)?Integer.parseInt(args[4]):null, data -> {
|
||||
switch (data.getInt("r")) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(null, args[0], args[1], args[2], new Version(args[3]), (args.length > 4)?Integer.parseInt(args[4]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("Server names cannot use spaces");
|
||||
case 4:
|
||||
@ -738,13 +726,11 @@ public class SubCommand {
|
||||
sender.sendMessage("That Template is not enabled");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("SubCreator cannot create servers before Minecraft 1.8");
|
||||
sender.sendMessage("That Template requires a Minecraft Version to be specified");
|
||||
break;
|
||||
case 11:
|
||||
sender.sendMessage("Invalid Port Number");
|
||||
break;
|
||||
default:
|
||||
host.log.warn.println("PacketCreateServer(null, " + args[0] + ", " + args[1] + ", " + args[2] + ", " + args[3] + ", " + ((args.length > 4)?args[4]:"null") + ") responded with: " + data.getRawString("m"));
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Launching SubCreator...");
|
||||
@ -753,7 +739,7 @@ public class SubCommand {
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <Name> <Host> <Template> <Version> <Port>");
|
||||
sender.sendMessage("Usage: /" + handle + " <Name> <Host> <Template> [Version] [Port]");
|
||||
}
|
||||
}
|
||||
}.autocomplete((sender, handle, args) -> {
|
||||
@ -798,15 +784,16 @@ public class SubCommand {
|
||||
"The <Template> argument is required, and should be the name of",
|
||||
"the template you want to create your server with.",
|
||||
"",
|
||||
"The <Version> argument is required, and should be a version",
|
||||
"string of the type of server that you want to create",
|
||||
"When the [Version] argument is provided, it will set the",
|
||||
"Minecraft version of the type of server that you want to create",
|
||||
"",
|
||||
"When the <Port> argument is provided, it will set the port number",
|
||||
"When the [Port] argument is provided, it will set the port number",
|
||||
"the server will listen on after it has been created.",
|
||||
"",
|
||||
"Examples:",
|
||||
" /create ExampleServer ExampleHost Spigot 1.13.1",
|
||||
" /create ExampleServer ExampleHost Spigot 1.13.1 25565"
|
||||
" /create ExampleServer ExampleHost Spigot",
|
||||
" /create ExampleServer ExampleHost Spigot 1.12.2",
|
||||
" /create ExampleServer ExampleHost Spigot 1.12.2 25565"
|
||||
).register("create");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user