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

            if (Instance == null)
            {
                return;
            }

            Trade Trade = Instance.TradeManager.GetTradeForUser(Session.CharacterId);

            if (Trade == null)
            {
                return;
            }

            Session TargetSession = SessionManager.GetSessionByCharacterId(Trade.UserOne == Session.CharacterId ?
                                                                           Trade.UserTwo : Trade.UserOne);

            if (TargetSession == null || !Trade.AcceptTrade(Trade.UserOne == Session.CharacterId))
            {
                return;
            }

            if (Trade.TradeStage == TradeStage.Finalized)
            {
                Session User1 = (TargetSession.CharacterId == Trade.UserOne ? TargetSession : Session);
                Session User2 = (TargetSession.CharacterId == Trade.UserTwo ? TargetSession : Session);

                Trade.DeliverItems(User1, User2);

                Session.SendData(TradeFinalizedComposer.Compose());
                TargetSession.SendData(TradeFinalizedComposer.Compose());

                Instance.TradeManager.StopTradeForUser(Session.CharacterId);
                Instance.TradeManager.StopTradeForUser(TargetSession.CharacterId);

                RoomActor Actor1 = Instance.GetActorByReferenceId(Session.CharacterId);
                RoomActor Actor2 = Instance.GetActorByReferenceId(TargetSession.CharacterId);

                if (Actor1 != null)
                {
                    Actor1.RemoveStatus("trd");
                    Actor1.UpdateNeeded = true;
                }

                if (Actor2 != null)
                {
                    Actor2.RemoveStatus("trd");
                    Actor2.UpdateNeeded = true;
                }
            }
        }
Exemple #2
0
        private static void ApplyEffect(Session Session, ClientMessage Message)
        {
            int EffectSpriteId = Message.PopWiredInt32();

            if (EffectSpriteId < 0)
            {
                EffectSpriteId = 0;
            }

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

            if (Instance == null)
            {
                return;
            }

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

            if (Actor == null || (EffectSpriteId != 0 && !Session.AvatarEffectCache.HasEffect(EffectSpriteId, true)))
            {
                return;
            }

            Actor.ApplyEffect(EffectSpriteId);
            Session.CurrentEffect = EffectSpriteId;
        }
Exemple #3
0
        public void SendInfoUpdate()
        {
            if (!Authenticated)
            {
                return;
            }

            SendData(UserInfoUpdateComposer.Compose(0, mCharacterInfo.Figure, mCharacterInfo.Gender, mCharacterInfo.Motto,
                                                    mCharacterInfo.Score));

            if (InRoom)
            {
                RoomInstance Instance = RoomManager.GetInstanceByRoomId(CurrentRoomId);

                if (Instance == null)
                {
                    return;
                }

                RoomActor Actor = Instance.GetActorByReferenceId(CharacterId);

                if (Actor == null)
                {
                    return;
                }

                Instance.BroadcastMessage(UserInfoUpdateComposer.Compose(Actor.Id, mCharacterInfo.Figure, mCharacterInfo.Gender,
                                                                         mCharacterInfo.Motto, mCharacterInfo.Score));
            }
        }
Exemple #4
0
        private static void SubmitAnswer(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 AnswerId = Message.PopWiredInt32();

            lock (mInfobusQuestions)
            {
                if (mInfobusQuestions.ContainsKey(Instance.RoomId))
                {
                    mInfobusQuestions[Instance.RoomId].SubmitAnswer(Actor.Id, AnswerId);
                }
            }
        }
Exemple #5
0
        private static bool HandleScoreboard(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
            case ItemEventType.Interact:

                if (!Instance.CheckUserRights(Session))
                {
                    break;
                }

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

                if (Actor == null)
                {
                    break;
                }

                if (!Distance.TilesTouching(Actor.Position.GetVector2(), Item.RoomPosition.GetVector2()))
                {
                    Actor.MoveToItemAndInteract(Item, RequestData, Opcode);
                    break;
                }

                int Val = 0;
                int.TryParse(Item.DisplayFlags, out Val);

                if (RequestData == 1)
                {
                    Val--;

                    if (Val < 0)
                    {
                        Val = 99;
                    }
                }
                else if (RequestData == 2)
                {
                    Val++;

                    if (Val > 99)
                    {
                        Val = 0;
                    }
                }
                else
                {
                    Val = (Val == -1 ? 0 : -1);
                }

                Item.DisplayFlags = Val.ToString();
                Item.BroadcastStateUpdate(Instance);
                break;
            }

            return(true);
        }
Exemple #6
0
        private static void TradeStop(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            Trade Trade = Instance.TradeManager.GetTradeForUser(Session.CharacterId);

            if (Trade == null)
            {
                return;
            }

            Instance.TradeManager.StopTradeForUser(Session.CharacterId);
            Session.SendData(TradeAbortedComposer.Compose(Session.CharacterId));

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

            if (Actor != null)
            {
                Actor.RemoveStatus("trd");
                Actor.UpdateNeeded = true;
            }

            Session TargetSession = SessionManager.GetSessionByCharacterId(Trade.UserOne == Session.CharacterId ?
                                                                           Trade.UserTwo : Trade.UserOne);

            if (TargetSession != null)
            {
                Instance.TradeManager.StopTradeForUser(TargetSession.CharacterId);
                TargetSession.SendData(TradeAbortedComposer.Compose(Session.CharacterId));

                RoomActor TargetActor = Instance.GetActorByReferenceId(TargetSession.CharacterId);

                if (TargetActor != null)
                {
                    TargetActor.RemoveStatus("trd");
                    TargetActor.UpdateNeeded = true;
                }
            }
        }
Exemple #7
0
        public override void OnSelfEnterRoom(RoomInstance Instance)
        {
            mSelfActor = Instance.GetActorByReferenceId(mSelfBot.Id, RoomActorType.AiBot);

            if (mSelfActor == null)
            {
                return;
            }

            mCurrentAction          = PetBotAction.Idle;
            mActionStartedTimestamp = UnixTimestamp.GetCurrent();
            mGstTimestamp           = UnixTimestamp.GetCurrent();

            RespondToEvent("SEE_OWNER");
        }
Exemple #8
0
        public void HandleExpiration(Session Session)
        {
            lock (mSyncRoot)
            {
                mQuantity--;

                mActivated          = false;
                mTimestampActivated = 0;

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    MySqlClient.SetParameter("id", mId);

                    if (mQuantity < 1)
                    {
                        MySqlClient.ExecuteNonQuery("DELETE FROM avatar_effects WHERE id = @id LIMIT 1");
                    }
                    else
                    {
                        MySqlClient.SetParameter("quantity", mQuantity);
                        MySqlClient.ExecuteNonQuery("UPDATE avatar_effects SET quantity = @quantity, activated = '0', timestamp_activated = 0 WHERE id = @id LIMIT 1");
                    }
                }

                Session.SendData(UserEffectRemovedComposer.Compose(this));

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

                if (Instance == null)
                {
                    return;
                }

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

                if (Actor == null)
                {
                    return;
                }

                if (Actor.AvatarEffectId == mSpriteId)
                {
                    Actor.ApplyEffect(0);
                    Session.CurrentEffect = 0;
                }
            }
        }
Exemple #9
0
        private static void TradeInitiate(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            RoomActor TargetActor = Instance.GetActor(Message.PopWiredUInt32());
            RoomActor SelfActor   = Instance.GetActorByReferenceId(Session.CharacterId);

            if (TargetActor == null || TargetActor.Type != RoomActorType.UserCharacter || SelfActor == null ||
                TargetActor.ReferenceId == SelfActor.ReferenceId)
            {
                return;
            }

            Session TargetSession = SessionManager.GetSessionByCharacterId(TargetActor.ReferenceId);

            if (TargetSession == null)
            {
                return;
            }

            if (!Instance.TradeManager.InitiateTrade(Session.CharacterId, TargetSession.CharacterId))
            {
                Session.SendData(RoomTradeCannotInitiate.Compose());
                return;
            }

            ServerMessage TradeInitiatedMessage = TradeInitiatedComposer.Compose(Session.CharacterId, Session.HasRight("trade"),
                                                                                 TargetSession.CharacterId, TargetSession.HasRight("trade"));

            Session.SendData(TradeInitiatedMessage);
            TargetSession.SendData(TradeInitiatedMessage);

            SelfActor.SetStatus("trd");
            SelfActor.UpdateNeeded = true;

            TargetActor.SetStatus("trd");
            TargetActor.UpdateNeeded = true;
        }
Exemple #10
0
        public static ServerMessage Compose(RoomInfo Info, RoomInstance Instance)
        {
            ReadOnlyCollection <string> Tags = Info.Tags;
            RoomEvent Event = (Instance == null ? null : Instance.Event);

            ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_ROOM_INFO);

            Message.AppendUInt32(Info.Id);
            Message.AppendInt32(Info.CurrentUsers);
            Message.AppendBoolean(Instance == null ? false : (Instance.GetActorByReferenceId(Info.OwnerId) != null));
            Message.AppendUInt32(Info.OwnerId);
            Message.AppendStringWithBreak(Info.OwnerName);
            Message.AppendUInt32(Info.Id);
            Message.AppendStringWithBreak(Info.Name);
            Message.AppendStringWithBreak(Info.Description);
            Message.AppendInt32(Tags.Count);

            foreach (string Tag in Tags)
            {
                Message.AppendStringWithBreak(Tag);
            }

            Message.AppendBoolean(Event != null);

            if (Event != null)
            {
                List <string> EventTags = Event.Tags;

                Message.AppendStringWithBreak(Event.Name);
                Message.AppendStringWithBreak(Event.Description);
                Message.AppendInt32(EventTags.Count);

                foreach (string Tag in EventTags)
                {
                    Message.AppendStringWithBreak(Tag);
                }
            }

            return(Message);
        }
Exemple #11
0
        public override void OnSelfEnterRoom(RoomInstance Instance)
        {
            mSelfActor = Instance.GetActorByReferenceId(mSelfBot.Id, RoomActorType.AiBot);

            if (mSelfActor == null)
            {
                return;
            }

            mNeedsRotation = false;
            mNextSpeechAttempt = RandomGenerator.GetNext(20, 255);
            mNextMovementAttempt = RandomGenerator.GetNext(20, 255);
            mServingItemId = 0;
            mServingActorId = 0;
            mMovingToServePos = false;
            mActorServePos = null;

            if (mSelfBot.Rotation >= 0)
            {
                mSelfActor.BodyRotation = mSelfBot.Rotation;
                mSelfActor.HeadRotation = mSelfBot.Rotation;
            }
        }
        private static bool HandleTeleporter(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            RoomActor Actor = null;

            uint LinkedRef = 0;

            uint.TryParse(Item.Flags, out LinkedRef);

            switch (Event)
            {
            case ItemEventType.InstanceLoaded:

                Item.DisplayFlags = "0";
                break;

            case ItemEventType.Moved:

                if (RequestData != 1)
                {
                    goto case ItemEventType.Removing;
                }

                break;

            case ItemEventType.Removing:
            case ItemEventType.Placed:

                if (Item.DisplayFlags != "0")
                {
                    Item.DisplayFlags = "0";

                    if (Event == ItemEventType.Moved)
                    {
                        Item.BroadcastStateUpdate(Instance);
                    }
                }

                foreach (uint RefId in Item.TemporaryInteractionReferenceIds.Values)
                {
                    RoomActor InteractingActor = Instance.GetActor(RefId);

                    if (InteractingActor != null)
                    {
                        InteractingActor.UnblockWalking();
                    }
                }

                Item.TemporaryInteractionReferenceIds.Clear();
                break;

            case ItemEventType.Interact:

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

                if (Actor == null)
                {
                    break;
                }

                bool IsInFront = (Actor.Position.X == Item.SquareInFront.X && Actor.Position.Y == Item.SquareInFront.Y);
                bool IsInTele  = !IsInFront && (Actor.Position.X == Item.RoomPosition.X &&
                                                Actor.Position.Y == Item.RoomPosition.Y);

                if (!IsInFront && !IsInTele)
                {
                    Actor.MoveToItemAndInteract(Item, RequestData, Opcode);
                    break;
                }

                if (Item.DisplayFlags == "0" && Item.TemporaryInteractionReferenceIds.Count == 0)
                {
                    Item.TemporaryInteractionReferenceIds.Add(1, Actor.Id);
                    Actor.BlockWalking();

                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        TeleporterLinkFinder.FillCache(MySqlClient, LinkedRef);
                    }

                    if (IsInTele)
                    {
                        Item.RequestUpdate(1);
                    }
                    else
                    {
                        Item.DisplayFlags = "1";
                        Actor.MoveTo(Item.RoomPosition.GetVector2(), true, true, true);

                        Item.BroadcastStateUpdate(Instance);
                        Item.RequestUpdate(3);
                    }
                }

                break;

            case ItemEventType.UpdateTick:

                RoomActor OutgoingUser = null;
                RoomActor IncomingUser = null;

                if (Item.TemporaryInteractionReferenceIds.ContainsKey(1))
                {
                    OutgoingUser = Instance.GetActor(Item.TemporaryInteractionReferenceIds[1]);

                    if (OutgoingUser == null)
                    {
                        Item.TemporaryInteractionReferenceIds.Remove(1);
                    }
                }

                if (Item.TemporaryInteractionReferenceIds.ContainsKey(2))
                {
                    IncomingUser = Instance.GetActor(Item.TemporaryInteractionReferenceIds[2]);

                    if (IncomingUser == null)
                    {
                        Item.TemporaryInteractionReferenceIds.Remove(2);
                    }
                }

                string       EffectToApply   = "0";
                uint         LinkedRoomRefId = TeleporterLinkFinder.GetValue(LinkedRef);
                RoomInstance LinkedRoomRef   = RoomManager.GetInstanceByRoomId(LinkedRoomRefId);

                if (OutgoingUser != null)
                {
                    Item    TargetItem      = null;
                    Session OutgoingSession = SessionManager.GetSessionByCharacterId(OutgoingUser.ReferenceId);

                    if (LinkedRoomRef == null && LinkedRoomRefId > 0)
                    {
                        RoomManager.TryLoadRoomInstance(LinkedRoomRefId);
                        LinkedRoomRef = RoomManager.GetInstanceByRoomId(LinkedRoomRefId);
                    }

                    if (LinkedRoomRef != null)
                    {
                        TargetItem = LinkedRoomRef.GetItem(LinkedRef);
                    }

                    if (OutgoingSession == null || OutgoingUser.Position.X != Item.RoomPosition.X ||
                        OutgoingUser.Position.Y != Item.RoomPosition.Y || (TargetItem != null &&
                                                                           TargetItem.TemporaryInteractionReferenceIds.ContainsKey(2)))
                    {
                        OutgoingUser.UnblockWalking();
                        Item.TemporaryInteractionReferenceIds.Remove(1);
                    }
                    else if (TargetItem != null)
                    {
                        EffectToApply = "2";

                        RoomActor TeleActor = OutgoingUser;

                        if (Instance != LinkedRoomRef)
                        {
                            OutgoingSession.IsTeleporting      = true;
                            OutgoingSession.TargetTeleporterId = LinkedRef;

                            RoomHandler.PrepareRoom(OutgoingSession, LinkedRoomRefId, string.Empty, true);

                            TeleActor = null;
                        }

                        if (TeleActor != null)
                        {
                            TeleActor.BlockWalking();

                            TeleActor.Position     = new Vector3(TargetItem.RoomPosition.X, TargetItem.RoomPosition.Y, TargetItem.RoomPosition.Z);
                            TeleActor.BodyRotation = TargetItem.RoomRotation;
                            TeleActor.HeadRotation = TeleActor.BodyRotation;
                            TeleActor.UpdateNeeded = true;

                            if (TargetItem.DisplayFlags != "2")
                            {
                                TargetItem.DisplayFlags = "2";
                                TargetItem.BroadcastStateUpdate(LinkedRoomRef);
                                TargetItem.RequestUpdate(3);
                            }

                            TargetItem.TemporaryInteractionReferenceIds.Add(2, TeleActor.Id);
                        }

                        Item.TemporaryInteractionReferenceIds.Remove(1);
                        Item.RequestUpdate(2);
                    }
                    else if (TargetItem == null)
                    {
                        EffectToApply = "1";
                        OutgoingUser.UnblockWalking();

                        if (Instance.IsValidStep(OutgoingUser.Position.GetVector2(), Item.SquareInFront, true))
                        {
                            OutgoingUser.MoveTo(Item.SquareInFront);
                        }

                        Item.TemporaryInteractionReferenceIds.Remove(1);
                        Item.RequestUpdate(2);
                    }
                }

                if (IncomingUser != null)
                {
                    if (IncomingUser.Position.X != Item.RoomPosition.X || IncomingUser.Position.Y != IncomingUser.Position.Y)
                    {
                        IncomingUser.UnblockWalking();
                        Item.TemporaryInteractionReferenceIds.Remove(2);
                    }
                    else
                    {
                        EffectToApply = "1";

                        IncomingUser.UnblockWalking();
                        Item.TemporaryInteractionReferenceIds.Remove(2);

                        if (Instance.CanInitiateMoveToPosition(Item.SquareInFront))
                        {
                            IncomingUser.MoveTo(Item.SquareInFront);
                        }

                        Item.RequestUpdate(3);
                    }
                }

                if (Item.DisplayFlags != EffectToApply)
                {
                    Item.DisplayFlags = EffectToApply;
                    Item.BroadcastStateUpdate(Instance);
                }

                break;
            }

            return(true);
        }
