Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hey, Many people have requested these and I basically released them on the git for project Plus.
- So thought I'd release them here. Please bare in mind, this quickly coded & is for
- PRODUCTION-201701242205-837386173.
- ok, goto Groups.cs add
- [CODE]public bool HasForum;[/CODE]
- then add
- [QUOTE]bool HasForum[/QUOTE]
- to the public Group() below.
- And add
- [QUOTE]this.HasForum = HasForum;[/QUOTE]
- inside the {}.
- then inside HabboHotel->Groups Create a new folder and add these files in there.
- GroupForum.cs
- [CODE]using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using Plus.Database.Interfaces;
- namespace Plus.HabboHotel.Groups.Forums
- {
- public class GroupForum
- {
- public int GroupId;
- public Group Group;
- public GroupForumSettings Settings;
- public List<GroupForumThread> Threads;
- public int Id
- {
- get
- {
- return GroupId;
- }
- }
- public string Name
- {
- get
- {
- return Group.Name;
- }
- }
- public string Description
- {
- get
- {
- return Group.Description;
- }
- }
- public GroupForum(Group group)
- {
- GroupId = group.Id;
- Group = group;
- Settings = new GroupForumSettings(this);
- Threads = new List<GroupForumThread>();
- LoadThreads();
- }
- private void LoadThreads()
- {
- DataTable table;
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("SELECT * FROM group_forums_threads WHERE forum_id = @id ORDER BY id DESC");
- adap.AddParameter("id", Id);
- table = adap.getTable();
- }
- foreach (DataRow Row in table.Rows)
- {
- Threads.Add(new GroupForumThread(this, Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["timestamp"]), Row["caption"].ToString(), Convert.ToInt32(Row["pinned"]) == 1, Convert.ToInt32(Row["locked"]) == 1, Convert.ToInt32(Row["deleted_level"]), Convert.ToInt32(Row["deleter_user_id"])));
- }
- }
- public int MessagesCount
- {
- get
- {
- return Threads.SelectMany(c => c.Posts).Count();
- }
- }
- public int UnreadMessages(int userid)
- {
- int i = 0;
- Threads.ForEach(c => i += c.GetUnreadMessages(userid));
- return i;
- }
- public GroupForumThreadPost GetLastPost()
- {
- var Posts = Threads.SelectMany(c => c.Posts);
- return Posts.OrderByDescending(c => c.Timestamp).FirstOrDefault();
- }
- public GroupForumThread GetThread(int ThreadId)
- {
- return Threads.FirstOrDefault(c => c.Id == ThreadId);
- }
- public GroupForumThread CreateThread(int Creator, string Caption)
- {
- var timestamp = (int)PlusEnvironment.GetUnixTimestamp();
- var Thread = new GroupForumThread(this, 0, Creator, (int)timestamp, Caption, false, false, 0, 0);
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("INSERT INTO group_forums_threads (forum_id, user_id, caption, timestamp) VALUES (@a, @b, @c, @d)");
- adap.AddParameter("a", this.Id);
- adap.AddParameter("b", Creator);
- adap.AddParameter("c", Caption);
- adap.AddParameter("d", timestamp);
- Thread.Id = (int)adap.InsertQuery();
- }
- this.Threads.Add(Thread);
- return Thread;
- }
- public GroupForumThreadPost GetPost(int postid)
- {
- return Threads.SelectMany(c => c.Posts).Where(c => c.Id == postid).FirstOrDefault();
- }
- }
- }
- [/CODE]
- GroupForumManager.cs
- [CODE]using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Plus.Database.Interfaces;
- namespace Plus.HabboHotel.Groups.Forums
- {
- public class GroupForumManager
- {
- List<GroupForum> Forums;
- public GroupForumManager()
- {
- Forums = new List<GroupForum>();
- }
- public GroupForum GetForum(int GroupId)
- {
- GroupForum f = null;
- return TryGetForum(GroupId, out f) ? f : null;
- }
- public GroupForum CreateGroupForum(Group Gp)
- {
- GroupForum GF;
- if (TryGetForum(Gp.Id, out GF))
- return GF;
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("INSERT INTO group_forums_settings (group_id) VALUES (@gp)");
- adap.AddParameter("gp", Gp.Id);
- adap.RunQuery();
- adap.SetQuery("UPDATE groups SET has_forum = '1' WHERE id = @id");
- adap.AddParameter("id", Gp.Id);
- adap.RunQuery();
- }
- GF = new GroupForum(Gp);
- Forums.Add(GF);
- return GF;
- }
- public bool TryGetForum(int Id, out GroupForum Forum)
- {
- if ((Forum = Forums.FirstOrDefault(c => c.Id == Id)) != null)
- return true;
- Group Gp;
- if (!PlusEnvironment.GetGame().GetGroupManager().TryGetGroup(Id, out Gp))
- return false;
- if (!Gp.HasForum)
- return false;
- Forum = new GroupForum(Gp);
- Forums.Add(Forum);
- return true;
- }
- public List<GroupForum> GetForumsByUserId(int Userid)
- {
- GroupForum F;
- return PlusEnvironment.GetGame().GetGroupManager().GetGroupsForUser(Userid).Where(c => TryGetForum(c.Id, out F)).Select(c => GetForum(c.Id)).ToList();
- }
- }
- }
- [/CODE]
- GroupForumSettings.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Plus.Database.Interfaces;
- using System.Data;
- using System.Threading.Tasks;
- namespace Plus.HabboHotel.Groups.Forums
- {
- public class GroupForumSettings {
- public GroupForum ParentForum { get; private set; }
- public int WhoCanRead;
- public int WhoCanPost;
- public int WhoCanInitDiscussions;
- public int WhoCanModerate;
- public GroupForumSettings(GroupForum Forum)
- {
- this.ParentForum = Forum;
- DataRow Row;
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("SELECT * FROM group_forums_settings WHERE group_id = '" + Forum.Id + "'");
- //adap.AddParameter("id", Forum.Id);
- Row = adap.getRow();
- }
- if (Row == null)
- {
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("REPLACE INTO group_forums_settings (group_id) VALUES @id);SELECT * FROM group_forums_settings WHERE group_id = @id");
- adap.AddParameter("id", Forum.Id);
- Row = adap.getRow();
- }
- }
- this.WhoCanRead = Convert.ToInt32(Row["who_can_read"]);
- this.WhoCanPost = Convert.ToInt32(Row["who_can_post"]);
- this.WhoCanInitDiscussions = Convert.ToInt32(Row["who_can_init_discussions"]);
- this.WhoCanModerate = Convert.ToInt32(Row["who_can_mod"]);
- }
- public void Save()
- {
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("UPDATE group_forums_settings SET who_can_read = @a, who_can_post = @b, who_can_init_discussions = @c, who_can_mod = @d WHERE group_id = @id");
- adap.AddParameter("id", ParentForum.Id);
- adap.AddParameter("a", WhoCanRead);
- adap.AddParameter("b", WhoCanPost);
- adap.AddParameter("c", WhoCanInitDiscussions);
- adap.AddParameter("d", WhoCanModerate);
- adap.RunQuery();
- }
- }
- public GroupForumPermissionLevel GetLevel(int n)
- {
- switch (n)
- {
- case 0:
- default:
- return GroupForumPermissionLevel.ANYONE;
- case 1:
- return GroupForumPermissionLevel.JUST_MEMBERS;
- case 2:
- return GroupForumPermissionLevel.JUST_ADMIN;
- case 3:
- return GroupForumPermissionLevel.JUST_OWNER;
- }
- }
- public string GetReasonForNot(GameClient Session, int PermissionType)
- {
- if (Session.GetHabbo().GetPermissions().HasRight("mod_tool"))
- return "";
- switch (GetLevel(PermissionType))
- {
- default:
- case GroupForumPermissionLevel.ANYONE:
- return "";
- case GroupForumPermissionLevel.JUST_ADMIN:
- return ParentForum.Group.IsAdmin(Session.GetHabbo().Id) ? "" : "not_admin";
- case GroupForumPermissionLevel.JUST_MEMBERS:
- return ParentForum.Group.IsMember(Session.GetHabbo().Id) ? "" : "not_member";
- case GroupForumPermissionLevel.JUST_OWNER:
- return ParentForum.Group.CreatorId == Session.GetHabbo().Id ? "" : "not_owner";
- }
- }
- }
- public enum GroupForumPermissionLevel
- {
- ANYONE,
- JUST_MEMBERS,
- JUST_ADMIN,
- JUST_OWNER
- }
- }
- [/CODE]
- GroupForumThread.cs
- [CODE]using Plus.Communication.Packets.Outgoing;
- using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Users;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using Plus.Database.Interfaces;
- using System.Text;
- namespace Plus.HabboHotel.Groups.Forums
- {
- public class GroupForumThread
- {
- public int Id;
- public int UserId;
- public string Caption;
- public int Timestamp;
- public bool Pinned;
- public bool Locked;
- public int DeletedLevel;
- public int DeleterUserId;
- public int DeletedTimestamp;
- public GroupForum ParentForum;
- public List<GroupForumThreadPost> Posts;
- public List<GameClient> UsersOnThread;
- public List<GroupForumThreadPostView> Views;
- public GroupForumThread(GroupForum parent, int id, int userid, int timestamp, string caption, bool pinned, bool locked, int deletedlevel, int deleterid)
- {
- Views = new List<GroupForumThreadPostView>(); ;
- UsersOnThread = new List<GameClient>();
- ParentForum = parent;
- Id = id;
- UserId = userid;
- Timestamp = timestamp;
- Caption = caption;
- Posts = new List<GroupForumThreadPost>();
- Pinned = pinned;
- Locked = locked;
- DeletedLevel = deletedlevel;
- DeleterUserId = deleterid;
- DeletedTimestamp = (int)PlusEnvironment.GetUnixTimestamp();
- DataTable table;
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("SELECT * FROM group_forums_thread_posts WHERE thread_id = @id ORDER BY `timestamp`");
- adap.AddParameter("id", this.Id);
- table = adap.getTable();
- }
- foreach (DataRow Row in table.Rows)
- {
- Posts.Add(new GroupForumThreadPost(this, Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["timestamp"]), Row["message"].ToString(), Convert.ToInt32(Row["deleted_level"]), Convert.ToInt32(Row["deleter_user_id"])));
- }
- using (IQueryAdapter Adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- Adap.SetQuery("SELECT * FROM group_forums_thread_views WHERE thread_id = @id");
- Adap.AddParameter("id", Id);
- table = Adap.getTable();
- }
- foreach (DataRow Row in table.Rows)
- {
- Views.Add(new GroupForumThreadPostView(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["count"])));
- }
- }
- private void GroupForumThread_OnClientDisconnect(GameClient client)
- {
- if (UsersOnThread.Contains(client))
- UsersOnThread.Remove(client);
- }
- public void AddView(int userid, int count = -1)
- {
- GroupForumThreadPostView v;
- if ((v = GetView(userid)) != null)
- {
- v.Count = count >= 0 ? count : Posts.Count;
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("UPDATE group_forums_thread_views SET count = @c WHERE thread_id = @p AND user_id = @u");
- adap.AddParameter("c", v.Count);
- adap.AddParameter("p", this.Id);
- adap.AddParameter("u", userid);
- adap.RunQuery();
- }
- }
- else
- {
- v = new GroupForumThreadPostView(0, userid, Posts.Count);
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("INSERT INTO group_forums_thread_views (thread_id, user_id, count) VALUES (@t, @u, @c)");
- adap.AddParameter("t", this.Id);
- adap.AddParameter("u", userid);
- adap.AddParameter("c", v.Count);
- v.Id = (int)adap.InsertQuery();
- Views.Add(v);
- }
- }
- }
- public GroupForumThreadPostView GetView(int userid)
- {
- return Views.FirstOrDefault(c => c.UserId == userid);
- }
- public int GetUnreadMessages(int userid)
- {
- GroupForumThreadPostView v;
- return (v = GetView(userid)) != null ? Posts.Count - v.Count : Posts.Count;
- }
- public List<GroupForumThreadPost> GetUserPosts(int userid)
- {
- return Posts.Where(c => c.UserId == userid).ToList();
- }
- public Habbo GetAuthor()
- {
- return PlusEnvironment.GetHabboById(UserId);
- }
- public Habbo GetDeleter()
- {
- return PlusEnvironment.GetHabboById(DeleterUserId);
- }
- public GroupForumThreadPost CreatePost(int userid, string message)
- {
- var now = (int)PlusEnvironment.GetUnixTimestamp();
- var Post = new GroupForumThreadPost(this, 0, userid, now, message, 0, 0);
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("INSERT INTO group_forums_thread_posts (thread_id, user_id, message, timestamp) VALUES (@a, @b, @c, @d)");
- adap.AddParameter("a", this.Id);
- adap.AddParameter("b", userid);
- adap.AddParameter("c", message);
- adap.AddParameter("d", now);
- Post.Id = (int)adap.InsertQuery();
- }
- Posts.Add(Post);
- return Post;
- }
- public void AddClientToThread(GameClient Session)
- {
- UsersOnThread.Add(Session);
- }
- public void RemoveClientFromThread(GameClient Session)
- {
- if (UsersOnThread.Contains(Session))
- UsersOnThread.Add(Session);
- }
- public GroupForumThreadPost GetLastMessage()
- {
- return Posts.LastOrDefault();
- }
- public void SerializeData(GameClient Session, ServerPacket Packet)
- {
- var lastpost = GetLastMessage();
- var isn = lastpost == null;
- Packet.WriteInteger(Id);
- Packet.WriteInteger(GetAuthor().Id);
- Packet.WriteString(GetAuthor().Username);
- Packet.WriteString(Caption);
- Packet.WriteBoolean(Pinned);
- Packet.WriteBoolean(Locked);
- Packet.WriteInteger((int)(PlusEnvironment.GetUnixTimestamp() - Timestamp));
- Packet.WriteInteger(Posts.Count);
- Packet.WriteInteger(GetUnreadMessages(Session.GetHabbo().Id));
- Packet.WriteInteger(0);
- Packet.WriteInteger(!isn ? lastpost.GetAuthor().Id : 0);
- Packet.WriteString(!isn ? lastpost.GetAuthor().Username : "");
- Packet.WriteInteger(!isn ? (int)(PlusEnvironment.GetUnixTimestamp() - lastpost.Timestamp) : 0);
- Packet.WriteByte(DeletedLevel * 10);
- var deleter = GetDeleter();
- if (deleter != null)
- {
- Packet.WriteInteger(deleter.Id);
- Packet.WriteString(deleter.Username);
- Packet.WriteInteger((int)(PlusEnvironment.GetUnixTimestamp() - DeletedTimestamp));
- }
- else
- {
- Packet.WriteInteger(1);
- Packet.WriteString("unknow");
- Packet.WriteInteger(0);
- }
- }
- public GroupForumThreadPost GetPost(int postId)
- {
- return Posts.FirstOrDefault(c => c.Id == postId);
- }
- public void Log(int threadId, int userID, string type)
- {
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("INSERT INTO group_forums_logs (thread_id, user_id, type) VALUES (@a, @duid, @type)");
- adap.AddParameter("type", type);
- adap.AddParameter("a", threadId);
- adap.AddParameter("duid", DeleterUserId);
- adap.RunQuery();
- }
- }
- public void Save()
- {
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("UPDATE group_forums_threads SET pinned = '@pinned', locked ='@locked', deleted_level = @dl, deleter_user_id = @duid WHERE id = @id");
- adap.AddParameter("pinned", Pinned ? 1 : 0);
- adap.AddParameter("locked", Locked ? 1 : 0);
- adap.AddParameter("dl", DeletedLevel);
- adap.AddParameter("duid", DeleterUserId);
- adap.AddParameter("id", Id);
- adap.RunQuery();
- }
- }
- }
- }
- [/CODE]
- GroupForumThreadPost.cs
- [CODE]using Plus.Communication.Packets.Outgoing;
- using Plus.HabboHotel.Users;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using Plus.Database.Interfaces;
- using System.Text;
- using System.Threading.Tasks;
- using Plus.HabboHotel.GameClients;
- namespace Plus.HabboHotel.Groups.Forums
- {
- public class GroupForumThreadPost
- {
- public int Id;
- public int UserId;
- public int Timestamp;
- public string Message;
- public int DeleterId;
- public int DeletedLevel;
- public GroupForumThread ParentThread;
- public GroupForumThreadPost(GroupForumThread parent, int id, int userid, int timestamp, string message, int deletedlevel, int deleterid)
- {
- ParentThread = parent;
- Id = id;
- UserId = userid;
- Timestamp = timestamp;
- Message = message;
- DeleterId = deleterid;
- DeletedLevel = deletedlevel;
- }
- public Habbo GetDeleter()
- {
- return PlusEnvironment.GetHabboById(DeleterId);
- }
- public Habbo GetAuthor()
- {
- return PlusEnvironment.GetHabboById(UserId);
- }
- public void SerializeData(GameClient Session, ServerPacket Packet)
- {
- var User = GetAuthor();
- var oculterData = GetDeleter();
- Packet.WriteInteger(Id);
- Packet.WriteInteger(ParentThread.Posts.IndexOf(this));
- Packet.WriteInteger(User.Id);
- Packet.WriteString(User.Username);
- Packet.WriteString(User.Look);
- Packet.WriteInteger((int)(PlusEnvironment.GetUnixTimestamp() - Timestamp));
- Packet.WriteString(Message.Replace("{username}", Session.GetHabbo().Username));
- Packet.WriteByte(DeletedLevel * 10);
- Packet.WriteInteger(oculterData != null ? oculterData.Id : 0);
- Packet.WriteString(oculterData != null ? oculterData.Username : "Unknown");
- Packet.WriteInteger(242342340);
- Packet.WriteInteger(ParentThread.GetUserPosts(User.Id).Count);
- }
- public void Log(int postID, int userID, string type)
- {
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("INSERT INTO group_forums_logs (thread_id, user_id, type) VALUES (@a, @duid, @type)");
- adap.AddParameter("type", type);
- adap.AddParameter("a", postID);
- adap.AddParameter("duid", userID);
- adap.RunQuery();
- }
- }
- internal void Save()
- {
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("UPDATE group_forums_thread_views SET deleted_level = @dl, deleter_user_id = @duid WHERE id = @id");
- adap.AddParameter("dl", DeletedLevel);
- adap.AddParameter("duid", DeleterId);
- adap.AddParameter("id", Id);
- adap.RunQuery();
- }
- }
- }
- }
- [/CODE]
- GroupForumThreadPostView.cs
- [CODE]using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Plus.HabboHotel.Groups.Forums
- {
- public class GroupForumThreadPostView
- {
- public int Id;
- public int UserId;
- public int Count;
- public GroupForumThreadPostView(int id, int userid, int count)
- {
- Id = id;
- UserId = userid;
- Count = count;
- }
- }
- }[/CODE]
- ok, now for the rest.
- Goto PacketManager then add this.RegisterGroupForums(); then this
- [CODE]private void RegisterGroupForums()
- {
- this._incomingPackets.Add(ClientPacketHeader.GetForumsListDataMessageEvent, new GetForumsListDataEvent());
- this._incomingPackets.Add(ClientPacketHeader.GetForumStatsMessageEvent, new GetForumStatsEvent());
- this._incomingPackets.Add(ClientPacketHeader.GetThreadsListDataMessageEvent, new GetThreadsListDataEvent());
- this._incomingPackets.Add(ClientPacketHeader.GetThreadDataMessageEvent, new GetThreadDataEvent());
- this._incomingPackets.Add(ClientPacketHeader.PostGroupContentMessageEvent, new PostGroupContentEvent());
- this._incomingPackets.Add(ClientPacketHeader.DeleteGroupThreadMessageEvent, new DeleteGroupThreadEvent());
- this._incomingPackets.Add(ClientPacketHeader.UpdateForumReadMarkerMessageEvent, new UpdateForumReadMarkerEvent());
- this._incomingPackets.Add(ClientPacketHeader.UpdateForumSettingsMessageEvent, new UpdateForumSettingsEvent());
- this._incomingPackets.Add(ClientPacketHeader.UpdateForumThreadStatusMessageEvent, new UpdateForumThreadStatusEvent());
- this._incomingPackets.Add(ClientPacketHeader.DeleteGroupPostMessageEvent, new DeleteGroupPostEvent());
- }[/CODE]
- Ok, in COmmunication->Packets->incoming->Groups
- Add these files.
- GetForumsListDataEvent.cs
- [CODE]using Plus.Communication.Packets.Outgoing;
- using Plus.Communication.Packets.Outgoing.Groups;
- using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using Plus.Database.Interfaces;
- using System.Collections.Generic;
- using System.Data;
- namespace Plus.Communication.Packets.Incoming.Groups
- {
- class GetForumsListDataEvent : IPacketEvent
- {
- public void Parse(GameClient Session, ClientPacket Packet)
- {
- var int1 = Packet.PopInt();
- var int2 = Packet.PopInt();
- int int3 = Packet.PopInt();
- var forums = new List<GroupForum>();
- DataTable table;
- switch (int1)
- {
- case 2:
- var Forums = PlusEnvironment.GetGame().GetGroupForumManager().GetForumsByUserId(Session.GetHabbo().Id);
- if (Forums.Count - 1 >= int2)
- {
- Forums = Forums.GetRange(int2, Math.Min(int3, Forums.Count));
- }
- Session.SendMessage(new ForumsListDataComposer(Forums, Session, int1, int2, int3));
- return;
- case 0:
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("SELECT g.id FROM groups as g INNER JOIN group_forums_thread_posts as posts, group_forums_threads as threads WHERE posts.thread_id = threads.id AND @now - posts.`timestamp`<= @Sdays AND threads.forum_id = g.id GROUP BY g.id ORDER BY posts.`timestamp` DESC LIMIT @Index, @LiMiT");
- adap.AddParameter("limit", int3);
- adap.AddParameter("index", int2);
- adap.AddParameter("now", (int)PlusEnvironment.GetUnixTimestamp());
- adap.AddParameter("sdays", (60 * 60 * 24 * 7));
- table = adap.getTable();
- }
- foreach (DataRow Row in table.Rows)
- {
- GroupForum forum;
- if (PlusEnvironment.GetGame().GetGroupForumManager().TryGetForum(Convert.ToInt32(Row["id"]), out forum))
- forums.Add(forum);
- }
- break;
- case 1:
- using (IQueryAdapter adap = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- adap.SetQuery("SELECT g.id FROM groups as g INNER JOIN group_forums_thread_views as v, group_forums_threads as threads WHERE v.thread_id = threads.id AND threads.forum_id = g.id AND @now - v.`timestamp` <= @Sdays GROUP BY g.id ORDER BY v.`timestamp` DESC LIMIT @Index, @LiMiT");
- adap.AddParameter("limit", int3);
- adap.AddParameter("index", int2);
- adap.AddParameter("now", (int)PlusEnvironment.GetUnixTimestamp());
- adap.AddParameter("sdays", (60 * 60 * 24 * 7));
- table = adap.getTable();
- }
- foreach (DataRow Row in table.Rows)
- {
- GroupForum forum;
- if (PlusEnvironment.GetGame().GetGroupForumManager().TryGetForum(Convert.ToInt32(Row["id"]), out forum))
- forums.Add(forum);
- }
- break;
- }
- Session.SendMessage(new ForumsListDataComposer(forums, Session, int1, int2, int3));
- }
- }
- }
- [/CODE]
- GetForumStatsEvent.cs
- [CODE]using Plus.Communication.Packets.Outgoing;
- using Plus.Communication.Packets.Outgoing.Groups;
- using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Incoming.Groups
- {
- class GetForumStatsEvent : IPacketEvent
- {
- public void Parse(GameClient Session, ClientPacket Packet)
- {
- var GroupForumId = Packet.PopInt();
- GroupForum Forum;
- if (!PlusEnvironment.GetGame().GetGroupForumManager().TryGetForum(GroupForumId, out Forum))
- {
- Session.SendNotification("Oops, There was a problem. Contact Staff to resolve this.");
- return;
- }
- Session.SendMessage(new ForumDataComposer(Forum, Session));
- }
- }
- }
- [/CODE]
- GetThreadDataEvent.cs
- [CODE]
- using Plus.Communication.Packets.Outgoing.Groups;
- using Plus.HabboHotel.GameClients;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Incoming.Groups
- {
- class GetThreadDataEvent : IPacketEvent
- {
- public void Parse(GameClient Session, ClientPacket Packet)
- {
- var ForumId = Packet.PopInt();
- var ThreadId = Packet.PopInt();
- var StartIndex = Packet.PopInt();
- var length = Packet.PopInt();
- var Forum = PlusEnvironment.GetGame().GetGroupForumManager().GetForum(ForumId);
- if (Forum == null)
- {
- return;
- }
- var Thread = Forum.GetThread(ThreadId);
- if (Thread == null)
- {
- return;
- }
- Session.SendMessage(new ThreadDataComposer(Session, Thread, StartIndex, length));
- }
- }
- }
- [/CODE]
- GetThreadListDataEvent.cs
- [CODE]using Plus.Communication.Packets.Outgoing;
- using Plus.Communication.Packets.Outgoing.Groups;
- using Plus.HabboHotel.GameClients;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Plus.HabboHotel.Groups.Forums;
- namespace Plus.Communication.Packets.Incoming.Groups
- {
- class GetThreadsListDataEvent : IPacketEvent
- {
- public void Parse(GameClient Session, ClientPacket Packet)
- {
- var ForumId = Packet.PopInt();
- var Int2 = Packet.PopInt();
- var Int3 = Packet.PopInt();
- var Forum = PlusEnvironment.GetGame().GetGroupForumManager().GetForum(ForumId);
- if (Forum == null)
- {
- return;
- }
- Session.SendMessage(new ThreadsListDataComposer(Forum, Session, Int2, Int3));
- }
- }
- }
- [/CODE]
- UpdateForumReadMarkerEvent.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Incoming.Groups
- {
- class UpdateForumReadMarkerEvent : IPacketEvent
- {
- public void Parse(GameClient Session, ClientPacket Packet)
- {
- var length = Packet.PopInt();
- for (var i = 0; i < length; i++)
- {
- var forumid = Packet.PopInt();
- var postid = Packet.PopInt();
- var readall = Packet.PopBoolean();
- var forum = PlusEnvironment.GetGame().GetGroupForumManager().GetForum(forumid);
- if (forum == null)
- continue;
- var post = forum.GetPost(postid);
- if (post == null)
- continue;
- var thread = post.ParentThread;
- var index = thread.Posts.IndexOf(post);
- thread.AddView(Session.GetHabbo().Id, index + 1);
- }
- //TODO thread.AddView(Session.GetHabbo().Id);
- }
- }
- }
- [/CODE]
- UpdateForumSettingsEvent.cs
- [CODE]using Plus.Communication.Packets.Outgoing.Groups;
- using Plus.HabboHotel.GameClients;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Incoming.Groups
- {
- class UpdateForumSettingsEvent : IPacketEvent
- {
- public void Parse(GameClient Session, ClientPacket Packet)
- {
- var ForumId = Packet.PopInt();
- var WhoCanRead = Packet.PopInt();
- var WhoCanReply = Packet.PopInt();
- var WhoCanPost = Packet.PopInt();
- var WhoCanMod = Packet.PopInt();
- var forum = PlusEnvironment.GetGame().GetGroupForumManager().GetForum(ForumId);
- if (forum == null)
- {
- Session.SendNotification("Forum not found 404!");
- return;
- }
- if (forum.Settings.GetReasonForNot(Session, forum.Settings.WhoCanModerate) != "")
- {
- Session.SendNotification("Can't update thread, you don't have the correct rights!");
- return;
- }
- forum.Settings.WhoCanRead = WhoCanRead;
- forum.Settings.WhoCanModerate = WhoCanMod;
- forum.Settings.WhoCanPost = WhoCanReply;
- forum.Settings.WhoCanInitDiscussions = WhoCanPost;
- forum.Settings.Save();
- PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(Session, "ACH_SelfModRoomFilterSeen", 1);
- Session.SendMessage(new ForumDataComposer(forum, Session));
- Session.SendMessage(new ThreadsListDataComposer(forum, Session));
- }
- }
- }
- [/CODE]
- UpdateForumThreadStatusEvent.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Incoming.Groups
- {
- public class UpdateForumThreadStatusEvent : IPacketEvent
- {
- public void Parse(GameClient Session, ClientPacket Packet)
- {
- var ForumID = Packet.PopInt();
- var ThreadID = Packet.PopInt();
- var Pinned = Packet.PopBoolean();
- var Locked = Packet.PopBoolean();
- var forum = PlusEnvironment.GetGame().GetGroupForumManager().GetForum(ForumID);
- var thread = forum.GetThread(ThreadID);
- if (forum.Settings.GetReasonForNot(Session, forum.Settings.WhoCanModerate) != "")
- {
- Session.SendNotification("You are not admin on this Thread!");
- return;
- }
- bool isPining = thread.Pinned != Pinned,
- isLocking = thread.Locked != Locked;
- thread.Pinned = Pinned;
- thread.Locked = Locked;
- thread.Save();
- Session.SendMessage(new Outgoing.Groups.ThreadUpdatedComposer(Session, thread));
- if (isPining)
- if (Pinned)
- Session.SendMessage(new Outgoing.Rooms.Notifications.RoomNotificationComposer("forums.thread.pinned"));
- else
- Session.SendMessage(new Outgoing.Rooms.Notifications.RoomNotificationComposer("forums.thread.unpinned"));
- if (isLocking)
- if (Locked)
- Session.SendMessage(new Outgoing.Rooms.Notifications.RoomNotificationComposer("forums.thread.locked"));
- else
- Session.SendMessage(new Outgoing.Rooms.Notifications.RoomNotificationComposer("forums.thread.unlocked"));
- }
- }
- }
- [/CODE]
- Ok, incoming is done. Now for Outgoing add these to the folder Groups.
- ForumDataComposer.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Outgoing.Groups
- {
- class ForumDataComposer : ServerPacket
- {
- public ForumDataComposer(GroupForum Forum, GameClient Session)
- : base(ServerPacketHeader.ForumDataMessageComposer)
- {
- base.WriteInteger(Forum.Id);
- base.WriteString(Forum.Group.Name);
- base.WriteString(Forum.Group.Description);
- base.WriteString(Forum.Group.Badge);
- base.WriteInteger(Forum.Threads.Count);
- base.WriteInteger(0);
- base.WriteInteger(0);
- base.WriteInteger(0);
- base.WriteInteger(0);
- base.WriteInteger(0);
- base.WriteString("not_member");
- base.WriteInteger(0);
- base.WriteInteger(Forum.Settings.WhoCanRead);
- base.WriteInteger(Forum.Settings.WhoCanPost);
- base.WriteInteger(Forum.Settings.WhoCanInitDiscussions);
- base.WriteInteger(Forum.Settings.WhoCanModerate);
- base.WriteString(Forum.Settings.GetReasonForNot(Session, Forum.Settings.WhoCanRead));
- base.WriteString(Forum.Settings.GetReasonForNot(Session, Forum.Settings.WhoCanPost));
- base.WriteString(Forum.Settings.GetReasonForNot(Session, Forum.Settings.WhoCanInitDiscussions));
- base.WriteString(Forum.Settings.GetReasonForNot(Session, Forum.Settings.WhoCanModerate));
- base.WriteString("-System");
- base.WriteBoolean(Forum.Group.CreatorId == Session.GetHabbo().Id);
- base.WriteBoolean(Forum.Group.IsAdmin(Session.GetHabbo().Id) && Forum.Settings.GetReasonForNot(Session, Forum.Settings.WhoCanModerate) == "");
- }
- }
- }
- [/CODE]
- ForumsListDataComposer.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Outgoing.Groups
- {
- class ForumsListDataComposer : ServerPacket
- {
- public ForumsListDataComposer(ICollection<GroupForum> Forums, GameClient Session, int ViewOrder = 0, int StartIndex = 0, int MaxLength = 20)
- : base(ServerPacketHeader.ForumsListDataMessageComposer)
- {
- base.WriteInteger(ViewOrder);
- base.WriteInteger(StartIndex);
- base.WriteInteger(StartIndex);
- base.WriteInteger(Forums.Count());
- foreach (var Forum in Forums)
- {
- var lastpost = Forum.GetLastPost();
- var isn = lastpost == null;
- base.WriteInteger(Forum.Id);
- base.WriteString(Forum.Name);
- base.WriteString(Forum.Description);
- base.WriteString(Forum.Group.Badge);
- base.WriteInteger(0);
- base.WriteInteger(0);
- base.WriteInteger(Forum.MessagesCount);
- base.WriteInteger(Forum.UnreadMessages(Session.GetHabbo().Id));
- base.WriteInteger(0);
- base.WriteInteger(!isn ? lastpost.GetAuthor().Id : 0);
- base.WriteString(!isn ? lastpost.GetAuthor().Username : "");
- base.WriteInteger(!isn ? (int)PlusEnvironment.GetUnixTimestamp() - lastpost.Timestamp : 0);
- }
- }
- }
- }
- [/CODE]
- PostUpdatedComposer.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Outgoing.Groups
- {
- class PostUpdatedComposer : ServerPacket
- {
- public PostUpdatedComposer(GameClient Session, GroupForumThreadPost Post)
- : base(ServerPacketHeader.PostUpdatedMessageComposer)
- {
- base.WriteInteger(Post.ParentThread.ParentForum.Id);
- base.WriteInteger(Post.ParentThread.Id);
- Post.SerializeData(Session, this);
- }
- }
- }
- [/CODE]
- ThreadCreatedComposer.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Outgoing.Groups
- {
- public class ThreadCreatedComposer : ServerPacket
- {
- public ThreadCreatedComposer(GameClient Session, GroupForumThread Thread)
- : base(ServerPacketHeader.ThreadCreatedMessageComposer)
- {
- base.WriteInteger(Thread.ParentForum.Id);
- base.WriteInteger(Thread.Id);
- base.WriteInteger(Thread.GetAuthor().Id);
- base.WriteString(Thread.GetAuthor().Username);
- base.WriteString(Thread.Caption);
- base.WriteBoolean(false);
- base.WriteBoolean(false);
- base.WriteInteger(1);
- base.WriteInteger(Thread.Posts.Count);
- base.WriteInteger(Thread.GetUnreadMessages(Session.GetHabbo().Id));
- base.WriteInteger(0);
- base.WriteInteger(0);
- base.WriteString("Unknown");
- base.WriteInteger(65);
- base.WriteByte(0);
- base.WriteInteger(10);
- base.WriteString("Str4");
- base.WriteInteger(11);
- }
- }
- }
- [/CODE]
- ThreadDataComposer.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Outgoing.Groups
- {
- class ThreadDataComposer : ServerPacket
- {
- public ThreadDataComposer(GameClient session, GroupForumThread Thread, int StartIndex, int MaxLength)
- : base(ServerPacketHeader.ThreadDataMessageComposer)
- {
- base.WriteInteger(Thread.ParentForum.Id);
- base.WriteInteger(Thread.Id);
- base.WriteInteger(StartIndex);
- base.WriteInteger(Thread.Posts.Count);
- foreach (var Post in Thread.Posts)
- {
- Post.SerializeData(session, this);
- }
- }
- }
- }
- [/CODE]
- ThreadReplyComposer.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Outgoing.Groups
- {
- class ThreadReplyComposer : ServerPacket
- {
- public ThreadReplyComposer(GameClient Session, GroupForumThreadPost Post)
- : base(ServerPacketHeader.ThreadReplyMessageComposer)
- {
- var User = Post.GetAuthor();
- base.WriteInteger(Post.ParentThread.ParentForum.Id);
- base.WriteInteger(Post.ParentThread.Id);
- base.WriteInteger(Post.Id);
- base.WriteInteger(Post.ParentThread.Posts.IndexOf(Post));
- base.WriteInteger(User.Id);
- base.WriteString(User.Username);
- base.WriteString(User.Look);
- base.WriteInteger((int)(PlusEnvironment.GetUnixTimestamp() - Post.Timestamp));
- base.WriteString(Post.Message);
- base.WriteByte(0);
- base.WriteInteger(0);
- base.WriteString("");
- base.WriteInteger(10);
- base.WriteInteger(Post.ParentThread.GetUserPosts(User.Id).Count);
- }
- }
- }
- [/CODE]
- ThreadListDataComposer.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Outgoing.Groups
- {
- class ThreadsListDataComposer : ServerPacket
- {
- public ThreadsListDataComposer(GroupForum Forum, GameClient Session, int StartIndex = 0, int MaxLength = 20)
- : base(ServerPacketHeader.ThreadsListDataMessageComposer)
- {
- base.WriteInteger(Forum.GroupId);
- base.WriteInteger(StartIndex);
- var Threads = Forum.Threads;
- if (Threads.Count - 1 >= StartIndex)
- Threads = Threads.GetRange(StartIndex, Math.Min(MaxLength, Threads.Count - StartIndex));
- base.WriteInteger(Threads.Count);
- foreach (var Thread in Threads)
- {
- Thread.SerializeData(Session, this);
- }
- }
- }
- }
- [/CODE]
- ThreadUpdatedComposer.cs
- [CODE]using Plus.HabboHotel.GameClients;
- using Plus.HabboHotel.Groups.Forums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Plus.Communication.Packets.Outgoing.Groups
- {
- class ThreadUpdatedComposer : ServerPacket
- {
- public ThreadUpdatedComposer(GameClient Session, GroupForumThread Thread)
- : base(ServerPacketHeader.ThreadUpdatedMessageComposer)
- {
- base.WriteInteger(Thread.ParentForum.Id);
- Thread.SerializeData(Session, this);
- }
- }
- }
- [/CODE]
- Ok, now goto Game.cs and add
- [CODE]private readonly GroupForumManager _groupForumManager;
- [/CODE]
- Then inside Game() Add
- [CODE] this._groupForumManager = new GroupForumManager();
- [/CODE]
- [CODE] public GroupForumManager GetGroupForumManager()
- {
- return _groupForumManager;
- }[/CODE]
- Ok, ServerPacketHeader.cs
- [CODE] public const int ForumsListDataMessageComposer = 1539;//3596
- public const int ForumDataMessageComposer = 91;//254
- public const int ThreadCreatedMessageComposer = 2675;//3683
- public const int ThreadDataMessageComposer = 2526;//879
- public const int ThreadsListDataMessageComposer = 1056;//1538
- public const int ThreadUpdatedMessageComposer = 951;//3226
- public const int ThreadReplyMessageComposer = 1003;//1936[/CODE]
- ClientPacketHeader.cs
- [CODE] public const int PostGroupContentMessageEvent = 1499;//477
- public const int GetForumStatsMessageEvent = 1126;//872
- public const int UpdateForumReadMarkerMessageEvent = 1659;
- public const int UpdateForumSettingsMessageEvent = 3295;//931
- public const int UpdateForumThreadStatusMessageEvent = 2980;
- public const int GetForumUserProfileMessageEvent = 3515;//2639
- public const int GetForumsListDataMessageEvent = 3802;//3912
- [/CODE]
- Then goto groupManager and replace TryGetGroup() with this.
- [CODE]public bool TryGetGroup(int id, out Group Group)
- {
- Group = null;
- if (this._groups.ContainsKey(id))
- return this._groups.TryGetValue(id, out Group);
- lock (this._groupLoadingSync)
- {
- if (this._groups.ContainsKey(id))
- return this._groups.TryGetValue(id, out Group);
- DataRow Row = null;
- using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("SELECT * FROM `groups` WHERE `id` = @id LIMIT 1");
- dbClient.AddParameter("id", id);
- Row = dbClient.getRow();
- if (Row != null)
- {
- Group = new Group(
- Convert.ToInt32(Row["id"]), Convert.ToString(Row["name"]), Convert.ToString(Row["desc"]), Convert.ToString(Row["badge"]), Convert.ToInt32(Row["room_id"]), Convert.ToInt32(Row["owner_id"]),
- Convert.ToInt32(Row["created"]), Convert.ToInt32(Row["state"]), Convert.ToInt32(Row["colour1"]), Convert.ToInt32(Row["colour2"]), Convert.ToInt32(Row["admindeco"]), Convert.ToInt32(Row["has_forum"]) == 1, Convert.ToInt32(Row["has_chat"]) == 1);
- this._groups.TryAdd(Group.Id, Group);
- return true;
- }
- }
- }
- return false;
- }[/CODE]
- then goto your Groups tabe and add has_forum enum '0','1' default '0'.
- I'll post Queries in a minute.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement