Пример #1
0
        /// <summary>
        /// Reads the forum thread.
        /// </summary>
        internal void ReadForumThread()
        {
            uint groupId = Request.GetUInteger();
            uint threadId = Request.GetUInteger();
            int startIndex = Request.GetInteger();
            Request.GetInteger();

            Guild theGroup = Azure.GetGame().GetGroupManager().GetGroup(groupId);

            if (theGroup == null || !theGroup.HasForum)
                return;

            using (IQueryAdapter dbClient = Azure.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery($"SELECT * FROM groups_forums_posts WHERE group_id = '{groupId}' AND parent_id = '{threadId}' OR id = '{threadId}' ORDER BY timestamp ASC;");

                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++;
                }

                var message = new ServerMessage(LibraryParser.OutgoingRequest("GroupForumReadThreadMessageComposer"));

                message.AppendInteger(groupId);
                message.AppendInteger(threadId);
                message.AppendInteger(startIndex);
                message.AppendInteger(b);
                int indx = 0;

                foreach (GroupForumPost post in posts)
                {
                    message.AppendInteger(indx++ - 1);
                    message.AppendInteger(indx - 1);
                    message.AppendInteger(post.PosterId);
                    message.AppendString(post.PosterName);
                    message.AppendString(post.PosterLook);
                    message.AppendInteger((Azure.GetUnixTimeStamp() - post.Timestamp));
                    message.AppendString(post.PostContent);
                    message.AppendByte(0);
                    message.AppendInteger(0);
                    message.AppendString(post.Hider);
                    message.AppendInteger(0);
                }

                Session.SendMessage(message);
            }
        }
Пример #2
0
        /// <summary>
        /// Updates the state of the thread.
        /// </summary>
        internal void UpdateThreadState()
        {
            uint groupId = Request.GetUInteger();
            uint threadId = Request.GetUInteger();
            bool pin = Request.GetBool();
            bool Lock = Request.GetBool();

            using (IQueryAdapter dbClient = Azure.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery($"SELECT * FROM groups_forums_posts WHERE group_id = '{groupId}' AND id = '{threadId}' LIMIT 1;");
                DataRow row = dbClient.GetRow();

                Guild theGroup = Azure.GetGame().GetGroupManager().GetGroup(groupId);

                if (row != null)
                {
                    if ((uint)row["poster_id"] == Session.GetHabbo().Id || theGroup.Admins.ContainsKey(Session.GetHabbo().Id))
                    {
                        dbClient.SetQuery($"UPDATE groups_forums_posts SET pinned = @pin , locked = @lock WHERE id = {threadId};");
                        dbClient.AddParameter("pin", (pin) ? "1" : "0");
                        dbClient.AddParameter("lock", (Lock) ? "1" : "0");
                        dbClient.RunQuery();
                    }
                }

                var thread = new GroupForumPost(row);

                if (thread.Pinned != pin)
                {
                    var notif = new ServerMessage(LibraryParser.OutgoingRequest("SuperNotificationMessageComposer"));

                    notif.AppendString((pin) ? "forums.thread.pinned" : "forums.thread.unpinned");
                    notif.AppendInteger(0);
                    Session.SendMessage(notif);
                }

                if (thread.Locked != Lock)
                {
                    var notif2 = new ServerMessage(LibraryParser.OutgoingRequest("SuperNotificationMessageComposer"));

                    notif2.AppendString((Lock) ? "forums.thread.locked" : "forums.thread.unlocked");
                    notif2.AppendInteger(0);
                    Session.SendMessage(notif2);
                }

                if (thread.ParentId != 0)
                    return;

                var message = new ServerMessage(LibraryParser.OutgoingRequest("GroupForumThreadUpdateMessageComposer"));
                message.AppendInteger(groupId);
                message.AppendInteger(thread.Id);
                message.AppendInteger(thread.PosterId);
                message.AppendString(thread.PosterName);
                message.AppendString(thread.Subject);
                message.AppendBool(pin);
                message.AppendBool(Lock);
                message.AppendInteger((Azure.GetUnixTimeStamp() - thread.Timestamp));
                message.AppendInteger(thread.MessageCount + 1);
                message.AppendInteger(0);
                message.AppendInteger(0);
                message.AppendInteger(1);
                message.AppendString("");
                message.AppendInteger((Azure.GetUnixTimeStamp() - thread.Timestamp));
                message.AppendByte((thread.Hidden) ? 10 : 1);
                message.AppendInteger(1);
                message.AppendString(thread.Hider);
                message.AppendInteger(0);

                Session.SendMessage(message);
            }
        }
