Skip to content

Commit

Permalink
Added intended protocol state to PreConnectEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Oct 6, 2024
1 parent af9ff84 commit a0f35c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.net.HostAndPort;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.Channel;
import net.raphimc.netminecraft.constants.IntendedState;
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;

import java.net.SocketAddress;
Expand All @@ -30,15 +31,17 @@ public class PreConnectEvent extends EventCancellable {
private ProtocolVersion serverVersion;
private final ProtocolVersion clientVersion;
private final HostAndPort clientHandshakeAddress;
private final IntendedState intendedState;
private final Channel clientChannel;

private String cancelMessage = "§cCould not connect to the backend server! (Server is blacklisted)";

public PreConnectEvent(final SocketAddress serverAddress, final ProtocolVersion serverVersion, final ProtocolVersion clientVersion, final HostAndPort clientHandshakeAddress, final Channel clientChannel) {
public PreConnectEvent(final SocketAddress serverAddress, final ProtocolVersion serverVersion, final ProtocolVersion clientVersion, final HostAndPort clientHandshakeAddress, final IntendedState intendedState, final Channel clientChannel) {
this.serverAddress = serverAddress;
this.serverVersion = serverVersion;
this.clientVersion = clientVersion;
this.clientHandshakeAddress = clientHandshakeAddress;
this.intendedState = intendedState;
this.clientChannel = clientChannel;
}

Expand Down Expand Up @@ -66,6 +69,10 @@ public HostAndPort getClientHandshakeAddress() {
return this.clientHandshakeAddress;
}

public IntendedState getIntendedState() {
return this.intendedState;
}

public Channel getClientChannel() {
return this.clientChannel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void handleHandshake(final C2SHandshakingClientIntentionPacket packet) {
clientHandshakeAddress = null;
}

final PreConnectEvent preConnectEvent = new PreConnectEvent(serverAddress, serverVersion, clientVersion, clientHandshakeAddress, this.proxyConnection.getC2P());
final PreConnectEvent preConnectEvent = new PreConnectEvent(serverAddress, serverVersion, clientVersion, clientHandshakeAddress, packet.intendedState, this.proxyConnection.getC2P());
if (ViaProxy.EVENT_MANAGER.call(preConnectEvent).isCancelled()) {
this.proxyConnection.kickClient(preConnectEvent.getCancelMessage());
}
Expand Down

0 comments on commit a0f35c8

Please sign in to comment.