Ejemplo n.º 1
0
        private static void MessageUser(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            uint   UserId      = Message.PopWiredUInt32();
            string MessageText = Message.PopString();

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("That user is not online at this point in time."));
                return;
            }

            TargetSession.SendData(NotificationMessageComposer.Compose("Notification from staff:\n\n" + MessageText));
            ModerationTicketManager.MarkTicketRespondedToForUser(UserId);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                ModerationLogs.LogModerationAction(MySqlClient, Session, "Sent message to user",
                                                   "User " + TargetSession.CharacterInfo.Username + " (ID " + TargetSession.CharacterId + "): '" +
                                                   MessageText + "'.");
            }
        }
Ejemplo n.º 2
0
        private static void BanUser(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            uint   UserId      = Message.PopWiredUInt32();
            string MessageText = Message.PopString();
            double Length      = (Message.PopWiredInt32() * 3600);

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession == null || TargetSession.HasRight("moderation_tool"))
            {
                Session.SendData(NotificationMessageComposer.Compose("This user is not online or you do not have permission to ban them.\nPlease use housekeeping to ban users that are offline."));
                return;
            }

            SessionManager.StopSession(TargetSession.Id);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                ModerationBanManager.BanUser(MySqlClient, UserId, MessageText, Session.CharacterId, Length);
                ModerationLogs.LogModerationAction(MySqlClient, Session, "Banned user",
                                                   "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ") for " +
                                                   Length + " hours: '" + MessageText + "'");
            }
        }
Ejemplo n.º 3
0
        private static void GetTicketChatlog(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            ModerationTicket Ticket = ModerationTicketManager.GetTicket(Message.PopWiredUInt32());

            if (Ticket == null || Ticket.ModeratorUserId != Session.CharacterId)
            {
                Session.SendData(NotificationMessageComposer.Compose("Ticket not found or ticket is not assigned to you."));
                return;
            }

            RoomInfo Info = null;

            if (Ticket.RoomId > 0)
            {
                Info = RoomInfoLoader.GetRoomInfo(Ticket.RoomId);
            }

            Session.SendData(ModerationTicketChatlogsComposer.Compose(Ticket, Info, ModerationLogs.GetLogsForRoom(Ticket.RoomId,
                                                                                                                  (Ticket.CreatedTimestamp - 600), UnixTimestamp.GetCurrent())));
        }
Ejemplo n.º 4
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."));
            }
        }
Ejemplo n.º 5
0
        private static void AlertRoom(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

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

            if (Instance == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("Could not send room alert."));
                return;
            }

            int    Unknown1     = Message.PopWiredInt32();
            int    AlertMode    = Message.PopWiredInt32();
            string AlertMessage = Message.PopString();
            bool   IsCaution    = AlertMode != 3;

            Instance.SendModerationAlert(AlertMessage, IsCaution);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                ModerationLogs.LogModerationAction(MySqlClient, Session, "Sent room " + (IsCaution ? "caution" : "message"),
                                                   "Room " + Instance.Info.Name + " (ID " + Instance.RoomId + "): '" + AlertMessage + "'");
            }
        }
Ejemplo n.º 6
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));
            }
        }
Ejemplo n.º 7
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."));
            }
        }
Ejemplo n.º 8
0
        private static void RecycleItems(Session Session, ClientMessage Message)
        {
            if (!mEnabled)
            {
                Session.SendData(NotificationMessageComposer.Compose("The recycler is temporarily disabled. Please check back later."));
                return;
            }

            int Amount = Message.PopWiredInt32();

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

            if (Instance == null || Amount != 5)
            {
                return;
            }

            ItemDefinition Reward = ItemDefinitionManager.GetDefinition(GetRandomReward());

            if (Reward == null)
            {
                return;
            }

            List <Item> ItemsToRecycle = new List <Item>();

            for (int i = 0; i < 5; i++)
            {
                Item Item = Session.InventoryCache.GetItem(Message.PopWiredUInt32());

                if (Item == null || !Item.Definition.AllowRecycle || ItemsToRecycle.Contains(Item))
                {
                    return;
                }

                ItemsToRecycle.Add(Item);
            }

            Item NewItem = null;

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                foreach (Item Item in ItemsToRecycle)
                {
                    Session.InventoryCache.RemoveItem(Item.Id);
                    Item.RemovePermanently(MySqlClient);

                    Session.SendData(InventoryItemRemovedComposer.Compose(Item.Id));
                }

                NewItem = ItemFactory.CreateItem(MySqlClient, Reward.Id, Session.CharacterId, string.Empty, string.Empty,
                                                 0);
            }

            Session.InventoryCache.Add(NewItem);

            Session.SendData(RecyclerResultComposer.Compose(true, NewItem.Id));
            Session.SendData(InventoryItemAddedComposer.Compose(NewItem));
        }
Ejemplo n.º 9
0
        private static void GetUserChatlog(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("chatlogs"))
            {
                Session.SendData(NotificationMessageComposer.Compose("You are not allowed to use this!"));
                return;
            }

            uint UserId = Message.PopWiredUInt32();

            Session.SendData(ModerationUserChatlogsComposer.Compose(UserId, ModerationLogs.GetLogsForUser(UserId,
                                                                                                          (UnixTimestamp.GetCurrent() - 3600))));
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        private static void CautionUser(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            uint   UserId      = Message.PopWiredUInt32();
            string MessageText = Message.PopString();

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession != null)
            {
                TargetSession.SendData(HotelManagerNotificationComposer.Compose("Caution from moderator:\n\n" + MessageText));
                ModerationTicketManager.MarkTicketRespondedToForUser(UserId);
            }
            else
            {
                Session.SendData(NotificationMessageComposer.Compose("That user is not online at this point in time."));
            }

            CharacterInfo Info = (TargetSession != null ? TargetSession.CharacterInfo : null);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                if (Info == null)
                {
                    Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, UserId);
                }

                if (Info != null)
                {
                    Info.ModerationCautions++;
                }

                ModerationLogs.LogModerationAction(MySqlClient, Session, "Sent caution to user",
                                                   "User " + TargetSession.CharacterInfo.Username + " (ID " + TargetSession.CharacterId + "): '" +
                                                   MessageText + "'.");

                MySqlClient.SetParameter("userid", TargetSession.CharacterInfo.Id);
                MySqlClient.SetParameter("modid", Session.CharacterId);
                MySqlClient.SetParameter("timestamp", UnixTimestamp.GetCurrent());
                MySqlClient.SetParameter("value", MessageText);
                MySqlClient.ExecuteNonQuery("INSERT INTO user_cautions (moderator_id,user_id,value,timestamp) VALUES (@modid,@userid,@value,@timestamp)");
            }
        }
Ejemplo n.º 12
0
        public Vector3 SetFloorItem(Session Session, Item Item, Vector2 Position, int Rotation)
        {
            bool AlreadyContained   = mItems.ContainsKey(Item.Id);
            int  TotalLimitCount    = AlreadyContained ? mItems.Count - 1 : mItems.Count;
            int  SpecificLimitCount = mItemLimitCache.ContainsKey(Item.Definition.Behavior) ? (AlreadyContained ?
                                                                                               mItemLimitCache[Item.Definition.Behavior] - 1 : mItemLimitCache[Item.Definition.Behavior]) : 0;

            if (Item.Definition.RoomLimit > 0 && SpecificLimitCount >= Item.Definition.RoomLimit)
            {
                Session.SendData(NotificationMessageComposer.Compose("This room cannot hold any more furniture of this type."));
                return(null);
            }

            if (TotalLimitCount >= (int)ConfigManager.GetValue("rooms.limit.furni"))
            {
                Session.SendData(RoomItemPlacementErrorComposer.Compose(RoomItemPlacementErrorCode.FurniLimitReached));
                return(null);
            }

            bool IsRotationOnly = (Item.RoomId == RoomId && Item.RoomPosition.X == Position.X &&
                                   Item.RoomPosition.Y == Position.Y && Rotation != Item.RoomRotation);

            if (!IsValidItemRotation(Rotation))
            {
                return(null);
            }

            List <Vector2> AffectedTiles   = CalculateAffectedTiles(Item, Position, Rotation);
            double         PlacementHeight = GetItemPlacementHeight(Item, AffectedTiles, IsRotationOnly);

            if (PlacementHeight < 0)
            {
                return(null);
            }

            lock (mItemSyncRoot)
            {
                if (!mItems.ContainsKey(Item.Id))
                {
                    mItems.Add(Item.Id, Item);
                    IncrecementFurniLimitCache(Item.Definition.Behavior);
                }
            }

            return(new Vector3(Position.X, Position.Y, PlacementHeight));
        }
Ejemplo n.º 13
0
        private static void GetRoomInfo(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            RoomInfo Info = RoomInfoLoader.GetRoomInfo(Message.PopWiredUInt32());

            if (Info == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("Could not retrieve room information."));
                return;
            }

            Session.SendData(ModerationRoomInfoComposer.Compose(Info, RoomManager.GetInstanceByRoomId(Info.Id)));
        }
