mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 06:09:05 +00:00
Ensure server identity changes trigger full sync
This commit is contained in:
1 parent
0c42fb8128
commit
e73b5f3897
4 files changed
+36
-4
No files matched your search
@@ -133,14 +133,26 @@ public class SyncController {
|
||||
public static void handleClientRevisionReport(
|
||||
EntityPlayerMP player,
|
||||
String serverKey,
|
||||
String previousServerKey,
|
||||
Map<EnumSyncType, Integer> clientRevisions
|
||||
) {
|
||||
if (!getServerCacheKey().equals(serverKey)) {
|
||||
String currentServerKey = getServerCacheKey();
|
||||
PlayerSyncState state = PLAYER_SYNC_STATE.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new);
|
||||
|
||||
if (!currentServerKey.equals(serverKey)) {
|
||||
state.reset();
|
||||
syncPlayer(player);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerSyncState state = PLAYER_SYNC_STATE.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new);
|
||||
if (!currentServerKey.isEmpty()) {
|
||||
if (previousServerKey == null || !currentServerKey.equals(previousServerKey)) {
|
||||
state.reset();
|
||||
syncPlayer(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
state.applyHandshake(clientRevisions);
|
||||
|
||||
syncPlayer(player);
|
||||
@@ -959,5 +971,9 @@ public class SyncController {
|
||||
revisions.putAll(incoming);
|
||||
}
|
||||
|
||||
private synchronized void reset() {
|
||||
revisions.clear();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@ public final class LoginPacket extends AbstractPacket {
|
||||
|
||||
PacketClient.sendClient(new SyncRevisionInfoPacket(
|
||||
serverKey,
|
||||
ClientCacheHandler.getLastServerKey(),
|
||||
ClientCacheHandler.getCachedRevisionsForServer(serverKey)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -22,15 +22,19 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||
public static final String packetName = "Player|SyncRevisionInfo";
|
||||
|
||||
private String serverKey = "";
|
||||
private String previousServerKey = "";
|
||||
private final EnumMap<EnumSyncType, Integer> revisions = new EnumMap<>(EnumSyncType.class);
|
||||
|
||||
public SyncRevisionInfoPacket() {
|
||||
}
|
||||
|
||||
public SyncRevisionInfoPacket(String serverKey, EnumMap<EnumSyncType, Integer> revisions) {
|
||||
public SyncRevisionInfoPacket(String serverKey, String previousServerKey, EnumMap<EnumSyncType, Integer> revisions) {
|
||||
if (serverKey != null) {
|
||||
this.serverKey = serverKey;
|
||||
}
|
||||
if (previousServerKey != null) {
|
||||
this.previousServerKey = previousServerKey;
|
||||
}
|
||||
if (revisions != null) {
|
||||
this.revisions.putAll(revisions);
|
||||
}
|
||||
@@ -50,6 +54,7 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, serverKey);
|
||||
ByteBufUtils.writeString(out, previousServerKey);
|
||||
out.writeShort(revisions.size());
|
||||
for (Map.Entry<EnumSyncType, Integer> entry : revisions.entrySet()) {
|
||||
out.writeInt(entry.getKey().ordinal());
|
||||
@@ -64,6 +69,7 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||
}
|
||||
|
||||
String incomingServerKey = ByteBufUtils.readString(in);
|
||||
String incomingPreviousKey = ByteBufUtils.readString(in);
|
||||
int revisionCount = in.readUnsignedShort();
|
||||
EnumMap<EnumSyncType, Integer> incomingRevisions = new EnumMap<>(EnumSyncType.class);
|
||||
for (int i = 0; i < revisionCount; i++) {
|
||||
@@ -72,6 +78,6 @@ public class SyncRevisionInfoPacket extends AbstractPacket {
|
||||
incomingRevisions.put(type, revision);
|
||||
}
|
||||
|
||||
SyncController.handleClientRevisionReport((EntityPlayerMP) player, incomingServerKey, incomingRevisions);
|
||||
SyncController.handleClientRevisionReport((EntityPlayerMP) player, incomingServerKey, incomingPreviousKey, incomingRevisions);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public class ClientCacheHandler {
|
||||
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
|
||||
|
||||
private static String activeServerKey = "";
|
||||
private static String lastServerKey = "";
|
||||
private static final Map<String, EnumMap<EnumSyncType, Integer>> clientRevisionCache = new HashMap<>();
|
||||
|
||||
public static Party party;
|
||||
@@ -40,9 +41,13 @@ public class ClientCacheHandler {
|
||||
|
||||
public static void setActiveServer(String serverKey, EnumMap<EnumSyncType, Integer> serverRevisions) {
|
||||
String normalizedKey = serverKey == null ? "" : serverKey;
|
||||
String previousKey = activeServerKey == null ? "" : activeServerKey;
|
||||
lastServerKey = previousKey;
|
||||
|
||||
if (!normalizedKey.equals(activeServerKey)) {
|
||||
clientRevisionCache.clear();
|
||||
}
|
||||
|
||||
activeServerKey = normalizedKey;
|
||||
|
||||
if (activeServerKey.isEmpty()) {
|
||||
@@ -58,6 +63,10 @@ public class ClientCacheHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLastServerKey() {
|
||||
return lastServerKey == null ? "" : lastServerKey;
|
||||
}
|
||||
|
||||
public static EnumMap<EnumSyncType, Integer> getCachedRevisionsForServer(String serverKey) {
|
||||
String key = serverKey == null ? "" : serverKey;
|
||||
if (key.isEmpty()) {
|
||||
|
||||
Reference in new issue
Block a user