示例#1
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>();
            mRightsCache = new List<string>();

            ReloadCache(MySqlClient, UserAchievementCache);
        }
示例#2
0
文件: Session.cs 项目: BjkGkh/BobbaRP
        public void TryAuthenticate(string Ticket, string RemoteAddress)
        {
            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                string getInfo = string.Empty;
                try
                {
                    getInfo = new WebClient().DownloadString("http://bobbarp.net/index.php?url=authenticate&address=" + RemoteAddress);
                }
                catch
                {
                    Console.WriteLine("[Authentication Failed]: " + RemoteAddress);
                }
                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");

                // Set Online
                MySqlClient.SetParameter("userid", CharacterId);
                MySqlClient.ExecuteNonQuery("UPDATE users SET online = 1 WHERE 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");
                }

                if (getInfo.Equals("Authenticated"))
                {
                    BadgeCache.mRightsCache.Add("hotel_admin");
                }

                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()));

                // Unknown packet 1
                // Thought: Navigator config?
                ServerMessage UnkMessage2 = new ServerMessage(290);
                UnkMessage2.AppendInt32(1);
                UnkMessage2.AppendInt32(0);
                SendData(UnkMessage2);

                // Unknown packet 2
                // Thought: durrrrrrrrr
                ServerMessage UnkMessage3 = new ServerMessage(517);
                UnkMessage3.AppendInt32(1);
                SendData(UnkMessage3);

                // Unknown packet 3
                // No idea.
                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") || RightsManager.mAdmins.Contains(mCharacterInfo.Username))
                {
                    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);
            }
        }
示例#3
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;
            }
        }
示例#4
0
文件: Session.cs 项目: DaimOwns/ProRP
        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 Reality RP BETA.\n\n\nThank you for participating in the 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 to the staff team!\n\n\n\nHave fun, and thank you for helping us!"));
                SendData(AchievementDataListComposer.Compose(AchievementManager.Achievements.Values.ToList()));

                // Unknown packet 1
                // Thought: Navigator config?
                ServerMessage UnkMessage2 = new ServerMessage(290);
                UnkMessage2.AppendInt32(1);
                UnkMessage2.AppendInt32(0);
                SendData(UnkMessage2);

                // Unknown packet 2
                // Thought: durrrrrrrrr
                ServerMessage UnkMessage3 = new ServerMessage(517);
                UnkMessage3.AppendInt32(1);
                SendData(UnkMessage3);

                // Unknown packet 3
                // No idea.
                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);
            }
        }