mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 02:08:27 +01:00
Minor API efficiency improvements
This commit is contained in:
parent
eba5e6a7d1
commit
ff82fd5151
@ -28,13 +28,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -28,14 +28,14 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -12,6 +12,7 @@ import java.io.IOException;
|
||||
*/
|
||||
public class Executable {
|
||||
private Executable() {}
|
||||
private static final boolean USE_SESSION_TRACKING;
|
||||
|
||||
/**
|
||||
* Format a command to be executed
|
||||
@ -30,7 +31,7 @@ public class Executable {
|
||||
exec = '"' + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
||||
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + '"';
|
||||
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
||||
} else if (Platform.getSystem() == Platform.LINUX) {
|
||||
} else if (USE_SESSION_TRACKING) {
|
||||
cmd = new String[]{"setsid", "-w", "sh", "-lc", exec};
|
||||
} else {
|
||||
cmd = new String[]{"sh", "-lc", exec};
|
||||
@ -38,6 +39,14 @@ public class Executable {
|
||||
return cmd;
|
||||
}
|
||||
|
||||
static {
|
||||
USE_SESSION_TRACKING = Platform.getSystem() != Platform.WINDOWS && Util.getDespiteException(() -> {
|
||||
Process test = Runtime.getRuntime().exec(new String[]{"setsid", "-w", "bash", "-c", "exit 0"});
|
||||
test.waitFor(); // The purpose of this block is to test for the 'setsid' command
|
||||
return test.exitValue() == 0;
|
||||
}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PID of a currently running process
|
||||
*
|
||||
@ -88,7 +97,7 @@ public class Executable {
|
||||
if (pid != null) try {
|
||||
if (Platform.getSystem() == Platform.WINDOWS) {
|
||||
Runtime.getRuntime().exec(new String[]{"taskkill.exe", "/T", "/F", "/PID", pid.toString()}).waitFor();
|
||||
} else if (Platform.getSystem() == Platform.LINUX) {
|
||||
} else if (USE_SESSION_TRACKING) {
|
||||
Runtime.getRuntime().exec(new String[]{"bash", "-c", "kill -9 $(ps -o pid= --sid $(ps -o sid= --pid " + pid + "))"}).waitFor();
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {}
|
||||
|
@ -70,11 +70,11 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
|
||||
@Override
|
||||
public DataClient[] getSubData() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
Integer[] keys = subdata.keySet().toArray(new Integer[0]);
|
||||
DataClient[] channels = new DataClient[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = subdata.get(keys[i]);
|
||||
return channels;
|
||||
}
|
||||
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
|
@ -44,11 +44,11 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
|
||||
@Override
|
||||
public DataClient[] getSubData() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
Integer[] keys = subdata.keySet().toArray(new Integer[0]);
|
||||
DataClient[] channels = new DataClient[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = subdata.get(keys[i]);
|
||||
return channels;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -82,11 +82,11 @@ public class ServerImpl extends BungeeServerInfo implements Server {
|
||||
|
||||
@Override
|
||||
public DataClient[] getSubData() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
Integer[] keys = subdata.keySet().toArray(new Integer[0]);
|
||||
DataClient[] channels = new DataClient[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = subdata.get(keys[i]);
|
||||
return channels;
|
||||
}
|
||||
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
|
@ -46,7 +46,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
@ -71,11 +71,11 @@ public final class SubAPI extends ClientAPI {
|
||||
* @return SubData Network Connections
|
||||
*/
|
||||
public DataClient[] getSubDataNetwork() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(plugin.subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(plugin.subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
Integer[] keys = plugin.subdata.keySet().toArray(new Integer[0]);
|
||||
DataClient[] channels = new DataClient[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = plugin.subdata.get(keys[i]);
|
||||
return channels;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,6 @@ public final class SubPlugin extends JavaPlugin {
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
reload(false);
|
||||
|
||||
subdata.put(0, null);
|
||||
subprotocol = SubProtocol.get();
|
||||
subprotocol.registerCipher("DHE", DHE.get(128));
|
||||
subprotocol.registerCipher("DHE-128", DHE.get(128));
|
||||
|
@ -18,7 +18,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -88,11 +88,11 @@ public class Host {
|
||||
public DataSender[] getSubData() {
|
||||
if (raw.contains("subdata")) {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<SubDataSender> channels = new LinkedList<SubDataSender>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add((subdata.isNull(channel))?null:new ForwardedDataSender((SubDataClient) ClientAPI.getInstance().getSubDataNetwork()[0], subdata.getUUID(channel)));
|
||||
return channels.toArray(new SubDataSender[0]);
|
||||
Integer[] keys = subdata.getKeys().toArray(new Integer[0]);
|
||||
DataSender[] channels = new DataSender[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = (subdata.isNull(keys[i]))? null : new ForwardedDataSender((SubDataClient) ClientAPI.getInstance().getSubDataNetwork()[0], subdata.getUUID(keys[i]));
|
||||
return channels;
|
||||
} else {
|
||||
return new SubDataSender[0];
|
||||
}
|
||||
|
@ -78,11 +78,11 @@ public class Proxy {
|
||||
@SuppressWarnings("unchecked")
|
||||
public DataSender[] getSubData() {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<SubDataSender> channels = new LinkedList<SubDataSender>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add((subdata.isNull(channel))?null:new ForwardedDataSender((SubDataClient) ClientAPI.getInstance().getSubDataNetwork()[0], subdata.getUUID(channel)));
|
||||
return channels.toArray(new SubDataSender[0]);
|
||||
Integer[] keys = subdata.getKeys().toArray(new Integer[0]);
|
||||
DataSender[] channels = new DataSender[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = (subdata.isNull(keys[i]))? null : new ForwardedDataSender((SubDataClient) ClientAPI.getInstance().getSubDataNetwork()[0], subdata.getUUID(keys[i]));
|
||||
return channels;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,11 +78,11 @@ public class Server {
|
||||
@SuppressWarnings("unchecked")
|
||||
public DataSender[] getSubData() {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<SubDataSender> channels = new LinkedList<SubDataSender>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add((subdata.isNull(channel))?null:new ForwardedDataSender((SubDataClient) ClientAPI.getInstance().getSubDataNetwork()[0], subdata.getUUID(channel)));
|
||||
return channels.toArray(new SubDataSender[0]);
|
||||
Integer[] keys = subdata.getKeys().toArray(new Integer[0]);
|
||||
DataSender[] channels = new DataSender[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = (subdata.isNull(keys[i]))? null : new ForwardedDataSender((SubDataClient) ClientAPI.getInstance().getSubDataNetwork()[0], subdata.getUUID(keys[i]));
|
||||
return channels;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
@ -73,11 +73,11 @@ public final class SubAPI extends ClientAPI {
|
||||
* @return SubData Network Connections
|
||||
*/
|
||||
public DataClient[] getSubDataNetwork() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(plugin.subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(plugin.subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
Integer[] keys = plugin.subdata.keySet().toArray(new Integer[0]);
|
||||
DataClient[] channels = new DataClient[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = plugin.subdata.get(keys[i]);
|
||||
return channels;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +106,6 @@ public final class SubPlugin {
|
||||
running = true;
|
||||
reload(false);
|
||||
|
||||
subdata.put(0, null);
|
||||
subprotocol = SubProtocol.get();
|
||||
subprotocol.registerCipher("DHE", DHE.get(128));
|
||||
subprotocol.registerCipher("DHE-128", DHE.get(128));
|
||||
|
@ -31,14 +31,14 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUI</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
@ -12,6 +12,7 @@ import java.io.IOException;
|
||||
*/
|
||||
public class Executable {
|
||||
private Executable() {}
|
||||
private static final boolean USE_SESSION_TRACKING;
|
||||
|
||||
/**
|
||||
* Format a command to be executed
|
||||
@ -30,7 +31,7 @@ public class Executable {
|
||||
exec = '"' + gitbash + ((gitbash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "sh.exe\" -lc \"" +
|
||||
exec.replace("\\", "/\\").replace("\"", "\\\"").replace("^", "^^").replace("%", "^%").replace("&", "^&").replace("<", "^<").replace(">", "^>").replace("|", "^|") + '"';
|
||||
cmd = new String[]{"cmd.exe", "/q", "/c", '"'+exec+'"'};
|
||||
} else if (Platform.getSystem() == Platform.LINUX) {
|
||||
} else if (USE_SESSION_TRACKING) {
|
||||
cmd = new String[]{"setsid", "-w", "sh", "-lc", exec};
|
||||
} else {
|
||||
cmd = new String[]{"sh", "-lc", exec};
|
||||
@ -38,6 +39,14 @@ public class Executable {
|
||||
return cmd;
|
||||
}
|
||||
|
||||
static {
|
||||
USE_SESSION_TRACKING = Platform.getSystem() != Platform.WINDOWS && Util.getDespiteException(() -> {
|
||||
Process test = Runtime.getRuntime().exec(new String[]{"setsid", "-w", "bash", "-c", "exit 0"});
|
||||
test.waitFor(); // The purpose of this block is to test for the 'setsid' command
|
||||
return test.exitValue() == 0;
|
||||
}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PID of a currently running process
|
||||
*
|
||||
@ -88,7 +97,7 @@ public class Executable {
|
||||
if (pid != null) try {
|
||||
if (Platform.getSystem() == Platform.WINDOWS) {
|
||||
Runtime.getRuntime().exec(new String[]{"taskkill.exe", "/T", "/F", "/PID", pid.toString()}).waitFor();
|
||||
} else if (Platform.getSystem() == Platform.LINUX) {
|
||||
} else if (USE_SESSION_TRACKING) {
|
||||
Runtime.getRuntime().exec(new String[]{"bash", "-c", "kill -9 $(ps -o pid= --sid $(ps -o sid= --pid " + pid + "))"}).waitFor();
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {}
|
||||
|
@ -57,11 +57,11 @@ public final class SubAPI extends ClientAPI {
|
||||
* @return SubData Network Connections
|
||||
*/
|
||||
public DataClient[] getSubDataNetwork() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(host.subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(host.subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
Integer[] keys = host.subdata.keySet().toArray(new Integer[0]);
|
||||
DataClient[] channels = new DataClient[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = host.subdata.get(keys[i]);
|
||||
return channels;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,14 +28,14 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>21w15a</version>
|
||||
<version>21w15b</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -67,11 +67,11 @@ public class ServerImpl extends BungeeServerInfo {
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public DataSender[] getSubData() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.keySet());
|
||||
LinkedList<SubDataSender> channels = new LinkedList<SubDataSender>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add((subdata.getOrDefault(channel, null) == null)?null:new ForwardedDataSender((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0], subdata.get(channel)));
|
||||
return channels.toArray(new SubDataSender[0]);
|
||||
Integer[] keys = subdata.keySet().toArray(new Integer[0]);
|
||||
DataSender[] channels = new DataSender[keys.length];
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; ++i) channels[i] = (subdata.getOrDefault(keys[i], null) == null)? null : new ForwardedDataSender((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0], subdata.get(keys[i]));
|
||||
return channels;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user