Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
f08a8971
Commit
f08a8971
authored
May 07, 2022
by
AnimeGitB
Committed by
Melledy
May 09, 2022
Browse files
Account permission wildcards
parent
80db118f
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/Account.java
View file @
f08a8971
package
emu.grasscutter.game
;
package
emu.grasscutter.game
;
import
dev.morphia.annotations.*
;
import
dev.morphia.annotations.*
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.utils.Crypto
;
import
emu.grasscutter.utils.Crypto
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
...
@@ -107,11 +108,41 @@ public class Account {
...
@@ -107,11 +108,41 @@ public class Account {
this
.
permissions
.
add
(
permission
);
return
true
;
this
.
permissions
.
add
(
permission
);
return
true
;
}
}
public
static
boolean
permissionMatchesWildcard
(
String
wildcard
,
String
[]
permissionParts
)
{
String
[]
wildcardParts
=
wildcard
.
split
(
"\\."
);
if
(
permissionParts
.
length
<
wildcardParts
.
length
)
{
// A longer wildcard can never match a shorter permission
return
false
;
}
for
(
int
i
=
0
;
i
<
wildcardParts
.
length
;
i
++)
{
switch
(
wildcardParts
[
i
])
{
case
"**"
:
// Recursing match
return
true
;
case
"*"
:
// Match only one layer
if
(
i
>=
(
permissionParts
.
length
-
1
))
{
return
true
;
}
break
;
default
:
// This layer isn't a wildcard, it needs to match exactly
if
(!
wildcardParts
[
i
].
equals
(
permissionParts
[
i
]))
{
return
false
;
}
}
}
// At this point the wildcard will have matched every layer, but if it is shorter then the permission then this is not a match at this point (no **).
return
(
wildcardParts
.
length
==
permissionParts
.
length
);
}
public
boolean
hasPermission
(
String
permission
)
{
public
boolean
hasPermission
(
String
permission
)
{
return
this
.
permissions
.
contains
(
permission
)
||
if
(
this
.
permissions
.
contains
(
permission
)
||
this
.
permissions
.
contains
(
"*"
))
{
this
.
permissions
.
contains
(
"*"
)
||
return
true
;
(
this
.
permissions
.
contains
(
"player"
)
||
this
.
permissions
.
contains
(
"player.*"
))
&&
permission
.
startsWith
(
"player."
)
||
}
(
this
.
permissions
.
contains
(
"server"
)
||
this
.
permissions
.
contains
(
"server.*"
))
&&
permission
.
startsWith
(
"server."
);
String
[]
permissionParts
=
permission
.
split
(
"\\."
);
for
(
String
p
:
this
.
permissions
)
{
if
(
permissionMatchesWildcard
(
p
,
permissionParts
))
{
return
true
;
}
}
return
false
;
}
}
public
boolean
removePermission
(
String
permission
)
{
public
boolean
removePermission
(
String
permission
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment