Ejemplo n.º 1
0
        internal static void TryRedeemVoucher(GameClient Session, string Code)
        {
            if (!IsValidCode(Code))
            {
                ServerMessage Error = new ServerMessage(Outgoing.VoucherRedeemError);
                Error.AppendRawInt32(0); // 0=invalid code,1=technical issue,3=redeem at webpage
                Session.SendMessage(Error);
                return;
            }

            int Value = GetVoucherValue(Code);

            TryDeleteVoucher(Code);

            Session.GetHabbo().Credits += Value;
            Session.GetHabbo().UpdateCreditsBalance();

            ServerMessage message = new ServerMessage(Outgoing.VoucherRedeemOk);
            message.AppendString("Credits"); // productName
            message.AppendString("Awesome"); // productDescription
            Session.SendMessage(message);
        }
Ejemplo n.º 2
0
        private static void GetSongData(GameClient Session, ClientMessage Message)
        {
            int Amount = Message.ReadInt32();
            List<SongData> Songs = new List<SongData>();

            for (int i = 0; i < Amount; i++)
            {
                SongData Song = GetSong(Message.ReadUInt32());

                if (Song == null)
                    continue;

                Songs.Add(Song);
            }

            Session.SendMessage(JukeboxComposer.Compose(Songs));
        }
Ejemplo n.º 3
0
        private static void GetPlaylist(GameClient Session, ClientMessage Message)
        {
            Room Instance = Session.GetHabbo().CurrentRoom;

            if (Instance == null || !Instance.CheckRights(Session, true))
            {
                return;
            }

            Session.SendMessage(JukeboxComposer.Compose(Instance.GetRoomMusicController().PlaylistCapacity,
                Instance.GetRoomMusicController().Playlist.Values.ToList()));
        }
Ejemplo n.º 4
0
 private static void GetDisks(GameClient Session, ClientMessage Message)
 {
     Session.SendMessage(JukeboxComposer.Compose(Session));
 }
Ejemplo n.º 5
0
        internal bool ProgressUserAchievement(GameClient Session, string AchievementGroup, int ProgressAmount)
        {
            if (!Achievements.ContainsKey(AchievementGroup))
            {
                return false;
            }

            Achievement AchievementData = null;

            AchievementData = Achievements[AchievementGroup];

            UserAchievement UserData = Session.GetHabbo().GetAchievementData(AchievementGroup);

            if (UserData == null)
            {
                UserData = new UserAchievement(AchievementGroup, 0, 0);
                Session.GetHabbo().Achievements.Add(AchievementGroup, UserData);
            }

            int TotalLevels = AchievementData.Levels.Count;

            if (UserData != null && UserData.Level == TotalLevels)
            {
                return false; // done, no more.
            }

            int TargetLevel = (UserData != null ? UserData.Level + 1 : 1);

            if (TargetLevel > TotalLevels)
            {
                TargetLevel = TotalLevels;
            }

            AchievementLevel TargetLevelData = AchievementData.Levels[TargetLevel];

            int NewProgress = (UserData != null ? UserData.Progress + ProgressAmount : ProgressAmount);
            int NewLevel = (UserData != null ? UserData.Level : 0);
            int NewTarget = NewLevel + 1;

            if (NewTarget > TotalLevels)
            {
                NewTarget = TotalLevels;
            }

            if (NewProgress >= TargetLevelData.Requirement)
            {
                NewLevel++;
                NewTarget++;

                int ProgressRemainder = NewProgress - TargetLevelData.Requirement;
                NewProgress = 0;

                Session.GetHabbo().GetBadgeComponent().GiveBadge(AchievementGroup + TargetLevel, true);

                if (NewTarget > TotalLevels)
                {
                    NewTarget = TotalLevels;
                }

                Session.GetHabbo().ActivityPoints += TargetLevelData.RewardPixels;
                Session.GetHabbo().UpdateActivityPointsBalance(false);

                Session.SendMessage(AchievementUnlockedComposer.Compose(AchievementData, TargetLevel, TargetLevelData.RewardPoints,
                    TargetLevelData.RewardPixels));

                using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("REPLACE INTO user_achievement VALUES (" + Session.GetHabbo().Id + ", @group, " + NewLevel + ", " + NewProgress + ")");
                    dbClient.addParameter("group", AchievementGroup);
                    dbClient.runQuery();
                }

                UserData.Level = NewLevel;
                UserData.Progress = NewProgress;

                Session.GetHabbo().AchievementPoints += TargetLevelData.RewardPoints;
                Session.GetHabbo().ActivityPoints += TargetLevelData.RewardPixels;
                Session.GetHabbo().UpdateActivityPointsBalance(false);
                Session.SendMessage(AchievementScoreUpdateComposer.Compose(Session.GetHabbo().AchievementPoints));

                AchievementLevel NewLevelData = AchievementData.Levels[NewTarget];
                Session.SendMessage(AchievementProgressComposer.Compose(AchievementData, NewTarget, NewLevelData,
                    TotalLevels, Session.GetHabbo().GetAchievementData(AchievementGroup)));

                return true;
            }
            else
            {
                UserData.Level = NewLevel;
                UserData.Progress = NewProgress;
                using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("REPLACE INTO user_achievement VALUES (" + Session.GetHabbo().Id + ", @group, " + NewLevel + ", " + NewProgress + ")");
                    dbClient.addParameter("group", AchievementGroup);
                    dbClient.runQuery();
                }

                Session.SendMessage(AchievementProgressComposer.Compose(AchievementData, TargetLevel, TargetLevelData,
                TotalLevels, Session.GetHabbo().GetAchievementData(AchievementGroup)));
            }

            return false;
        }