Exemple #13
0
        private static bool HandleDice(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
            case ItemEventType.Placed:
            case ItemEventType.Removing:

                if (Item.Flags != "0" && Item.Flags != "1")
                {
                    Item.Flags        = "0";
                    Item.DisplayFlags = "0";

                    RoomManager.MarkWriteback(Item, true);
                }

                break;

            case ItemEventType.Interact:

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

                if (TargetActor == null)
                {
                    break;
                }

                if (!Distance.TilesTouching(TargetActor.Position.GetVector2(), Item.RoomPosition.GetVector2()) &&
                    !Distance.IsDiagonal(TargetActor.Position.GetVector2(), Item.RoomPosition.GetVector2()))
                {
                    TargetActor.MoveToItemAndInteract(Item, RequestData);
                    break;
                }

                if (RequestData >= 0)
                {
                    if (Item.Flags != "-1")
                    {
                        Item.Flags        = "-1";
                        Item.DisplayFlags = "-1";

                        Item.BroadcastStateUpdate(Instance);
                        Item.RequestUpdate(3);
                    }
                }
                else
                {
                    Item.Flags        = "0";
                    Item.DisplayFlags = "0";
                }

                break;

            case ItemEventType.UpdateTick:

                Item.Flags        = RandomGenerator.GetNext(1, 6).ToString();
                Item.DisplayFlags = Item.Flags;

                Item.BroadcastStateUpdate(Instance);

                RoomManager.MarkWriteback(Item, true);
                break;
            }

            return(true);
        }
Exemple #14
0
        public static bool HandleCommand(Session Session, string Input)
        {
            Input = Input.Substring(1, Input.Length - 1);
            string[] Bits = Input.Split(' ');

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);
            RoomActor    Actor    = (Instance == null ? null : Instance.GetActorByReferenceId(Session.CharacterId));

            switch (Bits[0].ToLower())
            {
            case "commands":
            {
                Session.SendData(NotificationMessageComposer.Compose((string)LangManager.GetValue("command.commands.info") + ":\n\n:commands\n:online\n:about\n:pickall"));
                return(true);
            }

            case "update_catalog":
            {
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Snowlight.Game.Catalog.CatalogManager.RefreshCatalogData(MySqlClient);
                }
                Session.SendData(NotificationMessageComposer.Compose((string)LangManager.GetValue("command.updatecatalog.success")));
                return(true);
            }

            case "online":
            {
                List <string> OnlineUsers = SessionManager.ConnectedUserData.Values.ToList();
                StringBuilder MessageText = new StringBuilder((string)LangManager.GetValue("command.online.part1") + " " + OnlineUsers.Count + " " + (string)LangManager.GetValue("command.online.part2") + "\n");

                foreach (string OnlineUser in OnlineUsers)
                {
                    MessageText.Append('\n');
                    MessageText.Append("- " + OnlineUser);
                }

                Session.SendData(NotificationMessageComposer.Compose(MessageText.ToString()));
                return(true);
            }

            case "superkick":
            {
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.invalidsyntax") + " - :kick <username>", 0, ChatType.Whisper));
                    return(true);
                }

                string  Username      = UserInputFilter.FilterString(Bits[1].Trim());
                Session TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Username));

                if (TargetSession == null || TargetSession.HasRight("moderation_tool") || !TargetSession.InRoom)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.targetuser") + " '" + Username + "' is offline or cannot be kicked.", 0, ChatType.Whisper));
                    return(true);
                }

                SessionManager.StopSession(TargetSession.Id);

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Superkicked user from server (chat command)",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

            case "kick":
            {
                if (!Session.HasRight("moderation_tool"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.invalidsyntax") + " - :kick <username>", 0, ChatType.Whisper));
                    return(true);
                }

                string  Username      = UserInputFilter.FilterString(Bits[1].Trim());
                Session TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Username));

                if (TargetSession == null || TargetSession.HasRight("moderation_tool") || !TargetSession.InRoom)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.targetuser") + " '" + Username + "' is offline, not in a room, or cannot be kicked.", 0, ChatType.Whisper));
                    return(true);
                }

                RoomManager.RemoveUserFromRoom(TargetSession, true);
                TargetSession.SendData(NotificationMessageComposer.Compose((string)LangManager.GetValue("command.kick.success")));

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Kicked user from room (chat command)",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

            case "roomunmute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Instance.RoomMuted)
                {
                    Instance.RoomMuted = false;
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.roomunmute.success"), 0, ChatType.Whisper));
                }
                else
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.roomunmute.error"), 0, ChatType.Whisper));
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Unmuted room", "Room '"
                                                       + Instance.Info.Name + "' (ID " + Instance.RoomId + ")");
                }

                return(true);
            }

            case "roommute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (!Instance.RoomMuted)
                {
                    Instance.RoomMuted = true;
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.roommute.success"), 0, ChatType.Whisper));
                }
                else
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.roommute.error"), 0, ChatType.Whisper));
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Muted room", "Room '"
                                                       + Instance.Info.Name + "' (ID " + Instance.RoomId + ")");
                }

                return(true);
            }

            case "unmute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.invalidsyntax") + " - :unmute <username>", 0, ChatType.Whisper));
                    return(true);
                }

                string Username = UserInputFilter.FilterString(Bits[1].Trim());

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

                if (TargetSession == null)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.targetuser") + " '" + Username + "' " + (string)LangManager.GetValue("command.cannotproceedcmd3"), 0, ChatType.Whisper));
                    return(true);
                }

                if (!TargetSession.CharacterInfo.IsMuted)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.targetuser") + " '" + Username + "' " + (string)LangManager.GetValue("command.unmute.error"), 0, ChatType.Whisper));
                    return(true);
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    TargetSession.CharacterInfo.Unmute(MySqlClient);
                }

                TargetSession.SendData(NotificationMessageComposer.Compose((string)LangManager.GetValue("command.unmute.sucess")));
                Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.targetuser") + " '" + Username + "' " + (string)LangManager.GetValue("command.unmute.sucess2"), 0, ChatType.Whisper));

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Unmuted user",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

            case "mute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.invalidsyntax") + " - :mute <username> [length in seconds]", 0, ChatType.Whisper));
                    return(true);
                }

                string Username   = UserInputFilter.FilterString(Bits[1].Trim());
                int    TimeToMute = 0;

                if (Bits.Length >= 3)
                {
                    int.TryParse(Bits[2], out TimeToMute);
                }

                if (TimeToMute <= 0)
                {
                    TimeToMute = 300;
                }

                if (TimeToMute > 3600)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.mute.error"), 0, ChatType.Whisper));
                    return(true);
                }

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

                if (TargetSession == null || TargetSession.HasRight("mute"))
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.targetuser") + " '" + Username + "' " + (string)LangManager.GetValue("command.cannotproceedcmd4"), 0, ChatType.Whisper));
                    return(true);
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    TargetSession.CharacterInfo.Mute(MySqlClient, TimeToMute);
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Muted user",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ") for " + TimeToMute + " seconds.");
                }

                TargetSession.SendData(RoomMutedComposer.Compose(TimeToMute));
                Session.SendData(RoomChatComposer.Compose(Actor.Id, (string)LangManager.GetValue("command.mute.sucess.part1") + " '" + Username + "' " + (string)LangManager.GetValue("command.mute.sucess.part2") + " " + TimeToMute + " seconds.", 0, ChatType.Whisper));
                return(true);
            }

            case "clipping":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                Actor.OverrideClipping = !Actor.OverrideClipping;
                Actor.ApplyEffect(Actor.ClippingEnabled ? 0 : 23);
                Session.CurrentEffect = 0;
                return(true);

            case "about":

                Session.SendData(UserAlertModernComposer.Compose("Powered by Snowlight", "This hotel is proudly powered by Snowlight, the premium open-source Habbo Hotel emulator.\n\nhttp://www.meth0d.org/snowlight"));
                return(true);

            case "t":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                Session.SendData(NotificationMessageComposer.Compose("Position: " + Actor.Position.ToString() + ", Rotation: " + Actor.BodyRotation));
                return(true);

            case "emptyinv":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                Session.InventoryCache.ClearAndDeleteAll();
                Session.SendData(InventoryRefreshComposer.Compose());
                Session.SendData(NotificationMessageComposer.Compose((string)LangManager.GetValue("command.emptyinv.sucess")));
                return(true);

            case "pickall":

                if (!Instance.CheckUserRights(Session, true))
                {
                    Session.SendData(NotificationMessageComposer.Compose((string)LangManager.GetValue("command.pickall.error")));
                    return(true);
                }

                Instance.PickAllToUserInventory(Session);
                return(true);
            }

            return(false);
        }
Exemple #15
0
        public static bool HandleCommand(Session Session, string Input)
        {
            Input = Input.Substring(1, Input.Length - 1);
            string[] Bits = Input.Split(' ');

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);
            RoomActor    Actor    = (Instance == null ? null : Instance.GetActorByReferenceId(Session.CharacterId));

            switch (Bits[0].ToLower())
            {
            case "commands":
            {
                Session.SendData(NotificationMessageComposer.Compose("The following commands are available to regular users:\n\n:commands\n:online\n:about\n:pickall"));
                return(true);
            }

            case "online":
            {
                List <string> OnlineUsers = SessionManager.ConnectedUserData.Values.ToList();
                StringBuilder MessageText = new StringBuilder("There are currently " + OnlineUsers.Count + " user(s) online:\n");

                foreach (string OnlineUser in OnlineUsers)
                {
                    MessageText.Append('\n');
                    MessageText.Append("- " + OnlineUser);
                }

                Session.SendData(NotificationMessageComposer.Compose(MessageText.ToString()));
                return(true);
            }

            case "superkick":
            {
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :kick <username>", 0, ChatType.Whisper));
                    return(true);
                }

                string  Username      = UserInputFilter.FilterString(Bits[1].Trim());
                Session TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Username));

                if (TargetSession == null || TargetSession.HasRight("moderation_tool") || !TargetSession.InRoom)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Target user '" + Username + "' is offline or cannot be kicked.", 0, ChatType.Whisper));
                    return(true);
                }

                SessionManager.StopSession(TargetSession.Id);

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Superkicked user from server (chat command)",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

            case "kick":
            {
                if (!Session.HasRight("moderation_tool"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :kick <username>", 0, ChatType.Whisper));
                    return(true);
                }

                string  Username      = UserInputFilter.FilterString(Bits[1].Trim());
                Session TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Username));

                if (TargetSession == null || TargetSession.HasRight("moderation_tool") || !TargetSession.InRoom)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Target user '" + Username + "' is offline, not in a room, or cannot be kicked.", 0, ChatType.Whisper));
                    return(true);
                }

                RoomManager.RemoveUserFromRoom(TargetSession, true);
                TargetSession.SendData(NotificationMessageComposer.Compose("You have been kicked from the room by a community staff member."));

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Kicked user from room (chat command)",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

            case "roomunmute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Instance.RoomMuted)
                {
                    Instance.RoomMuted = false;
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "The current room has been unmuted successfully.", 0, ChatType.Whisper));
                }
                else
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "This room is not muted.", 0, ChatType.Whisper));
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Unmuted room", "Room '"
                                                       + Instance.Info.Name + "' (ID " + Instance.RoomId + ")");
                }

                return(true);
            }

            case "roommute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (!Instance.RoomMuted)
                {
                    Instance.RoomMuted = true;
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "The current room has been muted successfully.", 0, ChatType.Whisper));
                }
                else
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "This room is already muted.", 0, ChatType.Whisper));
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Muted room", "Room '"
                                                       + Instance.Info.Name + "' (ID " + Instance.RoomId + ")");
                }

                return(true);
            }

            case "unmute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :unmute <username>", 0, ChatType.Whisper));
                    return(true);
                }

                string Username = UserInputFilter.FilterString(Bits[1].Trim());

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

                if (TargetSession == null)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Target user '" + Username + "' does not exist or is not online.", 0, ChatType.Whisper));
                    return(true);
                }

                if (!TargetSession.CharacterInfo.IsMuted)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Target user '" + Username + "' is not muted.", 0, ChatType.Whisper));
                    return(true);
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    TargetSession.CharacterInfo.Unmute(MySqlClient);
                }

                TargetSession.SendData(NotificationMessageComposer.Compose("You have been unmuted. Please reload the room."));
                Session.SendData(RoomChatComposer.Compose(Actor.Id, "Target user '" + Username + "' was successfully unmuted.", 0, ChatType.Whisper));

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Unmuted user",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

            case "mute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :mute <username> [length in seconds]", 0, ChatType.Whisper));
                    return(true);
                }

                string Username   = UserInputFilter.FilterString(Bits[1].Trim());
                int    TimeToMute = 0;

                if (Bits.Length >= 3)
                {
                    int.TryParse(Bits[2], out TimeToMute);
                }

                if (TimeToMute <= 0)
                {
                    TimeToMute = 300;
                }

                if (TimeToMute > 3600)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "The maximum mute time is one hour.", 0, ChatType.Whisper));
                    return(true);
                }

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

                if (TargetSession == null || TargetSession.HasRight("mute"))
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Target user '" + Username + "' does not exist, is not online, or cannot be muted.", 0, ChatType.Whisper));
                    return(true);
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    TargetSession.CharacterInfo.Mute(MySqlClient, TimeToMute);
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Muted user",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ") for " + TimeToMute + " seconds.");
                }

                TargetSession.SendData(RoomMutedComposer.Compose(TimeToMute));
                Session.SendData(RoomChatComposer.Compose(Actor.Id, "User '" + Username + "' has been muted successfully for " + TimeToMute + " seconds.", 0, ChatType.Whisper));
                return(true);
            }

            case "clipping":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                Actor.OverrideClipping = !Actor.OverrideClipping;
                Actor.ApplyEffect(Actor.ClippingEnabled ? 0 : 23);
                Session.CurrentEffect = 0;
                return(true);

            case "about":

                Session.SendData(UserAlertModernComposer.Compose("Powered by Snowlight", "This hotel is proudly powered by Snowlight, the premium open-source Habbo Hotel emulator.\n\nhttp://www.meth0d.org/snowlight"));
                return(true);

            case "t":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                Session.SendData(NotificationMessageComposer.Compose("Position: " + Actor.Position.ToString() + ", Rotation: " + Actor.BodyRotation));
                return(true);

            case "emptyinv":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                Session.InventoryCache.ClearAndDeleteAll();
                Session.SendData(InventoryRefreshComposer.Compose());
                Session.SendData(NotificationMessageComposer.Compose("Your inventory has been emptied."));
                return(true);

            case "pickall":

                if (!Instance.CheckUserRights(Session, true))
                {
                    Session.SendData(NotificationMessageComposer.Compose("You do not have rights to pickall in this room."));
                    return(true);
                }

                Instance.PickAllToUserInventory(Session);
                return(true);
            }

            return(false);
        }
Exemple #16
0
        private static bool HandleOneWayGate(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
            case ItemEventType.InstanceLoaded:
            case ItemEventType.Moved:
            case ItemEventType.Placed:

                if (Item.DisplayFlags != "0")
                {
                    Item.DisplayFlags = "0";
                    Item.BroadcastStateUpdate(Instance);
                }

                foreach (uint ActorId in Item.TemporaryInteractionReferenceIds.Values)
                {
                    RoomActor ActorToUnlock = Instance.GetActor(ActorId);

                    if (ActorToUnlock != null)
                    {
                        ActorToUnlock.UnblockWalking();
                    }
                }

                Item.TemporaryInteractionReferenceIds.Clear();
                break;

            case ItemEventType.Interact:

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

                if (Actor == null)
                {
                    break;
                }

                if (Actor.Position.X != Item.SquareInFront.X || Actor.Position.Y != Item.SquareInFront.Y)
                {
                    Actor.MoveToItemAndInteract(Item, RequestData, Opcode);
                    break;
                }

                if (Item.TemporaryInteractionReferenceIds.Count == 0 && Instance.IsValidStep(Item.RoomPosition.GetVector2(),
                                                                                             Item.SquareBehind, true) && Item.DisplayFlags == "0")
                {
                    Actor.BlockWalking();
                    Actor.MoveTo(Item.RoomPosition.GetVector2(), true, true, true);
                    Item.TemporaryInteractionReferenceIds.Add(1, Actor.Id);
                    Item.RequestUpdate(1);
                }

                break;

            case ItemEventType.UpdateTick:

                RoomActor UpdateActor = null;

                if (Item.TemporaryInteractionReferenceIds.ContainsKey(1))
                {
                    UpdateActor = Instance.GetActor(Item.TemporaryInteractionReferenceIds[1]);
                }

                if (UpdateActor == null || !Instance.IsValidStep(Item.RoomPosition.GetVector2(), Item.SquareBehind, true) ||
                    ((UpdateActor.Position.X != Item.RoomPosition.X || UpdateActor.Position.Y !=
                      Item.RoomPosition.Y) && (UpdateActor.Position.X != Item.SquareInFront.X ||
                                               UpdateActor.Position.Y != Item.SquareInFront.Y)))
                {
                    if (Item.DisplayFlags != "0")
                    {
                        Item.DisplayFlags = "0";
                        Item.BroadcastStateUpdate(Instance);
                    }

                    if (Item.TemporaryInteractionReferenceIds.Count > 0)
                    {
                        Item.TemporaryInteractionReferenceIds.Clear();
                    }

                    if (UpdateActor != null)
                    {
                        UpdateActor.UnblockWalking();
                    }

                    break;
                }

                Item.DisplayFlags = "1";
                Item.BroadcastStateUpdate(Instance);

                UpdateActor.MoveTo(Item.SquareBehind, true, true, true);

                Item.RequestUpdate(2);
                break;
            }

            return(true);
        }
Exemple #17
0
        private static bool HandleFireworks(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            int CurrentCharges = 0;

            int.TryParse(Item.Flags, out CurrentCharges);

            switch (Event)
            {
            case ItemEventType.InstanceLoaded:
            case ItemEventType.Placed:
            case ItemEventType.Moved:
            case ItemEventType.UpdateTick:

                string DesiredDisplayFlags = "0";

                if (CurrentCharges > 0)
                {
                    DesiredDisplayFlags = "1";
                }

                if (Item.DisplayFlags != DesiredDisplayFlags)
                {
                    Item.DisplayFlags = DesiredDisplayFlags;
                    Item.BroadcastStateUpdate(Instance);
                }

                break;

            case ItemEventType.Interact:

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

                if (Actor == null)
                {
                    return(true);
                }

                if (Distance.Calculate(Actor.Position.GetVector2(), Item.RoomPosition.GetVector2()) > 1)
                {
                    Actor.MoveToItemAndInteract(Item, RequestData, Opcode, Item.SquareBehind);
                    return(true);
                }

                switch (RequestData)
                {
                // Purchase charges
                case 2:

                    if (Session.CharacterInfo.CreditsBalance < CHARGE_COSTS_CREDITS)
                    {
                        return(true);
                    }

                    if (Session.CharacterInfo.ActivityPointsBalance < CHARGE_COSTS_PIXELS)
                    {
                        return(true);
                    }

                    bool Update = (CurrentCharges <= 0);
                    CurrentCharges += CHARGE_AMOUNT;

                    Item.Flags = CurrentCharges.ToString();

                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        if (CHARGE_COSTS_CREDITS > 0)
                        {
                            Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -CHARGE_COSTS_CREDITS);
                            Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance));
                        }

                        if (CHARGE_COSTS_PIXELS > 0)
                        {
                            Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, -CHARGE_COSTS_PIXELS);
                            Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance,
                                                                                   -CHARGE_COSTS_PIXELS));
                        }

                        Item.SynchronizeDatabase(MySqlClient, true);
                    }

                    Session.SendData(FireworksChargeInfoComposer.Compose(Item.Id, CurrentCharges, CHARGE_COSTS_CREDITS,
                                                                         CHARGE_COSTS_PIXELS, CHARGE_AMOUNT));

                    if (Update)
                    {
                        Item.DisplayFlags = "1";
                        Item.BroadcastStateUpdate(Instance);
                    }

                    break;

                case 1:

                    Session.SendData(FireworksChargeInfoComposer.Compose(Item.Id, CurrentCharges, CHARGE_COSTS_CREDITS,
                                                                         CHARGE_COSTS_PIXELS, CHARGE_AMOUNT));
                    break;

                default:
                case 0:

                    if (Item.DisplayFlags == "2")
                    {
                        return(true);
                    }

                    if (CurrentCharges > 0)
                    {
                        Item.DisplayFlags = "2";
                        Item.BroadcastStateUpdate(Instance);

                        Item.Flags = (--CurrentCharges).ToString();
                        RoomManager.MarkWriteback(Item, true);

                        Item.RequestUpdate(Item.Definition.BehaviorData);
                    }
                    else
                    {
                        goto case 1;
                    }

                    break;
                }

                break;
            }

            return(true);
        }
Exemple #18
0
        private static bool HandleDispenser(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
            case ItemEventType.Moved:
            {
                RoomActor InteractingActor = (Item.TemporaryInteractionReferenceIds.ContainsKey(0) ?
                                              Instance.GetActor(Item.TemporaryInteractionReferenceIds[0]) : null);

                if (InteractingActor != null)
                {
                    InteractingActor.UnblockWalking();
                }

                goto case ItemEventType.InstanceLoaded;
            }

            case ItemEventType.InstanceLoaded:
            {
                if (Item.DisplayFlags != "0")
                {
                    Item.DisplayFlags = "0";
                    Item.BroadcastStateUpdate(Instance);
                }

                return(true);
            }

            case ItemEventType.Interact:
            {
                RoomActor InteractingActor = Instance.GetActorByReferenceId(Session.CharacterId);

                if (InteractingActor == null)
                {
                    return(true);
                }

                if (InteractingActor.Position.X != Item.SquareInFront.X || InteractingActor.Position.Y !=
                    Item.SquareInFront.Y)
                {
                    InteractingActor.MoveToItemAndInteract(Item, RequestData, Opcode);
                    return(true);
                }

                if (Item.TemporaryInteractionReferenceIds.Count == 0)
                {
                    Item.TemporaryInteractionReferenceIds.Add(0, InteractingActor.Id);

                    InteractingActor.BlockWalking();
                    InteractingActor.PositionToSet = Item.SquareInFront;

                    int NewRot = Rotation.Calculate(InteractingActor.Position.GetVector2(),
                                                    Item.RoomPosition.GetVector2());

                    if (InteractingActor.BodyRotation != NewRot)
                    {
                        InteractingActor.BodyRotation = NewRot;
                        InteractingActor.HeadRotation = NewRot;
                        InteractingActor.UpdateNeeded = true;
                    }

                    Item.DisplayFlags = "1";
                    Item.BroadcastStateUpdate(Instance);

                    Item.RequestUpdate(2);
                }

                return(true);
            }

            case ItemEventType.UpdateTick:
            {
                if (Item.DisplayFlags != "0")
                {
                    Item.DisplayFlags = "0";
                    Item.BroadcastStateUpdate(Instance);
                }

                if (Item.TemporaryInteractionReferenceIds.Count < 1)
                {
                    return(true);
                }

                RoomActor InteractingActor = Instance.GetActor(Item.TemporaryInteractionReferenceIds[0]);
                Item.TemporaryInteractionReferenceIds.Clear();

                if (InteractingActor == null)
                {
                    return(true);
                }

                InteractingActor.CarryItem(DrinkSetManager.GetRandomDrinkForSet(Item.Definition.BehaviorData));

                int NewRot = Rotation.Calculate(InteractingActor.Position.GetVector2(),
                                                Item.RoomPosition.GetVector2());

                if (InteractingActor.BodyRotation != NewRot)
                {
                    InteractingActor.BodyRotation = NewRot;
                    InteractingActor.HeadRotation = NewRot;
                    InteractingActor.UpdateNeeded = true;
                }

                InteractingActor.UnblockWalking();
                return(true);
            }
            }

            return(true);
        }
