public GuestRoomSearchResultComposer(int Mode, string UserQuery, ICollection <RoomData> Rooms) : base(ServerPacketHeader.GuestRoomSearchResultMessageComposer) { base.WriteInteger(Mode); base.WriteString(UserQuery); base.WriteInteger(Rooms.Count); foreach (RoomData data in Rooms) { RoomAppender.WriteRoom(this, data, data.Promotion); } base.WriteBoolean(false); }
public GuestRoomSearchResultComposer(int mode, string userQuery, ICollection <RoomData> rooms) : base(ServerPacketHeader.GuestRoomSearchResultMessageComposer) { WriteInteger(mode); WriteString(userQuery); WriteInteger(rooms.Count); foreach (var data in rooms) { RoomAppender.WriteRoom(this, data, data.Promotion); } WriteBoolean(false); }
public static void Search(ServerPacket Message, SearchResultList SearchResult, string SearchData, GameClient Session, int FetchLimit) { //Switching by categorys. switch (SearchResult.CategoryType) { default: Message.WriteInteger(0); break; case NavigatorCategoryType.QUERY: { #region Query if (SearchData.ToLower().StartsWith("owner:")) { if (SearchData.Length > 0) { int UserId = 0; DataTable GetRooms = null; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { if (SearchData.ToLower().StartsWith("owner:")) { dbClient.SetQuery("SELECT r.* FROM rooms r, users u WHERE u.username = @username AND r.owner = u.id AND r.state != 'invisible' ORDER BY r.users_now DESC LIMIT 50;"); dbClient.AddParameter("username", SearchData.Remove(0, 6)); GetRooms = dbClient.getTable(); } } List <RoomData> Results = new List <RoomData>(); if (GetRooms != null) { foreach (DataRow Row in GetRooms.Rows) { RoomData RoomData = PlusEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToInt32(Row["id"]), Row); if (RoomData != null && !Results.Contains(RoomData)) { Results.Add(RoomData); } } } Message.WriteInteger(Results.Count); foreach (RoomData Data in Results.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } } else if (SearchData.ToLower().StartsWith("tag:")) { SearchData = SearchData.Remove(0, 4); ICollection <RoomData> TagMatches = PlusEnvironment.GetGame().GetRoomManager().SearchTaggedRooms(SearchData); Message.WriteInteger(TagMatches.Count); foreach (RoomData Data in TagMatches.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } else if (SearchData.ToLower().StartsWith("group:")) { SearchData = SearchData.Remove(0, 6); ICollection <RoomData> GroupRooms = PlusEnvironment.GetGame().GetRoomManager().SearchGroupRooms(SearchData); Message.WriteInteger(GroupRooms.Count); foreach (RoomData Data in GroupRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } else { if (SearchData.Length > 0) { DataTable Table = null; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT `id`,`caption`,`description`,`roomtype`,`owner`,`state`,`category`,`users_now`,`users_max`,`model_name`,`score`,`allow_pets`,`allow_pets_eat`,`room_blocking_disabled`,`allow_hidewall`,`password`,`wallpaper`,`floor`,`landscape`,`floorthick`,`wallthick`,`mute_settings`,`kick_settings`,`ban_settings`,`chat_mode`,`chat_speed`,`chat_size`,`trade_settings`,`group_id`,`tags`,`push_enabled`,`pull_enabled`,`enables_enabled`,`respect_notifications_enabled`,`pet_morphs_allowed`,`spush_enabled`,`spull_enabled` FROM rooms WHERE `caption` LIKE @query ORDER BY `users_now` DESC LIMIT 50"); if (SearchData.ToLower().StartsWith("roomname:")) { dbClient.AddParameter("query", "%" + SearchData.Split(new char[] { ':' }, 2)[1] + "%"); } else { dbClient.AddParameter("query", "%" + SearchData + "%"); } Table = dbClient.getTable(); } List <RoomData> Results = new List <RoomData>(); if (Table != null) { foreach (DataRow Row in Table.Rows) { if (Convert.ToString(Row["state"]) == "invisible") { continue; } RoomData RData = PlusEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToInt32(Row["id"]), Row); if (RData != null && !Results.Contains(RData)) { Results.Add(RData); } } } Message.WriteInteger(Results.Count); foreach (RoomData Data in Results.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } } #endregion break; } case NavigatorCategoryType.FEATURED: #region Featured List <RoomData> Rooms = new List <RoomData>(); ICollection <FeaturedRoom> Featured = PlusEnvironment.GetGame().GetNavigator().GetFeaturedRooms(); foreach (FeaturedRoom FeaturedItem in Featured.ToList()) { if (FeaturedItem == null) { continue; } RoomData Data = PlusEnvironment.GetGame().GetRoomManager().GenerateRoomData(FeaturedItem.RoomId); if (Data == null) { continue; } if (!Rooms.Contains(Data)) { Rooms.Add(Data); } } Message.WriteInteger(Rooms.Count); foreach (RoomData Data in Rooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } #endregion break; case NavigatorCategoryType.POPULAR: { List <RoomData> PopularRooms = PlusEnvironment.GetGame().GetRoomManager().GetPopularRooms(-1, FetchLimit); Message.WriteInteger(PopularRooms.Count); foreach (RoomData Data in PopularRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.RECOMMENDED: { List <RoomData> RecommendedRooms = PlusEnvironment.GetGame().GetRoomManager().GetRecommendedRooms(FetchLimit); Message.WriteInteger(RecommendedRooms.Count); foreach (RoomData Data in RecommendedRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.CATEGORY: { List <RoomData> GetRoomsByCategory = PlusEnvironment.GetGame().GetRoomManager().GetRoomsByCategory(SearchResult.Id, FetchLimit); Message.WriteInteger(GetRoomsByCategory.Count); foreach (RoomData Data in GetRoomsByCategory.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.MY_ROOMS: Message.WriteInteger(Session.GetHabbo().UsersRooms.Count); foreach (RoomData Data in Session.GetHabbo().UsersRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MY_FAVORITES: List <RoomData> Favourites = new List <RoomData>(); foreach (int Id in Session.GetHabbo().FavoriteRooms.ToArray()) { RoomData Room = PlusEnvironment.GetGame().GetRoomManager().GenerateRoomData(Id); if (Room == null) { continue; } if (!Favourites.Contains(Room)) { Favourites.Add(Room); } } Favourites = Favourites.Take(FetchLimit).ToList(); Message.WriteInteger(Favourites.Count); foreach (RoomData Data in Favourites.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MY_GROUPS: List <RoomData> MyGroups = new List <RoomData>(); foreach (Group Group in PlusEnvironment.GetGame().GetGroupManager().GetGroupsForUser(Session.GetHabbo().Id).ToList()) { if (Group == null) { continue; } RoomData Data = PlusEnvironment.GetGame().GetRoomManager().GenerateRoomData(Group.RoomId); if (Data == null) { continue; } if (!MyGroups.Contains(Data)) { MyGroups.Add(Data); } } MyGroups = MyGroups.Take(FetchLimit).ToList(); Message.WriteInteger(MyGroups.Count); foreach (RoomData Data in MyGroups.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MY_FRIENDS_ROOMS: List <RoomData> MyFriendsRooms = new List <RoomData>(); foreach (MessengerBuddy buddy in Session.GetHabbo().GetMessenger().GetFriends().Where(p => p.InRoom)) { if (buddy == null || !buddy.InRoom || buddy.UserId == Session.GetHabbo().Id) { continue; } if (!MyFriendsRooms.Contains(buddy.CurrentRoom.RoomData)) { MyFriendsRooms.Add(buddy.CurrentRoom.RoomData); } } Message.WriteInteger(MyFriendsRooms.Count); foreach (RoomData Data in MyFriendsRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MY_RIGHTS: List <RoomData> MyRights = new List <RoomData>(); DataTable GetRights = null; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT `room_id` FROM `room_rights` WHERE `user_id` = @UserId LIMIT @FetchLimit"); dbClient.AddParameter("UserId", Session.GetHabbo().Id); dbClient.AddParameter("FetchLimit", FetchLimit); GetRights = dbClient.getTable(); foreach (DataRow Row in GetRights.Rows) { RoomData Data = PlusEnvironment.GetGame().GetRoomManager().GenerateRoomData(Convert.ToInt32(Row["room_id"])); if (Data == null) { continue; } if (!MyRights.Contains(Data)) { MyRights.Add(Data); } } } Message.WriteInteger(MyRights.Count); foreach (RoomData Data in MyRights.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.TOP_PROMOTIONS: { List <RoomData> GetPopularPromotions = PlusEnvironment.GetGame().GetRoomManager().GetOnGoingRoomPromotions(16, FetchLimit); Message.WriteInteger(GetPopularPromotions.Count); foreach (RoomData Data in GetPopularPromotions.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.PROMOTION_CATEGORY: { List <RoomData> GetPromotedRooms = PlusEnvironment.GetGame().GetRoomManager().GetPromotedRooms(SearchResult.Id, FetchLimit); Message.WriteInteger(GetPromotedRooms.Count); foreach (RoomData Data in GetPromotedRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } } }
public static void Search(ServerPacket packet, SearchResultList result, string query, Habbo habbo, int limit) { if (habbo == null) { return; } switch (result.CategoryType) { default: case NavigatorCategoryType.MyFavourites: case NavigatorCategoryType.MyHistory: case NavigatorCategoryType.Featured: packet.WriteInteger(0); break; case NavigatorCategoryType.Query: { #region Query if (query.ToLower().StartsWith("owner:")) { if (query.Length > 0) { int UserId = 0; DataTable GetRooms = null; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { if (query.ToLower().StartsWith("owner:")) { dbClient.SetQuery("SELECT `id` FROM `users` WHERE `username` = @username LIMIT 1"); dbClient.AddParameter("username", query.Remove(0, 6)); UserId = dbClient.GetInteger(); dbClient.SetQuery("SELECT * FROM `rooms` WHERE `owner` = '" + UserId + "' and `state` != 'invisible' ORDER BY `users_now` DESC LIMIT 50"); GetRooms = dbClient.GetTable(); } } List <RoomData> Results = new List <RoomData>(); if (GetRooms != null) { foreach (DataRow Row in GetRooms.Rows) { RoomData Data = null; if (!RoomFactory.TryGetData(Convert.ToInt32(Row["id"]), out Data)) { continue; } if (!Results.Contains(Data)) { Results.Add(Data); } } GetRooms = null; } packet.WriteInteger(Results.Count); foreach (RoomData Data in Results.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } Results = null; } } else if (query.ToLower().StartsWith("tag:")) { query = query.Remove(0, 4); ICollection <Room> TagMatches = PlusEnvironment.GetGame().GetRoomManager().SearchTaggedRooms(query); packet.WriteInteger(TagMatches.Count); foreach (RoomData Data in TagMatches.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } TagMatches = null; } else if (query.ToLower().StartsWith("group:")) { query = query.Remove(0, 6); ICollection <Room> GroupRooms = PlusEnvironment.GetGame().GetRoomManager().SearchGroupRooms(query); packet.WriteInteger(GroupRooms.Count); foreach (RoomData Data in GroupRooms.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } GroupRooms = null; } else { if (query.Length > 0) { DataTable Table = null; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT `id`,`caption`,`description`,`roomtype`,`owner`,`state`,`category`,`users_now`,`users_max`,`model_name`,`score`,`allow_pets`,`allow_pets_eat`,`room_blocking_disabled`,`allow_hidewall`,`password`,`wallpaper`,`floor`,`landscape`,`floorthick`,`wallthick`,`mute_settings`,`kick_settings`,`ban_settings`,`chat_mode`,`chat_speed`,`chat_size`,`trade_settings`,`group_id`,`tags`,`push_enabled`,`pull_enabled`,`enables_enabled`,`respect_notifications_enabled`,`pet_morphs_allowed`,`spush_enabled`,`spull_enabled`,`sale_price` FROM rooms WHERE `caption` LIKE @query ORDER BY `users_now` DESC LIMIT 50"); dbClient.AddParameter("query", query + "%"); Table = dbClient.GetTable(); } List <RoomData> Results = new List <RoomData>(); if (Table != null) { foreach (DataRow Row in Table.Rows) { if (Convert.ToString(Row["state"]) == "invisible") { continue; } RoomData Data = null; if (!RoomFactory.TryGetData(Convert.ToInt32(Row["id"]), out Data)) { continue; } if (!Results.Contains(Data)) { Results.Add(Data); } } Table = null; } packet.WriteInteger(Results.Count); foreach (RoomData Data in Results.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } Results = null; } } #endregion break; } case NavigatorCategoryType.Popular: { List <Room> PopularRooms = PlusEnvironment.GetGame().GetRoomManager().GetPopularRooms(-1, limit); packet.WriteInteger(PopularRooms.Count); foreach (RoomData Data in PopularRooms.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } PopularRooms = null; break; } case NavigatorCategoryType.Recommended: { List <Room> RecommendedRooms = PlusEnvironment.GetGame().GetRoomManager().GetRecommendedRooms(limit); packet.WriteInteger(RecommendedRooms.Count); foreach (RoomData Data in RecommendedRooms.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } RecommendedRooms = null; break; } case NavigatorCategoryType.Category: { List <Room> GetRoomsByCategory = PlusEnvironment.GetGame().GetRoomManager().GetRoomsByCategory(result.Id, limit); packet.WriteInteger(GetRoomsByCategory.Count); foreach (RoomData Data in GetRoomsByCategory.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } GetRoomsByCategory = null; break; } case NavigatorCategoryType.MyRooms: { ICollection <RoomData> rooms = RoomFactory.GetRoomsDataByOwnerSortByName(habbo.Id).OrderByDescending(x => x.UsersNow).ToList(); packet.WriteInteger(rooms.Count); foreach (RoomData Data in rooms.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } break; } case NavigatorCategoryType.MyGroups: { List <RoomData> MyGroups = new List <RoomData>(); foreach (Group Group in PlusEnvironment.GetGame().GetGroupManager().GetGroupsForUser(habbo.Id).ToList()) { if (Group == null) { continue; } RoomData Data = null; if (!RoomFactory.TryGetData(Group.RoomId, out Data)) { continue; } if (!MyGroups.Contains(Data)) { MyGroups.Add(Data); } } MyGroups = MyGroups.Take(limit).ToList(); packet.WriteInteger(MyGroups.Count); foreach (RoomData Data in MyGroups.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } MyGroups = null; break; } case NavigatorCategoryType.MyFriendsRooms: { List <int> RoomIds = new List <int>(); if (habbo == null || habbo.GetMessenger() == null || habbo.GetMessenger().GetFriends() == null) { return; } foreach (MessengerBuddy buddy in habbo.GetMessenger().GetFriends().Where(p => p.InRoom)) { if (buddy == null || !buddy.InRoom || buddy.UserId == habbo.Id) { continue; } if (!RoomIds.Contains(buddy.CurrentRoom.Id)) { RoomIds.Add(buddy.CurrentRoom.Id); } } List <Room> MyFriendsRooms = PlusEnvironment.GetGame().GetRoomManager().GetRoomsByIds(RoomIds.ToList()); packet.WriteInteger(MyFriendsRooms.Count); foreach (RoomData Data in MyFriendsRooms.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } MyFriendsRooms = null; break; } case NavigatorCategoryType.MyRights: { List <RoomData> MyRights = new List <RoomData>(); if (habbo != null) { DataTable GetRights = null; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT `room_id` FROM `room_rights` WHERE `user_id` = @UserId LIMIT @FetchLimit"); dbClient.AddParameter("UserId", habbo.Id); dbClient.AddParameter("FetchLimit", limit); GetRights = dbClient.GetTable(); foreach (DataRow Row in GetRights.Rows) { RoomData Data = null; if (!RoomFactory.TryGetData(Convert.ToInt32(Row["room_id"]), out Data)) { continue; } if (!MyRights.Contains(Data)) { MyRights.Add(Data); } } } } packet.WriteInteger(MyRights.Count); foreach (RoomData Data in MyRights.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } MyRights = null; break; } case NavigatorCategoryType.TopPromotions: { List <Room> GetPopularPromotions = PlusEnvironment.GetGame().GetRoomManager().GetOnGoingRoomPromotions(16, limit); packet.WriteInteger(GetPopularPromotions.Count); foreach (RoomData Data in GetPopularPromotions.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } GetPopularPromotions = null; break; } case NavigatorCategoryType.PromotionCategory: { List <Room> GetPromotedRooms = PlusEnvironment.GetGame().GetRoomManager().GetPromotedRooms(result.OrderId, limit); packet.WriteInteger(GetPromotedRooms.Count); foreach (RoomData Data in GetPromotedRooms.ToList()) { RoomAppender.WriteRoom(packet, Data, Data.Promotion); } GetPromotedRooms = null; break; } } }
public static void Search(ServerPacket Message, SearchResultList SearchResult, string SearchData, GameClient Session, int FetchLimit) { //Switching by categorys. switch (SearchResult.CategoryType) { default: Message.WriteInteger(0); break; case NavigatorCategoryType.QUERY: { #region Query if (SearchData.ToLower().StartsWith("owner:")) { if (SearchData.Length > 0) { int UserId = 0; DataTable GetRooms = null; using (IQueryAdapter dbClient = RavenEnvironment.GetDatabaseManager().GetQueryReactor()) { if (SearchData.ToLower().StartsWith("owner:")) { dbClient.SetQuery("SELECT `id` FROM `users` WHERE `username` = @username LIMIT 1"); dbClient.AddParameter("username", SearchData.Remove(0, 6)); UserId = dbClient.getInteger(); dbClient.SetQuery("SELECT * FROM `rooms` WHERE `owner` = '" + UserId + "' and `state` != 'invisible' ORDER BY `users_now` DESC LIMIT 50"); GetRooms = dbClient.getTable(); } } List <RoomData> Results = new List <RoomData>(); if (GetRooms != null) { foreach (DataRow Row in GetRooms.Rows) { RoomData RoomData = RavenEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToInt32(Row["id"]), Row); if (RoomData != null && !Results.Contains(RoomData)) { Results.Add(RoomData); } } } Message.WriteInteger(Results.Count); foreach (RoomData Data in Results.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } } else if (SearchData.ToLower().StartsWith("tag:")) { SearchData = SearchData.Remove(0, 4); ICollection <RoomData> TagMatches = RavenEnvironment.GetGame().GetRoomManager().SearchTaggedRooms(SearchData); Message.WriteInteger(TagMatches.Count); foreach (RoomData Data in TagMatches.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } else if (SearchData.ToLower().StartsWith("group:")) { SearchData = SearchData.Remove(0, 6); ICollection <RoomData> GroupRooms = RavenEnvironment.GetGame().GetRoomManager().SearchGroupRooms(SearchData); Message.WriteInteger(GroupRooms.Count); foreach (RoomData Data in GroupRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } else { if (SearchData.Length > 0) { DataTable Table = null; using (IQueryAdapter dbClient = RavenEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT * FROM rooms WHERE caption LIKE @query ORDER BY users_now DESC LIMIT 50"); dbClient.AddParameter("query", "%" + SearchData + "%"); Table = dbClient.getTable(); } List <RoomData> Results = new List <RoomData>(); if (Table != null) { foreach (DataRow Row in Table.Rows) { if (Convert.ToString(Row["state"]) == "invisible") { continue; } RoomData RData = RavenEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToInt32(Row["id"]), Row); if (RData != null && !Results.Contains(RData)) { Results.Add(RData); } } } Message.WriteInteger(Results.Count); foreach (RoomData Data in Results.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } } #endregion break; } case NavigatorCategoryType.FEATURED: { #region Featured List <RoomData> Rooms = new List <RoomData>(); ICollection <FeaturedRoom> Featured = RavenEnvironment.GetGame().GetNavigator().GetFeaturedRooms(SearchResult.Id); foreach (FeaturedRoom FeaturedItem in Featured.ToList()) { if (FeaturedItem == null) { continue; } RoomData Data = RavenEnvironment.GetGame().GetRoomManager().GenerateRoomData(FeaturedItem.RoomId); if (Data == null) { continue; } if (!Rooms.Contains(Data)) { Rooms.Add(Data); } } Message.WriteInteger(Rooms.Count); foreach (RoomData Data in Rooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } #endregion break; } case NavigatorCategoryType.STAFF_PICKS: { #region Featured List <RoomData> rooms = new List <RoomData>(); ICollection <StaffPick> picks = RavenEnvironment.GetGame().GetNavigator().GetStaffPicks(); foreach (StaffPick pick in picks.ToList()) { if (pick == null) { continue; } RoomData Data = RavenEnvironment.GetGame().GetRoomManager().GenerateRoomData(pick.RoomId); if (Data == null) { continue; } if (!rooms.Contains(Data)) { rooms.Add(Data); } } Message.WriteInteger(rooms.Count); foreach (RoomData data in rooms.ToList()) { RoomAppender.WriteRoom(Message, data, data.Promotion); } #endregion break; } case NavigatorCategoryType.POPULAR: { List <RoomData> PopularRooms = RavenEnvironment.GetGame().GetRoomManager().GetPopularRooms(-1, FetchLimit); Message.WriteInteger(PopularRooms.Count); foreach (RoomData Data in PopularRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.RECOMMENDED: { List <RoomData> RecommendedRooms = RavenEnvironment.GetGame().GetRoomManager().GetRecommendedRooms(FetchLimit); Message.WriteInteger(RecommendedRooms.Count); foreach (RoomData Data in RecommendedRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.CATEGORY: { List <RoomData> GetRoomsByCategory = RavenEnvironment.GetGame().GetRoomManager().GetRoomsByCategory(SearchResult.Id, FetchLimit); Message.WriteInteger(GetRoomsByCategory.Count); foreach (RoomData Data in GetRoomsByCategory.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.MY_ROOMS: Message.WriteInteger(Session.GetHabbo().UsersRooms.Count); foreach (RoomData Data in Session.GetHabbo().UsersRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MY_FAVORITES: List <RoomData> Favourites = new List <RoomData>(); foreach (int Id in Session.GetHabbo().FavoriteRooms.ToArray()) { RoomData Room = RavenEnvironment.GetGame().GetRoomManager().GenerateRoomData(Id); if (Room == null) { continue; } if (!Favourites.Contains(Room)) { Favourites.Add(Room); } } Favourites = Favourites.Take(FetchLimit).ToList(); Message.WriteInteger(Favourites.Count); foreach (RoomData Data in Favourites.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MY_GROUPS: List <RoomData> MyGroups = new List <RoomData>(); foreach (Group Group in RavenEnvironment.GetGame().GetGroupManager().GetGroupsForUser(Session.GetHabbo().Id).ToList()) { if (Group == null) { continue; } RoomData Data = RavenEnvironment.GetGame().GetRoomManager().GenerateRoomData(Group.RoomId); if (Data == null) { continue; } if (!MyGroups.Contains(Data)) { MyGroups.Add(Data); } } MyGroups = MyGroups.Take(FetchLimit).ToList(); Message.WriteInteger(MyGroups.Count); foreach (RoomData Data in MyGroups.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MY_FRIENDS_ROOMS: List <RoomData> MyFriendsRooms = new List <RoomData>(); foreach (MessengerBuddy buddy in Session.GetHabbo().GetMessenger().GetFriends().Where(p => p.InRoom)) { if (buddy == null || !buddy.InRoom || buddy.UserId == Session.GetHabbo().Id) { continue; } if (!MyFriendsRooms.Contains(buddy.CurrentRoom.RoomData)) { MyFriendsRooms.Add(buddy.CurrentRoom.RoomData); } } Message.WriteInteger(MyFriendsRooms.Count); foreach (RoomData Data in MyFriendsRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MY_RIGHTS: List <RoomData> MyRights = new List <RoomData>(); DataTable GetRights = null; using (IQueryAdapter dbClient = RavenEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT `room_id` FROM `room_rights` WHERE `user_id` = @UserId LIMIT @FetchLimit"); dbClient.AddParameter("UserId", Session.GetHabbo().Id); dbClient.AddParameter("FetchLimit", FetchLimit); GetRights = dbClient.getTable(); foreach (DataRow Row in GetRights.Rows) { RoomData Data = RavenEnvironment.GetGame().GetRoomManager().GenerateRoomData(Convert.ToInt32(Row["room_id"])); if (Data == null) { continue; } if (!MyRights.Contains(Data)) { MyRights.Add(Data); } } } Message.WriteInteger(MyRights.Count); foreach (RoomData Data in MyRights.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.TOP_PROMOTIONS: { List <RoomData> GetPopularPromotions = RavenEnvironment.GetGame().GetRoomManager().GetOnGoingRoomPromotions(16, FetchLimit); Message.WriteInteger(GetPopularPromotions.Count); foreach (RoomData Data in GetPopularPromotions.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.PROMOTION_CATEGORY: { List <RoomData> GetPromotedRooms = RavenEnvironment.GetGame().GetRoomManager().GetPromotedRooms(SearchResult.Id, FetchLimit); Message.WriteInteger(GetPromotedRooms.Count); foreach (RoomData Data in GetPromotedRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } } }
public static void Search(ServerPacket Message, SearchResultList SearchResult, string SearchData, GameClient Session, int FetchLimit) { //Switching by categorys. switch (SearchResult.CategoryType) { default: Message.WriteInteger(0); break; case NavigatorCategoryType.QUERY: { #region Query if (SearchData.ToLower().StartsWith("owner:")) { if (SearchData.Length > 0) { DataTable GetRooms = null; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor()) { if (SearchData.ToLower().StartsWith("owner:")) { dbClient.SetQuery("SELECT * FROM `rooms` WHERE `owner` = @username and `state` != 'invisible' ORDER BY `users_now` DESC"); dbClient.AddParameter("username", SearchData.Remove(0, 6)); GetRooms = dbClient.GetTable(); } } List <RoomData> Results = new List <RoomData>(); if (GetRooms != null) { foreach (DataRow Row in GetRooms.Rows) { RoomData RoomData = ButterflyEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToInt32(Row["id"]), Row); if (RoomData != null && !Results.Contains(RoomData)) { Results.Add(RoomData); } } } Message.WriteInteger(Results.Count); foreach (RoomData Data in Results.ToList()) { RoomAppender.WriteRoom(Message, Data); } } } else if (SearchData.ToLower().StartsWith("tag:")) { SearchData = SearchData.Remove(0, 4); ICollection <RoomData> TagMatches = ButterflyEnvironment.GetGame().GetRoomManager().SearchTaggedRooms(SearchData); Message.WriteInteger(TagMatches.Count); foreach (RoomData Data in TagMatches.ToList()) { RoomAppender.WriteRoom(Message, Data); } } else if (SearchData.ToLower().StartsWith("group:")) { SearchData = SearchData.Remove(0, 6); ICollection <RoomData> GroupRooms = ButterflyEnvironment.GetGame().GetRoomManager().SearchGroupRooms(SearchData); Message.WriteInteger(GroupRooms.Count); foreach (RoomData Data in GroupRooms.ToList()) { RoomAppender.WriteRoom(Message, Data); } } else { if (SearchData.Length > 0) { DataTable Table = null; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT * FROM rooms WHERE caption LIKE @query OR owner LIKE '@query' ORDER BY users_now DESC LIMIT 50"); dbClient.AddParameter("query", SearchData.Replace("%", "\\%").Replace("_", "\\_") + "%"); Table = dbClient.GetTable(); } List <RoomData> Results = new List <RoomData>(); if (Table != null) { foreach (DataRow Row in Table.Rows) { if (Convert.ToString(Row["state"]) == "invisible") { continue; } RoomData RData = ButterflyEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToInt32(Row["id"]), Row); if (RData != null && !Results.Contains(RData)) { Results.Add(RData); } } } Message.WriteInteger(Results.Count); foreach (RoomData Data in Results.ToList()) { RoomAppender.WriteRoom(Message, Data); } } } #endregion break; } case NavigatorCategoryType.FEATURED: #region Featured List <RoomData> Rooms = new List <RoomData>(); ICollection <FeaturedRoom> Featured = ButterflyEnvironment.GetGame().GetNavigator().GetFeaturedRooms(Session.Langue); foreach (FeaturedRoom FeaturedItem in Featured.ToList()) { if (FeaturedItem == null) { continue; } RoomData Data = ButterflyEnvironment.GetGame().GetRoomManager().GenerateRoomData(FeaturedItem.RoomId); if (Data == null) { continue; } if (!Rooms.Contains(Data)) { Rooms.Add(Data); } } Message.WriteInteger(Rooms.Count); foreach (RoomData Data in Rooms.ToList()) { RoomAppender.WriteRoom(Message, Data); } #endregion break; case NavigatorCategoryType.POPULAR: { List <RoomData> PopularRooms = new List <RoomData>(); //RoomData FistRoom = ButterflyEnvironment.GetGame().GetRoomManager().GenerateRoomData(5351934); //if(FistRoom != null) //PopularRooms.Add(FistRoom); PopularRooms.AddRange(ButterflyEnvironment.GetGame().GetRoomManager().GetPopularRooms(-1, 50, Session.Langue)); //FetchLimit Message.WriteInteger(PopularRooms.Count); foreach (RoomData Data in PopularRooms.ToList()) { RoomAppender.WriteRoom(Message, Data); } break; } case NavigatorCategoryType.RECOMMENDED: { List <RoomData> RecommendedRooms = ButterflyEnvironment.GetGame().GetRoomManager().GetRecommendedRooms(FetchLimit); Message.WriteInteger(RecommendedRooms.Count); foreach (RoomData Data in RecommendedRooms.ToList()) { RoomAppender.WriteRoom(Message, Data); } break; } case NavigatorCategoryType.CATEGORY: { List <RoomData> GetRoomsByCategory = ButterflyEnvironment.GetGame().GetRoomManager().GetRoomsByCategory(SearchResult.Id, FetchLimit); Message.WriteInteger(GetRoomsByCategory.Count); foreach (RoomData Data in GetRoomsByCategory.ToList()) { RoomAppender.WriteRoom(Message, Data); } break; } case NavigatorCategoryType.MY_ROOMS: Message.WriteInteger(Session.GetHabbo().UsersRooms.Count); foreach (RoomData Data in Session.GetHabbo().UsersRooms.OrderBy(a => a.Name).ToList()) { RoomAppender.WriteRoom(Message, Data); } break; case NavigatorCategoryType.MY_FAVORITES: List <RoomData> Favourites = new List <RoomData>(); foreach (RoomData Room in Session.GetHabbo().FavoriteRooms.ToArray()) { if (!Favourites.Contains(Room)) { Favourites.Add(Room); } } Favourites = Favourites.Take(FetchLimit).ToList(); Message.WriteInteger(Favourites.Count); foreach (RoomData Data in Favourites.ToList()) { RoomAppender.WriteRoom(Message, Data); } break; case NavigatorCategoryType.MY_GROUPS: List <RoomData> MyGroups = new List <RoomData>(); foreach (int GroupId in Session.GetHabbo().MyGroups.ToList()) { Group Group; if (!ButterflyEnvironment.GetGame().GetGroupManager().TryGetGroup(GroupId, out Group)) { continue; } RoomData Data = ButterflyEnvironment.GetGame().GetRoomManager().GenerateRoomData(Group.RoomId); if (Data == null) { continue; } if (!MyGroups.Contains(Data)) { MyGroups.Add(Data); } } MyGroups = MyGroups.Take(FetchLimit).ToList(); Message.WriteInteger(MyGroups.Count); foreach (RoomData Data in MyGroups.ToList()) { RoomAppender.WriteRoom(Message, Data); } break; /*case NavigatorCategoryType.MY_FRIENDS_ROOMS: * List<RoomData> MyFriendsRooms = new List<RoomData>(); * foreach (MessengerBuddy buddy in Session.GetHabbo().GetMessenger().GetFriends().Where(p => p.)) * { * if (buddy == null || !buddy.InRoom || buddy.UserId == Session.GetHabbo().Id) * continue; * * if (!MyFriendsRooms.Contains(buddy.CurrentRoom.RoomData)) * MyFriendsRooms.Add(buddy.CurrentRoom.RoomData); * } * * Message.WriteInteger(MyFriendsRooms.Count); * foreach (RoomData Data in MyFriendsRooms.ToList()) * { * RoomAppender.WriteRoom(Message, Data); * } * break;*/ case NavigatorCategoryType.MY_RIGHTS: List <RoomData> MyRights = new List <RoomData>(); foreach (RoomData Room in Session.GetHabbo().RoomRightsList.ToArray()) { if (Room == null) { continue; } if (!MyRights.Contains(Room)) { MyRights.Add(Room); } } MyRights = MyRights.Take(FetchLimit).ToList(); Message.WriteInteger(MyRights.Count); foreach (RoomData Data in MyRights.ToList()) { RoomAppender.WriteRoom(Message, Data); } break; } }
public static void Search(ServerPacket Message, SearchResultList SearchResult, string SearchData, Player Session, int FetchLimit) { //Switching by categorys. switch (SearchResult.CategoryType) { default: Message.WriteInteger(0); break; case NavigatorCategoryType.Query: { #region Query if (SearchData.ToLower().StartsWith("owner:")) { if (SearchData.Length > 0) { var UserId = 0; var Results = new List <RoomData>(); using (var dbClient = Program.DatabaseManager.GetQueryReactor()) { if (SearchData.ToLower().StartsWith("owner:")) { dbClient.SetQuery("SELECT `id` FROM `users` WHERE `username` = @username LIMIT 1"); dbClient.AddParameter("username", SearchData.Remove(0, 6)); UserId = dbClient.GetInteger(); dbClient.SetQuery("SELECT * FROM `rooms` WHERE `owner` = '" + UserId + "' and `state` != 'invisible' ORDER BY `users_now` DESC LIMIT 50"); using (var reader = dbClient.ExecuteReader()) { while (reader.Read()) { RoomData Data = null; if (!RoomFactory.TryGetData(reader.GetInt32("id"), out Data)) { continue; } if (!Results.Contains(Data)) { Results.Add(Data); } } } } } Message.WriteInteger(Results.Count); foreach (var Data in Results) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } } else if (SearchData.ToLower().StartsWith("tag:")) { SearchData = SearchData.Remove(0, 4); ICollection <Room> TagMatches = Program.GameContext.GetRoomManager().SearchTaggedRooms(SearchData); Message.WriteInteger(TagMatches.Count); foreach (RoomData Data in TagMatches.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } else if (SearchData.ToLower().StartsWith("group:")) { SearchData = SearchData.Remove(0, 6); ICollection <Room> GroupRooms = Program.GameContext.GetRoomManager().SearchGroupRooms(SearchData); Message.WriteInteger(GroupRooms.Count); foreach (RoomData Data in GroupRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } else { if (SearchData.Length > 0) { var Results = new List <RoomData>(); using (var dbClient = Program.DatabaseManager.GetQueryReactor()) { dbClient.SetQuery("SELECT `id`,`caption`,`description`,`roomtype`,`owner`,`state`,`category`,`users_now`,`users_max`,`model_name`,`score`,`allow_pets`,`allow_pets_eat`,`room_blocking_disabled`,`allow_hidewall`,`password`,`wallpaper`,`floor`,`landscape`,`floorthick`,`wallthick`,`mute_settings`,`kick_settings`,`ban_settings`,`chat_mode`,`chat_speed`,`chat_size`,`trade_settings`,`group_id`,`tags`,`push_enabled`,`pull_enabled`,`enables_enabled`,`respect_notifications_enabled`,`pet_morphs_allowed`,`spush_enabled`,`spull_enabled` FROM rooms WHERE `caption` LIKE @query ORDER BY `users_now` DESC LIMIT 50"); dbClient.AddParameter("query", "%" + SearchData + "%"); using (var reader = dbClient.ExecuteReader()) { while (reader.Read()) { if (reader.GetString("state") == "invisible") { continue; } if (RoomFactory.TryGetData(reader.GetInt32("id"), out var Data) && !Results.Contains(Data)) { Results.Add(Data); } } } } Message.WriteInteger(Results.Count); foreach (var Data in Results) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } } } #endregion break; } case NavigatorCategoryType.Featured: #region Featured var Rooms = new List <RoomData>(); var Featured = Program.GameContext.GetNavigator().GetFeaturedRooms(); foreach (var FeaturedItem in Featured.ToList()) { if (FeaturedItem == null) { continue; } if (!RoomFactory.TryGetData(FeaturedItem.RoomId, out var Data)) { continue; } if (!Rooms.Contains(Data)) { Rooms.Add(Data); } } Message.WriteInteger(Rooms.Count); foreach (var Data in Rooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } #endregion break; case NavigatorCategoryType.Popular: { var PopularRooms = Program.GameContext.GetRoomManager().GetPopularRooms(-1, FetchLimit); Message.WriteInteger(PopularRooms.Count); foreach (RoomData Data in PopularRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.Recommended: { var RecommendedRooms = Program.GameContext.GetRoomManager().GetRecommendedRooms(FetchLimit); Message.WriteInteger(RecommendedRooms.Count); foreach (RoomData Data in RecommendedRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.Category: { var GetRoomsByCategory = Program.GameContext.GetRoomManager().GetRoomsByCategory(SearchResult.Id, FetchLimit); Message.WriteInteger(GetRoomsByCategory.Count); foreach (RoomData Data in GetRoomsByCategory.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.MyRooms: ICollection <RoomData> rooms = RoomFactory.GetRoomsDataByOwnerSortByName(Session.GetHabbo().Id).OrderByDescending(x => x.UsersNow).ToList(); Message.WriteInteger(rooms.Count); foreach (var Data in rooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MyFavourites: var Favourites = new List <RoomData>(); foreach (int Id in Session.GetHabbo().FavoriteRooms.ToArray()) { RoomData Room = null; if (!RoomFactory.TryGetData(Id, out Room)) { continue; } if (!Favourites.Contains(Room)) { Favourites.Add(Room); } } Favourites = Favourites.Take(FetchLimit).ToList(); Message.WriteInteger(Favourites.Count); foreach (var Data in Favourites.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MyGroups: var MyGroups = new List <RoomData>(); foreach (var Group in Program.GameContext.GetGroupManager().GetGroupsForUser(Session.GetHabbo().Id).ToList()) { if (Group == null) { continue; } RoomData Data = null; if (!RoomFactory.TryGetData(Group.RoomId, out Data)) { continue; } if (!MyGroups.Contains(Data)) { MyGroups.Add(Data); } } MyGroups = MyGroups.Take(FetchLimit).ToList(); Message.WriteInteger(MyGroups.Count); foreach (var Data in MyGroups.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MyFriendsRooms: var MyFriendsRooms = new List <RoomData>(); foreach (var buddy in Session.GetHabbo().GetMessenger().GetFriends().Where(p => p.InRoom)) { if (buddy == null || !buddy.InRoom || buddy.UserId == Session.GetHabbo().Id) { continue; } if (!MyFriendsRooms.Contains(buddy.CurrentRoom)) { MyFriendsRooms.Add(buddy.CurrentRoom); } } Message.WriteInteger(MyFriendsRooms.Count); foreach (var Data in MyFriendsRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.MyRights: var MyRights = new List <RoomData>(); using (var dbClient = Program.DatabaseManager.GetQueryReactor()) { dbClient.SetQuery("SELECT `room_id` FROM `room_rights` WHERE `user_id` = @UserId LIMIT @FetchLimit"); dbClient.AddParameter("UserId", Session.GetHabbo().Id); dbClient.AddParameter("FetchLimit", FetchLimit); using (var reader = dbClient.ExecuteReader()) { while (reader.Read()) { RoomData Data = null; if (!RoomFactory.TryGetData(reader.GetInt32("room_id"), out Data)) { continue; } if (!MyRights.Contains(Data)) { MyRights.Add(Data); } } } } Message.WriteInteger(MyRights.Count); foreach (var Data in MyRights) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; case NavigatorCategoryType.TopPromotions: { var GetPopularPromotions = Program.GameContext.GetRoomManager().GetOnGoingRoomPromotions(16, FetchLimit); Message.WriteInteger(GetPopularPromotions.Count); foreach (RoomData Data in GetPopularPromotions.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } case NavigatorCategoryType.PromotionCategory: { var GetPromotedRooms = Program.GameContext.GetRoomManager().GetPromotedRooms(SearchResult.Id, FetchLimit); Message.WriteInteger(GetPromotedRooms.Count); foreach (RoomData Data in GetPromotedRooms.ToList()) { RoomAppender.WriteRoom(Message, Data, Data.Promotion); } break; } } }