summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/aizistral
diff options
context:
space:
mode:
authorAizistral2022-10-31 20:28:53 +0100
committerAizistral2022-10-31 20:28:53 +0100
commitd80460d3b6e3b7d6ff09bbcc50840f8da4932fd9 (patch)
tree8a91dc4cf1245ee61e505e60cfc14a05b545ebe0 /src/main/java/com/aizistral
parentd081e49c2fa3208090a905dd57611e8ab3c78fa5 (diff)
This is not going to be easy
Diffstat (limited to 'src/main/java/com/aizistral')
-rw-r--r--src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java66
-rw-r--r--src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java12
-rw-r--r--src/main/java/com/aizistral/nochatreports/config/NCRConfigClient.java31
-rw-r--r--src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java95
-rw-r--r--src/main/java/com/aizistral/nochatreports/gui/AwaitConnectionScreen.java82
-rw-r--r--src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java45
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/AccessorDisconnectedScreen.java25
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java4
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinClientboundHelloPacket.java33
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java14
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java2
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinLocalPlayer.java57
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinMinecraft.java23
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinProfileKeyPairManager.java89
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/client/MixinRealmsConnect.java2
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/server/MixinPlayer.java25
-rw-r--r--src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java2
17 files changed, 91 insertions, 516 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java
index b94e2f2..032af34 100644
--- a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java
+++ b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java
@@ -7,10 +7,8 @@ import com.aizistral.nochatreports.config.NCRConfigClient;
import com.aizistral.nochatreports.core.ServerDataExtension;
import com.aizistral.nochatreports.core.ServerSafetyLevel;
import com.aizistral.nochatreports.core.ServerSafetyState;
-import com.aizistral.nochatreports.gui.AwaitConnectionScreen;
import com.aizistral.nochatreports.gui.RealmsWarningScreen;
import com.aizistral.nochatreports.gui.UnsafeServerScreen;
-import com.aizistral.nochatreports.mixins.client.AccessorDisconnectedScreen;
import com.aizistral.nochatreports.network.ClientChannelHandler;
import com.google.common.collect.ImmutableList;
import com.mojang.realmsclient.RealmsMainScreen;
@@ -73,55 +71,7 @@ public final class NoChatReportsClient implements ClientModInitializer {
if (!NCRConfig.getClient().enableMod())
return;
- if (screen instanceof AccessorDisconnectedScreen dsc) {
- if (screenOverride || ServerSafetyState.isOnServer() || screen.getTitle() == CONNECT_FAILED_NCR)
- return;
-
- screenOverride = true;
- var disconnectReason = dsc.getReason();
-
- if (disconnectReason != null) {
- if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("Disconnected with reason {}, reconnect count: {}",
- Component.Serializer.toStableJson(disconnectReason), ServerSafetyState.getReconnectCount());
- }
-
- if (ServerSafetyState.allowsUnsafeServer()) {
- screen = new DisconnectedScreen(new JoinMultiplayerScreen(new TitleScreen()),
- CONNECT_FAILED_NCR, dsc.getReason());
- client.setScreen(screen);
- screenOverride = false;
- return;
- } else if (STRING_DISCONNECT_REASONS.contains(disconnectReason.getString())
- || (disconnectReason.getContents() instanceof TranslatableContents translatable &&
- KEY_DISCONNECT_REASONS.contains(translatable.getKey()))) {
- if (ServerSafetyState.getLastServerAddress() != null) {
- if (!NCRConfig.getServerWhitelist().isWhitelisted(ServerSafetyState.getLastServerAddress())) {
- if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("Server {} evaluated as unsafe and is not whitelisted, displaying warning screen.",
- ServerSafetyState.getLastServerAddress().getHost() + ":" + ServerSafetyState.getLastServerAddress().getPort());
- }
-
- client.setScreen(new UnsafeServerScreen());
- } else {
- NCRConfig.getClient().updateSigningCheck(ServerSafetyState.getLastServerAddress());
-
- if (ServerSafetyState.getReconnectCount() <= 0) {
- ServerSafetyState.setAllowsUnsafeServer(true);
- client.setScreen(new AwaitConnectionScreen(new JoinMultiplayerScreen(new TitleScreen())));
- screenOverride = false;
- return;
- } else {
- ServerSafetyState.setReconnectCount(0);
- screenOverride = false;
- return;
- }
- }
- }
- }
- }
- screenOverride = false;
- } else if (screen instanceof JoinMultiplayerScreen) {
+ if (screen instanceof JoinMultiplayerScreen) {
if (NCRConfig.getCommon().enableDebugLog()) {
NoChatReports.LOGGER.info("Initialized JoinMultiplayerScreen screen, resetting safety state!");
}
@@ -139,7 +89,6 @@ public final class NoChatReportsClient implements ClientModInitializer {
}
ServerSafetyState.reset();
- ServerSafetyState.setDisconnectMillis(Util.getMillis());
}
private void onPlayReady(ClientPacketListener handler, PacketSender sender, Minecraft client) {
@@ -147,9 +96,6 @@ public final class NoChatReportsClient implements ClientModInitializer {
return;
client.execute(() -> {
- ServerSafetyState.setReconnectCount(0);
- ServerSafetyState.setOnServer(true);
-
if (!client.isLocalServer()) {
boolean canSend = ClientPlayNetworking.canSend(NoChatReports.CHANNEL);
@@ -157,10 +103,8 @@ public final class NoChatReportsClient implements ClientModInitializer {
// NO-OP
} else if (canSend) {
ServerSafetyState.updateCurrent(ServerSafetyLevel.SECURE);
- } else if (ServerSafetyState.forceSignedMessages()) {
- ServerSafetyState.updateCurrent(ServerSafetyLevel.INSECURE);
} else {
- if (ServerSafetyState.getLastServerData() instanceof ServerDataExtension ext
+ if (client.getCurrentServer() instanceof ServerDataExtension ext
&& ext.preventsChatReports()) {
ServerSafetyState.updateCurrent(ServerSafetyLevel.SECURE);
} else {
@@ -179,10 +123,4 @@ public final class NoChatReportsClient implements ClientModInitializer {
});
}
- public static void reconnectLastServer() {
- ServerSafetyState.setReconnectCount(ServerSafetyState.getReconnectCount() + 1);
- ConnectScreen.startConnecting(new JoinMultiplayerScreen(new TitleScreen()), Minecraft.getInstance(),
- ServerSafetyState.getLastServerAddress(), ServerSafetyState.getLastServerData());
- }
-
}
diff --git a/src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java b/src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java
index 8139fca..6ddd81b 100644
--- a/src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java
+++ b/src/main/java/com/aizistral/nochatreports/config/ModMenuIntegration.java
@@ -96,24 +96,24 @@ public final class ModMenuIntegration implements ModMenuApi {
.build());
// Set an option for hideRedChatIndicators
- visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideRedChatIndicators"), NCRConfig.getClient().hideRedChatIndicators)
+ visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideRedChatIndicators"), NCRConfig.getClient().hideInsecureMessageIndicators)
.setDefaultValue(true)
.setTooltip(this.makeTooltip("option.NoChatReports.hideRedChatIndicators.tooltip"))
- .setSaveConsumer(newValue -> NCRConfig.getClient().hideRedChatIndicators = newValue)
+ .setSaveConsumer(newValue -> NCRConfig.getClient().hideInsecureMessageIndicators = newValue)
.build());
// Set an option for hideYellowChatIndicators
- visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideYellowChatIndicators"), NCRConfig.getClient().hideYellowChatIndicators)
+ visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideYellowChatIndicators"), NCRConfig.getClient().hideModifiedMessageIndicators)
.setDefaultValue(true)
.setTooltip(this.makeTooltip("option.NoChatReports.hideYellowChatIndicators.tooltip"))
- .setSaveConsumer(newValue -> NCRConfig.getClient().hideYellowChatIndicators = newValue)
+ .setSaveConsumer(newValue -> NCRConfig.getClient().hideModifiedMessageIndicators = newValue)
.build());
// Set an option for hideGrayChatIndicators
- visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideGrayChatIndicators"), NCRConfig.getClient().hideGrayChatIndicators)
+ visual.addEntry(entryBuilder.startBooleanToggle(Component.translatable("option.NoChatReports.hideGrayChatIndicators"), NCRConfig.getClient().hideSystemMessageIndicators)
.setDefaultValue(true)
.setTooltip(this.makeTooltip("option.NoChatReports.hideGrayChatIndicators.tooltip"))
- .setSaveConsumer(newValue -> NCRConfig.getClient().hideGrayChatIndicators = newValue)
+ .setSaveConsumer(newValue -> NCRConfig.getClient().hideSystemMessageIndicators = newValue)
.build());
// Set an option for hideWarningToast
diff --git a/src/main/java/com/aizistral/nochatreports/config/NCRConfigClient.java b/src/main/java/com/aizistral/nochatreports/config/NCRConfigClient.java
index 09496b1..cff126f 100644
--- a/src/main/java/com/aizistral/nochatreports/config/NCRConfigClient.java
+++ b/src/main/java/com/aizistral/nochatreports/config/NCRConfigClient.java
@@ -22,8 +22,8 @@ import net.minecraft.util.StringUtil;
public final class NCRConfigClient extends JSONConfig {
protected static final String FILE_NAME = "NoChatReports/NCR-Client.json";
- protected boolean demandOnServer = false, showServerSafety = true, hideRedChatIndicators = true,
- hideYellowChatIndicators = true, hideGrayChatIndicators = true, hideWarningToast = true,
+ protected boolean demandOnServer = false, showServerSafety = true, hideInsecureMessageIndicators = true,
+ hideModifiedMessageIndicators = true, hideSystemMessageIndicators = true, hideWarningToast = true,
alwaysHideReportButton = false, disableTelemetry = true, showReloadButton = true,
whitelistAllServers = false, verifiedIconEnabled = true, showNCRButton = true,
enableMod = true, skipRealmsWarning = false;
@@ -78,8 +78,8 @@ public final class NCRConfigClient extends JSONConfig {
* @see MixinChatListener#onEvaluateTrustLevel
*/
- public boolean hideRedChatIndicators() {
- return this.hideRedChatIndicators;
+ public boolean hideInsecureMessageIndicators() {
+ return this.hideInsecureMessageIndicators;
}
/**
@@ -90,8 +90,8 @@ public final class NCRConfigClient extends JSONConfig {
* @see MixinChatListener#onEvaluateTrustLevel
*/
- public boolean hideYellowChatIndicators() {
- return this.hideYellowChatIndicators;
+ public boolean hideModifiedMessageIndicators() {
+ return this.hideModifiedMessageIndicators;
}
/**
@@ -102,8 +102,8 @@ public final class NCRConfigClient extends JSONConfig {
* @see com.aizistral.nochatreports.mixins.client.MixinGuiMessageTag#onSystem
*/
- public boolean hideGrayChatIndicators() {
- return this.hideGrayChatIndicators;
+ public boolean hideSystemMessageIndicators() {
+ return this.hideSystemMessageIndicators;
}
/**
@@ -237,19 +237,4 @@ public final class NCRConfigClient extends JSONConfig {
this.skipRealmsWarning = skipRealmsWarning;
}
- public boolean doSigningCheck(ServerAddress serverAddress) {
- String server = serverAddress.getHost() + ":" + serverAddress.getPort();
-
- if (!this.serverSigningChecks.containsKey(server))
- return true;
- else
- return Instant.now().getEpochSecond() - this.serverSigningChecks.get(server) >= this.signingCheckDelaySeconds;
- }
-
- public void updateSigningCheck(ServerAddress serverAddress) {
- String server = serverAddress.getHost() + ":" + serverAddress.getPort();
- this.serverSigningChecks.put(server, Instant.now().getEpochSecond());
- this.saveFile();
- }
-
}
diff --git a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
index 21f8f75..c797d99 100644
--- a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
+++ b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyState.java
@@ -1,5 +1,6 @@
package com.aizistral.nochatreports.core;
+import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@@ -11,8 +12,11 @@ import com.aizistral.nochatreports.config.NCRConfig;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.resolver.ServerAddress;
+import net.minecraft.network.chat.LocalChatSession;
+import net.minecraft.network.chat.SignedMessageChain.Encoder;
/**
* All this global state is questionable, but we have to...
@@ -22,12 +26,7 @@ import net.minecraft.client.multiplayer.resolver.ServerAddress;
@Environment(EnvType.CLIENT)
public final class ServerSafetyState {
private static ServerSafetyLevel current = ServerSafetyLevel.UNDEFINED;
- private static ServerAddress lastServerAddress = null;
- private static ServerData lastServerData = null;
- private static AtomicBoolean allowUnsafeServer = new AtomicBoolean(false),
- sessionRequestedKey = new AtomicBoolean(false), isOnServer = new AtomicBoolean(false);
- private static AtomicInteger reconnectCount = new AtomicInteger(0);
- private static AtomicLong disconnectMillis = new AtomicLong(0);
+ private static AtomicBoolean allowChatSigning = new AtomicBoolean(false);
public static void updateCurrent(ServerSafetyLevel level) {
current = level;
@@ -37,79 +36,31 @@ public final class ServerSafetyState {
return current;
}
- public static boolean allowsUnsafeServer() {
- return current != ServerSafetyLevel.SECURE ? allowUnsafeServer.get() : false;
+ public static boolean allowChatSigning() {
+ return allowChatSigning.get();
}
- public static void setAllowsUnsafeServer(boolean allows) {
- if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("Set allowUnsafeServer to: " + allows + ", value set in stacktrace:");
- NoChatReports.LOGGER.catching(new RuntimeException().fillInStackTrace());
- }
-
- allowUnsafeServer.set(allows);
- }
-
- public static void setSessionRequestedKey(boolean requested) {
- sessionRequestedKey.set(requested);
- }
-
- public static boolean sessionRequestedKey() {
- return current != ServerSafetyLevel.SECURE ? sessionRequestedKey.get() : false;
- }
-
- public static boolean forceSignedMessages() {
- return allowsUnsafeServer() && sessionRequestedKey();
- }
-
- @Nullable
- public static ServerAddress getLastServerAddress() {
- return lastServerAddress;
- }
-
- @Nullable
- public static ServerData getLastServerData() {
- return lastServerData;
- }
-
- public static void setLastConnectedServer(@Nullable ServerAddress address, @Nullable ServerData data) {
- lastServerAddress = address;
- lastServerData = data;
- }
-
- public static int getReconnectCount() {
- return reconnectCount.get();
- }
-
- public static void setReconnectCount(int count) {
- reconnectCount.set(count);
- }
-
- public static long getDisconnectMillis() {
- return disconnectMillis.get();
- }
+ public static void setAllowChatSigning(boolean allow) {
+ if (allowChatSigning.compareAndSet(!allow, allow)) {
+ if (Minecraft.getInstance().player != null) {
+ var connection = Minecraft.getInstance().player.connection;
- public static void setDisconnectMillis(long millis) {
- disconnectMillis.set(millis);
- }
-
- public static boolean isOnServer() {
- return isOnServer.get();
- }
-
- public static void setOnServer(boolean on) {
- isOnServer.set(on);
+ if (allow) {
+ 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 reset() {
current = ServerSafetyLevel.UNDEFINED;
- allowUnsafeServer.set(false);
- sessionRequestedKey.set(false);
- isOnServer.set(false);
-
- if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("allowUnsafeServer: {}", allowUnsafeServer.get());
- }
+ allowChatSigning.set(false);
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/gui/AwaitConnectionScreen.java b/src/main/java/com/aizistral/nochatreports/gui/AwaitConnectionScreen.java
deleted file mode 100644
index b1fc036..0000000
--- a/src/main/java/com/aizistral/nochatreports/gui/AwaitConnectionScreen.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.aizistral.nochatreports.gui;
-
-import com.aizistral.nochatreports.NoChatReports;
-import com.aizistral.nochatreports.NoChatReportsClient;
-import com.aizistral.nochatreports.config.NCRConfig;
-import com.aizistral.nochatreports.core.ServerSafetyState;
-import com.mojang.blaze3d.vertex.PoseStack;
-
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-import net.minecraft.Util;
-import net.minecraft.client.GameNarrator;
-import net.minecraft.client.gui.components.Button;
-import net.minecraft.client.gui.screens.ConnectScreen;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.CommonComponents;
-import net.minecraft.network.chat.Component;
-
-@Environment(value=EnvType.CLIENT)
-public class AwaitConnectionScreen extends Screen {
- private final Screen parent;
- private boolean aborted = false;
- private long millisAwaiting = 0;
-
- public AwaitConnectionScreen(Screen parent) {
- super(GameNarrator.NO_TITLE);
- this.parent = parent;
- }
-
- @Override
- protected void init() {
- this.clearWidgets();
- this.millisAwaiting = Util.getMillis();
-
- this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> {
- if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("Aborted reconnect await!");
- }
-
- this.aborted = true;
- this.minecraft.setScreen(this.parent);
- ServerSafetyState.reset();
- }).pos(this.width / 2 - 100, this.height / 4 + 120 + 12).size(200, 20).build());
- }
-
- @Override
- public void tick() {
- if (!this.aborted)
- if (this.getRemainingTime() <= 0) {
- this.aborted = true;
- NoChatReportsClient.reconnectLastServer();
- }
- }
-
- @Override
- public void render(PoseStack poseStack, int i, int j, float f) {
- this.renderBackground(poseStack);
- Component status = Component.translatable("nochatreports.connect.await", (this.getRemainingTime()) / 1000L);
- ConnectScreen.drawCenteredString(poseStack, this.font, Component.translatable("nochatreports.connect.nokey_rejected"), this.width / 2, this.height / 2 - 50, 0xFFFFFF);
- ConnectScreen.drawCenteredString(poseStack, this.font, status, this.width / 2, this.height / 2 - 36, 0xFFFFFF);
- super.render(poseStack, i, j, f);
- }
-
- private long getRemainingTime() {
- long current = Util.getMillis();
- long disconnect = ServerSafetyState.getDisconnectMillis();
-
- if (current - disconnect <= this.getDisconnectAwaitTime() + 100L)
- return this.getDisconnectAwaitTime() - (current - disconnect);
- else
- return this.getAwaitTime() - (current - this.millisAwaiting);
- }
-
- private long getDisconnectAwaitTime() {
- return NCRConfig.getClient().getPostDisconnectAwaitSeconds() * 1000L;
- }
-
- private long getAwaitTime() {
- return NCRConfig.getClient().getReconnectAwaitSeconds() * 1000L;
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java b/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java
index 2511ccb..68e2a07 100644
--- a/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java
@@ -47,29 +47,28 @@ public final class UnsafeServerScreen extends WarningScreen {
@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(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());
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/AccessorDisconnectedScreen.java b/src/main/java/com/aizistral/nochatreports/mixins/client/AccessorDisconnectedScreen.java
deleted file mode 100644
index e6e5205..0000000
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/AccessorDisconnectedScreen.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.aizistral.nochatreports.mixins.client;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.gen.Accessor;
-
-import com.aizistral.nochatreports.NoChatReportsClient;
-import com.aizistral.nochatreports.gui.UnsafeServerScreen;
-
-import net.minecraft.client.gui.screens.DisconnectedScreen;
-import net.minecraft.network.chat.Component;
-
-@Mixin(DisconnectedScreen.class)
-public interface AccessorDisconnectedScreen {
-
- /**
- * @return Disconnect reason of this screen. This is used in {@link NoChatReportsClient} to detect
- * when player have been kicked out of server because client refused to send account's public key,
- * and subsequently swap the screen for {@link UnsafeServerScreen} where player can choose to
- * reconnect and expose their key.
- */
-
- @Accessor
- public Component getReason();
-
-}
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 a325e1b..3c4cc5c 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinChatListener.java
@@ -47,9 +47,9 @@ public class MixinChatListener {
} else {
var evaluate = ChatTrustLevel.evaluate(playerChatMessage, component, instant);
- if (evaluate == ChatTrustLevel.NOT_SECURE && NCRConfig.getClient().hideRedChatIndicators()) {
+ if (evaluate == ChatTrustLevel.NOT_SECURE && NCRConfig.getClient().hideInsecureMessageIndicators()) {
info.setReturnValue(ChatTrustLevel.SECURE);
- } else if (evaluate == ChatTrustLevel.MODIFIED && NCRConfig.getClient().hideYellowChatIndicators()) {
+ } else if (evaluate == ChatTrustLevel.MODIFIED && NCRConfig.getClient().hideModifiedMessageIndicators()) {
info.setReturnValue(ChatTrustLevel.SECURE);
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinClientboundHelloPacket.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinClientboundHelloPacket.java
deleted file mode 100644
index 82df5af..0000000
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinClientboundHelloPacket.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.aizistral.nochatreports.mixins.client;
-
-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.CallbackInfo;
-
-import com.aizistral.nochatreports.config.NCRConfig;
-import com.aizistral.nochatreports.core.ServerSafetyLevel;
-import com.aizistral.nochatreports.core.ServerSafetyState;
-
-import net.minecraft.network.protocol.login.ClientLoginPacketListener;
-import net.minecraft.network.protocol.login.ClientboundHelloPacket;
-
-@Mixin(ClientboundHelloPacket.class)
-public class MixinClientboundHelloPacket {
-
- /**
- * @reason If server is operated in the offline mode - we will never receive this type of packet
- * from it, which allows us to conclude we have no necessity to expose account's public key.
- * By acknowledging this we can update current {@link ServerSafetyLevel} accordingly.
- * @author Aizistral
- */
-
- @Inject(method = "handle", at = @At("HEAD"))
- private void onHandle(ClientLoginPacketListener listener, CallbackInfo info) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- ServerSafetyState.setSessionRequestedKey(true);
- }
-
-}
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 947729d..2788cbd 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinConnectScreen.java
@@ -23,7 +23,7 @@ public class MixinConnectScreen {
/**
* @reason Intercept initiation of any new server connection. This way we can keep track of which
- * server client currently tries to connect to
+ * server client currently tries to connect to.
* @author Aizistral
*/
@@ -34,18 +34,10 @@ public class MixinConnectScreen {
return;
ServerSafetyState.updateCurrent(ServerSafetyLevel.UNDEFINED); // just to be 100% sure
- ServerSafetyState.setLastConnectedServer(serverAddress, serverData);
-
- if (NCRConfig.getServerWhitelist().isWhitelisted(serverAddress)) {
- if (!NCRConfig.getClient().doSigningCheck(serverAddress)) {
- ServerSafetyState.setAllowsUnsafeServer(true);
- }
- }
if (NCRConfig.getCommon().enableDebugLog()) {
- NoChatReports.LOGGER.info("Connecting to: {}, will expose public key: {}",
- serverAddress.getHost() + ":" + serverAddress.getPort(),
- ServerSafetyState.allowsUnsafeServer());
+ NoChatReports.LOGGER.info("Connecting to: {}",
+ serverAddress.getHost() + ":" + serverAddress.getPort());
NoChatReports.LOGGER.info("Server Data IP: {}", serverData != null ? serverData.ip : "null");
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java
index 1c18c61..0b3ca1a 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinGuiMessageTag.java
@@ -24,7 +24,7 @@ public class MixinGuiMessageTag {
@Inject(method = "system", at = @At("HEAD"), cancellable = true)
private static void onSystem(CallbackInfoReturnable<GuiMessageTag> info) {
- if (NCRConfig.getClient().hideGrayChatIndicators()) {
+ if (NCRConfig.getClient().hideSystemMessageIndicators()) {
info.setReturnValue(null);
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinLocalPlayer.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinLocalPlayer.java
deleted file mode 100644
index 9e43d68..0000000
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinLocalPlayer.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.aizistral.nochatreports.mixins.client;
-
-import javax.annotation.Nullable;
-
-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 com.aizistral.nochatreports.config.NCRConfig;
-import com.aizistral.nochatreports.core.ServerSafetyState;
-import com.mojang.brigadier.ParseResults;
-
-import net.minecraft.client.player.LocalPlayer;
-import net.minecraft.commands.SharedSuggestionProvider;
-import net.minecraft.commands.arguments.ArgumentSignatures;
-import net.minecraft.network.chat.ChatMessageContent;
-import net.minecraft.network.chat.Component;
-import net.minecraft.network.chat.LastSeenMessages;
-import net.minecraft.network.chat.MessageSignature;
-import net.minecraft.network.chat.MessageSigner;
-
-@Mixin(LocalPlayer.class)
-public class MixinLocalPlayer {
-
- /**
- * @reason Never sign messages, so that neither server nor other clients have
- * proof of them being sent from your account.
- * @author Aizistral
- */
-
- @Inject(method = "signMessage", at = @At("HEAD"), cancellable = true)
- private void onSignMessage(MessageSigner signer, ChatMessageContent message, LastSeenMessages messages, CallbackInfoReturnable<MessageSignature> info) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- if (!ServerSafetyState.forceSignedMessages()) {
- info.setReturnValue(MessageSignature.EMPTY);
- }
- }
-
- /**
- * @reason Same as above, except commands mostly concern only server.
- * @author Aizistral
- */
-
- @Inject(method = "signCommandArguments", at = @At("HEAD"), cancellable = true)
- private void onSignCommand(MessageSigner signer, ParseResults<SharedSuggestionProvider> results, @Nullable Component component, LastSeenMessages messages, CallbackInfoReturnable<ArgumentSignatures> info) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- if (!ServerSafetyState.forceSignedMessages()) {
- info.setReturnValue(ArgumentSignatures.EMPTY);
- }
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinMinecraft.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinMinecraft.java
new file mode 100644
index 0000000..952f5fd
--- /dev/null
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinMinecraft.java
@@ -0,0 +1,23 @@
+package com.aizistral.nochatreports.mixins.client;
+
+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 com.aizistral.nochatreports.core.ServerSafetyState;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.multiplayer.ProfileKeyPairManager;
+
+@Mixin(Minecraft.class)
+public class MixinMinecraft {
+
+ @Inject(method = "getProfileKeyPairManager", at = @At("HEAD"), cancellable = true)
+ private void onGetProfileKeyPairManager(CallbackInfoReturnable<ProfileKeyPairManager> info) {
+ if (!ServerSafetyState.allowChatSigning()) {
+ info.setReturnValue(ProfileKeyPairManager.EMPTY_KEY_MANAGER);
+ }
+ }
+
+}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinProfileKeyPairManager.java b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinProfileKeyPairManager.java
deleted file mode 100644
index 407a7ed..0000000
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinProfileKeyPairManager.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package com.aizistral.nochatreports.mixins.client;
-
-import java.util.Optional;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Group;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-
-import com.aizistral.nochatreports.config.NCRConfig;
-import com.aizistral.nochatreports.core.ServerSafetyState;
-import com.mojang.authlib.yggdrasil.response.KeyPairResponse;
-
-import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl;
-import net.minecraft.client.multiplayer.ProfileKeyPairManager;
-import net.minecraft.util.Signer;
-import net.minecraft.world.entity.player.ProfilePublicKey;
-
-@Mixin(ProfileKeyPairManager.class)
-public class MixinProfileKeyPairManager {
-
- /**
- * @reason Prevent the client from exposing its public key, unless it is necessary
- * and user agreed to do so.
- * @author Aizistral
- */
-
- @Inject(method = "profilePublicKey", at = @At("HEAD"), cancellable = true)
- private void onProfilePublicKey(CallbackInfoReturnable<Optional<ProfilePublicKey>> info) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- if (!ServerSafetyState.allowsUnsafeServer()) {
- info.setReturnValue(Optional.empty());
- }
- }
-
- /**
- * @reason Prevent the client from exposing its public key, unless it is necessary
- * and user agreed to do so.
- * @author Aizistral
- */
-
- @Group(min = 1, max = 2)
- @Inject(method = "parsePublicKey", at = @At("HEAD"), cancellable = true)
- private static void onParsePublicKey(KeyPairResponse response, CallbackInfoReturnable<ProfilePublicKey.Data> info) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- if (!ServerSafetyState.allowsUnsafeServer()) {
- info.setReturnValue(null);
- }
- }
-
- /**
- * @reason Accomplishes the same thing as {@link #onParsePublicKey(KeyPairResponse, CallbackInfoReturnable)},
- * but only in 1.19.1.
- * @author Aizistral
- */
-
- @Group(min = 1, max = 2)
- @Inject(method = { "profilePublicKeyData", "method_43784" }, at = @At("HEAD"), cancellable = true, remap = false)
- private void onProfilePublicKeyData(CallbackInfoReturnable<Optional<ProfilePublicKey.Data>> info) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- if (!ServerSafetyState.allowsUnsafeServer()) {
- info.setReturnValue(Optional.empty());
- }
- }
-
- /**
- * @reason Prevent client from trying to produce signature in
- * {@link ClientHandshakePacketListenerImpl#handleHello}.
- * @author Aizistral
- */
-
- @Inject(method = "signer", at = @At("HEAD"), cancellable = true)
- private void onSigner(CallbackInfoReturnable<Optional<Signer>> info) {
- if (!NCRConfig.getClient().enableMod())
- return;
-
- if (!ServerSafetyState.allowsUnsafeServer()) {
- info.setReturnValue(null);
- }
- }
-
-}
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 5fd58dd..f6f735a 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/client/MixinRealmsConnect.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/client/MixinRealmsConnect.java
@@ -26,9 +26,7 @@ public class MixinRealmsConnect {
if (!NCRConfig.getClient().enableMod())
return;
- ServerSafetyState.setLastConnectedServer(serverAddress, null);
ServerSafetyState.updateCurrent(ServerSafetyLevel.REALMS);
- ServerSafetyState.setAllowsUnsafeServer(true);
}
}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinPlayer.java b/src/main/java/com/aizistral/nochatreports/mixins/server/MixinPlayer.java
deleted file mode 100644
index 1065a5a..0000000
--- a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinPlayer.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.aizistral.nochatreports.mixins.server;
-
-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 net.minecraft.world.entity.player.Player;
-import net.minecraft.world.entity.player.ProfilePublicKey;
-
-@Mixin(Player.class)
-public class MixinPlayer {
-
- /**
- * @reason Prevents server from trying to validate signatures on incoming
- * chat messages. Also prevents it from relaying public keys to other clients.
- * @author Aizistral
- */
-
- @Inject(method = "getProfilePublicKey", at = @At("HEAD"), cancellable = true)
- private void onGetProfileKey(CallbackInfoReturnable<ProfilePublicKey> info) {
- info.setReturnValue(null);
- }
-
-}
diff --git a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java b/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java
index d9332c1..44b3284 100644
--- a/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java
+++ b/src/main/java/com/aizistral/nochatreports/mixins/server/MixinServerboundChatPacket.java
@@ -20,7 +20,7 @@ public class MixinServerboundChatPacket {
@Inject(method = "signature", at = @At("RETURN"), cancellable = true)
private void onGetSignature(CallbackInfoReturnable<MessageSignature> info) {
- info.setReturnValue(MessageSignature.EMPTY);
+ info.setReturnValue(null);
}
}