mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-26 04:05:57 +01:00
Reduce dependance on SubServers.Bungee
SubServers.Host can now seamlessly reconnect to SubServers.Bungee, even if it's been restarted, without restarting uneffected servers. Also, you can now shutdown SubServers.Bungee without turning off remote servers. Isn't that neat?
This commit is contained in:
parent
3ff2459258
commit
81d37b8b1e
@ -19,6 +19,7 @@ import net.ME1312.SubServers.Bungee.Network.Packet.PacketExDeleteServer;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExRemoveServer;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExReset;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
@ -106,7 +107,9 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
clean = true;
|
||||
}
|
||||
for (SubServer server : servers.values()) {
|
||||
client.sendPacket(new PacketExAddServer(server.getName(), server.isEnabled(), server.getAddress().getPort(), server.isLogging(), server.getPath(), ((ExternalSubServer) server).exec, server.getStopCommand(), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null));
|
||||
client.sendPacket(new PacketExAddServer(server.getName(), server.isEnabled(), server.getAddress().getPort(), server.isLogging(), server.getPath(), ((ExternalSubServer) server).exec, server.getStopCommand(), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
|
||||
if (data.contains(0x0002)) ((ExternalSubServer) server).started(data.getUUID(0x0002));
|
||||
}));
|
||||
}
|
||||
while (queue.size() != 0) {
|
||||
client.sendPacket(queue.get(0));
|
||||
@ -164,11 +167,13 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
@Override
|
||||
public SubServer addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
||||
if (plugin.api.getServers().keySet().contains(name.toLowerCase())) throw new InvalidServerException("A Server already exists with this name!");
|
||||
SubServer server = new ExternalSubServer(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
||||
ExternalSubServer server = new ExternalSubServer(this, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
||||
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
queue(new PacketExAddServer(name, enabled, port, log, directory, executable, stopcmd, (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null));
|
||||
queue(new PacketExAddServer(name, enabled, port, log, directory, executable, stopcmd, (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
|
||||
if (data.contains(0x0002)) server.started(data.getUUID(0x0002));
|
||||
}));
|
||||
servers.put(name.toLowerCase(), server);
|
||||
return server;
|
||||
} else {
|
||||
@ -367,6 +372,14 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean destroy() {
|
||||
if (Util.getDespiteException(() -> Util.reflect(BungeeCord.class.getDeclaredField("isRunning"), plugin), true)) {
|
||||
return super.destroy();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<String> forSubData() {
|
||||
ObjectMap<String> hinfo = super.forSubData();
|
||||
|
@ -79,14 +79,18 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
lock = false;
|
||||
if (!event.isCancelled()) {
|
||||
Logger.get("SubServers").info("Now starting " + getName());
|
||||
started = false;
|
||||
running = true;
|
||||
logger.start();
|
||||
started(null);
|
||||
host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.START, logger.getExternalAddress().toString()));
|
||||
return true;
|
||||
} else return false;
|
||||
} else return false;
|
||||
}
|
||||
void started(UUID address) {
|
||||
started = false;
|
||||
running = true;
|
||||
logger.start();
|
||||
if (address != null && address != logger.getExternalAddress()) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_LOGGING_ADDRESS, logger.getExternalAddress().toString()));
|
||||
}
|
||||
private void falsestart() {
|
||||
Logger.get("SubServers").info("Couldn't start " + getName() + " - See the " + host.getName() + " console for more details");
|
||||
running = false;
|
||||
|
@ -13,9 +13,7 @@ import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Host Layout Class
|
||||
@ -390,6 +388,29 @@ public abstract class Host implements ExtraDataHandler {
|
||||
*/
|
||||
public abstract boolean forceDeleteSubServer(UUID player, String name) throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Resets this Host object
|
||||
*
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean destroy() {
|
||||
try {
|
||||
List<String> subservers = new ArrayList<String>();
|
||||
subservers.addAll(getSubServers().keySet());
|
||||
|
||||
for (String server : subservers) {
|
||||
forceRemoveSubServer(server);
|
||||
}
|
||||
subservers.clear();
|
||||
getCreator().terminate();
|
||||
getCreator().waitFor();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Signature of this Object
|
||||
*
|
||||
|
@ -11,6 +11,7 @@ import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Edit External Server Packet
|
||||
@ -31,7 +32,8 @@ public class PacketExEditServer implements PacketObjectIn<Integer>, PacketObject
|
||||
// Data Manipulation
|
||||
SET_ENABLED(0, Boolean.class),
|
||||
SET_LOGGING(5, Boolean.class),
|
||||
SET_STOP_COMMAND(6, String.class);
|
||||
SET_LOGGING_ADDRESS(6, String.class),
|
||||
SET_STOP_COMMAND(7, String.class);
|
||||
|
||||
private short value;
|
||||
private Class<?>[] args;
|
||||
|
@ -272,20 +272,10 @@ public final class SubAPI {
|
||||
SubRemoveHostEvent event = new SubRemoveHostEvent(player, getHost(name));
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
try {
|
||||
List<String> subservers = new ArrayList<String>();
|
||||
subservers.addAll(getHost(name).getSubServers().keySet());
|
||||
|
||||
for (String server : subservers) {
|
||||
getHost(name).removeSubServer(server);
|
||||
}
|
||||
subservers.clear();
|
||||
getHost(name).getCreator().terminate();
|
||||
getHost(name).getCreator().waitFor();
|
||||
if (getHost(name).destroy()) {
|
||||
plugin.hosts.remove(name.toLowerCase());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else return false;
|
||||
@ -312,20 +302,10 @@ public final class SubAPI {
|
||||
if (Util.isNull(name, getHost(name))) throw new NullPointerException();
|
||||
SubRemoveHostEvent event = new SubRemoveHostEvent(player, getHost(name));
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
try {
|
||||
List<String> subservers = new ArrayList<String>();
|
||||
subservers.addAll(getHost(name).getSubServers().keySet());
|
||||
|
||||
for (String server : subservers) {
|
||||
getHost(name).removeSubServer(server);
|
||||
}
|
||||
subservers.clear();
|
||||
getHost(name).getCreator().terminate();
|
||||
getHost(name).getCreator().waitFor();
|
||||
if (getHost(name).destroy()) {
|
||||
plugin.hosts.remove(name.toLowerCase());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,7 @@ package net.ME1312.SubServers.Host;
|
||||
|
||||
import com.dosse.upnp.UPnP;
|
||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Engine.GalaxiOption;
|
||||
import net.ME1312.Galaxi.Event.GalaxiReloadEvent;
|
||||
import net.ME1312.Galaxi.Galaxi;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
@ -18,18 +16,16 @@ import net.ME1312.Galaxi.Plugin.App;
|
||||
import net.ME1312.Galaxi.Plugin.PluginInfo;
|
||||
import net.ME1312.SubData.Client.Encryption.AES;
|
||||
import net.ME1312.SubData.Client.Encryption.RSA;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubCreator;
|
||||
import net.ME1312.SubServers.Host.Executable.SubLogger;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServerImpl;
|
||||
import net.ME1312.SubServers.Host.Library.*;
|
||||
import net.ME1312.SubServers.Host.Library.Updates.ConfigUpdater;
|
||||
import net.ME1312.SubServers.Host.Network.SubProtocol;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
@ -46,7 +42,7 @@ public final class ExHost {
|
||||
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
public HashMap<String, SubCreator.ServerTemplate> templates = new HashMap<String, SubCreator.ServerTemplate>();
|
||||
public HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||
public HashMap<String, SubServerImpl> servers = new HashMap<String, SubServerImpl>();
|
||||
public SubCreator creator;
|
||||
|
||||
public Logger log;
|
||||
|
@ -196,7 +196,7 @@ public class SubCreator {
|
||||
}
|
||||
|
||||
private class CreatorTask extends Thread {
|
||||
private final SubServer update;
|
||||
private final SubServerImpl update;
|
||||
private final String name;
|
||||
private final ServerTemplate template;
|
||||
private final Version version;
|
||||
@ -214,7 +214,7 @@ public class SubCreator {
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.dir = new File(host.host.getRawString("Directory"), dir.replace("$address$", host.config.get().getMap("Settings").getRawString("Server-Bind")));
|
||||
this.dir = new File(host.host.getRawString("Directory"), dir);
|
||||
this.log = new SubLogger(null, this, name + File.separator + ((update == null)?"Creator":"Updater"), address, new Container<Boolean>(true), null);
|
||||
this.address = address;
|
||||
this.tracker = tracker;
|
||||
|
@ -1,17 +1,25 @@
|
||||
package net.ME1312.SubServers.Host.Executable;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Callback.ReturnCallback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.Log.LogStream;
|
||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.DataClient;
|
||||
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.Library.TextColor;
|
||||
import net.ME1312.SubServers.Host.Network.API.Host;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketOutExLogMessage;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -59,7 +67,6 @@ public class SubLogger {
|
||||
*/
|
||||
public void start() {
|
||||
started = true;
|
||||
if (logn) Util.isException(() -> channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel());
|
||||
if (file != null && writer == null) {
|
||||
try {
|
||||
this.writer = new PrintWriter(file, "UTF-8");
|
||||
@ -69,6 +76,36 @@ public class SubLogger {
|
||||
logger.error.println(e);
|
||||
}
|
||||
}
|
||||
Process process = this.process;
|
||||
ExHost host = SubAPI.getInstance().getInternals();
|
||||
if (logn) Util.isException(() -> {
|
||||
channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel();
|
||||
channel.on.closed(new Callback<NamedContainer<DisconnectReason, DataClient>>() {
|
||||
@Override
|
||||
public void run(NamedContainer<DisconnectReason, DataClient> client) {
|
||||
if (started && SubLogger.this.process != null && process == SubLogger.this.process && process.isAlive()) {
|
||||
int reconnect = host.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
|
||||
if (Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("reconnect"), host), false) && reconnect > 0
|
||||
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
|
||||
Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::Log_Reconnect_Handler");
|
||||
Callback<NamedContainer<DisconnectReason, DataClient>> run = this;
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!started || SubLogger.this.process == null || process != SubLogger.this.process || !process.isAlive()) {
|
||||
timer.cancel();
|
||||
} else try {
|
||||
channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel();
|
||||
channel.on.closed(run);
|
||||
timer.cancel();
|
||||
} catch (NullPointerException | IOException e) {}
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if (out == null) (out = new Thread(() -> start(process.getInputStream(), false), SubAPI.getInstance().getAppInfo().getName() + "::Log_Spooler(" + name + ')')).start();
|
||||
if (err == null) (err = new Thread(() -> start(process.getErrorStream(), true), SubAPI.getInstance().getAppInfo().getName() + "::Error_Spooler(" + name + ')')).start();
|
||||
}
|
||||
@ -194,4 +231,13 @@ public class SubLogger {
|
||||
public boolean isLogging() {
|
||||
return log.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Logging Address
|
||||
*
|
||||
* @return Address
|
||||
*/
|
||||
public UUID getAddress() {
|
||||
return address;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import java.util.jar.JarInputStream;
|
||||
/**
|
||||
* Internal SubServer Class
|
||||
*/
|
||||
public class SubServer {
|
||||
public class SubServerImpl {
|
||||
private ExHost host;
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
@ -48,7 +48,7 @@ public class SubServer {
|
||||
* @param stopcmd Stop Command
|
||||
* @throws InvalidServerException
|
||||
*/
|
||||
public SubServer(ExHost host, String name, boolean enabled, int port, boolean log, String directory, String executable, String stopcmd) throws InvalidServerException {
|
||||
public SubServerImpl(ExHost host, String name, boolean enabled, int port, boolean log, String directory, String executable, String stopcmd) throws InvalidServerException {
|
||||
if (Util.isNull(host, name, enabled, log, directory, executable)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
@ -133,7 +133,8 @@ public class SubServer {
|
||||
if (falsestart) ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExEditServer(this, PacketExEditServer.UpdateType.LAUNCH_EXCEPTION));
|
||||
}
|
||||
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExEditServer(this, PacketExEditServer.UpdateType.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart));
|
||||
if (SubAPI.getInstance().getSubDataNetwork()[0] != null)
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExEditServer(this, PacketExEditServer.UpdateType.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart));
|
||||
host.log.info.println(name + " has stopped");
|
||||
process = null;
|
||||
command = null;
|
||||
@ -159,6 +160,7 @@ public class SubServer {
|
||||
try {
|
||||
allowrestart = false;
|
||||
if (process != null && process.isAlive()) {
|
||||
System.out.println(stopcmd);
|
||||
command.write(stopcmd);
|
||||
command.newLine();
|
||||
command.flush();
|
||||
@ -289,6 +291,15 @@ public class SubServer {
|
||||
return dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server's Executable String
|
||||
*
|
||||
* @return Executable String
|
||||
*/
|
||||
public String getExecutable() {
|
||||
return executable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the Command to Stop the Server
|
||||
*
|
@ -6,7 +6,7 @@ import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServerImpl;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -18,6 +18,7 @@ import java.util.logging.Logger;
|
||||
public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private int response;
|
||||
private UUID running;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
@ -37,9 +38,20 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketExAddServer(int response, UUID tracker) {
|
||||
this(response, null, tracker);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExAddServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketExAddServer(int response, UUID running, UUID tracker) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
this.response = response;
|
||||
this.tracker = tracker;
|
||||
this.running = running;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,6 +59,7 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, response);
|
||||
if (running != null) data.set(0x0002, running);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -65,14 +78,25 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
|
||||
UUID running = data.contains(0x0008)?data.getUUID(0x0008):null;
|
||||
|
||||
if (host.servers.keySet().contains(name.toLowerCase())) {
|
||||
client.sendPacket(new PacketExAddServer(1, tracker));
|
||||
SubServerImpl server = host.servers.get(name.toLowerCase());
|
||||
if (server.getPort() == port && server.getExecutable().equals(exec) && server.getDirectory().equals(dir)) {
|
||||
if (server.isEnabled() != enabled || server.getLogger().isLogging() != log || !server.getStopCommand().equals(stopcmd)) {
|
||||
server.setEnabled(enabled);
|
||||
server.setLogging(log);
|
||||
server.setStopCommand(stopcmd);
|
||||
logger.info("Re-Added SubServer: " + server.getName());
|
||||
}
|
||||
client.sendPacket(new PacketExAddServer(0, (server.isRunning())?server.getLogger().getAddress():null, tracker));
|
||||
} else {
|
||||
server.stop();
|
||||
server.waitFor();
|
||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(server.getPort()))
|
||||
UPnP.closePortTCP(server.getPort());
|
||||
|
||||
init(client, server = new SubServerImpl(host, name, enabled, port, log, dir, exec, stopcmd), running, tracker, logger);
|
||||
}
|
||||
} else {
|
||||
SubServer server = new SubServer(host, name, enabled, port, log, dir, exec, stopcmd);
|
||||
host.servers.put(name.toLowerCase(), server);
|
||||
if (UPnP.isUPnPAvailable() && host.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getPort());
|
||||
logger.info("Added SubServer: " + name);
|
||||
if (running != null) server.start(running);
|
||||
client.sendPacket(new PacketExAddServer(0, tracker));
|
||||
init(client, new SubServerImpl(host, name, enabled, port, log, dir, exec, stopcmd), running, tracker, logger);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketExAddServer(2, tracker));
|
||||
@ -80,6 +104,14 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
|
||||
}
|
||||
}
|
||||
|
||||
private void init(SubDataClient client, SubServerImpl server, UUID running, UUID tracker, Logger logger) {
|
||||
host.servers.put(server.getName().toLowerCase(), server);
|
||||
if (UPnP.isUPnPAvailable() && host.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getPort());
|
||||
logger.info("Added SubServer: " + server.getName());
|
||||
if (running != null) server.start(running);
|
||||
client.sendPacket(new PacketExAddServer(0, tracker));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
|
@ -90,7 +90,7 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
|
||||
String template = data.getRawString(0x0003);
|
||||
Version version = (data.contains(0x0004)?data.getVersion(0x0004):null);
|
||||
Integer port = data.getInt(0x0005);
|
||||
String dir = data.getRawString(0x0006);
|
||||
String dir = data.getRawString(0x0006).replace("$address$", host.config.get().getMap("Settings").getRawString("Server-Bind"));
|
||||
UUID log = data.getUUID(0x0007);
|
||||
|
||||
host.creator.create(name, host.templates.get(template.toLowerCase()), version,
|
||||
|
@ -6,11 +6,10 @@ import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServerImpl;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
@ -73,7 +72,7 @@ public class PacketExDeleteServer implements PacketObjectIn<Integer>, PacketObje
|
||||
} else if (host.servers.get(name.toLowerCase()).isRunning()) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExDeleteServer(3, tracker));
|
||||
} else {
|
||||
SubServer server = host.servers.get(name.toLowerCase());
|
||||
SubServerImpl server = host.servers.get(name.toLowerCase());
|
||||
host.servers.remove(name.toLowerCase());
|
||||
new Thread(() -> {
|
||||
UniversalFile to = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Recently Deleted:" + server.getName().toLowerCase());
|
||||
|
@ -1,22 +1,22 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServer;
|
||||
import net.ME1312.SubServers.Host.Executable.SubLogger;
|
||||
import net.ME1312.SubServers.Host.Executable.SubServerImpl;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Edit Server Packet
|
||||
*/
|
||||
public class PacketExEditServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private SubServer server;
|
||||
private SubServerImpl server;
|
||||
private UpdateType type;
|
||||
private Object[] args;
|
||||
|
||||
@ -56,7 +56,7 @@ public class PacketExEditServer implements PacketObjectIn<Integer>, PacketObject
|
||||
* @param type Update Type
|
||||
* @param arguments Arguments
|
||||
*/
|
||||
public PacketExEditServer(SubServer server, UpdateType type, Object... arguments) {
|
||||
public PacketExEditServer(SubServerImpl server, UpdateType type, Object... arguments) {
|
||||
if (arguments.length != type.getArguments().length) throw new IllegalArgumentException(((arguments.length > type.getArguments().length)?"Too many":"Not enough") + " arguments for type: " + type.toString());
|
||||
int i = 0;
|
||||
while (i < arguments.length) {
|
||||
@ -80,7 +80,7 @@ public class PacketExEditServer implements PacketObjectIn<Integer>, PacketObject
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
SubServer server = host.servers.get(data.getString(0x0000).toLowerCase());
|
||||
SubServerImpl server = host.servers.get(data.getString(0x0000).toLowerCase());
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 0:
|
||||
server.setEnabled(data.getList(0x0002).get(0).asBoolean());
|
||||
@ -101,6 +101,9 @@ public class PacketExEditServer implements PacketObjectIn<Integer>, PacketObject
|
||||
server.setLogging(data.getList(0x0002).get(0).asBoolean());
|
||||
break;
|
||||
case 6:
|
||||
Util.reflect(SubLogger.class.getDeclaredField("address"), server.getLogger(), data.getList(0x0002).get(0).asUUID());
|
||||
break;
|
||||
case 7:
|
||||
server.setStopCommand(data.getList(0x0002).get(0).asRawString());
|
||||
break;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class PacketInExReset implements PacketObjectIn<Integer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {/*
|
||||
List<String> subservers = new ArrayList<String>();
|
||||
subservers.addAll(host.servers.keySet());
|
||||
|
||||
@ -32,7 +32,7 @@ public class PacketInExReset implements PacketObjectIn<Integer> {
|
||||
}
|
||||
}
|
||||
subservers.clear();
|
||||
host.servers.clear();
|
||||
host.servers.clear(); */
|
||||
|
||||
host.creator.terminate();
|
||||
try {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.ME1312.SubServers.Host.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||
@ -162,7 +163,7 @@ public class SubProtocol extends SubDataProtocol {
|
||||
map.put(0, null);
|
||||
|
||||
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
|
||||
int reconnect = host.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
|
||||
int reconnect = host.config.get().getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getInt("Reconnect", 30);
|
||||
if (Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("reconnect"), host), false) && reconnect > 0
|
||||
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
|
||||
log.info("Attempting reconnect in " + reconnect + " seconds");
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Fallback;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerImpl;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerImpl;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
||||
@ -16,7 +16,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Smart Reconnect Handler Class
|
||||
@ -75,12 +74,12 @@ public class SmartReconnectHandler implements ReconnectHandler {
|
||||
if (server != null) {
|
||||
boolean valid = true;
|
||||
int confidence = 0;
|
||||
if (server instanceof ServerContainer) {
|
||||
if (!((ServerContainer) server).isHidden()) confidence++;
|
||||
if (!((ServerContainer) server).isRestricted()) confidence++;
|
||||
if (((ServerContainer) server).getSubData()[0] != null) confidence++;
|
||||
} if (server instanceof SubServerContainer) {
|
||||
if (!((SubServerContainer) server).isRunning()) valid = false;
|
||||
if (server instanceof ServerImpl) {
|
||||
if (!((ServerImpl) server).isHidden()) confidence++;
|
||||
if (!((ServerImpl) server).isRestricted()) confidence++;
|
||||
if (((ServerImpl) server).getSubData()[0] != null) confidence++;
|
||||
} if (server instanceof SubServerImpl) {
|
||||
if (!((SubServerImpl) server).isRunning()) valid = false;
|
||||
}
|
||||
|
||||
List<FallbackInspector> inspectors = new ArrayList<FallbackInspector>();
|
||||
|
@ -12,14 +12,14 @@ import java.util.*;
|
||||
/**
|
||||
* Server Class
|
||||
*/
|
||||
public class ServerContainer extends BungeeServerInfo {
|
||||
public class ServerImpl extends BungeeServerInfo {
|
||||
private HashMap<Integer, UUID> subdata = new HashMap<Integer, UUID>();
|
||||
private List<UUID> whitelist = new ArrayList<UUID>();
|
||||
private String nick = null;
|
||||
private boolean hidden;
|
||||
private final String signature;
|
||||
|
||||
public ServerContainer(String signature, String name, String display, InetSocketAddress address, Map<Integer, UUID> subdata, String motd, boolean hidden, boolean restricted, Collection<UUID> whitelist) {
|
||||
public ServerImpl(String signature, String name, String display, InetSocketAddress address, Map<Integer, UUID> subdata, String motd, boolean hidden, boolean restricted, Collection<UUID> whitelist) {
|
||||
super(name, address, motd, restricted);
|
||||
if (Util.isNull(name, address, motd, hidden, restricted)) throw new NullPointerException();
|
||||
this.signature = signature;
|
@ -8,10 +8,10 @@ import java.util.UUID;
|
||||
/**
|
||||
* SubServer Class
|
||||
*/
|
||||
public class SubServerContainer extends ServerContainer {
|
||||
public class SubServerImpl extends ServerImpl {
|
||||
private boolean running;
|
||||
|
||||
public SubServerContainer(String signature, String name, String display, InetSocketAddress address, Map<Integer, UUID> subdata, String motd, boolean hidden, boolean restricted, Collection<UUID> whitelist, boolean running) {
|
||||
public SubServerImpl(String signature, String name, String display, InetSocketAddress address, Map<Integer, UUID> subdata, String motd, boolean hidden, boolean restricted, Collection<UUID> whitelist, boolean running) {
|
||||
super(signature, name, display, address, subdata, motd, hidden, restricted, whitelist);
|
||||
this.running = running;
|
||||
}
|
@ -12,8 +12,8 @@ import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Library.Compatibility.GalaxiInfo;
|
||||
import net.ME1312.SubServers.Sync.Network.API.*;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerImpl;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerImpl;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@ -683,7 +683,7 @@ public final class SubCommand extends CommandX {
|
||||
// do nothing
|
||||
} else if (!players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
|
||||
|| Calendar.getInstance().getTime().getTime() - players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).name() >= TimeUnit.MINUTES.toMillis(1)) {
|
||||
if (!(((ProxiedPlayer) sender).getServer().getInfo() instanceof ServerContainer) || ((ServerContainer) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0] == null) {
|
||||
if (!(((ProxiedPlayer) sender).getServer().getInfo() instanceof ServerImpl) || ((ServerImpl) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0] == null) {
|
||||
HashMap<ServerInfo, NamedContainer<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, NamedContainer<Long, Boolean>>();
|
||||
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(Calendar.getInstance().getTime().getTime(), false));
|
||||
players.put(((ProxiedPlayer) sender).getUniqueId(), map);
|
||||
@ -723,7 +723,7 @@ public final class SubCommand extends CommandX {
|
||||
for (String proxy : proxyCache) if (!list.contains(proxy)) list.add(proxy);
|
||||
for (String host : hostCache.keySet()) if (!list.contains(host)) list.add(host);
|
||||
for (String group : groupCache) if (!list.contains(group)) list.add(group);
|
||||
for (ServerContainer server : plugin.servers.values()) if (!list.contains(server.getName())) list.add(server.getName());
|
||||
for (ServerImpl server : plugin.servers.values()) if (!list.contains(server.getName())) list.add(server.getName());
|
||||
} else {
|
||||
for (String command : subcommands) {
|
||||
if (!list.contains(command) && command.toLowerCase().startsWith(last))
|
||||
@ -741,7 +741,7 @@ public final class SubCommand extends CommandX {
|
||||
if (!list.contains(group) && group.toLowerCase().startsWith(last))
|
||||
list.add(last + group.substring(last.length()));
|
||||
}
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (!list.contains(server.getName()) && server.getName().toLowerCase().startsWith(last))
|
||||
list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
@ -767,7 +767,7 @@ public final class SubCommand extends CommandX {
|
||||
case "s":
|
||||
case "server":
|
||||
case "subserver":
|
||||
for (ServerContainer server : plugin.servers.values()) list.add(server.getName());
|
||||
for (ServerImpl server : plugin.servers.values()) list.add(server.getName());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -796,7 +796,7 @@ public final class SubCommand extends CommandX {
|
||||
case "s":
|
||||
case "server":
|
||||
case "subserver":
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (server.getName().toLowerCase().startsWith(last))
|
||||
list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
@ -812,10 +812,10 @@ public final class SubCommand extends CommandX {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (args.length == 2) {
|
||||
if (last.length() == 0) {
|
||||
for (ServerContainer server : plugin.servers.values()) if (server instanceof SubServerContainer) list.add(server.getName());
|
||||
for (ServerImpl server : plugin.servers.values()) if (server instanceof SubServerImpl) list.add(server.getName());
|
||||
} else {
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
if (server instanceof SubServerContainer && server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (server instanceof SubServerImpl && server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", args[0]):null, list);
|
||||
@ -828,11 +828,11 @@ public final class SubCommand extends CommandX {
|
||||
if (args.length == 2) {
|
||||
if (last.length() == 0) {
|
||||
list.add("*");
|
||||
for (ServerContainer server : plugin.servers.values()) if (server instanceof SubServerContainer) list.add(server.getName());
|
||||
for (ServerImpl server : plugin.servers.values()) if (server instanceof SubServerImpl) list.add(server.getName());
|
||||
} else {
|
||||
if ("*".startsWith(last)) list.add("*");
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
if (server instanceof SubServerContainer && server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (server instanceof SubServerImpl && server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", args[0]):null, list);
|
||||
@ -843,10 +843,10 @@ public final class SubCommand extends CommandX {
|
||||
if (args.length == 2) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (last.length() == 0) {
|
||||
for (ServerContainer server : plugin.servers.values()) if (server instanceof SubServerContainer) list.add(server.getName());
|
||||
for (ServerImpl server : plugin.servers.values()) if (server instanceof SubServerImpl) list.add(server.getName());
|
||||
} else {
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
if (server instanceof SubServerContainer && server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (server instanceof SubServerImpl && server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", args[0]):null, list);
|
||||
@ -900,9 +900,9 @@ public final class SubCommand extends CommandX {
|
||||
if (args.length == 2) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (last.length() == 0) {
|
||||
for (ServerContainer server : plugin.servers.values()) list.add(server.getName());
|
||||
for (ServerImpl server : plugin.servers.values()) list.add(server.getName());
|
||||
} else {
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
}
|
||||
@ -985,7 +985,7 @@ public final class SubCommand extends CommandX {
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
if (args.length > 0) {
|
||||
Map<String, ServerContainer> servers = plugin.servers;
|
||||
Map<String, ServerImpl> servers = plugin.servers;
|
||||
if (servers.keySet().contains(args[0].toLowerCase())) {
|
||||
((ProxiedPlayer) sender).connect(servers.get(args[0].toLowerCase()));
|
||||
} else {
|
||||
@ -995,8 +995,8 @@ public final class SubCommand extends CommandX {
|
||||
int i = 0;
|
||||
TextComponent serverm = new TextComponent(ChatColor.RESET.toString());
|
||||
TextComponent div = new TextComponent(plugin.api.getLang("SubServers", "Bungee.Server.Divider"));
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
if (!server.isHidden() && server.canAccess(sender) && (!(server instanceof SubServerContainer) || ((SubServerContainer) server).isRunning())) {
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (!server.isHidden() && server.canAccess(sender) && (!(server instanceof SubServerImpl) || ((SubServerImpl) server).isRunning())) {
|
||||
if (i != 0) serverm.addExtra(div);
|
||||
TextComponent message = new TextComponent(plugin.api.getLang("SubServers", "Bungee.Server.List").replace("$str$", server.getDisplayName()));
|
||||
try {
|
||||
@ -1031,12 +1031,12 @@ public final class SubCommand extends CommandX {
|
||||
String last = (args.length > 0)?args[args.length - 1].toLowerCase():"";
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (last.length() == 0) {
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (!server.isHidden()) list.add(server.getName());
|
||||
}
|
||||
return new NamedContainer<>(null, new LinkedList<>(list));
|
||||
} else {
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
if (server.getName().toLowerCase().startsWith(last) && !server.isHidden()) list.add(server.getName());
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Bungee.Server.Invalid").replace("$str$", args[0]):null, list);
|
||||
@ -1079,7 +1079,7 @@ public final class SubCommand extends CommandX {
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
List<String> messages = new LinkedList<String>();
|
||||
int players = 0;
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
for (ServerImpl server : plugin.servers.values()) {
|
||||
List<String> playerlist = new ArrayList<String>();
|
||||
if (plugin.redis) {
|
||||
try {
|
||||
@ -1093,7 +1093,7 @@ public final class SubCommand extends CommandX {
|
||||
Collections.sort(playerlist);
|
||||
|
||||
players += playerlist.size();
|
||||
if (!server.isHidden() && (!(server instanceof SubServerContainer) || ((SubServerContainer) server).isRunning())) {
|
||||
if (!server.isHidden() && (!(server instanceof SubServerImpl) || ((SubServerImpl) server).isRunning())) {
|
||||
int i = 0;
|
||||
String message = plugin.api.getLang("SubServers", "Bungee.List.Format").replace("$str$", server.getDisplayName()).replace("$int$", Integer.toString(playerlist.size()));
|
||||
for (String player : playerlist) {
|
||||
|
@ -18,8 +18,8 @@ import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Library.Updates.ConfigUpdater;
|
||||
import net.ME1312.SubServers.Sync.Network.SubProtocol;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerImpl;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerImpl;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public final class SubPlugin extends BungeeCord implements Listener {
|
||||
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
public final Map<String, ServerContainer> servers = new TreeMap<String, ServerContainer>();
|
||||
public final Map<String, ServerImpl> servers = new TreeMap<String, ServerImpl>();
|
||||
private final HashMap<UUID, List<ServerInfo>> fallbackLimbo = new HashMap<UUID, List<ServerInfo>>();
|
||||
|
||||
public final PrintStream out;
|
||||
@ -285,7 +285,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
int offline = 0;
|
||||
for (String name : e.getConnection().getListener().getServerPriority()) {
|
||||
ServerInfo server = getServerInfo(name);
|
||||
if (server == null || server instanceof SubServerContainer && !((SubServerContainer) server).isRunning()) offline++;
|
||||
if (server == null || server instanceof SubServerImpl && !((SubServerImpl) server).isRunning()) offline++;
|
||||
}
|
||||
|
||||
if (offline >= e.getConnection().getListener().getServerPriority().size()) {
|
||||
@ -320,7 +320,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
e.getPlayer().sendMessage(getTranslation("no_server_permission"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} else if (e.getPlayer().getServer() != null && !fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId()) && e.getTarget() instanceof SubServerContainer && !((SubServerContainer) e.getTarget()).isRunning()) {
|
||||
} else if (e.getPlayer().getServer() != null && !fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId()) && e.getTarget() instanceof SubServerImpl && !((SubServerImpl) e.getTarget()).isRunning()) {
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Server.Offline"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -349,7 +349,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
fallbacks.remove(e.getKickedFrom().getName());
|
||||
if (!fallbacks.isEmpty()) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback").replace("$str$", (e.getKickedFrom() instanceof ServerContainer)?((ServerContainer) e.getKickedFrom()).getDisplayName():e.getKickedFrom().getName()).replace("$msg$", e.getKickReason()));
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback").replace("$str$", (e.getKickedFrom() instanceof ServerImpl)?((ServerImpl) e.getKickedFrom()).getDisplayName():e.getKickedFrom().getName()).replace("$msg$", e.getKickReason()));
|
||||
if (!fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) fallbackLimbo.put(e.getPlayer().getUniqueId(), new LinkedList<>(fallbacks.values()));
|
||||
|
||||
ServerInfo next = new LinkedList<Map.Entry<String, ServerInfo>>(fallbacks.entrySet()).getFirst().getValue();
|
||||
@ -369,7 +369,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
public void run() {
|
||||
if (e.getPlayer().getServer() != null && !((UserConnection) e.getPlayer()).isDimensionChange() && e.getPlayer().getServer().getInfo().getAddress().equals(e.getServer().getInfo().getAddress())) {
|
||||
fallbackLimbo.remove(e.getPlayer().getUniqueId());
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback.Result").replace("$str$", (e.getServer().getInfo() instanceof ServerContainer)?((ServerContainer) e.getServer().getInfo()).getDisplayName():e.getServer().getInfo().getName()));
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback.Result").replace("$str$", (e.getServer().getInfo() instanceof ServerImpl)?((ServerImpl) e.getServer().getInfo()).getDisplayName():e.getServer().getInfo().getName()));
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
@ -393,11 +393,11 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
api.getServer(e.getServer(), server -> {
|
||||
if (server != null) {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer) {
|
||||
servers.put(server.getName().toLowerCase(), new SubServerContainer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
servers.put(server.getName().toLowerCase(), new SubServerImpl(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
getSubDataAsMap(server), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist(), ((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning()));
|
||||
Logger.get("SubServers").info("Added SubServer: " + e.getServer());
|
||||
} else {
|
||||
servers.put(server.getName().toLowerCase(), new ServerContainer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
servers.put(server.getName().toLowerCase(), new ServerImpl(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
getSubDataAsMap(server), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist()));
|
||||
Logger.get("SubServers").info("Added Server: " + e.getServer());
|
||||
}
|
||||
@ -406,14 +406,14 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
|
||||
public Boolean merge(net.ME1312.SubServers.Sync.Network.API.Server server) {
|
||||
ServerContainer current = servers.get(server.getName().toLowerCase());
|
||||
if (current == null || server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer || !(current instanceof SubServerContainer)) {
|
||||
ServerImpl current = servers.get(server.getName().toLowerCase());
|
||||
if (current == null || server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer || !(current instanceof SubServerImpl)) {
|
||||
if (current == null || !current.getSignature().equals(server.getSignature())) {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer) {
|
||||
servers.put(server.getName().toLowerCase(), new SubServerContainer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
servers.put(server.getName().toLowerCase(), new SubServerImpl(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
getSubDataAsMap(server), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist(), ((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning()));
|
||||
} else {
|
||||
servers.put(server.getName().toLowerCase(), new ServerContainer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
servers.put(server.getName().toLowerCase(), new ServerImpl(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
getSubDataAsMap(server), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist()));
|
||||
}
|
||||
|
||||
@ -421,8 +421,8 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
return true;
|
||||
} else {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer) {
|
||||
if (((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning() != ((SubServerContainer) current).isRunning())
|
||||
((SubServerContainer) current).setRunning(((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning());
|
||||
if (((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning() != ((SubServerImpl) current).isRunning())
|
||||
((SubServerImpl) current).setRunning(((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning());
|
||||
}
|
||||
if (!server.getMotd().equals(current.getMotd()))
|
||||
current.setMotd(server.getMotd());
|
||||
@ -443,7 +443,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void edit(SubEditServerEvent e) {
|
||||
if (servers.keySet().contains(e.getServer().toLowerCase())) {
|
||||
ServerContainer server = servers.get(e.getServer().toLowerCase());
|
||||
ServerImpl server = servers.get(e.getServer().toLowerCase());
|
||||
switch (e.getEdit().name().toLowerCase()) {
|
||||
case "display":
|
||||
server.setDisplayName(e.getEdit().get().asString());
|
||||
@ -463,17 +463,17 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void start(SubStartEvent e) {
|
||||
if (servers.keySet().contains(e.getServer().toLowerCase()) && servers.get(e.getServer().toLowerCase()) instanceof SubServerContainer)
|
||||
((SubServerContainer) servers.get(e.getServer().toLowerCase())).setRunning(true);
|
||||
if (servers.keySet().contains(e.getServer().toLowerCase()) && servers.get(e.getServer().toLowerCase()) instanceof SubServerImpl)
|
||||
((SubServerImpl) servers.get(e.getServer().toLowerCase())).setRunning(true);
|
||||
}
|
||||
|
||||
public void connect(ServerContainer server, int channel, UUID address) {
|
||||
public void connect(ServerImpl server, int channel, UUID address) {
|
||||
if (server != null) {
|
||||
server.setSubData(address, channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect(ServerContainer server, int channel) {
|
||||
public void disconnect(ServerImpl server, int channel) {
|
||||
if (server != null) {
|
||||
server.setSubData(null, channel);
|
||||
}
|
||||
@ -481,8 +481,8 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void stop(SubStoppedEvent e) {
|
||||
if (servers.keySet().contains(e.getServer().toLowerCase()) && servers.get(e.getServer().toLowerCase()) instanceof SubServerContainer)
|
||||
((SubServerContainer) servers.get(e.getServer().toLowerCase())).setRunning(false);
|
||||
if (servers.keySet().contains(e.getServer().toLowerCase()) && servers.get(e.getServer().toLowerCase()) instanceof SubServerImpl)
|
||||
((SubServerImpl) servers.get(e.getServer().toLowerCase())).setRunning(false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
|
Loading…
Reference in New Issue
Block a user