예제 #1
0
        public void ClaimAchievement(Type levelBaseType, int achivementLevelIndex)
        {
            AchievementInfo achievementinfo      = InfoResolver.Resolve <FortInfo>().Achievement.AchievementTypes[levelBaseType];
            Array           achivementLevelInfos =
                (Array)achievementinfo.GetType().GetProperty("LevelInfoes").GetValue(achievementinfo, new object[0]);

            if (achivementLevelIndex >= achivementLevelInfos.Length)
            {
                throw new Exception("Claim Achievement AchievementLevelInfoes out of index");
            }
            //AchivementLevelInfo achivementLevelInfo = (AchivementLevelInfo)achivementLevelInfos.GetValue(achivementLevelIndex);
            string achievementId = achievementinfo.Id;
            AchievementStoredData achievementStoredData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementStoredData>();

            if (achievementStoredData == null)
            {
                achievementStoredData = new AchievementStoredData();
            }
            if (achievementStoredData.Achievements.ContainsKey(achievementId) &&
                achievementStoredData.Achievements[achievementId] <= achivementLevelIndex)
            {
                return; //throw new Exception("Achievement Already Claimed");
            }
            achievementStoredData.Achievements[achievementId] = achivementLevelIndex;
            ServiceLocator.Resolve <IStorageService>().UpdateData(achievementStoredData);

            string[] possibleAchievementIds =
                achivementLevelInfos.Cast <AchievementLevelInfo>()
                .Take(achivementLevelIndex + 1)
                .Select(info => info.Id)
                .ToArray();
            AchievementCache achievementCache =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementCache>();

            if (achievementCache == null)
            {
                achievementCache = new AchievementCache();
            }
            foreach (string possibleAchievementId in possibleAchievementIds)
            {
                if (!achievementCache.ServerAchievementIds.ContainsKey(possibleAchievementId))
                {
                    achievementCache.ServerAchievementIds.Add(possibleAchievementId, false);
                }
            }
            ServiceLocator.Resolve <IStorageService>().UpdateData(achievementCache);
            AchievementLevelInfo achievementLevelInfo =
                (AchievementLevelInfo)achivementLevelInfos.GetValue(achivementLevelIndex);
            ScoreBalance scoreBalance = ResolveAchievementScoreBalance(achievementLevelInfo.Id);

            ServiceLocator.Resolve <IUserManagementService>()
            .AddScoreAndBalance(scoreBalance.Score, scoreBalance.Balance);
            ServiceLocator.Resolve <IAnalyticsService>().StatAchievementClaimed(achievementLevelInfo.Id, scoreBalance);
            ServiceLocator.Resolve <IEventAggregatorService>().GetEvent <AchievementClaimedEvent>().Publish(new LevelBaseAchievementClaimedEventArgs((LevelBaseAchievementInfo)achievementinfo, achivementLevelIndex));
        }
예제 #2
0
        public string[] GetNotSyncAchievementIds()
        {
            AchievementCache achievementCache =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementCache>() ?? new AchievementCache();

            return
                (achievementCache.ServerAchievementIds.Where(pair => pair.Value == false)
                 .Select(pair => pair.Key)
                 .ToArray());
        }
예제 #3
0
        public void OnServerAchievementResolved(Dictionary <string, ServerAchievementInfo> achievementInfos, string[] claimedAchievementIds)
        {
            AchievementCache achievementCache =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementCache>();

            if (achievementCache == null)
            {
                achievementCache = new AchievementCache();
            }
            foreach (string claimedAchievementId in claimedAchievementIds)
            {
                achievementCache.ServerAchievementIds[claimedAchievementId] = true;
            }
            ServiceLocator.Resolve <IStorageService>().UpdateData(achievementCache);

            AchievementStoredData achievementStoredData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementStoredData>();

            if (achievementStoredData == null)
            {
                achievementStoredData = new AchievementStoredData();
            }
            Dictionary <AchievementInfo, AchievementToken[]> achievementTokenses =
                claimedAchievementIds.Where(s => InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens.ContainsKey(s))
                .Select(s => InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens[s])
                .GroupBy(token => token.AchievementInfo)
                .ToDictionary(tokens => tokens.Key, tokens => tokens.Select(token => token).ToArray());

            foreach (KeyValuePair <AchievementInfo, AchievementToken[]> pair in achievementTokenses)
            {
                if (pair.Value.Length > 0)
                {
                    if (pair.Key is NoneLevelBaseAchievementInfo)
                    {
                        achievementStoredData.Achievements[pair.Key.Id] = 0;
                    }
                    else
                    {
                        int max = pair.Value.Max(token => token.Index);
                        if (
                            !(achievementStoredData.Achievements.ContainsKey(pair.Key.Id) &&
                              achievementStoredData.Achievements[pair.Key.Id] >= max))
                        {
                            achievementStoredData.Achievements[pair.Key.Id] = max;
                        }
                    }
                }
            }
            foreach (KeyValuePair <string, ServerAchievementInfo> pair in achievementInfos)
            {
                achievementStoredData.ServerAchievementInfos[pair.Key] = pair.Value;
            }
            ServiceLocator.Resolve <IStorageService>().UpdateData(achievementStoredData);
        }
