From 771ea02281d889a6cbaf55327f80fa0d96c251ee Mon Sep 17 00:00:00 2001 From: Aizistral Date: Fri, 1 Jul 2022 17:15:31 +0200 Subject: Final adjustments for release --- .../java/com/aizistral/nochatreports/NoChatReportsClient.java | 10 +++++----- .../com/aizistral/nochatreports/core/ServerSafetyState.java | 7 ++++++- .../com/aizistral/nochatreports/mixins/MixinConnectScreen.java | 2 ++ .../com/aizistral/nochatreports/mixins/MixinLocalPlayer.java | 9 +++++++-- .../com/aizistral/nochatreports/mixins/MixinMinecraft.java | 1 + .../com/aizistral/nochatreports/mixins/MixinPlayerEntry.java | 4 +++- .../com/aizistral/nochatreports/mixins/MixinTitleScreen.java | 2 +- src/main/resources/assets/nochatreports/lang/en_us.json | 4 ++-- src/main/resources/fabric.mod.json | 2 +- 9 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java index faac288..1586756 100644 --- a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java +++ b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java @@ -44,6 +44,7 @@ public class NoChatReportsClient implements ClientModInitializer { NoChatReports.LOGGER.info("Client initialization..."); ClientPlayNetworking.registerGlobalReceiver(NoChatReports.CHANNEL, ClientChannelHandler.INSTANCE); ClientPlayConnectionEvents.JOIN.register(this::onPlayReady); + ClientPlayConnectionEvents.DISCONNECT.register(this::onDisconnect); ScreenEvents.AFTER_INIT.register(this::onScreenInit); } @@ -55,7 +56,6 @@ public class NoChatReportsClient implements ClientModInitializer { if (dsc.getReason().getContents() instanceof TranslatableContents contents) { if (ServerSafetyState.allowsUnsafeServer()) { screenOverride = true; - ServerSafetyState.setAllowsUnsafeServer(false); screen = new DisconnectedScreen(new JoinMultiplayerScreen(new TitleScreen()), CommonComponents.CONNECT_FAILED, dsc.getReason()); client.setScreen(screen); @@ -70,6 +70,10 @@ public class NoChatReportsClient implements ClientModInitializer { } } + private void onDisconnect(ClientPacketListener handler, Minecraft client) { + client.execute(ServerSafetyState::reset); + } + private void onPlayReady(ClientPacketListener handler, PacketSender sender, Minecraft client) { client.execute(() -> { if (!client.isLocalServer()) { @@ -89,10 +93,6 @@ public class NoChatReportsClient implements ClientModInitializer { // NO-OP } } - - if (ServerSafetyState.allowsUnsafeServer()) { - ServerSafetyState.setAllowsUnsafeServer(false); - } } if (NoReportsConfig.demandsOnServer() && !ClientPlayNetworking.canSend(NoChatReports.CHANNEL)) { diff --git a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java index 2dff0e4..8fbe357 100644 --- a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java +++ b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java @@ -22,7 +22,7 @@ public class ServerSafetyState { } public static boolean allowsUnsafeServer() { - return allowUnsafeServer; + return current != ServerSafetyLevel.SECURE ? allowUnsafeServer : false; } public static void setAllowsUnsafeServer(boolean allows) { @@ -38,4 +38,9 @@ public class ServerSafetyState { lastConnectedServer = address; } + public static void reset() { + current = ServerSafetyLevel.UNKNOWN; + allowUnsafeServer = false; + } + } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinConnectScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinConnectScreen.java index 628e3e8..a850aed 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinConnectScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinConnectScreen.java @@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.aizistral.nochatreports.core.NoReportsConfig; +import com.aizistral.nochatreports.core.ServerSafetyLevel; import com.aizistral.nochatreports.core.ServerSafetyState; import net.minecraft.client.Minecraft; @@ -21,6 +22,7 @@ public class MixinConnectScreen { @Inject(method = "startConnecting", at = @At("HEAD")) private static void onStartConnecting(Screen screen, Minecraft minecraft, ServerAddress serverAddress, @Nullable ServerData serverData, CallbackInfo info) { + ServerSafetyState.reset(); // just to be 100% sure ServerSafetyState.setLastConnectedServer(serverAddress); if (serverAddress != null) diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinLocalPlayer.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinLocalPlayer.java index 2533fe5..2fa727f 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinLocalPlayer.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinLocalPlayer.java @@ -1,5 +1,6 @@ package com.aizistral.nochatreports.mixins; +import com.aizistral.nochatreports.core.ServerSafetyState; import com.mojang.brigadier.ParseResults; import net.minecraft.client.player.LocalPlayer; import net.minecraft.commands.SharedSuggestionProvider; @@ -26,7 +27,9 @@ public class MixinLocalPlayer { @Inject(method = "signMessage", at = @At("HEAD"), cancellable = true) private void onSignMessage(MessageSigner signer, Component message, CallbackInfoReturnable info) { - info.setReturnValue(MessageSignature.unsigned()); + if (!ServerSafetyState.allowsUnsafeServer()) { + info.setReturnValue(MessageSignature.unsigned()); + } } /** @@ -37,7 +40,9 @@ public class MixinLocalPlayer { @Inject(method = "signCommandArguments", at = @At("HEAD"), cancellable = true) private void onSignCommand(MessageSigner signer, ParseResults results, @Nullable Component component, CallbackInfoReturnable info) { - info.setReturnValue(ArgumentSignatures.empty()); + if (!ServerSafetyState.allowsUnsafeServer()) { + info.setReturnValue(ArgumentSignatures.empty()); + } } } diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinMinecraft.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinMinecraft.java index 547a6ad..a4bc7a3 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinMinecraft.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinMinecraft.java @@ -13,6 +13,7 @@ import com.aizistral.nochatreports.core.NoReportsConfig; import com.mojang.authlib.minecraft.BanDetails; import com.mojang.authlib.minecraft.UserApiService; +import net.fabricmc.fabric.mixin.client.rendering.MixinInGameHud; import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft.ChatStatus; import net.minecraft.world.entity.player.ChatVisiblity; diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayerEntry.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayerEntry.java index b50ce21..4b7a5eb 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayerEntry.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinPlayerEntry.java @@ -12,6 +12,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.aizistral.nochatreports.core.ServerSafetyLevel; +import com.aizistral.nochatreports.core.ServerSafetyState; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; @@ -44,7 +46,7 @@ public class MixinPlayerEntry { @Inject(method = "", at = @At("RETURN")) private void onConstructed(Minecraft minecraft, SocialInteractionsScreen socialInteractionsScreen, UUID uUID, String string, Supplier supplier, CallbackInfo info) { - if (this.reportButton != null) { + if (ServerSafetyState.getCurrent() == ServerSafetyLevel.SECURE && this.reportButton != null) { this.reportButton = new ImageButton(0, 0, 20, 20, 0, 0, 20, REPORT_BUTTON_LOCATION, 64, 64, button -> {}, new Button.OnTooltip() { @Override public void onTooltip(Button button, PoseStack poseStack, int i, int j) { diff --git a/src/main/java/com/aizistral/nochatreports/mixins/MixinTitleScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/MixinTitleScreen.java index dcebc92..e514d83 100644 --- a/src/main/java/com/aizistral/nochatreports/mixins/MixinTitleScreen.java +++ b/src/main/java/com/aizistral/nochatreports/mixins/MixinTitleScreen.java @@ -12,7 +12,7 @@ import net.minecraft.client.gui.screens.TitleScreen; @Mixin(TitleScreen.class) public class MixinTitleScreen { - @Redirect(method = "render", at = @At(value = "INVOKE", remap = false, target = + @Redirect(method = "render", at = @At(value = "INVOKE", remap = true, target = "Lnet/minecraft/WorldVersion;getName()Ljava/lang/String;"), require = 0) private String onGetVersionName(WorldVersion version) { String original = version.getName(); diff --git a/src/main/resources/assets/nochatreports/lang/en_us.json b/src/main/resources/assets/nochatreports/lang/en_us.json index 692b817..028234f 100644 --- a/src/main/resources/assets/nochatreports/lang/en_us.json +++ b/src/main/resources/assets/nochatreports/lang/en_us.json @@ -4,9 +4,9 @@ "disconnect.nochatreports.client": "This server does not have No Chat Reports, and you have it configured to require itself on server.", "gui.nochatreports.status_secure": "This server has No Chat Reports installed, or prevents your messages from being reportable in some other known way. You can chat safely.", "gui.nochatreports.status_unintrusive": "This server does not prevent chat reports, but allows you to send usigned messages. Technically they can still be reported to Mojang, but they are generally not a valid evidence, and it is improbable that any action would be taken on such reports.", - "gui.nochatreports.status_insecure": "This server demands all player messages to be signed, and you agreed to proceed with this arrangement. Everything you send in the chat is a potentially incriminating evidence that can be used against you in report. You can manually remove this server from NoChatReports.json in your config folder to get warned again.", + "gui.nochatreports.status_insecure": "This server demands all player messages to be signed, and you agreed to proceed with this arrangement. Everything you send in the chat is a potentially incriminating evidence that can be used against you in the report. You can manually remove this server from NoChatReports.json in your config folder to get warned again.", "gui.nochatreports.status_unknown": "No Chat Reports could not evaluate the safety of this server. This should never happen, please report it as a bug to the mod developer.", "gui.nochatreports.unsafe_server.header": "Caution: Unsafe Server", - "gui.nochatreports.unsafe_server.contents": "This server requires all chat messages to be signed, so they can be reported to Mojang. This likely means that the server kept 'enforce-secure-profile' enabled on server.properties, which is the default since 1.19.1. You can choose to play anyway, but No Chat Reports will not be able to protect you.", + "gui.nochatreports.unsafe_server.contents": "This server requires all chat messages to be signed, which means they can be reported to Mojang. This likely means that the server owner kept 'enforce-secure-profile' enabled on server.properties, which is the default since 1.19.1. You can choose to play anyway, but No Chat Reports will not be able to protect you.", "gui.nochatreports.unsafe_server.check": "Do not show again for this server" } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4d06ffd..8ef116b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -32,7 +32,7 @@ "depends": { "fabricloader": ">=0.14.6", "fabric": "*", - "minecraft": "~1.19", + "minecraft": "=1.19.1-beta.2", "java": ">=17" }, "suggests": {} -- cgit v1.2.3