Пример #3
0
        /// <summary>
        /// Alters the state of the forum thread.
        /// </summary>
        internal void AlterForumThreadState()
        {
            uint groupId = Request.GetUInteger();
            uint threadId = Request.GetUInteger();
            int stateToSet = Request.GetInteger();

            using (IQueryAdapter dbClient = Azure.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery($"SELECT * FROM groups_forums_posts WHERE group_id = '{groupId}' AND id = '{threadId}' LIMIT 1;");

                DataRow row = dbClient.GetRow();
                Guild theGroup = Azure.GetGame().GetGroupManager().GetGroup(groupId);

                if (row != null)
                {
                    if ((uint)row["poster_id"] == Session.GetHabbo().Id || theGroup.Admins.ContainsKey(Session.GetHabbo().Id))
                    {
                        dbClient.SetQuery($"UPDATE groups_forums_posts SET hidden = @hid WHERE id = {threadId};");
                        dbClient.AddParameter("hid", (stateToSet == 20) ? "1" : "0");
                        dbClient.RunQuery();
                    }
                }

                var thread = new GroupForumPost(row);
                var notif = new ServerMessage(LibraryParser.OutgoingRequest("SuperNotificationMessageComposer"));

                notif.AppendString((stateToSet == 20) ? "forums.thread.hidden" : "forums.thread.restored");
                notif.AppendInteger(0);
                Session.SendMessage(notif);

                if (thread.ParentId != 0)
                    return;

                var message = new ServerMessage(LibraryParser.OutgoingRequest("GroupForumThreadUpdateMessageComposer"));
                message.AppendInteger(groupId);
                message.AppendInteger(thread.Id);
                message.AppendInteger(thread.PosterId);
                message.AppendString(thread.PosterName);
                message.AppendString(thread.Subject);
                message.AppendBool(thread.Pinned);
                message.AppendBool(thread.Locked);
                message.AppendInteger((Azure.GetUnixTimeStamp() - thread.Timestamp));
                message.AppendInteger(thread.MessageCount + 1);
                message.AppendInteger(0);
                message.AppendInteger(0);
                message.AppendInteger(0);
                message.AppendString(string.Empty);
                message.AppendInteger((Azure.GetUnixTimeStamp() - thread.Timestamp));
                message.AppendByte(stateToSet);
                message.AppendInteger(0);
                message.AppendString(thread.Hider);
                message.AppendInteger(0);

                Session.SendMessage(message);
            }
        }
Пример #4
0
        /// <summary>
        /// Publishes the forum thread.
        /// </summary>
        internal void PublishForumThread()
        {
            if ((Azure.GetUnixTimeStamp() - Session.GetHabbo().LastSqlQuery) < 20)
                return;

            uint groupId = Request.GetUInteger();
            uint threadId = Request.GetUInteger();
            string subject = Request.GetString();
            string content = Request.GetString();

            Guild group = Azure.GetGame().GetGroupManager().GetGroup(groupId);

            if (group == null || !group.HasForum)
                return;

            int timestamp = Azure.GetUnixTimeStamp();

            using (IQueryAdapter dbClient = Azure.GetDatabaseManager().GetQueryReactor())
            {
                if (threadId != 0)
                {
                    dbClient.SetQuery($"SELECT * FROM groups_forums_posts WHERE id = {threadId}");

                    DataRow row = dbClient.GetRow();
                    var post = new GroupForumPost(row);

                    if (post.Locked || post.Hidden)
                    {
                        Session.SendNotif(Azure.GetLanguage().GetVar("forums_cancel"));
                        return;
                    }
                }

                Session.GetHabbo().LastSqlQuery = Azure.GetUnixTimeStamp();
                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 = (uint)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)
            {
                var message = new ServerMessage(LibraryParser.OutgoingRequest("GroupForumNewThreadMessageComposer"));
                message.AppendInteger(groupId);
                message.AppendInteger(threadId);
                message.AppendInteger(Session.GetHabbo().Id);
                message.AppendString(subject);
                message.AppendString(content);
                message.AppendBool(false);
                message.AppendBool(false);
                message.AppendInteger((Azure.GetUnixTimeStamp() - timestamp));
                message.AppendInteger(1);
                message.AppendInteger(0);
                message.AppendInteger(0);
                message.AppendInteger(1);
                message.AppendString("");
                message.AppendInteger((Azure.GetUnixTimeStamp() - timestamp));
                message.AppendByte(1);
                message.AppendInteger(1);
                message.AppendString("");
                message.AppendInteger(42);
                Session.SendMessage(message);
            }
            else
            {
                var message = new ServerMessage(LibraryParser.OutgoingRequest("GroupForumNewResponseMessageComposer"));
                message.AppendInteger(groupId);
                message.AppendInteger(threadId);
                message.AppendInteger(group.ForumMessagesCount);
                message.AppendInteger(0);
                message.AppendInteger(Session.GetHabbo().Id);
                message.AppendString(Session.GetHabbo().UserName);
                message.AppendString(Session.GetHabbo().Look);
                message.AppendInteger((Azure.GetUnixTimeStamp() - timestamp));
                message.AppendString(content);
                message.AppendByte(0);
                message.AppendInteger(0);
                message.AppendString("");
                message.AppendInteger(0);
                Session.SendMessage(message);
            }
        }