예제 #4
0
        public BadgeCache(SqlDatabaseClient MySqlClient, uint UserId, AchievementCache UserAchievementCache)
        {
            mUserId   = UserId;
            mSyncRoot = new object();

            mEquippedBadges    = new Dictionary <int, Badge>();
            mStaticBadges      = new List <Badge>();
            mAchievementBadges = new Dictionary <string, Badge>();
            mIndexCache        = new List <string>();

            ReloadCache(MySqlClient, UserAchievementCache);
        }
예제 #5
0
    public static void GetAchievementCacheData()
    {
        Debug.Log("-------------GetAchievementCacheData--------------------");
        if (dataAchievementCache != null)
        {
            dataAchievementCache = null;
        }
        dataAchievementCache = new AchievementCache[22];
        //Tao achievement
        if (!PlayerPrefs.HasKey(Achievement_data_key))
        {
            string achi = "";
            for (int i = 1; i <= 22; i++)
            {
                achi += i + "-1-0-0,";
            }
            //Debug.Log("Create new achievement " + achi);
            PlayerPrefs.SetString(Achievement_data_key, achi);
        }
        string achievement = PlayerPrefs.GetString(Achievement_data_key);

        //Debug.Log(achievement);
        string[] achie = achievement.Split(',');
        for (int i = 0; i < dataAchievementCache.Length; i++)
        {
            //Debug.Log(achie[i]);
            string[] infoAchie = achie[i].Split('-');
            string   group     = infoAchie[0];
            string   level     = infoAchie[1];
            string   value     = infoAchie[2];
            string   notify    = infoAchie[3];
            //Debug.Log(group +" " +  dataAchievementCache[i].Group);
            dataAchievementCache[i]        = new AchievementCache();
            dataAchievementCache[i].Group  = Convert.ToInt16(group);
            dataAchievementCache[i].Level  = Convert.ToInt16(level);
            dataAchievementCache[i].Value  = Convert.ToInt32(value);
            dataAchievementCache[i].Notify = Convert.ToInt16(notify);
        }
    }
예제 #6
0
        public void ClaimAchievement(Type noneLevelBaseType)
        {
            NoneLevelBaseAchievementInfo noneLevelBaseAchievementInfo =
                (NoneLevelBaseAchievementInfo)InfoResolver.Resolve <FortInfo>().Achievement.AchievementTypes[noneLevelBaseType];
            string achievementId = noneLevelBaseAchievementInfo.Id;
            AchievementStoredData achievementStoredData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementStoredData>();

            if (achievementStoredData == null)
            {
                achievementStoredData = new AchievementStoredData();
            }
            if (achievementStoredData.Achievements.ContainsKey(achievementId))
            {
                return; //throw new Exception("Achievement Already Claimed");
            }
            achievementStoredData.Achievements.Add(achievementId, 0);
            ServiceLocator.Resolve <IStorageService>().UpdateData(achievementStoredData);
            //Add to Server cashe
            AchievementCache achievementCache =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementCache>();

            if (achievementCache == null)
            {
                achievementCache = new AchievementCache();
            }
            if (!achievementCache.ServerAchievementIds.ContainsKey(achievementId))
            {
                achievementCache.ServerAchievementIds.Add(achievementId, false);
            }
            ServiceLocator.Resolve <IStorageService>().UpdateData(achievementCache);
            ScoreBalance scoreBalance = ResolveAchievementScoreBalance(noneLevelBaseAchievementInfo.Id);

            ServiceLocator.Resolve <IUserManagementService>()
            .AddScoreAndBalance(scoreBalance.Score, scoreBalance.Balance);
            ServiceLocator.Resolve <IAnalyticsService>().StatAchievementClaimed(noneLevelBaseAchievementInfo.Id, scoreBalance);
            ServiceLocator.Resolve <IEventAggregatorService>().GetEvent <AchievementClaimedEvent>().Publish(new NoneLeveBaseAchievementClaimedEventArgs(noneLevelBaseAchievementInfo));
        }
 void Awake()
 {
     DontDestroyOnLoad(gameObject);
     cache = new AchievementCache();
 }
