Beispiel #1
0
        private static void GetRoomsWithFriends(Session Session, ClientMessage Message)
        {
            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);
        }
Beispiel #2
0
        public static void GetUserRooms(Session Session, ClientMessage Message)
        {
            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);
        }
Beispiel #3
0
        private static void GetRatedRooms(Session Session, ClientMessage Message)
        {
            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);
        }
Beispiel #4
0
        private static void GetPopularRooms(Session Session, ClientMessage Message)
        {
            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);
        }
Beispiel #5
0
        private static void GetEventRooms(Session Session, ClientMessage Message)
        {
            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);
        }
Beispiel #6
0
        private static void GetFriendsRooms(Session Session, ClientMessage Message)
        {
            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);
        }
Beispiel #7
0
        private static void GetRecentRooms(Session Session, ClientMessage Message)
        {
            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);
        }
Beispiel #8
0
        private static void PerformSearch(Session Session, ClientMessage Message)
        {
            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);
        }