summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/aizistral/nochatreports
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/aizistral/nochatreports')
-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
10 files changed, 222 insertions, 117 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);
}
}