예제 #8
0
        public void TryAuthenticate(string Ticket, string RemoteAddress)
        {
            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                uint AuthedUid = SingleSignOnAuthenticator.TryAuthenticate(MySqlClient, Ticket, RemoteAddress);

                if (AuthedUid <= 0)
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                CharacterInfo Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, AuthedUid, mId, true);

                if (Info == null || !Info.HasLinkedSession) // not marked online = CharacterInfoLoader failed somehow
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo = Info;

                mAchieventCache = new AchievementCache(MySqlClient, CharacterId);
                mBadgeCache     = new BadgeCache(MySqlClient, CharacterId, mAchieventCache);

                if (!HasRight("login"))
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo.TimestampLastOnline = UnixTimestamp.GetCurrent();

                CharacterResolverCache.AddToCache(mCharacterInfo.Id, mCharacterInfo.Username, true);

                mMessengerFriendCache = new SessionMessengerFriendCache(MySqlClient, CharacterId);
                mFavoriteRoomsCache   = new FavoriteRoomsCache(MySqlClient, CharacterId);
                mRatedRoomsCache      = new RatedRoomsCache();
                mInventoryCache       = new InventoryCache(MySqlClient, CharacterId);
                mIgnoreCache          = new UserIgnoreCache(MySqlClient, CharacterId);
                mNewItemsCache        = new NewItemsCache(MySqlClient, CharacterId);
                mAvatarEffectCache    = new AvatarEffectCache(MySqlClient, CharacterId);
                mQuestCache           = new QuestCache(MySqlClient, CharacterId);
                mPetCache             = new PetInventoryCache(MySqlClient, CharacterId);

                // Subscription manager
                MySqlClient.SetParameter("userid", CharacterId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM user_subscriptions WHERE user_id = @userid");

                mSubscriptionManager = (Row != null ? new ClubSubscription(CharacterId,
                                                                           (ClubSubscriptionLevel)int.Parse((Row["subscription_level"].ToString())), (double)Row["timestamp_created"],
                                                                           (double)Row["timestamp_expire"], (double)Row["past_time_hc"], (double)Row["past_time_vip"]) :
                                        new ClubSubscription(CharacterId, ClubSubscriptionLevel.None, 0, 0, 0, 0));

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_VipClub");
                }

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.BasicClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_BasicClub");
                }

                mAvatarEffectCache.CheckEffectExpiry(this);

                mAuthProcessed = true;

                SendData(AuthenticationOkComposer.Compose());
                SendData(FuseRightsListComposer.Compose(this));
                SendData(UserHomeRoomComposer.Compose(mCharacterInfo.HomeRoom));
                SendData(UserEffectListComposer.Compose(AvatarEffectCache.Effects));
                SendData(NavigatorFavoriteRoomsComposer.Compose(FavoriteRoomsCache.FavoriteRooms));
                SendData(InventoryNewItemsComposer.Compose(NewItemsCache.NewItems));
                SendData(AchievementDataListComposer.Compose(AchievementManager.Achievements.Values.ToList()));

                SendData(AvailabilityStatusMessageComposer.Compose());
                SendData(InfoFeedEnableMessageComposer.Compose(1));
                SendData(ActivityPointsMessageComposer.Compose());

                if (HasRight("moderation_tool"))
                {
                    SendData(ModerationToolComposer.Compose(this, ModerationPresets.UserMessagePresets,
                                                            ModerationPresets.UserActionPresets, ModerationPresets.RoomMessagePresets));

                    foreach (ModerationTicket ModTicket in ModerationTicketManager.ActiveTickets)
                    {
                        SendData(ModerationTicketComposer.Compose(ModTicket));
                    }
                }

                MessengerHandler.MarkUpdateNeeded(this, 0, true);
            }
        }
예제 #9
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;
            }
        }
