From 77aead2fb722958b06bbe53ad8eafc9780118203 Mon Sep 17 00:00:00 2001 From: MrNavaStar Date: Sun, 8 Sep 2024 12:03:12 -0600 Subject: [PATCH] fix protocols always mismatching for real --- .../protocol/protoweaver/ClientConnectionHandler.java | 5 +++++ .../core/protocol/protoweaver/ProtocolStatus.java | 2 ++ .../protocol/protoweaver/ServerConnectionHandler.java | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ClientConnectionHandler.java b/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ClientConnectionHandler.java index 83e5180..b915300 100644 --- a/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ClientConnectionHandler.java +++ b/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ClientConnectionHandler.java @@ -6,6 +6,7 @@ import me.mrnavastar.protoweaver.api.netty.ProtoConnection; import me.mrnavastar.protoweaver.api.protocol.Protocol; import me.mrnavastar.protoweaver.api.protocol.Side; +import me.mrnavastar.protoweaver.core.util.ProtoConstants; public class ClientConnectionHandler extends InternalConnectionHandler implements ProtoConnectionHandler { @@ -38,6 +39,10 @@ public void handlePacket(ProtoConnection connection, Object packet) { disconnectIfNeverUpgraded(connection); } case UPGRADE -> { + if (!ProtoConstants.PROTOWEAVER_VERSION.equals(status.getProtoweaverVersion())) { + protocol.logWarn("Connecting with ProtoWeaver version: " + status.getProtoweaverVersion() + ", but server is running: " + ProtoConstants.PROTOWEAVER_VERSION + ". There could be unexpected issues."); + } + if (!authenticated) return; protocol = ProtoWeaver.getLoadedProtocol(status.getNextProtocol()); if (protocol == null) { diff --git a/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ProtocolStatus.java b/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ProtocolStatus.java index a73f00b..0b32138 100644 --- a/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ProtocolStatus.java +++ b/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ProtocolStatus.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import me.mrnavastar.protoweaver.core.util.ProtoConstants; @Getter @Setter @@ -17,6 +18,7 @@ public enum Status { UPGRADE } + private final String protoweaverVersion = ProtoConstants.PROTOWEAVER_VERSION; private String currentProtocol; private String nextProtocol; private byte[] nextSHA1; diff --git a/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ServerConnectionHandler.java b/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ServerConnectionHandler.java index 508fd2c..4a350a3 100644 --- a/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ServerConnectionHandler.java +++ b/common/src/main/java/me/mrnavastar/protoweaver/core/protocol/protoweaver/ServerConnectionHandler.java @@ -8,6 +8,9 @@ import me.mrnavastar.protoweaver.api.netty.Sender; import me.mrnavastar.protoweaver.api.protocol.Protocol; import me.mrnavastar.protoweaver.api.protocol.Side; +import me.mrnavastar.protoweaver.core.util.ProtoConstants; + +import java.util.Arrays; public class ServerConnectionHandler extends InternalConnectionHandler implements ProtoConnectionHandler { @@ -28,13 +31,17 @@ public void handlePacket(ProtoConnection connection, Object packet) { return; } + if (!ProtoConstants.PROTOWEAVER_VERSION.equals(status.getProtoweaverVersion())) { + nextProtocol.logWarn("Client connecting with ProtoWeaver version: " + status.getProtoweaverVersion() + ", but server is running: " + ProtoConstants.PROTOWEAVER_VERSION + ". There could be unexpected issues."); + } + if (nextProtocol.getMaxConnections() != -1 && nextProtocol.getConnections() >= nextProtocol.getMaxConnections()) { status.setStatus(ProtocolStatus.Status.FULL); disconnectIfNeverUpgraded(connection, connection.send(status)); return; } - if (nextProtocol.getSHA1() != status.getNextSHA1()) { + if (!Arrays.equals(nextProtocol.getSHA1(), status.getNextSHA1())) { nextProtocol.logErr("Mismatch with protocol version on the client!"); nextProtocol.logErr("Double check that all packets are registered in the same order and all settings are the same.");