Skip to content

Commit

Permalink
Don't attempt reconnect while shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Sep 26, 2019
1 parent 27806b9 commit a5c5a53
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
Expand Up @@ -46,7 +46,7 @@ public void send(SubDataClient client, OutputStream stream) throws Throwable {

@Override
public void receive(SubDataClient client) {
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost && plugin.config.get().getMap("Hosts").getKeys().contains(((ExternalHost) client.getHandler()).getName())) {
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost) {
client.sendPacket(new PacketExDownloadTemplates(plugin, (ExternalHost) client.getHandler()));
}
}
Expand Down
Expand Up @@ -166,8 +166,10 @@ public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddre
if (plugin.isEnabled()) Bukkit.getPluginManager().callEvent(event);
map.put(0, null);

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));
if (plugin.isEnabled()) {
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;
Expand Down
Expand Up @@ -177,9 +177,11 @@ public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddre
Sponge.getEventManager().post(event);
map.put(0, null);

Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
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));
if (Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("running"), plugin), true)) {
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
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;
Expand Down
Expand Up @@ -58,6 +58,7 @@ public final class SubPlugin {
@Inject public PluginContainer plugin;
@Inject public Game game;

private boolean running = false;
private long resetDate = 0;
private boolean reconnect = false;

Expand Down Expand Up @@ -97,6 +98,7 @@ public void enable(GameInitializationEvent event) {
Files.move(new UniversalFile(new File(System.getProperty("user.dir")), "subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
}

running = true;
subprotocol = SubProtocol.get();
reload(false);

Expand Down Expand Up @@ -218,6 +220,7 @@ public void run() {
*/
@Listener
public void disable(GameStoppingEvent event) {
running = false;
if (subdata != null) try {
reconnect = false;

Expand Down
Expand Up @@ -163,9 +163,11 @@ public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddre
host.engine.getPluginManager().executeEvent(event);
map.put(0, null);

Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
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));
if (Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("running"), host), true)) {
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
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;
Expand Down
Expand Up @@ -166,8 +166,10 @@ public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddre
plugin.getPluginManager().callEvent(event);
map.put(0, null);

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));
if (plugin.isRunning) {
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;
Expand Down

0 comments on commit a5c5a53

Please sign in to comment.