예제 #10
0
파일: Session.cs 프로젝트: habb0/Snowlight
        public void TryAuthenticate(string Ticket, string RemoteAddress)
        {
            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                uint AuthedUid = SingleSignOnAuthenticator.TryAuthenticate(MySqlClient, Ticket, RemoteAddress);

                if (AuthedUid <= 0)
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                CharacterInfo Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, AuthedUid, mId, true);

                if (Info == null || !Info.HasLinkedSession) // not marked online = CharacterInfoLoader failed somehow
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo = Info;

                mAchieventCache = new AchievementCache(MySqlClient, CharacterId);
                mBadgeCache     = new BadgeCache(MySqlClient, CharacterId, mAchieventCache);

                if (!HasRight("login"))
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo.TimestampLastOnline = UnixTimestamp.GetCurrent();

                CharacterResolverCache.AddToCache(mCharacterInfo.Id, mCharacterInfo.Username, true);

                mMessengerFriendCache = new SessionMessengerFriendCache(MySqlClient, CharacterId);
                mFavoriteRoomsCache   = new FavoriteRoomsCache(MySqlClient, CharacterId);
                mRatedRoomsCache      = new RatedRoomsCache();
                mInventoryCache       = new InventoryCache(MySqlClient, CharacterId);
                mIgnoreCache          = new UserIgnoreCache(MySqlClient, CharacterId);
                mNewItemsCache        = new NewItemsCache(MySqlClient, CharacterId);
                mAvatarEffectCache    = new AvatarEffectCache(MySqlClient, CharacterId);
                mQuestCache           = new QuestCache(MySqlClient, CharacterId);
                mPetCache             = new PetInventoryCache(MySqlClient, CharacterId);

                // Subscription manager
                MySqlClient.SetParameter("userid", CharacterId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM user_subscriptions WHERE user_id = @userid");

                mSubscriptionManager = (Row != null ? new ClubSubscription(CharacterId,
                                                                           (ClubSubscriptionLevel)int.Parse((Row["subscription_level"].ToString())), (double)Row["timestamp_created"],
                                                                           (double)Row["timestamp_expire"], (double)Row["past_time_hc"], (double)Row["past_time_vip"]) :
                                        new ClubSubscription(CharacterId, ClubSubscriptionLevel.None, 0, 0, 0, 0));

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_VipClub");
                }

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.BasicClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_BasicClub");
                }

                mAvatarEffectCache.CheckEffectExpiry(this);

                mAuthProcessed = true;

                SendData(AuthenticationOkComposer.Compose());
                SendData(FuseRightsListComposer.Compose(this));
                SendData(UserHomeRoomComposer.Compose(mCharacterInfo.HomeRoom));
                SendData(UserEffectListComposer.Compose(AvatarEffectCache.Effects));
                SendData(NavigatorFavoriteRoomsComposer.Compose(FavoriteRoomsCache.FavoriteRooms));
                SendData(InventoryNewItemsComposer.Compose(NewItemsCache.NewItems));
                SendData(MessageOfTheDayComposer.Compose("Welcome to uberHotel.org BETA.\n\n\nThank you for participating in the uberHotel.org BETA test. We hope to gather relevant feedback and ideas to help make this hotel into a success.\n\nPlease submit any bugs, feedback, or ideas via:\nhttp://snowlight.uservoice.com\n\n\nHave fun, and thank you for joining us!"));
                SendData(AchievementDataListComposer.Compose(AchievementManager.Achievements.Values.ToList()));

                // This is available status packet (AvailabilityStatusMessageComposer)
                ServerMessage UnkMessage2 = new ServerMessage(290);
                UnkMessage2.AppendInt32(1);
                UnkMessage2.AppendInt32(0);
                SendData(UnkMessage2);

                // This is info feed packet (InfoFeedEnableMessageComposer)
                ServerMessage UnkMessage3 = new ServerMessage(517);
                UnkMessage3.AppendInt32(1); // 1 = enabled     0 = disabled  (true/false)
                SendData(UnkMessage3);

                // This is activity points message (ActivityPointsMessageComposer)  not sure how this is handled...
                ServerMessage UnkMessage4 = new ServerMessage(628);
                UnkMessage4.AppendInt32(1);
                UnkMessage4.AppendInt32(0);
                UnkMessage4.AppendInt32(2971);
                SendData(UnkMessage4);

                SendData(ClientConfigComposer.Compose(CharacterInfo.ConfigVolume, false));

                if (HasRight("moderation_tool"))
                {
                    SendData(ModerationToolComposer.Compose(this, ModerationPresets.UserMessagePresets,
                                                            ModerationPresets.UserActionPresets, ModerationPresets.RoomMessagePresets));

                    foreach (ModerationTicket ModTicket in ModerationTicketManager.ActiveTickets)
                    {
                        SendData(ModerationTicketComposer.Compose(ModTicket));
                    }
                }

                MessengerHandler.MarkUpdateNeeded(this, 0, true);
            }
        }