Add an error checking thread for player sync

This commit is contained in:
ME1312 2020-08-22 20:01:58 -04:00
parent e9c0075144
commit 6e60138a79
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
7 changed files with 123 additions and 21 deletions

View File

@ -150,6 +150,7 @@ public class ConfigUpdater {
if (i > 0) {
YAMLSection settings = new YAMLSection();
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
if (updated.getMap("Settings", new YAMLSection()).contains("RemotePlayer-Cache-Interval")) settings.set("RemotePlayer-Cache-Interval", updated.getMap("Settings").getRawString("RemotePlayer-Cache-Interval"));
settings.set("Disabled-Overrides", updated.getMap("Settings", new YAMLSection()).getRawStringList("Disabled-Overrides", Collections.emptyList()));
YAMLSection smart_fallback = new YAMLSection();

View File

@ -64,14 +64,14 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
public void receive(SubDataClient client, ObjectMap<Integer> data) {
if (client.getHandler() instanceof Proxy) {
ArrayList<RemotePlayer> forward = new ArrayList<RemotePlayer>();
if (data.getBoolean(0x0001) == null) {
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, (Proxy) client.getHandler())) {
plugin.rPlayerLinkS.remove(id);
plugin.rPlayerLinkP.remove(id);
plugin.rPlayers.remove(id);
}
}
synchronized (plugin.rPlayers) {
if (data.getBoolean(0x0001) == null) {
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, (Proxy) client.getHandler())) {
plugin.rPlayerLinkS.remove(id);
plugin.rPlayerLinkP.remove(id);
plugin.rPlayers.remove(id);
}
}
if (data.getBoolean(0x0001) != Boolean.FALSE) {
if (data.contains(0x0002)) for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
Server server = (object.getOrDefault("server", null) != null)?plugin.api.getServer(object.get("server").toString()):null;
@ -99,8 +99,9 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
}
if (data.getBoolean(0x0001) == null || forward.size() > 0) {
PacketExSyncPlayer packet = new PacketExSyncPlayer(((Proxy) client.getHandler()).getName(), data.getBoolean(0x0001), forward.toArray(new RemotePlayer[0]));
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null && proxy != client.getHandler()) {
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(((Proxy) client.getHandler()).getName(), data.getBoolean(0x0001), forward.toArray(new RemotePlayer[0])));
((SubDataClient) proxy.getSubData()[0]).sendPacket(packet);
}
}
}

View File

@ -33,6 +33,7 @@ import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.BungeeServerInfo;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
@ -668,6 +669,46 @@ public final class SubProxy extends BungeeCord implements Listener {
} catch (Exception e) {}
}
}, 0, TimeUnit.DAYS.toMillis(2));
int interval = config.get().getMap("Settings").getInt("RemotePlayer-Cache-Interval", 300);
int start = interval - new Random().nextInt((interval / 3) + 1);
new Timer("SubServers.Bungee::RemotePlayer_Error_Checking").schedule(new TimerTask() {
@Override
public void run() {
synchronized (rPlayers) {
ArrayList<RemotePlayer> add = new ArrayList<RemotePlayer>();
for (ProxiedPlayer player : getPlayers()) {
if (!rPlayers.containsKey(player.getUniqueId())) { // Add players that don't exist
Logger.get("SubServers").info("RPEC::Add(" + player.getUniqueId() + ")");
RemotePlayer p = new RemotePlayer(player);
rPlayerLinkP.put(player.getUniqueId(), p.getProxy());
rPlayers.put(player.getUniqueId(), p);
if (p.getServer() != null) rPlayerLinkS.put(player.getUniqueId(), p.getServer());
add.add(p);
}
}
ArrayList<RemotePlayer> remove = new ArrayList<RemotePlayer>();
for (UUID player : Util.getBackwards(rPlayerLinkP, mProxy)) { // Remove players that shouldn't exist
if (getPlayer(player) == null) {
Logger.get("SubServers").info("RPEC::Remove(" + player + ")");
remove.add(rPlayers.get(player));
rPlayerLinkS.remove(player);
rPlayerLinkP.remove(player);
rPlayers.remove(player);
}
}
LinkedList<PacketExSyncPlayer> packets = new LinkedList<PacketExSyncPlayer>(); // Compile change data for external proxies
if (add.size() > 0) packets.add(new PacketExSyncPlayer(mProxy.getName(), true, add.toArray(new RemotePlayer[0])));
if (remove.size() > 0) packets.add(new PacketExSyncPlayer(mProxy.getName(), false, remove.toArray(new RemotePlayer[0])));
if (packets.size() > 0) {
PacketExSyncPlayer[] packet = packets.toArray(new PacketExSyncPlayer[0]);
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
((SubDataClient) proxy.getSubData()[0]).sendPacket(packet);
}
}
}
}
}, TimeUnit.SECONDS.toMillis(start), TimeUnit.SECONDS.toMillis(interval));
}
/**
@ -850,8 +891,9 @@ public final class SubProxy extends BungeeCord implements Listener {
@EventHandler(priority = Byte.MIN_VALUE)
public void login(LoginEvent e) {
ProxyServer.getInstance().getLogger().info("UUID of player " + e.getConnection().getName() + " is " + e.getConnection().getUniqueId());
if (rPlayers.containsKey(e.getConnection().getUniqueId())) {
Logger.get("SubServers").info(e.getConnection().getName() + " connected, but already had a database entry");
Logger.get("SubServers").warning(e.getConnection().getName() + " connected, but already had a database entry");
RemotePlayer player = rPlayers.get(e.getConnection().getUniqueId());
if (player.getProxy() == null || player.getProxy().isMaster()) {
ProxiedPlayer p = getPlayer(player.getUniqueId());
@ -962,12 +1004,14 @@ public final class SubProxy extends BungeeCord implements Listener {
synchronized (rPlayers) {
if (rPlayers.containsKey(e.getPlayer().getUniqueId()) && (!rPlayerLinkP.containsKey(e.getPlayer().getUniqueId()) || rPlayerLinkP.get(e.getPlayer().getUniqueId()).isMaster())) {
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(mProxy.getName(), false, rPlayers.get(e.getPlayer().getUniqueId())));
}
RemotePlayer player = rPlayers.get(e.getPlayer().getUniqueId());
rPlayerLinkS.remove(e.getPlayer().getUniqueId());
rPlayerLinkP.remove(e.getPlayer().getUniqueId());
rPlayers.remove(e.getPlayer().getUniqueId());
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(mProxy.getName(), false, player));
}
}
}
}

View File

@ -59,6 +59,7 @@ public class ConfigUpdater {
settings.set("Show-Addresses", updated.getMap("Settings", new YAMLSection()).getBoolean("Show-Addresses", false));
settings.set("Use-Title-Messages", updated.getMap("Settings", new YAMLSection()).getBoolean("Use-Title-Messages", true));
settings.set("PlaceholderAPI-Ready", updated.getMap("Settings", new YAMLSection()).getBoolean("PlaceholderAPI-Ready", false));
if (updated.getMap("Settings", new YAMLSection()).contains("PlaceholderAPI-Cache-Interval")) settings.set("PlaceholderAPI-Cache-Interval", updated.getMap("Settings").getRawString("PlaceholderAPI-Cache-Interval"));
YAMLSection subdata = new YAMLSection();
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Name")) subdata.set("Name", updated.getMap("Settings").getMap("SubData").getRawString("Name"));

View File

@ -32,6 +32,7 @@ import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.BungeeServerInfo;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
@ -237,6 +238,58 @@ public final class ExProxy extends BungeeCord implements Listener {
} catch (Exception e) {}
}
}, 0, TimeUnit.DAYS.toMillis(2));
int interval = config.get().getMap("Settings").getInt("RemotePlayer-Cache-Interval", 300);
int start = interval - new Random().nextInt((interval / 3) + 1);
new Timer("SubServers.Sync::RemotePlayer_Error_Checking").schedule(new TimerTask() {
@Override
public void run() {
if (api.getSubDataNetwork()[0] != null && !api.getSubDataNetwork()[0].isClosed()) {
api.getProxy(api.getName(), proxy -> {
synchronized (rPlayers) {
ArrayList<RemotePlayer> add = new ArrayList<RemotePlayer>();
for (ProxiedPlayer player : getPlayers()) {
if (!rPlayers.containsKey(player.getUniqueId())) { // Add players that don't exist
Logger.get("SubServers").info("RPEC::Add(" + player.getUniqueId() + ")");
RemotePlayer p = new RemotePlayer(player);
rPlayerLinkP.put(player.getUniqueId(), p.getProxy().toLowerCase());
rPlayers.put(player.getUniqueId(), p);
if (player.getServer().getInfo() instanceof ServerImpl) rPlayerLinkS.put(player.getUniqueId(), (ServerImpl) player.getServer().getInfo());
add.add(p);
}
}
ArrayList<RemotePlayer> remove = new ArrayList<RemotePlayer>();
for (NamedContainer<String, UUID> player : proxy.getPlayers()) { // Remove players that shouldn't exist
if (getPlayer(player.get()) == null) {
Logger.get("SubServers").info("RPEC::Remove(" + player + ")");
remove.add(rPlayers.get(player.get()));
rPlayerLinkS.remove(player.get());
rPlayerLinkP.remove(player.get());
rPlayers.remove(player.get());
}
}
for (UUID player : Util.getBackwards(rPlayerLinkP, api.getName().toLowerCase())) { // Remove players that shouldn't exist (internally)
if (getPlayer(player) == null) {
Logger.get("SubServers").info("RPEC::Internal(" + player + ")");
rPlayerLinkS.remove(player);
rPlayerLinkP.remove(player);
rPlayers.remove(player);
}
}
LinkedList<PacketExSyncPlayer> packets = new LinkedList<PacketExSyncPlayer>(); // Compile change data for external proxies
if (add.size() > 0) packets.add(new PacketExSyncPlayer(true, add.toArray(new RemotePlayer[0])));
if (remove.size() > 0) packets.add(new PacketExSyncPlayer(false, remove.toArray(new RemotePlayer[0])));
if (packets.size() > 0) {
PacketExSyncPlayer[] packet = packets.toArray(new PacketExSyncPlayer[0]);
if (api.getSubDataNetwork()[0] != null) {
((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(packet);
}
}
}
});
}
}
}, TimeUnit.SECONDS.toMillis(start), TimeUnit.SECONDS.toMillis(interval));
}
/**
@ -374,8 +427,9 @@ public final class ExProxy extends BungeeCord implements Listener {
@EventHandler(priority = Byte.MIN_VALUE)
public void login(LoginEvent e) {
ProxyServer.getInstance().getLogger().info("UUID of player " + e.getConnection().getName() + " is " + e.getConnection().getUniqueId());
if (rPlayers.containsKey(e.getConnection().getUniqueId())) {
Logger.get("SubServers").info(e.getConnection().getName() + " connected, but already had a database entry");
Logger.get("SubServers").warning(e.getConnection().getName() + " connected, but already had a database entry");
RemotePlayer player = rPlayers.get(e.getConnection().getUniqueId());
if (player.getProxy() != null && player.getProxy().equalsIgnoreCase(api.getName())) {
ProxiedPlayer p = getPlayer(player.getUniqueId());

View File

@ -74,6 +74,7 @@ public class ConfigUpdater {
if (i > 0) {
YAMLSection settings = new YAMLSection();
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
if (updated.getMap("Settings", new YAMLSection()).contains("RemotePlayer-Cache-Interval")) settings.set("RemotePlayer-Cache-Interval", updated.getMap("Settings").getRawString("RemotePlayer-Cache-Interval"));
settings.set("Disabled-Overrides", updated.getMap("Settings", new YAMLSection()).getRawStringList("Disabled-Overrides", Collections.emptyList()));
YAMLSection smart_fallback = new YAMLSection();

View File

@ -56,14 +56,14 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
String proxy = (data.contains(0x0000)?data.getRawString(0x0000).toLowerCase():null);
if (data.getBoolean(0x0001) == null) {
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, proxy)) {
plugin.rPlayerLinkS.remove(id);
plugin.rPlayerLinkP.remove(id);
plugin.rPlayers.remove(id);
}
}
synchronized (plugin.rPlayers) {
if (data.getBoolean(0x0001) == null) {
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, proxy)) {
plugin.rPlayerLinkS.remove(id);
plugin.rPlayerLinkP.remove(id);
plugin.rPlayers.remove(id);
}
}
if (data.getBoolean(0x0001) != Boolean.FALSE) {
if (data.contains(0x0002)) for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
ServerImpl server = (object.getOrDefault("server", null) != null)?plugin.servers.getOrDefault(object.get("server").toString().toLowerCase(), null):null;
@ -78,7 +78,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
UUID id = UUID.fromString(object.get("id").toString());
// Don't accept removal requests when we're managing players
if ((!plugin.rPlayerLinkP.containsKey(id) || !plugin.rPlayerLinkP.get(id).equalsIgnoreCase(plugin.api.getName()))) {
if ((!plugin.rPlayerLinkP.containsKey(id) || !plugin.rPlayerLinkP.get(id).equalsIgnoreCase(plugin.api.getName().toLowerCase()))) {
plugin.rPlayerLinkS.remove(id);
plugin.rPlayerLinkP.remove(id);
plugin.rPlayers.remove(id);