示例#1
0
        private static void IgnoreUser(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            uint UserId = CharacterResolverCache.GetUidFromName(Message.PopString());

            if (UserId == 0)
            {
                return;
            }

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession != null)
            {
                if (TargetSession.HasRight("cannot_ignore"))
                {
                    Session.SendData(NotificationMessageComposer.Compose("You can not ignore this user."));
                    return;
                }

                Session.IgnoreCache.MarkUserIgnored(TargetSession.CharacterId);
                Session.SendData(RoomIgnoreResultComposer.Compose(1));
            }
        }
示例#2
0
        public static RoomInfo GetRoomInfo(uint RoomId, bool IgnoreCache)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(RoomId);

            if (Instance != null)
            {
                return(Instance.Info);
            }

            if (!IgnoreCache)
            {
                RoomInfo CachedInfo = TryGetInfoFromCache(RoomId);

                if (CachedInfo != null)
                {
                    return(CachedInfo);
                }
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                MySqlClient.SetParameter("id", RoomId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM rooms WHERE id = @id LIMIT 1");

                if (Row != null)
                {
                    return(GenerateRoomInfoFromRow(Row));
                }
            }

            return(null);
        }
示例#3
0
        private static void MoveWallItem(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session))
            {
                return;
            }

            Item Item = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Type != ItemType.WallItem)
            {
                return;
            }

            string RawPlacementData = Message.PopString();
            string WallPos          = Instance.SetWallItem(Session, RawPlacementData, Item);

            if (WallPos.Length > 0)
            {
                Item.MoveToRoom(null, Instance.RoomId, new Vector3(0, 0, 0), 0, WallPos);
                RoomManager.MarkWriteback(Item, false);

                Instance.BroadcastMessage(RoomWallItemMovedComposer.Compose(Item));

                ItemEventDispatcher.InvokeItemEventHandler(Session, Item, Instance, ItemEventType.Moved);
            }
        }
示例#4
0
        private static void TakeItem(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            int  Unknown1 = Message.PopWiredInt32();
            Item Item     = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Behavior == ItemBehavior.StickyNote)
            {
                return;
            }

            if (Instance.TakeItem(Item.Id))
            {
                ItemEventDispatcher.InvokeItemEventHandler(Session, Item, Instance, ItemEventType.Removing);

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Item.MoveToUserInventory(MySqlClient, Session.CharacterId);
                }

                Instance.RegenerateRelativeHeightmap();

                Session.InventoryCache.Add(Item);
                Session.SendData(InventoryItemAddedComposer.Compose(Item));

                QuestManager.ProgressUserQuest(Session, QuestType.FURNI_PICK);
            }
        }
示例#5
0
        private static void AnswerDoorbell(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session))
            {
                return;
            }

            string Name   = Message.PopString();
            bool   Accept = (Message.ReadBytes(1)[0] == 65);

            Session TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Name));

            if (TargetSession == null || TargetSession.AbsoluteRoomId != Instance.RoomId || TargetSession.RoomAuthed)
            {
                return;
            }

            if (Accept)
            {
                TargetSession.RoomAuthed = true;
                TargetSession.SendData(RoomDoorbellAcceptedComposer.Compose());
                return;
            }

            TargetSession.SendData(RoomDoorbellNoResponseComposer.Compose());
            RoomManager.RemoveUserFromRoom(TargetSession, false);
        }
示例#6
0
        private static void AddToStaffPicked(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Session.HasRight("hotel_admin"))
            {
                return;
            }

            if (!Navigator.StaffPickedContainsRoom(Instance.RoomId))
            {
                Navigator.AddRoomToStaffPicked(Instance.RoomId);
                Session.SendData(NotificationMessageComposer.Compose("This room has been added to the staff picked rooms successfully."));

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Session TargetSession = SessionManager.GetSessionByCharacterId(Instance.Info.OwnerId);

                    if (TargetSession != null)
                    {
                        AchievementManager.ProgressUserAchievement(MySqlClient, TargetSession, "ACH_Spr", 1);
                    }

                    // todo: need a way to save achievement progress in the database so it can be applied on user login
                    //       right now it's impossible to progress an user's achievement if they're not logged in
                }
            }
            else
            {
                Navigator.RemoveRoomFromStaffPicked(Instance.RoomId);
                Session.SendData(NotificationMessageComposer.Compose("This room has been removed from the staff picked rooms successfully."));
            }
        }
