Fix possible player data desyncs

This commit is contained in:
ME1312 2020-07-25 05:43:42 -04:00
parent 891913dbe3
commit efc12e0649
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
5 changed files with 41 additions and 17 deletions

View File

@ -9,6 +9,7 @@ import net.ME1312.Galaxi.Library.ExtraDataHandler;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.ClientHandler;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExSyncPlayer;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.ME1312.SubServers.Bungee.SubProxy;
import net.md_5.bungee.api.ProxyServer;
@ -49,6 +50,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
return channels.toArray(new DataClient[0]);
}
@SuppressWarnings("deprecation")
public void setSubData(SubDataClient client, int channel) {
boolean update = false;
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
@ -65,9 +67,20 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
if (update) {
DataClient[] subdata = getSubData();
if (subdata[0] == null && subdata.length <= 1 && !persistent) {
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveProxyEvent(this));
SubAPI.getInstance().getInternals().proxies.remove(getName().toLowerCase());
if (subdata[0] == null && subdata.length <= 1) {
SubProxy plugin = SubAPI.getInstance().getInternals();
for (UUID id : Util.getBackwards(plugin.rPlayerLinkP, this)) {
plugin.rPlayerLinkS.remove(id);
plugin.rPlayerLinkP.remove(id);
plugin.rPlayers.remove(id);
}
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null && proxy != this) {
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(getName(), null, (RemotePlayer[]) null));
}
if (!persistent) {
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveProxyEvent(this));
SubAPI.getInstance().getInternals().proxies.remove(getName().toLowerCase());
}
}
}
}

View File

@ -20,7 +20,7 @@ import java.util.*;
public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private SubProxy plugin;
private String name;
private boolean mode;
private Boolean mode;
private RemotePlayer[] values;
/**
@ -41,7 +41,6 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
* @param values RemotePlayers
*/
public PacketExSyncPlayer(String name, Boolean mode, RemotePlayer... values) {
if (Util.isNull(mode)) throw new NullPointerException();
this.name = name;
this.mode = mode;
this.values = values;
@ -73,7 +72,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
}
}
if (data.getBoolean(0x0001) != Boolean.FALSE) {
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
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;
RemotePlayer player = new RemotePlayer(object.get("name").toString(), UUID.fromString(object.get("id").toString()), (Proxy) client.getHandler(), server,
new InetSocketAddress(object.get("address").toString().split(":")[0], Integer.parseInt(object.get("address").toString().split(":")[1])));
@ -84,7 +83,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
if (server != null) plugin.rPlayerLinkS.put(player.getUniqueId(), server);
}
} else {
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
if (data.contains(0x0002)) for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
UUID id = UUID.fromString(object.get("id").toString());
RemotePlayer player = plugin.rPlayers.get(id);
@ -95,7 +94,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
}
}
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null && proxy != client.getHandler()) {
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(proxy.getName(), data.getBoolean(0x0001), forward.toArray(new RemotePlayer[0])));
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketExSyncPlayer(((Proxy) client.getHandler()).getName(), data.getBoolean(0x0001), forward.toArray(new RemotePlayer[0])));
}
}
}

View File

@ -314,6 +314,10 @@ public final class ExProxy extends BungeeCord implements Listener {
for (ListenerInfo listener : getConfig().getListeners()) {
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
}
rPlayerLinkS.clear();
rPlayerLinkP.clear();
rPlayers.clear();
} catch (Exception e) {
e.printStackTrace();
}
@ -410,7 +414,7 @@ public final class ExProxy extends BungeeCord implements Listener {
raw.set("server", e.getServer().getInfo().getName());
RemotePlayer player = new RemotePlayer(raw);
rPlayers.put(player.getUniqueId(), player);
rPlayerLinkP.put(player.getUniqueId(), player.getProxy());
rPlayerLinkP.put(player.getUniqueId(), player.getProxy().toLowerCase());
if (e.getServer().getInfo() instanceof ServerImpl) rPlayerLinkS.put(player.getUniqueId(), (ServerImpl) e.getServer().getInfo());
if (api.getSubDataNetwork()[0] != null) {
((SubDataClient) api.getSubDataNetwork()[0]).sendPacket(new PacketExSyncPlayer(true, player));

View File

@ -16,7 +16,7 @@ import java.util.*;
*/
public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private ExProxy plugin;
private boolean mode;
private Boolean mode;
private RemotePlayer[] values;
/**
@ -36,7 +36,6 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
* @param values RemotePlayers
*/
public PacketExSyncPlayer(Boolean mode, RemotePlayer... values) {
if (Util.isNull(mode)) throw new NullPointerException();
this.mode = mode;
this.values = values;
}
@ -65,7 +64,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
}
}
if (data.getBoolean(0x0001) != Boolean.FALSE) {
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
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;
RemotePlayer player = new RemotePlayer(new ObjectMap<>(object));
@ -74,7 +73,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
if (server != null) plugin.rPlayerLinkS.put(player.getUniqueId(), server);
}
} else {
for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
if (data.contains(0x0002)) for (Map<String, Object> object : (List<Map<String, Object>>) data.getObjectList(0x0002)) {
UUID id = UUID.fromString(object.get("id").toString());
plugin.rPlayerLinkS.remove(id);
plugin.rPlayerLinkP.remove(id);

View File

@ -23,10 +23,7 @@ import net.md_5.bungee.conf.Configuration;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@ -161,6 +158,18 @@ public class SubProtocol extends SubDataProtocol {
e.printStackTrace();
}
ArrayList<RemotePlayer> localPlayers = new ArrayList<RemotePlayer>();
for (UUID id : new ArrayList<UUID>(plugin.rPlayers.keySet())) {
if (plugin.getPlayer(id) != null) {
localPlayers.add(plugin.rPlayers.get(id));
} else {
plugin.rPlayerLinkS.remove(id);
plugin.rPlayerLinkP.remove(id);
plugin.rPlayers.remove(id);
}
}
subdata.sendPacket(new PacketExSyncPlayer(null, localPlayers.toArray(new RemotePlayer[0])));
plugin.api.getServers(servers -> {
for (Server server : servers.values()) {
plugin.merge(server);