Example #1
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);
            }
        }
        private static void OnPurchase(Session Session, ClientMessage Message)
        {
            int    PageId = Message.PopWiredInt32();
            uint   ItemId = Message.PopWiredUInt32();
            string Data   = Message.PopString();

            CatalogPage Page = CatalogManager.GetCatalogPage(PageId);

            if (Page == null || Page.DummyPage || !Page.Visible || (Page.RequiredRight.Length > 0 &&
                                                                    !Session.HasRight(Page.RequiredRight)))
            {
                return;
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                switch (Page.Template)
                {
                default:

                    CatalogItem Item = Page.GetItem(ItemId);
                    if (Item == null || (Item.ClubRestriction == 1 && !Session.HasRight("club_regular")) ||
                        (Item.ClubRestriction == 2 && !Session.HasRight("club_vip")))
                    {
                        return;
                    }

                    HandlePurchase(MySqlClient, Session, Item, Data);
                    break;

                case "club_buy":

                    CatalogClubOffer Offer = CatalogManager.GetClubOffer(ItemId);

                    if (Offer == null || (Offer.Price > 0 && Session.CharacterInfo.CreditsBalance < Offer.Price) ||
                        (int)Offer.Level < (int)Session.SubscriptionManager.SubscriptionLevel)
                    {
                        return;
                    }

                    string BasicAchievement = "ACH_BasicClub";
                    string VipAchievement   = "ACH_VipClub";

                    // Extend membership and take credits
                    Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -Offer.Price);
                    Session.SubscriptionManager.AddOrExtend((int)Offer.Level, Offer.LengthSeconds);

                    // Check if we need to manually award basic/vip badges
                    bool NeedsBasicUnlock = !Session.BadgeCache.ContainsCodeWith(BasicAchievement);
                    bool NeedsVipUnlock   = !Session.BadgeCache.ContainsCodeWith(VipAchievement);

                    // Reload the badge cache (reactivating any disabled subscription badges)
                    Session.BadgeCache.ReloadCache(MySqlClient, Session.AchievementCache);

                    // Calculate progress
                    int Progress = (int)Math.Ceiling((double)(Offer.LengthDays / 31));

                    if (Progress <= 0)
                    {
                        Progress = 1;
                    }

                    // Progress VIP achievement
                    if (Offer.Level >= ClubSubscriptionLevel.VipClub)
                    {
                        NeedsVipUnlock = !AchievementManager.ProgressUserAchievement(MySqlClient,
                                                                                     Session, VipAchievement, Progress) && NeedsVipUnlock;
                    }
                    else
                    {
                        NeedsVipUnlock = false;
                    }

                    // Progress basic achievement
                    NeedsBasicUnlock = !AchievementManager.ProgressUserAchievement(MySqlClient,
                                                                                   Session, BasicAchievement, Progress) && NeedsBasicUnlock;

                    // Virtually unlock the basic achievement without reward if needed
                    if (NeedsBasicUnlock)
                    {
                        Achievement Achievement = AchievementManager.GetAchievement(BasicAchievement);

                        if (Achievement != null)
                        {
                            UserAchievement UserAchievement = Session.AchievementCache.GetAchievementData(
                                BasicAchievement);

                            if (UserAchievement != null)
                            {
                                Session.SendData(AchievementUnlockedComposer.Compose(Achievement, UserAchievement.Level,
                                                                                     0, 0));
                            }
                        }
                    }

                    // Virtually unlock the VIP achievement without reward if needed
                    if (NeedsVipUnlock)
                    {
                        Achievement Achievement = AchievementManager.GetAchievement(VipAchievement);

                        if (Achievement != null)
                        {
                            UserAchievement UserAchievement = Session.AchievementCache.GetAchievementData(
                                VipAchievement);

                            if (UserAchievement != null)
                            {
                                Session.SendData(AchievementUnlockedComposer.Compose(Achievement, UserAchievement.Level,
                                                                                     0, 0));
                            }
                        }
                    }

                    // Disable any VIP badges if they still aren't valid
                    if (Session.SubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub)
                    {
                        Session.BadgeCache.DisableSubscriptionBadge(VipAchievement);
                    }

                    // Synchronize equipped badges if the user has unlocked anything
                    if (NeedsVipUnlock || NeedsBasicUnlock)
                    {
                        RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

                        if (Instance != null)
                        {
                            Instance.BroadcastMessage(RoomUserBadgesComposer.Compose(Session.CharacterId,
                                                                                     Session.BadgeCache.EquippedBadges));
                        }
                    }

                    // Clear catalog cache for user (in case of changes)
                    CatalogManager.ClearCacheGroup(Session.CharacterId);

                    // Send new data to client
                    Session.SendData(CatalogPurchaseResultComposer.Compose(Offer));
                    Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance));
                    Session.SendData(FuseRightsListComposer.Compose(Session));
                    Session.SendData(SubscriptionStatusComposer.Compose(Session.SubscriptionManager, true));
                    //Session.SendData(ClubGiftReadyComposer.Compose(1));
                    break;
                }
            }
        }
Example #3
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(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);
            }
        }