Exemple #1
0
 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(Yupi.GetGroupDateJoinString(member.DateJoin));
 }
Exemple #2
0
        /// <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}'");
            }
        }
Exemple #3
0
        /// <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;
            }
        }
Exemple #4
0
        /// <summary>
        ///     Joins the group.
        /// </summary>
        internal void JoinGroup()
        {
            uint groupId = Request.GetUInteger();

            Group group = Yupi.GetGame().GetGroupManager().GetGroup(groupId);
            Habbo user = Session.GetHabbo();

            if (!group.Members.ContainsKey(user.Id))
            {
                if (group.State == 0)
                {
                    using (IQueryAdapter commitableQueryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                    {
                        commitableQueryReactor.RunFastQuery(
                            string.Concat("INSERT INTO groups_members (user_id, group_id, date_join) VALUES (", user.Id,
                                ",", groupId, ",", Yupi.GetUnixTimeStamp(), ")"));
                        commitableQueryReactor.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, Yupi.GetUnixTimeStamp()));

                    Session.GetHabbo().UserGroups.Add(group.Members[user.Id]);
                }
                else
                {
                    if (!group.Requests.ContainsKey(user.Id))
                    {
                        using (IQueryAdapter queryreactor2 = Yupi.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,
                            Yupi.GetUnixTimeStamp());

                        group.Requests.Add(user.Id, groupRequest);
                    }
                }

                Yupi.GetGame().GetGroupManager().SerializeGroupInfo(group, Response, Session);
            }
        }