public void Parse(GameClient Session, ClientPacket Packet)
        {
            int GroupId    = Packet.PopInt();
            int ThreadId   = Packet.PopInt();
            int StartIndex = Packet.PopInt();
            int StopIndex  = Packet.PopInt();

            Group Group = GroupManager.GetJob(GroupId);

            if (Group == null || !Group.ForumEnabled)
            {
                return;
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM groups_forums_posts WHERE group_id = @groupid AND parent_id = @threadid OR id = @threadid ORDER BY timestamp ASC");
                dbClient.AddParameter("groupid", GroupId);
                dbClient.AddParameter("threadid", ThreadId);

                DataTable Table = dbClient.getTable();

                if (Table == null)
                {
                    return;
                }

                int b     = (Table.Rows.Count <= 20) ? Table.Rows.Count : 20;
                var posts = new List <GroupForumPost>();

                int i = 1;

                while (i <= b)
                {
                    DataRow Row = Table.Rows[i - 1];

                    if (Row == null)
                    {
                        b--;
                        continue;
                    }

                    var thread = new GroupForumPost(Row);

                    if (thread.ParentId == 0 && thread.Hidden)
                    {
                        return;
                    }

                    posts.Add(thread);

                    i++;
                }
                Session.SendMessage(new GroupForumReadThreadMessageComposer(Session, GroupId, ThreadId, StartIndex, b, 0, posts));
            }
        }
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            int GroupId    = Packet.PopInt();
            int StartIndex = Packet.PopInt();
            int EndIndex   = Packet.PopInt();

            Group Group = GroupManager.GetJob(GroupId);

            if (Group == null || !Group.ForumEnabled)
            {
                return;
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `groups_forums_posts` WHERE `group_id` = @gid AND `parent_id` = '0' ORDER BY timestamp DESC");
                dbClient.AddParameter("gid", GroupId);

                DataTable Table = dbClient.getTable();

                if (Table == null)
                {
                    Session.SendMessage(new GroupForumThreadRootMessageComposer(Group, 1, 0, 0, null, Session));
                    return;
                }

                int b       = (Table.Rows.Count <= 20) ? Table.Rows.Count : 20;
                var Threads = new List <GroupForumPost>();

                int i = 1;

                while (i <= b)
                {
                    DataRow Row = Table.Rows[i - 1];

                    if (Row == null)
                    {
                        b--;
                        continue;
                    }

                    var thread = new GroupForumPost(Row);

                    Threads.Add(thread);

                    i++;
                }

                Threads = Threads.OrderByDescending(x => x.Pinned).ToList();

                Session.SendMessage(new GroupForumThreadRootMessageComposer(Group, 2, StartIndex, b, Threads, Session));
            }
        }
Exemple #3
0
 public GroupForumThreadUpdateMessageComposer(Group Group, GroupForumPost Thread, bool Pin, bool Lock)
     : base(ServerPacketHeader.GroupForumThreadUpdateMessageComposer)
 {
     base.WriteInteger(Group.Id);
     base.WriteInteger(Thread.Id);
     base.WriteInteger(Thread.PosterId);
     base.WriteString(Thread.PosterName);
     base.WriteString(Thread.Subject);
     base.WriteBoolean(Pin);
     base.WriteBoolean(Lock);
     base.WriteInteger(((int)PlusEnvironment.GetUnixTimestamp() - Thread.Timestamp));
     base.WriteInteger(Thread.MessageCount + 1);
     base.WriteInteger(0);
     base.WriteInteger(0);
     base.WriteInteger(1);
     base.WriteString("");
     base.WriteInteger(((int)PlusEnvironment.GetUnixTimestamp() - Thread.Timestamp));
     base.WriteByte((Thread.Hidden) ? 10 : 1);
     base.WriteInteger(1);
     base.WriteString(PlusEnvironment.GetHabboById(Thread.Hider).Username);
     base.WriteInteger(0);
 }
