コード例 #1
0
        /// <summary>
        /// Loads the database.
        /// </summary>
        public void Load()
        {
            _cache.Clear();
            using (var reader = _db.QueryReader("SELECT * FROM UserSpecificFunctions"))
            {
                if (!reader.Read())
                {
                    using (var reader2 = _db.QueryReader("SELECT * FROM UserHasPermission"))
                    {
                        while (reader2.Read())
                        {
                            var userId     = reader2.Get <int>("UserId");
                            var permission = reader2.Get <string>("Permission");
                            var negated    = reader2.Get <int>("IsNegated") == 1;

                            var playerInfo = _cache.SingleOrDefault(p => p.UserId == userId);
                            if (playerInfo == null)
                            {
                                playerInfo = new PlayerInfo(userId, new ChatData());
                                playerInfo.Permissions.AddPermission(new Permission(permission, negated));
                                _cache.Add(playerInfo);
                            }
                            else
                            {
                                playerInfo.Permissions.AddPermission(new Permission(permission, negated));
                            }
                        }
                    }
                }
                else
                {
                    while (reader.Read())
                    {
                        var userId   = reader.Get <int>("UserId");
                        var chatData = new ChatData(reader.Get <string>("Color"), reader.Get <string>("Prefix"),
                                                    reader.Get <string>("Suffix"));

                        var playerInfo = new PlayerInfo(userId, chatData);
                        using (var permissionReader =
                                   _db.QueryReader("SELECT * FROM UserHasPermission WHERE UserId = @0", userId))
                        {
                            while (permissionReader.Read())
                            {
                                var permission = permissionReader.Get <string>("Permission");
                                var negated    = permissionReader.Get <int>("IsNegated") == 1;
                                playerInfo.Permissions.AddPermission(new Permission(permission, negated));
                            }
                        }
                        _cache.Add(playerInfo);
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PlayerInfo"/> class with the specified user ID, chat data and permissions.
 /// </summary>
 /// <param name="userId">The user ID.</param>
 /// <param name="chatData">The user's chat information.</param>
 /// <param name="permissions">A collection of the user's permissions.</param>
 public PlayerInfo(int userId, [NotNull] ChatData chatData, [NotNull] PermissionCollection permissions) : this(userId, chatData)
 {
     Permissions = permissions ?? throw new ArgumentNullException(nameof(permissions));
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PlayerInfo"/> class with the specified user ID and chat data.
 /// </summary>
 /// <param name="userId">The user ID.</param>
 /// <param name="chatData">The user's chat information.</param>
 public PlayerInfo(int userId, [NotNull] ChatData chatData)
 {
     UserId   = userId;
     ChatData = chatData ?? throw new ArgumentNullException(nameof(chatData));
 }