diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java index 5c1284c..c992bc9 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java @@ -25,8 +25,15 @@ public class ValidateCommand extends Command { final String hash = fullArgs[0]; - if (hash.equals(bot.hashing.getHash(context.splitInput[0], context.sender))) return Component.text("Valid hash").color(NamedTextColor.GREEN); - else if (hash.equals(bot.hashing.getOwnerHash(context.splitInput[0], context.sender))) return Component.text("Valid OwnerHash").color(NamedTextColor.GREEN); + if ( + hash.equals(bot.hashing.getHash(context.splitInput[0], context.sender, true)) || + hash.equals(bot.hashing.getHash(context.splitInput[0], context.sender, false)) + ) return Component.text("Valid hash").color(NamedTextColor.GREEN); + + else if ( + hash.equals(bot.hashing.getOwnerHash(context.splitInput[0], context.sender, true)) || + hash.equals(bot.hashing.getOwnerHash(context.splitInput[0], context.sender, false)) + ) return Component.text("Valid OwnerHash").color(NamedTextColor.GREEN); return null; } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index f5de2e8..46d1feb 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -143,13 +143,17 @@ public class CommandHandlerPlugin { } else { if ( command.trustLevel == TrustLevel.TRUSTED && - !userHash.equals(bot.hashing.getHash(splitInput[0], context.sender)) && - !userHash.equals(bot.hashing.getOwnerHash(splitInput[0], context.sender)) + // mess? + !userHash.equals(bot.hashing.getHash(splitInput[0], context.sender, true)) && + !userHash.equals(bot.hashing.getOwnerHash(splitInput[0], context.sender, true)) && + !userHash.equals(bot.hashing.getHash(splitInput[0], context.sender, false)) && + !userHash.equals(bot.hashing.getOwnerHash(splitInput[0], context.sender, false)) ) return Component.text("Invalid hash").color(NamedTextColor.RED); if ( command.trustLevel == TrustLevel.OWNER && - !userHash.equals(bot.hashing.getOwnerHash(splitInput[0], context.sender)) + !userHash.equals(bot.hashing.getOwnerHash(splitInput[0], context.sender, false)) && + !userHash.equals(bot.hashing.getOwnerHash(splitInput[0], context.sender, true)) ) return Component.text("Invalid OwnerHash").color(NamedTextColor.RED); } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/HashingPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/HashingPlugin.java index 9bfd6ca..498e8ff 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/HashingPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/HashingPlugin.java @@ -5,6 +5,7 @@ import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.data.chat.PlayerEntry; import java.nio.charset.StandardCharsets; +import java.util.Arrays; public class HashingPlugin { private final Bot bot; @@ -13,29 +14,45 @@ public class HashingPlugin { this.bot = bot; } - public String getHash (String prefix, PlayerEntry sender) { + public String getHash (String prefix, PlayerEntry sender, boolean sectionSigns) { final long time = System.currentTimeMillis() / 5_000; final String key = bot.config.keys.normalKey; final String hashValue = sender.profile.getIdAsString() + prefix + time + key; - return Hashing.sha256() + final String hash = Hashing.sha256() .hashString(hashValue, StandardCharsets.UTF_8) .toString() .substring(0, 16); + + return sectionSigns ? + String.join("", + Arrays.stream(hash.split("")) + .map((letter) -> "§" + letter) + .toArray(String[]::new) + ) : + hash; } - public String getOwnerHash (String prefix, PlayerEntry sender) { + public String getOwnerHash (String prefix, PlayerEntry sender, boolean sectionSigns) { final long time = System.currentTimeMillis() / 5_000; final String key = bot.config.keys.ownerKey; final String value = sender.profile.getIdAsString() + prefix + time + key; - return Hashing.sha256() + final String hash = Hashing.sha256() .hashString(value, StandardCharsets.UTF_8) .toString() .substring(0, 16); + + return sectionSigns ? + String.join("", + Arrays.stream(hash.split("")) + .map((letter) -> "§" + letter) + .toArray(String[]::new) + ) : + hash; } }