Prevent Directory from being inherited

This commit is contained in:
ME1312 2021-07-26 16:50:03 -04:00
parent ef1c593607
commit 5263f9d018
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
4 changed files with 42 additions and 29 deletions

View File

@ -176,6 +176,7 @@ public class ExternalSubCreator extends SubCreator {
ObjectMap<String> server = new ObjectMap<String>();
ObjectMap<String> config = new ObjectMap<String>((Map<String, ?>) data.getObject(0x0002));
if (config.contains("Directory") && (update != null || !template.getConfigOptions().contains("Directory"))) config.remove("Directory");
if (update == null) {
server.set("Enabled", true);

View File

@ -278,6 +278,7 @@ public class InternalSubCreator extends SubCreator {
host.plugin.exServers.remove(name.toLowerCase());
config = new ObjectMap<String>((Map<String, ?>) replacements.replace(config.get()));
if (config.contains("Directory") && (update != null || !template.getConfigOptions().contains("Directory"))) config.remove("Directory");
if (update == null) {
server.set("Enabled", true);

View File

@ -87,13 +87,13 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
address = new InetSocketAddress(sa[0], Integer.parseInt(sa[1]));
}
Map<String, Server> servers = plugin.api.getServers();
Server server;
Map<String, Server> servers = plugin.api.getServers();
if (name != null && servers.keySet().contains(name.toLowerCase())) {
link(client, name, address, servers.get(name.toLowerCase()), channel);
link(client, servers.get(name.toLowerCase()), channel);
} else if (address != null) {
if ((server = search(address)) != null || !strict) {
link(client, name, address, server, channel);
if ((server = search(address)) != null || (server = create(name, address)) != null) {
link(client, server, channel);
} else {
throw new ServerLinkException("There is no server with address: " + address.getAddress().getHostAddress() + ':' + address.getPort());
}
@ -112,18 +112,31 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
}
}
private Server create(String name, InetSocketAddress address) throws Throwable {
if (strict) {
return null;
} else {
String id = (name == null)? Util.getNew(SubAPI.getInstance().getServers().keySet(), () -> UUID.randomUUID().toString()) : name;
Server server = SubAPI.getInstance().addServer(id, address.getAddress(), address.getPort(), "Some Dynamic Server", name == null, false);
if (server != null) Util.reflect(ServerImpl.class.getDeclaredField("persistent"), server, false);
return server;
}
}
private Server search(InetSocketAddress address) {
Server server = null;
for (Server s : plugin.api.getServers().values()) {
if (s.getAddress().equals(address)) {
if (server != null) throw new ServerLinkException("Multiple servers match address: " + address.getAddress().getHostAddress() + ':' + address.getPort());
server = s;
}
}
return server;
}
static long req = 1;
static long last = Calendar.getInstance().getTime().getTime();
private void link(SubDataClient client, String name, InetSocketAddress address, Server resolved, int channel) throws Throwable {
final Server server;
if (resolved == null) {
String id = (name == null)? Util.getNew(SubAPI.getInstance().getServers().keySet(), () -> UUID.randomUUID().toString()) : name;
server = SubAPI.getInstance().addServer(id, address.getAddress(), address.getPort(), "Some Dynamic Server", name == null, false);
Util.reflect(ServerImpl.class.getDeclaredField("persistent"), server, false);
} else {
server = resolved;
}
private void link(SubDataClient client, Server server, int channel) throws Throwable {
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(ServerImpl.class.getDeclaredField("subdata"), server), null);
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
server.setSubData(client, channel);
@ -166,17 +179,6 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
}
}
private Server search(InetSocketAddress address) throws ServerLinkException {
Server server = null;
for (Server s : plugin.api.getServers().values()) {
if (s.getAddress().equals(address)) {
if (server != null) throw new ServerLinkException("Multiple servers match address: " + address.getAddress().getHostAddress() + ':' + address.getPort());
server = s;
}
}
return server;
}
@Override
public int version() {
return 0x0001;

View File

@ -9,8 +9,10 @@ import net.ME1312.Galaxi.Log.LogStream;
import net.ME1312.Galaxi.Log.Logger;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.DisconnectReason;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Host.ExHost;
import net.ME1312.SubServers.Host.Library.TextColor;
import net.ME1312.SubServers.Host.Network.Packet.PacketOutExLogMessage;
@ -69,10 +71,7 @@ public class SubLoggerImpl {
// Log to NETWORK
if (logn) {
if (this.address != null && channel != null && !channel.isClosed()) {
if (ccache != null) {
for (Pair<Byte, String> val : ccache) channel.sendPacket(new PacketOutExLogMessage(this.address, val.key(), val.value()));
ccache = null;
}
flushCache(channel);
channel.sendPacket(new PacketOutExLogMessage(this.address, stream.getLevel().getID(), message));
} else {
if (ccache == null) ccache = new LinkedList<Pair<Byte, String>>();
@ -85,9 +84,18 @@ public class SubLoggerImpl {
});
}
private void flushCache(DataSender sender) {
if (ccache != null) {
SubDataSender channel = (SubDataSender) sender;
for (Pair<Byte, String> val : ccache) channel.sendPacket(new PacketOutExLogMessage(this.address, val.key(), val.value()));
ccache = null;
}
}
@SuppressWarnings("deprecation")
void init() {
if (logn) Util.isException(() -> {
Process process = this.process;
ExHost host = SubAPI.getInstance().getInternals();
channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel();
channel.on.closed(new Callback<Pair<DisconnectReason, DataClient>>() {
@ -107,6 +115,7 @@ public class SubLoggerImpl {
timer.cancel();
} else try {
SubDataClient open = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].newChannel();
open.on.ready(SubLoggerImpl.this::flushCache);
open.on.closed(run);
channel = open;
timer.cancel();