/// <summary> /// Composes the specified session. /// </summary> /// <param name="group"></param> /// <param name="groupForum"></param> /// <param name="requesterId"></param> /// <returns>ServerMessage.</returns> internal static ServerMessage Compose(Group group, GroupForum groupForum, uint requesterId) { string string1 = string.Empty, string2 = string.Empty, string3 = string.Empty, string4 = string.Empty; ServerMessage message = new ServerMessage(LibraryParser.OutgoingRequest("GroupForumDataMessageComposer")); message.AppendInteger(group.Id); message.AppendString(group.Name); message.AppendString(group.Description); message.AppendString(group.Badge); message.AppendInteger(0); message.AppendInteger(0); message.AppendInteger(groupForum.ForumMessagesCount); message.AppendInteger(0); message.AppendInteger(0); message.AppendInteger(groupForum.ForumLastPosterId); message.AppendString(groupForum.ForumLastPosterName); message.AppendInteger(groupForum.ForumLastPostTime); message.AppendInteger(groupForum.WhoCanRead); message.AppendInteger(groupForum.WhoCanPost); message.AppendInteger(groupForum.WhoCanThread); message.AppendInteger(groupForum.WhoCanMod); if (groupForum.WhoCanRead == 1 && !group.Members.ContainsKey(requesterId)) string1 = "not_member"; if (groupForum.WhoCanRead == 2 && !group.Admins.ContainsKey(requesterId)) string1 = "not_admin"; if (groupForum.WhoCanPost == 1 && !group.Members.ContainsKey(requesterId)) string2 = "not_member"; if (groupForum.WhoCanPost == 2 && !group.Admins.ContainsKey(requesterId)) string2 = "not_admin"; if (groupForum.WhoCanPost == 3 && requesterId != group.CreatorId) string2 = "not_owner"; if (groupForum.WhoCanThread == 1 && !group.Members.ContainsKey(requesterId)) string3 = "not_member"; if (groupForum.WhoCanThread == 2 && !group.Admins.ContainsKey(requesterId)) string3 = "not_admin"; if (groupForum.WhoCanThread == 3 && requesterId != group.CreatorId) string3 = "not_owner"; if (groupForum.WhoCanMod == 2 && !group.Admins.ContainsKey(requesterId)) string4 = "not_admin"; if (groupForum.WhoCanMod == 3 && requesterId != group.CreatorId) string4 = "not_owner"; message.AppendString(string1); message.AppendString(string2); message.AppendString(string3); message.AppendString(string4); message.AppendString(string.Empty); message.AppendBool(requesterId == group.CreatorId); message.AppendBool(true); return message; }
/// <summary> /// Composes the specified session. /// </summary> /// <param name="message"></param> /// <param name="group"></param> /// <param name="groupForum"></param> /// <returns>ServerMessage.</returns> internal static ServerMessage Compose(ServerMessage message, Group group, GroupForum groupForum) { message.AppendInteger(group.Id); message.AppendString(group.Name); message.AppendString(string.Empty); message.AppendString(group.Badge); message.AppendInteger(0); message.AppendInteger((int)Math.Round(groupForum.ForumScore)); message.AppendInteger(groupForum.ForumMessagesCount); message.AppendInteger(0); message.AppendInteger(0); message.AppendInteger(groupForum.ForumLastPosterId); message.AppendString(groupForum.ForumLastPosterName); message.AppendInteger(groupForum.ForumLastPostTime); return message; }
/// <summary> /// Serializes the theGroup information. /// </summary> /// <param name="group">The theGroup.</param> /// <param name="response">The response.</param> /// <param name="session">The session.</param> /// <param name="room">The room.</param> /// <param name="newWindow">if set to <c>true</c> [new window].</param> internal void SerializeGroupInfo(Group group, ServerMessage response, GameClient session, Room room, bool newWindow = false) { if (room == null || group == null) return; DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime dateTime2 = dateTime.AddSeconds(group.CreateTime); response.Init(LibraryParser.OutgoingRequest("GroupDataMessageComposer")); response.AppendInteger(group.Id); response.AppendBool(true); response.AppendInteger(group.State); response.AppendString(group.Name); response.AppendString(group.Description); response.AppendString(group.Badge); response.AppendInteger(group.RoomId); response.AppendString(Yupi.GetGame().GetRoomManager().GenerateRoomData(@group.RoomId) == null ? "No room found.." : Yupi.GetGame().GetRoomManager().GenerateRoomData(group.RoomId).Name); response.AppendInteger(@group.CreatorId == session.GetHabbo().Id ? 3 : (group.Requests.ContainsKey(session.GetHabbo().Id) ? 2 : (group.Members.ContainsKey(session.GetHabbo().Id) ? 1 : 0))); response.AppendInteger(group.Members.Count); response.AppendBool(session.GetHabbo().FavouriteGroup == group.Id); response.AppendString($"{dateTime2.Day.ToString("00")}-{dateTime2.Month.ToString("00")}-{dateTime2.Year}"); response.AppendBool(group.CreatorId == session.GetHabbo().Id); response.AppendBool(group.Admins.ContainsKey(session.GetHabbo().Id)); response.AppendString(Yupi.GetHabboById(@group.CreatorId) == null ? string.Empty : Yupi.GetHabboById(group.CreatorId).UserName); response.AppendBool(newWindow); response.AppendBool(group.AdminOnlyDeco == 0u); response.AppendInteger(group.Requests.Count); response.AppendBool(group.Forum.Id != 0); room.SendMessage(response); }
/// <summary> /// Gets the theGroup requests by string. /// </summary> /// <param name="theGroup">The theGroup.</param> /// <param name="searchVal">The search value.</param> /// <returns>List<System.UInt32>.</returns> internal List<GroupMember> GetGroupRequestsByString(Group theGroup, string searchVal) => string.IsNullOrWhiteSpace(searchVal) ? theGroup.Requests.Values.ToList() : theGroup.Requests.Values.Where(request => request.Name.ToLower().Contains(searchVal.ToLower())) .ToList();
/// <summary> /// Gets the theGroup users by string. /// </summary> /// <param name="theGroup">The theGroup.</param> /// <param name="searchVal">The search value.</param> /// <param name="req">The req.</param> /// <returns>List<GroupUser>.</returns> internal List<GroupMember> GetGroupUsersByString(Group theGroup, string searchVal, uint req) { List<GroupMember> list = new List<GroupMember>(); switch (req) { case 0: list = theGroup.Members.Values.ToList(); break; case 1: list = theGroup.Admins.Values.ToList(); break; case 2: list = GetGroupRequestsByString(theGroup, searchVal); break; } if (!string.IsNullOrWhiteSpace(searchVal)) list = list.Where(member => member.Name.ToLower().Contains(searchVal.ToLower())).ToList(); return list; }
/// <summary> /// Serializes the theGroup members. /// </summary> /// <param name="response">The response.</param> /// <param name="theGroup">The theGroup.</param> /// <param name="reqType">Type of the req.</param> /// <param name="session">The session.</param> /// <param name="searchVal">The search value.</param> /// <param name="page">The page.</param> /// <returns>ServerMessage.</returns> internal ServerMessage SerializeGroupMembers(ServerMessage response, Group theGroup, uint reqType, GameClient session, string searchVal = "", int page = 0) { if (theGroup == null || session == null) return null; if (page < 1) page = 0; response.AppendInteger(theGroup.Id); response.AppendString(theGroup.Name); response.AppendInteger(theGroup.RoomId); response.AppendString(theGroup.Badge); List<GroupMember> groupList = GetGroupUsersByString(theGroup, searchVal, reqType); if(groupList != null) { List<List<GroupMember>> list = Split(groupList); if(list != null) { if (reqType == 0) { response.AppendInteger(list.Count); if (theGroup.Members.Count > 0 && list.Count > 0 && list[page] != null) { response.AppendInteger(list[page].Count); using (List<GroupMember>.Enumerator enumerator = list[page].GetEnumerator()) { while (enumerator.MoveNext()) { GroupMember current = enumerator.Current; AddGroupMemberIntoResponse(response, current); } } } else response.AppendInteger(0); } else if (reqType == 1) { response.AppendInteger(theGroup.Admins.Count); List<GroupMember> paging = page <= list.Count ? list[page] : null; if ((theGroup.Admins.Count > 0) && (list.Count > 0) && paging != null) { response.AppendInteger(list[page].Count); using (List<GroupMember>.Enumerator enumerator = list[page].GetEnumerator()) { while (enumerator.MoveNext()) { GroupMember current = enumerator.Current; AddGroupMemberIntoResponse(response, current); } } } else response.AppendInteger(0); } else if (reqType == 2) { response.AppendInteger(theGroup.Requests.Count); if (theGroup.Requests.Count > 0 && list.Count > 0 && list[page] != null) { response.AppendInteger(list[page].Count); using (List<GroupMember>.Enumerator enumerator = list[page].GetEnumerator()) { while (enumerator.MoveNext()) { GroupMember current = enumerator.Current; response.AppendInteger(3); if (current != null) { response.AppendInteger(current.Id); response.AppendString(current.Name); response.AppendString(current.Look); } response.AppendString(string.Empty); } } } else response.AppendInteger(0); } } else response.AppendInteger(0); } else response.AppendInteger(0); response.AppendBool(session.GetHabbo().Id == theGroup.CreatorId); response.AppendInteger(14); response.AppendInteger(page); response.AppendInteger(reqType); response.AppendString(searchVal); return response; }
/// <summary> /// Gets the theGroup. /// </summary> /// <param name="groupId">The theGroup identifier.</param> /// <returns>Guild.</returns> internal Group GetGroup(uint groupId) { if (Groups == null) return null; if (Groups.Contains(groupId)) return (Group) Groups[groupId]; Dictionary<uint, GroupMember> members = new Dictionary<uint, GroupMember>(); Dictionary<uint, GroupMember> admins = new Dictionary<uint, GroupMember>(); Dictionary<uint, GroupMember> requests = new Dictionary<uint, GroupMember>(); using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery($"SELECT * FROM groups_data WHERE id ='{groupId}' LIMIT 1"); DataRow row = queryReactor.GetRow(); if (row == null) return null; queryReactor.SetQuery($"SELECT * FROM groups_forums_data WHERE group_id='{groupId}' LIMIT 1"); DataRow row2 = queryReactor.GetRow(); GroupForum groupForum; if (row2 == null) groupForum = new GroupForum(0, string.Empty, string.Empty, 0, 0, 0, string.Empty, 0, 0, 1, 1, 2); else groupForum = new GroupForum((uint) row2["id"], row2["forum_name"].ToString(), row2["forum_description"].ToString(), (uint) row2["forum_messages_count"], double.Parse(row2["forum_score"].ToString()), (uint) row2["forum_lastposter_id"], row2["forum_lastposter_name"].ToString(), (uint) row2["forum_lastposter_timestamp"], (uint) row2["who_can_read"], (uint) row2["who_can_post"], (uint) row2["who_can_thread"], (uint) row2["who_can_mod"]); queryReactor.SetQuery( "SELECT g.user_id, u.username, u.look, g.rank, g.date_join FROM groups_members g " + $"INNER JOIN users u ON (g.user_id = u.id) WHERE g.group_id='{groupId}'"); DataTable groupMembersTable = queryReactor.GetTable(); queryReactor.SetQuery("SELECT g.user_id, u.username, u.look FROM groups_requests g " + $"INNER JOIN users u ON (g.user_id = u.id) WHERE group_id='{groupId}'"); DataTable groupRequestsTable = queryReactor.GetTable(); uint userId; foreach (DataRow dataRow in groupMembersTable.Rows) { userId = (uint) dataRow["user_id"]; int rank = int.Parse(dataRow["rank"].ToString()); GroupMember membGroup = new GroupMember(userId, dataRow["username"].ToString(), dataRow["look"].ToString(), groupId, rank, (int) dataRow["date_join"]); members.Add(userId, membGroup); if (rank >= 1) admins.Add(userId, membGroup); } foreach (DataRow dataRow in groupRequestsTable.Rows) { userId = (uint) dataRow["user_id"]; GroupMember membGroup = new GroupMember(userId, dataRow["username"].ToString(), dataRow["look"].ToString(), groupId, 0, Yupi.GetUnixTimeStamp()); if (!requests.ContainsKey(userId)) requests.Add(userId, membGroup); } Group group = new Group((uint) row["id"], row["group_name"].ToString(), row["group_description"].ToString(), (uint) row["room_id"], row["group_badge"].ToString(), (int) row["created"], (uint) row["owner_id"], (int) row["colour1"], (int) row["colour2"], members, requests, admins, Convert.ToUInt16(row["state"]), Convert.ToUInt16(row["admindeco"]), groupForum); Groups.Add((uint) row["id"], group); return group; } }
/// <summary> /// Creates the theGroup. /// </summary> /// <param name="name">The name.</param> /// <param name="desc">The desc.</param> /// <param name="roomId">The room identifier.</param> /// <param name="badge">The badge.</param> /// <param name="session">The session.</param> /// <param name="colour1">The colour1.</param> /// <param name="colour2">The colour2.</param> /// <param name="group">The theGroup.</param> internal void CreateGroup(string name, string desc, uint roomId, string badge, GameClient session, int colour1, int colour2, out Group group) { Habbo user = session.GetHabbo(); Dictionary<uint, GroupMember> emptyDictionary = new Dictionary<uint, GroupMember>(); using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery( $"INSERT INTO groups_data (group_name, group_description, group_badge, owner_id, created, room_id, colour1, colour2) VALUES(@name,@desc,@badge,'{session.GetHabbo().Id}',UNIX_TIMESTAMP(),'{roomId}','{colour1}','{colour2}')"); queryReactor.AddParameter("name", name); queryReactor.AddParameter("desc", desc); queryReactor.AddParameter("badge", badge); uint id = (uint) queryReactor.InsertQuery(); queryReactor.RunFastQuery($"UPDATE rooms_data SET group_id='{id}' WHERE id='{roomId}' LIMIT 1"); GroupMember memberGroup = new GroupMember(user.Id, user.UserName, user.Look, id, 2, Yupi.GetUnixTimeStamp()); Dictionary<uint, GroupMember> dictionary = new Dictionary<uint, GroupMember> {{session.GetHabbo().Id, memberGroup}}; group = new Group(id, name, desc, roomId, badge, Yupi.GetUnixTimeStamp(), user.Id, colour1, colour2, dictionary, emptyDictionary, emptyDictionary, 0, 1, new GroupForum(0, string.Empty, string.Empty, 0, 0, 0, string.Empty, 0, 0, 1, 1, 2)); Groups.Add(id, group); queryReactor.RunFastQuery( $"INSERT INTO groups_members (group_id, user_id, rank, date_join) VALUES ('{id}','{session.GetHabbo().Id}','2','{Yupi.GetUnixTimeStamp()}')"); Room room = Yupi.GetGame().GetRoomManager().GetRoom(roomId); if (room != null) { room.RoomData.Group = group; room.RoomData.GroupId = id; } user.UserGroups.Add(memberGroup); group.Admins.Add(user.Id, memberGroup); queryReactor.RunFastQuery( $"UPDATE users_stats SET favourite_group='{id}' WHERE id='{user.Id}' LIMIT 1"); queryReactor.RunFastQuery($"DELETE FROM rooms_rights WHERE room_id='{roomId}'"); } }
/// <summary> /// Fills the specified row. /// </summary> /// <param name="row">The row.</param> internal void Fill(DataRow row) { try { Id = (uint) row["id"]; Name = (string) row["caption"]; PassWord = (string) row["password"]; Description = (string) row["description"]; Type = (string) row["roomtype"]; Owner = string.Empty; OwnerId = (uint) row["owner"]; RoomChat = new ConcurrentStack<Chatlog>(); WordFilter = new List<string>(); using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery("SELECT username FROM users WHERE id = @userId"); queryReactor.AddParameter("userId", OwnerId); Owner = queryReactor.GetString(); queryReactor.SetQuery($"SELECT user_id, message, timestamp FROM users_chatlogs WHERE room_id = '{Id}' ORDER BY timestamp ASC LIMIT 150"); DataTable table = queryReactor.GetTable(); foreach (DataRow dataRow in table.Rows) RoomChat.Push(new Chatlog((uint) dataRow[0], (string) dataRow[1], Yupi.UnixToDateTime(int.Parse(dataRow[2].ToString())), false)); queryReactor.SetQuery($"SELECT word FROM rooms_wordfilter WHERE room_id = '{Id}'"); DataTable tableFilter = queryReactor.GetTable(); foreach (DataRow dataRow in tableFilter.Rows) WordFilter.Add(dataRow["word"].ToString()); } string roomState = row["state"].ToString().ToLower(); switch (roomState) { case "locked": State = 1; break; case "password": State = 2; break; default: State = 0; break; } ModelName = (string) row["model_name"]; WallPaper = (string) row["wallpaper"]; Floor = (string) row["floor"]; LandScape = (string) row["landscape"]; CcTs = (string) row["public_ccts"]; int.TryParse(row["trade_state"].ToString(), out TradeState); int.TryParse(row["category"].ToString(), out Category); int.TryParse(row["walls_height"].ToString(), out WallHeight); int.TryParse(row["score"].ToString(), out Score); int.TryParse(row["floorthick"].ToString(), out FloorThickness); int.TryParse(row["wallthick"].ToString(), out WallThickness); int.TryParse(row["chat_type"].ToString(), out ChatType); int.TryParse(row["game_id"].ToString(), out GameId); int.TryParse(row["mute_settings"].ToString(), out WhoCanMute); int.TryParse(row["kick_settings"].ToString(), out WhoCanKick); int.TryParse(row["ban_settings"].ToString(), out WhoCanBan); uint.TryParse(row["users_now"].ToString(), out UsersNow); uint.TryParse(row["users_max"].ToString(), out UsersMax); uint.TryParse(row["group_id"].ToString(), out GroupId); uint.TryParse(row["chat_balloon"].ToString(), out ChatBalloon); uint.TryParse(row["chat_speed"].ToString(), out ChatSpeed); uint.TryParse(row["chat_max_distance"].ToString(), out ChatMaxDistance); uint.TryParse(row["chat_flood_protection"].ToString(), out ChatFloodProtection); AllowPets = Yupi.EnumToBool(row["allow_pets"].ToString()); AllowPetsEating = Yupi.EnumToBool(row["allow_pets_eat"].ToString()); AllowWalkThrough = Yupi.EnumToBool(row["allow_walkthrough"].ToString()); HideWall = Yupi.EnumToBool(row["hidewall"].ToString()); AllowRightsOverride = false; Group = Yupi.GetGame().GetGroupManager().GetGroup(GroupId); Event = Yupi.GetGame().GetRoomEvents().GetEvent(Id); _model = Yupi.GetGame().GetRoomManager().GetModel(ModelName, Id); CompetitionStatus = 0; Tags = new List<string>(); if (row.IsNull("tags") || string.IsNullOrEmpty(row["tags"].ToString())) return; foreach (string item in row["tags"].ToString().Split(',')) Tags.Add(item); } catch (Exception ex) { ServerLogManager.LogException(ex, "Yupi.Game.Rooms.RoomData.Fill"); } }
/// <summary> /// Fills the null. /// </summary> /// <param name="id">The identifier.</param> internal void FillNull(uint id) { Id = id; Name = "Unknown Room"; Description = "-"; Type = "private"; Owner = "-"; Category = 0; UsersNow = 0; UsersMax = 0; ModelName = "NO_MODEL"; CcTs = string.Empty; Score = 0; Tags = new List<string>(); AllowPets = true; AllowPetsEating = false; AllowWalkThrough = true; HideWall = false; PassWord = string.Empty; WallPaper = "0.0"; Floor = "0.0"; LandScape = "0.0"; WallThickness = 0; FloorThickness = 0; Group = null; AllowRightsOverride = false; Event = null; GameId = 0; WhoCanBan = 0; WhoCanKick = 0; WhoCanMute = 0; TradeState = 2; State = 0; RoomChat = new ConcurrentStack<Chatlog>(); WordFilter = new List<string>(); WallHeight = -1; _model = Yupi.GetGame().GetRoomManager().GetModel(ModelName, Id); CompetitionStatus = 0; }
/// <summary> /// Gets the theGroup users by string. /// </summary> /// <param name="theGroup">The theGroup.</param> /// <param name="searchVal">The search value.</param> /// <param name="req">The req.</param> /// <returns>List<GroupUser>.</returns> internal List<GroupMember> GetGroupUsersByString(Group theGroup, string searchVal, uint req) { List<GroupMember> list = new List<GroupMember>(); switch (req) { case 0: using (Dictionary<uint, GroupMember>.ValueCollection.Enumerator enumerator = theGroup.Members.Values.GetEnumerator()) while (enumerator.MoveNext()) list.Add(enumerator.Current); break; case 1: using (Dictionary<uint, GroupMember>.ValueCollection.Enumerator enumerator2 = theGroup.Admins.Values.GetEnumerator()) while (enumerator2.MoveNext()) list.Add(enumerator2.Current); break; case 2: list = GetGroupRequestsByString(theGroup, searchVal); break; } if (!string.IsNullOrWhiteSpace(searchVal)) list = list.Where(member => member.Name.ToLower().Contains(searchVal.ToLower())).ToList(); return list; }