forked from LittleBigRefresh/Refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameUserExtensions.cs
More file actions
34 lines (27 loc) · 1.13 KB
/
Copy pathGameUserExtensions.cs
File metadata and controls
34 lines (27 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Refresh.Core.Configuration;
using Refresh.Database.Models.Users;
namespace Refresh.Core.Extensions;
public static class GameUserExtensions
{
public static bool IsWriteBlocked(this GameUser user, GameServerConfig config)
{
if (user.Role == GameUserRole.Admin) return false;
return GetRolePermissionsForUser(user, config).ReadOnlyMode;
}
public static bool MayModifyUser(this GameUser user, GameUser targetUser)
{
// Users who are not at least a moderator may not update anyone else.
if (user.Role < GameUserRole.Moderator)
return false;
// Only admins may modify everyone, even other admins. Moderators may not modify other moderators and no admins either.
if (user.Role < GameUserRole.Admin && targetUser.Role >= GameUserRole.Moderator)
return false;
return true;
}
public static RolePermissions GetRolePermissionsForUser(this GameUser user, GameServerConfig config)
{
if (user.Role >= GameUserRole.Trusted)
return config.TrustedUserPermissions;
return config.NormalUserPermissions;
}
}