Ejemplo n.º 14
0
        private static void CautionUser(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            uint   UserId      = Message.PopWiredUInt32();
            string MessageText = Message.PopString();

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession != null)
            {
                TargetSession.SendData(HotelManagerNotificationComposer.Compose("Caution from moderator:\n\n" + MessageText));
                ModerationTicketManager.MarkTicketRespondedToForUser(UserId);
            }
            else
            {
                Session.SendData(NotificationMessageComposer.Compose("That user is not online at this point in time."));
            }

            CharacterInfo Info = (TargetSession != null ? TargetSession.CharacterInfo : null);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                if (Info == null)
                {
                    Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, UserId);
                }

                if (Info != null)
                {
                    Info.ModerationCautions++;
                }

                ModerationLogs.LogModerationAction(MySqlClient, Session, "Sent caution to user",
                                                   "User " + TargetSession.CharacterInfo.Username + " (ID " + TargetSession.CharacterId + "): '" +
                                                   MessageText + "'.");
            }
        }
Ejemplo n.º 15
0
        private static void GetRoomChatlog(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            int  Unknown1 = Message.PopWiredInt32();
            uint RoomId   = Message.PopWiredUInt32();

            RoomInfo Info = RoomInfoLoader.GetRoomInfo(RoomId);

            if (Info == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("Room not found; could not load chatlogs."));
                return;
            }

            Session.SendData(ModerationRoomChatlogsComposer.Compose(Info, ModerationLogs.GetLogsForRoom(RoomId,
                                                                                                        (UnixTimestamp.GetCurrent() - 3600), UnixTimestamp.GetCurrent())));
        }
Ejemplo n.º 16
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
            }
            else
            {
                Navigator.RemoveRoomFromStaffPicked(Instance.RoomId);
                Session.SendData(NotificationMessageComposer.Compose("This room has been removed from the staff picked rooms successfully."));
            }
        }
Ejemplo n.º 17
0
        private static void GetUserInfo(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            CharacterInfo Info = null;

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, Message.PopWiredUInt32());
            }

            if (Info == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("Could not retrieve user information."));
                return;
            }

            Session.SendData(ModerationUserInfoComposer.Compose(Info, SessionManager.GetSessionByCharacterId(Info.Id)));
        }
Ejemplo n.º 18
0
        private static void KickUser(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            uint   UserId      = Message.PopWiredUInt32();
            string MessageText = Message.PopString();

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession == null || TargetSession.HasRight("moderation_tool"))
            {
                Session.SendData(NotificationMessageComposer.Compose("That user is not online or cannot be kicked at this point in time."));
                return;
            }

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

            if (Instance == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("That user is not currently in any room."));
                return;
            }

            TargetSession.CharacterInfo.ModerationCautions++;
            Instance.SoftKickUser(TargetSession.CharacterId, true, false, true);
            TargetSession.SendData(NotificationMessageComposer.Compose("A moderator has kicked you from the room for the following reason:\n\n" + MessageText));

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                ModerationLogs.LogModerationAction(MySqlClient, Session, "Kicked user from room",
                                                   "User '" + TargetSession.CharacterInfo.Username + "' (ID " + TargetSession.CharacterId + ") from '" +
                                                   Instance.Info.Name + "' (ID " + Instance.RoomId + "): '" + MessageText + "'.");
            }
        }
Ejemplo n.º 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));

            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);
        }
Ejemplo n.º 20
0
        public void SendModerationAlert(string AlertMessage, bool IsCaution)
        {
            ServerMessage Message = IsCaution ? HotelManagerNotificationComposer.Compose("Caution from moderator:\n\n" +
                                                                                         AlertMessage) : NotificationMessageComposer.Compose("Notification from staff:\n\n" + AlertMessage);

            lock (mActorSyncRoot)
            {
                foreach (RoomActor Actor in mActors.Values)
                {
                    if (Actor.Type == RoomActorType.AiBot)
                    {
                        continue;
                    }

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

                    if (TargetSession == null)
                    {
                        continue;
                    }

                    TargetSession.SendData(Message);

                    if (IsCaution)
                    {
                        TargetSession.CharacterInfo.ModerationCautions++;
                    }
                }
            }
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        public string SetWallItem(Session Session, string[] Data, Item Item)
        {
            bool AlreadyContained   = mItems.ContainsKey(Item.Id);
            int  TotalLimitCount    = AlreadyContained ? mItems.Count - 1 : mItems.Count;
            int  SpecificLimitCount = mItemLimitCache.ContainsKey(Item.Definition.Behavior) ? (AlreadyContained ?
                                                                                               mItemLimitCache[Item.Definition.Behavior] - 1 : mItemLimitCache[Item.Definition.Behavior]) : 0;

            if (Item.Definition.RoomLimit > 0 && SpecificLimitCount >= Item.Definition.RoomLimit)
            {
                Session.SendData(NotificationMessageComposer.Compose("This room cannot hold any more furniture of this type."));
                return(string.Empty);
            }

            if (TotalLimitCount >= (int)ConfigManager.GetValue("rooms.limit.furni"))
            {
                Session.SendData(RoomItemPlacementErrorComposer.Compose(RoomItemPlacementErrorCode.FurniLimitReached));
                return(string.Empty);
            }

            if (Data.Length != 3 || !Data[0].StartsWith(":w=") || !Data[1].StartsWith("l=") || (Data[2] != "r" &&
                                                                                                Data[2] != "l"))
            {
                return(string.Empty);
            }

            string wBit = Data[0].Substring(3, Data[0].Length - 3);
            string lBit = Data[1].Substring(2, Data[1].Length - 2);

            if (!wBit.Contains(",") || !lBit.Contains(","))
            {
                return(string.Empty);
            }

            int w1 = 0;
            int w2 = 0;
            int l1 = 0;
            int l2 = 0;

            int.TryParse(wBit.Split(',')[0], out w1);
            int.TryParse(wBit.Split(',')[1], out w2);
            int.TryParse(lBit.Split(',')[0], out l1);
            int.TryParse(lBit.Split(',')[1], out l2);

            if (!Session.HasRight("hotel_admin") && (w1 < 0 || w2 < 0 || l1 < 0 || l2 < 0 || w1 > 200 || w2 > 200 || l1 > 200 || l2 > 200))
            {
                return(string.Empty);
            }

            string WallPos = ":w=" + w1 + "," + w2 + " l=" + l1 + "," + l2 + " " + Data[2];

            lock (mItemSyncRoot)
            {
                if (!mItems.ContainsKey(Item.Id))
                {
                    mItems.Add(Item.Id, Item);
                    IncrecementFurniLimitCache(Item.Definition.Behavior);
                }
            }

            return(WallPos);
        }
Ejemplo n.º 24
0
        private static void PerformRoomAction(Session Session, ClientMessage Message)
        {
            if (!Session.HasRight("moderation_tool"))
            {
                return;
            }

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Message.PopWiredUInt32());

            if (Instance == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("Could not perform room action."));
                return;
            }

            bool SetLock = Message.PopWiredBoolean();
            bool SetName = Message.PopWiredBoolean();
            bool KickAll = Message.PopWiredBoolean();

            List <string> Tags = new List <string>();

            if (!SetName)
            {
                foreach (string Tag in Instance.Info.Tags)
                {
                    Tags.Add(Tag);
                }
            }

            Instance.Info.EditRoom(SetName ? "Inappropriate to hotel management" : Instance.Info.Name, SetName ?
                                   "Inappropriate to hotel management" : Instance.Info.Description, SetLock ? RoomAccessType.Locked :
                                   Instance.Info.AccessType, SetLock ? string.Empty : Instance.Info.Password, Instance.Info.MaxUsers,
                                   SetName ? 0 : Instance.Info.CategoryId, Tags, Instance.Info.AllowPets, Instance.Info.AllowPets,
                                   Instance.Info.DisableRoomBlocking, Instance.Info.HideWalls, Instance.Info.WallThickness,
                                   Instance.Info.FloorThickness);

            if (KickAll)
            {
                Instance.KickRoom(true);
            }

            if (KickAll || SetName || SetLock)
            {
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    StringBuilder Details = new StringBuilder();

                    Details.Append("Room '" + Instance.Info.Name + "' (ID " + Instance.Info.Id + "): ");
                    int i = 0;

                    if (SetName)
                    {
                        Details.Append("Name set to 'Inappropriate to hotel management'");
                        i++;
                    }

                    if (KickAll)
                    {
                        if (i > 0)
                        {
                            Details.Append(", ");
                        }

                        Details.Append("Kicked all users from room");
                        i++;
                    }

                    if (SetLock)
                    {
                        if (i > 0)
                        {
                            Details.Append(", ");
                        }

                        Details.Append("Locked room");
                        i++;
                    }

                    ModerationLogs.LogModerationAction(MySqlClient, Session, "Performed room moderation action",
                                                       Details.ToString());
                }
            }
        }