aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0799-Prevent-causing-expired-keys-from-impacting-new-join.patch
blob: 0ee423dac7b910c5ad04b66f42cba4892acf0363 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Mon, 3 Apr 2023 08:55:52 +0100
Subject: [PATCH] Prevent causing expired keys from impacting new joins


diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
index d0b2a8b5ded71a9a41753f4addea1c49826b34a3..29b465fc1dc50e0e84ddb889c5303e80fe662874 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
@@ -114,7 +114,15 @@ public class ClientboundPlayerInfoUpdatePacket implements Packet<ClientGamePacke
         }),
         INITIALIZE_CHAT(
             (serialized, buf) -> serialized.chatSession = buf.readNullable(RemoteChatSession.Data::read),
-            (buf, entry) -> buf.writeNullable(entry.chatSession, RemoteChatSession.Data::write)
+            // Paper start - Prevent causing expired keys from impacting new joins
+            (buf, entry) -> {
+                RemoteChatSession.Data chatSession = entry.chatSession;
+                if (chatSession != null && chatSession.profilePublicKey().hasExpired()) {
+                    chatSession = null;
+                }
+                buf.writeNullable(chatSession, RemoteChatSession.Data::write);
+            }
+            // Paper end - Prevent causing expired keys from impacting new joins
         ),
         UPDATE_GAME_MODE((serialized, buf) -> serialized.gameMode = GameType.byId(buf.readVarInt()), (buf, entry) -> buf.writeVarInt(entry.gameMode().getId())),
         UPDATE_LISTED((serialized, buf) -> serialized.listed = buf.readBoolean(), (buf, entry) -> buf.writeBoolean(entry.listed())),
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 2edf9a3c4ce5d2feaac624c969c2711dfc2dc4f7..e653dc4ac16fd22674a6c1ba402f8913e0fbb336 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -305,6 +305,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
     private boolean receivedMovementThisTick;
     @Nullable
     private RemoteChatSession chatSession;
+    private boolean hasLoggedExpiry = false; // Paper - Prevent causing expired keys from impacting new joins
     private SignedMessageChain.Decoder signedMessageDecoder;
     private final LastSeenMessagesValidator lastSeenMessages = new LastSeenMessagesValidator(20);
     private final MessageSignatureCache messageSignatureCache = MessageSignatureCache.createDefault();
@@ -401,6 +402,13 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
             this.disconnect((Component) Component.translatable("multiplayer.disconnect.idling"), org.bukkit.event.player.PlayerKickEvent.Cause.IDLING); // Paper - kick event cause
         }
 
+        // Paper start - Prevent causing expired keys from impacting new joins
+        if (!hasLoggedExpiry && this.chatSession != null && this.chatSession.profilePublicKey().data().hasExpired()) {
+            LOGGER.info("Player profile key for {} has expired!", this.player.getName().getString());
+            hasLoggedExpiry = true;
+        }
+        // Paper end - Prevent causing expired keys from impacting new joins
+
     }
 
     private int getMaximumFlyingTicks(Entity vehicle) {
@@ -3485,6 +3493,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
 
     private void resetPlayerChatState(RemoteChatSession session) {
         this.chatSession = session;
+        this.hasLoggedExpiry = false; // Paper - Prevent causing expired keys from impacting new joins
         this.signedMessageDecoder = session.createMessageDecoder(this.player.getUUID());
         this.chatMessageChain.append(() -> {
             this.player.setChatSession(session);