Allow client apps to startup without a SubData connection active

They won't be all that useful like that, but... ¯\_(ツ)_/¯
This commit is contained in:
ME1312 2019-08-31 13:26:37 -04:00
parent bccbfb39c9
commit 17b63c1e6e
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
17 changed files with 135 additions and 116 deletions

View File

@ -30,14 +30,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>19w27b</version>
<version>19w28a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>19w27b</version>
<version>19w28a</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -53,9 +53,6 @@ public class ConfigUpdater {
if (existing.getMap("Settings", new YAMLSection()).contains("SubData") && !existing.getMap("Settings", new YAMLSection()).getMap("SubData").contains("Encryption"))
updated.getMap("Settings").getMap("SubData").set("Encryption", "NONE");
if (existing.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Allowed-Connections"))
updated.getMap("Settings").getMap("SubData").safeSet("Whitelist", existing.getMap("Settings").getMap("SubData").getRawStringList("Allowed-Connections"));
if (existing.contains("Servers")) {
YAMLConfig sc = new YAMLConfig(new File(file.getParentFile(), "servers.yml"));
YAMLSection settings = new YAMLSection();
@ -69,6 +66,12 @@ public class ConfigUpdater {
sc.save();
}
existing = updated.clone();
i++;
} if (was.compareTo(new Version("19w35b")) <= 0) {
if (existing.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Allowed-Connections"))
updated.getMap("Settings").getMap("SubData").safeSet("Whitelist", existing.getMap("Settings").getMap("SubData").getRawStringList("Allowed-Connections"));
existing = updated.clone();
i++;
}// if (was.compareTo(new Version("99w99a")) <= 0) {

View File

@ -72,7 +72,7 @@ public final class SubProxy extends BungeeCord implements Listener {
public SubProtocol subprotocol;
public SubDataServer subdata = null;
public SubServer sudo = null;
public static final Version version = Version.fromString("2.14.2a");
public static final Version version = Version.fromString("2.14.4a");
public Proxy redis = null;
public boolean canSudo = false;
@ -556,7 +556,7 @@ public final class SubProxy extends BungeeCord implements Listener {
subdata = subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
} // Add new entries to Allowed-Connections
for (String s : config.get().getMap("Settings").getMap("SubData").getStringList("Allowed-Connections", new ArrayList<String>())) {
for (String s : config.get().getMap("Settings").getMap("SubData").getStringList("Whitelist", new ArrayList<String>())) {
try {
subdata.whitelist(s);
} catch (Exception e) {

View File

@ -48,7 +48,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>19w27b</version>
<version>19w28a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Client.Bukkit.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.Library.DisconnectReason;
@ -165,26 +166,8 @@ public class SubProtocol extends SubDataProtocol {
if (plugin.isEnabled()) Bukkit.getPluginManager().callEvent(event);
map.put(0, null);
int reconnect = plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
if (Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("reconnect"), plugin), false) && reconnect > 0
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
Bukkit.getLogger().info("SubData > Attempting reconnect in " + reconnect + " seconds");
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
Util.reflect(SubPlugin.class.getDeclaredMethod("connect"), plugin);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof IOException) {
Bukkit.getLogger().info("SubData > Connection was unsuccessful, retrying in " + reconnect + " seconds");
Bukkit.getScheduler().runTaskLater(plugin, this, reconnect * 20);
} else e.printStackTrace();
} catch (NoSuchMethodException | IllegalAccessException e) {
e.printStackTrace();
}
}
}, reconnect * 20);
}
Bukkit.getLogger().info("SubData > Attempting reconnect in " + plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30) + " seconds");
Util.isException(() -> Util.reflect(SubPlugin.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
});
return subdata;

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Client.Bukkit;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.Encryption.AES;
import net.ME1312.SubData.Client.Encryption.RSA;
import net.ME1312.SubData.Client.Library.DisconnectReason;
@ -43,6 +44,7 @@ public final class SubPlugin extends JavaPlugin {
public final Version version;
public final SubAPI api = new SubAPI(this);
private long resetDate = 0;
private boolean reconnect = false;
public SubPlugin() {
@ -116,6 +118,7 @@ public final class SubPlugin extends JavaPlugin {
public void reload(boolean notifyPlugins) throws IOException {
reconnect = false;
resetDate = Calendar.getInstance().getTime().getTime();
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
tmp.addAll(subdata.values());
for (SubDataClient client : tmp) if (client != null) {
@ -154,7 +157,8 @@ public final class SubPlugin extends JavaPlugin {
reconnect = true;
System.out.println("SubData > ");
connect();
System.out.println("SubData > Connecting to /" + config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391"));
connect(null);
if (notifyPlugins) {
List<Runnable> listeners = api.reloadListeners;
@ -170,9 +174,26 @@ public final class SubPlugin extends JavaPlugin {
}
}
private void connect() throws IOException {
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
private void connect(NamedContainer<DisconnectReason, DataClient> disconnect) throws IOException {
int reconnect = config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.name() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.name() != DisconnectReason.ENCRYPTION_MISMATCH)) {
long reset = resetDate;
Bukkit.getScheduler().runTaskLaterAsynchronously(this, new Runnable() {
@Override
public void run() {
try {
if (reset == resetDate && subdata.getOrDefault(0, null) == null)
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?
null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
} catch (IOException e) {
Bukkit.getLogger().info("SubData > Connection was unsuccessful, retrying in " + reconnect + " seconds");
Bukkit.getScheduler().runTaskLater(SubPlugin.this, this, reconnect * 20);
}
}
}, (disconnect == null)?0:reconnect * 20);
}
}
/**

View File

@ -1,6 +1,6 @@
name: 'SubServers-Client-Bukkit'
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
version: '2.14.2a'
version: '2.14.4a'
authors: [ME1312]
softdepend: [Vault, TitleManager]
website: 'https://github.com/ME1312/SubServers-2'

View File

@ -30,7 +30,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>19w27b</version>
<version>19w28a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Client.Sponge.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.Library.DisconnectReason;
@ -177,27 +178,8 @@ public class SubProtocol extends SubDataProtocol {
map.put(0, null);
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
int reconnect = plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
if (Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("reconnect"), plugin), false) && reconnect > 0
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
log.info("Attempting reconnect in " + reconnect + " seconds");
Sponge.getScheduler().createTaskBuilder().async().execute(new Runnable() {
@Override
public void run() {
try {
Util.reflect(SubPlugin.class.getDeclaredMethod("connect"), plugin);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof IOException) {
log.info("Connection was unsuccessful, retrying in " + reconnect + " seconds");
Sponge.getScheduler().createTaskBuilder().async().execute(this).delay(reconnect, TimeUnit.SECONDS).submit(plugin);
} else e.printStackTrace();
} catch (NoSuchMethodException | IllegalAccessException e) {
e.printStackTrace();
}
}
}).delay(reconnect, TimeUnit.SECONDS).submit(plugin);
}
log.info("Attempting reconnect in " + plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30) + " seconds");
Util.isException(() -> Util.reflect(SubPlugin.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
});
return subdata;

View File

@ -2,8 +2,10 @@ package net.ME1312.SubServers.Client.Sponge;
import com.google.gson.Gson;
import com.google.inject.Inject;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.Encryption.AES;
import net.ME1312.SubData.Client.Encryption.RSA;
import net.ME1312.SubData.Client.Library.DisconnectReason;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Sponge.Graphic.UIHandler;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
@ -40,7 +42,7 @@ import java.util.concurrent.TimeUnit;
/**
* SubServers Client Plugin Class
*/
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.14.2a", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.14.4a", url = "https://github.com/ME1312/SubServers-2", description = "Take control of the server manager — from your servers")
public final class SubPlugin {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
@ -56,6 +58,7 @@ public final class SubPlugin {
@Inject public PluginContainer plugin;
@Inject public Game game;
private long resetDate = 0;
private boolean reconnect = false;
@Listener
@ -130,6 +133,7 @@ public final class SubPlugin {
public void reload(boolean notifyPlugins) throws IOException {
reconnect = false;
resetDate = Calendar.getInstance().getTime().getTime();
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
tmp.addAll(subdata.values());
for (SubDataClient client : tmp) if (client != null) {
@ -169,7 +173,8 @@ public final class SubPlugin {
reconnect = true;
log.info(" ");
connect();
log.info("Connecting to /" + config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391"));
connect(null);
if (notifyPlugins) {
List<Runnable> listeners = api.reloadListeners;
@ -185,9 +190,27 @@ public final class SubPlugin {
}
}
private void connect() throws IOException {
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
private void connect(NamedContainer<DisconnectReason, DataClient> disconnect) throws IOException {
int reconnect = config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.name() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.name() != DisconnectReason.ENCRYPTION_MISMATCH)) {
long reset = resetDate;
Logger log = LoggerFactory.getLogger("SubData");
Sponge.getScheduler().createTaskBuilder().async().execute(new Runnable() {
@Override
public void run() {
try {
if (reset == resetDate && subdata.getOrDefault(0, null) == null)
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?
null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
} catch (IOException e) {
log.info("Connection was unsuccessful, retrying in " + reconnect + " seconds");
Sponge.getScheduler().createTaskBuilder().async().execute(this).delay(reconnect, TimeUnit.SECONDS).submit(plugin);
}
}
}).delay((disconnect == null)?0:reconnect, TimeUnit.SECONDS).submit(plugin);
}
}
/**

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>19w27b</version>
<version>19w28a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -14,8 +14,10 @@ import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.Galaxi.Library.Version.VersionType;
import net.ME1312.Galaxi.Plugin.App;
import net.ME1312.Galaxi.Plugin.PluginInfo;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.Encryption.AES;
import net.ME1312.SubData.Client.Encryption.RSA;
import net.ME1312.SubData.Client.Library.DisconnectReason;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Host.Executable.SubCreatorImpl;
import net.ME1312.SubServers.Host.Executable.SubLoggerImpl;
@ -37,7 +39,7 @@ import java.util.jar.Manifest;
/**
* SubServers.Host Main Class
*/
@App(name = "SubServers.Host", version = "2.14.2a", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
@App(name = "SubServers.Host", version = "2.14.4a", authors = "ME1312", website = "https://github.com/ME1312/SubServers-2", description = "Host subservers on separate machines")
public final class ExHost {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
@ -54,6 +56,7 @@ public final class ExHost {
public final SubAPI api = new SubAPI(this);
private long resetDate = 0;
private boolean reconnect = true;
private boolean running = false;
@ -238,6 +241,7 @@ public final class ExHost {
}
public void reload(boolean notifyPlugins) throws IOException {
resetDate = Calendar.getInstance().getTime().getTime();
reconnect = false;
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
tmp.addAll(subdata.values());
@ -278,16 +282,34 @@ public final class ExHost {
reconnect = true;
log.info.println();
connect();
log.info.println("Connecting to /" + config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391"));
connect(log.toPrimitive(), null);
if (notifyPlugins) {
engine.getPluginManager().executeEvent(new GalaxiReloadEvent(engine));
}
}
private void connect() throws IOException {
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
private void connect(java.util.logging.Logger log, NamedContainer<DisconnectReason, DataClient> disconnect) throws IOException {
int reconnect = config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.name() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.name() != DisconnectReason.ENCRYPTION_MISMATCH)) {
long reset = resetDate;
Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::SubData_Reconnect_Handler");
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
if (reset == resetDate && subdata.getOrDefault(0, null) == null)
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?
null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
timer.cancel();
} catch (IOException e) {
log.info("Connection was unsuccessful, retrying in " + reconnect + " seconds");
}
}
}, (disconnect == null)?0:TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
}
}
private void stop() {

View File

@ -160,7 +160,6 @@ public class SubServerImpl {
try {
allowrestart = false;
if (process != null && process.isAlive()) {
System.out.println(stopcmd);
command.write(stopcmd);
command.newLine();
command.flush();

View File

@ -2,6 +2,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.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.Library.DisconnectReason;
@ -163,27 +164,8 @@ 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", 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");
Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::SubData_Reconnect_Handler");
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
Util.reflect(ExHost.class.getDeclaredMethod("connect"), host);
timer.cancel();
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof IOException) {
log.info("Connection was unsuccessful, retrying in " + reconnect + " seconds");
} else e.printStackTrace();
} catch (NoSuchMethodException | IllegalAccessException e) {
e.printStackTrace();
}
}
}, TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
}
log.info("Attempting reconnect in " + host.config.get().getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getInt("Reconnect", 30) + " seconds");
Util.isException(() -> Util.reflect(ExHost.class.getDeclaredMethod("connect", Logger.class, NamedContainer.class), host, log, client));
});
return subdata;

View File

@ -30,14 +30,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>19w27b</version>
<version>19w28a</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>19w27b</version>
<version>19w28a</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -2,8 +2,10 @@ package net.ME1312.SubServers.Sync;
import com.dosse.upnp.UPnP;
import com.google.gson.Gson;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.Encryption.AES;
import net.ME1312.SubData.Client.Encryption.RSA;
import net.ME1312.SubData.Client.Library.DisconnectReason;
import net.ME1312.SubServers.Sync.Event.*;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
@ -55,11 +57,12 @@ public final class ExProxy extends BungeeCord implements Listener {
public boolean redis = false;
public final SubAPI api = new SubAPI(this);
public SubProtocol subprotocol;
public static final Version version = Version.fromString("2.14.2a");
public static final Version version = Version.fromString("2.14.4a");
public final boolean isPatched;
public final boolean isGalaxi;
public long lastReload = -1;
private long resetDate = 0;
private boolean reconnect = false;
private boolean posted = false;
@ -99,6 +102,7 @@ public final class ExProxy extends BungeeCord implements Listener {
@Override
public void startListeners() {
try {
resetDate = Calendar.getInstance().getTime().getTime();
redis = getPluginManager().getPlugin("RedisBungee") != null;
ConfigUpdater.updateConfig(new UniversalFile(dir, "SubServers:sync.yml"));
config.reload();
@ -129,7 +133,8 @@ public final class ExProxy extends BungeeCord implements Listener {
reconnect = true;
Logger.get("SubData").info("");
connect();
Logger.get("SubData").info("Connecting to /" + config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391"));
connect(null);
super.startListeners();
@ -150,9 +155,26 @@ public final class ExProxy extends BungeeCord implements Listener {
}
}
private void connect() throws IOException {
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
private void connect(NamedContainer<DisconnectReason, DataClient> disconnect) throws IOException {
int reconnect = config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.name() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.name() != DisconnectReason.ENCRYPTION_MISMATCH)) {
long reset = resetDate;
Timer timer = new Timer("SubServers.Sync::SubData_Reconnect_Handler");
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
if (reset == resetDate && subdata.getOrDefault(0, null) == null)
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?
null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
timer.cancel();
} catch (IOException e) {
net.ME1312.SubServers.Sync.Library.Compatibility.Logger.get("SubData").info("Connection was unsuccessful, retrying in " + reconnect + " seconds");
}
}
}, (disconnect == null)?0:TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
}
}
private void post() {

View File

@ -2,6 +2,7 @@ package net.ME1312.SubServers.Sync.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.Library.DisconnectReason;
@ -165,27 +166,8 @@ public class SubProtocol extends SubDataProtocol {
plugin.getPluginManager().callEvent(event);
map.put(0, null);
int reconnect = plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
if (Util.getDespiteException(() -> Util.reflect(ExProxy.class.getDeclaredField("reconnect"), plugin), false) && reconnect > 0
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
net.ME1312.SubServers.Sync.Library.Compatibility.Logger.get("SubData").info("Attempting reconnect in " + reconnect + " seconds");
Timer timer = new Timer("SubServers.Sync::SubData_Reconnect_Handler");
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
Util.reflect(ExProxy.class.getDeclaredMethod("connect"), plugin);
timer.cancel();
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof IOException) {
net.ME1312.SubServers.Sync.Library.Compatibility.Logger.get("SubData").info("Connection was unsuccessful, retrying in " + reconnect + " seconds");
} else e.printStackTrace();
} catch (NoSuchMethodException | IllegalAccessException e) {
e.printStackTrace();
}
}
}, TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
}
net.ME1312.SubServers.Sync.Library.Compatibility.Logger.get("SubData").info("Attempting reconnect in " + plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30) + " seconds");
Util.isException(() -> Util.reflect(ExProxy.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
});
return subdata;