Skip to content

Commit

Permalink
Allow SubProtocol to be extended
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Aug 12, 2020
1 parent efc12e0 commit 83041a1
Show file tree
Hide file tree
Showing 42 changed files with 2,629 additions and 1,508 deletions.
4 changes: 2 additions & 2 deletions SubServers.Bungee/pom.xml
Expand Up @@ -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>
Expand Down
Expand Up @@ -15,10 +15,122 @@
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() {
Expand All @@ -27,111 +139,6 @@ public static SubProtocol get() {
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;
Expand Down
2 changes: 1 addition & 1 deletion SubServers.Client/Bukkit/pom.xml
Expand Up @@ -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>
Expand Down
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -18,11 +19,15 @@
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;

/**
Expand All @@ -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);
}

Expand All @@ -51,12 +67,16 @@ private void load(ObjectMap<String> raw) {
}
}

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))));
}

/**
Expand Down Expand Up @@ -193,7 +213,7 @@ public void getGlobalPlayers(Callback<Collection<RemotePlayer>> callback) {
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)));
Expand Down Expand Up @@ -363,7 +383,7 @@ public void addSubServer(String name, boolean enabled, int port, String motd, bo
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) {
Expand Down Expand Up @@ -500,7 +520,7 @@ public void forceRemoveSubServer(UUID player, String name, Callback<Integer> res
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) {
Expand Down Expand Up @@ -686,7 +706,7 @@ public void forceDeleteSubServer(UUID player, String name, Callback<Integer> res
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) {
Expand Down

0 comments on commit 83041a1

Please sign in to comment.