Ejemplo n.º 1
0
        /// <summary>
        /// 初始化用户数据
        /// </summary>
        /// <returns></returns>
        public async Task InitUserData()
        {
            bool exist = true;

            BeginDb(DAL =>
            {
                exist = DAL.ExistRankInfo(CurrentUser.PlatformID);
            });
            // 存在初始数据
            if (exist)
            {
                return;
            }
            // 获取用户信息
            MRankInfo          srRankInfo    = (await _steamBLL.GetRankScore(new[] { CurrentUser.RankID })).FirstOrDefault();
            PlayerSummaryModel playerSummary = await _steamBLL.GetPlayerSummary(CurrentUser.PlatformID);

            MRankInfo rankInfo = new MRankInfo
            {
                PlatformID  = playerSummary.SteamId.ToString(),
                RankID      = CurrentUser.RankID,
                PersonaName = playerSummary.Nickname,
                AvatarS     = playerSummary.AvatarUrl,
                AvatarM     = playerSummary.AvatarMediumUrl,
                AvatarL     = playerSummary.AvatarFullUrl,
                State       = (int)playerSummary.UserStatus
            };
            RecentlyPlayedGamesResultModel playedGames = await _steamBLL.GetRecentlyPlayedGames(CurrentUser.PlatformID);

            BeginDb(DAL =>
            {
                // 没有SR
                if (srRankInfo == null)
                {
                    DAL.AddRankInfo(rankInfo);
                    return;
                }
                int weekPlayTime = (int)(playedGames.RecentlyPlayedGames.FirstOrDefault(x => x.AppId == 207140)?.Playtime2Weeks ?? 0);
                // 添加RankInfo
                rankInfo.RankType     = 1;
                rankInfo.RankCount    = srRankInfo.RankCount;
                rankInfo.RankScore    = srRankInfo.RankScore;
                rankInfo.OldRankScore = srRankInfo.RankScore;
                rankInfo.RankLevel    = srRankInfo.RankLevel;
                rankInfo.WeekPlayTime = weekPlayTime;
                DAL.Db.BeginTrans();
                DAL.AddRankInfo(rankInfo);
                // 添加RankLog
                MRankLog rankLog = new MRankLog
                {
                    PlatformID = CurrentUser.PlatformID,
                    RankScore  = srRankInfo.RankScore.Value,
                };
                DAL.AddRankLog(rankLog);
                DAL.Db.CommitTrans();
            });
        }
