summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/aizistral/nochatreports/config/NoReportsConfig.java15
-rw-r--r--src/main/java/com/aizistral/nochatreports/core/ServerDataExtension.java23
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java2
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java2
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerData.java44
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java41
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatus.java (renamed from src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerStatus.java)29
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatusSerializer.java51
-rw-r--r--src/main/resources/nochatreports.mixins.json7
9 files changed, 206 insertions, 8 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/config/NoReportsConfig.java b/src/main/java/com/aizistral/nochatreports/config/NoReportsConfig.java
index 90059c1..fd60e10 100644
--- a/src/main/java/com/aizistral/nochatreports/config/NoReportsConfig.java
+++ b/src/main/java/com/aizistral/nochatreports/config/NoReportsConfig.java
@@ -44,7 +44,7 @@ public class NoReportsConfig {
convertToGameMessage = false, showServerSafety = true, hideRedChatIndicators = true,
hideYellowChatIndicators = true, hideGrayChatIndicators = true, hideWarningToast = true,
alwaysHideReportButton = false, disableTelemetry = true, showReloadButton = true,
- whitelistAllServers = false;
+ whitelistAllServers = false, addQueryData = true;
protected List<String> whitelistedServers;
protected static NoReportsConfig getInstance() {
@@ -233,7 +233,7 @@ public class NoReportsConfig {
* This is false by default.
*/
- public static boolean isDebugLogEnabled() {
+ public static boolean enableDebugLog() {
return getInstance().enableDebugLog;
}
@@ -281,4 +281,15 @@ public class NoReportsConfig {
return getInstance().whitelistAllServers;
}
+ /**
+ * @return True if server should include extra query data to help clients know that your server
+ * is secure.<br><br>
+ *
+ * This is true by default.
+ */
+
+ public static boolean addQueryData() {
+ return getInstance().addQueryData;
+ }
+
}
diff --git a/src/main/java/com/aizistral/nochatreports/core/ServerDataExtension.java b/src/main/java/com/aizistral/nochatreports/core/ServerDataExtension.java
new file mode 100644
index 0000000..a92ea52
--- /dev/null
+++ b/src/main/java/com/aizistral/nochatreports/core/ServerDataExtension.java
@@ -0,0 +1,23 @@
+package com.aizistral.nochatreports.core;
+
+import com.aizistral.nochatreports.mixins.client.MixinServerData;
+import com.aizistral.nochatreports.mixins.common.MixinServerStatus;
+
+import net.minecraft.client.multiplayer.ServerData;
+import net.minecraft.network.protocol.status.ServerStatus;
+
+/**
+ * Implemented by {@link MixinServerStatus} on {@link ServerStatus} class and {@link MixinServerData}
+ * on {@link ServerData} class.
+ *
+ * @author fxmorin (original implementation)
+ * @author Aizistral (current version)
+ */
+
+public interface ServerDataExtension {
+
+ public boolean preventsChatReports();
+
+ public void setPreventsChatReports(boolean prevents);
+
+} \ No newline at end of file
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
index 331c4b5..0c767af 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
@@ -58,7 +58,7 @@ public class MixinChatListener {
}
// Debug never dies
- if (NoReportsConfig.isDebugLogEnabled()) {
+ if (NoReportsConfig.enableDebugLog()) {
NoChatReports.LOGGER.info("Received message: {}, from: {}, signature: {}",
Component.Serializer.toStableJson(playerChatMessage.serverContent()),
playerChatMessage.signer().profileId(),
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java
index 5e8e1ac..36cca0b 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java
@@ -32,7 +32,7 @@ public class MixinConnectScreen {
ServerSafetyState.updateCurrent(ServerSafetyLevel.UNKNOWN); // just to be 100% sure
ServerSafetyState.setLastConnectedServer(serverAddress, serverData);
- if (NoReportsConfig.isDebugLogEnabled()) {
+ if (NoReportsConfig.enableDebugLog()) {
NoChatReports.LOGGER.info("Connecting to: {}, will expose public key: {}",
serverAddress.getHost() + ":" + serverAddress.getPort(),
ServerSafetyState.allowsUnsafeServer());
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerData.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerData.java
new file mode 100644
index 0000000..761ba2c
--- /dev/null
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerData.java
@@ -0,0 +1,44 @@
+package com.aizistral.nochatreports.mixins.client;
+
+import com.aizistral.nochatreports.core.ServerDataExtension;
+import net.minecraft.client.multiplayer.ServerData;
+import net.minecraft.nbt.CompoundTag;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
+
+/**
+ * Adds "preventsChatReports" property to {@link ServerData} and handles it during serialization to
+ * and deserialization from NBT-tag.
+ *
+ * @author fxmorin (original implementation)
+ * @author Aizistral (current version)
+ */
+
+@Mixin(ServerData.class)
+public class MixinServerData implements ServerDataExtension {
+ private boolean preventsChatReports;
+
+ @Override
+ public boolean preventsChatReports() {
+ return this.preventsChatReports;
+ }
+
+ @Override
+ public void setPreventsChatReports(boolean prevents) {
+ this.preventsChatReports = prevents;
+ }
+
+ @Inject(method = "write", at = @At("RETURN"))
+ private void onWrite(CallbackInfoReturnable<CompoundTag> info) {
+ info.getReturnValue().putBoolean("preventsChatReports", this.preventsChatReports);
+ }
+
+ @Inject(method = "read", locals = LocalCapture.CAPTURE_FAILSOFT, at = @At("RETURN"))
+ private static void onRead(CompoundTag tag, CallbackInfoReturnable<ServerData> info, ServerData data) {
+ ((ServerDataExtension)data).setPreventsChatReports(tag.getBoolean("preventsChatReports"));
+ }
+
+}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java
new file mode 100644
index 0000000..69e8251
--- /dev/null
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinServerStatusPinger$1.java
@@ -0,0 +1,41 @@
+package com.aizistral.nochatreports.mixins.client;
+
+import com.aizistral.nochatreports.NoChatReports;
+import com.aizistral.nochatreports.config.NoReportsConfig;
+import com.aizistral.nochatreports.core.ServerDataExtension;
+import net.minecraft.client.multiplayer.ServerData;
+import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
+import net.minecraft.network.protocol.status.ServerStatus;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(targets = "net/minecraft/client/multiplayer/ServerStatusPinger$1")
+public class MixinServerStatusPinger$1 {
+ @Shadow @Final
+ private ServerData val$data;
+
+ /**
+ * @reason Ensure "preventsChatReports" property is transferred from {@link ServerStatus} to
+ * {@link ServerData} when handling status response.
+ * @author fxmorin (original implementation)
+ * @author Aizistral (current version)
+ */
+
+ @Inject(method = "handleStatusResponse(Lnet/minecraft/network/protocol/status/ClientboundStatusResponsePacket;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/status/ServerStatus;getPlayers()Lnet/minecraft/network/protocol/status/ServerStatus$Players;", ordinal = 0, shift = At.Shift.BEFORE))
+ private void getNoChatReports(ClientboundStatusResponsePacket packet, CallbackInfo info) {
+ boolean preventsReports = ((ServerDataExtension) packet.getStatus()).preventsChatReports();
+ ((ServerDataExtension) this.val$data).setPreventsChatReports(preventsReports);
+
+ if (NoReportsConfig.enableDebugLog()) {
+ NoChatReports.LOGGER.info("Received status response packet from server, preventsChatReports: {}",
+ preventsReports);
+ }
+
+ }
+
+}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerStatus.java b/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatus.java
index 125f7ce..98a9d3d 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerStatus.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatus.java
@@ -1,4 +1,4 @@
-package com.aizistral.nochatreports.mixins.server;
+package com.aizistral.nochatreports.mixins.common;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.aizistral.nochatreports.config.NoReportsConfig;
+import com.aizistral.nochatreports.core.ServerDataExtension;
import net.minecraft.network.protocol.game.ClientboundServerDataPacket;
import net.minecraft.network.protocol.status.ServerStatus;
@@ -15,7 +16,21 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
@Mixin(ServerStatus.class)
-public class MixinServerStatus {
+public class MixinServerStatus implements ServerDataExtension {
+
+ /**
+ * Special additional variable that allows the client to know whether server prevents chat reports
+ * upon pinging it.
+ */
+
+ private boolean preventsChatReports;
+
+ /**
+ * @reason Spoof the value of "enforcesSecureChat" in case conversion to system messages is enabled.
+ * There is no way for client to verify the value of the option in such case, so that's one less
+ * annoying warning.
+ * @author Aizistral
+ */
@Inject(method = "enforcesSecureChat", at = @At("HEAD"), cancellable = true)
public void onSecureChatCheck(CallbackInfoReturnable<Boolean> info) {
@@ -24,4 +39,14 @@ public class MixinServerStatus {
}
}
+ @Override
+ public boolean preventsChatReports() {
+ return this.preventsChatReports;
+ }
+
+ @Override
+ public void setPreventsChatReports(boolean prevents) {
+ this.preventsChatReports = prevents;
+ }
+
}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatusSerializer.java b/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatusSerializer.java
new file mode 100644
index 0000000..acc710f
--- /dev/null
+++ b/src/main/java/com/aizistral/nochatreports/mixins/common/MixinServerStatusSerializer.java
@@ -0,0 +1,51 @@
+package com.aizistral.nochatreports.mixins.common;
+
+import com.aizistral.nochatreports.config.NoReportsConfig;
+import com.aizistral.nochatreports.core.ServerDataExtension;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonSerializationContext;
+import net.minecraft.network.protocol.status.ServerStatus;
+import net.minecraft.util.GsonHelper;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
+import java.lang.reflect.Type;
+
+/**
+ * Handles "preventsChatReports" property during serialization and deserialization of {@link ServerStatus}.
+ *
+ * @author fxmorin (original implementation)
+ * @author Aizistral (current version)
+ */
+
+@Mixin(ServerStatus.Serializer.class)
+public class MixinServerStatusSerializer {
+
+ @Inject(method = "serialize(Lnet/minecraft/network/protocol/status/ServerStatus;" +
+ "Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement;",
+ at = @At("RETURN"))
+ private void onSerialize(ServerStatus serverStatus, Type type, JsonSerializationContext context,
+ CallbackInfoReturnable<JsonElement> info) {
+ if (!NoReportsConfig.addQueryData())
+ return;
+
+ ((JsonObject) info.getReturnValue()).addProperty("preventsChatReports", true);
+ }
+
+ @Inject(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;" +
+ "Lcom/google/gson/JsonDeserializationContext;)" +
+ "Lnet/minecraft/network/protocol/status/ServerStatus;",
+ locals = LocalCapture.CAPTURE_FAILSOFT, at = @At("RETURN"))
+ private void onDeserialize(JsonElement element, Type type, JsonDeserializationContext context,
+ CallbackInfoReturnable<ServerStatus> info, JsonObject json, ServerStatus status) {
+ if (!json.has("preventsChatReports"))
+ return;
+
+ ((ServerDataExtension) status).setPreventsChatReports(GsonHelper.getAsBoolean(json, "preventsChatReports"));
+ }
+
+}
diff --git a/src/main/resources/nochatreports.mixins.json b/src/main/resources/nochatreports.mixins.json
index 10f0fd2..c4f4fd0 100644
--- a/src/main/resources/nochatreports.mixins.json
+++ b/src/main/resources/nochatreports.mixins.json
@@ -5,10 +5,11 @@
"compatibilityLevel": "JAVA_17",
"verbose": true,
"mixins": [
+ "common.MixinServerStatus",
+ "common.MixinServerStatusSerializer",
"server.MixinPlayer",
"server.MixinServerboundChatPacket",
"server.MixinServerGamePacketListenerImpl",
- "server.MixinServerStatus",
"server.MixinPlayerList"
],
"client": [
@@ -26,7 +27,9 @@
"client.MixinJoinMultiplayerScreen",
"client.MixinGuiMessageTag",
"client.MixinToastComponent",
- "client.MixinRealmsConnect"
+ "client.MixinRealmsConnect",
+ "client.MixinServerData",
+ "client.MixinServerStatusPinger$1"
],
"server": [
"server.MixinDedicatedServer"