internal void Merge(PlayerUserData playerUserData)
        {
            this.PermissionRank = playerUserData.PermissionRank;
            this.NameColor      = playerUserData.NameColor;
            this.Group          = playerUserData.Group;

            this.LastLogin  = playerUserData.LastLogin;
            this.LastOnline = playerUserData.LastOnline;

            this.SetTotalExp(playerUserData.TotalExp); //Gonna calc the rank and exp
            this.BonusExp = playerUserData.BonusExp;

            this._Hats  = playerUserData._Hats;
            this._Heads = playerUserData._Heads;
            this._Bodys = playerUserData._Bodys;
            this._Feets = playerUserData._Feets;

            this.SetParts(playerUserData.CurrentHat, playerUserData.CurrentHatColor, playerUserData.CurrentHead, playerUserData.CurrentHeadColor, playerUserData.CurrentBody, playerUserData.CurrentBodyColor, playerUserData.CurrentFeet, playerUserData.CurrentFeetColor);
            this.SetStats(playerUserData.Speed, playerUserData.Accel, playerUserData.Jump);

            this._CampaignLevelRecords = playerUserData._CampaignLevelRecords;

            this._Friends = playerUserData._Friends;
            this._Ignored = playerUserData._Ignored;
        }
示例#2
0
        private static PlayerUserData ParseSqlUserData(Task <DbDataReader> task)
        {
            if (task.IsCompletedSuccessfully)
            {
                DbDataReader reader = task.Result;
                if (reader?.Read() ?? false)
                {
                    PlayerUserData playerUserData = new PlayerUserData(reader);
                    return(UserManager.CachePlayerUserData(playerUserData));
                }
            }
            else if (task.IsFaulted)
            {
                UserManager.Logger.Error($"Failed to load {nameof(PlayerUserData)} from sql", task.Exception);
            }

            return(null);
        }
示例#3
0
        public static Task GiveSet(uint userId, Part part) => Task.WhenAll(UserManager.GiveHead(userId, part), UserManager.GiveBody(userId, part), UserManager.GiveFeet(userId, part)); //TODO: More optimized version

        private static PlayerUserData ParseRedisUserData(Task <RedisValue[]> task)
        {
            if (task.IsCompletedSuccessfully)
            {
                RedisValue[] results = task.Result;
                if (results?.All(v => v.HasValue) ?? false)
                {
                    PlayerUserData playerUserData = new PlayerUserData(results);
                    return(UserManager.CachePlayerUserData(playerUserData, true));
                }
            }
            else if (task.IsFaulted)
            {
                UserManager.Logger.Error($"Failed to load {nameof(PlayerUserData)} from redis", task.Exception);
            }

            return(null);
        }
示例#4
0
        private static IReadOnlyCollection <PlayerUserData> ParseSqlMultipleUserData(Task <DbDataReader> task)
        {
            List <PlayerUserData> users = new List <PlayerUserData>();

            if (task.IsCompletedSuccessfully)
            {
                DbDataReader reader = task.Result;
                while (reader?.Read() ?? false)
                {
                    PlayerUserData playerUserData = new PlayerUserData(reader);
                    users.Add(UserManager.CachePlayerUserData(playerUserData));
                }
            }
            else if (task.IsFaulted)
            {
                UserManager.Logger.Error($"Failed to load multipl {nameof(PlayerUserData)} from sql", task.Exception);
            }

            return(users);
        }
示例#5
0
        private static PlayerUserData CachePlayerUserData(PlayerUserData playerUserData, bool loadedFromRedis = false)
        {
            //Push it to redis to keep it up to date
            if (!loadedFromRedis) //We loaded it from redis... there is no point to push data back to there
            {
                RedisConnection.GetDatabase().HashSetAsync($"users:{playerUserData.Id}", playerUserData.ToRedis(), CommandFlags.FireAndForget);
            }

            //Make sure to keep the usernames sync
            RedisConnection.GetDatabase().HashSetAsync($"userids:{Math.Floor(playerUserData.Username.ToUpperInvariant().CountCharsSum() / 100.0)}", new HashEntry[] //TODO: Umh? Also ToUpper due to case sensetivity
            {
                new HashEntry(playerUserData.Username.ToUpperInvariant(), playerUserData.Id)
            }, CommandFlags.FireAndForget);

            UserManager.UserIds.GetOrCreate(playerUserData.Username.ToUpperInvariant(), (cacheEntry) =>
            {
                cacheEntry.SlidingExpiration = UserManager.UserIdsCacheTime;

                return(new Lazy <uint>(playerUserData.Id));
            });

            Lazy <PlayerUserData> lazy = UserManager.Users.GetOrCreate(playerUserData.Id, (cacheEntry) =>
            {
                cacheEntry.SlidingExpiration = UserManager.UserCacheTime;

                return(new Lazy <PlayerUserData>(playerUserData));
            });

            if (lazy.IsValueCreated)
            {
                lazy.Value.Merge(playerUserData);
                return(lazy.Value);
            }
            else
            {
                return(playerUserData);
            }
        }