Add config option to allow invalid usernames (#516)

This commit is contained in:
Luck 2017-10-22 09:00:10 +01:00
parent 6e429d6c78
commit ecfbed00b1
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
8 changed files with 63 additions and 11 deletions

View File

@ -70,6 +70,12 @@ use-server-uuids: true
# in the LuckPerms cache.
use-server-uuid-cache: false
# If set to true, LuckPerms will allow usernames with non alphanumeric characters.
#
# Note that due to the design of the storage implementation, usernames must still be
# 16 characters or less.
allow-invalid-usernames: false
# If LuckPerms should produce extra logging output when it handles logins.
# Useful if you're having issues with UUID forwarding or data not being loaded.
debug-logins: false

View File

@ -73,6 +73,12 @@ use-server-uuids: true
# try to find a uuid for a username using RedisBungee, if installed.
use-server-uuid-cache: false
# If set to true, LuckPerms will allow usernames with non alphanumeric characters.
#
# Note that due to the design of the storage implementation, usernames must still be
# 16 characters or less.
allow-invalid-usernames: false
# If LuckPerms should produce extra logging output when it handles logins.
# Useful if you're having issues with UUID forwarding or data not being loaded.
debug-logins: false

View File

@ -73,9 +73,16 @@ public class LogRecent extends SubCommand<Log> {
final String target = args.get(0);
UUID uuid = Util.parseUuid(target.toLowerCase());
if (uuid == null) {
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return CommandResult.INVALID_ARGS;
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return CommandResult.INVALID_ARGS;
}
} else {
if (!DataConstraints.PLAYER_USERNAME_TEST_LENIENT.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return CommandResult.INVALID_ARGS;
}
}
uuid = plugin.getStorage().getUUID(target.toLowerCase()).join();

View File

@ -68,22 +68,29 @@ public class LogUserHistory extends SubCommand<Log> {
UUID uuid = Util.parseUuid(target.toLowerCase());
if (uuid == null) {
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return null;
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return CommandResult.INVALID_ARGS;
}
} else {
if (!DataConstraints.PLAYER_USERNAME_TEST_LENIENT.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return CommandResult.INVALID_ARGS;
}
}
uuid = plugin.getStorage().getUUID(target.toLowerCase()).join();
if (uuid == null) {
if (!plugin.getConfiguration().get(ConfigKeys.USE_SERVER_UUID_CACHE)) {
Message.USER_NOT_FOUND.send(sender, target);
return null;
return CommandResult.INVALID_ARGS;
}
uuid = plugin.lookupUuid(target).orElse(null);
if (uuid == null) {
Message.USER_NOT_FOUND.send(sender, target);
return null;
return CommandResult.INVALID_ARGS;
}
}
}

View File

@ -83,9 +83,16 @@ public class UserMainCommand extends MainCommand<User, UserIdentifier> {
protected UserIdentifier parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
UUID uuid = Util.parseUuid(target.toLowerCase());
if (uuid == null) {
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return null;
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return null;
}
} else {
if (!DataConstraints.PLAYER_USERNAME_TEST_LENIENT.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
return null;
}
}
uuid = plugin.getStorage().getUUID(target.toLowerCase()).join();

View File

@ -122,6 +122,11 @@ public class ConfigKeys {
*/
public static final ConfigKey<Boolean> USE_SERVER_UUID_CACHE = BooleanKey.of("use-server-uuid-cache", false);
/**
* If LuckPerms should allow usernames with non alphanumeric characters.
*/
public static final ConfigKey<Boolean> ALLOW_INVALID_USERNAMES = BooleanKey.of("allow-invalid-usernames", false);
/**
* If LuckPerms should produce extra logging output when it handles logins.
*/

View File

@ -68,6 +68,14 @@ public class DataConstraints {
return true;
};
public static final Predicate<String> PLAYER_USERNAME_TEST_LENIENT = s -> {
if (s.length() <= 0 || s.length() > MAX_PLAYER_USERNAME_LENGTH) {
return false;
}
return true;
};
public static final Predicate<String> GROUP_NAME_TEST = s -> {
if (s.length() <= 0 || s.length() > MAX_GROUP_NAME_LENGTH) {
return false;

View File

@ -69,6 +69,12 @@ use-server-uuids=true
# in the LuckPerms cache.
use-server-uuid-cache=false
# If set to true, LuckPerms will allow usernames with non alphanumeric characters.
#
# Note that due to the design of the storage implementation, usernames must still be
# 16 characters or less.
allow-invalid-usernames=false
# If LuckPerms should produce extra logging output when it handles logins.
# Useful if you're having issues with UUID forwarding or data not being loaded.
debug-logins=false