diff options
7 files changed, 157 insertions, 1 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/NoChatReports.java b/src/main/java/com/aizistral/nochatreports/NoChatReports.java index 05c4ae4..f8492e5 100644 --- a/src/main/java/com/aizistral/nochatreports/NoChatReports.java +++ b/src/main/java/com/aizistral/nochatreports/NoChatReports.java @@ -22,6 +22,11 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerGamePacketListenerImpl; +/** + * Common initializer for the mod. Some networking and config setup here. + * @author Aizistral + */ + public class NoChatReports implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger(); public static final ResourceLocation CHANNEL = new ResourceLocation("nochatreports", "sync"); diff --git a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java index 7e3b852..0d3e485 100644 --- a/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java +++ b/src/main/java/com/aizistral/nochatreports/NoChatReportsClient.java @@ -30,6 +30,11 @@ import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.contents.TranslatableContents; +/** + * Client initializer for the mod. Some networking setup here, as well as few screen-related events. + * @author Aizistral + */ + @Environment(EnvType.CLIENT) public class NoChatReportsClient implements ClientModInitializer { private static final List<String> KEY_DISCONNECT_REASONS = ImmutableList.of( diff --git a/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java b/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java index 1a35202..384ab08 100644 --- a/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java +++ b/src/main/java/com/aizistral/nochatreports/core/NoReportsConfig.java @@ -12,6 +12,8 @@ import java.util.List; import javax.annotation.Nullable; import com.aizistral.nochatreports.NoChatReports; +import com.aizistral.nochatreports.gui.UnsafeServerScreen; +import com.aizistral.nochatreports.mixins.client.MixinChatListener; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; @@ -22,6 +24,16 @@ import net.minecraft.client.multiplayer.chat.ChatTrustLevel; import net.minecraft.client.multiplayer.resolver.ServerAddress; import net.minecraft.util.Tuple; +/** + * Simple implementation of JSON-config for the mod. Can be loaded at any time and does not depend + * on modloader-specific API. The only disadvantage is that we don't get to comment options.<br><br> + * + * For now, the config file is called <code>NoChatReports.json</code> and is located in default config + * folder. In the future this should be separated into client and server configs. + * + * @author Aizistral + */ + public class NoReportsConfig { private static final Path CONFIG_FILE = FabricLoader.getInstance().getConfigDir().resolve("NoChatReports.json"); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); @@ -38,6 +50,11 @@ public class NoReportsConfig { return INSTANCE; } + /** + * Loads (or reloads) the config from local file, or creates default one if that fails. + * Re-searializes validated {@link #INSTANCE} object back into the file. + */ + public static void loadConfig() { NoChatReports.LOGGER.info(INSTANCE == null ? "Loading config..." : "Reloading config..."); @@ -54,6 +71,10 @@ public class NoReportsConfig { writeFile(INSTANCE); } + /** + * Writes current config instance into local file. + */ + public static void saveConfig() { if (INSTANCE != null) { writeFile(INSTANCE); @@ -80,38 +101,108 @@ public class NoReportsConfig { } } + /** + * @return True if server with No Chat Reports installed should demand that mod is present on + * every client that tries to join. Mod's installation on client is optional otherwise.<br><br> + * + * This is false by default. + */ + public static boolean demandsOnClient() { return getInstance().demandOnClient; } + /** + * @return True if client with No Chat Reports installed should demand that mod is present on + * every server that it tries to join. In that case client will not be able to join servers that + * don't have the mod installed. Servers without the mod can still provide varying degrees of + * safety, which {@link ServerSafetyLevel} and respective icon in bottom-right corner of the chat + * screen is designed to indicate.<br><br> + * + * This is false by default. + */ + public static boolean demandsOnServer() { return getInstance().demandOnServer; } + /** + * @return True if server should convert all player messages to system messages. System messages + * do not feature signatures and look completely identical in the chat, with exception of gray line + * next to them added in pre-release 3. They are also unselectable for chat reporting.<br><br> + * + * This is true by default. + */ + public static boolean convertToGameMessage() { return getInstance().convertToGameMessage; } + /** + * @return True if current {@link ServerSafetyLevel} should be indicated on client by an icon in + * the bottom-right corner of chat screen.<br><br> + * + * This is true by default. + */ + public static boolean showServerSafety() { return getInstance().showServerSafety; } + /** + * @return Current list of whitelisted unsafe servers. Used on client to remember which servers + * user disabled unsafety warnings for.<br><br> + * + * This is empty by default. + * + * @see UnsafeServerScreen + */ + public static List<String> getWhitelistedServers() { return getInstance().whitelistedServers; } + /** + * @param address Address of the server to be check. + * @return Whether this server is in the whitelist of unsafe servers, as returned by + * {@link #getWhitelistedServers()}. + * @see UnsafeServerScreen + */ + public static boolean isWhitelistedServer(ServerAddress address) { return getWhitelistedServers().contains(address.getHost() + ":" + address.getPort()); } + /** + * @return True if vanilla's Chat Trust Status indicators should be removed.<br><br> + * + * This is true by default. + * + * @see MixinChatListener#onEvaluateTrustLevel + */ + public static boolean suppressMessageTrustIndicators() { return getInstance().suppressMessageTrustIndicators; } + /** + * @return True if mod should log some additional information about its activity and message + * signatures. Generally only useful for debugging.<br><br> + * + * This is false by default. + */ + public static boolean isDebugLogEnabled() { return getInstance().enableDebugLog; } + /** + * @return True if reporting buttons should always be hidden from social interactions screen, + * instead of simply being disabled.<br><br> + * + * This is false by default. + */ + public static boolean alwaysHideReportButton() { return getInstance().alwaysHideReportButton; } diff --git a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java index d6d0db5..bc324b5 100644 --- a/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java +++ b/src/main/java/com/aizistral/nochatreports/core/ServerSafetyLevel.java @@ -8,8 +8,42 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.network.chat.Component; +/** + * Represents the level of "safety" of the given server, in the eyes of the client. + * Current level is updated dynamically and can be obtained using {@link ServerSafetyState#getCurrent()}. + * @author Aizistral + */ + public enum ServerSafetyLevel { - SECURE, UNINTRUSIVE, INSECURE, UNKNOWN; + + /** + * For servers that have No Chat Reports or something of similar purpose installed, and make + * verifiable effort to remove cryptographic signature from every player message they relay. + */ + SECURE, + + + /** + * For servers that do not make any effort to remove signatures from chat messages themselves, + * but do not prohibit players from sending unsigned messages. To protect the player falls fully + * on the client of respective player in such case, and vanilla client will not do that. + */ + UNINTRUSIVE, + + /** + * For servers that have <code>enforce-secure-profile</code> enabled, or enforce signed messages + * through some other meands. Users of this mod can choose to play on those servers regardless + * after being informed of danger, but there is very little mod will be able to do to protect + * them in such case. + */ + + INSECURE, + + /** + * Transient status for when evaluation of safety level is not yet complete for current server. + */ + + UNKNOWN; @Environment(EnvType.CLIENT) public Component getTooltip() { diff --git a/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java b/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java index a51fc45..a7ce28a 100644 --- a/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java +++ b/src/main/java/com/aizistral/nochatreports/gui/UnsafeServerScreen.java @@ -20,6 +20,17 @@ 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 class UnsafeServerScreen extends WarningScreen { private static final Component TITLE = Component.translatable("gui.nochatreports.unsafe_server.header").withStyle(ChatFormatting.BOLD); diff --git a/src/main/java/com/aizistral/nochatreports/network/ClientChannelHandler.java b/src/main/java/com/aizistral/nochatreports/network/ClientChannelHandler.java index 179a090..1166a40 100644 --- a/src/main/java/com/aizistral/nochatreports/network/ClientChannelHandler.java +++ b/src/main/java/com/aizistral/nochatreports/network/ClientChannelHandler.java @@ -11,6 +11,11 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; +/** + * Mod's client channel handler. So far just passively exists. + * @author Aizistral + */ + @Environment(EnvType.CLIENT) public class ClientChannelHandler implements PlayChannelHandler { public static final ClientChannelHandler INSTANCE = new ClientChannelHandler(); diff --git a/src/main/java/com/aizistral/nochatreports/network/ServerChannelHandler.java b/src/main/java/com/aizistral/nochatreports/network/ServerChannelHandler.java index c649e71..faa7fe6 100644 --- a/src/main/java/com/aizistral/nochatreports/network/ServerChannelHandler.java +++ b/src/main/java/com/aizistral/nochatreports/network/ServerChannelHandler.java @@ -7,6 +7,11 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; +/** + * Mod's server channel handler. So far just passively exists. + * @author Aizistral + */ + public class ServerChannelHandler implements PlayChannelHandler { public static final ServerChannelHandler INSTANCE = new ServerChannelHandler(); |
