/// <summary> /// Joins the group. /// </summary> internal void JoinGroup() { uint groupId = Request.GetUInteger(); Guild group = Azure.GetGame().GetGroupManager().GetGroup(groupId); Habbo user = Session.GetHabbo(); if (!group.Members.ContainsKey(user.Id)) { if (group.State == 0) { using (IQueryAdapter queryReactor = Azure.GetDatabaseManager().GetQueryReactor()) { queryReactor.RunFastQuery(string.Concat("INSERT INTO groups_members (user_id, group_id, date_join) VALUES (", user.Id, ",", groupId, ",", Azure.GetUnixTimeStamp(), ")")); queryReactor.RunFastQuery(string.Concat("UPDATE users_stats SET favourite_group=", groupId, " WHERE id= ", user.Id, " LIMIT 1")); } group.Members.Add(user.Id, new GroupMember(user.Id, user.UserName, user.Look, group.Id, 0, Azure.GetUnixTimeStamp())); Session.GetHabbo().UserGroups.Add(group.Members[user.Id]); } else { if (!group.Requests.ContainsKey(user.Id)) { using (IQueryAdapter queryreactor2 = Azure.GetDatabaseManager().GetQueryReactor()) queryreactor2.RunFastQuery(string.Concat("INSERT INTO groups_requests (user_id, group_id) VALUES (", Session.GetHabbo().Id, ",", groupId, ")")); GroupMember groupRequest = new GroupMember(user.Id, user.UserName, user.Look, group.Id, 0, Azure.GetUnixTimeStamp()); group.Requests.Add(user.Id, groupRequest); } } Azure.GetGame().GetGroupManager().SerializeGroupInfo(group, Response, Session); } }
/// <summary> /// Gets the theGroup. /// </summary> /// <param name="groupId">The theGroup identifier.</param> /// <returns>Guild.</returns> internal Guild GetGroup(uint groupId) { if (Groups == null) return null; if (Groups.Contains(groupId)) return (Guild)Groups[groupId]; var members = new Dictionary<uint, GroupMember>(); var admins = new Dictionary<uint, GroupMember>(); var requests = new Dictionary<uint, GroupMember>(); using (var queryReactor = Azure.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery($"SELECT * FROM groups_data WHERE id={groupId} LIMIT 1"); var row = queryReactor.GetRow(); if (row == null) return null; 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}"); var 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}"); var groupRequestsTable = queryReactor.GetTable(); uint userId; foreach (DataRow dataRow in groupMembersTable.Rows) { userId = (uint)dataRow["user_id"]; var rank = int.Parse(dataRow["rank"].ToString()); var 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"]; var membGroup = new GroupMember(userId, dataRow["username"].ToString(), dataRow["look"].ToString(), groupId, 0, Azure.GetUnixTimeStamp()); if (!requests.ContainsKey(userId)) requests.Add(userId, membGroup); } var group = new Guild((uint)row[0], row[1].ToString(), row[2].ToString(), (uint)row[6], row[3].ToString(), (int)row[5], (uint)row[4], (int)row[8], (int)row[9], members, requests, admins, Convert.ToUInt16(row[7]), Convert.ToUInt16(row[10]), row["has_forum"].ToString() == "1", row["forum_name"].ToString(), row["forum_description"].ToString(), uint.Parse(row["forum_messages_count"].ToString()), double.Parse(row["forum_score"].ToString()), uint.Parse(row["forum_lastposter_id"].ToString()), row["forum_lastposter_name"].ToString(), int.Parse(row["forum_lastposter_timestamp"].ToString()), (int)row["who_can_read"], (int)row["who_can_post"], (int)row["who_can_thread"], (int)row["who_can_mod"]); Groups.Add((uint)row[0], group); return group; } }
internal void AddGroupMemberIntoResponse(ServerMessage response, GroupMember member) { response.AppendInteger(member.Rank == 2 ? 0 : member.Rank == 1 ? 1 : 2); response.AppendInteger(member.Id); response.AppendString(member.Name); response.AppendString(member.Look); response.AppendString(Azure.GetGroupDateJoinString(member.DateJoin)); }
/// <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 Guild group) { Habbo user = session.GetHabbo(); Dictionary<uint, GroupMember> emptyDictionary = new Dictionary<uint, GroupMember>(); using (var queryReactor = Azure.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery($"INSERT INTO groups_data (`name`, `desc`,`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); var 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, Azure.GetUnixTimeStamp()); Dictionary<uint, GroupMember> dictionary = new Dictionary<uint, GroupMember> {{ session.GetHabbo().Id, memberGroup }}; group = new Guild(id, name, desc, roomId, badge, Azure.GetUnixTimeStamp(), user.Id, colour1, colour2, dictionary, emptyDictionary, emptyDictionary, 0, 1, false, name, desc, 0, 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','{Azure.GetUnixTimeStamp()}')"); var room = Azure.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}'"); } }