Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.destroystokyo.paper.ClientOption;
import org.bukkit.ServerLinks;
import org.bukkit.plugin.messaging.PluginMessageRecipient;
import org.jspecify.annotations.Nullable;

/**
* Represents a connection that has properties shared between the GAME and CONFIG stage.
Expand Down Expand Up @@ -43,4 +44,13 @@ public interface PlayerCommonConnection extends WritablePlayerCookieConnection,
* @return the client option value of the player
*/
<T> T getClientOption(ClientOption<T> type);

/**
* Returns player's client brand name. If the client didn't send this information, the brand name will be null.
* <p>
* For the Notchian client this name defaults to {@code vanilla}. Some modified clients report other names such as {@code neoforge}.
*
* @return client brand name
*/
@Nullable String getClientBrandName();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.papermc.paper.connection;

import com.destroystokyo.paper.ClientOption;
import com.destroystokyo.paper.profile.PlayerProfile;
import net.kyori.adventure.audience.Audience;

Expand Down
12 changes: 6 additions & 6 deletions paper-api/src/main/java/org/bukkit/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3776,15 +3776,15 @@ public int getPing() {
// Paper end
}

// Paper start - brand support
/**
* Returns player's client brand name. If the client didn't send this information, the brand name will be null.<br>
* For the Notchian client this name defaults to <code>vanilla</code>. Some modified clients report other names such as <code>forge</code>.<br>
* Returns player's client brand name. If the client didn't send this information, the brand name will be null.
* <p>
* For the Notchian client this name defaults to {@code vanilla}. Some modified clients report other names such as {@code neoforge}.
*
* @return client brand name
* @see io.papermc.paper.connection.PlayerCommonConnection#getClientBrandName()
*/
@Nullable
String getClientBrandName();
// Paper end
@Nullable String getClientBrandName();

// Paper start - Teleport API
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,22 @@ index 0000000000000000000000000000000000000000..66d6af2833d76af28fbeb2ce70c194a5
+ }
+}
diff --git a/net/minecraft/server/network/CommonListenerCookie.java b/net/minecraft/server/network/CommonListenerCookie.java
index d87a00ee3cd04ce25dbe46ae6b386b7f0799102c..ace440c2b82a6368aa27a85ff433ba2cbc8f39a5 100644
index 021c2b0d4d8b55cb74b16a1210535e97576a83f1..da63706a8199ecfa9cd9de87bef20c8d1898a950 100644
--- a/net/minecraft/server/network/CommonListenerCookie.java
+++ b/net/minecraft/server/network/CommonListenerCookie.java
@@ -3,8 +3,8 @@ package net.minecraft.server.network;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.level.ClientInformation;

-public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @org.jspecify.annotations.Nullable String brandName, java.util.Set<String> channels) { // Paper
+public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @org.jspecify.annotations.Nullable String brandName, java.util.Set<String> channels, io.papermc.paper.util.KeepAlive keepAlive) { // Paper // Paper
-public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @org.jspecify.annotations.Nullable String clientBrand, java.util.Set<String> channels) { // Paper
+public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @org.jspecify.annotations.Nullable String clientBrand, java.util.Set<String> channels, io.papermc.paper.util.KeepAlive keepAlive) { // Paper // Paper
public static CommonListenerCookie createInitial(final GameProfile gameProfile, final boolean transferred) {
- return new CommonListenerCookie(gameProfile, 0, ClientInformation.createDefault(), transferred, null, new java.util.HashSet<>()); // Paper
+ return new CommonListenerCookie(gameProfile, 0, ClientInformation.createDefault(), transferred, null, new java.util.HashSet<>(), new io.papermc.paper.util.KeepAlive()); // Paper // Paper
}
}
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index f9be3e8cbc05fe74ac7816f8b2d81d52f6f23e40..8b194a59f79eea32c9e7a46227034942f6a6e816 100644
index 71156340713bbc95c2caf839dc2e75b4467a2f0c..bdf98fedaa168732e0477ec5b3a16f935ce3d015 100644
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -39,12 +39,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
Expand Down Expand Up @@ -147,7 +147,7 @@ index f9be3e8cbc05fe74ac7816f8b2d81d52f6f23e40..8b194a59f79eea32c9e7a46227034942
this.latency = cookie.latency();
this.transferred = cookie.transferred();
// Paper start
this.playerBrand = cookie.brandName();
this.clientBrand = cookie.clientBrand();
this.cserver = server.server;
this.pluginMessagerChannels = cookie.channels();
+ this.keepAlive = cookie.keepAlive();
Expand Down Expand Up @@ -238,14 +238,14 @@ index f9be3e8cbc05fe74ac7816f8b2d81d52f6f23e40..8b194a59f79eea32c9e7a46227034942
}