Exemple #4
0
        public override void HandleMessage(Yupi.Model.Domain.Habbo session, Yupi.Protocol.Buffers.ClientMessage request,
                                           Yupi.Protocol.IRouter router)
        {
            int    groupId  = request.GetInteger();
            int    threadId = request.GetInteger();
            string subject  = request.GetString();
            string content  = request.GetString();

            Group group = GroupRepository.Find(groupId);

            if (group == null)
            {
                return;
            }

            GroupForumThread thread;

            if (threadId == 0)
            {
                // New thread
                thread = new GroupForumThread();
            }
            else
            {
                thread = group.Forum.GetThread(threadId);

                if (thread == null)
                {
                    return;
                }
            }

            if (thread.Locked || thread.Hidden)
            {
                return;
            }

            GroupForumPost post = new GroupForumPost()
            {
                Content = content,
                Subject = subject,
                Poster  = session.Info
            };

            group.Forum.ForumScore += 0.25;
            // TODO SAVE
            throw new NotImplementedException();

            /*
             * group.UpdateForum();
             *
             * if (threadId == 0)
             * {
             *  router.GetComposer<GroupForumNewThreadMessageComposer> ().Compose (session, groupId, threadId, session.GetHabbo ().Id, subject, content, timestamp);
             * }
             * else
             * {
             *  router.GetComposer<GroupForumNewResponseMessageComposer> ().Compose (
             *      session, groupId, threadId, group.Forum.ForumMessagesCount, session.GetHabbo (), timestamp);
             * }*/
        }
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            int GroupId    = Packet.PopInt();
            int ThreadId   = Packet.PopInt();
            int StateToSet = Packet.PopInt();

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery(string.Format("SELECT * FROM groups_forums_posts WHERE group_id = '{0}' AND id = '{1}' LIMIT 1;", GroupId, ThreadId));
                DataRow Row = dbClient.getRow();

                Group Group = GroupManager.GetJob(GroupId);

                if (Row != null)
                {
                    if (Convert.ToInt32(Row["poster_id"]) == Session.GetHabbo().Id || Group.IsAdmin(Session.GetHabbo().Id))
                    {
                        string state = "0";
                        if (StateToSet == 20 || StateToSet == 10)
                        {
                            state = "1";
                        }

                        dbClient.SetQuery(string.Format("UPDATE groups_forums_posts SET hidden = @hid, post_hider = @uid WHERE id = {0};", ThreadId));
                        dbClient.AddParameter("hid", state);
                        dbClient.AddParameter("uid", Session.GetHabbo().Id);
                        dbClient.RunQuery();
                    }
                }

                var Thread = new GroupForumPost(Row);

                Session.SendMessage(new RoomNotificationComposer(((StateToSet == 20) || (StateToSet == 10)) ? "forums.thread.hidden" : "forums.thread.restored"));

                if (Thread.ParentId != 0)
                {
                    return;
                }

                Session.SendMessage(new GroupForumThreadUpdateMessageComposer(Group, Thread, Thread.Pinned, Thread.Locked));

                dbClient.SetQuery("SELECT * FROM groups_forums_posts WHERE group_id = @gid AND parent_id = 0 ORDER BY timestamp DESC");
                dbClient.AddParameter("gid", GroupId);

                DataTable Table = dbClient.getTable();

                if (Table == null)
                {
                    Session.SendMessage(new GroupForumThreadRootMessageComposer(Group, 1, 0, 0, null, Session));
                    return;
                }

                int b       = (Table.Rows.Count <= 20) ? Table.Rows.Count : 20;
                var Threads = new List <GroupForumPost>();

                int i = 1;

                while (i <= b)
                {
                    DataRow Row2 = Table.Rows[i - 1];

                    if (Row2 == null)
                    {
                        b--;
                        continue;
                    }

                    var thread = new GroupForumPost(Row2);

                    Threads.Add(thread);

                    i++;
                }

                Threads = Threads.OrderByDescending(x => x.Pinned).ToList();

                Session.SendMessage(new GroupForumThreadRootMessageComposer(Group, 2, 0, b, Threads, Session));
            }
        }
Exemple #6
0
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            int  GroupId  = Packet.PopInt();
            int  ThreadId = Packet.PopInt();
            bool Pin      = Packet.PopBoolean();
            bool Lock     = Packet.PopBoolean();

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery(string.Format("SELECT * FROM groups_forums_posts WHERE group_id = '{0}' AND id = '{1}' LIMIT 1;", GroupId, ThreadId));
                DataRow Row = dbClient.getRow();

                Group Group = GroupManager.GetJob(GroupId);

                if (Row != null)
                {
                    if ((uint)Row["poster_id"] == Session.GetHabbo().Id || Group.IsAdmin(Session.GetHabbo().Id))
                    {
                        dbClient.SetQuery(string.Format("UPDATE groups_forums_posts SET pinned = @pin , locked = @lock WHERE id = {0};", ThreadId));
                        dbClient.AddParameter("pin", (Pin) ? "1" : "0");
                        dbClient.AddParameter("lock", (Lock) ? "1" : "0");
                        dbClient.RunQuery();
                    }
                }

                var Thread = new GroupForumPost(Row);

                if (Thread.Pinned != Pin)
                {
                    Session.SendMessage(new RoomNotificationComposer((Pin) ? "forums.thread.pinned" : "forums.thread.unpinned"));
                }

                if (Thread.Locked != Lock)
                {
                    Session.SendMessage(new RoomNotificationComposer((Lock) ? "forums.thread.locked" : "forums.thread.unlocked"));
                }

                if (Thread.ParentId != 0)
                {
                    return;
                }

                Session.SendMessage(new GroupForumThreadUpdateMessageComposer(Group, Thread, Pin, Lock));

                dbClient.SetQuery("SELECT * FROM groups_forums_posts WHERE group_id = @gid AND parent_id = 0 ORDER BY timestamp DESC");
                dbClient.AddParameter("gid", GroupId);

                DataTable Table = dbClient.getTable();

                if (Table == null)
                {
                    Session.SendMessage(new GroupForumThreadRootMessageComposer(Group, 1, 0, 0, null, Session));
                    return;
                }

                int b       = (Table.Rows.Count <= 20) ? Table.Rows.Count : 20;
                var Threads = new List <GroupForumPost>();

                int i = 1;

                while (i <= b)
                {
                    DataRow Row2 = Table.Rows[i - 1];

                    if (Row2 == null)
                    {
                        b--;
                        continue;
                    }

                    var thread = new GroupForumPost(Row2);

                    Threads.Add(thread);

                    i++;
                }

                Threads = Threads.OrderByDescending(x => x.Pinned).ToList();

                Session.SendMessage(new GroupForumThreadRootMessageComposer(Group, 2, 0, b, Threads, Session));
            }
        }
Exemple #7
0
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            TimeSpan Span = DateTime.Now - Session.GetHabbo().LastForumMessageUpdateTime;

            if (Span.TotalSeconds < 20)
            {
                return;
            }

            int    groupId  = Packet.PopInt();
            int    threadId = Packet.PopInt();
            string subject  = Packet.PopString();
            string content  = Packet.PopString();

            Group group = GroupManager.GetJob(groupId);

            if (group == null || !group.ForumEnabled)
            {
                return;
            }

            int timestamp = Convert.ToInt32(PlusEnvironment.GetUnixTimestamp());

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                if (threadId != 0)
                {
                    dbClient.SetQuery(string.Format("SELECT * FROM groups_forums_posts WHERE id = {0}", threadId));
                    DataRow Row = dbClient.getRow();

                    var Post = new GroupForumPost(Row);

                    if (Post.Locked || Post.Hidden)
                    {
                        Session.SendNotification(PlusEnvironment.GetGame().GetLanguageLocale().TryGetValue("forums_cancel"));
                        return;
                    }
                }
                Session.GetHabbo().LastForumMessageUpdateTime = DateTime.Now;

                dbClient.SetQuery("INSERT INTO groups_forums_posts (group_id, parent_id, timestamp, poster_id, poster_name, poster_look, subject, post_content) VALUES (@gid, @pard, @ts, @pid, @pnm, @plk, @subjc, @content)");
                dbClient.AddParameter("gid", groupId);
                dbClient.AddParameter("pard", threadId);
                dbClient.AddParameter("ts", timestamp);
                dbClient.AddParameter("pid", Session.GetHabbo().Id);
                dbClient.AddParameter("pnm", Session.GetHabbo().Username);
                dbClient.AddParameter("plk", Session.GetHabbo().Look);
                dbClient.AddParameter("subjc", subject);
                dbClient.AddParameter("content", content);

                threadId = dbClient.getInteger();
            }

            group.ForumScore              += 0.25;
            group.ForumLastPosterName      = Session.GetHabbo().Username;
            group.ForumLastPosterId        = Session.GetHabbo().Id;
            group.ForumLastPosterTimestamp = timestamp;
            group.ForumMessagesCount++;
            group.UpdateForum();

            if (threadId == 0)
            {
                Session.SendMessage(new GroupForumNewThreadMessageComposer(Session, groupId, threadId, subject, content, timestamp));
            }
            else
            {
                Session.SendMessage(new GroupForumNewResponseMessageComposer(Session, group, groupId, threadId, content, timestamp));
            }

            Session.GetHabbo().GetStats().ForumPosts++;
        }
Exemple #8
0
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            int groupId    = Packet.PopInt();
            int parentId   = Packet.PopInt();
            int index      = Packet.PopInt() + 1;
            int StateToSet = Packet.PopInt();

            Group group   = GroupManager.GetJob(groupId);
            bool  IsAdmin = false;

            if (group.IsAdmin(Session.GetHabbo().Id) || Session.GetHabbo().GetPermissions().HasRight("corporation_rights") || group.CreatorId == Session.GetHabbo().Id || Session.GetHabbo().GetPermissions().HasRight("roleplay_corp_manager"))
            {
                IsAdmin = true;
            }

            if (!IsAdmin)
            {
                return;
            }

            if (group == null || !group.ForumEnabled)
            {
                return;
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery(string.Format("SELECT * FROM groups_forums_posts WHERE parent_id = {0} ORDER BY id", parentId));
                DataTable Table = dbClient.getTable();

                int t = 0;

                foreach (DataRow Row in Table.Rows)
                {
                    t++;
                    if (t == index)
                    {
                        string state = "0";
                        if (StateToSet == 20 || StateToSet == 10)
                        {
                            state = "1";
                        }

                        dbClient.RunQuery("UPDATE `groups_forums_posts` SET `hidden` = @hid WHERE id = @id");
                        dbClient.AddParameter("id", Convert.ToInt32(Row["id"]));
                        dbClient.AddParameter("hid", state);
                        dbClient.RunQuery();
                    }
                }

                Session.SendMessage(new RoomNotificationComposer(((StateToSet == 20) || (StateToSet == 10)) ? "forums.message.hidden" : "forums.message.restored"));

                dbClient.SetQuery("SELECT * FROM groups_forums_posts WHERE group_id = @groupid AND parent_id = @threadid OR id = @threadid ORDER BY timestamp ASC");
                dbClient.AddParameter("groupid", groupId);
                dbClient.AddParameter("threadid", parentId);

                DataTable Table2 = dbClient.getTable();

                if (Table2 == null)
                {
                    return;
                }

                int b     = (Table2.Rows.Count <= 20) ? Table2.Rows.Count : 20;
                var posts = new List <GroupForumPost>();

                int i = 1;

                while (i <= b)
                {
                    DataRow Row = Table2.Rows[i - 1];

                    if (Row == null)
                    {
                        b--;
                        continue;
                    }

                    var thread = new GroupForumPost(Row);

                    if (thread.ParentId == 0 && thread.Hidden)
                    {
                        return;
                    }

                    posts.Add(thread);

                    i++;
                }
                Session.SendMessage(new GroupForumReadThreadMessageComposer(Session, groupId, parentId, 0, b, 0, posts));
            }
        }