示例#7
0
        private static void ActivateGeneric(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null) // warning: rights need to be checked in the event handler; we do not check here
            {
                return;
            }

            Item Item = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Behavior == ItemBehavior.StaticItem)
            {
                return;
            }

            int RequestData = Message.PopWiredInt32();

            ItemEventDispatcher.InvokeItemEventHandler(Session, Item, Instance, ItemEventType.Interact, RequestData);
            QuestManager.ProgressUserQuest(Session, QuestType.EXPLORE_FIND_ITEM, Item.DefinitionId);

            if (Item.Definition.Behavior == ItemBehavior.Switchable)
            {
                QuestManager.ProgressUserQuest(Session, QuestType.FURNI_SWITCH);
            }
        }
示例#8
0
        private static void UserDance(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null || Actor.AvatarEffectId > 0)
            {
                return;
            }

            int DanceId = Message.PopWiredInt32();

            if (DanceId < 0 || DanceId > 4)
            {
                return;
            }

            if (!Session.HasRight("club_regular") && !Session.HasRight("club_vip") && DanceId != 0)
            {
                DanceId = 1;
            }

            Actor.Dance(DanceId);

            QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_DANCE);
        }
示例#9
0
        private static void AddToStaffPicked(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Session.HasRight("hotel_admin"))
            {
                return;
            }

            if (!Navigator.StaffPickedContainsRoom(Instance.RoomId))
            {
                Navigator.AddRoomToStaffPicked(Instance.RoomId);
                Session.SendData(NotificationMessageComposer.Compose("This room has been added to the staff picked rooms successfully."));

                // todo: unlock achievement for room owner
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Session TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Instance.Info.OwnerName));
                    AchievementManager.ProgressUserAchievement(MySqlClient, TargetSession, "ACH_Spr", 1);
                }
            }
            else
            {
                Navigator.RemoveRoomFromStaffPicked(Instance.RoomId);
                Session.SendData(NotificationMessageComposer.Compose("This room has been removed from the staff picked rooms successfully."));
            }
        }
示例#10
0
        private static void UserMoveTo(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null)
            {
                return;
            }

            int RequestX = Message.PopWiredInt32();
            int RequestY = Message.PopWiredInt32();

            if (RequestX < 0 || RequestY < 0)
            {
                return;
            }

            Actor.MoveTo(new Vector2(RequestX, RequestY));
        }
示例#11
0
        private static void GetPetInfo(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            uint      ActorRefId = Message.PopWiredUInt32();
            RoomActor Actor      = Instance.GetActorByReferenceId(ActorRefId, RoomActorType.AiBot);

            if (Actor == null)
            {
                return;
            }

            Pet PetData = ((Bot)Actor.ReferenceObject).PetData;

            if (PetData == null)
            {
                return;
            }

            Session.SendData(PetInfoComposer.Compose(Actor.ReferenceId, PetData));
        }
示例#12
0
        private static void TakePet(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Message.PopWiredUInt32(), RoomActorType.AiBot);

            if (Actor == null)
            {
                return;
            }

            Pet PetData = ((Bot)Actor.ReferenceObject).PetData;

            if (PetData == null || (PetData.OwnerId != Session.CharacterId && !Session.HasRight("hotel_admin")))
            {
                return;
            }

            Instance.RemoveActorFromRoom(Actor.Id);
            Session.PetInventoryCache.Add(PetData);
            Session.SendData(InventoryPetAddedComposer.Compose(PetData));
        }