protected CommonListenerCookie createCookie(final ClientInformation clientInformation) {
- return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels); // Paper
- return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.clientBrand, this.pluginMessagerChannels); // Paper
+ // Paper start - listener handoff should reset pending keepalive expectations
+ return new CommonListenerCookie(
+ this.playerProfile(),
+ this.latency,
+ clientInformation,
+ this.transferred,
+ this.playerBrand,
+ this.clientBrand,
+ this.pluginMessagerChannels,
+ this.keepAlive.copyForListenerHandoff()
+ );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.server.level.ClientInformation;

-public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred) {
+public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @org.jspecify.annotations.Nullable String brandName, java.util.Set<String> channels) { // Paper
+public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @org.jspecify.annotations.Nullable String clientBrand, java.util.Set<String> channels) { // Paper
public static CommonListenerCookie createInitial(final GameProfile gameProfile, final boolean transferred) {
- return new CommonListenerCookie(gameProfile, 0, ClientInformation.createDefault(), transferred);
+ return new CommonListenerCookie(gameProfile, 0, ClientInformation.createDefault(), transferred, null, new java.util.HashSet<>()); // Paper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
+ private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
+ protected static final net.minecraft.resources.Identifier MINECRAFT_BRAND = net.minecraft.resources.Identifier.withDefaultNamespace("brand"); // Paper - Brand support
+ // Paper start - retain certain values
+ public @Nullable String playerBrand;
+ public @Nullable String clientBrand;
+ public final java.util.Set<String> pluginMessagerChannels;
+ // Paper end - retain certain values

Expand All @@ -31,7 +31,7 @@
this.latency = cookie.latency();
this.transferred = cookie.transferred();
+ // Paper start
+ this.playerBrand = cookie.brandName();
+ this.clientBrand = cookie.clientBrand();
+ this.cserver = server.server;
+ this.pluginMessagerChannels = cookie.channels();
+ // Paper end
Expand Down Expand Up @@ -95,13 +95,13 @@
+ }
+
+ if (identifier.equals(MINECRAFT_BRAND)) {
+ this.playerBrand = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.wrappedBuffer(data)).readUtf(256);
+ this.clientBrand = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.wrappedBuffer(data)).readUtf(256);
+ }
+
+ this.cserver.getMessenger().dispatchIncomingMessage(paperConnection(), identifier.toString(), data);
+ } catch (final Exception e) {
+ LOGGER.error("Couldn't handle custom payload on channel {}", identifier, e);
+ this.disconnect(net.minecraft.network.chat.Component.literal("Invalid custom payload payload!"), io.papermc.paper.connection.DisconnectionReason.INVALID_PAYLOAD); // Paper - kick event cause
+ this.disconnect(Component.literal("Invalid custom payload payload!"), io.papermc.paper.connection.DisconnectionReason.INVALID_PAYLOAD); // Paper - kick event cause
+ }
+ }
+
Expand Down Expand Up @@ -335,6 +335,6 @@

protected CommonListenerCookie createCookie(final ClientInformation clientInformation) {
- return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred);
+ return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels); // Paper
+ return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.clientBrand, this.pluginMessagerChannels); // Paper
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public <T> T getClientOption(ClientOption<T> type) {
throw new RuntimeException("Unknown settings type");
}

@Override
public @Nullable String getClientBrandName() {
return this.packetListener.clientBrand;
}

@Override
public void disconnect(final Component component) {
this.packetListener.disconnect(PaperAdventure.asVanilla(component), DisconnectionReason.UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

public class PaperPlayerGameConnection extends PaperCommonConnection<ServerGamePacketListenerImpl> implements PlayerGameConnection {

public PaperPlayerGameConnection(final ServerGamePacketListenerImpl serverConfigurationPacketListenerImpl) {
super(serverConfigurationPacketListenerImpl);
public PaperPlayerGameConnection(final ServerGamePacketListenerImpl packetListener) {
super(packetListener);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
import net.minecraft.world.level.storage.ValueOutput;
import org.bukkit.BanEntry;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Effect;
import org.bukkit.EntityEffect;
Expand Down Expand Up @@ -188,7 +187,6 @@
import org.bukkit.craftbukkit.conversations.ConversationTracker;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftRecipe;
import org.bukkit.craftbukkit.map.CraftMapCursor;
import org.bukkit.craftbukkit.map.CraftMapView;
import org.bukkit.craftbukkit.map.RenderData;
Expand Down Expand Up @@ -3097,12 +3095,13 @@ public int getPing() {
// Paper end
};

// Paper start - brand support
@Override
public String getClientBrandName() {
return getHandle().connection.playerBrand;
if (this.getHandle().connection == null) {
return null;
}
return this.getHandle().connection.clientBrand;
}
// Paper end

// Paper start
@Override
Expand Down
Loading