Beispiel #1
0
        public virtual async Task <UserDto?> GetSession()
        {
            if (Actor == null)
            {
                return(null);
            }

            var user = await _userManager.FindUserAsync(Actor.Type, Actor.Id, UserSearchMode.FindById);

            if (user == null)
            {
                return(new UserDto
                {
                    Id = Actor.Id,
                    Type = Actor.Type,
                    Roles = new List <RoleDto>()
                });
            }

            var roles = await _roleStore.GetRolesAsync(user);

            return(new UserDto
            {
                Id = Actor.Id,
                Type = Actor.Type,
                SessionStartTime = user.Session?.SessionStartTime,
                Roles = roles.Select(d => new RoleDto
                {
                    DisplayName = d.DisplayName,
                    Id = d.Id,
                    IsAutoAssigned = d.IsAutoAssigned,
                    Priority = d.Priority
                }).ToList()
            });
        }
        private async Task <UserDto> MapToPlayerDtoAsync(IUser user)
        {
            var roles = await _roleStore.GetRolesAsync(user);

            return(new UserDto
            {
                Id = user.Id,
                Type = user.Type,
                SessionStartTime = user.Session?.SessionStartTime
            });
        }
        public async Task <IReadOnlyCollection <IPermissionRole> > GetRolesAsync(IPermissionActor actor, bool inherit = true)
        {
            if (actor == null)
            {
                throw new ArgumentNullException(nameof(actor));
            }

            var list = new List <IPermissionRole>();

            list.AddRange(await m_BasePermissionRoleStore.GetRolesAsync(actor, inherit));

            if (RocketModIntegrationEnabled() && IsPlayerActor(actor.Type))
            {
                foreach (var group in R.Permissions.GetGroups(ToRocketPlayer(actor), inherit))
                {
                    list.Add(new RocketGroupWrapper(group));
                }
            }

            return(list);
        }
Beispiel #4
0
        public async Task <TimeSpan?> GetCooldownSpan(ICommandActor actor, string commandId)
        {
            var roles = await m_PermissionRoleStore.GetRolesAsync(actor);

            if (roles == null || roles.Count == 0)
            {
                return(null);
            }

            TimeSpan?span     = null;
            int      priority = 0;

            foreach (var role in roles)
            {
                try
                {
                    // Skip as result won't matter
                    if (span.HasValue && priority >= role.Priority)
                    {
                        continue;
                    }

                    var data =
                        (await m_PermissionRolesDataStore.GetRoleDataAsync <List <object> >(role.Id,
                                                                                            "cooldowns"))?.OfType <Dictionary <object, object> >();

                    if (data == null)
                    {
                        continue;
                    }

                    foreach (var dict in data)
                    {
                        var currentSpan = dict.ToObject <CooldownSpan>();

                        if (currentSpan.Command.Equals(commandId, StringComparison.OrdinalIgnoreCase))
                        {
                            span     = currentSpan.GetParsedCooldown();
                            priority = role.Priority;
                        }
                    }
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex, "Error occurred while parsing command cooldown");
                    throw;
                }
            }

            return(span);
        }
Beispiel #5
0
        public List <RocketPermissionsGroup> GetGroups(IRocketPlayer player, bool includeParentGroups)
        {
            var actor  = ConvertToActor(player);
            var result = new List <RocketPermissionsGroup>();

            AsyncHelper.RunSync(async() =>
            {
                foreach (var group in await m_PermissionRoleStore.GetRolesAsync(actor))
                {
                    result.Add(GetGroup(group.Id));
                }
            });

            return(result);
        }
Beispiel #6
0
        protected async Task <HashSet <string> > GetPermissionsAsync(IPermissionActor actor, bool inherit = true) //order by descending priority
        {
            var permissions = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);
            var user        = await m_UserDataStore.GetUserDataAsync(actor.Id, actor.Type);

            if (user?.Permissions != null)
            {
                permissions.UnionWith(user.Permissions);
            }

            foreach (var role in (await m_PermissionRoleStore.GetRolesAsync(actor, inherit)).OrderByDescending(gp => gp.Priority))
            {
                permissions.UnionWith(((PermissionRole)role).Permissions);
            }

            return(permissions);
        }