mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-06 15:51:31 +00:00
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2 since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList. Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2 lazy handles filter condition on iteration, so much better.
161 lines
10 KiB
Diff
161 lines
10 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: etil2jz <81570777+etil2jz@users.noreply.github.com>
|
|
Date: Tue, 2 Aug 2022 14:48:12 +0200
|
|
Subject: [PATCH] Mirai: Configurable chat message signatures
|
|
|
|
Fixed & Updated by Dreeam-qwq
|
|
Original license: GPLv3
|
|
Original project: https://github.com/Dreeam-qwq/Mirai
|
|
|
|
Original license: GPLv3
|
|
Original project: https://github.com/etil2jz/Mirai
|
|
|
|
diff --git a/net/minecraft/network/FriendlyByteBuf.java b/net/minecraft/network/FriendlyByteBuf.java
|
|
index bef92cfa7eb86fbc6bc1b7d862eaca575eeeadec..8817aee7eb61e130aacc4f0df980036b92500ad1 100644
|
|
--- a/net/minecraft/network/FriendlyByteBuf.java
|
|
+++ b/net/minecraft/network/FriendlyByteBuf.java
|
|
@@ -119,6 +119,17 @@ public class FriendlyByteBuf extends ByteBuf {
|
|
public <T> void writeJsonWithCodec(Codec<T> codec, T value, int maxLength) {
|
|
// Paper end - Adventure; add max length parameter
|
|
DataResult<JsonElement> dataResult = codec.encodeStart(JsonOps.INSTANCE, value);
|
|
+ // Leaf start - Configurable chat message signatures
|
|
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled && codec == net.minecraft.network.protocol.status.ServerStatus.CODEC) {
|
|
+ JsonElement element = dataResult.getOrThrow(string -> new EncoderException("Failed to encode: " + string + " " + value));
|
|
+
|
|
+ element.getAsJsonObject().addProperty("preventsChatReports", true);
|
|
+ this.writeUtf(GSON.toJson(element));
|
|
+
|
|
+ return;
|
|
+ }
|
|
+ // Leaf end - Configurable chat message signatures
|
|
+
|
|
this.writeUtf(GSON.toJson(dataResult.getOrThrow(exception -> new EncoderException("Failed to encode: " + exception + " " + value))), maxLength); // Paper - Adventure; add max length parameter
|
|
}
|
|
|
|
diff --git a/net/minecraft/network/protocol/game/ClientboundLoginPacket.java b/net/minecraft/network/protocol/game/ClientboundLoginPacket.java
|
|
index 89f06581e2b1f9f0240e7841db2f57dedc5d81b7..ba4ec05a9c9dfa958fdfa4a68ee85bcd9c379883 100644
|
|
--- a/net/minecraft/network/protocol/game/ClientboundLoginPacket.java
|
|
+++ b/net/minecraft/network/protocol/game/ClientboundLoginPacket.java
|
|
@@ -55,7 +55,7 @@ public record ClientboundLoginPacket(
|
|
buffer.writeBoolean(this.showDeathScreen);
|
|
buffer.writeBoolean(this.doLimitedCrafting);
|
|
this.commonPlayerSpawnInfo.write(buffer);
|
|
- buffer.writeBoolean(this.enforcesSecureChat);
|
|
+ buffer.writeBoolean(!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled || this.enforcesSecureChat); // Leaf - Mirai - Configurable chat message signatures
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/network/protocol/game/ServerboundChatPacket.java b/net/minecraft/network/protocol/game/ServerboundChatPacket.java
|
|
index b5afc05924ae899e020c303c8b86398e1d4ab8a0..73c2ed488c34cddbafdcbb6f2636264ebcc7286b 100644
|
|
--- a/net/minecraft/network/protocol/game/ServerboundChatPacket.java
|
|
+++ b/net/minecraft/network/protocol/game/ServerboundChatPacket.java
|
|
@@ -23,7 +23,7 @@ public record ServerboundChatPacket(String message, Instant timeStamp, long salt
|
|
buffer.writeUtf(this.message, 256);
|
|
buffer.writeInstant(this.timeStamp);
|
|
buffer.writeLong(this.salt);
|
|
- buffer.writeNullable(this.signature, MessageSignature::write);
|
|
+ if (org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) buffer.writeNullable(this.signature, MessageSignature::write); // Leaf - Mirai - Configurable chat message signatures
|
|
this.lastSeenMessages.write(buffer);
|
|
}
|
|
|
|
diff --git a/net/minecraft/network/protocol/status/ServerStatus.java b/net/minecraft/network/protocol/status/ServerStatus.java
|
|
index a491be4250de3199c3e1aa9e5482b568692bd2f5..5db038df25a1b5bf2f7395464250dc0bbf8d8241 100644
|
|
--- a/net/minecraft/network/protocol/status/ServerStatus.java
|
|
+++ b/net/minecraft/network/protocol/status/ServerStatus.java
|
|
@@ -23,7 +23,10 @@ public record ServerStatus(
|
|
boolean enforcesSecureChat
|
|
) {
|
|
public static final Codec<ServerStatus> CODEC = RecordCodecBuilder.create(
|
|
- instance -> instance.group(
|
|
+ // Leaf start - Mirai - Configurable chat message signatures
|
|
+ instance ->
|
|
+ org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled
|
|
+ ? instance.group(
|
|
ComponentSerialization.CODEC.lenientOptionalFieldOf("description", CommonComponents.EMPTY).forGetter(ServerStatus::description),
|
|
ServerStatus.Players.CODEC.lenientOptionalFieldOf("players").forGetter(ServerStatus::players),
|
|
ServerStatus.Version.CODEC.lenientOptionalFieldOf("version").forGetter(ServerStatus::version),
|
|
@@ -31,6 +34,15 @@ public record ServerStatus(
|
|
Codec.BOOL.lenientOptionalFieldOf("enforcesSecureChat", false).forGetter(ServerStatus::enforcesSecureChat)
|
|
)
|
|
.apply(instance, ServerStatus::new)
|
|
+ : instance.group(
|
|
+ ComponentSerialization.CODEC.lenientOptionalFieldOf("description", CommonComponents.EMPTY).forGetter(ServerStatus::description),
|
|
+ ServerStatus.Players.CODEC.lenientOptionalFieldOf("players").forGetter(ServerStatus::players),
|
|
+ ServerStatus.Version.CODEC.lenientOptionalFieldOf("version").forGetter(ServerStatus::version),
|
|
+ ServerStatus.Favicon.CODEC.lenientOptionalFieldOf("favicon").forGetter(ServerStatus::favicon),
|
|
+ Codec.BOOL.lenientOptionalFieldOf("enforcesSecureChat", false).forGetter(x -> true)
|
|
+ )
|
|
+ .apply(instance, ServerStatus::new)
|
|
+ // Leaf end- Mirai - Configurable chat message signatures
|
|
);
|
|
|
|
public record Favicon(byte[] iconBytes) {
|
|
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index 87fc8861948b50361ec04c5a23406d3abdec6eac..77f11179836636424927843f5f10c3fd23d2b2d4 100644
|
|
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -614,6 +614,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
|
|
@Override
|
|
public boolean enforceSecureProfile() {
|
|
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) return false; // Leaf - Mirai - Configurable chat message signatures
|
|
DedicatedServerProperties properties = this.getProperties();
|
|
// Paper start - Add setting for proxy online mode status
|
|
return properties.enforceSecureProfile
|
|
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
index fa6095200243fafa796e49df3930c6d7ab2dcd84..84030c40f2f91b433b3ccd21e0367d2f8b7c97b6 100644
|
|
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
@@ -363,10 +363,30 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
}
|
|
|
|
public void send(Packet<?> packet) {
|
|
+ // Leaf start - Mirai - Configurable chat message signatures
|
|
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) {
|
|
+ if (packet instanceof net.minecraft.network.protocol.game.ClientboundPlayerChatPacket chat) {
|
|
+ packet = new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(
|
|
+ chat.chatType().decorate(chat.unsignedContent() != null ? chat.unsignedContent() : Component.literal(chat.body().content())),
|
|
+ false
|
|
+ );
|
|
+ this.send(packet);
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Mirai - Configurable chat message signatures
|
|
this.send(packet, null);
|
|
}
|
|
|
|
public void send(Packet<?> packet, @Nullable ChannelFutureListener channelFutureListener) {
|
|
+ // Leaf start - Mirai - Configurable chat message signatures
|
|
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) {
|
|
+ if (packet instanceof net.minecraft.network.protocol.game.ClientboundPlayerChatPacket chat && channelFutureListener != null) {
|
|
+ this.send(chat);
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ // Leaf end - Mirai - Configurable chat message signatures
|
|
// CraftBukkit start
|
|
if (packet == null || this.processedDisconnect) { // Spigot
|
|
return;
|
|
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
|
index a332253d11564818a24d78e4dff262e55d7cc450..47d0af92cb0d744f4188597ad3f4b096aca84a9e 100644
|
|
--- a/net/minecraft/server/players/PlayerList.java
|
|
+++ b/net/minecraft/server/players/PlayerList.java
|
|
@@ -1505,7 +1505,7 @@ public abstract class PlayerList {
|
|
public void broadcastChatMessage(PlayerChatMessage message, Predicate<ServerPlayer> shouldFilterMessageTo, @Nullable ServerPlayer sender, ChatType.Bound boundChatType, @Nullable Function<net.kyori.adventure.audience.Audience, Component> unsignedFunction) {
|
|
// Paper end
|
|
boolean flag = this.verifyChatTrusted(message);
|
|
- this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), boundChatType, flag || !org.galemc.gale.configuration.GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker ? null : "Not Secure"); // Paper // Gale - do not log Not Secure marker
|
|
+ this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), boundChatType, !org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled || flag || !org.galemc.gale.configuration.GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker ? null : "Not Secure"); // Paper // Gale - do not log Not Secure marker // Leaf - Mirai - Configurable chat message signatures
|
|
OutgoingChatMessage outgoingChatMessage = OutgoingChatMessage.create(message);
|
|
boolean flag1 = false;
|
|
|
|
@@ -1530,6 +1530,7 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
public boolean verifyChatTrusted(PlayerChatMessage message) {
|
|
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) return true; // Leaf - Mirai - Configurable chat message signatures
|
|
return message.hasSignature() && !message.hasExpiredServer(Instant.now());
|
|
}
|
|
|