the custom chat format HASHING >...... :)

This commit is contained in:
Chayapak 2023-09-22 18:46:12 +07:00
parent 78689abe93
commit 706fff00d4
3 changed files with 20 additions and 4 deletions

View file

@ -25,7 +25,7 @@ public class Configuration {
public BotInfo hbot = new BotInfo("#", null); public BotInfo hbot = new BotInfo("#", null);
public BotInfo sbot = new BotInfo(":", null); public BotInfo sbot = new BotInfo(":", null);
public BotInfo chipmunk = new BotInfo("'", null); public BotInfo chipmunk = new BotInfo("'", null);
public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null); public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null);
public BotInfo kittycorp = new BotInfo("^", null); public BotInfo kittycorp = new BotInfo("^", null);
public TestBotInfo testbot = new TestBotInfo("-", null); public TestBotInfo testbot = new TestBotInfo("-", null);
} }
@ -34,11 +34,13 @@ public class Configuration {
public String prefix; public String prefix;
public String key; public String key;
public String authKey; public String authKey;
public String formatKey;
public ChomeNSBotInfo (String prefix, String key, String authKey) { public ChomeNSBotInfo (String prefix, String key, String authKey, String formatKey) {
this.prefix = prefix; this.prefix = prefix;
this.key = key; this.key = key;
this.authKey = authKey; this.authKey = authKey;
this.formatKey = formatKey;
} }
} }

View file

@ -1,5 +1,6 @@
package land.chipmunk.chipmunkmod.modules; package land.chipmunk.chipmunkmod.modules;
import com.google.common.hash.Hashing;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.ChipmunkMod;
@ -14,6 +15,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -73,6 +75,17 @@ public class CustomChat {
final Component deserialized = serializer.deserialize(message); final Component deserialized = serializer.deserialize(message);
final String messageWithColor = GsonComponentSerializer.gson().serialize(deserialized).replace("MESSAGE", randomized); final String messageWithColor = GsonComponentSerializer.gson().serialize(deserialized).replace("MESSAGE", randomized);
final long time = System.currentTimeMillis() / 10_000;
final String key = ChipmunkMod.CONFIG.bots.chomens.formatKey;
final String hash = key != null ?
Hashing.sha256()
.hashString(key + key + time + time, StandardCharsets.UTF_8)
.toString()
.substring(0, 8) :
"";
try { try {
// final MutablePlayerListEntry entry = Players.INSTANCE.getEntry(client.getNetworkHandler().getProfile().getId()); // final MutablePlayerListEntry entry = Players.INSTANCE.getEntry(client.getNetworkHandler().getProfile().getId());
@ -86,9 +99,10 @@ public class CustomChat {
// .replace("\"PREFIX\"", prefix) // .replace("\"PREFIX\"", prefix)
// .replace("\"DISPLAYNAME\"", displayName) // .replace("\"DISPLAYNAME\"", displayName)
.replace("USERNAME", username) .replace("USERNAME", username)
.replace("HASH", hash)
.replace("{\"text\":\"MESSAGE\"}", messageWithColor) .replace("{\"text\":\"MESSAGE\"}", messageWithColor)
.replace("\"extra\":[\"MESSAGE\"],\"color\":", "\"extra\":[" + messageWithColor + "],\"color\":") .replace("\"extra\":[\"MESSAGE\"],\"color\":", "\"extra\":[" + messageWithColor + "],\"color\":")
.replace("MESSAGE", sanitizedMessage.replaceAll("&.", "")) // TODO: make this not use regex .replace("MESSAGE", sanitizedMessage.replaceAll("&.", ""))
.replace(randomized, "MESSAGE"); // ohio ohio .replace(randomized, "MESSAGE"); // ohio ohio
CommandCore.INSTANCE.run((KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw @a " : "tellraw @a ") + sanitizedFormat); CommandCore.INSTANCE.run((KaboomCheck.INSTANCE.isKaboom ? "minecraft:tellraw @a " : "tellraw @a ") + sanitizedFormat);

View file

@ -14,7 +14,7 @@
"hbot": { "prefix": "#", "key": null }, "hbot": { "prefix": "#", "key": null },
"sbot": { "prefix": ":", "key": null }, "sbot": { "prefix": ":", "key": null },
"chipmunk": { "prefix": "'", "key": null }, "chipmunk": { "prefix": "'", "key": null },
"chomens": { "prefix": "*", "key": null, "authKey": null }, "chomens": { "prefix": "*", "key": null, "authKey": null, "formatKey": null },
"kittycorp": { "prefix": "^", "key": null }, "kittycorp": { "prefix": "^", "key": null },
"testbot": { "prefix": "-", "webhookUrl": null } "testbot": { "prefix": "-", "webhookUrl": null }
}, },