示例#1
0
        /// <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;
        }
示例#2
0
        /// <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;
        }
示例#3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Group" /> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <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="create">The create.</param>
 /// <param name="creator">The creator.</param>
 /// <param name="colour1">The colour1.</param>
 /// <param name="colour2">The colour2.</param>
 /// <param name="members">The members.</param>
 /// <param name="requests">The requests.</param>
 /// <param name="admins">The admins.</param>
 /// <param name="state">The state.</param>
 /// <param name="adminOnlyDeco">The admin only deco.</param>
 /// <param name="forum"></param>
 internal Group(uint id, string name, string desc, uint roomId, string badge, int create, uint creator,
                int colour1, int colour2, Dictionary <uint, GroupMember> members, Dictionary <uint, GroupMember> requests,
                Dictionary <uint, GroupMember> admins, uint state, uint adminOnlyDeco, GroupForum forum)
 {
     Id            = id;
     Name          = name;
     Description   = desc;
     RoomId        = roomId;
     Badge         = badge;
     CreateTime    = create;
     CreatorId     = creator;
     Colour1       = colour1 == 0 ? 1 : colour1;
     Colour2       = colour2 == 0 ? 1 : colour2;
     Members       = members;
     Requests      = requests;
     Admins        = admins;
     State         = state;
     AdminOnlyDeco = adminOnlyDeco;
     Forum         = forum;
 }
示例#4
0
        internal void CreateForum()
        {
            using (IQueryAdapter adapter = Yupi.GetDatabaseManager().GetQueryReactor())
            {
                adapter.SetQuery(
                    "INSERT INTO groups_forums_data (group_id, forum_name, forum_description, forum_messages_count, forum_score, forum_lastposter_id, forum_lastposter_name, forum_lastposter_timestamp) " +
                    $"VALUES ('{Id}', @name, @desc, @msgcount, @score, @lastposterid, @lastpostername, @lasttimestamp)");
                adapter.AddParameter("name", Forum.ForumName);
                adapter.AddParameter("desc", Forum.ForumDescription);
                adapter.AddParameter("msgcount", Forum.ForumMessagesCount);
                adapter.AddParameter("score", Forum.ForumScore.ToString(CultureInfo.InvariantCulture));
                adapter.AddParameter("lastposterid", Forum.ForumLastPosterId);
                adapter.AddParameter("lastpostername", Forum.ForumLastPosterName);
                adapter.AddParameter("lasttimestamp", Forum.ForumLastPosterTimestamp);

                adapter.RunQuery();

                adapter.SetQuery($"SELECT * FROM groups_forums_data WHERE group_id='{Id}' LIMIT 1");

                DataRow row2 = adapter.GetRow();

                if (row2 == null)
                {
                    Forum = new GroupForum(0, Forum.ForumName, Forum.ForumDescription, Forum.ForumMessagesCount, 0, 0,
                                           string.Empty, 0, 0, 1, 1, 2);
                }
                else
                {
                    Forum = 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"]);
                }
            }
        }
示例#5
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;
            }
        }
示例#6
0
文件: Group.cs 项目: weslley17w/Yupi
        internal void CreateForum()
        {
            using (IQueryAdapter adapter = Yupi.GetDatabaseManager().GetQueryReactor())
            {
                adapter.SetQuery(
                    "INSERT INTO groups_forums_data (group_id, forum_name, forum_description, forum_messages_count, forum_score, forum_lastposter_id, forum_lastposter_name, forum_lastposter_timestamp) " +
                    $"VALUES ('{Id}', @name, @desc, @msgcount, @score, @lastposterid, @lastpostername, @lasttimestamp)");
                adapter.AddParameter("name", Forum.ForumName);
                adapter.AddParameter("desc", Forum.ForumDescription);
                adapter.AddParameter("msgcount", Forum.ForumMessagesCount);
                adapter.AddParameter("score", Forum.ForumScore.ToString(CultureInfo.InvariantCulture));
                adapter.AddParameter("lastposterid", Forum.ForumLastPosterId);
                adapter.AddParameter("lastpostername", Forum.ForumLastPosterName);
                adapter.AddParameter("lasttimestamp", Forum.ForumLastPosterTimestamp);

                adapter.RunQuery();

                adapter.SetQuery($"SELECT * FROM groups_forums_data WHERE group_id='{Id}' LIMIT 1");

                DataRow row2 = adapter.GetRow();

                if (row2 == null)
                    Forum = new GroupForum(0, Forum.ForumName, Forum.ForumDescription, Forum.ForumMessagesCount, 0, 0,
                        string.Empty, 0, 0, 1, 1, 2);
                else
                    Forum = 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"]);
            }
        }
示例#7
0
文件: Group.cs 项目: weslley17w/Yupi
 /// <summary>
 ///     Initializes a new instance of the <see cref="Group" /> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <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="create">The create.</param>
 /// <param name="creator">The creator.</param>
 /// <param name="colour1">The colour1.</param>
 /// <param name="colour2">The colour2.</param>
 /// <param name="members">The members.</param>
 /// <param name="requests">The requests.</param>
 /// <param name="admins">The admins.</param>
 /// <param name="state">The state.</param>
 /// <param name="adminOnlyDeco">The admin only deco.</param>
 /// <param name="forum"></param>
 internal Group(uint id, string name, string desc, uint roomId, string badge, int create, uint creator,
     int colour1, int colour2, Dictionary<uint, GroupMember> members, Dictionary<uint, GroupMember> requests,
     Dictionary<uint, GroupMember> admins, uint state, uint adminOnlyDeco, GroupForum forum)
 {
     Id = id;
     Name = name;
     Description = desc;
     RoomId = roomId;
     Badge = badge;
     CreateTime = create;
     CreatorId = creator;
     Colour1 = colour1 == 0 ? 1 : colour1;
     Colour2 = colour2 == 0 ? 1 : colour2;
     Members = members;
     Requests = requests;
     Admins = admins;
     State = state;
     AdminOnlyDeco = adminOnlyDeco;
     Forum = forum;
 }