示例#13
0
        private static void MonitorCache()
        {
            try
            {
                while (Program.Alive)
                {
                    lock (mRoomInfoCache)
                    {
                        List <uint> ToRemove = new List <uint>();

                        foreach (RoomInfo Info in mRoomInfoCache.Values)
                        {
                            if (RoomManager.GetInstanceByRoomId(Info.Id) != null || Info.CacheAge >= CACHE_LIFE_TIME)
                            {
                                ToRemove.Add(Info.Id);
                                continue;
                            }
                        }

                        foreach (uint RemoveUid in ToRemove)
                        {
                            mRoomInfoCache.Remove(RemoveUid);
                        }
                    }

                    Thread.Sleep(30000);
                }
            }
            catch (ThreadAbortException) { }
            catch (ThreadInterruptedException) { }
        }
示例#14
0
        public static bool RemoveUserFromRoom(Session Session, bool SendKick = true)
        {
            uint CurrentRoomId = Session.AbsoluteRoomId;
            bool Ok            = false;

            if (CurrentRoomId > 0)
            {
                if (Session.RoomJoined)
                {
                    RoomInstance Instance = RoomManager.GetInstanceByRoomId(CurrentRoomId);

                    if (Instance != null)
                    {
                        Instance.RemoveCharacterFromRoom(Session.CharacterId);
                    }
                }

                Session.AbsoluteRoomId = 0;
                Session.RoomAuthed     = false;
                Session.RoomJoined     = false;

                MessengerHandler.MarkUpdateNeeded(Session, 0, false);

                Ok = true;
            }

            if (SendKick)
            {
                Session.SendData(RoomKickedComposer.Compose());
            }

            return(Ok);
        }
示例#15
0
        private static void SwitchMoodlight(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            Item Item = Instance.MoodlightItem;

            if (Item == null)
            {
                return;
            }

            MoodlightData Data = MoodlightData.GenerateFromFlags(Item.Flags);

            Data.Enabled = !Data.Enabled;

            Item.Flags        = Data.ToItemFlagData();
            Item.DisplayFlags = Data.ToDisplayData();

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Item.SynchronizeDatabase(MySqlClient, true);
            }

            Item.BroadcastStateUpdate(Instance);
        }
示例#16
0
        private static void DeleteSticky(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            Item Item = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Behavior != ItemBehavior.StickyNote)
            {
                return;
            }

            if (Instance.TakeItem(Item.Id))
            {
                Instance.RegenerateRelativeHeightmap();

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Item.RemovePermanently(MySqlClient);
                }
            }
        }
示例#17
0
        private static void SaveSticky(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            Item Item = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Behavior != ItemBehavior.StickyNote)
            {
                return;
            }

            StickieEditingRights Rights = Instance.GetStickieEditingRights(Session, Item);

            if (Rights == StickieEditingRights.ReadOnly)
            {
                return;
            }

            string RawData = Message.PopString();

            string[] Bits = RawData.Split(' ');

            if (Bits.Length < 2)
            {
                return;
            }

            string Color = Bits[0].ToUpper().Trim();
            string Text  = UserInputFilter.FilterString(RawData.Substring(Color.Length + 1, RawData.Length - (Color.Length + 1))).Trim();

            if (Color != "FFFF33" && Color != "FF9CFF" && Color != "9CCEFF" && Color != "9CFF9C" || Text.Length > 391)
            {
                return;
            }

            Item.Flags        = RawData;
            Item.DisplayFlags = Color;

            if (Rights == StickieEditingRights.GuestEdit)
            {
                Item.Flags += "\n-----\n" + Session.CharacterInfo.Username + "\n" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
            }

            Instance.RevokeTemporaryStickieRights(Item.Id);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Item.SynchronizeDatabase(MySqlClient, true);
            }

            Instance.BroadcastMessage(RoomWallItemMovedComposer.Compose(Item));
        }
示例#18
0
        private static void WiredSave(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }
            Instance.WiredManager.HandleSave(Session, Message);
        }