Ejemplo n.º 2
0
 public RecentlyPlayedGamesCacheItem(ulong id, RecentlyPlayedGamesResultModel data)
 {
     Id   = id;
     Data = data;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Processes the users in the <see cref="usersDic"/> dictionary and matches them based on the method parameters.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="similarityThreshold">The profile picture similarity threshold.</param>
        /// <param name="compareUsername">if set to <c>true</c> usernames will be compared.</param>
        /// <param name="caseSensitiveUsername">if set to <c>true</c> will compare usernames with case sensitivity enabled.</param>
        /// <param name="compareAkaNames">if set to <c>true</c> will compare to users other names.</param>
        /// <param name="comparePfp">if set to <c>true</c> will compare profile pictures.</param>
        /// <param name="compareImage">The image to which to compare to.</param>
        /// <param name="userStatusSelectedIndex">Index of the <see cref="userStatusComboBox"/> control.</param>
        /// <param name="checkIngame">if set to <c>true</c> will check if user is ingame and if game matches <see cref="ingameId"/>.</param>
        /// <param name="ingameId">The game ID to compare to.</param>
        /// <param name="checkRecentGames">if set to <c>true</c> will check users recently played games.</param>
        /// <param name="recentGamesList">The recent games list to compare to.</param>
        private async Task processUsers(string username, int similarityThreshold, bool compareUsername, bool caseSensitiveUsername,
                                        bool compareAkaNames, bool comparePfp, Image compareImage, int userStatusSelectedIndex, bool checkIngame, string ingameId, bool checkRecentGames, List <string> recentGamesList)
        {
            status = Status.ProcessingUsers;
            if (!usersDic.ContainsKey(username))
            {
                // Nothing to check
                return;
            }

            List <ulong> steamApiUsersQueue = new List <ulong>();

            foreach (User user in usersDic[username])
            {
                // Username text comparison
                if (compareUsername)
                {
                    bool foundMatch = false;
                    if (caseSensitiveUsername)
                    {
                        if (string.Equals(username, user.Username) || (user.CustomId && string.Equals(username, user.Id)))
                        {
                            foundMatch = true;
                        }
                    }
                    else
                    {
                        if (string.Equals(username, user.Username, StringComparison.CurrentCultureIgnoreCase) || (user.CustomId && string.Equals(username, user.Id, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            foundMatch = true;
                        }
                    }

                    // Compare to other names the user goes by
                    if (compareAkaNames)
                    {
                        foreach (string akaName in user.OtherNames)
                        {
                            if (caseSensitiveUsername)
                            {
                                if (string.Equals(akaName, user.Username))
                                {
                                    foundMatch = true;
                                }
                            }
                            else
                            {
                                if (string.Equals(akaName, user.Username, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    foundMatch = true;
                                }
                            }
                        }
                    }

                    // No username match, continue on
                    if (!foundMatch)
                    {
                        usersProcessed++;
                        continue;
                    }
                }

                // Profile picture comparison
                if (comparePfp)
                {
                    double similarity = getImageSimilarityPercentage(compareImage, user.ProfilePic);
                    if (similarity < similarityThreshold)
                    {
                        usersProcessed++;
                        continue;
                    }
                }

                // If no Steam API key then we finish here without continuing further on
                string userUrl = user.CustomId ? "https://steamcommunity.com/id/" + user.Id : "https://steamcommunity.com/profiles/" + user.Id;
                if (webInterfaceFactory == null)
                {
                    foundUserUrls.Add(userUrl);
                    usersProcessed++;
                    continue;
                }

                // If true further processing needs to happen, so we add all ID's
                // to a list to coalesce requests which saves time and API requests
                if (userStatusSelectedIndex != 0 || checkIngame || checkRecentGames)
                {
                    if (user.SteamId == 0)
                    {
                        user.SteamId = await getSteamIdVanityAsync(user.Id).ConfigureAwait(false);
                    }

                    steamApiUsersQueue.Add(user.SteamId);
                }
            }

            // GetPlayerSummaries has a limit of 100 steam Ids so the list needs to be split
            while (steamApiUsersQueue.Count > 0)
            {
                var tempSteamQueue = steamApiUsersQueue.Take(100).ToList();

                IReadOnlyCollection <PlayerSummaryModel> playerSummaries = null;
                while (playerSummaries == null)
                {
                    try
                    {
                        var playerSummariesResponse = await steamInterface.GetPlayerSummariesAsync(tempSteamQueue).ConfigureAwait(false);

                        playerSummaries = playerSummariesResponse.Data;
                    }
                    catch { }
                }

                foreach (var playerSummary in playerSummaries)
                {
                    // User status comparison
                    // Offline state value is 0 while userStatusComboBox SelectedIndex will be 1 for offline
                    // so we subtract 1 to align the values
                    if (userStatusSelectedIndex != 0 && (int)playerSummary.UserStatus != (userStatusSelectedIndex - 1))
                    {
                        usersProcessed++;
                        continue;
                    }

                    // User in game
                    if (checkIngame && playerSummary.PlayingGameId != ingameId)
                    {
                        usersProcessed++;
                        continue;
                    }

                    // User recent games played
                    if (checkRecentGames)
                    {
                        RecentlyPlayedGamesResultModel recentlyPlayedGameResult = null;
                        while (true)
                        {
                            try
                            {
                                var playerRecentlyPlayedResponse = await playerService.GetRecentlyPlayedGamesAsync(playerSummary.SteamId).ConfigureAwait(false);

                                recentlyPlayedGameResult = playerRecentlyPlayedResponse.Data;
                                break;
                            }
                            catch { }
                        }

                        List <string> recentlyPlayedList = new List <string>();
                        foreach (var recentGame in recentlyPlayedGameResult.RecentlyPlayedGames)
                        {
                            recentlyPlayedList.Add(recentGame.AppId.ToString());
                        }

                        if (!recentGamesList.All(i => recentlyPlayedList.Contains(i)))
                        {
                            usersProcessed++;
                            continue;
                        }
                    }

                    foundUserUrls.Add(playerSummary.ProfileUrl);
                }

                steamApiUsersQueue = steamApiUsersQueue.Skip(100).ToList();
            }
        }