forked from ChomeNS/chomens-bot-java
section signs validation for the funny reason
This commit is contained in:
parent
b7ff56e28d
commit
dc6c159db3
3 changed files with 37 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue