Пример #1
0
        public List <string> RegenerateRights()
        {
            List <string> Rights = new List <string>();

            Rights.AddRange(RightsManager.GetDefaultRights());

            lock (mSyncRoot)
            {
                foreach (Badge Badge in mStaticBadges)
                {
                    Rights.AddRange(RightsManager.GetRightsForBadge(Badge));
                }

                foreach (Badge Badge in mAchievementBadges.Values)
                {
                    Rights.AddRange(RightsManager.GetRightsForBadge(Badge));
                }
            }

            return(Rights);
        }
Пример #2
0
        public void ReloadCache(SqlDatabaseClient MySqlClient, AchievementCache UserAchievementCache)
        {
            Dictionary <int, Badge>    EquippedBadges    = new Dictionary <int, Badge>();
            List <Badge>               StaticBadges      = new List <Badge>();
            Dictionary <string, Badge> AchievementBadges = new Dictionary <string, Badge>();
            List <string>              IndexCache        = new List <string>();

            MySqlClient.SetParameter("userid", mUserId);
            DataTable Table = MySqlClient.ExecuteQueryTable("SELECT badge_id,slot_id,source_type,source_data FROM badges WHERE user_id = @userid");

            foreach (DataRow Row in Table.Rows)
            {
                Badge Badge = RightsManager.GetBadgeById((uint)Row["badge_id"]);

                if (Badge == null)
                {
                    continue;
                }

                string SourceType = Row["source_type"].ToString();
                string SourceData = Row["source_data"].ToString();

                Badge BadgeToEquip = null;

                if (SourceType == "static")
                {
                    BadgeToEquip = Badge;
                    StaticBadges.Add(BadgeToEquip);
                }
                else if (SourceType == "achievement")
                {
                    if (AchievementBadges.ContainsKey(SourceData))
                    {
                        continue;
                    }

                    UserAchievement UserAchievement = UserAchievementCache.GetAchievementData(SourceData);

                    if (UserAchievement == null || UserAchievement.Level < 1)
                    {
                        MySqlClient.SetParameter("userid", mUserId);
                        MySqlClient.SetParameter("badgeid", Badge.Id);
                        MySqlClient.ExecuteNonQuery("DELETE FROM badges WHERE user_id = @userid AND badge_id = @badgeid");
                        continue;
                    }

                    string Code = UserAchievement.GetBadgeCodeForLevel();

                    BadgeToEquip = (Badge.Code == Code ? Badge : RightsManager.GetBadgeByCode(Code));
                    AchievementBadges.Add(SourceData, BadgeToEquip);
                }

                if (BadgeToEquip != null)
                {
                    int SlotId = (int)Row["slot_id"];

                    if (!EquippedBadges.ContainsKey(SlotId) && SlotId >= 1 && SlotId <= 5)
                    {
                        EquippedBadges.Add(SlotId, BadgeToEquip);
                    }

                    IndexCache.Add(BadgeToEquip.Code);
                }
            }

            lock (mSyncRoot)
            {
                mEquippedBadges    = EquippedBadges;
                mStaticBadges      = StaticBadges;
                mAchievementBadges = AchievementBadges;
                mRightsCache       = RegenerateRights();
                mIndexCache        = IndexCache;
            }
        }