mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 02:08:27 +01:00
Queue packets until subdata connection is authorized
This commit is contained in:
parent
f2f01576df
commit
9a219a7d0f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path: BungeeCord.jar
|
||||
Main-Class: net.ME1312.SubServers.Bungee.Launch
|
||||
Implementation-Version: 2.12.1f
|
||||
Specification-Version: 0
|
||||
Implementation-Version: 2.12.2a
|
||||
Specification-Version: 1
|
||||
|
Binary file not shown.
@ -25,6 +25,7 @@ import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Internal SubCreator Class
|
||||
@ -44,7 +45,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
public InternalSubCreator(InternalHost host, String gitBash) {
|
||||
if (Util.isNull(host, gitBash)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.gitBash = gitBash;
|
||||
this.gitBash = (System.getenv("ProgramFiles(x86)") == null)?Pattern.compile("%(ProgramFiles)\\(x86\\)%", Pattern.CASE_INSENSITIVE).matcher(gitBash).replaceAll("%$1%"):gitBash;
|
||||
this.thread = new TreeMap<String, NamedContainer<Thread, NamedContainer<InternalSubLogger, Process>>>();
|
||||
reload();
|
||||
}
|
||||
@ -132,7 +133,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
}
|
||||
|
||||
if (template.getBuildOptions().contains("Shell-Location")) {
|
||||
File gitBash = new File(this.gitBash, "bin" + File.separatorChar + "bash.exe");
|
||||
String gitBash = this.gitBash + ((this.gitBash.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "bash.exe";
|
||||
if (!(System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) && template.getBuildOptions().contains("Permission")) {
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("chmod " + template.getBuildOptions().getRawString("Permission") + ' ' + template.getBuildOptions().getRawString("Shell-Location"), null, dir);
|
||||
@ -148,7 +149,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
|
||||
try {
|
||||
System.out.println(name + "/Creator > Launching " + template.getBuildOptions().getRawString("Shell-Location"));
|
||||
thread.set(Runtime.getRuntime().exec((System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) ? "\"" + gitBash + "\" --login -i -c \"bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + '\"' : ("bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + " " + System.getProperty("user.home")), null, dir));
|
||||
thread.set(Runtime.getRuntime().exec((System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) ? "cmd.exe /c \"\"" + gitBash + "\" --login -i -c \"bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + "\"\"" : ("bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + " " + System.getProperty("user.home")), null, dir));
|
||||
thread.name().log.set(host.plugin.config.get().getSection("Settings").getBoolean("Log-Creator"));
|
||||
thread.name().file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString().replace(" ", "@") + ".log");
|
||||
thread.name().process = thread.get();
|
||||
|
@ -14,7 +14,7 @@ Hosts:
|
||||
Driver: 'BUILT-IN'
|
||||
Address: '127.0.0.1'
|
||||
Directory: './'
|
||||
Git-Bash: 'C:\Program Files\Git'
|
||||
Git-Bash: '%ProgramFiles%\Git'
|
||||
|
||||
Servers:
|
||||
'Example':
|
||||
|
Binary file not shown.
@ -1,14 +1,17 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
@ -29,7 +32,12 @@ public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
public void execute(JSONObject data) {
|
||||
try {
|
||||
if (data.getInt("r") == 0) {
|
||||
plugin.subdata.sendPacket(new PacketLinkServer(plugin));
|
||||
try {
|
||||
Method m = SubDataClient.class.getDeclaredMethod("sendPacket", NamedContainer.class);
|
||||
m.setAccessible(true);
|
||||
m.invoke(plugin.subdata, new NamedContainer<String, PacketOut>(null, new PacketLinkServer(plugin)));
|
||||
m.setAccessible(false);
|
||||
} catch (Exception e) {}
|
||||
} else {
|
||||
Bukkit.getLogger().info("SubServers > Could not authorize SubData connection: " + data.getString("m"));
|
||||
plugin.subdata.destroy(0);
|
||||
|
@ -1,14 +1,16 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Link Server Packet
|
||||
*/
|
||||
@ -35,8 +37,12 @@ public class PacketLinkServer implements PacketIn, PacketOut {
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
if (data.getInt("r") == 0) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadLang());
|
||||
Bukkit.getPluginManager().callEvent(new SubNetworkConnectEvent(plugin.subdata));
|
||||
try {
|
||||
Method m = SubDataClient.class.getDeclaredMethod("init");
|
||||
m.setAccessible(true);
|
||||
m.invoke(plugin.subdata);
|
||||
m.setAccessible(false);
|
||||
} catch (Exception e) {}
|
||||
} else {
|
||||
Bukkit.getLogger().info("SubData > Could not link name with server: " + data.getString("m"));
|
||||
plugin.onDisable();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Container;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Exception.IllegalPacketException;
|
||||
@ -28,7 +29,7 @@ public final class SubDataClient {
|
||||
private static HashMap<String, List<PacketIn>> pIn = new HashMap<String, List<PacketIn>>();
|
||||
private static boolean defaults = false;
|
||||
private PrintWriter writer;
|
||||
private Socket socket;
|
||||
private NamedContainer<Boolean, Socket> socket;
|
||||
private String name;
|
||||
private Encryption encryption;
|
||||
private SubPlugin plugin;
|
||||
@ -54,17 +55,27 @@ public final class SubDataClient {
|
||||
*/
|
||||
public SubDataClient(SubPlugin plugin, String name, InetAddress address, int port, Encryption encryption) throws IOException {
|
||||
if (Util.isNull(plugin, name, address, port)) throw new NullPointerException();
|
||||
socket = new Socket(address, port);
|
||||
socket = new NamedContainer<>(false, new Socket(address, port));
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.writer = new PrintWriter(socket.getOutputStream(), true);
|
||||
this.writer = new PrintWriter(socket.get().getOutputStream(), true);
|
||||
this.encryption = encryption;
|
||||
this.queue = new LinkedList<NamedContainer<String, PacketOut>>();
|
||||
|
||||
if (!defaults) loadDefaults();
|
||||
loop();
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> sendPacket(new PacketAuthorization(plugin)), 10);
|
||||
sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin)));
|
||||
}
|
||||
|
||||
private void init() {
|
||||
sendPacket(new PacketDownloadLang());
|
||||
while (queue.size() != 0) {
|
||||
sendPacket(queue.get(0));
|
||||
queue.remove(0);
|
||||
}
|
||||
socket.rename(true);
|
||||
Bukkit.getPluginManager().callEvent(new SubNetworkConnectEvent(this));
|
||||
}
|
||||
|
||||
private void loadDefaults() {
|
||||
@ -104,7 +115,7 @@ public final class SubDataClient {
|
||||
private void loop() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.get().getInputStream()));
|
||||
String input;
|
||||
while ((input = in.readLine()) != null) {
|
||||
String decoded = null;
|
||||
@ -168,7 +179,7 @@ public final class SubDataClient {
|
||||
* @return Server Socket
|
||||
*/
|
||||
public Socket getClient() {
|
||||
return socket;
|
||||
return socket.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -254,27 +265,33 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void sendPacket(PacketOut packet) {
|
||||
if (Util.isNull(packet)) throw new NullPointerException();
|
||||
if (socket == null) {
|
||||
if (socket == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(null, packet));
|
||||
} else {
|
||||
try {
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(encodePacket(packet));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendPacket(new NamedContainer<>(null, packet));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(NamedContainer<String, PacketOut> packet) {
|
||||
try {
|
||||
JSONObject json = encodePacket(packet.get());
|
||||
if (packet.name() != null) json.put("f", packet.name());
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(json.toString());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,29 +303,10 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void forwardPacket(PacketOut packet, String location) {
|
||||
if (Util.isNull(packet, location)) throw new NullPointerException();
|
||||
if (socket == null) {
|
||||
if (socket.get() == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(location, packet));
|
||||
} else {
|
||||
try {
|
||||
JSONObject json = encodePacket(packet);
|
||||
json.put("f", location);
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(json.toString());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendPacket(new NamedContainer<>(location, packet));
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,9 +374,9 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void destroy(int reconnect) throws IOException {
|
||||
if (Util.isNull(reconnect)) throw new NullPointerException();
|
||||
if (socket != null) {
|
||||
final Socket socket = this.socket;
|
||||
this.socket = null;
|
||||
if (socket.get() != null) {
|
||||
final Socket socket = this.socket.get();
|
||||
this.socket.set(null);
|
||||
if (!socket.isClosed()) socket.close();
|
||||
Bukkit.getPluginManager().callEvent(new SubNetworkDisconnectEvent());
|
||||
Bukkit.getLogger().info("SubServers > The SubData Connection was closed");
|
||||
|
@ -27,7 +27,7 @@ public final class SubPlugin extends JavaPlugin {
|
||||
|
||||
public UIHandler gui = null;
|
||||
public final Version version;
|
||||
public final Version bversion = null;
|
||||
public final Version bversion = new Version(1);
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
|
||||
public SubPlugin() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: 'SubServers-Client-Bukkit'
|
||||
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
|
||||
version: '2.12.1e'
|
||||
version: '2.12.2a'
|
||||
authors: [ME1312]
|
||||
softdepend: [Vault, TitleManager]
|
||||
website: 'http://www.ME1312.net/'
|
||||
|
@ -105,10 +105,10 @@ public class AnsiHTMLColorStream extends AnsiOutputStream {
|
||||
}
|
||||
|
||||
protected void processSetForegroundColor(int color) throws IOException {
|
||||
this.writeAttribute("span style=\"color: #" + ANSI_COLOR_MAP[color] + ";\"");
|
||||
this.writeAttribute("span class=\"ansi\" style=\"color: #" + ANSI_COLOR_MAP[color] + ";\"");
|
||||
}
|
||||
|
||||
protected void processSetBackgroundColor(int color) throws IOException {
|
||||
this.writeAttribute("span style=\"background-color: #" + ANSI_COLOR_MAP[color] + ";\"");
|
||||
this.writeAttribute("span class=\"ansi-background\" style=\"background-color: #" + ANSI_COLOR_MAP[color] + ";\"");
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package net.ME1312.SubServers.Console;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubLogFilter;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubLogger;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.fusesource.jansi.AnsiOutputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
@ -45,7 +47,8 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
private boolean open = false;
|
||||
private SubLogger logger;
|
||||
private int fontSize = 12;
|
||||
private AnsiHTMLColorStream stream = new AnsiHTMLColorStream(new OutputStream() {
|
||||
private boolean ansi = true;
|
||||
private AnsiOutputStream stream = new AnsiHTMLColorStream(new OutputStream() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
|
||||
@Override
|
||||
@ -110,15 +113,51 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
window = new JFrame();
|
||||
|
||||
JMenuBar jMenu = new JMenuBar();
|
||||
JMenu menu = new JMenu("View");
|
||||
JMenuItem item = new JMenuItem("Scroll to Top");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> vScroll.getVerticalScrollBar().setValue(0));
|
||||
JMenu menu = new JMenu("\u00A0Log\u00A0");
|
||||
JMenuItem item = new JMenuItem("Clear Screen");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> clear());
|
||||
menu.add(item);
|
||||
item = new JMenuItem("Scroll to Bottom");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> vScroll.getVerticalScrollBar().setValue(vScroll.getVerticalScrollBar().getMaximum() - vScroll.getVerticalScrollBar().getVisibleAmount()));
|
||||
item = new JMenuItem("Reload Log");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> {
|
||||
log.setText(RESET_VALUE);
|
||||
loadContent();
|
||||
});
|
||||
menu.add(item);
|
||||
if (logger.getHandler() instanceof SubServer || logger.getHandler() instanceof SubCreator) {
|
||||
item = new JCheckBoxMenuItem("Auto Popout Log");
|
||||
item.setSelected((logger.getHandler() instanceof SubServer && (plugin.config.get().getStringList("Enabled-Servers").contains(((SubServer) logger.getHandler()).getName().toLowerCase()))) || (logger.getHandler() instanceof SubCreator && (plugin.config.get().getStringList("Enabled-Creators").contains(((SubCreator) logger.getHandler()).getHost().getName().toLowerCase()))));
|
||||
item.addActionListener(event -> {
|
||||
try {
|
||||
if (logger.getHandler() instanceof SubServer) {
|
||||
List<String> list = plugin.config.get().getStringList("Enabled-Servers");
|
||||
if (((AbstractButton) event.getSource()).getModel().isSelected()) {
|
||||
list.add(((SubServer) logger.getHandler()).getName().toLowerCase());
|
||||
} else {
|
||||
list.remove(((SubServer) logger.getHandler()).getName().toLowerCase());
|
||||
}
|
||||
plugin.config.get().set("Enabled-Servers", list);
|
||||
plugin.config.save();
|
||||
} else if (logger.getHandler() instanceof SubCreator) {
|
||||
List<String> list = plugin.config.get().getStringList("Enabled-Servers");
|
||||
if (((AbstractButton) event.getSource()).getModel().isSelected()) {
|
||||
list.add(((SubCreator) logger.getHandler()).getHost().getName().toLowerCase());
|
||||
} else {
|
||||
list.remove(((SubCreator) logger.getHandler()).getHost().getName().toLowerCase());
|
||||
}
|
||||
plugin.config.get().set("Enabled-Servers", list);
|
||||
plugin.config.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
jMenu.add(menu);
|
||||
}
|
||||
|
||||
menu = new JMenu("\u00A0Search\u00A0");
|
||||
item = new JMenuItem("Find");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> {
|
||||
@ -133,7 +172,48 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
item = new JMenuItem("Find Next");
|
||||
item.addActionListener(event -> {
|
||||
if (find.isVisible()) {
|
||||
find(true);
|
||||
} else {
|
||||
find.setVisible(true);
|
||||
findT.selectAll();
|
||||
findT.requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
item = new JMenuItem("Find Previous");
|
||||
item.addActionListener(event -> {
|
||||
if (find.isVisible()) {
|
||||
find(false);
|
||||
} else {
|
||||
find.setVisible(true);
|
||||
findT.selectAll();
|
||||
findT.requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
jMenu.add(menu);
|
||||
|
||||
menu = new JMenu("\u00A0View\u00A0");
|
||||
item = new JMenuItem("Scroll to Top");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> vScroll.getVerticalScrollBar().setValue(0));
|
||||
menu.add(item);
|
||||
item = new JMenuItem("Scroll to Bottom");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> vScroll.getVerticalScrollBar().setValue(vScroll.getVerticalScrollBar().getMaximum() - vScroll.getVerticalScrollBar().getVisibleAmount()));
|
||||
menu.add(item);
|
||||
menu.addSeparator();
|
||||
item = new JCheckBoxMenuItem("Show Text Colors");
|
||||
item.setSelected(true);
|
||||
item.addActionListener(event -> {
|
||||
ansi = ((AbstractButton) event.getSource()).getModel().isSelected();
|
||||
log.setText(RESET_VALUE);
|
||||
loadContent();
|
||||
});
|
||||
menu.add(item);
|
||||
item = new JMenuItem("Reset Text Size");
|
||||
item.addActionListener(event -> {
|
||||
HTMLDocument doc = (HTMLDocument) log.getDocument();
|
||||
@ -160,19 +240,8 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
hScroll();
|
||||
});
|
||||
menu.add(item);
|
||||
menu.addSeparator();
|
||||
item = new JMenuItem("Clear Screen");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> clear());
|
||||
menu.add(item);
|
||||
item = new JMenuItem("Reload Log");
|
||||
item.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
|
||||
item.addActionListener(event -> {
|
||||
log.setText(RESET_VALUE);
|
||||
loadContent();
|
||||
});
|
||||
menu.add(item);
|
||||
jMenu.add(menu);
|
||||
|
||||
window.setJMenuBar(jMenu);
|
||||
window.setContentPane(panel);
|
||||
window.pack();
|
||||
@ -391,7 +460,8 @@ public final class ConsoleWindow implements SubLogFilter {
|
||||
|
||||
public void log(Date date, String message) {
|
||||
try {
|
||||
stream.write((' ' + new SimpleDateFormat("hh:mm:ss").format(date) + ' ' + message + " \n").getBytes("UTF-8"));
|
||||
|
||||
stream.write(('\u00A0' + new SimpleDateFormat("hh:mm:ss").format(date) + ' ' + ((ansi)?message:message.replaceAll("\u001B\\[[;\\d]*m", "")) + "\u00A0\n").getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public final class PopoutCommand {
|
||||
list.remove(args[0].toLowerCase());
|
||||
plugin.config.get().set("Enabled-Servers", list);
|
||||
if (plugin.sCurrent.keySet().contains(args[0].toLowerCase()) && !plugin.sCurrent.get(args[0].toLowerCase()).isOpen()) plugin.onClose(plugin.sCurrent.get(args[0].toLowerCase()));
|
||||
plugin.config.save();
|
||||
if (!success) System.out.println("SubConsole > " + servers.get(args[0].toLowerCase()).getName() + " was removed from the enabled list");
|
||||
success = true;
|
||||
}
|
||||
@ -126,6 +127,7 @@ public final class PopoutCommand {
|
||||
list.remove(args[0].toLowerCase());
|
||||
plugin.config.get().set("Enabled-Creators", list);
|
||||
if (plugin.cCurrent.keySet().contains(args[0].toLowerCase()) && !plugin.cCurrent.get(args[0].toLowerCase()).isOpen()) plugin.onClose(plugin.cCurrent.get(args[0].toLowerCase()));
|
||||
plugin.config.save();
|
||||
if (!success) System.out.println("SubConsole > " + hosts.get(args[0].toLowerCase()).getName() + "/Creator was removed from the enabled list");
|
||||
success = true;
|
||||
}
|
||||
|
Binary file not shown.
@ -53,8 +53,8 @@ public final class ExHost {
|
||||
public YAMLSection lang = null;
|
||||
public SubDataClient subdata = null;
|
||||
|
||||
public final Version version = new Version("2.12.1d");
|
||||
public final Version bversion = null;
|
||||
public final Version version = new Version("2.12.2a");
|
||||
public final Version bversion = new Version(1);
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
|
||||
private boolean running;
|
||||
|
@ -23,6 +23,7 @@ import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Internal SubCreator Class
|
||||
@ -258,7 +259,8 @@ public class SubCreator {
|
||||
}
|
||||
|
||||
if (template.getBuildOptions().contains("Shell-Location")) {
|
||||
File gitBash = new File(host.host.getRawString("Git-Bash"), "bin" + File.separatorChar + "bash.exe");
|
||||
String git = (System.getenv("ProgramFiles(x86)") == null)?Pattern.compile("%(ProgramFiles)\\(x86\\)%", Pattern.CASE_INSENSITIVE).matcher(host.host.getRawString("Git-Bash")).replaceAll("%$1%"):host.host.getRawString("Git-Bash");
|
||||
String gitBash = git + ((git.endsWith(File.separator))?"":File.separator) + "bin" + File.separatorChar + "bash.exe";
|
||||
if (!(System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) && template.getBuildOptions().contains("Permission")) {
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("chmod " + template.getBuildOptions().getRawString("Permission") + ' ' + template.getBuildOptions().getRawString("Shell-Location"), null, dir);
|
||||
@ -277,7 +279,7 @@ public class SubCreator {
|
||||
try {
|
||||
thread.name().logger.info.println("Launching " + template.getBuildOptions().getRawString("Shell-Location"));
|
||||
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Launching " + template.getBuildOptions().getRawString("Shell-Location")));
|
||||
thread.set(Runtime.getRuntime().exec((System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)?"\"" + gitBash + "\" --login -i -c \"bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + '\"':("bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + " " + System.getProperty("user.home")), null, dir));
|
||||
thread.set(Runtime.getRuntime().exec((System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)?"cmd.exe /c \"\"" + gitBash + "\" --login -i -c \"bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + "\"\"":("bash " + template.getBuildOptions().getRawString("Shell-Location") + ' ' + version.toString() + " " + System.getProperty("user.home")), null, dir));
|
||||
thread.name().file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString().replace(" ", "@") + ".log");
|
||||
thread.name().process = thread.get();
|
||||
thread.name().start();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Host.Library.Log.Logger;
|
||||
import net.ME1312.SubServers.Host.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
@ -11,6 +12,7 @@ import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Authorization Packet
|
||||
@ -46,7 +48,12 @@ public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
public void execute(JSONObject data) {
|
||||
try {
|
||||
if (data.getInt("r") == 0) {
|
||||
host.subdata.sendPacket(new PacketLinkExHost(host));
|
||||
try {
|
||||
Method m = SubDataClient.class.getDeclaredMethod("sendPacket", NamedContainer.class);
|
||||
m.setAccessible(true);
|
||||
m.invoke(host.subdata, new NamedContainer<String, PacketOut>(null, new PacketLinkExHost(host)));
|
||||
m.setAccessible(false);
|
||||
} catch (Exception e) {}
|
||||
} else {
|
||||
log.info.println("SubServers > Could not authorize SubData connection: " + data.getString("m"));
|
||||
host.subdata.destroy(0);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Host.API.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Host.Library.Log.Logger;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Library.Version.Version;
|
||||
@ -11,6 +10,7 @@ import net.ME1312.SubServers.Host.ExHost;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Link Host Packet
|
||||
@ -45,10 +45,12 @@ public class PacketLinkExHost implements PacketIn, PacketOut {
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
if (data.getInt("r") == 0) {
|
||||
host.subdata.sendPacket(new PacketExConfigureHost(host));
|
||||
host.subdata.sendPacket(new PacketDownloadLang());
|
||||
host.subdata.sendPacket(new PacketOutExRequestQueue());
|
||||
host.api.executeEvent(new SubNetworkConnectEvent(host.subdata));
|
||||
try {
|
||||
Method m = SubDataClient.class.getDeclaredMethod("init");
|
||||
m.setAccessible(true);
|
||||
m.invoke(host.subdata);
|
||||
m.setAccessible(false);
|
||||
} catch (Exception e) {}
|
||||
} else {
|
||||
log.info.println("Could not link name with host: " + data.getString("m"));
|
||||
host.stop(1);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Host.Network;
|
||||
|
||||
import net.ME1312.SubServers.Host.API.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Host.API.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Host.Library.Exception.IllegalPacketException;
|
||||
import net.ME1312.SubServers.Host.Library.Log.Logger;
|
||||
@ -33,7 +34,7 @@ public final class SubDataClient {
|
||||
private static boolean defaults = false;
|
||||
protected static Logger log;
|
||||
private PrintWriter writer;
|
||||
private Socket socket;
|
||||
private NamedContainer<Boolean, Socket> socket;
|
||||
private String name;
|
||||
private Encryption encryption;
|
||||
private ExHost host;
|
||||
@ -59,22 +60,29 @@ public final class SubDataClient {
|
||||
*/
|
||||
public SubDataClient(ExHost host, String name, InetAddress address, int port, Encryption encryption) throws IOException {
|
||||
if (Util.isNull(host, name, address, port, encryption)) throw new NullPointerException();
|
||||
socket = new Socket(address, port);
|
||||
socket = new NamedContainer<>(false, new Socket(address, port));
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.writer = new PrintWriter(socket.getOutputStream(), true);
|
||||
this.writer = new PrintWriter(socket.get().getOutputStream(), true);
|
||||
this.encryption = encryption;
|
||||
this.queue = new LinkedList<NamedContainer<String, PacketOut>>();
|
||||
|
||||
if (!defaults) loadDefaults();
|
||||
loop();
|
||||
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendPacket(new PacketAuthorization(host));
|
||||
}
|
||||
}, 500);
|
||||
sendPacket(new NamedContainer<>(null, new PacketAuthorization(host)));
|
||||
}
|
||||
|
||||
private void init() {
|
||||
sendPacket(new PacketExConfigureHost(host));
|
||||
sendPacket(new PacketDownloadLang());
|
||||
sendPacket(new PacketOutExRequestQueue());
|
||||
while (queue.size() != 0) {
|
||||
sendPacket(queue.get(0));
|
||||
queue.remove(0);
|
||||
}
|
||||
socket.rename(true);
|
||||
host.api.executeEvent(new SubNetworkConnectEvent(host.subdata));
|
||||
}
|
||||
|
||||
private void loadDefaults() {
|
||||
@ -130,7 +138,7 @@ public final class SubDataClient {
|
||||
private void loop() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.get().getInputStream()));
|
||||
String input;
|
||||
while ((input = in.readLine()) != null) {
|
||||
String decoded = null;
|
||||
@ -192,7 +200,7 @@ public final class SubDataClient {
|
||||
* @return Server Socket
|
||||
*/
|
||||
public Socket getClient() {
|
||||
return socket;
|
||||
return socket.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -266,30 +274,35 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void sendPacket(PacketOut packet) {
|
||||
if (Util.isNull(packet)) throw new NullPointerException();
|
||||
if (socket == null) {
|
||||
if (socket.get() == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(null, packet));
|
||||
} else {
|
||||
try {
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(encodePacket(packet));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
sendPacket(new NamedContainer<>(null, packet));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(NamedContainer<String, PacketOut> packet) {
|
||||
try {
|
||||
JSONObject json = encodePacket(packet.get());
|
||||
if (packet.name() != null) json.put("f", packet.name());
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(json.toString());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Forward Packet to Server
|
||||
*
|
||||
@ -298,29 +311,10 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void forwardPacket(PacketOut packet, String location) {
|
||||
if (Util.isNull(packet, location)) throw new NullPointerException();
|
||||
if (socket == null) {
|
||||
if (socket == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(location, packet));
|
||||
} else {
|
||||
try {
|
||||
JSONObject json = encodePacket(packet);
|
||||
json.put("f", location);
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, host.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(json.toString());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error.println(e);
|
||||
}
|
||||
sendPacket(new NamedContainer<>(location, packet));
|
||||
}
|
||||
}
|
||||
|
||||
@ -389,9 +383,9 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void destroy(int reconnect) throws IOException {
|
||||
if (Util.isNull(reconnect)) throw new NullPointerException();
|
||||
if (socket != null) {
|
||||
final Socket socket = this.socket;
|
||||
this.socket = null;
|
||||
if (socket.get() != null) {
|
||||
final Socket socket = this.socket.get();
|
||||
this.socket.set(null);
|
||||
if (!socket.isClosed()) socket.close();
|
||||
host.api.executeEvent(new SubNetworkDisconnectEvent());
|
||||
log.info.println("The SubData Connection was closed");
|
||||
|
@ -1,5 +1,5 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path: BungeeCord.jar
|
||||
Main-Class: net.ME1312.SubServers.Sync.Launch
|
||||
Implementation-Version: 2.12.1b
|
||||
Specification-Version: 0
|
||||
Implementation-Version: 2.12.2a
|
||||
Specification-Version: 1
|
||||
|
Binary file not shown.
@ -4,6 +4,7 @@ import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Sync.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Sync.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Server.Server;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServer;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
@ -11,6 +12,7 @@ import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
@ -32,25 +34,12 @@ public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
public void execute(JSONObject data) {
|
||||
try {
|
||||
if (data.getInt("r") == 0) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadLang(plugin));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, json -> {
|
||||
System.out.println("SubServers > Resetting Server Data");
|
||||
plugin.servers.clear();
|
||||
for (String host : json.getJSONObject("hosts").keySet()) {
|
||||
for (String subserver : json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet()) {
|
||||
plugin.servers.put(subserver.toLowerCase(), new SubServer(subserver, json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("display"),
|
||||
new InetSocketAddress(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[0], Integer.parseInt(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[1])),
|
||||
json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("motd"), json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("hidden"),
|
||||
json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("restricted"), json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("running")));
|
||||
System.out.println("SubServers > Added SubServer: " + subserver);
|
||||
}
|
||||
}
|
||||
for (String server : json.getJSONObject("servers").keySet()) {
|
||||
plugin.servers.put(server.toLowerCase(), new Server(server, json.getJSONObject("servers").getJSONObject(server).getString("display"), new InetSocketAddress(json.getJSONObject("servers").getJSONObject(server).getString("address").split(":")[0], Integer.parseInt(json.getJSONObject("servers").getJSONObject(server).getString("address").split(":")[1])),
|
||||
json.getJSONObject("servers").getJSONObject(server).getString("motd"), json.getJSONObject("servers").getJSONObject(server).getBoolean("hidden"), json.getJSONObject("servers").getJSONObject(server).getBoolean("restricted")));
|
||||
System.out.println("SubServers > Added Server: " + server);
|
||||
}
|
||||
}));
|
||||
try {
|
||||
Method m = SubDataClient.class.getDeclaredMethod("init");
|
||||
m.setAccessible(true);
|
||||
m.invoke(plugin.subdata);
|
||||
m.setAccessible(false);
|
||||
} catch (Exception e) {}
|
||||
} else {
|
||||
System.out.println("SubServers > Could not authorize SubData connection: " + data.getString("m"));
|
||||
plugin.subdata.destroy(0);
|
||||
|
@ -1,11 +1,14 @@
|
||||
package net.ME1312.SubServers.Sync.Network;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Sync.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Exception.IllegalPacketException;
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Sync.Server.Server;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServer;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -16,6 +19,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.*;
|
||||
@ -29,7 +33,7 @@ public final class SubDataClient {
|
||||
private static HashMap<String, List<PacketIn>> pIn = new HashMap<String, List<PacketIn>>();
|
||||
private static boolean defaults = false;
|
||||
private PrintWriter writer;
|
||||
private Socket socket;
|
||||
private NamedContainer<Boolean, Socket> socket;
|
||||
private Encryption encryption;
|
||||
private SubPlugin plugin;
|
||||
private LinkedList<NamedContainer<String, PacketOut>> queue;
|
||||
@ -53,21 +57,44 @@ public final class SubDataClient {
|
||||
*/
|
||||
public SubDataClient(SubPlugin plugin, InetAddress address, int port, Encryption encryption) throws IOException {
|
||||
if (Util.isNull(plugin, address, port)) throw new NullPointerException();
|
||||
socket = new Socket(address, port);
|
||||
socket = new NamedContainer<>(false, new Socket(address, port));
|
||||
this.plugin = plugin;
|
||||
this.writer = new PrintWriter(socket.getOutputStream(), true);
|
||||
this.writer = new PrintWriter(socket.get().getOutputStream(), true);
|
||||
this.encryption = encryption;
|
||||
this.queue = new LinkedList<NamedContainer<String, PacketOut>>();
|
||||
|
||||
if (!defaults) loadDefaults();
|
||||
loop();
|
||||
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendPacket(new PacketAuthorization(plugin));
|
||||
sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin)));
|
||||
}
|
||||
|
||||
private void init() {
|
||||
plugin.subdata.sendPacket(new PacketDownloadLang(plugin));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, json -> {
|
||||
System.out.println("SubServers > Resetting Server Data");
|
||||
plugin.servers.clear();
|
||||
for (String host : json.getJSONObject("hosts").keySet()) {
|
||||
for (String subserver : json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet()) {
|
||||
plugin.servers.put(subserver.toLowerCase(), new SubServer(subserver, json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("display"),
|
||||
new InetSocketAddress(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[0], Integer.parseInt(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[1])),
|
||||
json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("motd"), json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("hidden"),
|
||||
json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("restricted"), json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("running")));
|
||||
System.out.println("SubServers > Added SubServer: " + subserver);
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
for (String server : json.getJSONObject("servers").keySet()) {
|
||||
plugin.servers.put(server.toLowerCase(), new Server(server, json.getJSONObject("servers").getJSONObject(server).getString("display"), new InetSocketAddress(json.getJSONObject("servers").getJSONObject(server).getString("address").split(":")[0], Integer.parseInt(json.getJSONObject("servers").getJSONObject(server).getString("address").split(":")[1])),
|
||||
json.getJSONObject("servers").getJSONObject(server).getString("motd"), json.getJSONObject("servers").getJSONObject(server).getBoolean("hidden"), json.getJSONObject("servers").getJSONObject(server).getBoolean("restricted")));
|
||||
System.out.println("SubServers > Added Server: " + server);
|
||||
}
|
||||
}));
|
||||
while (queue.size() != 0) {
|
||||
sendPacket(queue.get(0));
|
||||
queue.remove(0);
|
||||
}
|
||||
socket.rename(true);
|
||||
plugin.getPluginManager().callEvent(new SubNetworkConnectEvent(this));
|
||||
}
|
||||
|
||||
private void loadDefaults() {
|
||||
@ -105,7 +132,7 @@ public final class SubDataClient {
|
||||
private void loop() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.get().getInputStream()));
|
||||
String input;
|
||||
while ((input = in.readLine()) != null) {
|
||||
String decoded = null;
|
||||
@ -158,7 +185,7 @@ public final class SubDataClient {
|
||||
* @return Server Socket
|
||||
*/
|
||||
public Socket getClient() {
|
||||
return socket;
|
||||
return socket.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,27 +271,33 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void sendPacket(PacketOut packet) {
|
||||
if (Util.isNull(packet)) throw new NullPointerException();
|
||||
if (socket == null) {
|
||||
if (socket.get() == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(null, packet));
|
||||
} else {
|
||||
try {
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), encodePacket(packet).toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(encodePacket(packet));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendPacket(new NamedContainer<>(null, packet));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(NamedContainer<String, PacketOut> packet) {
|
||||
try {
|
||||
JSONObject json = encodePacket(packet.get());
|
||||
if (packet.name() != null) json.put("f", packet.name());
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(json.toString());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,29 +309,10 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void forwardPacket(PacketOut packet, String location) {
|
||||
if (Util.isNull(packet, location)) throw new NullPointerException();
|
||||
if (socket == null) {
|
||||
if (socket.get() == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(location, packet));
|
||||
} else {
|
||||
try {
|
||||
JSONObject json = encodePacket(packet);
|
||||
json.put("f", location);
|
||||
switch (getEncryption()) {
|
||||
case AES:
|
||||
case AES_128:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(128, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_192:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(192, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
case AES_256:
|
||||
writer.println(Base64.getEncoder().encodeToString(AES.encrypt(256, plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), json.toString())));
|
||||
break;
|
||||
default:
|
||||
writer.println(json.toString());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendPacket(new NamedContainer<>(null, packet));
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,9 +380,9 @@ public final class SubDataClient {
|
||||
*/
|
||||
public void destroy(int reconnect) throws IOException {
|
||||
if (Util.isNull(reconnect)) throw new NullPointerException();
|
||||
if (socket != null) {
|
||||
final Socket socket = this.socket;
|
||||
this.socket = null;
|
||||
if (socket.get() != null) {
|
||||
final Socket socket = this.socket.get();
|
||||
this.socket.set(null);
|
||||
if (!socket.isClosed()) socket.close();
|
||||
plugin.getPluginManager().callEvent(new SubNetworkDisconnectEvent());
|
||||
System.out.println("SubServers > The SubData Connection was closed");
|
||||
|
Loading…
Reference in New Issue
Block a user