1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2026-01-04 15:31:48 +00:00

Added some debug logs for login

This commit is contained in:
Tim203
2023-03-02 21:05:34 +01:00
parent 5e70a0c8aa
commit 9748094cf8
6 changed files with 33 additions and 8 deletions

View File

@@ -80,6 +80,6 @@ public final class DebugAddon implements InjectorAddon {
@Override
public boolean shouldInject() {
return config.isDebug();
return false;
}
}

View File

@@ -34,6 +34,7 @@ import java.net.InetSocketAddress;
import java.util.Queue;
import lombok.RequiredArgsConstructor;
import org.geysermc.floodgate.api.handshake.HandshakeData;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.config.FloodgateConfig;
import org.geysermc.floodgate.crypto.FloodgateCipher;
import org.geysermc.floodgate.player.FloodgateHandshakeHandler;
@@ -47,6 +48,7 @@ public abstract class CommonDataHandler extends ChannelInboundHandlerAdapter {
protected final FloodgateConfig config;
protected final AttributeKey<String> kickMessageAttribute;
protected final PacketBlocker blocker;
protected final FloodgateLogger logger;
protected final Queue<Object> packetQueue = Queues.newConcurrentLinkedQueue();
protected Object handshakePacket;
@@ -70,6 +72,7 @@ public abstract class CommonDataHandler extends ChannelInboundHandlerAdapter {
this.handshakePacket = handshakePacket;
HostnameSeparationResult separation = handshakeHandler.separateHostname(hostname);
logger.info("Is Floodgate player? {} ({})", separation.floodgateData() != null, ctx.channel().id());
if (separation.floodgateData() == null) {
// not a Floodgate player, make sure to resend the cancelled handshake packet
disablePacketQueue(true);
@@ -93,6 +96,10 @@ public abstract class CommonDataHandler extends ChannelInboundHandlerAdapter {
.handle(channel, separation.floodgateData(), separation.hostnameRemainder())
.thenApply(result -> {
HandshakeData handshakeData = result.getHandshakeData();
logger.info(
"passed the first half {} {} ({})",
handshakeData.shouldDisconnect(), result.getResultType(), ctx.channel().id()
);
// we'll change the IP address to the real IP of the client very early on
// so that almost every plugin will use the real IP of the client

View File

@@ -57,9 +57,10 @@ public final class ChannelInDebugHandler extends SimpleChannelInboundHandler<Byt
int index = msg.readerIndex();
if (changeDetector.shouldPrintPacket(msg, !toServer)) {
logger.info("{} {}:\n{}",
logger.info("{} {} ({}):\n{}",
direction,
changeDetector.getCurrentState(),
ctx.channel().id(),
ByteBufUtil.prettyHexDump(msg)
);

View File

@@ -58,9 +58,10 @@ public final class ChannelOutDebugHandler extends MessageToByteEncoder<ByteBuf>
if (changeDetector.shouldPrintPacket(msg, toServer)) {
logger.info(
"{} {}:\n{}",
"{} {} ({}):\n{}",
direction,
changeDetector.getCurrentState(),
ctx.channel().id(),
ByteBufUtil.prettyHexDump(msg)
);

View File

@@ -59,7 +59,7 @@ public final class SpigotDataAddon implements InjectorAddon {
// we have to add the packet blocker in the data handler, otherwise ProtocolSupport breaks
channel.pipeline().addBefore(
packetHandlerName, "floodgate_data_handler",
new SpigotDataHandler(handshakeHandler, config, kickMessageAttribute)
new SpigotDataHandler(handshakeHandler, config, kickMessageAttribute, logger)
);
}

View File

@@ -32,6 +32,7 @@ import com.mojang.authlib.GameProfile;
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import java.net.InetSocketAddress;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.geysermc.floodgate.config.FloodgateConfig;
import org.geysermc.floodgate.player.FloodgateHandshakeHandler;
@@ -47,8 +48,10 @@ public final class SpigotDataHandler extends CommonDataHandler {
public SpigotDataHandler(
FloodgateHandshakeHandler handshakeHandler,
FloodgateConfig config,
AttributeKey<String> kickMessageAttribute) {
super(handshakeHandler, config, kickMessageAttribute, new PacketBlocker());
AttributeKey<String> kickMessageAttribute,
FloodgateLogger logger
) {
super(handshakeHandler, config, kickMessageAttribute, new PacketBlocker(), logger);
}
@Override
@@ -104,6 +107,7 @@ public final class SpigotDataHandler extends CommonDataHandler {
@Override
public boolean channelRead(Object packet) throws Exception {
logger.info("received packet {} ({})", packet.getClass().getName(), ctx.channel().id());
if (ClassNames.HANDSHAKE_PACKET.isInstance(packet)) {
// ProtocolSupport would break if we added this during the creation of this handler
ctx.pipeline().addAfter("splitter", "floodgate_packet_blocker", blocker);
@@ -119,17 +123,27 @@ public final class SpigotDataHandler extends CommonDataHandler {
}
private boolean checkAndHandleLogin(Object packet) throws Exception {
logger.info("check packet {} ({})", packet.getClass().getName(), ctx.channel().id());
if (ClassNames.LOGIN_START_PACKET.isInstance(packet)) {
Object packetListener = ClassNames.PACKET_LISTENER.get(networkManager);
String kickMessage = getKickMessage();
boolean loginListener = !ClassNames.LOGIN_LISTENER.isInstance(packetListener);
boolean usernameValidation = ClassNames.PAPER_DISABLE_USERNAME_VALIDATION != null;
logger.info(
"{} {} {} {} ({})",
kickMessage, loginListener, usernameValidation, proxyData, ctx.channel().id()
);
if (kickMessage != null) {
disconnect(packetListener, kickMessage);
return true;
}
// check if the server is actually in the Login state
if (!ClassNames.LOGIN_LISTENER.isInstance(packetListener)) {
if (loginListener) {
// player is not in the login state, abort
// I would've liked to close the channel for security reasons, but our big friend
@@ -138,7 +152,7 @@ public final class SpigotDataHandler extends CommonDataHandler {
return true;
}
if (ClassNames.PAPER_DISABLE_USERNAME_VALIDATION != null) {
if (usernameValidation) {
// ensure that Paper will not be checking
setValue(packetListener, ClassNames.PAPER_DISABLE_USERNAME_VALIDATION, true);
if (proxyData) {
@@ -168,6 +182,8 @@ public final class SpigotDataHandler extends CommonDataHandler {
ClassNames.LOGIN_HANDLER_CONSTRUCTOR.newInstance(packetListener);
ClassNames.FIRE_LOGIN_EVENTS.invoke(loginHandler);
logger.info("removing self ({})", ctx.channel().id());
ctx.pipeline().remove(this);
return true;
}