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
1adffc21
Commit
1adffc21
authored
May 16, 2022
by
xtaodada
Committed by
Melledy
May 16, 2022
Browse files
Enhance the default permissions logic
parent
21478b0a
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java
View file @
1adffc21
...
@@ -41,10 +41,6 @@ public final class DefaultAuthenticators {
...
@@ -41,10 +41,6 @@ public final class DefaultAuthenticators {
responseMessage
=
translate
(
"messages.dispatch.account.username_create_error"
);
responseMessage
=
translate
(
"messages.dispatch.account.username_create_error"
);
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.dispatch.account.account_login_create_error"
,
address
));
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.dispatch.account.account_login_create_error"
,
address
));
}
else
{
}
else
{
// Add default permissions.
for
(
var
permission
:
ACCOUNT
.
defaultPermissions
)
account
.
addPermission
(
permission
);
// Continue with login.
// Continue with login.
successfulLogin
=
true
;
successfulLogin
=
true
;
...
...
src/main/java/emu/grasscutter/game/Account.java
View file @
1adffc21
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
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.List
;
import
java.util.stream.Stream
;
import
java.util.Locale
;
import
org.bson.Document
;
import
org.bson.Document
;
...
@@ -144,19 +142,24 @@ public class Account {
...
@@ -144,19 +142,24 @@ public class Account {
}
}
public
boolean
hasPermission
(
String
permission
)
{
public
boolean
hasPermission
(
String
permission
)
{
if
(
this
.
permissions
.
contains
(
permission
))
return
true
;
if
(
this
.
permissions
.
contains
(
"*"
)
&&
this
.
permissions
.
size
()
==
1
)
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
(
"\\."
);
String
[]
permissionParts
=
permission
.
split
(
"\\."
);
for
(
String
p
:
this
.
permissions
)
{
for
(
String
p
:
permissions
)
{
if
(
p
.
startsWith
(
"-"
)
&&
permissionMatchesWildcard
(
p
.
substring
(
1
),
permissionParts
))
return
false
;
if
(
p
.
startsWith
(
"-"
)
&&
permissionMatchesWildcard
(
p
.
substring
(
1
),
permissionParts
))
return
false
;
if
(
permissionMatchesWildcard
(
p
,
permissionParts
))
return
true
;
if
(
permissionMatchesWildcard
(
p
,
permissionParts
))
return
true
;
}
}
return
this
.
permissions
.
contains
(
"*"
);
return
permissions
.
contains
(
"*"
);
}
}
public
boolean
removePermission
(
String
permission
)
{
public
boolean
removePermission
(
String
permission
)
{
return
this
.
permissions
.
remove
(
permission
);
return
this
.
permissions
.
remove
(
permission
);
}
}
...
...
src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java
View file @
1adffc21
...
@@ -32,7 +32,7 @@ public final class GachaHandler implements Router {
...
@@ -32,7 +32,7 @@ public final class GachaHandler implements Router {
private
final
String
gachaMappings
;
private
final
String
gachaMappings
;
public
GachaHandler
()
{
public
GachaHandler
()
{
this
.
gachaMappings
=
Utils
.
toFilePath
(
DATA
(
"
/
gacha/mappings.js"
));
this
.
gachaMappings
=
Utils
.
toFilePath
(
DATA
(
"gacha/mappings.js"
));
if
(!(
new
File
(
this
.
gachaMappings
).
exists
()))
{
if
(!(
new
File
(
this
.
gachaMappings
).
exists
()))
{
try
{
try
{
Tools
.
createGachaMapping
(
this
.
gachaMappings
);
Tools
.
createGachaMapping
(
this
.
gachaMappings
);
...
...
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