geforkt von Mirrors/Velocity
Strictly validate server ping state
Dieser Commit ist enthalten in:
Ursprung
f34b5ac2fc
Commit
c3dcf9b1dd
@ -19,6 +19,7 @@ import com.velocitypowered.proxy.protocol.packet.StatusPing;
|
|||||||
import com.velocitypowered.proxy.protocol.packet.StatusRequest;
|
import com.velocitypowered.proxy.protocol.packet.StatusRequest;
|
||||||
import com.velocitypowered.proxy.protocol.packet.StatusResponse;
|
import com.velocitypowered.proxy.protocol.packet.StatusResponse;
|
||||||
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
||||||
|
import com.velocitypowered.proxy.util.except.QuietRuntimeException;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -31,16 +32,22 @@ import org.apache.logging.log4j.Logger;
|
|||||||
public class StatusSessionHandler implements MinecraftSessionHandler {
|
public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(StatusSessionHandler.class);
|
private static final Logger logger = LogManager.getLogger(StatusSessionHandler.class);
|
||||||
|
private static final QuietRuntimeException EXPECTED_AWAITING_REQUEST = new QuietRuntimeException(
|
||||||
|
"Expected connection to be awaiting status request");
|
||||||
|
private static final QuietRuntimeException EXPECTED_RECEIVED_REQUEST = new QuietRuntimeException(
|
||||||
|
"Expected connection to be awaiting ping");
|
||||||
|
|
||||||
private final VelocityServer server;
|
private final VelocityServer server;
|
||||||
private final MinecraftConnection connection;
|
private final MinecraftConnection connection;
|
||||||
private final InboundConnection inbound;
|
private final InboundConnection inbound;
|
||||||
|
private State state;
|
||||||
|
|
||||||
StatusSessionHandler(VelocityServer server, MinecraftConnection connection,
|
StatusSessionHandler(VelocityServer server, MinecraftConnection connection,
|
||||||
InboundConnection inbound) {
|
InboundConnection inbound) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.inbound = inbound;
|
this.inbound = inbound;
|
||||||
|
this.state = State.AWAITING_REQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -151,6 +158,10 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(LegacyPing packet) {
|
public boolean handle(LegacyPing packet) {
|
||||||
|
if (this.state != State.AWAITING_REQUEST) {
|
||||||
|
throw EXPECTED_AWAITING_REQUEST;
|
||||||
|
}
|
||||||
|
this.state = State.RECEIVED_REQUEST;
|
||||||
getInitialPing()
|
getInitialPing()
|
||||||
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
|
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
|
||||||
.thenAcceptAsync(event -> {
|
.thenAcceptAsync(event -> {
|
||||||
@ -162,12 +173,19 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(StatusPing packet) {
|
public boolean handle(StatusPing packet) {
|
||||||
|
if (this.state != State.RECEIVED_REQUEST) {
|
||||||
|
throw EXPECTED_RECEIVED_REQUEST;
|
||||||
|
}
|
||||||
connection.closeWith(packet);
|
connection.closeWith(packet);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(StatusRequest packet) {
|
public boolean handle(StatusRequest packet) {
|
||||||
|
if (this.state != State.AWAITING_REQUEST) {
|
||||||
|
throw EXPECTED_AWAITING_REQUEST;
|
||||||
|
}
|
||||||
|
this.state = State.RECEIVED_REQUEST;
|
||||||
getInitialPing()
|
getInitialPing()
|
||||||
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
|
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
|
||||||
.thenAcceptAsync(
|
.thenAcceptAsync(
|
||||||
@ -186,4 +204,9 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
|||||||
// what even is going on?
|
// what even is going on?
|
||||||
connection.close(true);
|
connection.close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum State {
|
||||||
|
AWAITING_REQUEST,
|
||||||
|
RECEIVED_REQUEST
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren