summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/java/com/aizistral/nochatreports/debug/NoChatReportsDebug.java48
-rw-r--r--src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java38
-rw-r--r--src/test/java/com/aizistral/nochatreports/debug/UnrealPlayer.java58
-rw-r--r--src/test/java/com/aizistral/nochatreports/debug/mixins/MixinAbuseReportSenderServices.java33
-rw-r--r--src/test/java/com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java19
-rw-r--r--src/test/resources/fabric.mod.json36
-rw-r--r--src/test/resources/nochatreportstest.mixins.json18
7 files changed, 250 insertions, 0 deletions
diff --git a/src/test/java/com/aizistral/nochatreports/debug/NoChatReportsDebug.java b/src/test/java/com/aizistral/nochatreports/debug/NoChatReportsDebug.java
new file mode 100644
index 0000000..f9f49ba
--- /dev/null
+++ b/src/test/java/com/aizistral/nochatreports/debug/NoChatReportsDebug.java
@@ -0,0 +1,48 @@
+package com.aizistral.nochatreports.debug;
+
+import java.util.UUID;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import com.aizistral.nochatreports.NoChatReports;
+import com.aizistral.nochatreports.handlers.NoReportsConfig;
+import com.aizistral.nochatreports.network.ServerChannelHandler;
+import com.mojang.authlib.GameProfile;
+import com.mojang.authlib.minecraft.UserApiService;
+
+import net.fabricmc.api.ClientModInitializer;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.ModInitializer;
+import net.fabricmc.fabric.api.networking.v1.PacketSender;
+import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
+import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
+import net.fabricmc.loader.api.FabricLoader;
+import net.minecraft.client.gui.screens.TitleScreen;
+import net.minecraft.client.gui.screens.reporting.ChatReportScreen;
+import net.minecraft.client.multiplayer.chat.LoggedChat;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
+import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket.Action;
+import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket.PlayerUpdate;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.server.network.ServerGamePacketListenerImpl;
+
+public class NoChatReportsDebug implements ModInitializer {
+ @Override
+ public void onInitialize() {
+ ServerPlayConnectionEvents.JOIN.register(this::onPlayReady);
+ }
+
+ private void onPlayReady(ServerGamePacketListenerImpl handler, PacketSender sender, MinecraftServer server) {
+ server.execute(() -> {
+ UnrealPlayer.DEFAULT.join(server, handler);
+ UnrealPlayer.DEFAULT.sendMessage(server, handler, "Helo");
+ UnrealPlayer.DEFAULT.sendMessage(server, handler, "I am fake af");
+
+ NoChatReports.LOGGER.info("Unreal player deployed");
+ });
+ }
+}
diff --git a/src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java b/src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java
new file mode 100644
index 0000000..5e8ee0f
--- /dev/null
+++ b/src/test/java/com/aizistral/nochatreports/debug/ReportWriter.java
@@ -0,0 +1,38 @@
+package com.aizistral.nochatreports.debug;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Date;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.ibm.icu.text.SimpleDateFormat;
+import com.mojang.authlib.minecraft.client.ObjectMapper;
+import com.mojang.authlib.minecraft.report.AbuseReport;
+import com.mojang.authlib.yggdrasil.request.AbuseReportRequest;
+
+import net.fabricmc.loader.api.FabricLoader;
+
+public class ReportWriter {
+ private static final ObjectMapper MAPPER = ObjectMapper.create();
+ private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
+
+ public static void saveReport(AbuseReportRequest report) {
+ String string = MAPPER.writeValueAsString(report);
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_hh.mm.ss");
+ Path path = FabricLoader.getInstance().getGameDir().resolve("intercepted-reports/report-"
+ + format.format(Date.from(report.report.createdTime)) + ".json");
+ path.getParent().toFile().mkdirs();
+
+ try (BufferedWriter writer = Files.newBufferedWriter(path)) {
+ GSON.toJson(GSON.fromJson(string, Object.class), writer);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/test/java/com/aizistral/nochatreports/debug/UnrealPlayer.java b/src/test/java/com/aizistral/nochatreports/debug/UnrealPlayer.java
new file mode 100644
index 0000000..d28f07e
--- /dev/null
+++ b/src/test/java/com/aizistral/nochatreports/debug/UnrealPlayer.java
@@ -0,0 +1,58 @@
+package com.aizistral.nochatreports.debug;
+
+import java.time.Instant;
+import java.util.Optional;
+import java.util.UUID;
+
+import com.mojang.authlib.GameProfile;
+
+import net.minecraft.network.chat.ChatSender;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
+import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
+import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket.Action;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.server.network.ServerGamePacketListenerImpl;
+import net.minecraft.util.Crypt;
+
+/**
+ * Exists solely to help with testing some of the features of the mod.
+ * You can use this to trick client into thinking there is another player
+ * on server, and send chat messages as if they are from that player.
+ * <br><br>
+ * DON'T FORGET TO TURN "convertToGameMessage" OFF!
+ *
+ * @author Aizistral
+ */
+
+public class UnrealPlayer {
+ public static final UnrealPlayer DEFAULT = new UnrealPlayer(UUID.fromString("bfa45411-874a-4ee0-b3bd-00c716059d95"), "Aizistral");
+ private final UUID id;
+ private final String name;
+
+ public UnrealPlayer(UUID id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public void join(MinecraftServer server, ServerGamePacketListenerImpl connection) {
+ ClientboundPlayerInfoPacket packet = new ClientboundPlayerInfoPacket(Action.ADD_PLAYER,
+ new ServerPlayer(server, server.overworld(), new GameProfile(this.id, this.name), null));
+ connection.send(packet);
+ }
+
+ public void leave(MinecraftServer server, ServerGamePacketListenerImpl connection) {
+ ClientboundPlayerInfoPacket packet = new ClientboundPlayerInfoPacket(Action.REMOVE_PLAYER,
+ new ServerPlayer(server, server.overworld(), new GameProfile(this.id, this.name), null));
+ connection.send(packet);
+ }
+
+ public void sendMessage(MinecraftServer server, ServerGamePacketListenerImpl connection, String message) {
+ ClientboundPlayerChatPacket packet = new ClientboundPlayerChatPacket(Component.literal(message),
+ Optional.empty(), 0, new ChatSender(this.id, Component.literal(this.name)), Instant.now(),
+ Crypt.SaltSignaturePair.EMPTY);
+ connection.send(packet);
+ }
+
+}
diff --git a/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinAbuseReportSenderServices.java b/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinAbuseReportSenderServices.java
new file mode 100644
index 0000000..9ce6933
--- /dev/null
+++ b/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinAbuseReportSenderServices.java
@@ -0,0 +1,33 @@
+package com.aizistral.nochatreports.debug.mixins;
+
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Overwrite;
+import org.spongepowered.asm.mixin.Shadow;
+
+import com.aizistral.nochatreports.debug.ReportWriter;
+import com.mojang.authlib.minecraft.report.AbuseReport;
+import com.mojang.authlib.yggdrasil.request.AbuseReportRequest;
+import com.mojang.datafixers.util.Unit;
+
+import net.minecraft.client.multiplayer.chat.report.AbuseReportSender;
+import net.minecraft.client.multiplayer.chat.report.ReportEnvironment;
+
+@Mixin(AbuseReportSender.Services.class)
+public class MixinAbuseReportSenderServices {
+ @Shadow @Final
+ private ReportEnvironment environment;
+
+ @Overwrite
+ public CompletableFuture<Unit> send(UUID uuid, AbuseReport abuseReport) {
+ AbuseReportRequest abuseReportRequest = new AbuseReportRequest(uuid,
+ abuseReport, this.environment.clientInfo(), this.environment.thirdPartyServerInfo(),
+ this.environment.realmInfo());
+ ReportWriter.saveReport(abuseReportRequest);
+ return CompletableFuture.supplyAsync(() -> Unit.INSTANCE);
+ }
+
+}
diff --git a/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java b/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java
new file mode 100644
index 0000000..1f671ca
--- /dev/null
+++ b/src/test/java/com/aizistral/nochatreports/debug/mixins/MixinPlayerEntry.java
@@ -0,0 +1,19 @@
+package com.aizistral.nochatreports.debug.mixins;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Redirect;
+
+import net.minecraft.client.gui.screens.social.PlayerEntry;
+import net.minecraft.client.multiplayer.chat.report.AbuseReportSender;
+
+@Mixin(PlayerEntry.class)
+public class MixinPlayerEntry {
+
+ @Redirect(method = "<init>", at = @At(value = "INVOKE", target =
+ "Lnet/minecraft/client/multiplayer/chat/report/AbuseReportSender;isEnabled()Z"))
+ private boolean forceEnableReporting(AbuseReportSender sender) {
+ return true;
+ }
+
+}
diff --git a/src/test/resources/fabric.mod.json b/src/test/resources/fabric.mod.json
new file mode 100644
index 0000000..d364a5f
--- /dev/null
+++ b/src/test/resources/fabric.mod.json
@@ -0,0 +1,36 @@
+{
+ "schemaVersion": 1,
+ "id": "nochatreportstest",
+ "version": "${version}",
+
+ "name": "No Chat Reports Test",
+ "description": "Testmod",
+ "authors": [
+ "Aizistral"
+ ],
+ "contact": {
+ "homepage": "https://www.curseforge.com/minecraft/mc-mods/no-chat-reports",
+ "sources": "https://github.com/Aizistral-Studios/No-Chat-Reports"
+ },
+
+ "license": "WTFPL",
+ "icon": "NCR_logo.png",
+
+ "environment": "*",
+ "entrypoints": {
+ "main": [
+ "com.aizistral.nochatreports.debug.NoChatReportsDebug"
+ ]
+ },
+ "mixins": [
+ "nochatreportstest.mixins.json"
+ ],
+
+ "depends": {
+ "fabricloader": ">=0.14.6",
+ "fabric": "*",
+ "minecraft": "~1.19",
+ "java": ">=17"
+ },
+ "suggests": {}
+}
diff --git a/src/test/resources/nochatreportstest.mixins.json b/src/test/resources/nochatreportstest.mixins.json
new file mode 100644
index 0000000..f389b5e
--- /dev/null
+++ b/src/test/resources/nochatreportstest.mixins.json
@@ -0,0 +1,18 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "com.aizistral.nochatreports.debug.mixins",
+ "compatibilityLevel": "JAVA_17",
+ "verbose": true,
+ "mixins": [
+ ],
+ "client": [
+ "MixinPlayerEntry",
+ "MixinAbuseReportSenderServices"
+ ],
+ "server": [
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}