Ejemplo n.º 6
0
 internal void GetList(GameClient Session, ClientMessage Message)
 {
     Session.SendMessage(AchievementListComposer.Compose(Session, Achievements.Values.ToList()));
 }
Ejemplo n.º 7
0
        internal override bool OnTrigger(GameClient Session, RoomItem Item, int Request, bool UserHasRights)
        {
            if (Session == null || Item == null)
                return false;

            if (!UserHasRights)
                return false;

            String ExtraInfo = "";
            List<RoomItem> items = new List<RoomItem>();
            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                try
                {
                    dbClient.setQuery("SELECT trigger_data FROM trigger_item WHERE trigger_id = @id ");
                    dbClient.addParameter("id", (int)Item.Id);
                    ExtraInfo = dbClient.getString();
                }
                catch { }
                try
                {
                    dbClient.setQuery("SELECT triggers_item FROM trigger_in_place WHERE original_trigger = @id");
                    dbClient.addParameter("id", (int)Item.Id);
                    DataTable dTable = dbClient.getTable();
                    RoomItem targetItem;
                    foreach (DataRow dRows in dTable.Rows)
                    {
                        targetItem = Item.GetRoom().GetRoomItemHandler().GetItem(Convert.ToUInt32(dRows[0]));
                        if (targetItem == null || items.Contains(targetItem))
                            continue;
                        items.Add(targetItem);
                    }
                }
                catch { }
            }
            switch (Item.GetBaseItem().InteractionType)
            {
                #region Triggers

                case InteractionType.triggerwalkonfurni:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false); // stuffTypeSelectionEnabled
                        message.AppendInt32(5); // furniLimit

                        message.AppendInt32(items.Count); //stuffIds
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);

                        message.AppendInt32(Item.GetBaseItem().SpriteId); // stuffTypeId
                        message.AppendUInt(Item.Id); // id
                        message.AppendString(ExtraInfo); // stringParam

                        message.AppendInt32(0); // intParams

                        message.AppendInt32(8); // type
                        message.AppendInt32(0); // delayInPulses
                        message.AppendInt32(0); // conflictingTriggers
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggergamestart:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(0);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(8);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggerroomenter:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(0);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(7);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggergameend:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(0);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(8);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggertimer:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);

                        message.AppendString(ExtraInfo);
                        message.AppendInt32(1);
                        message.AppendInt32(1);
                        message.AppendInt32(1);
                        message.AppendInt32(3);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggerwalkofffurni:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);

                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(8);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggeronusersay:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(0);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggerscoreachieved:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(1);
                        message.AppendInt32(100);
                        message.AppendInt32(0);
                        message.AppendInt32(10);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggerrepeater:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(1);
                        message.AppendInt32(10);
                        message.AppendInt32(0);
                        message.AppendInt32(6);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.triggerstatechanged:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredFurniTrigger);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(8);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }
                #endregion

                #region Effects
                case InteractionType.actionposreset:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.actiongivescore:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(2);
                        message.AppendInt32(5);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(6);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.actionresettimer:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.actiontogglestate:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(8);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.actionshowmessage:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(0);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(7);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.actionteleportto:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(8);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendByte(2);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.actionmoverotate:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(2);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(4);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                #endregion

                #region Add-ons
                case InteractionType.specialrandom:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(8);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.specialunseen:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredEffect);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendString(ExtraInfo);
                        message.AppendInt32(0);
                        message.AppendInt32(8);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }
                #endregion

                #region Conditions
                case InteractionType.conditiontimelessthan:
                case InteractionType.conditiontimemorethan:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredCondition);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        //message.AppendBoolean(false);
                        //message.AppendBoolean(false);
                        //message.AppendInt32(7);
                        //message.AppendBoolean(false);
                        //message.AppendBoolean(false);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.conditionfurnishaveusers:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredCondition);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);

                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(1);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.conditionstatepos:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredCondition);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);

                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(1);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                case InteractionType.conditiontriggeronfurni:
                    {
                        ServerMessage message = new ServerMessage(Outgoing.WiredCondition);
                        message.AppendBoolean(false);
                        message.AppendInt32(5);
                        message.AppendInt32(items.Count);
                        foreach (RoomItem item in items)
                            message.AppendUInt(item.Id);
                        message.AppendInt32(Item.GetBaseItem().SpriteId);
                        message.AppendUInt(Item.Id);

                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);
                        message.AppendInt32(0);

                        Session.SendMessage(message);
                        break;
                    }

                //Unknown:
                //2 radio + 5 selct
                #endregion

            }
            return true;
        }
Ejemplo n.º 8
0
        internal void GetCurrentQuest(GameClient Session, ClientMessage Message)
        {
            if (!Session.GetHabbo().InRoom)
            {
                return;
            }

            Quest UserQuest = GetQuest(Session.GetHabbo().LastCompleted);
            Quest NextQuest = GetNextQuestInSeries(UserQuest.Category, UserQuest.Number + 1);

            if (NextQuest == null)
            {
                return;
            }

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.runFastQuery("REPLACE INTO user_quests VALUES (" + Session.GetHabbo().Id + ", " + NextQuest.Id + ", 0)");
                dbClient.runFastQuery("UPDATE users SET currentquestid = " + NextQuest.Id + " WHERE id = " + Session.GetHabbo().Id);
            }

            Session.GetHabbo().CurrentQuestId = NextQuest.Id;
            GetList(Session, null);
            Session.SendMessage(QuestStartedComposer.Compose(Session, NextQuest));

            //Session.SendMessage(QuestStartedComposer.Compose(Session, NextQuest));
        }
Ejemplo n.º 9
0
        internal static void HandleSave(GameClient Session, uint itemID, Room room, ClientMessage clientMessage)
        {
            RoomItem item = room.GetRoomItemHandler().GetItem(itemID);
            if (item == null)
                return;

            if (item.wiredHandler != null)
            {
                item.wiredHandler.Dispose();
                item.wiredHandler = null;
            }
            //Logging.WriteLine("handle wired!");
            InteractionType type = item.GetBaseItem().InteractionType;
            switch (type)
            {
                case InteractionType.triggeronusersay:
                    {
                        int junk = clientMessage.ReadInt32();
                        bool isOnlyOwner = (clientMessage.ReadInt32() == 1);
                        string message = clientMessage.ReadString();
                        //Logging.WriteLine("Handle 'onusersay' itemid(" + item.Id + ") junk(" + junk + ") wired: isOnlyOwner(" + isOnlyOwner + ") message = " + message);

                        IWiredTrigger handler = new UserSays(item, room.GetWiredHandler(), isOnlyOwner, message, room);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }
                case InteractionType.triggerwalkonfurni:
                    {
                        int junk = clientMessage.ReadInt32();
                        string message = clientMessage.ReadString();
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.ReadInt32();

                        IWiredTrigger handler = new WalksOnFurni(item, room.GetWiredHandler(), items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }
                case InteractionType.triggerwalkofffurni:
                    {
                        int junk = clientMessage.ReadInt32();
                        string message = clientMessage.ReadString();
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.ReadInt32();

                        IWiredTrigger handler = new WalksOnFurni(item, room.GetWiredHandler(), items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }
                case InteractionType.actionshowmessage:
                    {
                        int junk = clientMessage.ReadInt32();
                        string message = clientMessage.ReadString();

                        IWiredTrigger action = new ShowMessage(message, room.GetWiredHandler(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);
                        break;
                    }
                case InteractionType.actionteleportto:
                    {
                        int junk = clientMessage.ReadInt32();
                        string junk2 = clientMessage.ReadString();
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.ReadInt32();

                        IWiredTrigger action = new TeleportToItem(room.GetGameMap(), room.GetWiredHandler(), items, delay, itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);
                        break;
                    }
                case InteractionType.actiontogglestate:
                    {
                        int junk = clientMessage.ReadInt32();
                        string message = clientMessage.ReadString();
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.ReadInt32();
                        //Logging.WriteLine("Save action toogle wired with " + items.Count + " item(s) and " + delay + " second(s) of delay!");

                        IWiredTrigger action = new ToggleItemState(room.GetGameMap(), room.GetWiredHandler(), items, delay, item);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);
                        break;
                    }
                case InteractionType.actionmoverotate:
                    {
                        int junk = clientMessage.ReadInt32();
                        MovementState movement = (MovementState)clientMessage.ReadInt32();
                        RotationState rotation = (RotationState)clientMessage.ReadInt32();

                        bool junk3 = clientMessage.ReadBoolean();
                        bool junk2 = clientMessage.ReadBoolean();
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.ReadInt32();

                        IWiredTrigger handler = new MoveRotate(movement, rotation, items, delay, room, room.GetWiredHandler(), itemID);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }
                case InteractionType.actionposreset:
                    {

                        int junk = clientMessage.ReadInt32();
                        bool junk3 = clientMessage.ReadBoolean();
                        bool junk2 = clientMessage.ReadBoolean();

                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.ReadInt32();

                        IWiredTrigger action = new PositionReset(items, delay, room.GetRoomItemHandler(), room.GetWiredHandler(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionresettimer:
                    {

                        int junk = clientMessage.ReadInt32();
                        bool junk3 = clientMessage.ReadBoolean();
                        bool junk2 = clientMessage.ReadBoolean();
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.ReadInt32();

                        IWiredTrigger action = new TimerReset(room, room.GetWiredHandler(), items, delay, itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }
                case InteractionType.actiongivescore:
                    {
                        int junk = clientMessage.ReadInt32();
                        int points = clientMessage.ReadInt32();
                        int games = clientMessage.ReadInt32();

                        IWiredTrigger action = new GiveScore(games, points, room.GetGameManager(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }
                case InteractionType.triggergameend:
                    {
                        IWiredTrigger handler = new GameEnds(item, room.GetWiredHandler(), room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggergamestart:
                    {
                        IWiredTrigger handler = new GameStarts(item, room.GetWiredHandler(), room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }
                case InteractionType.triggerrepeater:
                    {
                        int junk = clientMessage.ReadInt32();
                        int cycleTimes = clientMessage.ReadInt32();

                        IWiredTrigger handler = new Repeater(room.GetWiredHandler(), item, cycleTimes);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerroomenter:
                    {
                        int junk = clientMessage.ReadInt32();
                        string users = clientMessage.ReadString();

                        IWiredTrigger handler = new EntersRoom(item, room.GetWiredHandler(), room.GetRoomUserManager(), !string.IsNullOrEmpty(users), users);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggerscoreachieved:
                    {
                        int junk = clientMessage.ReadInt32();
                        int score = clientMessage.ReadInt32();

                        IWiredTrigger handler = new ScoreAchieved(item, room.GetWiredHandler(), score, room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggertimer:
                    {
                        int junk = clientMessage.ReadInt32();
                        int cycles = clientMessage.ReadInt32();

                        IWiredTrigger handler = new Timer(item, room.GetWiredHandler(), cycles, room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerstatechanged:
                    {
                        int junk = clientMessage.ReadInt32();
                        bool junk3 = clientMessage.ReadBoolean();
                        bool junk2 = clientMessage.ReadBoolean();

                        int furniAmount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniAmount);
                        int delay = clientMessage.ReadInt32();

                        IWiredTrigger handler = new SateChanged(room.GetWiredHandler(), item, items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }
            }
            Session.SendMessage(new ServerMessage(Outgoing.SaveWired));
            /*switch (type)
            {
                case InteractionType.actiongivescore:
                    {
                        clientMessage.AdvancePointer(1);
                        int points = clientMessage.PopWiredInt32();
                        int games = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new GiveScore(games, points, room.GetGameManager(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionmoverotate:
                    {
                        clientMessage.AdvancePointer(1);
                        MovementState movement = (MovementState)clientMessage.PopWiredInt32();
                        RotationState rotation = (RotationState)clientMessage.PopWiredInt32();

                        clientMessage.AdvancePointer(2);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new MoveRotate(movement, rotation, items, delay, room, room.GetWiredHandler(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionposreset:
                    {

                        clientMessage.AdvancePointer(3);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new PositionReset(items, delay, room.GetRoomItemHandler(), room.GetWiredHandler(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionresettimer:
                    {

                        clientMessage.AdvancePointer(3);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new TimerReset(room, room.GetWiredHandler(), items, delay, itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionshowmessage:
                    {
                        clientMessage.AdvancePointer(1);
                        string message = clientMessage.PopFixedString();

                        IWiredTrigger action = new ShowMessage(message, room.GetWiredHandler(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.actionteleportto:
                    {
                        clientMessage.AdvancePointer(3);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new TeleportToItem(room.GetGameMap(), room.GetWiredHandler(), items, delay, itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actiontogglestate:
                    {
                        clientMessage.AdvancePointer(3);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new ToggleItemState(room.GetGameMap(), room.GetWiredHandler(), items, delay, itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.conditionfurnishaveusers:
                    {
                        clientMessage.AdvancePointer(1);
                        bool a = clientMessage.PopWiredBoolean();
                        bool b = clientMessage.PopWiredBoolean();
                        bool c = clientMessage.PopWiredBoolean();
                        clientMessage.AdvancePointer(2);

                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);

                        if (a)
                        {
                            int a1 = 2;
                        }

                        break;
                    }

                case InteractionType.conditionstatepos:
                    {

                        break;
                    }

                case InteractionType.conditiontimelessthan:
                    {

                        break;
                    }

                case InteractionType.conditiontimemorethan:
                    {

                        break;
                    }

                case InteractionType.conditiontriggeronfurni:
                    {

                        break;
                    }

                case InteractionType.specialrandom:
                    {

                        break;
                    }

                case InteractionType.specialunseen:
                    {

                        break;
                    }

                case InteractionType.triggergameend:
                    {
                        IWiredTrigger handler = new GameEnds(item, room.GetWiredHandler(), room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggergamestart:
                    {
                        IWiredTrigger handler = new GameStarts(item, room.GetWiredHandler(), room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggeronusersay:
                    {
                        clientMessage.AdvancePointer(1);
                        bool isOnlyOwner = clientMessage.PopWiredBoolean();
                        clientMessage.AdvancePointer(0);
                        string message = clientMessage.PopFixedString();
                        string stuff = clientMessage.ToString();

                        IWiredTrigger handler = new UserSays(item, room.GetWiredHandler(), isOnlyOwner, message, room);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerrepeater:
                    {
                        clientMessage.AdvancePointer(1);
                        int cycleTimes = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new Repeater(room.GetWiredHandler(), item, cycleTimes);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerroomenter:
                    {
                        clientMessage.AdvancePointer(1);
                        string users = clientMessage.PopFixedString();

                        IWiredTrigger handler = new EntersRoom(item, room.GetWiredHandler(), room.GetRoomUserManager(), !string.IsNullOrEmpty(users), users);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggerscoreachieved:
                    {
                        clientMessage.AdvancePointer(1);
                        int score = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new ScoreAchieved(item, room.GetWiredHandler(), score, room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggertimer:
                    {
                        clientMessage.AdvancePointer(1);
                        int cycles = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new Timer(item, room.GetWiredHandler(), cycles, room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerstatechanged:
                    {
                        clientMessage.AdvancePointer(3);

                        int furniAmount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniAmount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new SateChanged(room.GetWiredHandler(), item, items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerwalkofffurni:
                    {
                        clientMessage.AdvancePointer(3);

                        int furniAmount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniAmount);

                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new WalksOffFurni(item, room.GetWiredHandler(), items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggerwalkonfurni:
                    {
                        clientMessage.AdvancePointer(3);
                        int furniAmount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniAmount);

                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new WalksOnFurni(item, room.GetWiredHandler(), items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }
            }*/
        }
Ejemplo n.º 10
0
        internal void CancelQuest(GameClient Session, ClientMessage Message)
        {
            Quest Quest = GetQuest(Session.GetHabbo().CurrentQuestId);

            if (Quest == null)
            {
                return;
            }

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.runFastQuery("DELETE FROM user_quests WHERE user_id = " + Session.GetHabbo().Id + " AND quest_id = " + Quest.Id);
            }

            Session.SendMessage(QuestAbortedComposer.Compose());
            GetList(Session, null);
        }
Ejemplo n.º 11
0
        internal void ActivateQuest(GameClient Session, ClientMessage Message)
        {
            Quest Quest = GetQuest(Message.ReadUInt32());

            if (Quest == null)
            {
                return;
            }

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {

                dbClient.runFastQuery("REPLACE INTO user_quests VALUES (" + Session.GetHabbo().Id + ", " + Quest.Id + ", 0)");
                dbClient.runFastQuery("UPDATE users SET currentquestid = " + Quest.Id + " WHERE id = " + Session.GetHabbo().Id);
            }

            Session.GetHabbo().CurrentQuestId = Quest.Id;
            GetList(Session, null);
            Session.SendMessage(QuestStartedComposer.Compose(Session, Quest));
        }
Ejemplo n.º 12
0
        internal void ProgressUserQuest(GameClient Session, QuestType QuestType, uint EventData = 0)
        {
            if (Session == null || Session.GetHabbo() == null || Session.GetHabbo().CurrentQuestId <= 0)
            {
                return;
            }

            Quest UserQuest = GetQuest(Session.GetHabbo().CurrentQuestId);

            if (UserQuest == null || UserQuest.GoalType != QuestType)
            {
                return;
            }

            int CurrentProgress = Session.GetHabbo().GetQuestProgress(UserQuest.Id);
            int NewProgress = CurrentProgress;
            bool PassQuest = false;

            switch (QuestType)
            {
                default:

                    NewProgress++;

                    if (NewProgress >= UserQuest.GoalData)
                    {
                        PassQuest = true;
                    }

                    break;

                case QuestType.EXPLORE_FIND_ITEM:

                    if (EventData != UserQuest.GoalData)
                        return;

                    NewProgress = (int)UserQuest.GoalData;
                    PassQuest = true;
                    break;
            }

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.runFastQuery("UPDATE user_quests SET progress = " + NewProgress +  " WHERE user_id = " + Session.GetHabbo().Id + " AND quest_id =  " + UserQuest.Id);

                if (PassQuest)
                {
                    dbClient.runFastQuery("UPDATE users SET currentquestid = 0 WHERE id = " + Session.GetHabbo().Id);
                    //Quest NextQuest = GetNextQuestInSeries(UserQuest.Category, UserQuest.Number + 1);

                    //if (NextQuest != null)
                    //    dbClient.runFastQuery("INSERT INTO user_quests (user_id, quest_id, progress) VALUES (" + Session.GetHabbo().Id + ", " + NextQuest.Id + ", 0)");
                }
            }

            Session.GetHabbo().quests[Session.GetHabbo().CurrentQuestId] = NewProgress;
            Session.SendMessage(QuestStartedComposer.Compose(Session, UserQuest));

            if (PassQuest)
            {
                Session.GetHabbo().CurrentQuestId = 0;
                Session.GetHabbo().LastCompleted = UserQuest.Id;
                Session.SendMessage(QuestCompletedComposer.Compose(Session, UserQuest));
                Session.GetHabbo().ActivityPoints += UserQuest.Reward;
                Session.GetHabbo().UpdateActivityPointsBalance(false);
                GetList(Session, null);
            }
        }
Ejemplo n.º 13
0
 internal void GetList(GameClient Session, ClientMessage Message)
 {
     Session.SendMessage(QuestListComposer.Compose(Session, quests.Values.ToList(), (Message != null)));
 }
Ejemplo n.º 14
0
        private static void RemoveFromPlaylist(GameClient Session, ClientMessage Message)
        {
            Room Instance = Session.GetHabbo().CurrentRoom;

            if (Instance == null ||  !Instance.GotMusicController() || !Instance.CheckRights(Session, true))
            {
                return;
            }

            SongItem TakenItem = Instance.GetRoomMusicController().RemoveDisk(Message.ReadInt32());
            // playlist will skip to the next item automatically if it has to

            if (TakenItem == null)
            {
                return;
            }

            Session.GetHabbo().GetInventoryComponent().AddNewItem(TakenItem.itemID, TakenItem.baseItem.ItemId, new StringData(TakenItem.songID.ToString()), 0, true, true);

            Session.SendMessage(JukeboxComposer.Compose(Session));
            Session.SendMessage(JukeboxComposer.Compose(Instance.GetRoomMusicController().PlaylistCapacity,
                Instance.GetRoomMusicController().Playlist.Values.ToList()));
        }
Ejemplo n.º 15
0
        internal void HandlePurchase(GameClient Session, int PageId, uint ItemId, string extraParameter, int buyAmount, Boolean IsGift, string GiftUser, string GiftMessage, int GiftSpriteId, int GiftLazo, int GiftColor, bool giftShowIdentity)
        {
            int finalAmount = buyAmount;
            if (buyAmount > 5) // Possible discount!
            {
                // Nearest number that increases the amount of free items
                int nearestDiscount = ((int)Math.Floor(buyAmount / 6.0) * 6);

                // How many free ones we get
                int freeItemsCount = (nearestDiscount - 3) / 3;

                // Add 1 free if more than 42
                if (buyAmount >= 42)
                    freeItemsCount++;

                // Doesn't follow rules as it isn't dividable by 6, but still increases free items
                if (buyAmount >= 99)
                {
                    freeItemsCount = 33;
                }

                // This is how many we pay for in the end
                finalAmount = buyAmount - freeItemsCount;
            }

            //Logging.WriteLine("Amount: " + priceAmount + "; withOffer= " + finalAmount);
            CatalogPage Page;
            if (!Pages.TryGetValue(PageId, out Page))
                return;
            if (Page == null || !Page.Enabled || !Page.Visible || Session == null || Session.GetHabbo() == null)
            {
                Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                return;
            }
            if (Page.ClubOnly && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_club") && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip"))
            {
                Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                return;
            }
            if (Page.MinRank > Session.GetHabbo().Rank)
            {
                Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                return;
            }
            CatalogItem Item = Page.GetItem(ItemId);

            if (Item == null) // TODO: Check item minimum club rank
            {
                Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                return;
            }
            if (!Item.HaveOffer && buyAmount > 1) // Check if somebody is bulk-buying when not allowed
            {
                Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                return;
            }
            if (Item.IsLimited && Item.LimitedStack <= Item.LimitedSelled)
            {
                Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                return;
            }

            uint GiftUserId = 0;
            //int giftWrappingCost = 0;
            if (IsGift)
            {
                if(!Item.AllowGift)
                {
                    Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                    return;
                }
                if(Item.Items.Count > 1 || Item.Amount > 1) // Gifts can only have 1 item?
                {
                    Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                    return;
                }

                DataRow dRow;
                using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("SELECT id FROM users WHERE username = @gift_user");
                    dbClient.addParameter("gift_user", GiftUser);

                    dRow = dbClient.getRow();
                }

                if (dRow == null)
                {
                    Session.GetMessageHandler().GetResponse().Init(Outgoing.GiftError);
                    Session.GetMessageHandler().GetResponse().AppendString(GiftUser);
                    Session.GetMessageHandler().SendResponse();

                    return;
                }

                GiftUserId = Convert.ToUInt32(dRow[0]);

                if (GiftUserId == 0)
                {
                    Session.GetMessageHandler().GetResponse().Init(Outgoing.GiftError);
                    Session.GetMessageHandler().GetResponse().AppendString(GiftUser);
                    Session.GetMessageHandler().SendResponse();

                    return;
                }
            }

            Boolean CreditsError = false;
            Boolean PixelError = false;
            Boolean CrystalError = false;

            if (Session.GetHabbo().Credits < (Item.CreditsCost * finalAmount))
            {
                CreditsError = true;
            }

            if (Session.GetHabbo().VipPoints < (Item.CrystalCost * finalAmount))
            {
                CrystalError = true;
            }

            if (Session.GetHabbo().ActivityPoints < (Item.PixelsCost * finalAmount))
            {
                PixelError = true;
            }

            if (CreditsError || PixelError)
            {
                ServerMessage message = new ServerMessage(Outgoing.NotEnoughBalance);
                message.AppendBoolean(CreditsError);
                message.AppendBoolean(PixelError);
                Session.SendMessage(message);
                return;
            }

            if (Item.CrystalCost > 0)
            {
                int cost = Item.CrystalCost * finalAmount;
                if (Session.GetHabbo().VipPoints < cost)
                {
                    Session.SendNotif("You can't afford that item!");
                    Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                    return;
                }

                Session.GetHabbo().VipPoints -= cost;
                Session.GetHabbo().UpdateActivityPointsBalance(true);

                using (IQueryAdapter adapter = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    adapter.runFastQuery("UPDATE users SET vip_points = " + Session.GetHabbo().VipPoints + " WHERE id = " + Session.GetHabbo().Id);
                }

            }

            if (Item.CreditsCost > 0 && !IsGift)
            {
                Session.GetHabbo().Credits -= (Item.CreditsCost * finalAmount);
                Session.GetHabbo().UpdateCreditsBalance();
            }

            if (Item.PixelsCost > 0 && !IsGift)
            {
                Session.GetHabbo().ActivityPoints -= (Item.PixelsCost * finalAmount);
                Session.GetHabbo().UpdateActivityPointsBalance(true);
            }

            // Item is purchased, now do post-proccessing
            if (Item.IsLimited)
            {
                Item.LimitedSelled++;
                using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.runFastQuery("UPDATE catalog_items SET limited_sells = " + Item.LimitedSelled + " WHERE id = " + Item.Id);
                }
                Page.InitMsg(); // update page!

                // send update
                Session.SendMessage(Page.GetMessage);
            }

            foreach (uint i in Item.Items)
            {
                //Logging.WriteLine(Item.GetBaseItem().ItemId);
                //Logging.WriteLine(Item.GetBaseItem().InteractionType.ToLower());
                // Extra Data is _NOT_ filtered at this point and MUST BE VERIFIED BELOW:
                if (Item.GetBaseItem(i).Type == 'h') // Subscription
                {
                    int Months = 0;
                    int Days = 0;
                    if (Item.Name.Contains("HABBO_CLUB_VIP_"))
                    {
                        if (Item.Name.Contains("_DAY"))
                        {
                            Days = int.Parse(Item.Name.Split('_')[3]);
                        }
                        else if (Item.Name.Contains("_MONTH"))
                        {
                            Months = int.Parse(Item.Name.Split('_')[3]);
                            Days = 31 * Months;
                        }
                    }
                    else if (Item.Name.Equals("deal_vip_1_year_and_badge"))
                    {
                        Months = 12;
                        Days = 31 * Months;
                    }
                    else if (Item.Name.Equals("HABBO_CLUB_VIP_5_YEAR"))
                    {
                        Months = 5 * 12;
                        Days = 31 * Months;
                    }
                    else if (Item.Name.StartsWith("DEAL_HC_"))
                    {
                        Months = int.Parse(Item.Name.Split('_')[2]);
                        Days = 31 * Months;

                        Session.GetHabbo().GetSubscriptionManager().AddOrExtendSubscription("habbo_club", Days * 24 * 3600);
                        Session.GetHabbo().SerializeClub();
                        return;
                    }

                    Session.GetHabbo().GetSubscriptionManager().AddOrExtendSubscription("habbo_vip", Days * 24 * 3600);
                    Session.GetHabbo().SerializeClub();
                    return;
                }

                if (IsGift && Item.GetBaseItem(i).Type == 'e')
                {
                    Session.SendNotif(LanguageLocale.GetValue("catalog.gift.send.error"));
                    return;
                }
                IRoomItemData itemData = new StringData(extraParameter);
                switch (Item.GetBaseItem(i).InteractionType)
                {
                    case InteractionType.none:
                        //itemData = new StringData(extraParameter);
                        break;

                    case InteractionType.musicdisc:
                        itemData = new StringData(Item.songID.ToString());
                        break;

                    #region Pet handling
                    case InteractionType.pet:
                        try
                        {
                            string[] Bits = extraParameter.Split('\n');
                            string PetName = Bits[0];
                            string Race = Bits[1];
                            string Color = Bits[2];

                            int.Parse(Race); // to trigger any possible errors

                            if (!CheckPetName(PetName))
                            {
                                Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                                return;
                            }

                            //if (Race.Length != 1)
                            //    return;

                            if (Color.Length != 6)
                            {
                                Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                                return;
                            }
                        }
                        catch (Exception e)
                        {
                            Logging.WriteLine(e.ToString());
                            Logging.HandleException(e, "Catalog.HandlePurchase");
                            Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                            return;
                        }

                        break;

                    #endregion

                    case InteractionType.roomeffect:

                        Double Number = 0;

                        try
                        {
                            if (string.IsNullOrEmpty(extraParameter))
                                Number = 0;
                            else
                                Number = Double.Parse(extraParameter, FirewindEnvironment.cultureInfo);
                        }
                        catch (Exception e) { Logging.HandleException(e, "Catalog.HandlePurchase: " + extraParameter); }

                        itemData = new StringData(Number.ToString().Replace(',', '.'));
                        break; // maintain extra data // todo: validate

                    case InteractionType.postit:
                        itemData = new StringData("FFFF33");
                        break;

                    case InteractionType.dimmer:
                        itemData = new StringData("1,1,1,#000000,255");
                        break;

                    case InteractionType.trophy:
                        itemData = new StringData(String.Format("{0}\t{1}\t{2}", Session.GetHabbo().Username, DateTime.Now.ToString("d-M-yyy"), extraParameter));
                        break;

                    //case InteractionType.mannequin:
                    //    MapStuffData data = new MapStuffData();
                    //    data.Data.Add("OUTFIT_NAME", "");
                    //    data.Data.Add("FIGURE", "");
                    //    data.Data.Add("GENDER", "");
                    //    itemData = data;
                    //    break;
                    default:
                        //itemData = new StringData(extraParameter);
                        break;
                }

                //Session.GetMessageHandler().GetResponse().Init(Outgoing.UpdateInventary);
                //Session.GetMessageHandler().SendResponse();

                Session.GetMessageHandler().GetResponse().Init(Outgoing.PurchaseOK); // PurchaseOKMessageEvent
                Item.Serialize(Session.GetMessageHandler().GetResponse());
                Session.GetMessageHandler().SendResponse();

                if (IsGift)
                {
                    uint itemID;
                    //uint GenId = GenerateItemId();
                    Item Present = FirewindEnvironment.GetGame().GetItemManager().GetItemBySpriteID(GiftSpriteId);
                    if (Present == null)
                    {
                        Logging.LogDebug(string.Format("Somebody tried to purchase a present with invalid sprite ID: {0}", GiftSpriteId));
                        Session.SendMessage(new ServerMessage(Outgoing.PurchaseError));
                        return;
                    }

                    MapStuffData giftData = new MapStuffData();

                    if (giftShowIdentity)
                    {
                        giftData.Data.Add("PURCHASER_NAME", Session.GetHabbo().Username);
                        giftData.Data.Add("PURCHASER_FIGURE", Session.GetHabbo().Look);
                    }
                    giftData.Data.Add("MESSAGE", GiftMessage);
                    giftData.Data.Add("PRODUCT_CODE", "10");
                    giftData.Data.Add("EXTRA_PARAM", "test");
                    giftData.Data.Add("state", "1");

                    using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + Present.ItemId + ")");
                        itemID = (uint)dbClient.insertQuery();

                        dbClient.runFastQuery("INSERT INTO items_users VALUES (" + itemID + "," + GiftUserId + ")");

                        if (!string.IsNullOrEmpty(GiftMessage))
                        {
                            dbClient.setQuery("INSERT INTO items_extradata VALUES (" + itemID + ",@datatype,@data,@extra)");
                            dbClient.addParameter("datatype", giftData.GetTypeID());
                            dbClient.addParameter("data", giftData.ToString());
                            dbClient.addParameter("extra", GiftColor * 1000 + GiftLazo);
                            dbClient.runQuery();
                        }

                        dbClient.setQuery("INSERT INTO user_presents (item_id,base_id,amount,extra_data) VALUES (" + itemID + "," + Item.GetBaseItem(i).ItemId + "," + Item.Amount + ",@extra_data)");
                        dbClient.addParameter("extra_data", itemData.ToString());
                        dbClient.runQuery();
                    }

                    GameClient Receiver = FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(GiftUserId);

                    if (Receiver != null)
                    {
                        Receiver.SendNotif(LanguageLocale.GetValue("catalog.gift.received") + Session.GetHabbo().Username);
                        UserItem u = Receiver.GetHabbo().GetInventoryComponent().AddNewItem(itemID, Present.ItemId, giftData, GiftColor * 1000 + GiftLazo, false, false, 0);
                        Receiver.GetHabbo().GetInventoryComponent().SendFloorInventoryUpdate();
                        Receiver.GetMessageHandler().GetResponse().Init(Outgoing.UnseenItems);
                        Receiver.GetMessageHandler().GetResponse().AppendInt32(1); // items
                        Receiver.GetMessageHandler().GetResponse().AppendInt32(1); // type (gift) == s
                        Receiver.GetMessageHandler().GetResponse().AppendInt32(1);
                        Receiver.GetMessageHandler().GetResponse().AppendUInt(u.Id);
                        Receiver.GetMessageHandler().SendResponse();
                        InventoryComponent targetInventory = Receiver.GetHabbo().GetInventoryComponent();
                        if (targetInventory != null)
                            targetInventory.RunDBUpdate();
                    }

                    Session.SendNotif(LanguageLocale.GetValue("catalog.gift.sent"));
                }
                else
                {
                    List<UserItem> items = DeliverItems(Session, Item.GetBaseItem(i), (buyAmount * Item.Amount), itemData.ToString(), Item.songID);
                    int Type = 2;
                    if (Item.GetBaseItem(i).Type.ToString().ToLower().Equals("s"))
                    {
                        if (Item.GetBaseItem(i).InteractionType == InteractionType.pet)
                            Type = 3;
                        else
                            Type = 1;
                    }

                    Session.GetMessageHandler().GetResponse().Init(Outgoing.UnseenItems);
                    Session.GetMessageHandler().GetResponse().AppendInt32(1); // items
                    Session.GetMessageHandler().GetResponse().AppendInt32(Type);

                    Session.GetMessageHandler().GetResponse().AppendInt32(items.Count);
                    foreach (UserItem u in items)
                        Session.GetMessageHandler().GetResponse().AppendUInt(u.Id);

                    Session.GetMessageHandler().SendResponse();

                    //Logging.WriteLine("Purchased " + items.Count);
                    Session.GetHabbo().GetInventoryComponent().UpdateItems(false);

                    if (Item.GetBaseItem(i).InteractionType == InteractionType.pet)
                    {
                        Session.SendMessage(Session.GetHabbo().GetInventoryComponent().SerializePetInventory());
                    }

                }
            }
        }
Ejemplo n.º 16
0
        private static void AddToPlaylist(GameClient Session, ClientMessage Message)
        {
            Room Instance = Session.GetHabbo().CurrentRoom;

            if (Instance == null || !Instance.CheckRights(Session, true) || !Instance.GotMusicController() ||
                Instance.GetRoomMusicController().PlaylistSize >= Instance.GetRoomMusicController().PlaylistCapacity)
            {
                return;
            }

            UserItem DiskUserItem = Session.GetHabbo().GetInventoryComponent().GetItem(Message.ReadUInt32());

            if (DiskUserItem == null || DiskUserItem.GetBaseItem().InteractionType != InteractionType.musicdisc)
            {
                return;
            }

            SongItem item = new SongItem(DiskUserItem);

            int NewOrder = Instance.GetRoomMusicController().AddDisk(item);

            if (NewOrder < 0)
            {
                return;
            }

            Session.GetHabbo().GetInventoryComponent().RemoveItem(item.itemID, true);

            Session.SendMessage(JukeboxComposer.Compose(Instance.GetRoomMusicController().PlaylistCapacity,
                Instance.GetRoomMusicController().Playlist.Values.ToList()));
        }
Ejemplo n.º 17
0
        internal static void HandleConditionSave(GameClient Session, uint itemID, Room room, ClientMessage clientMessage)
        {
            // // id, resolveIntParams, resolveStringParam, getStuffIds, resolveStuffSelectionType
            RoomItem item = room.GetRoomItemHandler().GetItem(itemID);
            if (item == null)
                return;

            if (item.wiredCondition != null)
            {
                item.wiredCondition.Dispose();
                item.wiredCondition = null;
            }

            InteractionType type = item.GetBaseItem().InteractionType;

            if (type != InteractionType.conditionfurnishaveusers && type != InteractionType.conditionstatepos &&
                type != InteractionType.conditiontimelessthan && type != InteractionType.conditiontimemorethan &&
                type != InteractionType.conditiontriggeronfurni)
                return;

            // Parse data
            int[] intParams = new int[clientMessage.ReadInt32()];
            for (int i = 0; i < intParams.Length; i++)
                intParams[i] = clientMessage.ReadInt32();

            string stringParam = clientMessage.ReadString();

            int furniCount;
            List<RoomItem> items = GetItems(clientMessage, room, out furniCount);

            int stuffSelectionType = clientMessage.ReadInt32();

            IWiredCondition handler = null;

            switch (type)
            {
                case InteractionType.conditionfurnishaveusers:
                    {
                        handler = new FurniHasUser(item, items);
                        break;
                    }
                case InteractionType.conditionstatepos:
                    {
                        handler = new FurniStatePosMatch(item, items);
                        break;
                    }

                case InteractionType.conditiontimelessthan:
                    {
                        handler = new LessThanTimer(500, room, item);
                        break;
                    }

                case InteractionType.conditiontimemorethan:
                    {
                        handler = new MoreThanTimer(500, room, item);
                        break;
                    }

                case InteractionType.conditiontriggeronfurni:
                    {
                        handler = new TriggerUserIsOnFurni(item, items);
                        break;
                    }

                default:
                    return;
            }

            item.wiredCondition = handler;
            room.GetWiredHandler().conditionHandler.AddOrIgnoreRefferance(item);

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                handler.SaveToDatabase(dbClient);
            }
            Session.SendMessage(new ServerMessage(Outgoing.SaveWired));
        }