Auto-Update SubServers.Client
This commit is contained in:
parent
b7a8fbc8b5
commit
8458acb255
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -11,4 +11,5 @@ These are some quick links for common resources of SubServers 2.
|
|||
|
||||
### Javadocs for Developers
|
||||
> [http://subservers.ME1312.net/Javadoc/SubServers.Bungee/](http://subservers.ME1312.net/Javadoc/SubServers.Bungee/)<br>
|
||||
> [http://subservers.ME1312.net/Javadoc/SubServers.Host/](http://subservers.ME1312.net/Javadoc/SubServers.Host/)<br>
|
||||
> [http://subservers.ME1312.net/Javadoc/SubServers.Client.Bukkit/](http://subservers.ME1312.net/Javadoc/SubServers.Client.Bukkit/)
|
||||
|
|
|
@ -25,7 +25,7 @@ public class SubAddServerEvent extends Event implements SubEvent, Cancellable {
|
|||
* @param server Server Starting
|
||||
*/
|
||||
public SubAddServerEvent(UUID player, Host host, Server server) {
|
||||
if (Util.isNull(host, server)) throw new NullPointerException();
|
||||
if (Util.isNull(server)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.server = server;
|
||||
|
|
|
@ -25,7 +25,7 @@ public class SubRemoveServerEvent extends Event implements SubEvent, Cancellable
|
|||
* @param server Server Starting
|
||||
*/
|
||||
public SubRemoveServerEvent(UUID player, Host host, Server server) {
|
||||
if (Util.isNull(host, server)) throw new NullPointerException();
|
||||
if (Util.isNull(server)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.server = server;
|
||||
|
|
|
@ -81,12 +81,12 @@ public class InternalSubLogger extends SubLogger {
|
|||
|
||||
// REGEX Formatting
|
||||
String type = "";
|
||||
Matcher matcher = Pattern.compile("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?\\s*)").matcher(msg);
|
||||
Matcher matcher = Pattern.compile("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)").matcher(msg);
|
||||
while (matcher.find()) {
|
||||
type = matcher.group(3).toUpperCase();
|
||||
}
|
||||
|
||||
msg = msg.replaceAll("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?\\s*)", "");
|
||||
msg = msg.replaceAll("^((?:\\s*\\[?([0-9]{2}:[0-9]{2}:[0-9]{2})]?)?[\\s\\/\\\\\\|]*(?:\\[|\\[.*\\/)?(MESSAGE|INFO|WARNING|WARN|ERROR|ERR|SEVERE)\\]?:?(?:\\s*>)?\\s*)", "");
|
||||
|
||||
// Determine LOG LEVEL
|
||||
switch (type) {
|
||||
|
|
|
@ -3,21 +3,25 @@ package net.ME1312.SubServers.Bungee.Host.Internal;
|
|||
import net.ME1312.SubServers.Bungee.Event.*;
|
||||
import net.ME1312.SubServers.Bungee.Host.Executable;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubLogger;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Container;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
/**
|
||||
* Internal SubServer Class
|
||||
|
@ -74,6 +78,21 @@ public class InternalSubServer extends SubServer {
|
|||
this.thread = null;
|
||||
this.command = null;
|
||||
this.restart = restart;
|
||||
|
||||
if (new UniversalFile(this.directory, "plugins:SubServers.Client.jar").exists()) {
|
||||
try {
|
||||
JarFile jar = new JarFile(new UniversalFile(this.directory, "plugins:SubServers.Client.jar"));
|
||||
YAMLSection plugin = new YAMLSection(Util.readAll(new InputStreamReader(jar.getInputStream(jar.getJarEntry("plugin.yml")))));
|
||||
YAMLSection bplugin = new YAMLSection(Util.readAll(new InputStreamReader(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/bukkit.yml"))));
|
||||
if (new Version(plugin.getString("version")).compareTo(new Version(bplugin.getString("version"))) < 0) {
|
||||
new UniversalFile(this.directory, "plugins:SubServers.Client.jar").delete();
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/bukkit.jar", new UniversalFile(this.directory, "plugins:SubServers.Client.jar").getPath());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
System.out.println("Couldn't auto-update SubServers.Client.jar");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.temporary = !((start || temporary) && !start()) && temporary;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SubAddServerEvent extends Event implements SubEvent {
|
|||
* @param server Server Starting
|
||||
*/
|
||||
public SubAddServerEvent(UUID player, String host, String server) {
|
||||
if (Util.isNull(host, server)) throw new NullPointerException();
|
||||
if (Util.isNull(server)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.server = server;
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SubRemoveServerEvent extends Event implements SubEvent {
|
|||
* @param server Server Starting
|
||||
*/
|
||||
public SubRemoveServerEvent(UUID player, String host, String server) {
|
||||
if (Util.isNull(host, server)) throw new NullPointerException();
|
||||
if (Util.isNull(server)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.server = server;
|
||||
|
|
|
@ -1,20 +1,30 @@
|
|||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Host.Library.Log.Logger;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.SubServers;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
private SubServers plugin;
|
||||
private Logger log = null;
|
||||
|
||||
public PacketAuthorization(SubServers plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
Field f = SubDataClient.class.getDeclaredField("log");
|
||||
f.setAccessible(true);
|
||||
this.log = (Logger) f.get(null);
|
||||
f.setAccessible(false);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,11 +41,11 @@ public final class PacketAuthorization implements PacketIn, PacketOut {
|
|||
//plugin.subdata.sendPacket(new PacketLinkServer(plugin));
|
||||
plugin.subdata.sendPacket(new PacketDownloadLang());
|
||||
} else {
|
||||
plugin.log.info("SubServers > Could not authorize SubData connection: " + data.getString("m"));
|
||||
log.info("SubServers > Could not authorize SubData connection: " + data.getString("m"));
|
||||
plugin.subdata.destroy(false);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.log.error(e);
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,33 @@
|
|||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Host.Library.Log.Logger;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.SubServers;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
private SubServers plugin;
|
||||
private Logger log = null;
|
||||
|
||||
public PacketDownloadLang() {};
|
||||
|
||||
public PacketDownloadLang(SubServers plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
Field f = SubDataClient.class.getDeclaredField("log");
|
||||
f.setAccessible(true);
|
||||
this.log = (Logger) f.get(null);
|
||||
f.setAccessible(false);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,7 +39,7 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
|
|||
public void execute(JSONObject data) {
|
||||
data.put("Updated", Calendar.getInstance().getTime().getTime());
|
||||
plugin.lang = new YAMLSection(data);
|
||||
plugin.log.info("SubData > Lang Settings Downloaded");
|
||||
log.info("Lang Settings Downloaded");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.ME1312.SubServers.Host.Network;
|
|||
|
||||
import net.ME1312.SubServers.Host.Library.Container;
|
||||
import net.ME1312.SubServers.Host.Library.Exception.IllegalPacketException;
|
||||
import net.ME1312.SubServers.Host.Library.Log.Logger;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketAuthorization;
|
||||
|
@ -29,6 +30,7 @@ public final class SubDataClient {
|
|||
private static HashMap<Class<? extends PacketOut>, String> pOut = new HashMap<Class<? extends PacketOut>, String>();
|
||||
private static HashMap<String, List<PacketIn>> pIn = new HashMap<String, List<PacketIn>>();
|
||||
private static boolean defaults = false;
|
||||
protected static Logger log;
|
||||
private PrintWriter writer;
|
||||
private Socket socket;
|
||||
private String name;
|
||||
|
@ -62,6 +64,7 @@ public final class SubDataClient {
|
|||
|
||||
private void loadDefaults() {
|
||||
defaults = true;
|
||||
log = new Logger("SubData");
|
||||
|
||||
registerPacket(new PacketAuthorization(plugin), "Authorization");
|
||||
registerPacket(new PacketDownloadLang(plugin), "SubDownloadLang");
|
||||
|
@ -82,26 +85,26 @@ public final class SubDataClient {
|
|||
try {
|
||||
packet.execute((json.keySet().contains("c"))?json.getJSONObject("c"):null);
|
||||
} catch (Exception e) {
|
||||
plugin.log.error(new InvocationTargetException(e, "Exception while executing PacketIn"));
|
||||
log.error(new InvocationTargetException(e, "Exception while executing PacketIn"));
|
||||
}
|
||||
}
|
||||
} catch (IllegalPacketException e) {
|
||||
plugin.log.error(e);
|
||||
log.error(e);
|
||||
} catch (JSONException e) {
|
||||
plugin.log.error(new IllegalPacketException("Unknown Packet Format: " + input));
|
||||
log.error(new IllegalPacketException("Unknown Packet Format: " + input));
|
||||
}
|
||||
}
|
||||
try {
|
||||
destroy(true);
|
||||
} catch (IOException e1) {
|
||||
plugin.log.error(e1);
|
||||
log.error(e1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException)) plugin.log.error(e);
|
||||
if (!(e instanceof SocketException)) log.error(e);
|
||||
try {
|
||||
destroy(true);
|
||||
} catch (IOException e1) {
|
||||
plugin.log.error(e1);
|
||||
log.error(e1);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
@ -190,7 +193,7 @@ public final class SubDataClient {
|
|||
try {
|
||||
writer.println(encodePacket(packet));
|
||||
} catch (IllegalPacketException e) {
|
||||
plugin.log.error(e);
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,22 +253,21 @@ public final class SubDataClient {
|
|||
final Socket socket = this.socket;
|
||||
this.socket = null;
|
||||
if (!socket.isClosed()) socket.close();
|
||||
plugin.log.info("The SubData Connection was closed");
|
||||
log.info("The SubData Connection was closed");
|
||||
if (reconnect) {
|
||||
plugin.log.info("Attempting to reconnect in 30 seconds");
|
||||
final Container<Timer> timer = new Container<Timer>(new Timer());
|
||||
timer.get().schedule(new TimerTask() {
|
||||
log.info("Attempting to reconnect in 30 seconds");
|
||||
Timer timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
plugin.subdata = new SubDataClient(plugin, name, socket.getInetAddress(), socket.getPort());
|
||||
timer.cancel();
|
||||
} catch (IOException e) {
|
||||
plugin.log.info("Connection was unsuccessful, retrying in 30 seconds");
|
||||
timer.set(new Timer());
|
||||
timer.get().schedule(this, TimeUnit.SECONDS.toMillis(30));
|
||||
log.warn("Connection was unsuccessful, retrying in 30 seconds");
|
||||
}
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(30));
|
||||
}, TimeUnit.SECONDS.toMillis(30), TimeUnit.SECONDS.toMillis(30));
|
||||
}
|
||||
plugin.subdata = null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue