コード例 #1
0
ファイル: GroupForumRepository.cs プロジェクト: ngocpq/MHX2
 public void DeleteGroupForum(GroupForum groupForum)
 {
     using (SPKTDataContext dc = conn.GetContext())
     {
         dc.GroupForums.Attach(groupForum, true);
         dc.GroupForums.DeleteOnSubmit(groupForum);
         dc.SubmitChanges();
     }
 }
コード例 #2
0
ファイル: GroupForumRepository.cs プロジェクト: ngocpq/MHX2
 public void SaveGroupForum(GroupForum groupForum)
 {
     using (SPKTDataContext dc = conn.GetContext())
     {
         if (dc.GroupForums.Where(gf => gf.ForumID == groupForum.ForumID && gf.GroupID == groupForum.GroupID).FirstOrDefault() == null)
         {
             dc.GroupForums.InsertOnSubmit(groupForum);
             dc.SubmitChanges();
         }
     }
 }
コード例 #3
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);
        }
コード例 #4
0
        public ThreadsListDataComposer(GroupForum Forum, GameClient Session, int StartIndex = 0, int MaxLength = 20)
            : base(ServerPacketHeader.ThreadsListDataMessageComposer)
        {
            WriteInteger(Forum.GroupId);          //Group Forum ID
            WriteInteger(StartIndex);             //Page Index

            var Threads = Forum.Threads;

            if (Threads.Count - 1 >= StartIndex)
            {
                Threads = Threads.GetRange(StartIndex, Math.Min(MaxLength, Threads.Count - StartIndex));
            }

            WriteInteger(Threads.Count);             //Thread Count

            foreach (var Thread in Threads)
            {
                Thread.SerializeData(Session, this);
            }
        }
コード例 #5
0
        public int SaveGroup(Group group)
        {
            int result = 0;

            if (group.GroupID > 0)
            {
                result = _groupRepository.SaveGroup(group);
            }
            else
            {
                result = _groupRepository.SaveGroup(group);

                BoardForum forum = new BoardForum();
                forum.CategoryID          = 8; //group forums container
                forum.CreateDate          = DateTime.Now;
                forum.LastPostByAccountID = _webContext.CurrentUser.AccountID;
                forum.LastPostByUsername  = _webContext.CurrentUser.UserName;
                forum.LastPostDate        = DateTime.Now;
                forum.Name        = group.Name;
                forum.PageName    = group.PageName;
                forum.PostCount   = 0;
                forum.Subject     = group.Name;
                forum.ThreadCount = 0;
                forum.UpdateDate  = DateTime.Now;
                int ForumID = _forumRepository.SaveForum(forum);

                //create relationship between the group and forum
                GroupForum gf = new GroupForum();
                gf.ForumID    = ForumID;
                gf.GroupID    = group.GroupID;
                gf.CreateDate = DateTime.Now;
                _groupForumRepository.SaveGroupForum(gf);
            }

            return(result);
        }
コード例 #6
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);
            }
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: GroupService.cs プロジェクト: SPKT/MHX2
        public int SaveGroup(Group group)
        {
            int result = 0;
            if (group.GroupID > 0)
            {
                result = _groupRepository.SaveGroup(group);
            }
            else
            {
                result = _groupRepository.SaveGroup(group);

                BoardForum forum = new BoardForum();
                forum.CategoryID = 8; //group forums container
                forum.CreateDate = DateTime.Now;
                forum.LastPostByAccountID = _webContext.CurrentUser.AccountID;
                forum.LastPostByUsername = _webContext.CurrentUser.UserName;
                forum.LastPostDate = DateTime.Now;
                forum.Name = group.Name;
                forum.PageName = group.PageName;
                forum.PostCount = 0;
                forum.Subject = group.Name;
                forum.ThreadCount = 0;
                forum.UpdateDate = DateTime.Now;
                int ForumID = _forumRepository.SaveForum(forum);

                //create relationship between the group and forum
                GroupForum gf = new GroupForum();
                gf.ForumID = ForumID;
                gf.GroupID = group.GroupID;
                gf.CreateDate = DateTime.Now;
                _groupForumRepository.SaveGroupForum(gf);

                //add Groupleader is member
                GroupMember gm = new GroupMember();
                gm.AccountID = _webContext.CurrentUser.AccountID;
                gm.GroupID = group.GroupID;
                gm.CreateDate = DateTime.Now;
                gm.IsAdmin = true;
                gm.IsApproved = true;
                _groupMemberRepository.SaveGroupMember(gm);

            }

            return result;
        }