Skip to content

Commit

Permalink
fix protocols always mismatching for real
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Sep 8, 2024
1 parent 51cc320 commit 77aead2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import me.mrnavastar.protoweaver.core.util.ProtoConstants;

@Getter
@Setter
Expand All @@ -17,6 +18,7 @@ public enum Status {
UPGRADE
}

private final String protoweaverVersion = ProtoConstants.PROTOWEAVER_VERSION;
private String currentProtocol;
private String nextProtocol;
private byte[] nextSHA1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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.");

Expand Down

0 comments on commit 77aead2

Please sign in to comment.