summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java58
-rw-r--r--src/main/java/com/aizistral/nochatreports/config/NCRServerWhitelist.java12
-rw-r--r--src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java3
-rw-r--r--src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java31
-rw-r--r--src/main/java/com/aizistral/nochatreports/gui/ExtendedWarningScreen.java32
-rw-r--r--src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java95
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java24
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java79
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java3
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinRealmsConnect.java2
-rw-r--r--src/main/resources/assets/nochatreports/lang/en_us.json36
-rw-r--r--src/main/resources/assets/nochatreports/textures/gui/chat_status_icons_extended.pngbin2329 -> 2331 bytes
-rw-r--r--src/main/resources/nochatreports.mixins.json3
13 files changed, 243 insertions, 135 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java
index 032af34..e3b671a 100644
--- a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java
+++ b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java
@@ -41,18 +41,6 @@ import net.minecraft.realms.RealmsScreen;
@Environment(EnvType.CLIENT)
public final class NoChatReportsClient implements ClientModInitializer {
- private static final List<String> KEY_DISCONNECT_REASONS = ImmutableList.of(
- "multiplayer.disconnect.missing_public_key",
- "multiplayer.disconnect.invalid_public_key_signature",
- "multiplayer.disconnect.invalid_public_key"
- );
- private static final List<String> STRING_DISCONNECT_REASONS = ImmutableList.of(
- "A secure profile is required to join this server.",
- "Secure profile expired.",
- "Secure profile invalid."
- );
- private static final Component CONNECT_FAILED_NCR = Component.translatable("connect.failed");
- private static boolean screenOverride = false;
@Override
public void onInitializeClient() {
@@ -63,32 +51,6 @@ public final class NoChatReportsClient implements ClientModInitializer {
}
ClientPlayConnectionEvents.JOIN.register(this::onPlayReady);
- ClientPlayConnectionEvents.DISCONNECT.register(this::onDisconnect);
- ScreenEvents.AFTER_INIT.register(this::onScreenInit);
- }
-
- private void onScreenInit(Minecraft client, Screen screen, int scaledWidth, int scaledHeight) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- if (screen instanceof JoinMultiplayerScreen) {
- if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("Initialized JoinMultiplayerScreen screen, resetting safety state!");
- }
-
- ServerSafetyState.reset();
- }
- }
-
- private void onDisconnect(ClientPacketListener handler, Minecraft client) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("Disconnected from server, resetting safety state!");
- }
-
- ServerSafetyState.reset();
}
private void onPlayReady(ClientPacketListener handler, PacketSender sender, Minecraft client) {
@@ -99,22 +61,26 @@ public final class NoChatReportsClient implements ClientModInitializer {
if (!client.isLocalServer()) {
boolean canSend = ClientPlayNetworking.canSend(NoChatReports.CHANNEL);
- if (ServerSafetyState.getCurrent() == ServerSafetyLevel.REALMS) {
+ if (ServerSafetyState.isOnRealms()) {
// NO-OP
} else if (canSend) {
ServerSafetyState.updateCurrent(ServerSafetyLevel.SECURE);
+ } else if (client.getCurrentServer() instanceof ServerDataExtension ext &&
+ ext.preventsChatReports()) {
+ ServerSafetyState.updateCurrent(ServerSafetyLevel.SECURE);
+ } else if (ServerSafetyState.getLastServer() != null &&
+ NCRConfig.getServerWhitelist().isWhitelisted(ServerSafetyState.getLastServer())) {
+ ServerSafetyState.updateCurrent(ServerSafetyLevel.INSECURE);
+ ServerSafetyState.setAllowChatSigning(true);
} else {
- if (client.getCurrentServer() instanceof ServerDataExtension ext
- && ext.preventsChatReports()) {
- ServerSafetyState.updateCurrent(ServerSafetyLevel.SECURE);
- } else {
- ServerSafetyState.updateCurrent(ServerSafetyLevel.UNINTRUSIVE);
- }
+ ServerSafetyState.updateCurrent(ServerSafetyLevel.UNKNOWN);
}
+ } else {
+ ServerSafetyState.updateCurrent(ServerSafetyLevel.SECURE);
}
if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("Sucessfully connected to server, safety state: {}, reconnect count reset.", ServerSafetyState.getCurrent());
+ NoChatReports.LOGGER.info("Sucessfully connected to server, safety state: {}", ServerSafetyState.getCurrent());
}
if (NCRConfig.getClient().demandOnServer() && !ClientPlayNetworking.canSend(NoChatReports.CHANNEL)) {
diff --git a/src/main/java/com/aizistral/nochatreports/config/NCRServerWhitelist.java b/src/main/java/com/aizistral/nochatreports/config/NCRServerWhitelist.java
index 5d36cf5..a8cc1c2 100644
--- a/src/main/java/com/aizistral/nochatreports/config/NCRServerWhitelist.java
+++ b/src/main/java/com/aizistral/nochatreports/config/NCRServerWhitelist.java
@@ -42,8 +42,16 @@ public class NCRServerWhitelist extends JSONConfig {
*/
public boolean isWhitelisted(ServerAddress address) {
- return NCRConfig.getClient().whitelistAllServers() ||
- this.getList().contains(address.getHost() + ":" + address.getPort());
+ return NCRConfig.getClient().whitelistAllServers() || (address != null &&
+ this.getList().contains(address.getHost() + ":" + address.getPort()));
+ }
+
+ public boolean add(ServerAddress address) {
+ return this.getList().add(address.getHost() + ":" + address.getPort());
+ }
+
+ public boolean remove(ServerAddress address) {
+ return this.getList().remove(address.getHost() + ":" + address.getPort());
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java
index 586d828..2e01dbf 100644
--- a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java
+++ b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java
@@ -5,6 +5,7 @@ import com.aizistral.nochatreports.config.NCRConfig;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.MutableComponent;
/**
* Represents the level of "safety" of the given server, in the eyes of the client.
@@ -56,7 +57,7 @@ public enum ServerSafetyLevel {
UNDEFINED;
@Environment(EnvType.CLIENT)
- public Component getTooltip() {
+ public MutableComponent getTooltip() {
if (NCRConfig.getClient().whitelistAllServers() && this.equals(ServerSafetyLevel.INSECURE))
return Component.translatable("gui.nochatreports.status_insecure_whitelist_all_servers");
else
diff --git a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
index c797d99..de80bfb 100644
--- a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
+++ b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
@@ -9,6 +9,7 @@ import javax.annotation.Nullable;
import com.aizistral.nochatreports.NoChatReports;
import com.aizistral.nochatreports.config.NCRConfig;
+import com.aizistral.nochatreports.gui.UnsafeServerScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -26,6 +27,7 @@ import net.minecraft.network.chat.SignedMessageChain.Encoder;
@Environment(EnvType.CLIENT)
public final class ServerSafetyState {
private static ServerSafetyLevel current = ServerSafetyLevel.UNDEFINED;
+ private static ServerAddress lastServer = null;
private static AtomicBoolean allowChatSigning = new AtomicBoolean(false);
public static void updateCurrent(ServerSafetyLevel level) {
@@ -45,22 +47,43 @@ public final class ServerSafetyState {
if (Minecraft.getInstance().player != null) {
var connection = Minecraft.getInstance().player.connection;
- if (allow) {
+ if (allow && connection.chatSession == null) {
Minecraft.getInstance().getProfileKeyPairManager().prepareKeyPair()
.thenAcceptAsync(optional -> optional.ifPresent(profileKeyPair ->
connection.setChatSession(LocalChatSession.create(profileKeyPair))),
Minecraft.getInstance());
- } else {
- connection.chatSession = null;
- connection.signedMessageEncoder = Encoder.UNSIGNED;
}
}
}
}
+ public static void toggleChatSigning() {
+ setAllowChatSigning(!allowChatSigning.get());
+ }
+
+ public static boolean isOnRealms() {
+ return current == ServerSafetyLevel.REALMS;
+ }
+
+ public static boolean isDetermined() {
+ return current != ServerSafetyLevel.UNINTRUSIVE && current != ServerSafetyLevel.UNDEFINED
+ && current != ServerSafetyLevel.UNKNOWN;
+ }
+
+ @Nullable
+ public static ServerAddress getLastServer() {
+ return lastServer;
+ }
+
+ public static void setLastServer(@Nullable ServerAddress address) {
+ lastServer = address;
+ }
+
public static void reset() {
+ lastServer = null;
current = ServerSafetyLevel.UNDEFINED;
allowChatSigning.set(false);
+ UnsafeServerScreen.setHideThisSession(false);
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/gui/ExtendedWarningScreen.java b/src/main/java/com/aizistral/nochatreports/gui/ExtendedWarningScreen.java
index 1d37628..a9d5818 100644
--- a/src/main/java/com/aizistral/nochatreports/gui/ExtendedWarningScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/gui/ExtendedWarningScreen.java
@@ -17,22 +17,22 @@ import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
public abstract class ExtendedWarningScreen extends Screen {
- private final Component TITLE;
- private final Component CONTENT;
- private final Component CHECK;
- private final Component NARRATION;
- private final String WIKI_LINK;
+ private final Component title;
+ private final Component content;
+ private final Component check;
+ private final Component narration;
+ private final String wiki_link;
protected final Screen previous;
protected MultiLineLabel message = MultiLineLabel.EMPTY;
protected Checkbox stopShowing = null;
public ExtendedWarningScreen(Component title, Component content, Component check, String wikiLink, Screen previous) {
super(title);
- this.TITLE = title;
- this.CONTENT = content;
- this.CHECK = check;
- this.WIKI_LINK = wikiLink;
- this.NARRATION = this.TITLE.copy().append("\n").append(this.CONTENT);
+ this.title = title;
+ this.content = content;
+ this.check = check;
+ this.wiki_link = wikiLink;
+ this.narration = this.title.copy().append("\n").append(this.content);
this.previous = previous;
}
@@ -40,12 +40,12 @@ public abstract class ExtendedWarningScreen extends Screen {
protected void init() {
this.clearWidgets();
super.init();
- this.message = MultiLineLabel.create(this.font, this.CONTENT, this.width - (this.hugeGUI() ? 65 : 100));
+ this.message = MultiLineLabel.create(this.font, this.content, this.width - (this.hugeGUI() ? 65 : 100));
int i = (this.message.getLineCount() + 1) * this.getLineHeight();
- if (this.CHECK != null) {
+ if (this.check != null) {
int checkY = this.hugeGUI() ? 27 : 76;
- int j = this.font.width(this.CHECK);
- this.stopShowing = new Checkbox(this.width / 2 - j / 2 - 8, checkY + i, j + 24, 20, this.CHECK, false);
+ int j = this.font.width(this.check);
+ this.stopShowing = new Checkbox(this.width / 2 - j / 2 - 8, checkY + i, j + 24, 20, this.check, false);
this.addRenderableWidget(this.stopShowing);
}
this.initButtons(i);
@@ -61,11 +61,11 @@ public abstract class ExtendedWarningScreen extends Screen {
this.addRenderableWidget(Button.builder(Component.translatable("gui.nochatreports.encryption_warning.learn_more"), button -> {
Minecraft.getInstance().setScreen(new ConfirmLinkScreen(agree -> {
if (agree) {
- Util.getPlatform().openUri(this.WIKI_LINK);
+ Util.getPlatform().openUri(this.wiki_link);
}
Minecraft.getInstance().setScreen(this);
- }, this.WIKI_LINK, true));
+ }, this.wiki_link, true));
}).pos(this.width / 2 - 100 + offset, buttonY + i).size(150, 20).build());
diff --git a/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java b/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java
index 68e2a07..c0bb983 100644
--- a/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java
@@ -11,64 +11,81 @@ import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
+import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraft.client.gui.screens.ConfirmLinkScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
import net.minecraft.client.gui.screens.multiplayer.WarningScreen;
+import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.resolver.ServerAddress;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
-/**
- * This is the screen user gets thrown into when they try to enter server that refuses to let them in
- * without exposing account's public key. From here the user can choose not to play on the server, or
- * agree to expose the key and send only signed messages. In the latter case they get reconnected to
- * the server and mod will not prevent the key from being sent. Optional checkbox is provided to add
- * the server to persistent whitelist in the config, to remove the need of going through this screen
- * every time when entering that specific server.
- *
- * @author Aizistral
- */
-
@Environment(EnvType.CLIENT)
public final class UnsafeServerScreen extends WarningScreen {
- private static final Component TITLE = Component.translatable("gui.nochatreports.unsafe_server.header").withStyle(ChatFormatting.BOLD);
- private static final Component CONTENT = Component.translatable("gui.nochatreports.unsafe_server.contents");
- private static final Component CHECK = Component.translatable("gui.nochatreports.unsafe_server.check");
+ private static final Component TITLE = Component.translatable("gui.nochatreports.signing_required.header").withStyle(ChatFormatting.BOLD);
+ private static final Component CONTENT = Component.translatable("gui.nochatreports.signing_required.contents");
+ private static final Component CHECK = Component.translatable("gui.nochatreports.signing_required.check");
private static final Component NARRATION = TITLE.copy().append("\n").append(CONTENT);
+ private static boolean hideThisSession = false;
- private final Screen previous = new TitleScreen();
- private final Screen joinMultiplayer = new JoinMultiplayerScreen(new TitleScreen());
+ private final Screen previous;
- public UnsafeServerScreen() {
+ public UnsafeServerScreen(Screen previous) {
super(TITLE, CONTENT, CHECK, NARRATION);
+ this.previous = previous;
}
@Override
protected void initButtons(int i) {
- // this.addRenderableWidget(Button.builder(CommonComponents.GUI_PROCEED, button -> {
- // ServerAddress address = ServerSafetyState.getLastServerAddress();
- //
- // if (address != null) {
- // if (this.stopShowing.selected()) {
- // NCRConfig.getServerWhitelist().getList().add(address.getHost() + ":" + address.getPort());
- // NCRConfig.getServerWhitelist().saveFile();
- // }
- //
- // if (NCRConfig.getCommon().enableDebugLog()) {
- // NoChatReports.LOGGER.info("Proceeding with unsafe connection to {}, added to whitelist: {}",
- // address.getHost() + ":" + address.getPort(), this.stopShowing.selected());
- // }
- //
- // ServerSafetyState.setAllowsUnsafeServer(true);
- // this.minecraft.setScreen(new AwaitConnectionScreen(this.joinMultiplayer));
- // }
- // }).pos(this.width / 2 - 155, 100 + i).size(150, 20).build());
- //
- // this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, button -> {
- // this.minecraft.setScreen(this.joinMultiplayer);
- // }).pos(this.width / 2 - 155 + 160, 100 + i).size(150, 20).build());
+ this.addRenderableWidget(Button.builder(Component.translatable("gui.nochatreports.signing_required.allow_signing"),
+ button -> {
+ ServerSafetyState.setAllowChatSigning(true);
+ this.minecraft.setScreen(this.previous);
+ }).pos(this.width / 2 - 260 + 28, 100 + i).size(150, 20)
+ .build());
+
+ ServerAddress address = ServerSafetyState.getLastServer();
+ var whitelist = Button.builder(Component.translatable("gui.nochatreports.signing_required.whitelist_server"),
+ button -> {
+ if (address != null) {
+ NCRConfig.getServerWhitelist().add(address);
+ NCRConfig.getServerWhitelist().saveFile();
+ }
+
+ ServerSafetyState.setAllowChatSigning(true);
+ this.minecraft.setScreen(this.previous);
+ }).pos(this.width / 2 - 100 + 28, 100 + i).size(150, 20)
+ .build();
+
+ if (address == null) {
+ whitelist.active = false;
+ }
+
+ this.addRenderableWidget(whitelist);
+
+ this.addRenderableWidget(Button.builder(Component.translatable("gui.nochatreports.signing_required.cancel"),
+ button -> {
+ if (this.stopShowing.selected()) {
+ hideThisSession = true;
+ }
+ this.minecraft.setScreen(this.previous);
+ }).pos(this.width / 2 + 60 + 28, 100 + i).size(150, 20).build());
+ }
+
+ private void resendLastMessage() {
+ if (this.previous instanceof ChatScreen chat) {
+ chat.handleChatInput(NCRConfig.getEncryption().getLastMessage(), false);
+ }
+ }
+
+ public static void setHideThisSession(boolean hide) {
+ hideThisSession = hide;
+ }
+
+ public static boolean hideThisSession() {
+ return hideThisSession;
}
}
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 b776a81..91375c3 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
@@ -10,18 +10,25 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.At.Shift;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.aizistral.nochatreports.NoChatReports;
import com.aizistral.nochatreports.config.NCRConfig;
import com.aizistral.nochatreports.core.EncryptionUtil;
+import com.aizistral.nochatreports.core.ServerSafetyLevel;
+import com.aizistral.nochatreports.core.ServerSafetyState;
+import com.aizistral.nochatreports.gui.UnsafeServerScreen;
import net.minecraft.client.GuiMessageTag;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.multiplayer.chat.ChatListener;
import net.minecraft.client.multiplayer.chat.ChatTrustLevel;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.PlayerChatMessage;
+import net.minecraft.network.chat.contents.TranslatableContents;
@Mixin(ChatListener.class)
public class MixinChatListener {
@@ -31,6 +38,23 @@ public class MixinChatListener {
throw new IllegalStateException("@Shadow transformation failed. Should never happen.");
}
+ @Inject(method = "handleSystemMessage", at = @At("HEAD"))
+ private void onHandleSystemMessage(Component message, boolean overlay, CallbackInfo info) {
+ if (message.getContents() instanceof TranslatableContents translatable) {
+ if (translatable.getKey().equals("chat.disabled.missingProfileKey")) {
+ if (!ServerSafetyState.isOnRealms()) {
+ ServerSafetyState.updateCurrent(ServerSafetyLevel.INSECURE);
+ }
+
+ if (UnsafeServerScreen.hideThisSession())
+ return;
+
+ Minecraft.getInstance().setScreen(new UnsafeServerScreen(Minecraft.getInstance().screen
+ instanceof ChatScreen chat ? chat : new ChatScreen("")));
+ }
+ }
+ }
+
/**
* @reason Removes "Not Secure" and "Modified" statuses of chat messages. They ultimately
* serve no purpose but to annoy the user and scare them away from servers that actually
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java
index 6d246ec..4343db8 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatScreen.java
@@ -30,10 +30,12 @@ import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
+import net.minecraft.client.multiplayer.resolver.ServerAddress;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
@@ -46,6 +48,7 @@ import net.minecraft.util.FormattedCharSequence;
public abstract class MixinChatScreen extends Screen {
private static final ResourceLocation CHAT_STATUS_ICONS = new ResourceLocation("nochatreports", "textures/gui/chat_status_icons_extended.png");
private static final ResourceLocation ENCRYPTION_BUTTON = new ResourceLocation("nochatreports", "textures/gui/encryption_toggle_button.png");
+ private ImageButton safetyStatusButton;
protected MixinChatScreen() {
super(null);
@@ -57,6 +60,10 @@ public abstract class MixinChatScreen extends Screen {
String message = info.getReturnValue();
NCRConfig.getEncryption().setLastMessage(message);
+ if (!ServerSafetyState.allowChatSigning() && !ServerSafetyState.isDetermined()) {
+ ServerSafetyState.updateCurrent(ServerSafetyLevel.UNINTRUSIVE); // asume unintrusive until further notice
+ }
+
if (!message.isEmpty() && !Screen.hasControlDown() && NCRConfig.getEncryption().shouldEncrypt(message)) {
NCRConfig.getEncryption().getEncryptor().ifPresent(e -> {
int index = NCRConfig.getEncryption().getEncryptionStartIndex(message);
@@ -75,16 +82,57 @@ public abstract class MixinChatScreen extends Screen {
int buttonX = this.width - 23;
if (NCRConfig.getClient().showServerSafety() && NCRConfig.getClient().enableMod()) {
- ServerSafetyLevel trust = this.minecraft.isLocalServer() ? ServerSafetyLevel.SECURE : ServerSafetyState.getCurrent();
+ this.safetyStatusButton = new ImageButton(buttonX, this.height - 37, 20, 20, this.getXOffset(),
+ 0, 20, CHAT_STATUS_ICONS, 128, 128, btn -> {
+ var address = ServerSafetyState.getLastServer();
+ if (address != null) {
+ var whitelist = NCRConfig.getServerWhitelist();
+
+ if (!whitelist.isWhitelisted(address)) {
+ whitelist.add(address);
+ whitelist.saveFile();
+
+ if (ServerSafetyState.getCurrent() != ServerSafetyLevel.SECURE) {
+ ServerSafetyState.setAllowChatSigning(true);
+ ServerSafetyState.updateCurrent(ServerSafetyLevel.INSECURE);
+ }
+ } else {
+ whitelist.remove(address);
+ whitelist.saveFile();
+ }
+ }
+ }, (btn, poseStack, i, j) -> {
+ MutableComponent tooltip = this.getSafetyLevel().getTooltip();
+ ServerAddress address = ServerSafetyState.getLastServer();
+ String signing = "gui.nochatreports.status_signing_denied";
+
+ if (ServerSafetyState.getCurrent() == ServerSafetyLevel.REALMS) {
+ signing = "gui.nochatreports.status_signing_allowed_realms";
+ } else if (NCRConfig.getServerWhitelist().isWhitelisted(address)) {
+ signing = "gui.nochatreports.status_signing_allowed_whitelisted";
+ } else if (ServerSafetyState.allowChatSigning()) {
+ signing = "gui.nochatreports.status_signing_allowed";
+ }
+
+ tooltip.append("\n\n").append(Component.translatable(signing));
+
+ if (address != null) {
+ String status = "gui.nochatreports.status_whitelist_no";
+
+ if (NCRConfig.getClient().whitelistAllServers()) {
+ status = "gui.nochatreports.status_whitelist_all";
+ } else if (NCRConfig.getServerWhitelist().isWhitelisted(address)) {
+ status = "gui.nochatreports.status_whitelist_yes";
+ }
- var button = new ImageButton(buttonX, this.height - 37, 20, 20, this.getXOffset(trust),
- 0, 20, CHAT_STATUS_ICONS, 128, 128, btn -> {}, (btn, poseStack, i, j) ->
- this.renderTooltipNoGap(poseStack, this.minecraft.font.split(trust.getTooltip(), 250), i, j),
- Component.empty());
- button.active = false;
- button.visible = true;
+ tooltip.append("\n\n").append(Component.translatable(
+ "gui.nochatreports.status_whitelist_mode", Component.translatable(status)));
+ }
- this.addRenderableOnly(button);
+ this.renderTooltipNoGap(poseStack, this.minecraft.font.split(tooltip, 250), i, j);
+ }, Component.empty());
+
+ this.addRenderableWidget(this.safetyStatusButton);
buttonX -= 25;
}
@@ -124,6 +172,21 @@ public abstract class MixinChatScreen extends Screen {
this.addRenderableWidget(button);
}
+ @Inject(method = "tick", at = @At("RETURN"))
+ private void onTick(CallbackInfo info) {
+ if (this.safetyStatusButton != null) {
+ this.safetyStatusButton.xTexStart = this.getXOffset();
+ }
+ }
+
+ private ServerSafetyLevel getSafetyLevel() {
+ return this.minecraft.isLocalServer() ? ServerSafetyLevel.SECURE : ServerSafetyState.getCurrent();
+ }
+
+ private int getXOffset() {
+ return this.getXOffset(this.getSafetyLevel());
+ }
+
private int getXOffset(ServerSafetyLevel level) {
return switch (level) {
case SECURE -> 21;
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 2788cbd..e4dd387 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java
@@ -33,7 +33,8 @@ public class MixinConnectScreen {
if (!NCRConfig.getClient().enableMod())
return;
- ServerSafetyState.updateCurrent(ServerSafetyLevel.UNDEFINED); // just to be 100% sure
+ ServerSafetyState.reset();
+ ServerSafetyState.setLastServer(serverAddress);
if (NCRConfig.getCommon().enableDebugLog()) {
NoChatReports.LOGGER.info("Connecting to: {}",
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinRealmsConnect.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinRealmsConnect.java
index f6f735a..7bcb9a8 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinRealmsConnect.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinRealmsConnect.java
@@ -26,7 +26,9 @@ public class MixinRealmsConnect {
if (!NCRConfig.getClient().enableMod())
return;
+ ServerSafetyState.reset();
ServerSafetyState.updateCurrent(ServerSafetyLevel.REALMS);
+ ServerSafetyState.setAllowChatSigning(true);
}
}
diff --git a/src/main/resources/assets/nochatreports/lang/en_us.json b/src/main/resources/assets/nochatreports/lang/en_us.json
index 776abb4..2139170 100644
--- a/src/main/resources/assets/nochatreports/lang/en_us.json
+++ b/src/main/resources/assets/nochatreports/lang/en_us.json
@@ -4,15 +4,19 @@
"gui.nochatreport.noReporting": "Chat reports are disabled on this server, courtesy of No Chat Reports.",
"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 allows you to send unsigned messages which cannot be reported to Mojang. Unless some kind of plugin is installed on server that prevents chat reports - vanilla clients will still send signed messages, display unsigned messages as \"Not Secure\" and not show them if \"Only Show Secure Chat\" is enabled in chat options.",
- "gui.nochatreports.status_insecure": "This server demands all chat messages to be signed and you agreed to proceed with this arrangement. Everything you send in the chat is potentially incriminating evidence that can be used against you in the report. You can remove this server from §oWhitelisted Servers§r in the mod config to get warned again.",
+ "gui.nochatreports.status_unintrusive": "This server allows you to send unsigned messages which cannot be reported to Mojang. Unless some kind of plugin is installed on server that prevents chat reports - vanilla clients will still send signed messages, display unsigned messages as \"Unverified\" and not show them if \"Only Show Secure Chat\" is enabled in chat options.",
+ "gui.nochatreports.status_insecure": "This server currently demands all chat messages to be signed. All signed messages are a potentially incriminating evidence that can be used against you in the report.",
"gui.nochatreports.status_realms": "This is a Realms server. Not only there is no way to prevent chat reports here, but Mojang also employ automated chat monitoring to identify potential \"online harms\" and escalate them for human review, whether owner of the realm likes it or not. Your only hope is chat encryption.",
- "gui.nochatreports.status_insecure_whitelist_all_servers": "This server demands all chat messages to be signed and you disabled the full-screen warning for it. Everything you send in the chat is potentially incriminating evidence that can be used against you in the report. You can disable §oWhitelist all servers§r in the mod config to get warned again.",
- "gui.nochatreports.status_unknown": "No Chat Reports was toggled mid-session. Server safety status can only be evaluated on login. Please re-join the server to evaluate its safety status.",
+ "gui.nochatreports.status_unknown": "No Chat Reports is not sure about safety of this server yet. Try to send a message in chat in order to evaluate it.",
"gui.nochatreports.status_undefined": "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, which means they can be reported to Mojang, which may result in a ban from all multiplayer servers. This likely means that the server owner kept \"enforce-secure-profile\" enabled in the 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",
+ "gui.nochatreports.status_signing_allowed_realms": "Chat signing is always enabled on Realms, since it is always required and disabling it would yield no benefit anyways.",
+ "gui.nochatreports.status_signing_allowed_whitelisted": "Message signing is enabled for this session. If you want to disable it - remove this server from whitelist and re-join. Keep in mind that there is no way to detect whether server allows to send unsigned messages without trying to send one, so you'll have to disable it to check whether current server configuration allows unsigned messages.",
+ "gui.nochatreports.status_signing_allowed": "Message signing is enabled for this session. Re-join the server to disable it.",
+ "gui.nochatreports.status_signing_denied": "Message signing is disabled for this session. You can whitelist this server to always enable chat signing automatically on it.",
+ "gui.nochatreports.status_whitelist_mode": "§lWhitelisted Server: %1$s",
+ "gui.nochatreports.status_whitelist_all": "§a§lYes (All Servers)",
+ "gui.nochatreports.status_whitelist_yes": "§a§lYes",
+ "gui.nochatreports.status_whitelist_no": "§c§lNo",
"gui.nochatreports.reload_config_tooltip": "Reload No Chat Reports config. Use carefully.",
"gui.nochatreports.verified_server": "§a§lSafe Server§r\nWe could verify that this server has No Chat Reports installed, or prevents chat reports in some other known way. You can chat there safely.",
"gui.nochatreports.ncr_toggle_tooltip": "§lNo Chat Reports:§r %1$s\nDisable or enable most of the mod's client-sided functionality. You may have to do this to join some Paper/Velocity servers, as they are known for causing issues with NCR.\nCertain networking-unrelated things, such as encryption, chat trust status tweaks and removal of vanilla's \"Chat messages can't be verified\" toast will still work; they can be disabled in config individually.",
@@ -52,12 +56,15 @@
"gui.nochatreports.realms_warning.contents": "Realms servers are not private. Realm owners cannot disable chat reporting, and Mojang applies additional chat monitoring to identify potential \"online harms\" and escalate them to human review. If you are then found to violate Minecraft's Community Standards - even if chat participants did not get offended - you will be banned, temporarily or permanently, from all multiplayer services. Use of encryption is highly advised.",
"gui.nochatreports.realms_warning.check": "Don't show again",
"gui.nochatreports.realms_warning.learn_more": "Learn More",
- "gui.NoChatReports.showEncryptionButtonWarning": "§cBelow does not disable encryption, it only hides the button!",
+ "gui.nochatreports.signing_required.header": "Caution: Chat Signing Requested",
+ "gui.nochatreports.signing_required.contents": "This server requires all chat messages to be signed, which means they can be reported to Mojang, which may result in a ban from all multiplayer servers. This likely means that the server owner kept \"enforce-secure-profile\" enabled in the server.properties, which is the default since 1.19.1. Click \"Allow Signing\" to enable message signing for this session, or \"Whitelist Server\" to always enable signing on this server.",
+ "gui.nochatreports.signing_required.allow_signing": "Allow Signing",
+ "gui.nochatreports.signing_required.whitelist_server": "Whitelist Server",
+ "gui.nochatreports.signing_required.cancel": "Dismiss",
+ "gui.nochatreports.signing_required.check": "Don't show again during this session",
"configuration.NoChatReports.config": "No Chat Reports",
-
"configuration.NoChatReports.category.visual": "Visual",
-
"option.NoChatReports.showServerSafety": "Show server safety",
"option.NoChatReports.showServerSafety.tooltip": "Allows the client to display server safety status in bottom-right corner of chat screen. The icon is hoverable for additional information.",
"option.NoChatReports.showServerSafety.moreInfo": "§bClick here to read more about server safety levels",
@@ -77,9 +84,7 @@
"option.NoChatReports.hideWarningToast.tooltip": "Removes a warning toast that is displayed when entering servers with disabled §oenforce-secure-profile§r.",
"option.NoChatReports.alwaysHideReportButton": "Always hide report button",
"option.NoChatReports.alwaysHideReportButton.tooltip": "Prevents the client from ever showing report button in Social Interactions screen. This is disabled by default, and mod simply makes button inactive on servers that have No Chat Reports installed, adding an explanation to the tooltip of the button.",
-
"configuration.NoChatReports.category.technical": "Technical",
-
"option.NoChatReports.demandOnServer": "Demand on server",
"option.NoChatReports.demandOnServer.tooltip": "Prevents the client from joining servers that don't have No Chat Reports installed.",
"option.NoChatReports.enableDebugLog": "Enable debug log",
@@ -104,22 +109,19 @@
"option.NoChatReports.serverSigningChecks.tooltip": "Map of whitelisted servers to last signing enforcement check times, in epoch seconds. This typically does not have to be edited manually.",
"option.NoChatReports.showEncryptionButton": "Show encryption button",
"option.NoChatReports.showEncryptionButton.tooltip": "Setting this to false will simply prevent encryption button from being displayed in the chat screen. Be aware that encryption itself will not be automatically disabled along with the button.",
-
"configuration.NoChatReports.category.whitelistedServers": "Whitelisted Servers",
-
"option.NoChatReports.whitelistedServers": "Whitelisted Servers",
"option.NoChatReports.whitelistedServers.tooltip": "Contains servers for which \"Unsafe Server\" warning screen should never display. Servers are added to this list automatically when you check \"Do not show again for this server\" box in that screen.\nEach entry is a string that is formatted as §l<server-ip>:<port>§r.",
"option.NoChatReports.whitelistedServers.addButtonTooltip": "Add server",
"option.NoChatReports.whitelistedServers.removeButtonTooltip": "Remove selected server",
"option.NoChatReports.whitelistedServers.instructions": "Click the + to add a server. Click the - to remove the selected server.",
"option.NoChatReports.whitelistedServers.serverAddress": "Click here to edit server address",
-
"configuration.NoChatReports.category.lanOptions": "LAN Options",
-
"option.NoChatReports.demandOnClient": "Demand on client",
"option.NoChatReports.demandOnClient.tooltip": "Makes the server require all joining clients to have No Chat Reports installed.",
"option.NoChatReports.convertToGameMessage": "Convert to game message",
"option.NoChatReports.convertToGameMessage.tooltip": "Makes the server convert all player messages into system messages. System messages don't have any signatures attached and cannot be reported; on unmodified clients they will display with gray bar to the left.",
"option.NoChatReports.addQueryData": "Add query data",
- "option.NoChatReports.addQueryData.tooltip": "Allows the server to send additional data to client when handling pings. This is used for displaying \"Safe Server\" icon, as well as some other technical purposes."
+ "option.NoChatReports.addQueryData.tooltip": "Allows the server to send additional data to client when handling pings. This is used for displaying \"Safe Server\" icon, as well as some other technical purposes.",
+ "gui.NoChatReports.showEncryptionButtonWarning": "§cBelow does not disable encryption, it only hides the button!"
}
diff --git a/src/main/resources/assets/nochatreports/textures/gui/chat_status_icons_extended.png b/src/main/resources/assets/nochatreports/textures/gui/chat_status_icons_extended.png
index 27ddc40..8020aa2 100644
--- a/src/main/resources/assets/nochatreports/textures/gui/chat_status_icons_extended.png
+++ b/src/main/resources/assets/nochatreports/textures/gui/chat_status_icons_extended.png
Binary files differ
diff --git a/src/main/resources/nochatreports.mixins.json b/src/main/resources/nochatreports.mixins.json
index 27539f5..b148627 100644
--- a/src/main/resources/nochatreports.mixins.json
+++ b/src/main/resources/nochatreports.mixins.json
@@ -28,7 +28,8 @@
"client.MixinOnlineServerEntry",
"client.MixinChatComponent",
"client.MixinGuiMessageTagIcon",
- "client.MixinTitleScreen"
+ "client.MixinTitleScreen",
+ "client.MixinMinecraft"
],
"server": [
"server.MixinDedicatedServer"