Ejemplo n.º 1
0
        public static ServerMessage Compose(Session Session, Dictionary<int, CatalogPage> Pages)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.CATALOG_INDEX);
            SerializePage(Message, Pages[-1], CalcTreeSize(Session, Pages, -1));

            foreach (CatalogPage Page in Pages.Values)
            {
                if (Page.ParentId != -1 || (Page.RequiredRight.Length > 0 && !Session.HasRight(Page.RequiredRight)))
                {
                    continue;
                }

                SerializePage(Message, Page, CalcTreeSize(Session, Pages, Page.Id));

                foreach (CatalogPage ChildPage in Pages.Values)
                {
                    if (ChildPage.ParentId != Page.Id || (ChildPage.RequiredRight.Length > 0 && !Session.HasRight(ChildPage.RequiredRight)))
                    {
                        continue;
                    }

                    SerializePage(Message, ChildPage, 0);
                }
            }

            return Message;
        }
Ejemplo n.º 2
0
        public bool CheckUserRights(Session Session, bool RequireOwnership = false)
        {
            bool IsOwner = (Session.HasRight("room_rights_owner") || Session.CharacterId == Info.OwnerId);

            if (RequireOwnership)
            {
                return IsOwner;
            }

            return (IsOwner || Session.HasRight("room_rights") || mUsersWithRights.Contains(Session.CharacterId));
        }
Ejemplo n.º 3
0
        public static int GetWardrobeSlotAmountForSession(Session Session)
        {
            int WardrobeSlots = 0;

            if (Session.HasRight("club_regular"))
            {
                WardrobeSlots += 5;
            }

            if (Session.HasRight("club_vip"))
            {
                WardrobeSlots += 5;
            }

            return WardrobeSlots;
        }
Ejemplo n.º 4
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.º 5
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.º 6
0
        public static ServerMessage Compose(Session Session)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.USER_RIGHTS);

            if (Session.HasRight("club_vip"))
            {
                Message.AppendInt32(2);
            }
            else if (Session.HasRight("club_regular"))
            {
                Message.AppendInt32(1);
            }
            else
            {
                Message.AppendInt32(0);
            }

            // TODO: Dig in to the mod tool and other staff stuff further to figure out how much this does

            Message.AppendInt32(Session.HasRight("hotel_admin") ? 1000 : 0);

            return Message;
        }
Ejemplo n.º 7
0
        public static ServerMessage Compose(Session Session, List<string> UserMessagePresets,
            Dictionary<string, Dictionary<string, string>> UserActionPresets, List<string> RoomMessagePresets)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_TOOL_INIT);
            Message.AppendInt32(-1);
            Message.AppendInt32(UserMessagePresets.Count);

            foreach (string Preset in UserMessagePresets)
            {
                Message.AppendStringWithBreak(Preset);
            }

            Message.AppendInt32(UserActionPresets.Count);

            foreach (KeyValuePair<string, Dictionary<string, string>> PresetCategory in UserActionPresets)
            {
                Message.AppendStringWithBreak(PresetCategory.Key);
                Message.AppendInt32(PresetCategory.Value.Count);

                foreach (KeyValuePair<string, string> Preset in PresetCategory.Value)
                {
                    Message.AppendStringWithBreak(Preset.Key);
                    Message.AppendStringWithBreak(Preset.Value);
                }
            }

            Message.AppendBoolean(Session.HasRight("moderation_tickets")); // Tickets
            Message.AppendInt32(1); // Chatlogs
            Message.AppendInt32(1); // Message, user action, send caution
            Message.AppendInt32(1); // kick
            Message.AppendInt32(1); // ban
            Message.AppendInt32(1); // caution, message
            Message.AppendInt32(1); // ?

            Message.AppendInt32(RoomMessagePresets.Count);

            foreach (string Preset in RoomMessagePresets)
            {
                Message.AppendStringWithBreak(Preset);
            }

            return Message;
        }
Ejemplo n.º 8
0
        private static int CalcTreeSize(Session Session, Dictionary<int, CatalogPage> Pages, int ParentId)
        {
            int Num = 0;

            foreach (CatalogPage Page in Pages.Values)
            {
                if (Page.RequiredRight.Length > 0 && !Session.HasRight(Page.RequiredRight))
                {
                    continue;
                }

                if (Page.ParentId == ParentId)
                {
                    Num++;
                }
            }

            return Num;
        }
Ejemplo n.º 9
0
        private static void GetFriendsRooms(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                List<RoomInfo> Rooms = new List<RoomInfo>();
                ReadOnlyCollection<uint> Friends = Session.MessengerFriendCache.Friends;

                if (Friends.Count > 0)
                {
                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        StringBuilder QueryBuilder = new StringBuilder("SELECT * FROM rooms WHERE ");

                        int i = 0;

                        foreach (uint FriendId in Friends)
                        {
                            if (i >= 1)
                            {
                                QueryBuilder.Append("OR ");
                            }

                            QueryBuilder.Append("owner_id = " + FriendId + " ");
                            i++;
                        }

                        QueryBuilder.Append("ORDER BY current_users DESC LIMIT 50");

                        DataTable Table = MySqlClient.ExecuteQueryTable(QueryBuilder.ToString());

                        foreach (DataRow Row in Table.Rows)
                        {
                            Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row));
                        }
                    }
                }

                Response = NavigatorRoomListComposer.Compose(0, 3, string.Empty, Rooms);
                AddToCacheIfNeeded(Session.CharacterId, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 10
0
        private static void GetEventRooms(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(0, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                int Category = -1;
                int.TryParse(Message.PopString(), out Category);

                IEnumerable<RoomInstance> Rooms =
                    (from RoomInstance in RoomManager.RoomInstances
                     where (RoomInstance.Value.HasOngoingEvent &&
                         (Category == -1 || RoomInstance.Value.Event.CategoryId == Category))
                     orderby RoomInstance.Value.Event.TimestampStarted descending
                     select RoomInstance.Value).Take(50);

                Response = NavigatorRoomListComposer.Compose(Category, 12, string.Empty, Rooms.ToList(), true);
                AddToCacheIfNeeded(0, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 11
0
        private static void GetCategories(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(0, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                Response = NavigatorFlatCategoriesComposer.Compose(mFlatCategories);
                AddToCacheIfNeeded(0, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 12
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.º 13
0
        private static void PerformSearch(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(0, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                Dictionary<uint, RoomInfo> Rooms = new Dictionary<uint, RoomInfo>();
                string Query = UserInputFilter.FilterString(Message.PopString()).ToLower().Trim();
                int SearchEventCatId = 0;

                if (mEventSearchQueries.ContainsKey(Query.ToLower()))
                {
                    SearchEventCatId = mEventSearchQueries[Query.ToLower()];
                }

                // Limit query length. just a precaution.
                if (Query.Length > 64)
                {
                    Query = Query.Substring(0, 64);
                }

                if (Query.Length > 0)
                {
                    IEnumerable<RoomInstance> InstanceMatches =
                        (from RoomInstance in RoomManager.RoomInstances
                         where RoomInstance.Value.HumanActorCount > 0 &&
                             RoomInstance.Value.Info.Type == RoomType.Flat &&
                             (RoomInstance.Value.Info.OwnerName.StartsWith(Query) ||
                             RoomInstance.Value.SearchableTags.Contains(Query) ||
                             RoomInstance.Value.Info.Name.Contains(Query) ||
                             (RoomInstance.Value.HasOngoingEvent &&
                             (RoomInstance.Value.Event.Name.StartsWith(Query) ||
                             (SearchEventCatId > 0 && RoomInstance.Value.Event.CategoryId == SearchEventCatId))))
                         orderby RoomInstance.Value.HumanActorCount descending
                         select RoomInstance.Value).Take(50);

                    foreach (RoomInstance Instance in InstanceMatches)
                    {
                        Rooms.Add(Instance.RoomId, Instance.Info);
                    }

                    if (Rooms.Count < 50) // need db results?
                    {
                        using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                        {
                            MySqlClient.SetParameter("query", Query + "%");
                            MySqlClient.SetParameter("fquery", "%" + Query + "%");

                            uint ToUid = CharacterResolverCache.GetUidFromName(Query);

                            if (ToUid > 0)
                            {
                                MySqlClient.SetParameter("owneruid", ToUid);
                            }

                            DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE name LIKE @query AND type = 'flat' OR tags LIKE @fquery AND type = 'flat'" + (ToUid > 0 ? " OR owner_id = @owneruid AND type = 'flat'" : string.Empty) + " LIMIT 50");

                            foreach (DataRow Row in Table.Rows)
                            {
                                uint RoomId = (uint)Row["id"];

                                if (!Rooms.ContainsKey(RoomId))
                                {
                                    Rooms.Add(RoomId, RoomInfoLoader.GenerateRoomInfoFromRow(Row));
                                }
                            }
                        }
                    }
                }

                Response = NavigatorRoomListComposer.Compose(1, 9, Query, Rooms.Values.Take(50).ToList());
                AddToCacheIfNeeded(0, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 14
0
        private static void GetRecentRooms(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                List<uint> VisitedUids = new List<uint>();
                List<RoomInfo> Rooms = new List<RoomInfo>();

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    MySqlClient.SetParameter("userid", Session.CharacterId);
                    DataTable Table = MySqlClient.ExecuteQueryTable("SELECT room_id FROM room_visits WHERE user_id = @userid ORDER BY timestamp_entered DESC LIMIT 50");

                    foreach (DataRow Row in Table.Rows)
                    {
                        uint Id = (uint)Row["room_id"];

                        if (VisitedUids.Contains(Id))
                        {
                            continue;
                        }

                        RoomInfo Info = RoomInfoLoader.GetRoomInfo(Id);

                        if (Info == null || Info.Type == RoomType.Public)
                        {
                            continue;
                        }

                        Rooms.Add(Info);
                        VisitedUids.Add(Info.Id);
                    }
                }

                Response = NavigatorRoomListComposer.Compose(0, 7, string.Empty, Rooms);
                AddToCacheIfNeeded(Session.CharacterId, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 15
0
        private static void GetPopularTags(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(0, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                IEnumerable<List<string>> Tags =
                    (from RoomInstance in RoomManager.RoomInstances
                     where RoomInstance.Value.HumanActorCount > 0
                     orderby RoomInstance.Value.HumanActorCount descending
                     select RoomInstance.Value.SearchableTags).Take(50);

                Dictionary<string, int> TagValues = new Dictionary<string, int>();

                foreach (List<string> TagList in Tags)
                {
                    foreach (string Tag in TagList)
                    {
                        if (!TagValues.ContainsKey(Tag))
                        {
                            TagValues.Add(Tag, 1);
                        }
                        else
                        {
                            TagValues[Tag]++;
                        }
                    }
                }

                List<KeyValuePair<string, int>> SortedTags = new List<KeyValuePair<string, int>>(TagValues);

                SortedTags.Sort((FirstPair, NextPair) =>
                {
                    return FirstPair.Value.CompareTo(NextPair.Value);
                });

                SortedTags.Reverse();

                Response = NavigatorPopularTagListComposer.Compose(SortedTags);
                AddToCacheIfNeeded(0, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 16
0
        private static void EditRoom(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

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

            // FQJ@LRoy's Office@fThis is where I handle business. Yeah.J@@RBIJ@Foffice@IbuttsechsAAAA

            uint Id = Message.PopWiredUInt32();

            if (Id != Instance.RoomId)
            {
                return;
            }

            string Name = UserInputFilter.FilterString(Message.PopString()).Trim();
            string Description = UserInputFilter.FilterString(Message.PopString()).Trim();
            RoomAccessType AccessType = (RoomAccessType)Message.PopWiredInt32();
            string Password = UserInputFilter.FilterString(Message.PopString()).Trim();
            int UserLimit = Message.PopWiredInt32();
            int CategoryId = Message.PopWiredInt32();
            int TagCount = Message.PopWiredInt32();

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

            for (int i = 0; (i < TagCount && i < 2); i++)
            {
                string Tag = UserInputFilter.FilterString(Message.PopString()).Trim().ToLower();

                if (Tag.Length > 32)
                {
                    Tag = Tag.Substring(0, 32);
                }

                if (Tag.Length > 0 && !Tags.Contains(Tag))
                {
                    Tags.Add(Tag);
                }
            }

            bool AllowPets = (Message.ReadBytes(1)[0] == 65);
            bool AllowPetEating = (Message.ReadBytes(1)[0] == 65);
            bool AllowBlocking = (Message.ReadBytes(1)[0] == 65);
            bool HideWalls = (Message.ReadBytes(1)[0] == 65);
            int WallThickness = Message.PopWiredInt32();
            int FloorThickness = Message.PopWiredInt32();

            if (WallThickness < -2 || WallThickness > 1)
            {
                WallThickness = 0;
            }

            if (FloorThickness < -2 || FloorThickness > 1)
            {
                FloorThickness = 0;
            }

            if (HideWalls && !Session.HasRight("club_vip"))
            {
                HideWalls = false;
            }

            if (Name.Length > 60) // was 25
            {
                Name = Name.Substring(0, 60);
            }

            if (Description.Length > 128)
            {
                Description = Description.Substring(0, 128);
            }

            if (Password.Length > 64)
            {
                Password = Password.Substring(0, 64);
            }

            if (UserLimit > Instance.Model.MaxUsers)
            {
                UserLimit = Instance.Model.MaxUsers;
            }

            if (Name.Length == 0)
            {
                Name = "Room";
            }

            if (AccessType == RoomAccessType.PasswordProtected && Password.Length == 0)
            {
                AccessType = RoomAccessType.Open;
            }

            Instance.Info.EditRoom(Name, Description, AccessType, Password, UserLimit, CategoryId, Tags, AllowPets,
                AllowPetEating, AllowBlocking, HideWalls, WallThickness, FloorThickness);

            Session.SendData(RoomUpdatedNotification1Composer.Compose(Instance.RoomId));
            Instance.BroadcastMessage(RoomUpdatedNotification2Composer.Compose(Instance.RoomId));
            Instance.BroadcastMessage(RoomWallsStatusComposer.Compose(Instance.Info.HideWalls, Instance.Info.WallThickness,
                Instance.Info.FloorThickness));
            //Instance.BroadcastMessage(RoomInfoComposer.Compose(Instance.Info, false));

            if (Instance.Info.AccessType != RoomAccessType.Open && Instance.HasOngoingEvent)
            {
                Instance.StopEvent();
            }
        }
Ejemplo n.º 17
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.º 18
0
        public static void UserChat(Session Session, ClientMessage Message)
        {
            if (Session.CharacterInfo.IsMuted)
            {
                return;
            }

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

            if (Instance == null)
            {
                return;
            }

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

            if (Actor == null)
            {
                return;
            }

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

            bool done = Instance.WiredManager.HandleChat(MessageText, Actor);

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

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

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

            if (!done)
            {
                Actor.Chat(MessageText, Shout, Session.HasRight("mute"));
            }
            else
            {
                Session.SendData(RoomChatComposer.Compose(Actor.Id, MessageText, 0, ChatType.Whisper));
            }

            if (Instance.HumanActorCount > 1)
            {
                QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_CHAT);
            }
        }
Ejemplo n.º 19
0
        public static void PrepareRoom(Session Session, uint RoomId, string Password = "", bool BypassAuthentication = false)
        {
            // Remove user from any previous room
            RoomManager.RemoveUserFromRoom(Session, false);

            // Try to retrieve room information
            RoomInfo Info = RoomInfoLoader.GetRoomInfo(RoomId);

            // Room not found, send kick notif and stop
            if (Info == null)
            {
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }
            Session.AbsoluteRoomId = Info.Id;
            // Try to retrieve room model information
            RoomModel Model = Info.TryGetModel();

            // Model information not found, send kick notif and stop
            if (Model == null)
            {
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Load room instance into the server memory if needed
            if (!RoomManager.InstanceIsLoadedForRoom(Info.Id))
            {
                RoomManager.TryLoadRoomInstance(Info.Id);
            }

            // Attempt to retrieve the instance from the server memory
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Info.Id);

            // If the instance was not created or is unavailable, send kick notif and stop
            if (Instance == null)
            {
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Check if the room capacity has been reached
            if (Info.CurrentUsers >= Info.MaxUsers && !Session.HasRight("enter_full_rooms"))
            {
                Session.SendData(RoomJoinErrorComposer.Compose(1));
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Check if the user has been banned from this room
            if (Instance.IsUserBanned(Session.CharacterId))
            {
                Session.SendData(RoomJoinErrorComposer.Compose(4));
                Session.SendData(RoomKickedComposer.Compose());
                return;
            }

            // Mark room as loading and check for initial authorization
            Session.AbsoluteRoomId = Info.Id;
            Session.RoomAuthed = (BypassAuthentication || Info.OwnerId == Session.CharacterId ||
                Session.HasRight("enter_locked_rooms"));
            Session.RoomJoined = false;

            // Send confirmation that the initial checks have been passed (if this is a flat)
            if (Info.Type == RoomType.Flat)
            {
                Session.SendData(RoomOpenFlatComposer.Compose());
            }

            // Try to accomplish authorization (if not already initially authorized by character rights)
            if (!Session.RoomAuthed)
            {
                // Check for valid password, if needed
                if (Info.AccessType == RoomAccessType.PasswordProtected)
                {
                    if (Info.Password != Password)
                    {
                        Session.SendData(GenericErrorComposer.Compose(-100002));
                        RoomManager.RemoveUserFromRoom(Session);
                        return;
                    }
                }
                // Send doorbell, if any users are in this room.
                else if (Info.AccessType == RoomAccessType.Locked)
                {
                    if (Instance.HumanActorCount > 0)
                    {
                        Session.SendData(RoomDoorbellComposer.Compose());
                        Instance.BroadcastMessage(RoomDoorbellComposer.Compose(Session.CharacterInfo.Username), true);
                        return;
                    }
                    else
                    {
                        Session.SendData(RoomDoorbellNoResponseComposer.Compose());
                        RoomManager.RemoveUserFromRoom(Session);
                        return;
                    }
                }
            }

            // If all these stages have been passed, mark auth as OK and continue loading
            Session.RoomAuthed = true;
            EnterRoom(Session, Instance);
        }
Ejemplo n.º 20
0
        private static void UserDance(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

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

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

            int DanceId = Message.PopWiredInt32();

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

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

            Actor.Dance(DanceId);

            QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_DANCE);
        }
Ejemplo n.º 21
0
        private static void OnSendIm(Session Session, ClientMessage Message)
        {
            uint UserId = Message.PopWiredUInt32();
            string Text = UserInputFilter.FilterString(Message.PopString()).Trim();

            if (UserId <= 0 || Text.Length < 1)
            {
                return;
            }

            if (Session.CharacterInfo.IsMuted)
            {
                Session.SendData(MessengerImErrorComposer.Compose(4, UserId));
                return;
            }

            if (!Session.MessengerFriendCache.Friends.Contains(UserId))
            {
                Session.SendData(MessengerImErrorComposer.Compose(6, UserId));
                return;
            }

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession == null)
            {
                Session.SendData(MessengerImErrorComposer.Compose(5, UserId));
                return;
            }

            if (TargetSession.CharacterInfo.IsMuted)
            {
                Session.SendData(MessengerImErrorComposer.Compose(3, UserId));
                return;
            }

            TargetSession.SendData(MessengerImMessageComposer.Compose(Session.CharacterId, Text));
            if (Text == ":restart")
            {
                if (!Session.HasRight("hotel_admin"))
                {
                }
                else
                {

                    string reason = "[SYS] Forced update";
                    SessionManager.BroadcastPacket(NotificationMessageComposer.Compose("The server is restarting for an update! \nPlease log back in when you logout.\n\nUpdates don't take long at RealityRP.\n\nReason for Update:\n" + reason));
                    System.Threading.Thread.Sleep(15000);
                    if (System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe" == "Reality.exe")
                    {
                        Process.Start(Environment.CurrentDirectory + "\\Reality1.exe", "\"delay 4000\"");
                    }
                    else
                    {
                        Process.Start(Environment.CurrentDirectory + "\\Reality.exe", "\"delay 4000\"");
                    }
                    Program.Stop();
                    Program.Stop();
                }
            }
        }
Ejemplo n.º 22
0
        private static void GetOfficialRooms(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(0, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                Response = NavigatorOfficialRoomsComposer.Message(mOfficialItems);
                AddToCacheIfNeeded(0, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 23
0
        private static void GetPopularRooms(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(0, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                int Category = -1;
                int.TryParse(Message.PopString(), out Category);

                IEnumerable<RoomInstance> Rooms =
                    (from RoomInstance in RoomManager.RoomInstances
                     where RoomInstance.Value.Info.Type == RoomType.Flat &&
                        RoomInstance.Value.CachedNavigatorUserCount > 0 &&
                        (Category == -1 || RoomInstance.Value.Info.CategoryId == Category)
                     orderby RoomInstance.Value.CachedNavigatorUserCount descending
                     select RoomInstance.Value).Take(50);

                Response = NavigatorRoomListComposer.Compose(Category, 1, string.Empty, Rooms.ToList());
                AddToCacheIfNeeded(0, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 24
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.º 25
0
        private static void GetRatedRooms(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(0, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                List<RoomInfo> Rooms = new List<RoomInfo>();

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE type = 'flat' AND score > 0 ORDER BY score DESC LIMIT 50");

                    foreach (DataRow Row in Table.Rows)
                    {
                        Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row));
                    }
                }

                Response = NavigatorRoomListComposer.Compose(0, 2, string.Empty, Rooms);
                AddToCacheIfNeeded(0, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 26
0
        public static void GetUserRooms(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                List<RoomInfo> Rooms = new List<RoomInfo>();

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    MySqlClient.SetParameter("ownerid", Session.CharacterId);
                    MySqlClient.SetParameter("limit", MaxRoomsPerUser);
                    DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE owner_id = @ownerid ORDER BY name ASC LIMIT @limit");

                    foreach (DataRow Row in Table.Rows)
                    {
                        Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row));
                    }
                }

                Response = NavigatorRoomListComposer.Compose(0, 5, string.Empty, Rooms);
                AddToCacheIfNeeded(Session.CharacterId, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 27
0
        private static void GetRoomsWithFriends(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message);

                if (Response != null)
                {
                    Session.SendData(Response);
                    return;
                }

                List<uint> RoomUids = new List<uint>();
                ReadOnlyCollection<uint> Friends = Session.MessengerFriendCache.Friends;

                foreach (uint FriendId in Friends)
                {
                    Session FriendSession = SessionManager.GetSessionByCharacterId(FriendId);

                    if (FriendSession != null && FriendSession.CurrentRoomId > 0)
                    {
                        RoomUids.Add(FriendSession.CurrentRoomId);
                    }
                }

                IEnumerable<RoomInstance> Rooms =
                    (from RoomInstance in RoomManager.RoomInstances
                     where RoomUids.Contains(RoomInstance.Value.RoomId)
                     select RoomInstance.Value).Take(50);

                Response = NavigatorRoomListComposer.Compose(0, 4, string.Empty, Rooms.ToList());
                AddToCacheIfNeeded(Session.CharacterId, Message, Response);
                Session.SendData(Response);
            }
        }
Ejemplo n.º 28
0
        private static void AddFavorite(Session Session, ClientMessage Message)
        {
            if (Session.HasRight("hotel_admin"))
            {
                uint RoomId = Message.PopWiredUInt32();

                if (Session.FavoriteRoomsCache.AddRoomToFavorites(RoomId))
                {
                    Session.SendData(NavigatorFavoriteRoomsChanged.Compose(RoomId, true));
                }

                ClearCacheGroup(Session.CharacterId);
            }
        }
Ejemplo n.º 29
0
        private static void TakePet(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

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

            if (Actor == null)
            {
                return;
            }

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

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

            Instance.RemoveActorFromRoom(Actor.Id);
            Session.PetInventoryCache.Add(PetData);
            Session.SendData(InventoryPetAddedComposer.Compose(PetData));
        }
Ejemplo n.º 30
0
        private static void OnPurchase(Session Session, ClientMessage Message)
        {
            int PageId = Message.PopWiredInt32();
            uint ItemId = Message.PopWiredUInt32();
            string Data = Message.PopString();

            CatalogPage Page = CatalogManager.GetCatalogPage(PageId);

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

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

                        CatalogItem Item = Page.GetItem(ItemId);

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

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

                    case "club_buy":

                        CatalogClubOffer Offer = CatalogManager.GetClubOffer(ItemId);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        // Send new data to client
                        Session.SendData(CatalogPurchaseResultComposer.Compose(Offer));
                        Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance));
                        Session.SendData(FuseRightsListComposer.Compose(Session));
                        Session.SendData(SubscriptionStatusComposer.Compose(Session.SubscriptionManager, true));
                        //Session.SendData(ClubGiftReadyComposer.Compose(1));
                        break;
                }
            }
        }