Allow SubProtocol to be extended

This commit is contained in:
ME1312 2020-08-11 20:28:34 -04:00
parent efc12e0649
commit 83041a1f3f
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
42 changed files with 2633 additions and 1512 deletions

View File

@ -30,14 +30,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w30b</version>
<version>20w33a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>20w30b</version>
<version>20w33a</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -15,10 +15,122 @@ import java.io.IOException;
import java.net.InetAddress;
import java.util.logging.Logger;
/**
* SubServers Protocol Class
*/
public class SubProtocol extends SubDataProtocol {
private static SubProtocol instance;
private static Logger log;
private SubProtocol() {}
@SuppressWarnings("deprecation")
protected SubProtocol() {
SubProxy plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2");
setVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
registerPacket(0x0000, PacketLinkProxy.class);
registerPacket(0x0001, PacketLinkExHost.class);
registerPacket(0x0002, PacketLinkServer.class);
registerPacket(0x0000, new PacketLinkProxy(plugin));
registerPacket(0x0001, new PacketLinkExHost(plugin));
registerPacket(0x0002, new PacketLinkServer(plugin));
// 10-2F: Download Packets
registerPacket(0x0010, PacketDownloadLang.class);
registerPacket(0x0011, PacketDownloadPlatformInfo.class);
registerPacket(0x0012, PacketDownloadProxyInfo.class);
registerPacket(0x0013, PacketDownloadHostInfo.class);
registerPacket(0x0014, PacketDownloadGroupInfo.class);
registerPacket(0x0015, PacketDownloadServerInfo.class);
registerPacket(0x0016, PacketDownloadPlayerInfo.class);
registerPacket(0x0017, PacketCheckPermission.class);
registerPacket(0x0018, PacketCheckPermissionResponse.class);
registerPacket(0x0010, new PacketDownloadLang(plugin));
registerPacket(0x0011, new PacketDownloadPlatformInfo(plugin));
registerPacket(0x0012, new PacketDownloadProxyInfo(plugin));
registerPacket(0x0013, new PacketDownloadHostInfo(plugin));
registerPacket(0x0014, new PacketDownloadGroupInfo(plugin));
registerPacket(0x0015, new PacketDownloadServerInfo(plugin));
registerPacket(0x0016, new PacketDownloadPlayerInfo(plugin));
registerPacket(0x0017, new PacketCheckPermission());
registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
registerPacket(0x0030, PacketCreateServer.class);
registerPacket(0x0031, PacketAddServer.class);
registerPacket(0x0032, PacketStartServer.class);
registerPacket(0x0033, PacketUpdateServer.class);
registerPacket(0x0034, PacketEditServer.class);
registerPacket(0x0035, PacketRestartServer.class);
registerPacket(0x0036, PacketCommandServer.class);
registerPacket(0x0037, PacketStopServer.class);
registerPacket(0x0038, PacketRemoveServer.class);
registerPacket(0x0039, PacketDeleteServer.class);
//registerPacket(0x003A, PacketRestoreServer.class); // TODO
//registerPacket(0x003B, PacketTeleportPlayer.class);
//registerPacket(0x003C, PacketTeleportPlayerResponse.class);
registerPacket(0x0030, new PacketCreateServer(plugin));
registerPacket(0x0031, new PacketAddServer(plugin));
registerPacket(0x0032, new PacketStartServer(plugin));
registerPacket(0x0033, new PacketUpdateServer(plugin));
registerPacket(0x0034, new PacketEditServer(plugin));
registerPacket(0x0035, new PacketRestartServer(plugin));
registerPacket(0x0036, new PacketCommandServer(plugin));
registerPacket(0x0037, new PacketStopServer(plugin));
registerPacket(0x0038, new PacketRemoveServer(plugin));
registerPacket(0x0039, new PacketDeleteServer(plugin));
//registerPacket(0x003A, new PacketRestoreServer(plugin)); // TODO
//registerPacket(0x003B, new PacketTeleportPlayer(plugin));
//registerPacket(0x003C, new PacketTeleportPlayerResponse(plugin));
// 50-6F: External Host Packets
registerPacket(0x0050, PacketExConfigureHost.class);
registerPacket(0x0051, PacketExUploadTemplates.class);
registerPacket(0x0052, PacketExDownloadTemplates.class);
//registerPacket(0x0053, PacketInExRequestQueue.class);
registerPacket(0x0054, PacketExCreateServer.class);
registerPacket(0x0055, PacketExAddServer.class);
registerPacket(0x0056, PacketExEditServer.class);
//registerPacket(0x0057, PacketInExLogMessage.class);
registerPacket(0x0058, PacketExRemoveServer.class);
registerPacket(0x0059, PacketExDeleteServer.class);
//registerPacket(0x005A, PacketExRestoreServer.class);
registerPacket(0x0050, new PacketExConfigureHost(plugin));
registerPacket(0x0051, new PacketExUploadTemplates(plugin));
registerPacket(0x0052, new PacketExDownloadTemplates(plugin));
registerPacket(0x0053, new PacketInExRequestQueue(plugin));
registerPacket(0x0054, new PacketExCreateServer(null));
registerPacket(0x0055, new PacketExAddServer());
registerPacket(0x0056, new PacketExEditServer(plugin));
registerPacket(0x0057, new PacketInExLogMessage());
registerPacket(0x0058, new PacketExRemoveServer());
registerPacket(0x0059, new PacketExDeleteServer());
//registerPacket(0x005A, new PacketExRestoreServer());
// 70-7F: External Misc Packets
registerPacket(0x0070, PacketOutExRunEvent.class);
registerPacket(0x0071, PacketOutExReset.class);
registerPacket(0x0072, PacketOutExReload.class);
registerPacket(0x0073, PacketOutExUpdateWhitelist.class);
registerPacket(0x0074, PacketExSyncPlayer.class);
//registerPacket(0x0070, new PacketOutRunEvent());
//registerPacket(0x0071, new PacketOutReset());
//registerPacket(0x0072, new PacketOutReload());
//registerPacket(0x0073, new PacketOutExUpdateWhitelist());
registerPacket(0x0074, new PacketExSyncPlayer(plugin));
}
@SuppressWarnings("deprecation")
public static SubProtocol get() {
@ -27,111 +139,6 @@ public class SubProtocol extends SubDataProtocol {
log = net.ME1312.SubServers.Bungee.Library.Compatibility.Logger.get("SubData");
SubProxy plugin = SubAPI.getInstance().getInternals();
plugin.getPluginManager().registerListener(null, new PacketOutExRunEvent(plugin));
instance.setName("SubServers 2");
instance.setVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
instance.registerPacket(0x0000, PacketLinkProxy.class);
instance.registerPacket(0x0001, PacketLinkExHost.class);
instance.registerPacket(0x0002, PacketLinkServer.class);
instance.registerPacket(0x0000, new PacketLinkProxy(plugin));
instance.registerPacket(0x0001, new PacketLinkExHost(plugin));
instance.registerPacket(0x0002, new PacketLinkServer(plugin));
// 10-2F: 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, PacketDownloadPlayerInfo.class);
instance.registerPacket(0x0017, PacketCheckPermission.class);
instance.registerPacket(0x0018, PacketCheckPermissionResponse.class);
instance.registerPacket(0x0010, new PacketDownloadLang(plugin));
instance.registerPacket(0x0011, new PacketDownloadPlatformInfo(plugin));
instance.registerPacket(0x0012, new PacketDownloadProxyInfo(plugin));
instance.registerPacket(0x0013, new PacketDownloadHostInfo(plugin));
instance.registerPacket(0x0014, new PacketDownloadGroupInfo(plugin));
instance.registerPacket(0x0015, new PacketDownloadServerInfo(plugin));
instance.registerPacket(0x0016, new PacketDownloadPlayerInfo(plugin));
instance.registerPacket(0x0017, new PacketCheckPermission());
instance.registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
instance.registerPacket(0x0033, PacketUpdateServer.class);
instance.registerPacket(0x0034, PacketEditServer.class);
instance.registerPacket(0x0035, PacketRestartServer.class);
instance.registerPacket(0x0036, PacketCommandServer.class);
instance.registerPacket(0x0037, PacketStopServer.class);
instance.registerPacket(0x0038, PacketRemoveServer.class);
instance.registerPacket(0x0039, PacketDeleteServer.class);
//instance.registerPacket(0x003A, PacketRestoreServer.class); // TODO
//instance.registerPacket(0x003B, PacketTeleportPlayer.class);
//instance.registerPacket(0x003C, PacketTeleportPlayerResponse.class);
instance.registerPacket(0x0030, new PacketCreateServer(plugin));
instance.registerPacket(0x0031, new PacketAddServer(plugin));
instance.registerPacket(0x0032, new PacketStartServer(plugin));
instance.registerPacket(0x0033, new PacketUpdateServer(plugin));
instance.registerPacket(0x0034, new PacketEditServer(plugin));
instance.registerPacket(0x0035, new PacketRestartServer(plugin));
instance.registerPacket(0x0036, new PacketCommandServer(plugin));
instance.registerPacket(0x0037, new PacketStopServer(plugin));
instance.registerPacket(0x0038, new PacketRemoveServer(plugin));
instance.registerPacket(0x0039, new PacketDeleteServer(plugin));
//instance.registerPacket(0x003A, new PacketRestoreServer(plugin)); // TODO
//instance.registerPacket(0x003B, new PacketTeleportPlayer(plugin));
//instance.registerPacket(0x003C, new PacketTeleportPlayerResponse(plugin));
// 50-6F: External Host Packets
instance.registerPacket(0x0050, PacketExConfigureHost.class);
instance.registerPacket(0x0051, PacketExUploadTemplates.class);
instance.registerPacket(0x0052, PacketExDownloadTemplates.class);
//instance.registerPacket(0x0053, PacketInExRequestQueue.class);
instance.registerPacket(0x0054, PacketExCreateServer.class);
instance.registerPacket(0x0055, PacketExAddServer.class);
instance.registerPacket(0x0056, PacketExEditServer.class);
//instance.registerPacket(0x0057, PacketInExLogMessage.class);
instance.registerPacket(0x0058, PacketExRemoveServer.class);
instance.registerPacket(0x0059, PacketExDeleteServer.class);
//instance.registerPacket(0x005A, PacketExRestoreServer.class);
instance.registerPacket(0x0050, new PacketExConfigureHost(plugin));
instance.registerPacket(0x0051, new PacketExUploadTemplates(plugin));
instance.registerPacket(0x0052, new PacketExDownloadTemplates(plugin));
instance.registerPacket(0x0053, new PacketInExRequestQueue(plugin));
instance.registerPacket(0x0054, new PacketExCreateServer(null));
instance.registerPacket(0x0055, new PacketExAddServer());
instance.registerPacket(0x0056, new PacketExEditServer(plugin));
instance.registerPacket(0x0057, new PacketInExLogMessage());
instance.registerPacket(0x0058, new PacketExRemoveServer());
instance.registerPacket(0x0059, new PacketExDeleteServer());
//instance.registerPacket(0x005A, new PacketExRestoreServer());
// 70-7F: External Misc Packets
instance.registerPacket(0x0070, PacketOutExRunEvent.class);
instance.registerPacket(0x0071, PacketOutExReset.class);
instance.registerPacket(0x0072, PacketOutExReload.class);
instance.registerPacket(0x0073, PacketOutExUpdateWhitelist.class);
instance.registerPacket(0x0074, PacketExSyncPlayer.class);
//instance.registerPacket(0x0070, new PacketOutRunEvent());
//instance.registerPacket(0x0071, new PacketOutReset());
//instance.registerPacket(0x0072, new PacketOutReload());
//instance.registerPacket(0x0073, new PacketOutExUpdateWhitelist());
instance.registerPacket(0x0074, new PacketExSyncPlayer(plugin));
}
return instance;

View File

@ -48,7 +48,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w30b</version>
<version>20w33a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.Container.NamedContainer;
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.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -18,11 +19,15 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
/**
* Simplified Host Data Class
*/
public class Host {
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
private SubCreator creator;
private List<RemotePlayer> players = null;
ObjectMap<String> raw;
DataClient client;
long timestamp;
/**
@ -31,6 +36,17 @@ public class Host {
* @param raw Raw representation of the Host
*/
public Host(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Host
*
* @param client SubData connection
* @param raw Raw representation of the Host
*/
Host(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -51,12 +67,16 @@ public class Host {
}
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -193,7 +213,7 @@ public class Host {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (SubServer server : getSubServers().values()) for (NamedContainer<String, UUID> player : server.getGlobalPlayers()) ids.add(player.get());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));
@ -363,7 +383,7 @@ public class Host {
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 -> {
client().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) {
@ -500,7 +520,7 @@ public class Host {
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 -> {
client().sendPacket(new PacketRemoveServer(player, name, force, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -686,7 +706,7 @@ public class Host {
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 -> {
client().sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {

View File

@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -17,9 +18,13 @@ import org.bukkit.permissions.Permissible;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified Proxy Data Class
*/
public class Proxy {
ObjectMap<String> raw;
private List<RemotePlayer> players = null;
DataClient client;
long timestamp;
/**
@ -28,6 +33,17 @@ public class Proxy {
* @param raw Raw representation of the Proxy
*/
public Proxy(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Proxy
*
* @param client SubData connection
* @param raw Raw representation of the Proxy
*/
Proxy(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -42,12 +58,16 @@ public class Proxy {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -149,7 +169,7 @@ public class Proxy {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (String id : raw.getMap("players").getKeys()) ids.add(UUID.fromString(id));
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));

View File

@ -3,6 +3,7 @@ package net.ME1312.SubServers.Client.Bukkit.Network.API;
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.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
@ -12,10 +13,14 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.*;
/**
* Simplified RemotePlayer Data Class
*/
public class RemotePlayer {
ObjectMap<String> raw;
private Proxy proxy = null;
private Server server = null;
DataClient client;
long timestamp;
/**
@ -24,6 +29,17 @@ public class RemotePlayer {
* @param raw Raw representation of the Remote Player
*/
public RemotePlayer(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Remote Player
*
* @param client SubData connection
* @param raw Raw representation of the Remote Player
*/
RemotePlayer(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -39,12 +55,16 @@ public class RemotePlayer {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
UUID id = getUniqueId();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> load(data.getMap(id.toString()))));
client().sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> load(data.getMap(id.toString()))));
}
/**

View File

@ -4,6 +4,7 @@ import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -17,9 +18,13 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.*;
/**
* Simplified Server Data Class
*/
public class Server {
ObjectMap<String> raw;
private List<RemotePlayer> players = null;
DataClient client;
long timestamp;
/**
@ -28,6 +33,17 @@ public class Server {
* @param raw Raw representation of the Server
*/
public Server(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Server
*
* @param client SubData connection
* @param raw Raw representation of the Server
*/
Server(DataClient client, ObjectMap<String> raw) {
this.client = (SubDataClient) client;
load(raw);
}
@ -42,12 +58,16 @@ public class Server {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -172,7 +192,7 @@ public class Server {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (String id : raw.getMap("players").getKeys()) ids.add(UUID.fromString(id));
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));

View File

@ -0,0 +1,400 @@
package net.ME1312.SubServers.Client.Bukkit.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified Data Requesting Class
*/
public final class SimplifiedData {
private SimplifiedData() {}
static SubDataClient client(DataClient client) {
return (SubDataClient) ((client != null)? client : SubAPI.getInstance().getSubDataNetwork()[0]);
}
/**
* Requests the Hosts
*
* @param client SubData connection
* @param callback Host Map
*/
public static void requestHosts(DataClient client, Callback<Map<String, Host>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadHostInfo(null, data -> {
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
for (String host : data.getKeys()) {
hosts.put(host.toLowerCase(), new Host(client, data.getMap(host)));
}
try {
callback.run(hosts);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Host
*
* @param client SubData connection
* @param name Host name
* @param callback a Host
*/
public static void requestHost(DataClient client, String name, Callback<Host> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> {
Host host = null;
if (data.getKeys().size() > 0) {
host = new Host(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(host);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Server Groups (Group names are case sensitive here)
*
* @param client SubData connection
* @param callback Group Map
*/
public static void requestGroups(DataClient client, Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(null, data -> {
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
for (String group : data.getKeys()) {
ArrayList<Server> servers = new ArrayList<Server>();
for (String server : data.getMap(group).getKeys()) {
if (data.getMap(group).getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.add(new SubServer(client, data.getMap(group).getMap(server)));
} else {
servers.add(new Server(client, data.getMap(group).getMap(server)));
}
}
if (servers.size() > 0) groups.put(group, servers);
}
try {
callback.run(groups);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Server Groups (Group names are all lowercase here)
*
* @param client SubData connection
* @param callback Group Map
*/
public static void requestLowercaseGroups(DataClient client, Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
requestGroups(client, groups -> {
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
for (String key : groups.keySet()) {
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
}
callback.run(lowercaseGroups);
});
}
/**
* Requests a Server Group (Group names are case insensitive here)
*
* @param client SubData connection
* @param name Group name
* @param callback a Server Group
*/
public static void requestGroup(DataClient client, String name, Callback<NamedContainer<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<Server>();
for (String server : data.getMap(key).getKeys()) {
if (data.getMap(key).getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.add(new SubServer(client, data.getMap(key).getMap(server)));
} else {
servers.add(new Server(client, data.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
}
try {
callback.run(group);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Servers (including SubServers)
*
* @param client SubData connection
* @param callback Server Map
*/
public static void requestServers(DataClient client, Callback<Map<String, Server>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadServerInfo(null, data -> {
TreeMap<String, Server> servers = new TreeMap<String, Server>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.put(server.toLowerCase(), new SubServer(client, data.getMap(server)));
} else {
servers.put(server.toLowerCase(), new Server(client, data.getMap(server)));
}
}
try {
callback.run(servers);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Server
*
* @param client SubData connection
* @param name Server name
* @param callback a Server
*/
public static void requestServer(DataClient client, String name, Callback<Server> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> {
Server server = null;
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(client, data.getMap(key));
} else {
server = new Server(client, data.getMap(key));
}
}
try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the SubServers
*
* @param client SubData connection
* @param callback SubServer Map
*/
public static void requestSubServers(DataClient client, Callback<Map<String, SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
requestServers(client, servers -> {
TreeMap<String, SubServer> subservers = new TreeMap<String, SubServer>();
for (String server : servers.keySet()) {
if (servers.get(server) instanceof SubServer) subservers.put(server, (SubServer) servers.get(server));
}
callback.run(subservers);
});
}
/**
* Requests a SubServer
*
* @param client SubData connection
* @param name SubServer name
* @param callback a SubServer
*/
public static void requestSubServer(DataClient client, String name, Callback<SubServer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
requestServer(client, name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
}
/**
* Requests the known Proxies
*
* @param client SubData connection
* @param callback Proxy Map
*/
public static void requestProxies(DataClient client, Callback<Map<String, Proxy>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(null, data -> {
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
for (String proxy : data.getKeys()) {
proxies.put(proxy.toLowerCase(), new Proxy(client, data.getMap(proxy)));
}
try {
callback.run(proxies);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Proxy
*
* @param client SubData connection
* @param name Proxy name
* @param callback a Proxy
*/
public static void requestProxy(DataClient client, String name, Callback<Proxy> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Request the Master Proxy redis container (null if unavailable)
*
* @param client SubData connection
* @param callback Master Proxy
*/
public static void requestMasterProxy(DataClient client, Callback<Proxy> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(Collections.emptyList(), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests players on this network across all known proxies
*
* @param client SubData connection
* @param callback Remote Player Collection
*/
public static void requestGlobalPlayers(DataClient client, Callback<Map<UUID, RemotePlayer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) {
players.put(UUID.fromString(player), new RemotePlayer(client, data.getMap(player)));
}
try {
callback.run(players);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a player on this network by searching across all known proxies
*
* @param client SubData connection
* @param name Player name
* @param callback Remote Player
*/
public static void requestGlobalPlayer(DataClient client, String name, Callback<RemotePlayer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a player on this network by searching across all known proxies
*
* @param client SubData connection
* @param id Player UUID
* @param callback Remote Player
*/
public static void requestGlobalPlayer(DataClient client, UUID id, Callback<RemotePlayer> callback) {
if (Util.isNull(id, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
}

View File

@ -15,6 +15,9 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
/**
* Simplified SubCreator Data Class
*/
public class SubCreator {
HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
Host host;

View File

@ -3,6 +3,7 @@ package net.ME1312.SubServers.Client.Bukkit.Network.API;
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.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
@ -10,6 +11,9 @@ import net.ME1312.SubServers.Client.Bukkit.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified SubServer Data Class
*/
public class SubServer extends Server {
private List<SubServer> incompatibilities = null;
private List<SubServer> currentIncompatibilities = null;
@ -32,22 +36,33 @@ public class SubServer extends Server {
}
/**
* Create an API representation of a Server
* Create an API representation of a SubServer
*
* @param raw JSON representation of the Server
* @param raw JSON representation of the SubServer
*/
public SubServer(ObjectMap<String> raw) {
super(raw);
super(null, raw);
}
/**
* Create an API representation of a Server
* Create an API representation of a SubServer
*
* @param client SubData connection
* @param raw JSON representation of the SubServer
*/
SubServer(DataClient client, ObjectMap<String> raw) {
super(client, raw);
}
/**
* Create an API representation of a SubServer
*
* @param host Host
* @param raw JSON representation of the Server
* @param raw JSON representation of the SubServer
*/
SubServer(Host host, ObjectMap<String> raw) {
super(raw);
super(host.client, raw);
this.host = host;
}
@ -73,7 +88,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(player, getName(), data -> {
client().sendPacket(new PacketStartServer(player, getName(), data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -118,7 +133,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), false, data -> {
client().sendPacket(new PacketStopServer(player, getName(), false, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -163,7 +178,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), true, data -> {
client().sendPacket(new PacketStopServer(player, getName(), true, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -209,7 +224,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(player, getName(), command, data -> {
client().sendPacket(new PacketCommandServer(player, getName(), command, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -332,7 +347,7 @@ public class SubServer extends Server {
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 -> {
client().sendPacket(new PacketEditServer(player, getName(), edit, perma, data -> {
try {
if (data.getInt(0x0001) != 0) {
response.run(data.getInt(0x0001) * -1);
@ -657,7 +672,7 @@ public class SubServer extends Server {
if (incompatibilities == null) {
LinkedList<String> incompatible = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible-list")) incompatible.add(subserver.toLowerCase());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
client().sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) incompatibilities.add(new SubServer(data.getMap(server)));
@ -701,7 +716,7 @@ public class SubServer extends Server {
if (currentIncompatibilities == null) {
LinkedList<String> incompatible = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible")) incompatible.add(subserver.toLowerCase());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
client().sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) incompatibilities.add(new SubServer(data.getMap(server)));

View File

@ -21,80 +21,84 @@ import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
/**
* SubServers Protocol Class
*/
public class SubProtocol extends SubDataProtocol {
private static SubProtocol instance;
private SubProtocol() {}
@SuppressWarnings("deprecation")
protected SubProtocol() {
SubPlugin plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2");
addVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
registerPacket(0x0002, PacketLinkServer.class);
registerPacket(0x0002, new PacketLinkServer(plugin));
// 10-2F: Download Packets
registerPacket(0x0010, PacketDownloadLang.class);
registerPacket(0x0011, PacketDownloadPlatformInfo.class);
registerPacket(0x0012, PacketDownloadProxyInfo.class);
registerPacket(0x0013, PacketDownloadHostInfo.class);
registerPacket(0x0014, PacketDownloadGroupInfo.class);
registerPacket(0x0015, PacketDownloadServerInfo.class);
registerPacket(0x0016, PacketDownloadPlayerInfo.class);
registerPacket(0x0017, PacketCheckPermission.class);
registerPacket(0x0018, PacketCheckPermissionResponse.class);
registerPacket(0x0010, new PacketDownloadLang(plugin));
registerPacket(0x0011, new PacketDownloadPlatformInfo());
registerPacket(0x0012, new PacketDownloadProxyInfo());
registerPacket(0x0013, new PacketDownloadHostInfo());
registerPacket(0x0014, new PacketDownloadGroupInfo());
registerPacket(0x0015, new PacketDownloadServerInfo());
registerPacket(0x0016, new PacketDownloadPlayerInfo());
registerPacket(0x0017, new PacketCheckPermission());
registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
registerPacket(0x0030, PacketCreateServer.class);
registerPacket(0x0031, PacketAddServer.class);
registerPacket(0x0032, PacketStartServer.class);
registerPacket(0x0033, PacketUpdateServer.class);
registerPacket(0x0034, PacketEditServer.class);
registerPacket(0x0035, PacketRestartServer.class);
registerPacket(0x0036, PacketCommandServer.class);
registerPacket(0x0037, PacketStopServer.class);
registerPacket(0x0038, PacketRemoveServer.class);
registerPacket(0x0039, PacketDeleteServer.class);
registerPacket(0x0030, new PacketCreateServer());
registerPacket(0x0031, new PacketAddServer());
registerPacket(0x0032, new PacketStartServer());
registerPacket(0x0033, new PacketUpdateServer());
registerPacket(0x0034, new PacketEditServer());
registerPacket(0x0035, new PacketRestartServer());
registerPacket(0x0036, new PacketCommandServer());
registerPacket(0x0037, new PacketStopServer());
registerPacket(0x0038, new PacketRemoveServer());
registerPacket(0x0039, new PacketDeleteServer());
// 70-7F: External Misc Packets
//registerPacket(0x0070, PacketInExRunEvent.class);
//registerPacket(0x0071, PacketInExReset.class);
//registerPacket(0x0072, PacketInExReload.class);
registerPacket(0x0070, new PacketInExRunEvent(plugin));
registerPacket(0x0071, new PacketInExReset());
registerPacket(0x0072, new PacketInExReload(plugin));
}
public static SubProtocol get() {
if (instance == null) {
if (instance == null)
instance = new SubProtocol();
SubPlugin plugin = SubAPI.getInstance().getInternals();
instance.setName("SubServers 2");
instance.addVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
instance.registerPacket(0x0002, PacketLinkServer.class);
instance.registerPacket(0x0002, new PacketLinkServer(plugin));
// 10-2F: 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, PacketDownloadPlayerInfo.class);
instance.registerPacket(0x0017, PacketCheckPermission.class);
instance.registerPacket(0x0018, PacketCheckPermissionResponse.class);
instance.registerPacket(0x0010, new PacketDownloadLang(plugin));
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 PacketDownloadPlayerInfo());
instance.registerPacket(0x0017, new PacketCheckPermission());
instance.registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
instance.registerPacket(0x0033, PacketUpdateServer.class);
instance.registerPacket(0x0034, PacketEditServer.class);
instance.registerPacket(0x0035, PacketRestartServer.class);
instance.registerPacket(0x0036, PacketCommandServer.class);
instance.registerPacket(0x0037, PacketStopServer.class);
instance.registerPacket(0x0038, PacketRemoveServer.class);
instance.registerPacket(0x0039, PacketDeleteServer.class);
instance.registerPacket(0x0030, new PacketCreateServer());
instance.registerPacket(0x0031, new PacketAddServer());
instance.registerPacket(0x0032, new PacketStartServer());
instance.registerPacket(0x0033, new PacketUpdateServer());
instance.registerPacket(0x0034, new PacketEditServer());
instance.registerPacket(0x0035, new PacketRestartServer());
instance.registerPacket(0x0036, new PacketCommandServer());
instance.registerPacket(0x0037, new PacketStopServer());
instance.registerPacket(0x0038, new PacketRemoveServer());
instance.registerPacket(0x0039, new PacketDeleteServer());
// 70-7F: External Misc Packets
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
//instance.registerPacket(0x0071, PacketInExReset.class);
//instance.registerPacket(0x0072, PacketInExReload.class);
instance.registerPacket(0x0070, new PacketInExRunEvent(plugin));
instance.registerPacket(0x0071, new PacketInExReset());
instance.registerPacket(0x0072, new PacketInExReload(plugin));
}
return instance;
}

View File

@ -16,6 +16,8 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.util.*;
import static net.ME1312.SubServers.Client.Bukkit.Network.API.SimplifiedData.*;
/**
* SubAPI Class
*/
@ -75,22 +77,7 @@ public final class SubAPI {
* @param callback Host Map
*/
public void getHosts(Callback<Map<String, Host>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(null, data -> {
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
for (String host : data.getKeys()) {
hosts.put(host.toLowerCase(), new Host(data.getMap(host)));
}
try {
callback.run(hosts);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestHosts(null, callback);
}
/**
@ -100,22 +87,7 @@ public final class SubAPI {
* @param callback a Host
*/
public void getHost(String name, Callback<Host> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> {
Host host = null;
if (data.getKeys().size() > 0) {
host = new Host(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(host);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestHost(null, name, callback);
}
/**
@ -124,30 +96,7 @@ public final class SubAPI {
* @param callback Group Map
*/
public void getGroups(Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(null, data -> {
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
for (String group : data.getKeys()) {
ArrayList<Server> servers = new ArrayList<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.getMap(group).getMap(server)));
}
}
if (servers.size() > 0) groups.put(group, servers);
}
try {
callback.run(groups);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGroups(null, callback);
}
/**
@ -156,14 +105,7 @@ public final class SubAPI {
* @param callback Group Map
*/
public void getLowercaseGroups(Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
getGroups(groups -> {
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
for (String key : groups.keySet()) {
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
}
callback.run(lowercaseGroups);
});
requestLowercaseGroups(null, callback);
}
/**
@ -173,31 +115,7 @@ public final class SubAPI {
* @param callback a Server Group
*/
public void getGroup(String name, Callback<NamedContainer<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<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.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
}
try {
callback.run(group);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGroup(null, name, callback);
}
/**
@ -206,26 +124,7 @@ public final class SubAPI {
* @param callback Server Map
*/
public void getServers(Callback<Map<String, Server>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(null, data -> {
TreeMap<String, Server> servers = new TreeMap<String, 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.getMap(server)));
}
}
try {
callback.run(servers);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestServers(null, callback);
}
/**
@ -235,27 +134,7 @@ public final class SubAPI {
* @param callback a Server
*/
public void getServer(String name, Callback<Server> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> {
Server server = null;
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.getMap(key));
}
}
try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestServer(null, name, callback);
}
/**
@ -432,14 +311,7 @@ public final class SubAPI {
* @param callback SubServer Map
*/
public void getSubServers(Callback<Map<String, SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
getServers(servers -> {
TreeMap<String, SubServer> subservers = new TreeMap<String, SubServer>();
for (String server : servers.keySet()) {
if (servers.get(server) instanceof SubServer) subservers.put(server, (SubServer) servers.get(server));
}
callback.run(subservers);
});
requestSubServers(null, callback);
}
/**
@ -449,8 +321,7 @@ public final class SubAPI {
* @param callback a SubServer
*/
public void getSubServer(String name, Callback<SubServer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
getServer(name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
requestSubServer(null, name, callback);
}
/**
@ -459,22 +330,7 @@ public final class SubAPI {
* @param callback Proxy Map
*/
public void getProxies(Callback<Map<String, Proxy>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(null, data -> {
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
for (String proxy : data.getKeys()) {
proxies.put(proxy.toLowerCase(), new Proxy(data.getMap(proxy)));
}
try {
callback.run(proxies);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestProxies(null, callback);
}
/**
@ -484,120 +340,45 @@ public final class SubAPI {
* @param callback a Proxy
*/
public void getProxy(String name, Callback<Proxy> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestProxy(null, name, callback);
}
/**
* Get the Master Proxy redis container (null if unavailable)
* Get the Master Proxy Container
*
* @param callback Master Proxy
*/
public void getMasterProxy(Callback<Proxy> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.emptyList(), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestMasterProxy(null, callback);
}
/**
* Get players on this network across all known proxies
* Gets players on this network across all known proxies
*
* @param callback Remote Player Collection
*/
public void getGlobalPlayers(Callback<Map<UUID, RemotePlayer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) {
players.put(UUID.fromString(player), new RemotePlayer(data.getMap(player)));
}
try {
callback.run(players);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayers(null, callback);
}
/**
* Get a player on this network by searching across all known proxies
* Gets a player on this network by searching across all known proxies
*
* @param name Player name
* @param callback Remote Player
*/
public void getGlobalPlayer(String name, Callback<RemotePlayer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayer(null, name, callback);
}
/**
* Get a player on this network by searching across all known proxies
* Gets a player on this network by searching across all known proxies
*
* @param id Player UUID
* @param callback Remote Player
*/
public void getGlobalPlayer(UUID id, Callback<RemotePlayer> callback) {
if (Util.isNull(id, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayer(null, id, callback);
}
/**

View File

@ -30,7 +30,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w30b</version>
<version>20w33a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.Container.NamedContainer;
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.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -18,11 +19,15 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
/**
* Simplified Host Data Class
*/
public class Host {
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
private SubCreator creator;
private List<RemotePlayer> players = null;
ObjectMap<String> raw;
DataClient client;
long timestamp;
/**
@ -31,6 +36,17 @@ public class Host {
* @param raw Raw representation of the Host
*/
public Host(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Host
*
* @param client SubData connection
* @param raw Raw representation of the Host
*/
Host(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -51,12 +67,16 @@ public class Host {
}
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -193,7 +213,7 @@ public class Host {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (SubServer server : getSubServers().values()) for (NamedContainer<String, UUID> player : server.getGlobalPlayers()) ids.add(player.get());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));
@ -363,7 +383,7 @@ public class Host {
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 -> {
client().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) {
@ -500,7 +520,7 @@ public class Host {
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 -> {
client().sendPacket(new PacketRemoveServer(player, name, force, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -686,7 +706,7 @@ public class Host {
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 -> {
client().sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {

View File

@ -1,10 +1,11 @@
package net.ME1312.SubServers.Client.Sponge.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -17,9 +18,13 @@ import org.spongepowered.api.service.permission.Subject;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified Proxy Data Class
*/
public class Proxy {
ObjectMap<String> raw;
private List<RemotePlayer> players = null;
DataClient client;
long timestamp;
/**
@ -28,6 +33,17 @@ public class Proxy {
* @param raw Raw representation of the Proxy
*/
public Proxy(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Proxy
*
* @param client SubData connection
* @param raw Raw representation of the Proxy
*/
Proxy(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -42,12 +58,16 @@ public class Proxy {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -149,7 +169,7 @@ public class Proxy {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (String id : raw.getMap("players").getKeys()) ids.add(UUID.fromString(id));
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));

View File

@ -3,21 +3,23 @@ package net.ME1312.SubServers.Client.Sponge.Network.API;
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.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Client.Sponge.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Calendar;
import java.util.Collections;
import java.util.UUID;
import java.util.*;
/**
* Simplified RemotePlayer Data Class
*/
public class RemotePlayer {
ObjectMap<String> raw;
private Proxy proxy = null;
private Server server = null;
DataClient client;
long timestamp;
/**
@ -26,6 +28,17 @@ public class RemotePlayer {
* @param raw Raw representation of the Remote Player
*/
public RemotePlayer(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Remote Player
*
* @param client SubData connection
* @param raw Raw representation of the Remote Player
*/
RemotePlayer(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -41,12 +54,16 @@ public class RemotePlayer {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
UUID id = getUniqueId();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> load(data.getMap(id.toString()))));
client().sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> load(data.getMap(id.toString()))));
}
/**

View File

@ -1,9 +1,10 @@
package net.ME1312.SubServers.Client.Sponge.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -17,9 +18,13 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.*;
/**
* Simplified Server Data Class
*/
public class Server {
ObjectMap<String> raw;
private List<RemotePlayer> players = null;
DataClient client;
long timestamp;
/**
@ -28,6 +33,17 @@ public class Server {
* @param raw Raw representation of the Server
*/
public Server(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Server
*
* @param client SubData connection
* @param raw Raw representation of the Server
*/
Server(DataClient client, ObjectMap<String> raw) {
this.client = (SubDataClient) client;
load(raw);
}
@ -42,12 +58,16 @@ public class Server {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -172,7 +192,7 @@ public class Server {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (String id : raw.getMap("players").getKeys()) ids.add(UUID.fromString(id));
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));

View File

@ -0,0 +1,400 @@
package net.ME1312.SubServers.Client.Sponge.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
import net.ME1312.SubServers.Client.Sponge.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified Data Requesting Class
*/
public final class SimplifiedData {
private SimplifiedData() {}
static SubDataClient client(DataClient client) {
return (SubDataClient) ((client != null)? client : SubAPI.getInstance().getSubDataNetwork()[0]);
}
/**
* Requests the Hosts
*
* @param client SubData connection
* @param callback Host Map
*/
public static void requestHosts(DataClient client, Callback<Map<String, Host>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadHostInfo(null, data -> {
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
for (String host : data.getKeys()) {
hosts.put(host.toLowerCase(), new Host(client, data.getMap(host)));
}
try {
callback.run(hosts);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Host
*
* @param client SubData connection
* @param name Host name
* @param callback a Host
*/
public static void requestHost(DataClient client, String name, Callback<Host> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> {
Host host = null;
if (data.getKeys().size() > 0) {
host = new Host(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(host);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Server Groups (Group names are case sensitive here)
*
* @param client SubData connection
* @param callback Group Map
*/
public static void requestGroups(DataClient client, Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(null, data -> {
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
for (String group : data.getKeys()) {
ArrayList<Server> servers = new ArrayList<Server>();
for (String server : data.getMap(group).getKeys()) {
if (data.getMap(group).getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.add(new SubServer(client, data.getMap(group).getMap(server)));
} else {
servers.add(new Server(client, data.getMap(group).getMap(server)));
}
}
if (servers.size() > 0) groups.put(group, servers);
}
try {
callback.run(groups);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Server Groups (Group names are all lowercase here)
*
* @param client SubData connection
* @param callback Group Map
*/
public static void requestLowercaseGroups(DataClient client, Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
requestGroups(client, groups -> {
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
for (String key : groups.keySet()) {
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
}
callback.run(lowercaseGroups);
});
}
/**
* Requests a Server Group (Group names are case insensitive here)
*
* @param client SubData connection
* @param name Group name
* @param callback a Server Group
*/
public static void requestGroup(DataClient client, String name, Callback<NamedContainer<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<Server>();
for (String server : data.getMap(key).getKeys()) {
if (data.getMap(key).getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.add(new SubServer(client, data.getMap(key).getMap(server)));
} else {
servers.add(new Server(client, data.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
}
try {
callback.run(group);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Servers (including SubServers)
*
* @param client SubData connection
* @param callback Server Map
*/
public static void requestServers(DataClient client, Callback<Map<String, Server>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadServerInfo(null, data -> {
TreeMap<String, Server> servers = new TreeMap<String, Server>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.put(server.toLowerCase(), new SubServer(client, data.getMap(server)));
} else {
servers.put(server.toLowerCase(), new Server(client, data.getMap(server)));
}
}
try {
callback.run(servers);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Server
*
* @param client SubData connection
* @param name Server name
* @param callback a Server
*/
public static void requestServer(DataClient client, String name, Callback<Server> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> {
Server server = null;
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(client, data.getMap(key));
} else {
server = new Server(client, data.getMap(key));
}
}
try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the SubServers
*
* @param client SubData connection
* @param callback SubServer Map
*/
public static void requestSubServers(DataClient client, Callback<Map<String, SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
requestServers(client, servers -> {
TreeMap<String, SubServer> subservers = new TreeMap<String, SubServer>();
for (String server : servers.keySet()) {
if (servers.get(server) instanceof SubServer) subservers.put(server, (SubServer) servers.get(server));
}
callback.run(subservers);
});
}
/**
* Requests a SubServer
*
* @param client SubData connection
* @param name SubServer name
* @param callback a SubServer
*/
public static void requestSubServer(DataClient client, String name, Callback<SubServer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
requestServer(client, name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
}
/**
* Requests the known Proxies
*
* @param client SubData connection
* @param callback Proxy Map
*/
public static void requestProxies(DataClient client, Callback<Map<String, Proxy>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(null, data -> {
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
for (String proxy : data.getKeys()) {
proxies.put(proxy.toLowerCase(), new Proxy(client, data.getMap(proxy)));
}
try {
callback.run(proxies);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Proxy
*
* @param client SubData connection
* @param name Proxy name
* @param callback a Proxy
*/
public static void requestProxy(DataClient client, String name, Callback<Proxy> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Request the Master Proxy redis container (null if unavailable)
*
* @param client SubData connection
* @param callback Master Proxy
*/
public static void requestMasterProxy(DataClient client, Callback<Proxy> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(Collections.emptyList(), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests players on this network across all known proxies
*
* @param client SubData connection
* @param callback Remote Player Collection
*/
public static void requestGlobalPlayers(DataClient client, Callback<Map<UUID, RemotePlayer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) {
players.put(UUID.fromString(player), new RemotePlayer(client, data.getMap(player)));
}
try {
callback.run(players);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a player on this network by searching across all known proxies
*
* @param client SubData connection
* @param name Player name
* @param callback Remote Player
*/
public static void requestGlobalPlayer(DataClient client, String name, Callback<RemotePlayer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a player on this network by searching across all known proxies
*
* @param client SubData connection
* @param id Player UUID
* @param callback Remote Player
*/
public static void requestGlobalPlayer(DataClient client, UUID id, Callback<RemotePlayer> callback) {
if (Util.isNull(id, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
}

View File

@ -15,6 +15,9 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
/**
* Simplified SubCreator Data Class
*/
public class SubCreator {
HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
Host host;

View File

@ -3,16 +3,16 @@ package net.ME1312.SubServers.Client.Sponge.Network.API;
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.SubData.Client.DataClient;
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
import net.ME1312.SubServers.Client.Sponge.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.*;
/**
* Simplified SubServer Data Class
*/
public class SubServer extends Server {
private List<SubServer> incompatibilities = null;
private List<SubServer> currentIncompatibilities = null;
@ -35,22 +35,33 @@ public class SubServer extends Server {
}
/**
* Create an API representation of a Server
* Create an API representation of a SubServer
*
* @param raw JSON representation of the Server
* @param raw JSON representation of the SubServer
*/
public SubServer(ObjectMap<String> raw) {
super(raw);
super(null, raw);
}
/**
* Create an API representation of a Server
* Create an API representation of a SubServer
*
* @param client SubData connection
* @param raw JSON representation of the SubServer
*/
SubServer(DataClient client, ObjectMap<String> raw) {
super(client, raw);
}
/**
* Create an API representation of a SubServer
*
* @param host Host
* @param raw JSON representation of the Server
* @param raw JSON representation of the SubServer
*/
SubServer(Host host, ObjectMap<String> raw) {
super(raw);
super(host.client, raw);
this.host = host;
}
@ -76,7 +87,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(player, getName(), data -> {
client().sendPacket(new PacketStartServer(player, getName(), data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -121,7 +132,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), false, data -> {
client().sendPacket(new PacketStopServer(player, getName(), false, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -166,7 +177,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), true, data -> {
client().sendPacket(new PacketStopServer(player, getName(), true, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -212,7 +223,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(player, getName(), command, data -> {
client().sendPacket(new PacketCommandServer(player, getName(), command, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -335,7 +346,7 @@ public class SubServer extends Server {
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 -> {
client().sendPacket(new PacketEditServer(player, getName(), edit, perma, data -> {
try {
if (data.getInt(0x0001) != 0) {
response.run(data.getInt(0x0001) * -1);
@ -660,7 +671,7 @@ public class SubServer extends Server {
if (incompatibilities == null) {
LinkedList<String> incompatible = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible-list")) incompatible.add(subserver.toLowerCase());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
client().sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) incompatibilities.add(new SubServer(data.getMap(server)));
@ -704,7 +715,7 @@ public class SubServer extends Server {
if (currentIncompatibilities == null) {
LinkedList<String> incompatible = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible")) incompatible.add(subserver.toLowerCase());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
client().sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) incompatibilities.add(new SubServer(data.getMap(server)));

View File

@ -24,82 +24,85 @@ import java.util.logging.Logger;
import static java.util.logging.Level.*;
/**
* SubServers Protocol Class
*/
public class SubProtocol extends SubDataProtocol {
private static SubProtocol instance;
private SubProtocol() {}
@SuppressWarnings("deprecation")
protected SubProtocol() {
SubPlugin plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2");
addVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
registerPacket(0x0002, PacketLinkServer.class);
registerPacket(0x0002, new PacketLinkServer(plugin));
// 10-2F: Download Packets
registerPacket(0x0010, PacketDownloadLang.class);
registerPacket(0x0011, PacketDownloadPlatformInfo.class);
registerPacket(0x0012, PacketDownloadProxyInfo.class);
registerPacket(0x0013, PacketDownloadHostInfo.class);
registerPacket(0x0014, PacketDownloadGroupInfo.class);
registerPacket(0x0015, PacketDownloadServerInfo.class);
registerPacket(0x0016, PacketDownloadPlayerInfo.class);
registerPacket(0x0017, PacketCheckPermission.class);
registerPacket(0x0018, PacketCheckPermissionResponse.class);
registerPacket(0x0010, new PacketDownloadLang(plugin));
registerPacket(0x0011, new PacketDownloadPlatformInfo());
registerPacket(0x0012, new PacketDownloadProxyInfo());
registerPacket(0x0013, new PacketDownloadHostInfo());
registerPacket(0x0014, new PacketDownloadGroupInfo());
registerPacket(0x0015, new PacketDownloadServerInfo());
registerPacket(0x0016, new PacketDownloadPlayerInfo());
registerPacket(0x0017, new PacketCheckPermission());
registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
registerPacket(0x0030, PacketCreateServer.class);
registerPacket(0x0031, PacketAddServer.class);
registerPacket(0x0032, PacketStartServer.class);
registerPacket(0x0033, PacketUpdateServer.class);
registerPacket(0x0034, PacketEditServer.class);
registerPacket(0x0035, PacketRestartServer.class);
registerPacket(0x0036, PacketCommandServer.class);
registerPacket(0x0037, PacketStopServer.class);
registerPacket(0x0038, PacketRemoveServer.class);
registerPacket(0x0039, PacketDeleteServer.class);
registerPacket(0x0030, new PacketCreateServer());
registerPacket(0x0031, new PacketAddServer());
registerPacket(0x0032, new PacketStartServer());
registerPacket(0x0033, new PacketUpdateServer());
registerPacket(0x0034, new PacketEditServer());
registerPacket(0x0035, new PacketRestartServer());
registerPacket(0x0036, new PacketCommandServer());
registerPacket(0x0037, new PacketStopServer());
registerPacket(0x0038, new PacketRemoveServer());
registerPacket(0x0039, new PacketDeleteServer());
// 70-7F: External Misc Packets
//registerPacket(0x0070, PacketInExRunEvent.class);
//registerPacket(0x0071, PacketInExReset.class);
//registerPacket(0x0072, PacketInExReload.class);
registerPacket(0x0070, new PacketInExRunEvent(plugin));
registerPacket(0x0071, new PacketInExReset());
registerPacket(0x0072, new PacketInExReload(plugin));
}
public static SubProtocol get() {
if (instance == null) {
if (instance == null)
instance = new SubProtocol();
SubPlugin plugin = SubAPI.getInstance().getInternals();
instance.setName("SubServers 2");
instance.addVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
instance.registerPacket(0x0002, PacketLinkServer.class);
instance.registerPacket(0x0002, new PacketLinkServer(plugin));
// 10-2F: 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, PacketDownloadPlayerInfo.class);
instance.registerPacket(0x0017, PacketCheckPermission.class);
instance.registerPacket(0x0018, PacketCheckPermissionResponse.class);
instance.registerPacket(0x0010, new PacketDownloadLang(plugin));
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 PacketDownloadPlayerInfo());
instance.registerPacket(0x0017, new PacketCheckPermission());
instance.registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
instance.registerPacket(0x0033, PacketUpdateServer.class);
instance.registerPacket(0x0034, PacketEditServer.class);
instance.registerPacket(0x0035, PacketRestartServer.class);
instance.registerPacket(0x0036, PacketCommandServer.class);
instance.registerPacket(0x0037, PacketStopServer.class);
instance.registerPacket(0x0038, PacketRemoveServer.class);
instance.registerPacket(0x0039, PacketDeleteServer.class);
instance.registerPacket(0x0030, new PacketCreateServer());
instance.registerPacket(0x0031, new PacketAddServer());
instance.registerPacket(0x0032, new PacketStartServer());
instance.registerPacket(0x0033, new PacketUpdateServer());
instance.registerPacket(0x0034, new PacketEditServer());
instance.registerPacket(0x0035, new PacketRestartServer());
instance.registerPacket(0x0036, new PacketCommandServer());
instance.registerPacket(0x0037, new PacketStopServer());
instance.registerPacket(0x0038, new PacketRemoveServer());
instance.registerPacket(0x0039, new PacketDeleteServer());
// 70-7F: External Misc Packets
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
//instance.registerPacket(0x0071, PacketInExReset.class);
//instance.registerPacket(0x0072, PacketInExReload.class);
instance.registerPacket(0x0070, new PacketInExRunEvent(plugin));
instance.registerPacket(0x0071, new PacketInExReset());
instance.registerPacket(0x0072, new PacketInExReload(plugin));
}
return instance;
}

View File

@ -18,6 +18,8 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.util.*;
import static net.ME1312.SubServers.Client.Sponge.Network.API.SimplifiedData.*;
/**
* SubAPI Class
*/
@ -77,22 +79,7 @@ public final class SubAPI {
* @param callback Host Map
*/
public void getHosts(Callback<Map<String, Host>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(null, data -> {
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
for (String host : data.getKeys()) {
hosts.put(host.toLowerCase(), new Host(data.getMap(host)));
}
try {
callback.run(hosts);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestHosts(null, callback);
}
/**
@ -102,22 +89,7 @@ public final class SubAPI {
* @param callback a Host
*/
public void getHost(String name, Callback<Host> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> {
Host host = null;
if (data.getKeys().size() > 0) {
host = new Host(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(host);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestHost(null, name, callback);
}
/**
@ -126,30 +98,7 @@ public final class SubAPI {
* @param callback Group Map
*/
public void getGroups(Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(null, data -> {
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
for (String group : data.getKeys()) {
ArrayList<Server> servers = new ArrayList<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.getMap(group).getMap(server)));
}
}
if (servers.size() > 0) groups.put(group, servers);
}
try {
callback.run(groups);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGroups(null, callback);
}
/**
@ -158,14 +107,7 @@ public final class SubAPI {
* @param callback Group Map
*/
public void getLowercaseGroups(Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
getGroups(groups -> {
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
for (String key : groups.keySet()) {
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
}
callback.run(lowercaseGroups);
});
requestLowercaseGroups(null, callback);
}
/**
@ -175,31 +117,7 @@ public final class SubAPI {
* @param callback a Server Group
*/
public void getGroup(String name, Callback<NamedContainer<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<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.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
}
try {
callback.run(group);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGroup(null, name, callback);
}
/**
@ -208,26 +126,7 @@ public final class SubAPI {
* @param callback Server Map
*/
public void getServers(Callback<Map<String, Server>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(null, data -> {
TreeMap<String, Server> servers = new TreeMap<String, 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.getMap(server)));
}
}
try {
callback.run(servers);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestServers(null, callback);
}
/**
@ -237,27 +136,7 @@ public final class SubAPI {
* @param callback a Server
*/
public void getServer(String name, Callback<Server> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> {
Server server = null;
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.getMap(key));
}
}
try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestServer(null, name, callback);
}
/**
@ -434,14 +313,7 @@ public final class SubAPI {
* @param callback SubServer Map
*/
public void getSubServers(Callback<Map<String, SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
getServers(servers -> {
TreeMap<String, SubServer> subservers = new TreeMap<String, SubServer>();
for (String server : servers.keySet()) {
if (servers.get(server) instanceof SubServer) subservers.put(server, (SubServer) servers.get(server));
}
callback.run(subservers);
});
requestSubServers(null, callback);
}
/**
@ -451,8 +323,7 @@ public final class SubAPI {
* @param callback a SubServer
*/
public void getSubServer(String name, Callback<SubServer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
getServer(name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
requestSubServer(null, name, callback);
}
/**
@ -461,22 +332,7 @@ public final class SubAPI {
* @param callback Proxy Map
*/
public void getProxies(Callback<Map<String, Proxy>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(null, data -> {
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
for (String proxy : data.getKeys()) {
proxies.put(proxy.toLowerCase(), new Proxy(data.getMap(proxy)));
}
try {
callback.run(proxies);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestProxies(null, callback);
}
/**
@ -486,120 +342,45 @@ public final class SubAPI {
* @param callback a Proxy
*/
public void getProxy(String name, Callback<Proxy> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestProxy(null, name, callback);
}
/**
* Get the Master Proxy redis container (null if unavailable)
* Get the Master Proxy Container
*
* @param callback Master Proxy
*/
public void getMasterProxy(Callback<Proxy> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.emptyList(), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestMasterProxy(null, callback);
}
/**
* Get players on this network across all known proxies
* Gets players on this network across all known proxies
*
* @param callback Remote Player Collection
*/
public void getGlobalPlayers(Callback<Map<UUID, RemotePlayer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) {
players.put(UUID.fromString(player), new RemotePlayer(data.getMap(player)));
}
try {
callback.run(players);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayers(null, callback);
}
/**
* Get a player on this network by searching across all known proxies
* Gets a player on this network by searching across all known proxies
*
* @param name Player name
* @param callback Remote Player
*/
public void getGlobalPlayer(String name, Callback<RemotePlayer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayer(null, name, callback);
}
/**
* Get a player on this network by searching across all known proxies
* Gets a player on this network by searching across all known proxies
*
* @param id Player UUID
* @param callback Remote Player
*/
public void getGlobalPlayer(UUID id, Callback<RemotePlayer> callback) {
if (Util.isNull(id, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayer(null, id, callback);
}
/**

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>20w30b</version>
<version>20w33a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.Container.NamedContainer;
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.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -17,11 +18,15 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
/**
* Simplified Host Data Class
*/
public class Host {
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
private SubCreator creator;
private List<RemotePlayer> players = null;
ObjectMap<String> raw;
DataClient client;
long timestamp;
/**
@ -30,6 +35,17 @@ public class Host {
* @param raw Raw representation of the Host
*/
public Host(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Host
*
* @param client SubData connection
* @param raw Raw representation of the Host
*/
Host(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -50,12 +66,16 @@ public class Host {
}
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -169,7 +189,7 @@ public class Host {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (SubServer server : getSubServers().values()) for (NamedContainer<String, UUID> player : server.getGlobalPlayers()) ids.add(player.get());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));
@ -339,7 +359,7 @@ public class Host {
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 -> {
client().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) {
@ -476,7 +496,7 @@ public class Host {
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 -> {
client().sendPacket(new PacketRemoveServer(player, name, force, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -662,7 +682,7 @@ public class Host {
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 -> {
client().sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {

View File

@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.Container.NamedContainer;
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.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -16,9 +17,13 @@ import net.ME1312.SubServers.Host.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified Proxy Data Class
*/
public class Proxy {
ObjectMap<String> raw;
private List<RemotePlayer> players = null;
DataClient client;
long timestamp;
/**
@ -27,6 +32,17 @@ public class Proxy {
* @param raw Raw representation of the Proxy
*/
public Proxy(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Proxy
*
* @param client SubData connection
* @param raw Raw representation of the Proxy
*/
Proxy(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -41,12 +57,16 @@ public class Proxy {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -125,7 +145,7 @@ public class Proxy {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (String id : raw.getMap("players").getKeys()) ids.add(UUID.fromString(id));
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));

View File

@ -3,21 +3,25 @@ package net.ME1312.SubServers.Host.Network.API;
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.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Host.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Calendar;
import java.util.Collections;
import java.util.UUID;
/**
* Simplified RemotePlayer Data Class
*/
public class RemotePlayer {
ObjectMap<String> raw;
private Proxy proxy = null;
private Server server = null;
DataClient client;
long timestamp;
/**
@ -26,6 +30,17 @@ public class RemotePlayer {
* @param raw Raw representation of the Remote Player
*/
public RemotePlayer(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Remote Player
*
* @param client SubData connection
* @param raw Raw representation of the Remote Player
*/
RemotePlayer(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -41,12 +56,16 @@ public class RemotePlayer {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
UUID id = getUniqueId();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> load(data.getMap(id.toString()))));
client().sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> load(data.getMap(id.toString()))));
}
/**

View File

@ -4,6 +4,7 @@ import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -16,9 +17,13 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.*;
/**
* Simplified Server Data Class
*/
public class Server {
ObjectMap<String> raw;
private List<RemotePlayer> players = null;
DataClient client;
long timestamp;
/**
@ -27,6 +32,17 @@ public class Server {
* @param raw Raw representation of the Server
*/
public Server(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Server
*
* @param client SubData connection
* @param raw Raw representation of the Server
*/
Server(DataClient client, ObjectMap<String> raw) {
this.client = (SubDataClient) client;
load(raw);
}
@ -41,12 +57,16 @@ public class Server {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -133,7 +153,7 @@ public class Server {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (String id : raw.getMap("players").getKeys()) ids.add(UUID.fromString(id));
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));

View File

@ -0,0 +1,400 @@
package net.ME1312.SubServers.Host.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Host.Network.Packet.*;
import net.ME1312.SubServers.Host.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified Data Requesting Class
*/
public final class SimplifiedData {
private SimplifiedData() {}
static SubDataClient client(DataClient client) {
return (SubDataClient) ((client != null)? client : SubAPI.getInstance().getSubDataNetwork()[0]);
}
/**
* Requests the Hosts
*
* @param client SubData connection
* @param callback Host Map
*/
public static void requestHosts(DataClient client, Callback<Map<String, Host>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadHostInfo(null, data -> {
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
for (String host : data.getKeys()) {
hosts.put(host.toLowerCase(), new Host(client, data.getMap(host)));
}
try {
callback.run(hosts);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Host
*
* @param client SubData connection
* @param name Host name
* @param callback a Host
*/
public static void requestHost(DataClient client, String name, Callback<Host> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> {
Host host = null;
if (data.getKeys().size() > 0) {
host = new Host(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(host);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Server Groups (Group names are case sensitive here)
*
* @param client SubData connection
* @param callback Group Map
*/
public static void requestGroups(DataClient client, Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(null, data -> {
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
for (String group : data.getKeys()) {
ArrayList<Server> servers = new ArrayList<Server>();
for (String server : data.getMap(group).getKeys()) {
if (data.getMap(group).getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.add(new SubServer(client, data.getMap(group).getMap(server)));
} else {
servers.add(new Server(client, data.getMap(group).getMap(server)));
}
}
if (servers.size() > 0) groups.put(group, servers);
}
try {
callback.run(groups);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Server Groups (Group names are all lowercase here)
*
* @param client SubData connection
* @param callback Group Map
*/
public static void requestLowercaseGroups(DataClient client, Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
requestGroups(client, groups -> {
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
for (String key : groups.keySet()) {
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
}
callback.run(lowercaseGroups);
});
}
/**
* Requests a Server Group (Group names are case insensitive here)
*
* @param client SubData connection
* @param name Group name
* @param callback a Server Group
*/
public static void requestGroup(DataClient client, String name, Callback<NamedContainer<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<Server>();
for (String server : data.getMap(key).getKeys()) {
if (data.getMap(key).getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.add(new SubServer(client, data.getMap(key).getMap(server)));
} else {
servers.add(new Server(client, data.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
}
try {
callback.run(group);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Servers (including SubServers)
*
* @param client SubData connection
* @param callback Server Map
*/
public static void requestServers(DataClient client, Callback<Map<String, Server>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadServerInfo(null, data -> {
TreeMap<String, Server> servers = new TreeMap<String, Server>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.put(server.toLowerCase(), new SubServer(client, data.getMap(server)));
} else {
servers.put(server.toLowerCase(), new Server(client, data.getMap(server)));
}
}
try {
callback.run(servers);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Server
*
* @param client SubData connection
* @param name Server name
* @param callback a Server
*/
public static void requestServer(DataClient client, String name, Callback<Server> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> {
Server server = null;
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(client, data.getMap(key));
} else {
server = new Server(client, data.getMap(key));
}
}
try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the SubServers
*
* @param client SubData connection
* @param callback SubServer Map
*/
public static void requestSubServers(DataClient client, Callback<Map<String, SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
requestServers(client, servers -> {
TreeMap<String, SubServer> subservers = new TreeMap<String, SubServer>();
for (String server : servers.keySet()) {
if (servers.get(server) instanceof SubServer) subservers.put(server, (SubServer) servers.get(server));
}
callback.run(subservers);
});
}
/**
* Requests a SubServer
*
* @param client SubData connection
* @param name SubServer name
* @param callback a SubServer
*/
public static void requestSubServer(DataClient client, String name, Callback<SubServer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
requestServer(client, name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
}
/**
* Requests the known Proxies
*
* @param client SubData connection
* @param callback Proxy Map
*/
public static void requestProxies(DataClient client, Callback<Map<String, Proxy>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(null, data -> {
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
for (String proxy : data.getKeys()) {
proxies.put(proxy.toLowerCase(), new Proxy(client, data.getMap(proxy)));
}
try {
callback.run(proxies);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Proxy
*
* @param client SubData connection
* @param name Proxy name
* @param callback a Proxy
*/
public static void requestProxy(DataClient client, String name, Callback<Proxy> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Request the Master Proxy redis container (null if unavailable)
*
* @param client SubData connection
* @param callback Master Proxy
*/
public static void requestMasterProxy(DataClient client, Callback<Proxy> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(Collections.emptyList(), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests players on this network across all known proxies
*
* @param client SubData connection
* @param callback Remote Player Collection
*/
public static void requestGlobalPlayers(DataClient client, Callback<Map<UUID, RemotePlayer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) {
players.put(UUID.fromString(player), new RemotePlayer(client, data.getMap(player)));
}
try {
callback.run(players);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a player on this network by searching across all known proxies
*
* @param client SubData connection
* @param name Player name
* @param callback Remote Player
*/
public static void requestGlobalPlayer(DataClient client, String name, Callback<RemotePlayer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a player on this network by searching across all known proxies
*
* @param client SubData connection
* @param id Player UUID
* @param callback Remote Player
*/
public static void requestGlobalPlayer(DataClient client, UUID id, Callback<RemotePlayer> callback) {
if (Util.isNull(id, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
}

View File

@ -15,6 +15,9 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
/**
* Simplified SubCreator Data Class
*/
public class SubCreator {
HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
Host host;

View File

@ -3,7 +3,7 @@ package net.ME1312.SubServers.Host.Network.API;
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.SubData.Client.DataClient;
import net.ME1312.SubServers.Host.Network.Packet.*;
import net.ME1312.SubServers.Host.SubAPI;
@ -13,6 +13,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
/**
* Simplified SubServer Data Class
*/
public class SubServer extends Server {
private List<SubServer> incompatibilities = null;
private List<SubServer> currentIncompatibilities = null;
@ -35,22 +38,33 @@ public class SubServer extends Server {
}
/**
* Create an API representation of a Server
* Create an API representation of a SubServer
*
* @param raw JSON representation of the Server
* @param raw JSON representation of the SubServer
*/
public SubServer(ObjectMap<String> raw) {
super(raw);
super(null, raw);
}
/**
* Create an API representation of a Server
* Create an API representation of a SubServer
*
* @param client SubData connection
* @param raw JSON representation of the SubServer
*/
SubServer(DataClient client, ObjectMap<String> raw) {
super(client, raw);
}
/**
* Create an API representation of a SubServer
*
* @param host Host
* @param raw JSON representation of the Server
* @param raw JSON representation of the SubServer
*/
SubServer(Host host, ObjectMap<String> raw) {
super(raw);
super(host.client, raw);
this.host = host;
}
@ -76,7 +90,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(player, getName(), data -> {
client().sendPacket(new PacketStartServer(player, getName(), data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -121,7 +135,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), false, data -> {
client().sendPacket(new PacketStopServer(player, getName(), false, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -166,7 +180,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), true, data -> {
client().sendPacket(new PacketStopServer(player, getName(), true, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -212,7 +226,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(player, getName(), command, data -> {
client().sendPacket(new PacketCommandServer(player, getName(), command, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -335,7 +349,7 @@ public class SubServer extends Server {
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 -> {
client().sendPacket(new PacketEditServer(player, getName(), edit, perma, data -> {
try {
if (data.getInt(0x0001) != 0) {
response.run(data.getInt(0x0001) * -1);
@ -660,7 +674,7 @@ public class SubServer extends Server {
if (incompatibilities == null) {
LinkedList<String> incompatible = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible-list")) incompatible.add(subserver.toLowerCase());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
client().sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) incompatibilities.add(new SubServer(data.getMap(server)));
@ -704,7 +718,7 @@ public class SubServer extends Server {
if (currentIncompatibilities == null) {
LinkedList<String> incompatible = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible")) incompatible.add(subserver.toLowerCase());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
client().sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) incompatibilities.add(new SubServer(data.getMap(server)));

View File

@ -20,107 +20,110 @@ import java.net.InetAddress;
import java.util.HashMap;
import java.util.logging.Logger;
/**
* SubServers Protocol Class
*/
public class SubProtocol extends SubDataProtocol {
private static SubProtocol instance;
private SubProtocol() {}
@SuppressWarnings("deprecation")
protected SubProtocol() {
ExHost host = SubAPI.getInstance().getInternals();
setName("SubServers 2");
addVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
registerPacket(0x0001, PacketLinkExHost.class);
registerPacket(0x0001, new PacketLinkExHost(host));
// 10-2F: Download Packets
registerPacket(0x0010, PacketDownloadLang.class);
registerPacket(0x0011, PacketDownloadPlatformInfo.class);
registerPacket(0x0012, PacketDownloadProxyInfo.class);
registerPacket(0x0013, PacketDownloadHostInfo.class);
registerPacket(0x0014, PacketDownloadGroupInfo.class);
registerPacket(0x0015, PacketDownloadServerInfo.class);
registerPacket(0x0016, PacketDownloadPlayerInfo.class);
registerPacket(0x0017, PacketCheckPermission.class);
registerPacket(0x0017, PacketCheckPermissionResponse.class);
registerPacket(0x0010, new PacketDownloadLang(host));
registerPacket(0x0011, new PacketDownloadPlatformInfo());
registerPacket(0x0012, new PacketDownloadProxyInfo());
registerPacket(0x0013, new PacketDownloadHostInfo());
registerPacket(0x0014, new PacketDownloadGroupInfo());
registerPacket(0x0015, new PacketDownloadServerInfo());
registerPacket(0x0016, new PacketDownloadPlayerInfo());
registerPacket(0x0017, new PacketCheckPermission());
registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
registerPacket(0x0030, PacketCreateServer.class);
registerPacket(0x0031, PacketAddServer.class);
registerPacket(0x0032, PacketStartServer.class);
registerPacket(0x0033, PacketUpdateServer.class);
registerPacket(0x0034, PacketEditServer.class);
registerPacket(0x0035, PacketRestartServer.class);
registerPacket(0x0036, PacketCommandServer.class);
registerPacket(0x0037, PacketStopServer.class);
registerPacket(0x0038, PacketRemoveServer.class);
registerPacket(0x0039, PacketDeleteServer.class);
registerPacket(0x0030, new PacketCreateServer());
registerPacket(0x0031, new PacketAddServer());
registerPacket(0x0032, new PacketStartServer());
registerPacket(0x0033, new PacketUpdateServer());
registerPacket(0x0034, new PacketEditServer());
registerPacket(0x0035, new PacketRestartServer());
registerPacket(0x0036, new PacketCommandServer());
registerPacket(0x0037, new PacketStopServer());
registerPacket(0x0038, new PacketRemoveServer());
registerPacket(0x0039, new PacketDeleteServer());
// 50-6F: External Host Packets
registerPacket(0x0050, PacketExConfigureHost.class);
registerPacket(0x0051, PacketExUploadTemplates.class);
registerPacket(0x0052, PacketExDownloadTemplates.class);
registerPacket(0x0053, PacketOutExRequestQueue.class);
registerPacket(0x0054, PacketExCreateServer.class);
registerPacket(0x0055, PacketExAddServer.class);
registerPacket(0x0056, PacketExEditServer.class);
registerPacket(0x0057, PacketOutExLogMessage.class);
registerPacket(0x0058, PacketExRemoveServer.class);
registerPacket(0x0059, PacketExDeleteServer.class);
registerPacket(0x0050, new PacketExConfigureHost(host));
registerPacket(0x0051, new PacketExUploadTemplates(host));
registerPacket(0x0052, new PacketExDownloadTemplates(host));
//registerPacket(0x0053, new PacketOutExRequestQueue(host));
registerPacket(0x0054, new PacketExCreateServer(host));
registerPacket(0x0055, new PacketExAddServer(host));
registerPacket(0x0056, new PacketExEditServer(host));
//registerPacket(0x0057, new PacketOutExLogMessage());
registerPacket(0x0058, new PacketExRemoveServer(host));
registerPacket(0x0059, new PacketExDeleteServer(host));
// 70-7F: External Misc Packets
//registerPacket(0x0070, PacketInExRunEvent.class);
//registerPacket(0x0071, PacketInExReset.class);
//registerPacket(0x0072, PacketInExReload.class);
registerPacket(0x0070, new PacketInExRunEvent());
registerPacket(0x0071, new PacketInExReset(host));
registerPacket(0x0072, new PacketInExReload(host));
}
public static SubProtocol get() {
if (instance == null) {
if (instance == null)
instance = new SubProtocol();
ExHost host = SubAPI.getInstance().getInternals();
instance.setName("SubServers 2");
instance.addVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
instance.registerPacket(0x0001, PacketLinkExHost.class);
instance.registerPacket(0x0001, new PacketLinkExHost(host));
// 10-2F: 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, PacketDownloadPlayerInfo.class);
instance.registerPacket(0x0017, PacketCheckPermission.class);
instance.registerPacket(0x0017, PacketCheckPermissionResponse.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 PacketDownloadPlayerInfo());
instance.registerPacket(0x0017, new PacketCheckPermission());
instance.registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
instance.registerPacket(0x0033, PacketUpdateServer.class);
instance.registerPacket(0x0034, PacketEditServer.class);
instance.registerPacket(0x0035, PacketRestartServer.class);
instance.registerPacket(0x0036, PacketCommandServer.class);
instance.registerPacket(0x0037, PacketStopServer.class);
instance.registerPacket(0x0038, PacketRemoveServer.class);
instance.registerPacket(0x0039, PacketDeleteServer.class);
instance.registerPacket(0x0030, new PacketCreateServer());
instance.registerPacket(0x0031, new PacketAddServer());
instance.registerPacket(0x0032, new PacketStartServer());
instance.registerPacket(0x0033, new PacketUpdateServer());
instance.registerPacket(0x0034, new PacketEditServer());
instance.registerPacket(0x0035, new PacketRestartServer());
instance.registerPacket(0x0036, new PacketCommandServer());
instance.registerPacket(0x0037, new PacketStopServer());
instance.registerPacket(0x0038, new PacketRemoveServer());
instance.registerPacket(0x0039, new PacketDeleteServer());
// 50-6F: External Host Packets
instance.registerPacket(0x0050, PacketExConfigureHost.class);
instance.registerPacket(0x0051, PacketExUploadTemplates.class);
instance.registerPacket(0x0052, PacketExDownloadTemplates.class);
instance.registerPacket(0x0053, PacketOutExRequestQueue.class);
instance.registerPacket(0x0054, PacketExCreateServer.class);
instance.registerPacket(0x0055, PacketExAddServer.class);
instance.registerPacket(0x0056, PacketExEditServer.class);
instance.registerPacket(0x0057, PacketOutExLogMessage.class);
instance.registerPacket(0x0058, PacketExRemoveServer.class);
instance.registerPacket(0x0059, PacketExDeleteServer.class);
instance.registerPacket(0x0050, new PacketExConfigureHost(host));
instance.registerPacket(0x0051, new PacketExUploadTemplates(host));
instance.registerPacket(0x0052, new PacketExDownloadTemplates(host));
//instance.registerPacket(0x0053, new PacketOutExRequestQueue(host));
instance.registerPacket(0x0054, new PacketExCreateServer(host));
instance.registerPacket(0x0055, new PacketExAddServer(host));
instance.registerPacket(0x0056, new PacketExEditServer(host));
//instance.registerPacket(0x0057, new PacketOutExLogMessage());
instance.registerPacket(0x0058, new PacketExRemoveServer(host));
instance.registerPacket(0x0059, new PacketExDeleteServer(host));
// 70-7F: 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;
}

View File

@ -14,6 +14,8 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.util.*;
import static net.ME1312.SubServers.Host.Network.API.SimplifiedData.*;
/**
* SubAPI Class
*/
@ -62,22 +64,7 @@ public final class SubAPI {
* @param callback Host Map
*/
public void getHosts(Callback<Map<String, Host>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(null, data -> {
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
for (String host : data.getKeys()) {
hosts.put(host.toLowerCase(), new Host(data.getMap(host)));
}
try {
callback.run(hosts);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestHosts(null, callback);
}
/**
@ -87,22 +74,7 @@ public final class SubAPI {
* @param callback a Host
*/
public void getHost(String name, Callback<Host> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> {
Host host = null;
if (data.getKeys().size() > 0) {
host = new Host(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(host);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestHost(null, name, callback);
}
/**
@ -111,30 +83,7 @@ public final class SubAPI {
* @param callback Group Map
*/
public void getGroups(Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(null, data -> {
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
for (String group : data.getKeys()) {
ArrayList<Server> servers = new ArrayList<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.getMap(group).getMap(server)));
}
}
if (servers.size() > 0) groups.put(group, servers);
}
try {
callback.run(groups);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGroups(null, callback);
}
/**
@ -143,14 +92,7 @@ public final class SubAPI {
* @param callback Group Map
*/
public void getLowercaseGroups(Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
getGroups(groups -> {
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
for (String key : groups.keySet()) {
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
}
callback.run(lowercaseGroups);
});
requestLowercaseGroups(null, callback);
}
/**
@ -160,31 +102,7 @@ public final class SubAPI {
* @param callback a Server Group
*/
public void getGroup(String name, Callback<NamedContainer<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<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.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
}
try {
callback.run(group);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGroup(null, name, callback);
}
/**
@ -193,26 +111,7 @@ public final class SubAPI {
* @param callback Server Map
*/
public void getServers(Callback<Map<String, Server>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(null, data -> {
TreeMap<String, Server> servers = new TreeMap<String, 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.getMap(server)));
}
}
try {
callback.run(servers);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestServers(null, callback);
}
/**
@ -222,27 +121,7 @@ public final class SubAPI {
* @param callback a Server
*/
public void getServer(String name, Callback<Server> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> {
Server server = null;
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.getMap(key));
}
}
try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestServer(null, name, callback);
}
/**
@ -419,14 +298,7 @@ public final class SubAPI {
* @param callback SubServer Map
*/
public void getSubServers(Callback<Map<String, SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
getServers(servers -> {
TreeMap<String, SubServer> subservers = new TreeMap<String, SubServer>();
for (String server : servers.keySet()) {
if (servers.get(server) instanceof SubServer) subservers.put(server, (SubServer) servers.get(server));
}
callback.run(subservers);
});
requestSubServers(null, callback);
}
/**
@ -436,8 +308,7 @@ public final class SubAPI {
* @param callback a SubServer
*/
public void getSubServer(String name, Callback<SubServer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
getServer(name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
requestSubServer(null, name, callback);
}
/**
@ -446,22 +317,7 @@ public final class SubAPI {
* @param callback Proxy Map
*/
public void getProxies(Callback<Map<String, Proxy>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(null, data -> {
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
for (String proxy : data.getKeys()) {
proxies.put(proxy.toLowerCase(), new Proxy(data.getMap(proxy)));
}
try {
callback.run(proxies);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestProxies(null, callback);
}
/**
@ -471,120 +327,45 @@ public final class SubAPI {
* @param callback a Proxy
*/
public void getProxy(String name, Callback<Proxy> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestProxy(null, name, callback);
}
/**
* Get the Master Proxy redis container (null if unavailable)
* Get the Master Proxy Container
*
* @param callback Master Proxy
*/
public void getMasterProxy(Callback<Proxy> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.emptyList(), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestMasterProxy(null, callback);
}
/**
* Get players on this network across all known proxies
* Gets players on this network across all known proxies
*
* @param callback Remote Player Collection
*/
public void getGlobalPlayers(Callback<Map<UUID, RemotePlayer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) {
players.put(UUID.fromString(player), new RemotePlayer(data.getMap(player)));
}
try {
callback.run(players);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayers(null, callback);
}
/**
* Get a player on this network by searching across all known proxies
* Gets a player on this network by searching across all known proxies
*
* @param name Player name
* @param callback Remote Player
*/
public void getGlobalPlayer(String name, Callback<RemotePlayer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayer(null, name, callback);
}
/**
* Get a player on this network by searching across all known proxies
* Gets a player on this network by searching across all known proxies
*
* @param id Player UUID
* @param callback Remote Player
*/
public void getGlobalPlayer(UUID id, Callback<RemotePlayer> callback) {
if (Util.isNull(id, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGlobalPlayer(null, id, callback);
}
/**

View File

@ -30,14 +30,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w30b</version>
<version>20w33a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>20w30b</version>
<version>20w33a</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.Container.NamedContainer;
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.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -17,11 +18,15 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
/**
* Simplified Host Data Class
*/
public class Host {
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
private SubCreator creator;
private List<RemotePlayer> players = null;
ObjectMap<String> raw;
DataClient client;
long timestamp;
/**
@ -30,6 +35,17 @@ public class Host {
* @param raw Raw representation of the Host
*/
public Host(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Host
*
* @param client SubData connection
* @param raw Raw representation of the Host
*/
Host(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -50,12 +66,16 @@ public class Host {
}
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -169,7 +189,7 @@ public class Host {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (SubServer server : getSubServers().values()) for (NamedContainer<String, UUID> player : server.getGlobalPlayers()) ids.add(player.get());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));
@ -339,7 +359,7 @@ public class Host {
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 -> {
client().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) {
@ -476,7 +496,7 @@ public class Host {
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 -> {
client().sendPacket(new PacketRemoveServer(player, name, force, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -662,7 +682,7 @@ public class Host {
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 -> {
client().sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {

View File

@ -5,6 +5,7 @@ import net.ME1312.Galaxi.Library.Container.NamedContainer;
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.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -16,9 +17,13 @@ import net.ME1312.SubServers.Sync.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified Proxy Data Class
*/
public class Proxy {
ObjectMap<String> raw;
private List<RemotePlayer> players = null;
DataClient client;
long timestamp;
/**
@ -27,6 +32,17 @@ public class Proxy {
* @param raw Raw representation of the Proxy
*/
public Proxy(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Proxy
*
* @param client SubData connection
* @param raw Raw representation of the Proxy
*/
Proxy(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -41,12 +57,16 @@ public class Proxy {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -125,7 +145,7 @@ public class Proxy {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (String id : raw.getMap("players").getKeys()) ids.add(UUID.fromString(id));
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));

View File

@ -3,22 +3,26 @@ package net.ME1312.SubServers.Sync.Network.API;
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.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Sync.SubAPI;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Calendar;
import java.util.Collections;
import java.util.UUID;
/**
* Simplified RemotePlayer Data Class
*/
public class RemotePlayer {
ObjectMap<String> raw;
private Proxy proxy = null;
private Server server = null;
DataClient client;
long timestamp;
/**
@ -53,6 +57,17 @@ public class RemotePlayer {
* @param raw Raw representation of the Remote Player
*/
public RemotePlayer(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Remote Player
*
* @param client SubData connection
* @param raw Raw representation of the Remote Player
*/
RemotePlayer(DataClient client, ObjectMap<String> raw) {
this.client = client;
load(raw);
}
@ -68,12 +83,16 @@ public class RemotePlayer {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
private SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
UUID id = getUniqueId();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> load(data.getMap(id.toString()))));
client().sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> load(data.getMap(id.toString()))));
}
/**

View File

@ -4,6 +4,7 @@ import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient;
@ -16,9 +17,13 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.*;
/**
* Simplified Server Data Class
*/
public class Server {
ObjectMap<String> raw;
private List<RemotePlayer> players = null;
DataClient client;
long timestamp;
/**
@ -27,6 +32,17 @@ public class Server {
* @param raw Raw representation of the Server
*/
public Server(ObjectMap<String> raw) {
this(null, raw);
}
/**
* Create an API representation of a Server
*
* @param client SubData connection
* @param raw Raw representation of the Server
*/
Server(DataClient client, ObjectMap<String> raw) {
this.client = (SubDataClient) client;
load(raw);
}
@ -41,12 +57,16 @@ public class Server {
this.timestamp = Calendar.getInstance().getTime().getTime();
}
SubDataClient client() {
return SimplifiedData.client(client);
}
/**
* Download a new copy of the data from SubData
*/
public void refresh() {
String name = getName();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
client().sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> load(data.getMap(name))));
}
/**
@ -133,7 +153,7 @@ public class Server {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (String id : raw.getMap("players").getKeys()) ids.add(UUID.fromString(id));
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {
players.add(new RemotePlayer(data.getMap(player)));

View File

@ -0,0 +1,400 @@
package net.ME1312.SubServers.Sync.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Sync.Network.Packet.*;
import net.ME1312.SubServers.Sync.SubAPI;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
* Simplified Data Requesting Class
*/
public final class SimplifiedData {
private SimplifiedData() {}
static SubDataClient client(DataClient client) {
return (SubDataClient) ((client != null)? client : SubAPI.getInstance().getSubDataNetwork()[0]);
}
/**
* Requests the Hosts
*
* @param client SubData connection
* @param callback Host Map
*/
public static void requestHosts(DataClient client, Callback<Map<String, Host>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadHostInfo(null, data -> {
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
for (String host : data.getKeys()) {
hosts.put(host.toLowerCase(), new Host(client, data.getMap(host)));
}
try {
callback.run(hosts);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Host
*
* @param client SubData connection
* @param name Host name
* @param callback a Host
*/
public static void requestHost(DataClient client, String name, Callback<Host> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> {
Host host = null;
if (data.getKeys().size() > 0) {
host = new Host(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(host);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Server Groups (Group names are case sensitive here)
*
* @param client SubData connection
* @param callback Group Map
*/
public static void requestGroups(DataClient client, Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(null, data -> {
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
for (String group : data.getKeys()) {
ArrayList<Server> servers = new ArrayList<Server>();
for (String server : data.getMap(group).getKeys()) {
if (data.getMap(group).getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.add(new SubServer(client, data.getMap(group).getMap(server)));
} else {
servers.add(new Server(client, data.getMap(group).getMap(server)));
}
}
if (servers.size() > 0) groups.put(group, servers);
}
try {
callback.run(groups);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Server Groups (Group names are all lowercase here)
*
* @param client SubData connection
* @param callback Group Map
*/
public static void requestLowercaseGroups(DataClient client, Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
requestGroups(client, groups -> {
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
for (String key : groups.keySet()) {
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
}
callback.run(lowercaseGroups);
});
}
/**
* Requests a Server Group (Group names are case insensitive here)
*
* @param client SubData connection
* @param name Group name
* @param callback a Server Group
*/
public static void requestGroup(DataClient client, String name, Callback<NamedContainer<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<Server>();
for (String server : data.getMap(key).getKeys()) {
if (data.getMap(key).getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.add(new SubServer(client, data.getMap(key).getMap(server)));
} else {
servers.add(new Server(client, data.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
}
try {
callback.run(group);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the Servers (including SubServers)
*
* @param client SubData connection
* @param callback Server Map
*/
public static void requestServers(DataClient client, Callback<Map<String, Server>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadServerInfo(null, data -> {
TreeMap<String, Server> servers = new TreeMap<String, Server>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) {
servers.put(server.toLowerCase(), new SubServer(client, data.getMap(server)));
} else {
servers.put(server.toLowerCase(), new Server(client, data.getMap(server)));
}
}
try {
callback.run(servers);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Server
*
* @param client SubData connection
* @param name Server name
* @param callback a Server
*/
public static void requestServer(DataClient client, String name, Callback<Server> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> {
Server server = null;
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(client, data.getMap(key));
} else {
server = new Server(client, data.getMap(key));
}
}
try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests the SubServers
*
* @param client SubData connection
* @param callback SubServer Map
*/
public static void requestSubServers(DataClient client, Callback<Map<String, SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
requestServers(client, servers -> {
TreeMap<String, SubServer> subservers = new TreeMap<String, SubServer>();
for (String server : servers.keySet()) {
if (servers.get(server) instanceof SubServer) subservers.put(server, (SubServer) servers.get(server));
}
callback.run(subservers);
});
}
/**
* Requests a SubServer
*
* @param client SubData connection
* @param name SubServer name
* @param callback a SubServer
*/
public static void requestSubServer(DataClient client, String name, Callback<SubServer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
requestServer(client, name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
}
/**
* Requests the known Proxies
*
* @param client SubData connection
* @param callback Proxy Map
*/
public static void requestProxies(DataClient client, Callback<Map<String, Proxy>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(null, data -> {
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
for (String proxy : data.getKeys()) {
proxies.put(proxy.toLowerCase(), new Proxy(client, data.getMap(proxy)));
}
try {
callback.run(proxies);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a Proxy
*
* @param client SubData connection
* @param name Proxy name
* @param callback a Proxy
*/
public static void requestProxy(DataClient client, String name, Callback<Proxy> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Request the Master Proxy redis container (null if unavailable)
*
* @param client SubData connection
* @param callback Master Proxy
*/
public static void requestMasterProxy(DataClient client, Callback<Proxy> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadProxyInfo(Collections.emptyList(), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests players on this network across all known proxies
*
* @param client SubData connection
* @param callback Remote Player Collection
*/
public static void requestGlobalPlayers(DataClient client, Callback<Map<UUID, RemotePlayer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) {
players.put(UUID.fromString(player), new RemotePlayer(client, data.getMap(player)));
}
try {
callback.run(players);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a player on this network by searching across all known proxies
*
* @param client SubData connection
* @param name Player name
* @param callback Remote Player
*/
public static void requestGlobalPlayer(DataClient client, String name, Callback<RemotePlayer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Requests a player on this network by searching across all known proxies
*
* @param client SubData connection
* @param id Player UUID
* @param callback Remote Player
*/
public static void requestGlobalPlayer(DataClient client, UUID id, Callback<RemotePlayer> callback) {
if (Util.isNull(id, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(client, data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
}

View File

@ -15,6 +15,9 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
/**
* Simplified SubCreator Data Class
*/
public class SubCreator {
HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
Host host;

View File

@ -3,7 +3,7 @@ package net.ME1312.SubServers.Sync.Network.API;
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.SubData.Client.DataClient;
import net.ME1312.SubServers.Sync.Network.Packet.*;
import net.ME1312.SubServers.Sync.SubAPI;
@ -13,6 +13,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
/**
* Simplified SubServer Data Class
*/
public class SubServer extends Server {
private List<SubServer> incompatibilities = null;
private List<SubServer> currentIncompatibilities = null;
@ -35,22 +38,33 @@ public class SubServer extends Server {
}
/**
* Create an API representation of a Server
* Create an API representation of a SubServer
*
* @param raw JSON representation of the Server
* @param raw JSON representation of the SubServer
*/
public SubServer(ObjectMap<String> raw) {
super(raw);
super(null, raw);
}
/**
* Create an API representation of a Server
* Create an API representation of a SubServer
*
* @param client SubData connection
* @param raw JSON representation of the SubServer
*/
SubServer(DataClient client, ObjectMap<String> raw) {
super(client, raw);
}
/**
* Create an API representation of a SubServer
*
* @param host Host
* @param raw JSON representation of the Server
* @param raw JSON representation of the SubServer
*/
SubServer(Host host, ObjectMap<String> raw) {
super(raw);
super(host.client, raw);
this.host = host;
}
@ -76,7 +90,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(player, getName(), data -> {
client().sendPacket(new PacketStartServer(player, getName(), data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -121,7 +135,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), false, data -> {
client().sendPacket(new PacketStopServer(player, getName(), false, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -166,7 +180,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), true, data -> {
client().sendPacket(new PacketStopServer(player, getName(), true, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -212,7 +226,7 @@ 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();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(player, getName(), command, data -> {
client().sendPacket(new PacketCommandServer(player, getName(), command, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -335,7 +349,7 @@ public class SubServer extends Server {
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 -> {
client().sendPacket(new PacketEditServer(player, getName(), edit, perma, data -> {
try {
if (data.getInt(0x0001) != 0) {
response.run(data.getInt(0x0001) * -1);
@ -660,7 +674,7 @@ public class SubServer extends Server {
if (incompatibilities == null) {
LinkedList<String> incompatible = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible-list")) incompatible.add(subserver.toLowerCase());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
client().sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) incompatibilities.add(new SubServer(data.getMap(server)));
@ -704,7 +718,7 @@ public class SubServer extends Server {
if (currentIncompatibilities == null) {
LinkedList<String> incompatible = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible")) incompatible.add(subserver.toLowerCase());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
client().sendPacket(new PacketDownloadServerInfo(incompatible, data -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (String server : data.getKeys()) {
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) incompatibilities.add(new SubServer(data.getMap(server)));

View File

@ -27,82 +27,86 @@ import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
/**
* SubServers Protocol Class
*/
public class SubProtocol extends SubDataProtocol {
private static SubProtocol instance;
private SubProtocol() {}
@SuppressWarnings("deprecation")
protected SubProtocol() {
ExProxy plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2");
addVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
registerPacket(0x0000, PacketLinkProxy.class);
registerPacket(0x0000, new PacketLinkProxy(plugin));
// 10-2F: Download Packets
registerPacket(0x0010, PacketDownloadLang.class);
registerPacket(0x0011, PacketDownloadPlatformInfo.class);
registerPacket(0x0012, PacketDownloadProxyInfo.class);
registerPacket(0x0013, PacketDownloadHostInfo.class);
registerPacket(0x0014, PacketDownloadGroupInfo.class);
registerPacket(0x0015, PacketDownloadServerInfo.class);
registerPacket(0x0016, PacketDownloadPlayerInfo.class);
registerPacket(0x0017, PacketCheckPermission.class);
registerPacket(0x0018, PacketCheckPermissionResponse.class);
registerPacket(0x0010, new PacketDownloadLang(plugin));
registerPacket(0x0011, new PacketDownloadPlatformInfo());
registerPacket(0x0012, new PacketDownloadProxyInfo());
registerPacket(0x0013, new PacketDownloadHostInfo());
registerPacket(0x0014, new PacketDownloadGroupInfo());
registerPacket(0x0015, new PacketDownloadServerInfo());
registerPacket(0x0016, new PacketDownloadPlayerInfo());
registerPacket(0x0017, new PacketCheckPermission());
registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
registerPacket(0x0030, PacketCreateServer.class);
registerPacket(0x0031, PacketAddServer.class);
registerPacket(0x0032, PacketStartServer.class);
registerPacket(0x0033, PacketUpdateServer.class);
registerPacket(0x0034, PacketEditServer.class);
registerPacket(0x0035, PacketRestartServer.class);
registerPacket(0x0036, PacketCommandServer.class);
registerPacket(0x0037, PacketStopServer.class);
registerPacket(0x0038, PacketRemoveServer.class);
registerPacket(0x0039, PacketDeleteServer.class);
registerPacket(0x0030, new PacketCreateServer());
registerPacket(0x0031, new PacketAddServer());
registerPacket(0x0032, new PacketStartServer());
registerPacket(0x0033, new PacketUpdateServer());
registerPacket(0x0034, new PacketEditServer());
registerPacket(0x0035, new PacketRestartServer());
registerPacket(0x0036, new PacketCommandServer());
registerPacket(0x0037, new PacketStopServer());
registerPacket(0x0038, new PacketRemoveServer());
registerPacket(0x0039, new PacketDeleteServer());
// 70-7F: External Misc Packets
//registerPacket(0x0070, PacketInExRunEvent.class);
//registerPacket(0x0071, PacketInExReset.class);
//registerPacket(0x0073, PacketInExReload.class);
registerPacket(0x0074, PacketExSyncPlayer.class);
registerPacket(0x0070, new PacketInExRunEvent(plugin));
registerPacket(0x0071, new PacketInExReset());
registerPacket(0x0073, new PacketInExUpdateWhitelist(plugin));
registerPacket(0x0074, new PacketExSyncPlayer(plugin));
}
public static SubProtocol get() {
if (instance == null) {
if (instance == null)
instance = new SubProtocol();
ExProxy plugin = SubAPI.getInstance().getInternals();
instance.setName("SubServers 2");
instance.addVersion(new Version("2.16a+"));
// 00-0F: Object Link Packets
instance.registerPacket(0x0000, PacketLinkProxy.class);
instance.registerPacket(0x0000, new PacketLinkProxy(plugin));
// 10-2F: 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, PacketDownloadPlayerInfo.class);
instance.registerPacket(0x0017, PacketCheckPermission.class);
instance.registerPacket(0x0018, PacketCheckPermissionResponse.class);
instance.registerPacket(0x0010, new PacketDownloadLang(plugin));
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 PacketDownloadPlayerInfo());
instance.registerPacket(0x0017, new PacketCheckPermission());
instance.registerPacket(0x0018, new PacketCheckPermissionResponse());
// 30-4F: Control Packets
instance.registerPacket(0x0030, PacketCreateServer.class);
instance.registerPacket(0x0031, PacketAddServer.class);
instance.registerPacket(0x0032, PacketStartServer.class);
instance.registerPacket(0x0033, PacketUpdateServer.class);
instance.registerPacket(0x0034, PacketEditServer.class);
instance.registerPacket(0x0035, PacketRestartServer.class);
instance.registerPacket(0x0036, PacketCommandServer.class);
instance.registerPacket(0x0037, PacketStopServer.class);
instance.registerPacket(0x0038, PacketRemoveServer.class);
instance.registerPacket(0x0039, PacketDeleteServer.class);
instance.registerPacket(0x0030, new PacketCreateServer());
instance.registerPacket(0x0031, new PacketAddServer());
instance.registerPacket(0x0032, new PacketStartServer());
instance.registerPacket(0x0033, new PacketUpdateServer());
instance.registerPacket(0x0034, new PacketEditServer());
instance.registerPacket(0x0035, new PacketRestartServer());
instance.registerPacket(0x0036, new PacketCommandServer());
instance.registerPacket(0x0037, new PacketStopServer());
instance.registerPacket(0x0038, new PacketRemoveServer());
instance.registerPacket(0x0039, new PacketDeleteServer());
// 70-7F: External Misc Packets
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
//instance.registerPacket(0x0071, PacketInExReset.class);
//instance.registerPacket(0x0073, PacketInExReload.class);
instance.registerPacket(0x0074, PacketExSyncPlayer.class);
instance.registerPacket(0x0070, new PacketInExRunEvent(plugin));
instance.registerPacket(0x0071, new PacketInExReset());
instance.registerPacket(0x0073, new PacketInExUpdateWhitelist(plugin));
instance.registerPacket(0x0074, new PacketExSyncPlayer(plugin));
}
return instance;
}

View File

@ -16,6 +16,8 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.util.*;
import static net.ME1312.SubServers.Sync.Network.API.SimplifiedData.*;
/**
* SubAPI Class
*/
@ -68,13 +70,8 @@ public final class SubAPI {
*
* @return Proxy Name
*/
@SuppressWarnings("unchecked")
public String getName() {
if (name != null) {
return name;
} else {
return null;
}
return name;
}
/**
@ -83,22 +80,7 @@ public final class SubAPI {
* @param callback Host Map
*/
public void getHosts(Callback<Map<String, Host>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(null, data -> {
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
for (String host : data.getKeys()) {
hosts.put(host.toLowerCase(), new Host(data.getMap(host)));
}
try {
callback.run(hosts);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestHosts(null, callback);
}
/**
@ -108,22 +90,7 @@ public final class SubAPI {
* @param callback a Host
*/
public void getHost(String name, Callback<Host> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(Collections.singletonList(name), data -> {
Host host = null;
if (data.getKeys().size() > 0) {
host = new Host(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(host);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestHost(null, name, callback);
}
/**
@ -132,30 +99,7 @@ public final class SubAPI {
* @param callback Group Map
*/
public void getGroups(Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(null, data -> {
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
for (String group : data.getKeys()) {
ArrayList<Server> servers = new ArrayList<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.getMap(group).getMap(server)));
}
}
if (servers.size() > 0) groups.put(group, servers);
}
try {
callback.run(groups);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGroups(null, callback);
}
/**
@ -164,14 +108,7 @@ public final class SubAPI {
* @param callback Group Map
*/
public void getLowercaseGroups(Callback<Map<String, List<Server>>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
getGroups(groups -> {
TreeMap<String, List<Server>> lowercaseGroups = new TreeMap<String, List<Server>>();
for (String key : groups.keySet()) {
lowercaseGroups.put(key.toLowerCase(), groups.get(key));
}
callback.run(lowercaseGroups);
});
requestLowercaseGroups(null, callback);
}
/**
@ -181,31 +118,7 @@ public final class SubAPI {
* @param callback a Server Group
*/
public void getGroup(String name, Callback<NamedContainer<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<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.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
}
try {
callback.run(group);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestGroup(null, name, callback);
}
/**
@ -214,26 +127,7 @@ public final class SubAPI {
* @param callback Server Map
*/
public void getServers(Callback<Map<String, Server>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(null, data -> {
TreeMap<String, Server> servers = new TreeMap<String, 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.getMap(server)));
}
}
try {
callback.run(servers);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestServers(null, callback);
}
/**
@ -243,27 +137,7 @@ public final class SubAPI {
* @param callback a Server
*/
public void getServer(String name, Callback<Server> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(Collections.singletonList(name), data -> {
Server server = null;
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.getMap(key));
}
}
try {
callback.run(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestServer(null, name, callback);
}
/**
@ -440,14 +314,7 @@ public final class SubAPI {
* @param callback SubServer Map
*/
public void getSubServers(Callback<Map<String, SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
getServers(servers -> {
TreeMap<String, SubServer> subservers = new TreeMap<String, SubServer>();
for (String server : servers.keySet()) {
if (servers.get(server) instanceof SubServer) subservers.put(server, (SubServer) servers.get(server));
}
callback.run(subservers);
});
requestSubServers(null, callback);
}
/**
@ -457,8 +324,7 @@ public final class SubAPI {
* @param callback a SubServer
*/
public void getSubServer(String name, Callback<SubServer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
getServer(name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
requestSubServer(null, name, callback);
}
/**
@ -467,22 +333,7 @@ public final class SubAPI {
* @param callback Proxy Map
*/
public void getProxies(Callback<Map<String, Proxy>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(null, data -> {
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
for (String proxy : data.getKeys()) {
proxies.put(proxy.toLowerCase(), new Proxy(data.getMap(proxy)));
}
try {
callback.run(proxies);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestProxies(null, callback);
}
/**
@ -492,22 +343,7 @@ public final class SubAPI {
* @param callback a Proxy
*/
public void getProxy(String name, Callback<Proxy> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.singletonList(name), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestProxy(null, name, callback);
}
/**
@ -516,26 +352,40 @@ public final class SubAPI {
* @param callback Master Proxy
*/
public void getMasterProxy(Callback<Proxy> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(Collections.emptyList(), data -> {
Proxy proxy = null;
if (data.getKeys().size() > 0) {
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(proxy);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
requestMasterProxy(null, callback);
}
/**
* Get players on this network across all known proxies (Cached)
* Gets players on this network across all known proxies
*
* @param callback Remote Player Collection
*/
public void getGlobalPlayers(Callback<Map<UUID, RemotePlayer>> callback) {
requestGlobalPlayers(null, callback);
}
/**
* Gets a player on this network by searching across all known proxies
*
* @param name Player name
* @param callback Remote Player
*/
public void getGlobalPlayer(String name, Callback<RemotePlayer> callback) {
requestGlobalPlayer(null, name, callback);
}
/**
* Gets a player on this network by searching across all known proxies
*
* @param id Player UUID
* @param callback Remote Player
*/
public void getGlobalPlayer(UUID id, Callback<RemotePlayer> callback) {
requestGlobalPlayer(null, id, callback);
}
/**
* Gets players on this network across all known proxies (Cached)
*
* @return Remote Player Collection
*/
@ -544,31 +394,7 @@ public final class SubAPI {
}
/**
* Get players on this network across all known proxies
*
* @param callback Remote Player Collection
*/
public void getGlobalPlayers(Callback<Map<UUID, RemotePlayer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo((List<UUID>) null, data -> {
TreeMap<UUID, RemotePlayer> players = new TreeMap<UUID, RemotePlayer>();
for (String player : data.getKeys()) {
players.put(UUID.fromString(player), new RemotePlayer(data.getMap(player)));
}
try {
callback.run(players);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Get a player on this network by searching across all known proxies (Cached)
* Gets a player on this network by searching across all known proxies (Cached)
*
* @param name Player name
* @return Remote Player
@ -582,32 +408,7 @@ public final class SubAPI {
}
/**
* Get a player on this network by searching across all known proxies
*
* @param name Player name
* @param callback Remote Player
*/
public void getGlobalPlayer(String name, Callback<RemotePlayer> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(name), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Get a player on this network by searching across all known proxies (Cached)
* Gets a player on this network by searching across all known proxies (Cached)
*
* @param id Player UUID
* @return Remote Player
@ -617,31 +418,6 @@ public final class SubAPI {
return getGlobalPlayers().getOrDefault(id, null);
}
/**
* Get a player on this network by searching across all known proxies
*
* @param id Player UUID
* @param callback Remote Player
*/
public void getGlobalPlayer(UUID id, Callback<RemotePlayer> callback) {
if (Util.isNull(id, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerInfo(Collections.singletonList(id), data -> {
RemotePlayer player = null;
if (data.getKeys().size() > 0) {
player = new RemotePlayer(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
}
try {
callback.run(player);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Gets the SubData Network Connections
*