SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2024-08-24 07:51:55 +10:00
parent 84f1d558c3
commit 0916d51f5d
3 changed files with 36 additions and 26 deletions

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/LoginListener.java
+++ b/net/minecraft/server/network/LoginListener.java
@@ -44,8 +44,33 @@
@@ -44,8 +44,38 @@
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
@ -26,16 +26,21 @@
+ public EnumProtocol getProtocol() {
+ return EnumProtocol.LOGIN;
+ }
+
+ @Override
+ public void sendPacket(Packet<?> packet) {
+ this.connection.send(packet);
+ }
+ @Override
+ public void kickPlayer(IChatBaseComponent reason) {
+ disconnect(reason);
+ }
+ // CraftBukkit end
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
static final Logger LOGGER = LogUtils.getLogger();
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
@@ -60,6 +85,7 @@
@@ -60,6 +90,7 @@
private GameProfile authenticatedProfile;
private final String serverId;
private final boolean transferred;
@ -43,7 +48,7 @@
public LoginListener(MinecraftServer minecraftserver, NetworkManager networkmanager, boolean flag) {
this.state = LoginListener.EnumProtocolState.HELLO;
@@ -76,6 +102,12 @@
@@ -76,6 +107,12 @@
this.verifyLoginAndFinishConnectionSetup((GameProfile) Objects.requireNonNull(this.authenticatedProfile));
}
@ -56,7 +61,7 @@
if (this.state == LoginListener.EnumProtocolState.WAITING_FOR_DUPE_DISCONNECT && !this.isPlayerAlreadyInWorld((GameProfile) Objects.requireNonNull(this.authenticatedProfile))) {
this.finishLoginAndWaitForClient(this.authenticatedProfile);
}
@@ -86,6 +118,13 @@
@@ -86,6 +123,13 @@
}
@ -70,7 +75,7 @@
@Override
public boolean isAcceptingMessages() {
return this.connection.isConnected();
@@ -131,7 +170,27 @@
@@ -131,7 +175,27 @@
this.state = LoginListener.EnumProtocolState.KEY;
this.connection.send(new PacketLoginOutEncryptionBegin("", this.server.getKeyPair().getPublic().getEncoded(), this.challenge, true));
} else {
@ -99,7 +104,7 @@
}
}
@@ -144,10 +203,24 @@
@@ -144,10 +208,24 @@
private void verifyLoginAndFinishConnectionSetup(GameProfile gameprofile) {
PlayerList playerlist = this.server.getPlayerList();
@ -127,7 +132,7 @@
} else {
if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) {
this.connection.send(new PacketLoginOutSetCompression(this.server.getCompressionThreshold()), PacketSendListener.thenRun(() -> {
@@ -155,7 +228,7 @@
@@ -155,7 +233,7 @@
}));
}
@ -136,7 +141,7 @@
if (flag) {
this.state = LoginListener.EnumProtocolState.WAITING_FOR_DUPE_DISCONNECT;
@@ -205,6 +278,12 @@
@@ -205,6 +283,12 @@
if (profileresult != null) {
GameProfile gameprofile = profileresult.profile();
@ -149,7 +154,7 @@
LoginListener.LOGGER.info("UUID of player {} is {}", gameprofile.getName(), gameprofile.getId());
LoginListener.this.startClientVerification(gameprofile);
} else if (LoginListener.this.server.isSingleplayer()) {
@@ -222,6 +301,11 @@
@@ -222,6 +306,11 @@
LoginListener.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.authservers_down"));
LoginListener.LOGGER.error("Couldn't verify username because servers are unavailable");
}
@ -161,7 +166,7 @@
}
}
@@ -238,6 +322,43 @@
@@ -238,6 +327,43 @@
thread.start();
}
@ -205,7 +210,7 @@
@Override
public void handleCustomQueryPacket(ServerboundCustomQueryAnswerPacket serverboundcustomqueryanswerpacket) {
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
@@ -245,10 +366,11 @@
@@ -245,10 +371,11 @@
@Override
public void handleLoginAcknowledgement(ServerboundLoginAcknowledgedPacket serverboundloginacknowledgedpacket) {
@ -218,7 +223,7 @@
this.connection.setupInboundProtocol(ConfigurationProtocols.SERVERBOUND, serverconfigurationpacketlistenerimpl);
serverconfigurationpacketlistenerimpl.startConfiguration();
@@ -264,12 +386,18 @@
@@ -264,12 +391,18 @@
@Override
public void handleCookieResponse(ServerboundCookieResponsePacket serverboundcookieresponsepacket) {

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -28,8 +28,39 @@
@@ -28,8 +28,44 @@
import net.minecraft.util.thread.IAsyncTaskHandler;
import org.slf4j.Logger;
@ -20,14 +20,14 @@
+import org.bukkit.craftbukkit.util.Waitable;
+import org.bukkit.event.player.PlayerKickEvent;
+import org.bukkit.event.player.PlayerResourcePackStatusEvent;
+
+public abstract class ServerCommonPacketListenerImpl implements ServerCommonPacketListener, CraftPlayer.TransferCookieConnection {
+
+ @Override
+ public boolean isTransferred() {
+ return this.transferred;
+ }
+
+ @Override
+ public EnumProtocol getProtocol() {
+ return protocol();
@ -37,11 +37,16 @@
+ public void sendPacket(Packet<?> packet) {
+ send(packet);
+ }
+
+ @Override
+ public void kickPlayer(IChatBaseComponent reason) {
+ disconnect(reason);
+ }
+ // CraftBukkit end
private static final Logger LOGGER = LogUtils.getLogger();
public static final int LATENCY_CHECK_INTERVAL = 15000;
private static final int CLOSED_LISTENER_TIMEOUT = 15000;
@@ -46,12 +77,24 @@
@@ -46,12 +82,24 @@
private int latency;
private volatile boolean suspendFlushingOnServerThread = false;
@ -67,7 +72,7 @@
}
private void close() {
@@ -73,6 +116,7 @@
@@ -73,6 +121,7 @@
@Override
public void handleKeepAlive(ServerboundKeepAlivePacket serverboundkeepalivepacket) {
@ -75,7 +80,7 @@
if (this.keepAlivePending && serverboundkeepalivepacket.getId() == this.keepAliveChallenge) {
int i = (int) (SystemUtils.getMillis() - this.keepAliveTime);
@@ -87,8 +131,56 @@
@@ -87,8 +136,56 @@
@Override
public void handlePong(ServerboundPongPacket serverboundpongpacket) {}
@ -133,7 +138,7 @@
@Override
public void handleResourcePackResponse(ServerboundResourcePackPacket serverboundresourcepackpacket) {
@@ -97,11 +189,18 @@
@@ -97,11 +194,18 @@
ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), serverboundresourcepackpacket.id());
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.requiredTexturePrompt.disconnect"));
}
@ -152,7 +157,7 @@
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
}
@@ -109,7 +208,7 @@
@@ -109,7 +213,7 @@
this.server.getProfiler().push("keepAlive");
long i = SystemUtils.getMillis();
@ -161,7 +166,7 @@
if (this.keepAlivePending) {
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
} else if (this.checkIfClosed(i)) {
@@ -149,6 +248,14 @@
@@ -149,6 +253,14 @@
}
public void send(Packet<?> packet, @Nullable PacketSendListener packetsendlistener) {
@ -176,7 +181,7 @@
if (packet.isTerminal()) {
this.close();
}
@@ -173,15 +280,61 @@
@@ -173,15 +285,61 @@
}
public void disconnect(DisconnectionDetails disconnectiondetails) {

View file

@ -274,6 +274,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
EnumProtocol getProtocol();
void sendPacket(Packet<?> packet);
void kickPlayer(IChatBaseComponent reason);
}
public record CookieFuture(MinecraftKey key, CompletableFuture<byte[]> future) {
@ -477,9 +479,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public void kickPlayer(String message) {
if (getHandle().connection == null) return;
getHandle().connection.disconnect(CraftChatMessage.fromStringOrEmpty(message, true));
getHandle().transferCookieConnection.kickPlayer(CraftChatMessage.fromStringOrEmpty(message, true));
}
@Override