Exemple #19
0
        public static bool HandleCommand(Session Session, string Input)
        {
            Input = Input.Substring(1, Input.Length - 1);
            string[] Bits = Input.Split(' ');

            RoomInstance Instance      = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);
            RoomActor    Actor         = (Instance == null ? null : Instance.GetActorByReferenceId(Session.CharacterId));
            Session      TargetSession = null;
            RoomActor    TargetActor   = null;
            String       TargetName    = "";

            switch (Bits[0].ToLower())
            {
                #region users
                #region misc
            case "commands":
            {
                Session.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.commands.info") + ":\n\n:commands\n:online\n:about\n:pickall"));
                return(true);
            }

            case "online":
            {
                List <string> OnlineUsers = SessionManager.ConnectedUserData.Values.ToList();
                StringBuilder MessageText = new StringBuilder(Localization.GetValue("command.online", OnlineUsers.Count.ToString()) + "\n");

                foreach (string OnlineUser in OnlineUsers)
                {
                    MessageText.Append('\n');
                    MessageText.Append("- " + OnlineUser);
                }

                Session.SendData(NotificationMessageComposer.Compose(MessageText.ToString()));
                return(true);
            }

            case "about":

                Session.SendData(UserAlertModernComposer.Compose("Powered by Snowlight", "This hotel is proudly powered by Snowlight,\nedited by flx5. \nCredits to Meth0d."));
                return(true);

                #endregion
                #region furni
            case "empty":
            case "emptyinv":

                if (Bits.Length > 2)
                {
                    return(false);
                }

                if (!Session.HasRight("hotel_admin") && Bits.Length == 2)
                {
                    return(false);
                }

                Session Targetuser = Session;

                if (Bits.Length == 2)
                {
                    uint userid = CharacterResolverCache.GetUidFromName(Bits[1]);
                    Targetuser = SessionManager.GetSessionByCharacterId(userid);
                }

                Targetuser.PetInventoryCache.ClearAndDeleteAll();
                Targetuser.InventoryCache.ClearAndDeleteAll();
                Targetuser.SendData(InventoryRefreshComposer.Compose());
                Targetuser.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.emptyinv.sucess")));
                return(true);

            case "pickall":

                if (!Instance.CheckUserRights(Session, true))
                {
                    Session.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.pickall.error")));
                    return(true);
                }
                Instance.PickAllToUserInventory(Session);
                return(true);

                #endregion
                #region extra
            case "moonwalk":
                if (!Session.CharacterInfo.IsPremium)
                {
                    return(false);
                }

                Actor.WalkingBackwards = !Actor.WalkingBackwards;
                Actor.Dance(Actor.WalkingBackwards ? 4 : 0);
                Session.SendData(RoomChatComposer.Compose(Actor.Id, "TEST " + Actor.WalkingBackwards, 0, ChatType.Whisper));
                return(true);

                #region push
            case "push":
                if (!Session.CharacterInfo.IsPremium || Bits.Length != 2)
                {
                    return(false);
                }
                TargetName  = UserInputFilter.FilterString(Bits[1].Trim());
                TargetActor = Instance.GetActorByReferenceId(CharacterResolverCache.GetUidFromName(TargetName));

                if (TargetActor == null || TargetActor.IsMoving)
                {
                    return(false);
                }



                if ((TargetActor.Position.X == Actor.Position.X - 1) || (TargetActor.Position.X == Actor.Position.X + 1) || (TargetActor.Position.Y == Actor.Position.Y - 1) || (TargetActor.Position.Y == Actor.Position.Y + 1))
                {
                    Vector2 Newposition = null;

                    if (TargetActor.Position.X == Actor.Position.X - 1 && TargetActor.Position.Y == Actor.Position.Y)
                    {
                        Newposition = new Vector2(TargetActor.Position.X - 1, TargetActor.Position.Y);
                    }

                    if (TargetActor.Position.X == Actor.Position.X + 1 && TargetActor.Position.Y == Actor.Position.Y)
                    {
                        Newposition = new Vector2(TargetActor.Position.X + 1, TargetActor.Position.Y);
                    }

                    if (TargetActor.Position.X == Actor.Position.X && TargetActor.Position.Y == Actor.Position.Y + 1)
                    {
                        Newposition = new Vector2(TargetActor.Position.X, TargetActor.Position.Y + 1);
                    }

                    if (TargetActor.Position.X == Actor.Position.X && TargetActor.Position.Y == Actor.Position.Y - 1)
                    {
                        Newposition = new Vector2(TargetActor.Position.X, TargetActor.Position.Y - 1);
                    }

                    if (TargetActor.Position.X == Actor.Position.X + 1 && TargetActor.Position.Y == Actor.Position.Y + 1)
                    {
                        Newposition = new Vector2(TargetActor.Position.X + 1, TargetActor.Position.Y + 1);
                    }

                    if (TargetActor.Position.X == Actor.Position.X - 1 && TargetActor.Position.Y == Actor.Position.Y - 1)
                    {
                        Newposition = new Vector2(TargetActor.Position.X - 1, TargetActor.Position.Y - 1);
                    }

                    if (TargetActor.Position.X == Actor.Position.X - 1 && TargetActor.Position.Y == Actor.Position.Y + 1)
                    {
                        Newposition = new Vector2(TargetActor.Position.X - 1, TargetActor.Position.Y + 1);
                    }

                    if (TargetActor.Position.X == Actor.Position.X + 1 && TargetActor.Position.Y == Actor.Position.Y - 1)
                    {
                        Newposition = new Vector2(TargetActor.Position.X + 1, TargetActor.Position.Y - 1);
                    }

                    if (Newposition == null || !Instance.IsValidPosition(Newposition) || (Instance.Model.DoorPosition.GetVector2().X == Newposition.X && Instance.Model.DoorPosition.GetVector2().Y == Newposition.Y))
                    {
                        return(false);
                    }

                    TargetActor.MoveTo(Newposition);
                    Actor.Chat("*" + Session.CharacterInfo.Username + " pushes " + Bits[1] + "*");
                    return(true);
                }
                else
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Bits[1] + " is not in your area.", 0, ChatType.Whisper));
                    return(false);
                }

                #endregion

            case "pull":
                if (!Session.CharacterInfo.IsPremium || Bits.Length != 2)
                {
                    return(false);
                }

                TargetName  = UserInputFilter.FilterString(Bits[1].Trim());
                TargetActor = Instance.GetActorByReferenceId(CharacterResolverCache.GetUidFromName(TargetName));

                if (TargetActor == null || TargetActor.IsMoving)
                {
                    return(false);
                }

                if ((TargetActor.Position.X > Actor.Position.X - 10) && (TargetActor.Position.X < Actor.Position.X + 10) && (TargetActor.Position.Y > Actor.Position.Y - 10) && (TargetActor.Position.Y < Actor.Position.Y + 10) && (Instance.Model.DoorPosition.GetVector2().X == Actor.SquareInFront.X && Instance.Model.DoorPosition.GetVector2().Y == Actor.SquareInFront.Y))
                {
                    TargetActor.MoveTo(Actor.SquareInFront);
                    Actor.Chat("*" + Session.CharacterInfo.Username + " pulls " + Bits[1] + "*");
                    return(true);
                }

                Session.SendData(RoomChatComposer.Compose(Actor.Id, Bits[1] + " is not in your area.", 0, ChatType.Whisper));
                return(false);

                #endregion
                #endregion

                #region debugging
                #region items
            case "update_catalog":
            {
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Snowlight.Game.Catalog.CatalogManager.RefreshCatalogData(MySqlClient);
                }
                Session.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.updatecatalog.success")));
                return(true);
            }

            case "update_items":
            {
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Snowlight.Game.Items.ItemDefinitionManager.Initialize(MySqlClient);
                }
                Session.SendData(NotificationMessageComposer.Compose("Items reloaded"));
                return(true);
            }

                #endregion
                #region rooms
            case "unload":
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }
                Instance.BroadcastMessage(NotificationMessageComposer.Compose("This room was unloaded!"));
                Instance.Unload();
                return(true);

            case "t":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                Session.SendData(NotificationMessageComposer.Compose("Position: " + Actor.Position.ToString() + ", Rotation: " + Actor.BodyRotation));
                return(true);

                #endregion

            case "update_rights":
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    RightsManager.RebuildCache(MySqlClient);
                }

                return(true);

            case "effect":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                if (Bits.Length < 1)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :effect <id>", 0, ChatType.Whisper));
                    return(true);
                }

                int effectID;

                if (int.TryParse(Bits[1], out effectID))
                {
                    Actor.ApplyEffect(effectID);
                    Session.CurrentEffect = 0;
                }
                else
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :effect <id>", 0, ChatType.Whisper));
                }

                return(true);

            case "clipping":

                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                Actor.OverrideClipping = !Actor.OverrideClipping;
                Actor.ApplyEffect(Actor.ClippingEnabled ? 0 : 23);
                Session.CurrentEffect = 0;
                return(true);

                #endregion

                #region moderation
                #region kick
            case "superkick":      // Kick User out of the Hotel
            {
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.invalidsyntax") + " - :kick <username>", 0, ChatType.Whisper));
                    return(true);
                }

                TargetName    = UserInputFilter.FilterString(Bits[1].Trim());
                TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(TargetName));

                if (TargetSession == null || TargetSession.HasRight("moderation_tool") || !TargetSession.InRoom)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' is offline or cannot be kicked.", 0, ChatType.Whisper));
                    return(true);
                }

                SessionManager.StopSession(TargetSession.Id);

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Superkicked user from server (chat command)",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

            case "kick":     //kick User out of Room
            {
                if (!Session.HasRight("moderation_tool"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.invalidsyntax") + " - :kick <username>", 0, ChatType.Whisper));
                    return(true);
                }

                TargetName    = UserInputFilter.FilterString(Bits[1].Trim());
                TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(TargetName));

                if (TargetSession == null || TargetSession.HasRight("moderation_tool") || !TargetSession.InRoom)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' is offline, not in a room, or cannot be kicked.", 0, ChatType.Whisper));
                    return(true);
                }

                RoomManager.RemoveUserFromRoom(TargetSession, true);
                TargetSession.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.kick.success")));

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Kicked user from room (chat command)",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

                #endregion
                #region mute
            case "roomunmute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Instance.RoomMuted)
                {
                    Instance.RoomMuted = false;
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.roomunmute.success"), 0, ChatType.Whisper));
                }
                else
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.roomunmute.error"), 0, ChatType.Whisper));
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Unmuted room", "Room '"
                                                       + Instance.Info.Name + "' (ID " + Instance.RoomId + ")");
                }

                return(true);
            }

            case "roommute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (!Instance.RoomMuted)
                {
                    Instance.RoomMuted = true;
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.roommute.success"), 0, ChatType.Whisper));
                }
                else
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.roommute.error"), 0, ChatType.Whisper));
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Muted room", "Room '"
                                                       + Instance.Info.Name + "' (ID " + Instance.RoomId + ")");
                }

                return(true);
            }

            case "unmute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.invalidsyntax") + " - :unmute <username>", 0, ChatType.Whisper));
                    return(true);
                }

                TargetName = UserInputFilter.FilterString(Bits[1].Trim());

                TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(TargetName));

                if (TargetSession == null)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' " + Localization.GetValue("command.cannotproceedcmd3"), 0, ChatType.Whisper));
                    return(true);
                }

                if (!TargetSession.CharacterInfo.IsMuted)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' " + Localization.GetValue("command.unmute.error"), 0, ChatType.Whisper));
                    return(true);
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    TargetSession.CharacterInfo.Unmute(MySqlClient);
                }

                TargetSession.SendData(NotificationMessageComposer.Compose(Localization.GetValue("command.unmute.sucess")));
                Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' " + Localization.GetValue("command.unmute.sucess2"), 0, ChatType.Whisper));

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Unmuted user",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ").");
                }

                return(true);
            }

            case "mute":
            {
                if (!Session.HasRight("mute"))
                {
                    return(false);
                }

                if (Bits.Length < 2)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.invalidsyntax") + " - :mute <username> [length in seconds]", 0, ChatType.Whisper));
                    return(true);
                }

                TargetName = UserInputFilter.FilterString(Bits[1].Trim());
                int TimeToMute = 0;

                if (Bits.Length >= 3)
                {
                    int.TryParse(Bits[2], out TimeToMute);
                }

                if (TimeToMute <= 0)
                {
                    TimeToMute = 300;
                }

                if (TimeToMute > 3600)
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.mute.error"), 0, ChatType.Whisper));
                    return(true);
                }

                TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(TargetName));

                if (TargetSession == null || TargetSession.HasRight("mute"))
                {
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.targetuser") + " '" + TargetName + "' " + Localization.GetValue("command.cannotproceedcmd4"), 0, ChatType.Whisper));
                    return(true);
                }

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    TargetSession.CharacterInfo.Mute(MySqlClient, TimeToMute);
                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Muted user",
                                                       "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ") for " + TimeToMute + " seconds.");
                }

                TargetSession.SendData(RoomMutedComposer.Compose(TimeToMute));
                Session.SendData(RoomChatComposer.Compose(Actor.Id, Localization.GetValue("command.mute.sucess.part1") + " '" + TargetName + "' " + Localization.GetValue("command.mute.sucess.part2") + " " + TimeToMute + " seconds.", 0, ChatType.Whisper));
                return(true);
            }

                #endregion
                #region credits
            case "coins":
            case "credits":
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    if (!Session.HasRight("hotel_admin"))
                    {
                        return(false);
                    }
                    if (Bits.Length < 2)
                    {
                        Session.SendData(RoomChatComposer.Compose(Actor.Id, "Invalid syntax - :" + Bits[0].ToLower() + " <user> <amount>", 0, ChatType.Whisper));
                        return(false);
                    }
                    int Valor;
                    if (!Int32.TryParse(Bits[2], out Valor))
                    {
                        Session.SendData(RoomChatComposer.Compose(Actor.Id, "Amount must be numeric!", 0, ChatType.Whisper));
                        return(false);
                    }

                    TargetName = UserInputFilter.FilterString(Bits[1].Trim());
                    uint UserID = CharacterResolverCache.GetUidFromName(TargetName);

                    if (UserID == 0)
                    {
                        Session.SendData(RoomChatComposer.Compose(Actor.Id, "User not found!", 0, ChatType.Whisper));
                        return(false);
                    }
                    Session TargetUser = SessionManager.GetSessionByCharacterId(UserID);
                    if (TargetUser == null)
                    {
                        Session.SendData(RoomChatComposer.Compose(Actor.Id, "User not online!", 0, ChatType.Whisper));
                        return(false);
                    }
                    TargetUser.CharacterInfo.UpdateCreditsBalance(MySqlClient, (int)Valor);
                    TargetUser.SendData(RoomChatComposer.Compose(TargetUser.Id, "You received " + Valor + " coins!", 0, ChatType.Whisper));
                    Session.SendData(RoomChatComposer.Compose(Actor.Id, TargetName + " received " + Valor + " coins!", 0, ChatType.Whisper));
                    TargetUser.SendData(CreditsBalanceComposer.Compose(TargetUser.CharacterInfo.CreditsBalance));

                    return(true);
                }

                #endregion
                #region messages
            case "ha":
            {
                if (!Session.HasRight("hotel_admin"))
                {
                    return(false);
                }
                string Alert = UserInputFilter.FilterString(MergeInputs(Bits, 1));
                SessionManager.BroadcastPacket(UserAlertModernComposer.Compose("Important notice from Hotel Management", Alert));
                return(true);
            }
                #endregion
                #endregion
            }


            return(false);
        }