mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 07:37:43 +00:00
Enhance the default permissions logic
This commit is contained in:
parent
21478b0a33
commit
1adffc21c0
@ -41,10 +41,6 @@ public final class DefaultAuthenticators {
|
||||
responseMessage = translate("messages.dispatch.account.username_create_error");
|
||||
Grasscutter.getLogger().info(translate("messages.dispatch.account.account_login_create_error", address));
|
||||
} else {
|
||||
// Add default permissions.
|
||||
for (var permission : ACCOUNT.defaultPermissions)
|
||||
account.addPermission(permission);
|
||||
|
||||
// Continue with login.
|
||||
successfulLogin = true;
|
||||
|
||||
|
@ -1,14 +1,12 @@
|
||||
package emu.grasscutter.game;
|
||||
|
||||
import dev.morphia.annotations.*;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.utils.Crypto;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
@ -144,17 +142,22 @@ public class Account {
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
|
||||
if (this.permissions.contains(permission)) return true;
|
||||
if(this.permissions.contains("*") && this.permissions.size() == 1) return true;
|
||||
|
||||
// Add default permissions if it doesn't exist
|
||||
List<String> permissions = Stream.of(this.permissions, Arrays.asList(ACCOUNT.defaultPermissions))
|
||||
.flatMap(Collection::stream)
|
||||
.distinct().toList();
|
||||
|
||||
if (permissions.contains(permission)) return true;
|
||||
|
||||
String[] permissionParts = permission.split("\\.");
|
||||
for (String p : this.permissions) {
|
||||
for (String p : permissions) {
|
||||
if (p.startsWith("-") && permissionMatchesWildcard(p.substring(1), permissionParts)) return false;
|
||||
if (permissionMatchesWildcard(p, permissionParts)) return true;
|
||||
}
|
||||
|
||||
return this.permissions.contains("*");
|
||||
return permissions.contains("*");
|
||||
}
|
||||
|
||||
public boolean removePermission(String permission) {
|
||||
|
@ -32,7 +32,7 @@ public final class GachaHandler implements Router {
|
||||
private final String gachaMappings;
|
||||
|
||||
public GachaHandler() {
|
||||
this.gachaMappings = Utils.toFilePath(DATA("/gacha/mappings.js"));
|
||||
this.gachaMappings = Utils.toFilePath(DATA("gacha/mappings.js"));
|
||||
if(!(new File(this.gachaMappings).exists())) {
|
||||
try {
|
||||
Tools.createGachaMapping(this.gachaMappings);
|
||||
|
Loading…
Reference in New Issue
Block a user