140 lines
8.0 KiB
Diff
140 lines
8.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: AlphaKR93 <dev@alpha93.kr>
|
|
Date: Sun, 26 Mar 2023 13:48:48 +0900
|
|
Subject: [PATCH] Implement No Chat Reports
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/FriendlyByteBuf.java b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
|
index 1f4b64a5f812376c499c98cb4be62469bd0b7dbe..c0bd2997fe3ebbfe926de832a36d209cc875f3e2 100644
|
|
--- a/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
|
+++ b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
|
@@ -147,18 +147,23 @@ public class FriendlyByteBuf extends ByteBuf {
|
|
public <T> T readJsonWithCodec(Codec<T> codec) {
|
|
JsonElement jsonelement = (JsonElement) GsonHelper.fromJson(FriendlyByteBuf.GSON, this.readUtf(), JsonElement.class);
|
|
DataResult<T> dataresult = codec.parse(JsonOps.INSTANCE, jsonelement);
|
|
-
|
|
- return Util.getOrThrow(dataresult, (s) -> {
|
|
- return new DecoderException("Failed to decode json: " + s);
|
|
- });
|
|
+ // Plazma start - NCR
|
|
+ T result = Util.getOrThrow(dataresult, (s) -> new DecoderException("Failed to decode json: " + s));
|
|
+ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().noChatReports.addQueryData() && jsonelement.getAsJsonObject().has("preventsChatReports"))
|
|
+ ((net.minecraft.network.protocol.status.ServerStatus) result).setPreventsChatReports(jsonelement.getAsJsonObject().get("preventsChatReports").getAsBoolean());
|
|
+ return result;
|
|
+ // Plazma end
|
|
}
|
|
|
|
public <T> void writeJsonWithCodec(Codec<T> codec, T value) {
|
|
DataResult<JsonElement> dataresult = codec.encodeStart(JsonOps.INSTANCE, value);
|
|
|
|
- this.writeUtf(FriendlyByteBuf.GSON.toJson((JsonElement) Util.getOrThrow(dataresult, (s) -> {
|
|
- return new EncoderException("Failed to encode: " + s + " " + value);
|
|
- })));
|
|
+ // Plazma start - NCR
|
|
+ JsonElement element = Util.getOrThrow(dataresult, (s) -> new EncoderException("Failed to encode: " + s + " " + value));
|
|
+ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().noChatReports.addQueryData() && codec == net.minecraft.network.protocol.status.ServerStatus.CODEC)
|
|
+ element.getAsJsonObject().addProperty("preventsChatReports", true);
|
|
+ this.writeUtf(FriendlyByteBuf.GSON.toJson(element));
|
|
+ // Plazma end
|
|
}
|
|
|
|
public <T> void writeId(IdMap<T> registry, T value) {
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/status/ServerStatus.java b/src/main/java/net/minecraft/network/protocol/status/ServerStatus.java
|
|
index 98ea56cbc8de5a5694b4f4d9a2f25811fdecba04..9e2a1f04cd9de2b0a7f3c512a4849a572d8fc00c 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/status/ServerStatus.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/status/ServerStatus.java
|
|
@@ -62,4 +62,21 @@ public record ServerStatus(Component description, Optional<ServerStatus.Players>
|
|
return new ServerStatus.Version(worldVersion.getName(), worldVersion.getProtocolVersion());
|
|
}
|
|
}
|
|
+
|
|
+ // Plazma start - NCR
|
|
+ public boolean enforcesSecureChat() {
|
|
+ return org.plazmamc.plazma.configurations.GlobalConfiguration.get().noChatReports.enabled || this.enforcesSecureChat;
|
|
+ }
|
|
+
|
|
+ private static boolean preventsChatReports;
|
|
+
|
|
+ public boolean preventsChatReports() {
|
|
+ if (this.version().isPresent() && this.version().get().protocol() < 759 && this.version().get().protocol() > 0) return true;
|
|
+ return this.preventsChatReports;
|
|
+ }
|
|
+
|
|
+ public void setPreventsChatReports(boolean prevents) {
|
|
+ this.preventsChatReports = prevents;
|
|
+ }
|
|
+ // Plazma end
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index 191bebab12c94756e9f98cfacbf06eb9a7c2f2f9..2d47c13f768ac482422e118921d186d3cfd5d765 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -684,7 +684,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
public boolean enforceSecureProfile() {
|
|
DedicatedServerProperties dedicatedserverproperties = this.getProperties();
|
|
|
|
- return dedicatedserverproperties.enforceSecureProfile && dedicatedserverproperties.onlineMode && this.services.profileKeySignatureValidator() != null;
|
|
+ return !org.plazmamc.plazma.configurations.GlobalConfiguration.get().noChatReports.enabled && dedicatedserverproperties.enforceSecureProfile && dedicatedserverproperties.onlineMode && this.services.profileKeySignatureValidator() != null; // Plazma - NCR // TODO: Check
|
|
}
|
|
|
|
protected boolean convertOldUsers() {
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 09183dbac0e8ca2cc2c8da57b105b80eab42d459..e4c92730b63204126609a52d286da46ef6495080 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2293,10 +2293,19 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
|
|
@Override
|
|
public void send(Packet<?> packet) {
|
|
+ // Plazma start - NCR
|
|
+ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().noChatReports.convertToGameMessage() && packet instanceof ClientboundPlayerChatPacket chat)
|
|
+ packet = new ClientboundSystemChatPacket(null, Component.Serializer.toJson(chat.chatType().resolve(this.player.level().registryAccess()).get().decorate(chat.unsignedContent() != null ? chat.unsignedContent() : Component.literal(chat.body().content()))), false);
|
|
this.send(packet, (PacketSendListener) null);
|
|
}
|
|
|
|
public void send(Packet<?> packet, @Nullable PacketSendListener callbacks) {
|
|
+ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().noChatReports.convertToGameMessage() && packet instanceof ClientboundPlayerChatPacket p && callbacks != null) {
|
|
+ this.send(p);
|
|
+ return;
|
|
+ }
|
|
+ // Plazma end
|
|
+
|
|
// CraftBukkit start
|
|
if (packet == null || this.processedDisconnect) { // Spigot
|
|
return;
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 86932974a9101779691de336a8c45c464158fca8..b711efca8a834adaf0db902fab34c3c80c9cbad6 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -1479,7 +1479,7 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
public boolean verifyChatTrusted(PlayerChatMessage message) { // Paper - private -> public
|
|
- return message.hasSignature() && !message.hasExpiredServer(Instant.now());
|
|
+ return org.plazmamc.plazma.configurations.GlobalConfiguration.get().noChatReports.enabled || (message.hasSignature() && !message.hasExpiredServer(Instant.now())); // Plazma - NCR
|
|
}
|
|
|
|
// CraftBukkit start
|
|
diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
index f67ac1a3dddb024af606da14b3929f10d8f22330..2033c7ff519e30f507e6535004687eb49c08c33b 100644
|
|
--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
+++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
@@ -49,7 +49,17 @@ public class GlobalConfiguration extends ConfigurationPart {
|
|
public NoChatReports noChatReports;
|
|
public class NoChatReports extends ConfigurationPart {
|
|
|
|
+ public boolean enabled = false;
|
|
+ boolean addQueryData = true;
|
|
+ boolean convertToGameMessage = true;
|
|
|
|
+ public boolean addQueryData() {
|
|
+ return enabled && addQueryData;
|
|
+ }
|
|
+
|
|
+ public boolean convertToGameMessage() {
|
|
+ return enabled && convertToGameMessage;
|
|
+ }
|
|
|
|
}
|
|
}
|