示例#19
0
        private static void UserChat(Session Session, ClientMessage Message)
        {
            if (Session.CharacterInfo.IsMuted)
            {
                return;
            }

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null)
            {
                return;
            }

            bool   Shout       = (Message.Id == OpcodesIn.ROOM_CHAT_SHOUT);
            string MessageText = UserInputFilter.FilterString(Message.PopString());

            if (MessageText.Length == 0)
            {
                return;
            }

            if (MessageText.Length > 100)
            {
                MessageText = MessageText.Substring(0, 100);
            }

            MessageText = Wordfilter.Filter(MessageText);

            if (MessageText.StartsWith(":") && (ChatCommands.HandleCommand(Session, MessageText) ||
                                                Session.HasRight("moderation_tool")))
            {
                return;
            }

            if (Instance.WiredManager.HandleChat(MessageText, Actor))
            {
                Actor.Whisper(MessageText, 0);
                return;
            }

            Actor.Chat(MessageText, Shout, Session.HasRight("mute"));

            if (Instance.HumanActorCount > 1)
            {
                QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_CHAT);
            }
        }
示例#20
0
        private static void StopEvent(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            Instance.StopEvent();
        }
示例#21
0
        private static void ApplyDecoration(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            Item Item = Session.InventoryCache.GetItem(Message.PopWiredUInt32());

            if (Item == null)
            {
                return;
            }

            string DecorationKey = string.Empty;

            switch (Item.Definition.Behavior)
            {
            case ItemBehavior.Floor:

                QuestManager.ProgressUserQuest(Session, QuestType.FURNI_DECORATION_FLOOR);
                DecorationKey = "floor";
                break;

            case ItemBehavior.Wallpaper:

                QuestManager.ProgressUserQuest(Session, QuestType.FURNI_DECORATION_WALL);
                DecorationKey = "wallpaper";
                break;

            case ItemBehavior.Landscape:

                DecorationKey = "landscape";
                break;
            }

            if (DecorationKey.Length == 0)
            {
                return;
            }

            Session.InventoryCache.RemoveItem(Item.Id);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Item.RemovePermanently(MySqlClient);
                Instance.Info.ApplyDecoration(MySqlClient, DecorationKey, Item.Flags);
            }

            Instance.BroadcastMessage(RoomDecorationComposer.Compose(DecorationKey, Item.Flags));
            Session.SendData(InventoryItemRemovedComposer.Compose(Item.Id));
        }
示例#22
0
        private static void GetEditInfo(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            Session.SendData(RoomEditInfoComposer.Compose(Instance));
        }
示例#23
0
        private static void KickBot(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            Instance.KickBot(Message.PopWiredUInt32());
        }
示例#24
0
        private static void ContinueLoadingAfterDoorbell(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Message.PopWiredUInt32());

            if (Instance == null)
            {
                return;
            }

            EnterRoom(Session, Instance);
        }
示例#25
0
        private static void RateRoom(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || Instance.CheckUserRights(Session, true) || Session.RatedRoomsCache.HasRatedRoom(Instance.RoomId))
            {
                return;
            }

            Instance.Info.IncreaseScore();
            Session.SendData(RoomRatingInfoComposer.Compose(Instance.Info.Score));
        }
示例#26
0
        private static void DeleteRoom(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            Instance.DeleteRoom(Session);
            //Navigator.GetUserRooms(Session, null); todo: fix. do not uncomment, shit will break in this implementation.
        }
示例#27
0
        private static void GetRoomObjects(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.AbsoluteRoomId);

            if (Instance == null || Session.RoomJoined || !Session.RoomAuthed) // if instance not found, or user already joined us, OR if the user isn't authed in the first place, let's gtfo
            {
                return;
            }

            Instance.SendObjects(Session);

            if (!Instance.AddUserToRoom(Session))
            {
                RoomManager.RemoveUserFromRoom(Session);
                return;
            }

            Session.RoomAuthed = true;
            Session.RoomJoined = true;

            ModerationLogs.LogRoomEntry(Session.CharacterId, Instance.RoomId);
            MessengerHandler.MarkUpdateNeeded(Session, 0, false);

            Session.SendData(RoomWallsStatusComposer.Compose(Instance.Info.HideWalls, Instance.Info.WallThickness, Instance.Info.FloorThickness));
            Session.SendData(RoomInfoRightsComposer.Compose(Instance.Info.Type == RoomType.Flat, Instance.RoomId,
                                                            (Instance.Info.Type == RoomType.Flat && Instance.CheckUserRights(Session, true)), Instance.Info.PubInternalName));

            /*if (Instance.Info.Type == RoomType.Flat)
             * {
             *  Session.SendData(RoomInfoComposer.Compose(Instance.Info, true));
             * }*/

            if (Session.CharacterInfo.IsMuted)
            {
                Session.SendData(RoomMutedComposer.Compose((int)Session.CharacterInfo.MutedSecondsLeft));
            }

            if (Instance.Info.OwnerId != Session.CharacterId)
            {
                QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_VISIT);
            }

            if (Session.QuestCache.CurrentQuestId > 0)
            {
                Quest Quest = QuestManager.GetQuest(Session.QuestCache.CurrentQuestId);

                if (Quest != null)
                {
                    Session.SendData(QuestStartedComposer.Compose(Session, Quest));
                }
            }
        }
