Added intended protocol state to PreConnectEvent
Some checks are pending
build-docker / build (push) Waiting to run
build / build (push) Waiting to run

This commit is contained in:
RaphiMC 2024-10-06 19:30:06 +02:00
parent af9ff84fbb
commit a0f35c8ae0
No known key found for this signature in database
GPG key ID: 0F6BB0657A03AC94
2 changed files with 9 additions and 2 deletions

View file

@ -20,6 +20,7 @@ package net.raphimc.viaproxy.plugins.events;
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;
@ -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;
}
@ -66,6 +69,10 @@ public class PreConnectEvent extends EventCancellable {
return this.clientHandshakeAddress;
}
public IntendedState getIntendedState() {
return this.intendedState;
}
public Channel getClientChannel() {
return this.clientChannel;
}

View file

@ -186,7 +186,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<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());
}