示例#28
0
        private static void UserWhisper(Session Session, ClientMessage Message)
        {
            if (Session.CharacterInfo.IsMuted)
            {
                return;
            }

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null)
            {
                return;
            }

            string MessageText = UserInputFilter.FilterString(Message.PopString().Trim());

            if (MessageText.Length == 0)
            {
                return;
            }

            if (MessageText.Length > 100)
            {
                MessageText = MessageText.Substring(0, 100);
            }

            string[] Bits = MessageText.Split(' ');

            if (Bits.Length < 2)
            {
                return;
            }

            string UserBit = Bits[0];

            MessageText = MessageText.Substring(UserBit.Length + 1);

            uint UserId = CharacterResolverCache.GetUidFromName(UserBit);

            if (UserId > 0)
            {
                Actor.Whisper(MessageText, UserId);
            }
        }
示例#29
0
        private static void UpdateMoodlight(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            Item Item = Instance.MoodlightItem;

            if (Item == null)
            {
                return;
            }

            MoodlightData   Data     = MoodlightData.GenerateFromFlags(Item.Flags);
            int             PresetId = Message.PopWiredInt32();
            MoodlightPreset Preset   = null;

            if (Data.Presets.ContainsKey(PresetId))
            {
                Preset = Data.Presets[PresetId];
            }

            if (Preset == null)
            {
                return;
            }

            Preset.BackgroundOnly = !Message.PopWiredBoolean();
            Preset.ColorCode      = UserInputFilter.FilterString(Message.PopString().Trim());
            Preset.ColorIntensity = Message.PopWiredInt32();

            if (!MoodlightData.IsValidColor(Preset.ColorCode))
            {
                return;
            }

            Item.Flags        = Data.ToItemFlagData();
            Item.DisplayFlags = Data.ToDisplayData();

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Item.SynchronizeDatabase(MySqlClient, true);
            }

            Item.BroadcastStateUpdate(Instance);
        }
示例#30
0
        private static void PlacePet(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || (!Instance.CheckUserRights(Session, true) && !Instance.Info.AllowPets))
            {
                return;
            }

            Pet Pet = Session.PetInventoryCache.GetPet(Message.PopWiredUInt32());

            if (Pet == null)
            {
                return;
            }

            Vector2 DesiredPosition = new Vector2(Message.PopWiredInt32(), Message.PopWiredInt32());

            if (!Instance.IsValidPosition(DesiredPosition))
            {
                return;
            }

            Bot BotDefinition = BotManager.GetHandlerDefinitionForPetType(Pet.Type);

            if (BotDefinition == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("This pet cannot be placed right now. Please try again later."));
                return;
            }

            if (!Instance.CanPlacePet(Instance.CheckUserRights(Session, true)))
            {
                Session.SendData(RoomItemPlacementErrorComposer.Compose(RoomItemPlacementErrorCode.PetLimitReached));
                return;
            }

            Vector3 Position = new Vector3(DesiredPosition.X, DesiredPosition.Y, Instance.GetUserStepHeight(DesiredPosition));

            Pet.MoveToRoom(Instance.RoomId, Position);
            Instance.AddBotToRoom(BotManager.CreateNewInstance(BotDefinition, Instance.RoomId, Position, Pet));

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Pet.SynchronizeDatabase(MySqlClient);
            }

            Session.SendData(InventoryPetRemovedComposer.Compose(Pet.Id));
        }