Group forums

This commit is contained in:
Beny 2019-05-10 18:45:07 -04:00
parent 1283c02937
commit 7606dcad35
40 changed files with 1450 additions and 1134 deletions

View File

@ -0,0 +1,66 @@
#DATABASE UPDATE: 2.0.0 -> DEV
ALTER TABLE `guilds_forums` RENAME TO `old_guilds_forums`;
ALTER TABLE `guilds_forums_comments` RENAME TO `old_guilds_forums_comments`;
DROP TABLE IF EXISTS `guilds_forums_comments`;
CREATE TABLE `guilds_forums_comments` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`thread_id` int(11) NOT NULL DEFAULT 0,
`user_id` int(11) NOT NULL DEFAULT 0,
`message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
`created_at` int(11) NOT NULL DEFAULT 0,
`state` int(11) NOT NULL DEFAULT 0,
`admin_id` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Compact;
CREATE TABLE `guilds_forums_threads` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`guild_id` int(11) NULL DEFAULT 0,
`opener_id` int(11) NULL DEFAULT 0,
`subject` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT '',
`posts_count` int(11) NULL DEFAULT 0,
`created_at` int(11) NULL DEFAULT 0,
`updated_at` int(11) NULL DEFAULT 0,
`state` int(11) NULL DEFAULT 0,
`pinned` tinyint(4) NULL DEFAULT 0,
`locked` tinyint(4) NULL DEFAULT 0,
`admin_id` int(11) NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Compact;
DROP PROCEDURE IF EXISTS MIGRATION_FORUMS;
DELIMITER ;;
CREATE PROCEDURE MIGRATION_FORUMS()
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
SELECT COUNT(*) FROM `old_guilds_forums` INTO n;
SET i=0;
WHILE i<n DO
SET @old_id = (SELECT id FROM `old_guilds_forums` LIMIT i,1);
INSERT INTO `guilds_forums_threads` (`guild_id`, `opener_id`, `subject`, `posts_count`, `created_at`, `updated_at`, `state`, `pinned`, `locked`, `admin_id`)
SELECT `guild_id`, `user_id`, `subject`, 0 AS `posts_count`, `timestamp`, `timestamp`, IF(STRCMP(`state`,'OPEN')=0, 0, IF(STRCMP(`state`,'HIDDEN_BY_ADMIN')=0, 10, IF(STRCMP(`state`,'HIDDEN_BY_STAFF')=0, 20, 1))) AS `state`, IF(STRCMP(`pinned`,'1')=0, 1, 0), IF(STRCMP(`locked`,'1')=0, 1, 0), `admin_id` FROM `old_guilds_forums`
LIMIT i,1;
SET @new_id = LAST_INSERT_ID();
INSERT INTO `guilds_forums_comments` (`thread_id`, `user_id`, `message`, `created_at`, `state`, `admin_id`)
SELECT @new_id AS `thread_id`, `user_id`, `message`, `timestamp`, IF(STRCMP(`state`,'OPEN')=0, 0, IF(STRCMP(`state`,'HIDDEN_BY_ADMIN')=0, 10, IF(STRCMP(`state`,'HIDDEN_BY_STAFF')=0, 20, 1))) AS `state`, `admin_id` FROM `old_guilds_forums_comments`
WHERE thread_id = @old_id;
SET i = i + 1;
END WHILE;
END;
;;
DELIMITER ;
CALL MIGRATION_FORUMS();
DROP PROCEDURE IF EXISTS MIGRATION_FORUMS;
UPDATE `users_pets` LEFT JOIN `rooms` ON `users_pets`.`room_id` = `rooms`.`id` SET `users_pets`.`room_id` = 0 WHERE `users_pets`.`room_id` != 0 AND `rooms`.`id` IS NULL;
#END DATABASE UPDATE: 2.0.0 -> DEV

View File

@ -1,6 +1,7 @@
package com.eu.habbo.core;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.incoming.friends.SearchUserEvent;
import com.eu.habbo.messages.incoming.navigator.SearchRoomsEvent;
@ -107,7 +108,7 @@ public class CleanerThread implements Runnable {
if (time - LAST_INACTIVE_GUILDS_CLEARED > REMOVE_INACTIVE_GUILDS)
{
Emulator.getGameEnvironment().getGuildManager().clearInactiveGuilds();
Emulator.getGameEnvironment().getGuildForumManager().clearInactiveForums();
ForumThread.clearCache();
LAST_INACTIVE_GUILDS_CLEARED = time;
}

View File

@ -11,7 +11,6 @@ import com.eu.habbo.habbohotel.commands.CommandHandler;
import com.eu.habbo.habbohotel.crafting.CraftingManager;
import com.eu.habbo.habbohotel.guides.GuideManager;
import com.eu.habbo.habbohotel.guilds.GuildManager;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumManager;
import com.eu.habbo.habbohotel.hotelview.HotelViewManager;
import com.eu.habbo.habbohotel.items.ItemManager;
import com.eu.habbo.habbohotel.modtool.ModToolManager;
@ -28,7 +27,6 @@ public class GameEnvironment
private HabboManager habboManager;
private NavigatorManager navigatorManager;
private GuildManager guildManager;
private GuildForumManager guildForumManager;
private ItemManager itemManager;
private CatalogManager catalogManager;
private HotelViewManager hotelViewManager;
@ -60,7 +58,6 @@ public class GameEnvironment
this.botManager = new BotManager();
this.petManager = new PetManager();
this.guildManager = new GuildManager();
this.guildForumManager = new GuildForumManager();
this.catalogManager = new CatalogManager();
this.roomManager = new RoomManager();
this.navigatorManager = new NavigatorManager();
@ -116,11 +113,6 @@ public class GameEnvironment
return this.guildManager;
}
public GuildForumManager getGuildForumManager()
{
return this.guildForumManager;
}
public ItemManager getItemManager()
{
return this.itemManager;

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.catalog.layouts.*;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.items.FurnitureType;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.SoundTrack;
@ -1229,18 +1230,12 @@ public class CatalogManager
itemsList.add(habboItem);
if(baseItem.getName().equals("guild_forum")) {
Emulator.getGameEnvironment().getGuildManager().getGuild(guildId).setForum(true);
Emulator.getGameEnvironment().getGuildManager().getGuild(guildId).needsUpdate = true;
Emulator.getGameEnvironment().getGuildForumManager().addGuildForum(guildId);
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds SET forum = '1' WHERE id = ?"))
{
statement.setInt(1, guildId);
statement.execute();
}
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
if(guild != null) {
guild.setForum(true);
guild.needsUpdate = true;
guild.run();
}
}
}

View File

@ -114,7 +114,7 @@ public class Guild implements Runnable
{
if(this.needsUpdate)
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds SET name = ?, description = ?, state = ?, rights = ?, color_one = ?, color_two = ?, badge = ?, read_forum = ?, post_messages = ?, post_threads = ?, mod_forum = ? WHERE id = ?"))
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds SET name = ?, description = ?, state = ?, rights = ?, color_one = ?, color_two = ?, badge = ?, read_forum = ?, post_messages = ?, post_threads = ?, mod_forum = ?, forum = ? WHERE id = ?"))
{
statement.setString(1, this.name);
statement.setString(2, this.description);
@ -127,7 +127,8 @@ public class Guild implements Runnable
statement.setString(9, this.postMessages.name());
statement.setString(10, this.postThreads.name());
statement.setString(11, this.modForum.name());
statement.setInt(12, this.id);
statement.setString(12, this.forum ? "1" : "0");
statement.setInt(13, this.id);
statement.execute();
this.needsUpdate = false;

View File

@ -23,7 +23,6 @@ public class GuildManager {
private final THashMap<GuildPartType, THashMap<Integer, GuildPart>> guildParts;
private final TIntObjectMap<Guild> guilds;
public GuildManager() {
@ -40,7 +39,7 @@ public class GuildManager {
this.guildParts.clear();
for (GuildPartType t : GuildPartType.values()) {
this.guildParts.put(t, new THashMap<Integer, GuildPart>());
this.guildParts.put(t, new THashMap<>());
}
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();

View File

@ -0,0 +1,478 @@
package com.eu.habbo.habbohotel.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.plugin.events.guilds.forums.GuildForumThreadBeforeCreated;
import com.eu.habbo.plugin.events.guilds.forums.GuildForumThreadCreated;
import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
import java.sql.*;
import java.util.*;
public class ForumThread implements Runnable, ISerialize {
private final int threadId;
private final int guildId;
private final int openerId;
private final String subject;
private int postsCount;
private final int createdAt;
private int updatedAt;
private ForumThreadState state;
private boolean pinned;
private boolean locked;
private int adminId;
private boolean needsUpdate;
private boolean hasCommentsLoaded;
private final THashMap<Integer, ForumThreadComment> comments;
private int commentIndex;
private ForumThreadComment lastComment;
private final static THashMap<Integer, THashSet<ForumThread>> guildThreadsCache = new THashMap<>();
private final static THashMap<Integer, ForumThread> forumThreadsCache = new THashMap<>();
public ForumThread(int threadId, int guildId, int openerId, String subject, int postsCount, int createdAt, int updatedAt, ForumThreadState state, boolean pinned, boolean locked, int adminId, ForumThreadComment lastComment) {
this.threadId = threadId;
this.guildId = guildId;
this.openerId = openerId;
this.subject = subject;
this.postsCount = postsCount;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.state = state;
this.pinned = pinned;
this.locked = locked;
this.adminId = adminId;
this.lastComment = lastComment;
this.comments = new THashMap<>();
this.needsUpdate = false;
this.hasCommentsLoaded = false;
this.commentIndex = 0;
}
public ForumThread(ResultSet set) throws SQLException {
this.threadId = set.getInt("id");
this.guildId = set.getInt("guild_id");
this.openerId = set.getInt("opener_id");
this.subject = set.getString("subject");
this.postsCount = set.getInt("posts_count");
this.createdAt = set.getInt("created_at");
this.updatedAt = set.getInt("updated_at");
this.state = ForumThreadState.fromValue(set.getInt("state"));
this.pinned = set.getInt("pinned") > 0;
this.locked = set.getInt("locked") > 0;
this.adminId = set.getInt("admin_id");
this.lastComment = null;
try {
this.lastComment = ForumThreadComment.getById(set.getInt("last_comment_id"));
}
catch (Exception e) { }
this.comments = new THashMap<>();
this.needsUpdate = false;
this.hasCommentsLoaded = false;
this.commentIndex = 0;
}
public int getThreadId() {
return threadId;
}
public int getGuildId() {
return guildId;
}
public int getOpenerId() {
return openerId;
}
public String getSubject() {
return subject;
}
public int getCreatedAt() {
return createdAt;
}
public int getPostsCount() {
return postsCount;
}
public void setPostsCount(int postsCount) {
this.postsCount = postsCount;
this.needsUpdate = true;
}
public int getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(int updatedAt) {
this.updatedAt = updatedAt;
this.needsUpdate = true;
}
public ForumThreadState getState() {
return state;
}
public void setState(ForumThreadState state) {
this.state = state;
this.needsUpdate = true;
}
public boolean isPinned() {
return pinned;
}
public void setPinned(boolean pinned) {
this.pinned = pinned;
this.needsUpdate = true;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
this.needsUpdate = true;
}
public int getAdminId() {
return adminId;
}
public ForumThreadComment getLastComment() {
return lastComment;
}
public void setLastComment(ForumThreadComment lastComment) {
this.lastComment = lastComment;
}
public void setAdminId(int adminId) {
this.adminId = adminId;
this.needsUpdate = true;
}
private void loadComments() {
if(this.hasCommentsLoaded)
return;
synchronized (this.comments) {
this.hasCommentsLoaded = true;
commentIndex = 0;
this.comments.clear();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM `guilds_forums_comments` WHERE `thread_id` = ? ORDER BY `id`")) {
statement.setInt(1, this.threadId);
ResultSet set = statement.executeQuery();
while (set.next()) {
ForumThreadComment comment = new ForumThreadComment(set);
addComment(comment);
}
} catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
}
}
public void addComment(ForumThreadComment comment) {
this.comments.put(comment.getCommentId(), comment);
comment.setIndex(this.commentIndex);
this.commentIndex++;
this.lastComment = comment;
}
public Collection<ForumThreadComment> getComments() {
if(!this.hasCommentsLoaded) {
loadComments();
}
return this.comments.values();
}
public Collection<ForumThreadComment> getComments(int limit, int offset) {
if(!this.hasCommentsLoaded) {
loadComments();
}
synchronized (this.comments) {
ArrayList<ForumThreadComment> limitedComments = new ArrayList<>();
List<ForumThreadComment> comments = new ArrayList<>(this.comments.values());
comments.sort(Comparator.comparingInt(ForumThreadComment::getIndex));
Iterator<ForumThreadComment> iterator = comments.iterator();
for (; offset > 0; --offset) {
if (!iterator.hasNext())
break;
iterator.next();
}
for (; limit > 0; --limit) {
if (!iterator.hasNext())
break;
limitedComments.add(iterator.next());
}
return limitedComments;
}
}
public ForumThreadComment getCommentById(int commentId) {
if(!this.hasCommentsLoaded) {
loadComments();
}
synchronized (this.comments) {
return this.comments.get(commentId);
}
}
@Override
public void serialize(ServerMessage message) {
Habbo opener = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.openerId);
Habbo admin = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.adminId);
Collection<ForumThreadComment> comments = this.getComments();
int lastSeenAt = 0;
int totalComments = comments.size();
int newComments = 0;
ForumThreadComment lastComment = this.lastComment;
if(lastComment == null) {
for (ForumThreadComment comment : comments) {
if (comment.getCreatedAt() > lastSeenAt) {
newComments++;
}
if (lastComment == null || lastComment.getCreatedAt() < comment.getCreatedAt()) {
lastComment = comment;
}
}
this.lastComment = lastComment;
}
Habbo lastAuthor = lastComment != null ? lastComment.getHabbo() : null;
int nowTimestamp = Emulator.getIntUnixTimestamp();
message.appendInt(this.threadId);
message.appendInt(this.openerId);
message.appendString(opener != null ? opener.getHabboInfo().getUsername() : "");
message.appendString(this.subject);
message.appendBoolean(this.pinned);
message.appendBoolean(this.locked);
message.appendInt(nowTimestamp - this.createdAt);
message.appendInt(totalComments); // total comments
message.appendInt(newComments); // unread comments
message.appendInt(1);
message.appendInt(lastAuthor != null ? lastAuthor.getHabboInfo().getId() : -1);
message.appendString(lastAuthor != null ? lastAuthor.getHabboInfo().getUsername() : "");
message.appendInt(nowTimestamp - (lastComment != null ? lastComment.getCreatedAt() : this.updatedAt));
message.appendByte(this.state.getStateId());
message.appendInt(this.adminId);
message.appendString(admin != null ? admin.getHabboInfo().getUsername() : "");
message.appendInt(this.threadId);
}
@Override
public void run() {
if(!this.needsUpdate)
return;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE `guilds_forums_threads` SET `posts_count` = ?, `updated_at` = ?, `state` = ?, `pinned` = ?, `locked` = ?, `admin_id` = ? WHERE `id` = ?"))
{
statement.setInt(1, this.postsCount);
statement.setInt(2, this.updatedAt);
statement.setInt(3, this.state.getStateId());
statement.setInt(4, this.pinned ? 1 : 0);
statement.setInt(5, this.locked ? 1 : 0);
statement.setInt(6, this.adminId);
statement.setInt(7, this.threadId);
statement.execute();
this.needsUpdate = false;
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
public static ForumThread create(Guild guild, Habbo opener, String subject, String message) throws Exception {
ForumThread createdThread = null;
if(Emulator.getPluginManager().fireEvent(new GuildForumThreadBeforeCreated(guild, opener, subject, message)).isCancelled())
return null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO `guilds_forums_threads`(`guild_id`, `opener_id`, `subject`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS))
{
int timestamp = Emulator.getIntUnixTimestamp();
statement.setInt(1, guild.getId());
statement.setInt(2, opener.getHabboInfo().getId());
statement.setString(3, subject);
statement.setInt(4, timestamp);
statement.setInt(5, timestamp);
if(statement.executeUpdate() < 1)
return null;
ResultSet set = statement.getGeneratedKeys();
if(set.next()) {
int threadId = set.getInt(1);
createdThread = new ForumThread(threadId, guild.getId(), opener.getHabboInfo().getId(), subject, 0, timestamp, timestamp, ForumThreadState.OPEN, false, false, 0, null);
cacheThread(createdThread);
ForumThreadComment comment = ForumThreadComment.create(createdThread, opener, message);
createdThread.addComment(comment);
Emulator.getPluginManager().fireEvent(new GuildForumThreadCreated(createdThread));
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return createdThread;
}
public static THashSet<ForumThread> getByGuildId(int guildId) throws SQLException {
THashSet<ForumThread> threads = null;
if(guildThreadsCache.containsKey(guildId)) {
guildThreadsCache.get(guildId);
}
if(threads != null)
return threads;
threads = new THashSet<ForumThread>();
guildThreadsCache.put(guildId, threads);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT A.*, B.`id` AS `last_comment_id` " +
"FROM guilds_forums_threads A " +
"JOIN (" +
"SELECT * " +
"FROM `guilds_forums_comments` " +
"WHERE `id` IN (" +
"SELECT MAX(id) " +
"FROM `guilds_forums_comments` B " +
"GROUP BY `thread_id` " +
"ORDER BY B.`id` ASC " +
") " +
"ORDER BY `id` DESC " +
") B ON A.`id` = B.`thread_id` " +
"WHERE A.`guild_id` = ? " +
"ORDER BY A.`pinned` DESC, B.`created_at` DESC "
))
{
statement.setInt(1, guildId);
ResultSet set = statement.executeQuery();
while(set.next()) {
ForumThread thread = new ForumThread(set);
synchronized (threads) {
threads.add(thread);
}
cacheThread(thread);
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return threads;
}
public static ForumThread getById(int threadId) throws SQLException {
ForumThread foundThread = forumThreadsCache.get(threadId);
if(foundThread != null)
return foundThread;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(
"SELECT A.*, B.`id` AS `last_comment_id` " +
"FROM guilds_forums_threads A " +
"JOIN (" +
"SELECT * " +
"FROM `guilds_forums_comments` " +
"WHERE `id` IN (" +
"SELECT MAX(id) " +
"FROM `guilds_forums_comments` B " +
"GROUP BY `thread_id` " +
"ORDER BY B.`id` ASC " +
") " +
"ORDER BY `id` DESC " +
") B ON A.`id` = B.`thread_id` " +
"WHERE A.`id` = ? " +
"ORDER BY A.`pinned` DESC, B.`created_at` DESC " +
"LIMIT 1"
))
{
statement.setInt(1, threadId);
ResultSet set = statement.executeQuery();
while(set.next()) {
foundThread = new ForumThread(set);
cacheThread(foundThread);
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return foundThread;
}
private static void cacheThread(ForumThread thread) {
synchronized (forumThreadsCache) {
forumThreadsCache.put(thread.threadId, thread);
}
THashSet<ForumThread> guildThreads = guildThreadsCache.get(thread.guildId);
if(guildThreads == null) {
guildThreads = new THashSet<>();
synchronized (forumThreadsCache) {
guildThreadsCache.put(thread.guildId, guildThreads);
}
}
synchronized (guildThreads) {
guildThreads.add(thread);
}
}
public static void clearCache() {
for(THashSet<ForumThread> threads : guildThreadsCache.values()) {
for(ForumThread thread : threads) {
thread.run();
}
}
synchronized (forumThreadsCache) {
forumThreadsCache.clear();
}
synchronized (guildThreadsCache) {
guildThreadsCache.clear();
}
}
}

View File

@ -0,0 +1,214 @@
package com.eu.habbo.habbohotel.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.plugin.events.guilds.forums.GuildForumThreadCommentBeforeCreated;
import com.eu.habbo.plugin.events.guilds.forums.GuildForumThreadCommentCreated;
import gnu.trove.map.hash.THashMap;
import java.sql.*;
public class ForumThreadComment implements Runnable, ISerialize {
private final int commentId;
private final int threadId;
private final int userId;
private final String message;
private final int createdAt;
private ForumThreadState state;
private int adminId;
private int index;
private boolean needsUpdate;
private static THashMap<Integer, ForumThreadComment> forumCommentsCache = new THashMap<>();
public ForumThreadComment(int commentId, int threadId, int userId, String message, int createdAt, ForumThreadState state, int adminId) {
this.commentId = commentId;
this.threadId = threadId;
this.userId = userId;
this.message = message;
this.createdAt = createdAt;
this.state = state;
this.adminId = adminId;
this.index = -1;
this.needsUpdate = false;
}
public ForumThreadComment(ResultSet set) throws SQLException {
this.commentId = set.getInt("id");
this.threadId = set.getInt("thread_id");
this.userId = set.getInt("user_id");
this.message = set.getString("message");
this.createdAt = set.getInt("created_at");
this.state = ForumThreadState.fromValue(set.getInt("state"));
this.adminId = set.getInt("admin_id");
this.index = -1;
this.needsUpdate = false;
}
public static ForumThreadComment getById(int id) {
ForumThreadComment foundComment = forumCommentsCache.get(id);
if(foundComment != null)
return foundComment;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM `guilds_forums_comments` WHERE `id` = ? LIMIT 1"))
{
statement.setInt(1, id);
ResultSet set = statement.executeQuery();
while(set.next()) {
foundComment = new ForumThreadComment(set);
cacheComment(foundComment);
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return foundComment;
}
public static void cacheComment(ForumThreadComment foundComment) {
forumCommentsCache.put(foundComment.commentId, foundComment);
}
public static void clearCache() {
forumCommentsCache.clear();
}
public int getCommentId() {
return commentId;
}
public int getThreadId() {
return threadId;
}
public int getUserId() {
return userId;
}
public String getMessage() {
return message;
}
public int getCreatedAt() {
return createdAt;
}
public ForumThreadState getState() {
return state;
}
public void setState(ForumThreadState state) {
this.state = state;
this.needsUpdate = true;
}
public int getAdminId() {
return adminId;
}
public void setAdminId(int adminId) {
this.adminId = adminId;
this.needsUpdate = true;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public Habbo getHabbo() {
return Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId);
}
public ForumThread getThread() {
try {
return ForumThread.getById(this.threadId);
} catch (SQLException e) {
return null;
}
}
@Override
public void serialize(ServerMessage message) {
HabboInfo habbo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(this.userId);
HabboInfo admin = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(this.adminId);
message.appendInt(this.commentId);
message.appendInt(this.index);
message.appendInt(this.userId);
message.appendString(habbo != null ? habbo.getUsername() : "");
message.appendString(habbo != null ? habbo.getLook() : "");
message.appendInt(Emulator.getIntUnixTimestamp() - this.createdAt);
message.appendString(this.message);
message.appendByte(this.state.getStateId());
message.appendInt(this.adminId);
message.appendString(admin != null ? admin.getUsername() : "");
message.appendInt(0); // admin action time ago?
message.appendInt(habbo != null ? habbo.getHabboStats().forumPostsCount : 0);
}
@Override
public void run() {
if(!this.needsUpdate)
return;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds_forums_comments` SET `state` = ?, `admin_id` = ? WHERE `id` = ?;"))
{
statement.setInt(1, this.state.getStateId());
statement.setInt(2, this.adminId);
statement.setInt(3, this.commentId);
statement.execute();
this.needsUpdate = false;
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
public static ForumThreadComment create(ForumThread thread, Habbo poster, String message) throws Exception {
ForumThreadComment createdComment = null;
if(Emulator.getPluginManager().fireEvent(new GuildForumThreadCommentBeforeCreated(thread, poster, message)).isCancelled())
return null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO `guilds_forums_comments`(`thread_id`, `user_id`, `message`, `created_at`) VALUES (?, ?, ?, ?);", Statement.RETURN_GENERATED_KEYS))
{
int timestamp = Emulator.getIntUnixTimestamp();
statement.setInt(1, thread.getThreadId());
statement.setInt(2, poster.getHabboInfo().getId());
statement.setString(3, message);
statement.setInt(4, timestamp);
if(statement.executeUpdate() < 1)
return null;
ResultSet set = statement.getGeneratedKeys();
if(set.next()) {
int commentId = set.getInt(1);
createdComment = new ForumThreadComment(commentId, thread.getThreadId(), poster.getHabboInfo().getId(), message, timestamp, ForumThreadState.OPEN, 0);
Emulator.getPluginManager().fireEvent(new GuildForumThreadCommentCreated(createdComment));
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
return createdComment;
}
}

View File

@ -0,0 +1,33 @@
package com.eu.habbo.habbohotel.guilds.forums;
public enum ForumThreadState {
OPEN(0),
CLOSED(1),
HIDDEN_BY_ADMIN(10),
HIDDEN_BY_STAFF(20);
private int stateId;
public int getStateId()
{
return this.stateId;
}
ForumThreadState(int stateId)
{
this.stateId = stateId;
}
public static ForumThreadState fromValue(int value)
{
for (ForumThreadState state : ForumThreadState.values())
{
if (state.stateId == value)
{
return state;
}
}
return CLOSED;
}
}

View File

@ -1,200 +0,0 @@
package com.eu.habbo.habbohotel.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class GuildForum implements ISerialize {
private final int guild;
private int totalThreads;
private final TIntObjectHashMap<GuildForumThread> threads;
private int lastRequested = Emulator.getIntUnixTimestamp();
public GuildForum(int guild) {
this.guild = guild;
this.threads = new TIntObjectHashMap<GuildForumThread>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT author.username as author_name, author.look as look, COALESCE(admin.username, '') as admin_name, guilds_forums.id as thread_id, 0 as row_number, guilds_forums.* FROM guilds_forums " +
"INNER JOIN users AS author ON author.id = user_id " +
"LEFT JOIN users AS admin ON guilds_forums.admin_id = admin.id " +
"WHERE guild_id = ?")) {
statement.setInt(1, this.guild);
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
this.threads.put(set.getInt("id"), new GuildForumThread(set));
}
}
} catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
}
public GuildForumComment getLastComment() {
if (!this.threads.valueCollection().isEmpty()) {
GuildForumThread thread = Collections.max(this.threads.valueCollection(), Comparator.comparing(GuildForumThread::getLastCommentTimestamp));
if (thread != null && thread.comments.size() > 0) {
return thread.comments.get(thread.comments.size() - 1);
}
}
return null;
}
public List<GuildForumThread> getThreads() {
return new ArrayList<>(this.threads.valueCollection());
}
public List<GuildForumThread> getThreadsByAuthor(int userId) {
return this.threads.valueCollection().stream().filter(p -> p.getAuthorId() == userId).collect(Collectors.toList());
}
public GuildForumThread getThread(int threadId) {
return threads.get(threadId);
}
public GuildForumThread createThread(Habbo habbo, String subject, String message) {
int timestamp = Emulator.getIntUnixTimestamp();
GuildForumThread thread = null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO guilds_forums (guild_id, user_id, subject, message, timestamp) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
statement.setInt(1, this.guild);
statement.setInt(2, habbo.getClient().getHabbo().getHabboInfo().getId());
statement.setString(3, subject);
statement.setString(4, message);
statement.setInt(5, timestamp);
statement.execute();
try (ResultSet set = statement.getGeneratedKeys()) {
if (set.next()) {
thread = new GuildForumThread(habbo, set.getInt(1), this.guild, subject, message, timestamp);
this.threads.put(set.getInt(1), //Thread id
thread);
}
}
} catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
return thread;
}
//TODO:
public void hideThread(int threadId) {
this.threads.get(threadId).setState(ThreadState.HIDDEN_BY_ADMIN);
}
public int getGuild() {
return this.guild;
}
int getLastRequestedTime() {
return this.lastRequested;
}
@Override
public void serialize(ServerMessage message) {
}
public void serializeThreads(final ServerMessage message) {
synchronized (this.threads) {
message.appendInt(this.threads.size());
this.threads.forEachValue(new TObjectProcedure<GuildForumThread>() {
@Override
public boolean execute(GuildForumThread thread) {
thread.serialize(message);
return true;
}
});
}
}
public int threadSize() {
synchronized (this.threads) {
return this.threads.size();
}
}
void updateLastRequested() {
this.lastRequested = Emulator.getIntUnixTimestamp();
}
public enum ThreadState {
CLOSED(0),
OPEN(1),
HIDDEN_BY_ADMIN(10), //DELETED
HIDDEN_BY_STAFF(20);
public final int state;
ThreadState(int state) {
this.state = state;
}
public static ThreadState fromValue(int state) {
switch (state) {
case 0:
return CLOSED;
case 1:
return OPEN;
case 10:
return HIDDEN_BY_ADMIN;
case 20:
return HIDDEN_BY_STAFF;
}
return OPEN;
}
}
public void serializeUserForum(ServerMessage response, Habbo habbo) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild);
GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(this.guild);
Integer amountOfComments = forum.getThreads().stream().map(GuildForumThread::getAmountOfComments).mapToInt(Integer::intValue).sum();
response.appendInt(guild.getId());
response.appendString(guild.getName());
response.appendString(guild.getDescription());
response.appendString(guild.getBadge());
response.appendInt(0);
response.appendInt(0); //Rating
response.appendInt(amountOfComments);
response.appendInt(0); //New Messages
GuildForumComment comment = this.getLastComment();
if (comment != null) {
response.appendInt(comment.getThreadId());
response.appendInt(comment.getUserId());
response.appendString(comment.getUserName());
response.appendInt(Emulator.getIntUnixTimestamp() - comment.getTimestamp());
return;
}
response.appendInt(-1);
response.appendInt(-1);
response.appendString("");
response.appendInt(0);
}
}

View File

@ -1,157 +0,0 @@
package com.eu.habbo.habbohotel.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class GuildForumComment implements ISerialize, Runnable {
private int id;
private final int guildId;
private final int threadId;
private int index = -1;
private final int userId;
private final String userName;
private final String look;
private final int timestamp;
private final String message;
private GuildForum.ThreadState state = GuildForum.ThreadState.OPEN;
private int adminId;
private String adminName;
public GuildForumComment(int guildId, int threadId, int userId, String userName, String look, String message) {
this.guildId = guildId;
this.threadId = threadId;
this.userId = userId;
this.userName = userName;
this.look = look;
this.timestamp = Emulator.getIntUnixTimestamp();
this.message = message;
this.adminName = "";
}
public GuildForumComment(final ResultSet set, int index, int guildId) throws SQLException {
this.id = set.getInt("id");
this.guildId = guildId;
this.threadId = set.getInt("thread_id");
this.index = index;
this.userId = set.getInt("user_id");
this.userName = set.getString("author_name");
this.look = set.getString("look");
this.timestamp = set.getInt("timestamp");
this.message = set.getString("message");
this.state = GuildForum.ThreadState.valueOf(set.getString("state"));
this.adminId = set.getInt("admin_id");
this.adminName = set.getString("admin_name");
}
public int getAuthorPostCount() {
GuildForum guildForum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(this.guildId);
List<GuildForumComment> matchingObjects = guildForum.getThreads().stream().flatMap(e -> e.getAllComments().stream()).collect(Collectors.toList()).stream().filter(c -> c.getUserId() == this.userId).collect(Collectors.toList());
return matchingObjects.size();
}
@Override
public void serialize(ServerMessage message) {
message.appendInt(this.id);
message.appendInt(this.index - 1);
message.appendInt(this.userId);
message.appendString(this.userName);
message.appendString(this.look);
message.appendInt(Emulator.getIntUnixTimestamp() - this.timestamp);
message.appendString(this.message);
message.appendByte(this.state.state);
message.appendInt(this.adminId);
message.appendString(this.adminName);
message.appendInt(0);
message.appendInt(this.getAuthorPostCount());
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public int getThreadId() {
return this.threadId;
}
public int getIndex() {
return this.index;
}
public void setIndex(int index) {
this.index = index;
}
public int getUserId() {
return this.userId;
}
public String getUserName() {
return this.userName;
}
public String getLook() {
return this.look;
}
public int getTimestamp() {
return this.timestamp;
}
public String getMessage() {
return this.message;
}
public GuildForum.ThreadState getState() {
return this.state;
}
public void setState(GuildForum.ThreadState state) {
this.state = state;
}
public int getAdminId() {
return this.adminId;
}
public void setAdminId(int adminId) {
this.adminId = adminId;
}
public String getAdminName() {
return this.adminName;
}
public void setAdminName(String adminName) {
this.adminName = adminName;
}
@Override
public void run() {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds_forums_comments SET state = ?, admin_id = ? WHERE id = ?")) {
statement.setString(1, this.state.name());
statement.setInt(2, this.adminId);
statement.setInt(3, this.getId());
statement.execute();
} catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
}
public int getGuildId() {
return this.guildId;
}
}

View File

@ -1,151 +0,0 @@
package com.eu.habbo.habbohotel.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.users.Habbo;
import gnu.trove.TCollections;
import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import java.util.*;
public class GuildForumManager {
private final TIntObjectMap<GuildForum> guildForums;
public void addGuildForum(int guildId) {
GuildForum forum = new GuildForum(guildId);
this.guildForums.put(guildId, forum);
}
public GuildForumManager() {
this.guildForums = TCollections.synchronizedMap(new TIntObjectHashMap<GuildForum>());
}
public GuildForum getGuildForum(int guildId) {
synchronized (this.guildForums) {
GuildForum forum = this.guildForums.get(guildId);
if (forum == null) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
if (guild != null && guild.hasForum()) {
forum = new GuildForum(guildId);
this.guildForums.put(guildId, forum);
}
}
if (forum != null) {
forum.updateLastRequested();
return forum;
}
return null;
}
}
public void clearInactiveForums() {
List<Integer> toRemove = new ArrayList<Integer>();
TIntObjectIterator<GuildForum> guildForums = this.guildForums.iterator();
for (int i = this.guildForums.size(); i-- > 0; ) {
try {
guildForums.advance();
} catch (NoSuchElementException | ConcurrentModificationException e) {
break;
}
if (guildForums.value().getLastRequestedTime() < Emulator.getIntUnixTimestamp() - 300) {
toRemove.add(guildForums.key());
}
for (Integer j : toRemove) {
this.guildForums.remove(j);
}
}
}
public List<GuildForum> getGuildForums(Habbo habbo) {
List<GuildForum> forums = new ArrayList<>();
for (Integer i : habbo.getHabboStats().guilds) {
forums.add(this.getGuildForum(i));
}
return forums;
}
public List<GuildForum> getAllForums() {
List<GuildForum> forums = new ArrayList<>();
for (Guild guild : Emulator.getGameEnvironment().getGuildManager().getAllGuilds()) {
if (guild != null && guild.hasForum()) {
forums.add(this.getGuildForum(guild.getId()));
}
}
return forums;
}
public List<GuildForum> getAllForumsWithPosts() {
List<GuildForum> forums = new ArrayList<>();
for (Guild guild : Emulator.getGameEnvironment().getGuildManager().getAllGuilds()) {
if (guild != null && guild.hasForum()) {
GuildForum forum = this.getGuildForum(guild.getId());
if (forum.getLastComment() == null)
continue;
forums.add(forum);
}
}
return forums;
}
private static final Comparator<GuildForum> SORT_ACTIVE = new Comparator<GuildForum>() {
@Override
public int compare(GuildForum o1, GuildForum o2) {
if (o2.getLastComment() == null || o2.getLastComment().getTimestamp() <= 0)
return 0;
if (o1.getLastComment() == null || o1.getLastComment().getTimestamp() <= 0)
return 0;
return o2.getLastComment().getTimestamp() - o1.getLastComment().getTimestamp();
}
};
private static final Comparator<GuildForum> SORT_VISITED = new Comparator<GuildForum>() {
@Override
public int compare(GuildForum o1, GuildForum o2) {
if (o2.getLastRequestedTime() <= 0 || o1.getLastRequestedTime() <= 0)
return 0;
return o2.getLastRequestedTime() - o1.getLastRequestedTime();
}
};
public List<GuildForum> getAllForumsByActive() {
List<GuildForum> forums = this.getAllForumsWithPosts();
forums.sort(SORT_ACTIVE);
return forums;
}
public List<GuildForum> getAllForumsByVisited() {
List<GuildForum> forums = this.getAllForumsWithPosts();
forums.sort(SORT_VISITED);
return forums;
}
}

View File

@ -1,33 +0,0 @@
package com.eu.habbo.habbohotel.guilds.forums;
public enum GuildForumState
{
OPEN(0),
CLOSED(1),
HIDDEN_BY_ADMIN(10),
HIDDEN_BY_STAFF(20);
private int state;
public int getState()
{
return this.state;
}
GuildForumState(int state)
{
this.state = state;
}
public static GuildForumState fromValue(int value)
{
for (GuildForumState state : GuildForumState.values())
{
if (state.state == value)
{
return state;
}
}
return CLOSED;
}
}

View File

@ -1,312 +0,0 @@
package com.eu.habbo.habbohotel.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.map.hash.THashMap;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class GuildForumThread implements ISerialize, Runnable {
private final int threadId;
private final int guildId;
private final int authorId;
private final String authorName;
private final String subject;
private final String message;
private GuildForum.ThreadState state;
private final int timestamp;
private boolean pinned = false;
private boolean locked = false;
private int lastAuthorId = 0;
private String lastAuthorName;
public int getLastCommentTimestamp() {
return this.lastCommentTimestamp;
}
private int lastCommentTimestamp = 0;
private int adminId;
private String adminName = "";
private int commentsIndex = 1;
public final THashMap<Integer, GuildForumComment> comments;
public GuildForumThread(Habbo habbo, int threadId, int guildId, String subject, String message, int timestamp) {
this.threadId = threadId;
this.guildId = guildId;
this.authorId = habbo.getHabboInfo().getId();
this.authorName = habbo.getHabboInfo().getUsername();
this.subject = subject;
this.message = message;
this.state = GuildForum.ThreadState.OPEN;
this.timestamp = timestamp;
this.lastAuthorId = this.authorId;
this.lastAuthorName = this.authorName;
this.lastCommentTimestamp = this.timestamp;
this.comments = new THashMap<>();
}
public GuildForumThread(ResultSet set) throws SQLException {
this.threadId = set.getInt("id");
this.guildId = set.getInt("guild_id");
this.authorId = set.getInt("user_id");
this.authorName = set.getString("author_name");
this.subject = set.getString("subject");
this.message = set.getString("message");
this.state = GuildForum.ThreadState.valueOf(set.getString("state"));
this.timestamp = set.getInt("timestamp");
this.pinned = set.getString("pinned").equals("1");
this.locked = set.getString("locked").equals("1");
this.adminId = set.getInt("admin_id");
this.adminName = set.getString("admin_name");
this.lastAuthorId = this.authorId;
this.lastAuthorName = this.authorName;
this.lastCommentTimestamp = this.timestamp;
this.comments = new THashMap<>();
this.comments.put(commentsIndex, new GuildForumComment(set, commentsIndex, guildId));
commentsIndex++;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT " +
"author.username AS author_name, " +
"COALESCE(admin.username, '') as admin_name, " +
"author.look, " +
"guilds_forums_comments.* " +
"FROM guilds_forums_comments " +
"INNER JOIN users AS author ON guilds_forums_comments.user_id = author.id " +
"LEFT JOIN users AS admin ON guilds_forums_comments.admin_id = admin.id " +
"WHERE thread_id = ? " +
"ORDER BY id ASC")) {
statement.setInt(1, this.threadId);
try (ResultSet commentSet = statement.executeQuery()) {
while (commentSet.next()) {
this.comments.put(commentsIndex, new GuildForumComment(commentSet, commentsIndex, this.guildId));
commentsIndex++;
}
}
} catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
}
public void setPinned(boolean pinned) {
this.pinned = pinned;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public void addComment(GuildForumComment comment) {
synchronized (this.comments) {
comment.setIndex(commentsIndex);
this.comments.put(commentsIndex, comment);
commentsIndex++;
}
this.lastAuthorId = comment.getUserId();
this.lastAuthorName = comment.getUserName();
this.lastCommentTimestamp = comment.getTimestamp();
}
public GuildForumComment addComment(Habbo habbo, String message) {
int commentId = -1;
GuildForumComment comment = new GuildForumComment(this.guildId, this.threadId, habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername(), habbo.getHabboInfo().getLook(), message);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO guilds_forums_comments (thread_id, user_id, timestamp, message) VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
statement.setInt(1, this.threadId);
statement.setInt(2, habbo.getHabboInfo().getId());
int nowTimestamp = Emulator.getIntUnixTimestamp();
statement.setInt(3, nowTimestamp);
statement.setString(4, message);
statement.execute();
try (ResultSet set = statement.getGeneratedKeys()) {
if (set.next()) {
commentId = set.getInt(1);
}
}
} catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
if (commentId >= 0) {
comment.setId(commentId);
addComment(comment);
return comment;
}
return null;
}
public GuildForumComment getCommentById(int id) {
synchronized (this.comments) {
for(GuildForumComment comment : this.comments.values()) {
if(comment.getId() == id) {
return comment;
}
}
}
return null;
}
public GuildForumComment getCommentByIndex(int id) {
synchronized (this.comments) {
return this.comments.get(id);
}
}
/* Original Group Forum Code By Claudio and TheGeneral.
Rewritten because it was terrible.
Credits To Beny.
*/
public List<GuildForumComment> getComments(int page, int limit) {
List<GuildForumComment> allComments = new ArrayList(this.comments.values());
Collections.reverse(allComments);
List<GuildForumComment> comments = new ArrayList<>();
int start = page;
int end = start + limit;
int i = 0;
synchronized (this.comments) {
for(GuildForumComment comment : allComments) {
if(i >= start && i < end) {
comments.add(comment);
}
i++;
}
}
return comments;
}
public Collection<GuildForumComment> getAllComments() {
synchronized (this.comments) {
return this.comments.values();
}
}
public Integer getAmountOfComments() {
synchronized (this.comments) {
return this.comments.size();
}
}
public int getId() {
return this.threadId;
}
public int getGuildId() {
return this.guildId;
}
public int getCommentsSize() {
return this.comments.size();
}
public String getSubject() {
return this.subject;
}
public int getThreadId() {
return this.threadId;
}
public int getAuthorId() {
return this.authorId;
}
public String getAuthorName() {
return this.authorName;
}
public String getMessage() {
return this.message;
}
public GuildForum.ThreadState getState() {
return this.state;
}
public void setState(GuildForum.ThreadState state) {
this.state = state;
}
public void setAdminId(int adminId) {
this.adminId = adminId;
}
public void setAdminName(String adminName) {
this.adminName = adminName;
}
public boolean isPinned() {
return pinned;
}
public boolean isLocked() {
return locked;
}
@Override
public void serialize(ServerMessage message) {
int nowTimestamp = Emulator.getIntUnixTimestamp();
message.appendInt(this.threadId);
message.appendInt(this.authorId);
message.appendString(this.authorName);
message.appendString(this.subject);
message.appendBoolean(this.pinned);
message.appendBoolean(this.locked);
message.appendInt(nowTimestamp - this.timestamp);
message.appendInt(this.getCommentsSize());
message.appendInt(0);
message.appendInt(1);
message.appendInt(this.lastAuthorId);
message.appendString(this.lastAuthorName);
message.appendInt(nowTimestamp - this.lastCommentTimestamp);
message.appendByte(this.state.state);
message.appendInt(this.adminId);
message.appendString(this.adminName);
message.appendInt(this.threadId);
}
@Override
public void run() {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds_forums SET message = ?, state = ?, pinned = ?, locked = ?, admin_id = ? WHERE id = ?")) {
statement.setString(1, this.message);
statement.setString(2, this.state.name());
statement.setString(3, this.pinned ? "1" : "0");
statement.setString(4, this.locked ? "1" : "0");
statement.setInt(5, this.adminId);
statement.setInt(6, this.getId());
statement.execute();
} catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
}
}

View File

@ -40,13 +40,11 @@ public class Habbo implements Runnable
private volatile boolean disconnected = false;
private volatile boolean disconnecting = false;
public boolean firstVisit = false;
public Habbo(ResultSet set)
{
this.client = null;
this.habboInfo = new HabboInfo(set);
this.habboStats = HabboStats.load(this);
this.habboStats = HabboStats.load(this.habboInfo);
this.habboInventory = new HabboInventory(this);
this.messenger = new Messenger();

View File

@ -60,6 +60,7 @@ public class HabboInfo implements Runnable
private String photoJSON;
private int webPublishTimestamp;
private String machineID;
public boolean firstVisit = false;
public HabboInfo(ResultSet set)
{
@ -529,4 +530,13 @@ public class HabboInfo implements Runnable
{
return this.getCurrencyAmount(Emulator.getConfig().getInt("hotelview.promotional.points.type"));
}
public HabboStats getHabboStats() {
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getId());
if(habbo != null) {
return habbo.getHabboStats();
}
return HabboStats.load(this);
}
}

View File

@ -119,7 +119,7 @@ public class HabboManager
{
habbo = new Habbo(set);
if (habbo.firstVisit)
if (habbo.getHabboInfo().firstVisit)
{
Emulator.getPluginManager().fireEvent(new UserRegisteredEvent(habbo));
}
@ -152,6 +152,13 @@ public class HabboManager
return habbo;
}
public HabboInfo getHabboInfo(int id) {
if(this.getHabbo(id) == null) {
return getOfflineHabboInfo(id);
}
return this.getHabbo(id).getHabboInfo();
}
public static HabboInfo getOfflineHabboInfo(int id)
{
HabboInfo info = null;

View File

@ -27,7 +27,7 @@ public class HabboStats implements Runnable
{
private final int timeLoggedIn = Emulator.getIntUnixTimestamp();
private Habbo habbo;
private HabboInfo habboInfo;
public int achievementScore;
public int respectPointsReceived;
@ -96,13 +96,15 @@ public class HabboStats implements Runnable
public boolean allowNameChange;
public boolean isPurchasingFurniture = false;
public int forumPostsCount;
public THashMap<Integer, List<Integer>> ltdPurchaseLog = new THashMap<>(0);
public long lastTradeTimestamp = Emulator.getIntUnixTimestamp();
public long lastPurchaseTimestamp = Emulator.getIntUnixTimestamp();
public long lastGiftTimestamp = Emulator.getIntUnixTimestamp();
public final TIntObjectMap<HabboOfferPurchase> offerCache = new TIntObjectHashMap<>();
private HabboStats(ResultSet set, Habbo habbo) throws SQLException
private HabboStats(ResultSet set, HabboInfo habboInfo) throws SQLException
{
this.cache = new THashMap<>(0);
this.achievementProgress = new THashMap<>(0);
@ -113,7 +115,7 @@ public class HabboStats implements Runnable
this.secretRecipes = new TIntArrayList(0);
this.calendarRewardsClaimed = new TIntArrayList(0);
this.habbo = habbo;
this.habboInfo = habboInfo;
this.achievementScore = set.getInt("achievement_score");
this.respectPointsReceived = set.getInt("respects_received");
@ -148,11 +150,12 @@ public class HabboStats implements Runnable
this.muteEndTime = set.getInt("mute_end_timestamp");
this.allowNameChange = set.getString("allow_name_change").equalsIgnoreCase("1");
this.perkTrade = set.getString("perk_trade").equalsIgnoreCase("1");
this.forumPostsCount = set.getInt("forums_post_count");
this.nuxReward = this.nux;
try (PreparedStatement statement = set.getStatement().getConnection().prepareStatement("SELECT * FROM user_window_settings WHERE user_id = ? LIMIT 1"))
{
statement.setInt(1, this.habbo.getHabboInfo().getId());
statement.setInt(1, this.habboInfo.getId());
try (ResultSet nSet = statement.executeQuery())
{
if (nSet.next())
@ -163,18 +166,18 @@ public class HabboStats implements Runnable
{
try (PreparedStatement stmt = statement.getConnection().prepareStatement("INSERT INTO user_window_settings (user_id) VALUES (?)"))
{
stmt.setInt(1, this.habbo.getHabboInfo().getId());
stmt.setInt(1, this.habboInfo.getId());
stmt.executeUpdate();
}
this.navigatorWindowSettings = new HabboNavigatorWindowSettings(habbo.getHabboInfo().getId());
this.navigatorWindowSettings = new HabboNavigatorWindowSettings(habboInfo.getId());
}
}
}
try (PreparedStatement statement = set.getStatement().getConnection().prepareStatement("SELECT * FROM users_navigator_settings WHERE user_id = ?"))
{
statement.setInt(1, this.habbo.getHabboInfo().getId());
statement.setInt(1, this.habboInfo.getId());
try (ResultSet nSet = statement.executeQuery())
{
while (nSet.next())
@ -186,7 +189,7 @@ public class HabboStats implements Runnable
try (PreparedStatement favoriteRoomsStatement = set.getStatement().getConnection().prepareStatement("SELECT * FROM users_favorite_rooms WHERE user_id = ?"))
{
favoriteRoomsStatement.setInt(1, this.habbo.getHabboInfo().getId());
favoriteRoomsStatement.setInt(1, this.habboInfo.getId());
try (ResultSet favoriteSet = favoriteRoomsStatement.executeQuery())
{
while (favoriteSet.next())
@ -199,7 +202,7 @@ public class HabboStats implements Runnable
try (PreparedStatement recipesStatement = set.getStatement().getConnection().prepareStatement("SELECT * FROM users_recipes WHERE user_id = ?"))
{
recipesStatement.setInt(1, this.habbo.getHabboInfo().getId());
recipesStatement.setInt(1, this.habboInfo.getId());
try (ResultSet recipeSet = recipesStatement.executeQuery())
{
while (recipeSet.next())
@ -211,7 +214,7 @@ public class HabboStats implements Runnable
try (PreparedStatement calendarRewardsStatement = set.getStatement().getConnection().prepareStatement("SELECT * FROM calendar_rewards_claimed WHERE user_id = ?"))
{
calendarRewardsStatement.setInt(1, this.habbo.getHabboInfo().getId());
calendarRewardsStatement.setInt(1, this.habboInfo.getId());
try (ResultSet rewardSet = calendarRewardsStatement.executeQuery())
{
while (rewardSet.next())
@ -223,7 +226,7 @@ public class HabboStats implements Runnable
try (PreparedStatement ltdPurchaseLogStatement = set.getStatement().getConnection().prepareStatement("SELECT catalog_item_id, timestamp FROM catalog_items_limited WHERE user_id = ? AND timestamp > ?"))
{
ltdPurchaseLogStatement.setInt(1, this.habbo.getHabboInfo().getId());
ltdPurchaseLogStatement.setInt(1, this.habboInfo.getId());
ltdPurchaseLogStatement.setInt(2, Emulator.getIntUnixTimestamp() - 86400);
try (ResultSet ltdSet = ltdPurchaseLogStatement.executeQuery())
{
@ -236,7 +239,7 @@ public class HabboStats implements Runnable
try (PreparedStatement ignoredPlayersStatement = set.getStatement().getConnection().prepareStatement("SELECT target_id FROM users_ignored WHERE user_id = ?"))
{
ignoredPlayersStatement.setInt(1, this.habbo.getHabboInfo().getId());
ignoredPlayersStatement.setInt(1, this.habboInfo.getId());
try (ResultSet ignoredSet = ignoredPlayersStatement.executeQuery())
{
while (ignoredSet.next())
@ -248,7 +251,7 @@ public class HabboStats implements Runnable
try (PreparedStatement loadOfferPurchaseStatement = set.getStatement().getConnection().prepareStatement("SELECT * FROM users_target_offer_purchases WHERE user_id = ?"))
{
loadOfferPurchaseStatement.setInt(1, this.habbo.getHabboInfo().getId());
loadOfferPurchaseStatement.setInt(1, this.habboInfo.getId());
try (ResultSet offerSet = loadOfferPurchaseStatement.executeQuery())
{
while (offerSet.next())
@ -264,7 +267,7 @@ public class HabboStats implements Runnable
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection())
{
try (PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET achievement_score = ?, respects_received = ?, respects_given = ?, daily_respect_points = ?, block_following = ?, block_friendrequests = ?, online_time = online_time + ?, guild_id = ?, daily_pet_respect_points = ?, club_expire_timestamp = ?, login_streak = ?, rent_space_id = ?, rent_space_endtime = ?, volume_system = ?, volume_furni = ?, volume_trax = ?, block_roominvites = ?, old_chat = ?, block_camera_follow = ?, chat_color = ?, hof_points = ?, block_alerts = ?, talent_track_citizenship_level = ?, talent_track_helpers_level = ?, ignore_bots = ?, ignore_pets = ?, nux = ?, mute_end_timestamp = ?, allow_name_change = ?, perk_trade = ?, can_trade = ? WHERE user_id = ? LIMIT 1"))
try (PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET achievement_score = ?, respects_received = ?, respects_given = ?, daily_respect_points = ?, block_following = ?, block_friendrequests = ?, online_time = online_time + ?, guild_id = ?, daily_pet_respect_points = ?, club_expire_timestamp = ?, login_streak = ?, rent_space_id = ?, rent_space_endtime = ?, volume_system = ?, volume_furni = ?, volume_trax = ?, block_roominvites = ?, old_chat = ?, block_camera_follow = ?, chat_color = ?, hof_points = ?, block_alerts = ?, talent_track_citizenship_level = ?, talent_track_helpers_level = ?, ignore_bots = ?, ignore_pets = ?, nux = ?, mute_end_timestamp = ?, allow_name_change = ?, perk_trade = ?, can_trade = ?, `forums_post_count` = ? WHERE user_id = ? LIMIT 1"))
{
statement.setInt(1, this.achievementScore);
statement.setInt(2, this.respectPointsReceived);
@ -297,7 +300,8 @@ public class HabboStats implements Runnable
statement.setString(29, this.allowNameChange ? "1" : "0");
statement.setString(30, this.perkTrade ? "1" : "0");
statement.setString(31, this.allowTrade ? "1" : "0");
statement.setInt(32, this.habbo.getHabboInfo().getId());
statement.setInt(32, this.forumPostsCount);
statement.setInt(33, this.habboInfo.getId());
statement.executeUpdate();
}
@ -308,7 +312,7 @@ public class HabboStats implements Runnable
statement.setInt(3, this.navigatorWindowSettings.width);
statement.setInt(4, this.navigatorWindowSettings.height);
statement.setString(5, this.navigatorWindowSettings.openSearches ? "1" : "0");
statement.setInt(6, this.habbo.getHabboInfo().getId());
statement.setInt(6, this.habboInfo.getId());
statement.executeUpdate();
}
@ -323,7 +327,7 @@ public class HabboStats implements Runnable
statement.setInt(1, purchase.getState());
statement.setInt(2, purchase.getAmount());
statement.setInt(3, purchase.getLastPurchaseTimestamp());
statement.setInt(4, this.habbo.getHabboInfo().getId());
statement.setInt(4, this.habboInfo.getId());
statement.setInt(5, purchase.getOfferId());
statement.execute();
}
@ -341,17 +345,17 @@ public class HabboStats implements Runnable
public void dispose()
{
this.run();
this.habbo = null;
this.habboInfo = null;
this.recentPurchases.clear();
}
private static HabboStats createNewStats(Habbo habbo)
private static HabboStats createNewStats(HabboInfo habboInfo)
{
habbo.firstVisit = true;
habboInfo.firstVisit = true;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_settings (user_id) VALUES (?)"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(1, habboInfo.getId());
statement.executeUpdate();
}
catch (SQLException e)
@ -359,27 +363,27 @@ public class HabboStats implements Runnable
Emulator.getLogging().logSQLException(e);
}
return load(habbo);
return load(habboInfo);
}
public static HabboStats load(Habbo habbo)
public static HabboStats load(HabboInfo habboInfo)
{
HabboStats stats = null;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection())
{
try(PreparedStatement statement = connection.prepareStatement("SELECT * FROM users_settings WHERE user_id = ? LIMIT 1"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(1, habboInfo.getId());
try (ResultSet set = statement.executeQuery())
{
set.first();
if (set.getRow() != 0)
{
stats = new HabboStats(set, habbo);
stats = new HabboStats(set, habboInfo);
}
else
{
stats = createNewStats(habbo);
stats = createNewStats(habboInfo);
}
}
}
@ -388,7 +392,7 @@ public class HabboStats implements Runnable
{
try (PreparedStatement statement = connection.prepareStatement("SELECT guild_id FROM guilds_members WHERE user_id = ? AND level_id < 3 LIMIT 100"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(1, habboInfo.getId());
try (ResultSet set = statement.executeQuery())
{
@ -405,7 +409,7 @@ public class HabboStats implements Runnable
try (PreparedStatement statement = connection.prepareStatement("SELECT room_id FROM room_votes WHERE user_id = ?"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(1, habboInfo.getId());
try (ResultSet set = statement.executeQuery())
{
while (set.next())
@ -417,7 +421,7 @@ public class HabboStats implements Runnable
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM users_achievements WHERE user_id = ?"))
{
statement.setInt(1, habbo.getHabboInfo().getId());
statement.setInt(1, habboInfo.getId());
try (ResultSet set = statement.executeQuery())
{
while (set.next())
@ -566,7 +570,7 @@ public class HabboStats implements Runnable
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_favorite_rooms (user_id, room_id) VALUES (?, ?)"))
{
statement.setInt(1, this.habbo.getHabboInfo().getId());
statement.setInt(1, this.habboInfo.getId());
statement.setInt(2, roomId);
statement.execute();
}
@ -585,7 +589,7 @@ public class HabboStats implements Runnable
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_favorite_rooms WHERE user_id = ? AND room_id = ? LIMIT 1"))
{
statement.setInt(1, this.habbo.getHabboInfo().getId());
statement.setInt(1, this.habboInfo.getId());
statement.setInt(2, roomId);
statement.execute();
}
@ -618,7 +622,7 @@ public class HabboStats implements Runnable
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_recipes (user_id, recipe) VALUES (?, ?)"))
{
statement.setInt(1, this.habbo.getHabboInfo().getId());
statement.setInt(1, this.habboInfo.getId());
statement.setInt(2, id);
statement.execute();
}
@ -723,7 +727,7 @@ public class HabboStats implements Runnable
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)"))
{
statement.setInt(1, this.habbo.getHabboInfo().getId());
statement.setInt(1, this.habboInfo.getId());
statement.setInt(2, userId);
statement.execute();
}
@ -743,7 +747,7 @@ public class HabboStats implements Runnable
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("DELETE FROM users_ignored WHERE user_id = ? AND target_id = ?"))
{
statement.setInt(1, this.habbo.getHabboInfo().getId());
statement.setInt(1, this.habboInfo.getId());
statement.setInt(2, userId);
statement.execute();
}

View File

@ -1,7 +1,7 @@
package com.eu.habbo.messages.incoming.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumDataComposer;
@ -12,11 +12,11 @@ public class GuildForumDataEvent extends MessageHandler
{
int guildId = packet.readInt();
GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId);
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
if(forum == null)
if(guild == null)
return;
this.client.sendResponse(new GuildForumDataComposer(forum, this.client.getHabbo()));
this.client.sendResponse(new GuildForumDataComposer(guild, this.client.getHabbo()));
}
}

View File

@ -1,26 +1,96 @@
package com.eu.habbo.messages.incoming.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumListComposer;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
import gnu.trove.set.hash.THashSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class GuildForumListEvent extends MessageHandler {
@Override
public void handle() throws Exception {
int mode = this.packet.readInt();
int page = this.packet.readInt();
int offset = this.packet.readInt();
int amount = this.packet.readInt();
THashSet<Guild> guilds = null;
switch (mode) {
case 0:
this.client.sendResponse(new GuildForumListComposer(Emulator.getGameEnvironment().getGuildForumManager().getAllForumsByVisited(), this.client.getHabbo(), mode, page));
case 0: // most active
guilds = getPopularForums();
break;
case 1:
this.client.sendResponse(new GuildForumListComposer(Emulator.getGameEnvironment().getGuildForumManager().getAllForumsByActive(), this.client.getHabbo(), mode, page));
case 1: // most viewed
guilds = getPopularForums();
break;
case 2:
this.client.sendResponse(new GuildForumListComposer(Emulator.getGameEnvironment().getGuildForumManager().getGuildForums(this.client.getHabbo()), this.client.getHabbo(), mode, page));
case 2: // my groups
guilds = getMyForums(this.client.getHabbo().getHabboInfo().getId());
break;
}
if(guilds != null) {
this.client.sendResponse(new GuildForumListComposer(guilds, this.client.getHabbo(), mode, offset));
}
}
private THashSet<Guild> getPopularForums() {
THashSet<Guild> guilds = new THashSet<Guild>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT `guilds`.`id`, SUM(`guilds_forums_threads`.`posts_count`) AS `post_count` " +
"FROM `guilds_forums_threads` " +
"LEFT JOIN `guilds` ON `guilds`.`id` = `guilds_forums_threads`.`guild_id` " +
"GROUP BY `guilds`.`id` " +
"ORDER BY `post_count` DESC LIMIT 100"))
{
ResultSet set = statement.executeQuery();
while(set.next()) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(set.getInt("id"));
if(guild != null) {
guilds.add(guild);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
this.client.sendResponse(new ConnectionErrorComposer(500));
}
return guilds;
}
private THashSet<Guild> getMyForums(int userId) {
THashSet<Guild> guilds = new THashSet<Guild>();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT `guilds`.`id` FROM `guilds_members` " +
"LEFT JOIN `guilds` ON `guilds`.`id` = `guilds_members`.`guild_id` " +
"WHERE `guilds_members`.`user_id` = ? AND `guilds`.`forum` = '1'"))
{
statement.setInt(1, userId);
ResultSet set = statement.executeQuery();
while(set.next()) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(set.getInt("id"));
if(guild != null) {
guilds.add(guild);
}
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
this.client.sendResponse(new ConnectionErrorComposer(500));
}
return guilds;
}
}

View File

@ -4,13 +4,14 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildMember;
import com.eu.habbo.habbohotel.guilds.GuildRank;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadState;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
import com.eu.habbo.messages.outgoing.guilds.forums.PostUpdateMessageComposer;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
public class GuildForumModerateMessageEvent extends MessageHandler {
@ -22,43 +23,52 @@ public class GuildForumModerateMessageEvent extends MessageHandler {
int state = packet.readInt();
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
ForumThread thread = ForumThread.getById(threadId);
if(guild == null || thread == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
}
ForumThreadComment comment = thread.getCommentById(messageId);
if(comment == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
}
boolean isStaff = this.client.getHabbo().hasPermission("acc_modtool_ticket_q");
final GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId());
boolean isAdmin = member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId());
if (guild == null || (!isAdmin && !isStaff))
GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId());
if(member == null) {
this.client.sendResponse(new ConnectionErrorComposer(401));
return;
GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId);
GuildForumThread thread = forum.getThread(threadId);
if (thread != null) {
if(messageId >= 0) {
Emulator.getLogging().logDebugLine("Forum message ID - " + messageId);
GuildForumComment comment = thread.getCommentById(messageId);
comment.setState(GuildForum.ThreadState.fromValue(state));
comment.setAdminId(this.client.getHabbo().getHabboInfo().getId());
comment.setAdminName(this.client.getHabbo().getHabboInfo().getUsername());
Emulator.getThreading().run(comment);
this.client.sendResponse(new PostUpdateMessageComposer(guildId, threadId, comment));
}
switch (state) {
case 10:
case 20:
this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_MESSAGE_HIDDEN.key).compose());
break;
case 1:
this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_MESSAGE_RESTORED.key).compose());
break;
}
} else {
}
boolean isAdmin = (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().type < GuildRank.MEMBER.type);
if (!isAdmin && !isStaff) {
this.client.sendResponse(new ConnectionErrorComposer(403));
return;
}
if(state == ForumThreadState.HIDDEN_BY_STAFF.getStateId() && !isStaff) {
this.client.sendResponse(new ConnectionErrorComposer(403));
return;
}
comment.setState(ForumThreadState.fromValue(state));
comment.setAdminId(this.client.getHabbo().getHabboInfo().getId());
this.client.sendResponse(new PostUpdateMessageComposer(guild.getId(), thread.getThreadId(), comment));
switch (state) {
case 10:
case 20:
this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_MESSAGE_HIDDEN.key).compose());
break;
case 1:
this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_MESSAGE_RESTORED.key).compose());
break;
}
}
}

View File

@ -4,12 +4,13 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildMember;
import com.eu.habbo.habbohotel.guilds.GuildRank;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadState;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumThreadMessagesComposer;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
public class GuildForumModerateThreadEvent extends MessageHandler {
@ -20,19 +21,35 @@ public class GuildForumModerateThreadEvent extends MessageHandler {
int state = packet.readInt();
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
ForumThread thread = ForumThread.getById(threadId);
if(guild == null || thread == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
}
boolean isStaff = this.client.getHabbo().hasPermission("acc_modtool_ticket_q");
final GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId());
boolean isAdmin = member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId());
if (guild == null || (!isAdmin && !isStaff))
GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId());
if(member == null) {
this.client.sendResponse(new ConnectionErrorComposer(401));
return;
}
GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId);
GuildForumThread thread = forum.getThread(threadId);
thread.setState(GuildForum.ThreadState.fromValue(state));
boolean isAdmin = (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().type < GuildRank.MEMBER.type);
if (!isAdmin && !isStaff) {
this.client.sendResponse(new ConnectionErrorComposer(403));
return;
}
if(state == ForumThreadState.HIDDEN_BY_STAFF.getStateId() && !isStaff) {
this.client.sendResponse(new ConnectionErrorComposer(403));
return;
}
thread.setState(ForumThreadState.fromValue(state));
thread.setAdminId(this.client.getHabbo().getHabboInfo().getId());
thread.setAdminName(this.client.getHabbo().getHabboInfo().getUsername());
switch (state) {
case 10:
@ -44,8 +61,6 @@ public class GuildForumModerateThreadEvent extends MessageHandler {
break;
}
Emulator.getThreading().run(thread);
this.client.sendResponse(new GuildForumThreadMessagesComposer(thread));
}
}

View File

@ -4,12 +4,12 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildMember;
import com.eu.habbo.habbohotel.guilds.GuildRank;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumAddCommentComposer;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumThreadMessagesComposer;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
public class GuildForumPostThreadEvent extends MessageHandler {
@ -20,49 +20,74 @@ public class GuildForumPostThreadEvent extends MessageHandler {
String subject = this.packet.readString();
String message = this.packet.readString();
final GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId);
final Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
final GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId());
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
if(guild == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
}
if (message.length() < 10 || message.length() > 4000 || (threadId == 0 && (subject.length() < 10 || subject.length() > 120))) {
this.client.sendResponse(new ConnectionErrorComposer(400));
return;
}
boolean isStaff = this.client.getHabbo().hasPermission("acc_modtool_ticket_q");
final GuildForumThread thread;
GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId());
if (forum != null) {
if (message.length() < 10 || message.length() > 4000) return;
ForumThread thread = ForumThread.getById(threadId);
if (threadId == 0) {
if ((guild.canPostThreads().state == 0)
|| (guild.canPostThreads().state == 1 && member != null)
|| (guild.canPostThreads().state == 2 && member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN))
|| (guild.canPostThreads().state == 3 && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId())
|| isStaff) {
thread = forum.createThread(this.client.getHabbo(), subject, message);
GuildForumComment comment = new GuildForumComment(guildId, threadId, this.client.getHabbo().getHabboInfo().getId(),
this.client.getHabbo().getHabboInfo().getUsername(), this.client.getHabbo().getHabboInfo().getLook(), message);
thread.addComment(comment);
this.client.sendResponse(new GuildForumThreadMessagesComposer(thread));
}
} else {
if ((guild.canPostThreads().state == 0)
|| (guild.canPostThreads().state == 1 && member != null)
|| (guild.canPostThreads().state == 2 && member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN))
|| (guild.canPostThreads().state == 3 && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId())
|| isStaff) {
thread = forum.getThread(threadId);
if(thread == null)
return;
GuildForumComment comment = thread.addComment(this.client.getHabbo(), message);
if (comment != null) {
this.client.sendResponse(new GuildForumAddCommentComposer(comment));
}
}
if(threadId == 0) {
if (!((guild.canPostThreads().state == 0)
|| (guild.canPostThreads().state == 1 && member != null)
|| (guild.canPostThreads().state == 2 && member != null && (member.getRank().type < GuildRank.MEMBER.type))
|| (guild.canPostThreads().state == 3 && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId())
|| isStaff)) {
this.client.sendResponse(new ConnectionErrorComposer(403));
return;
}
thread = ForumThread.create(guild, this.client.getHabbo(), subject, message);
if (thread == null) {
this.client.sendResponse(new ConnectionErrorComposer(500));
return;
}
this.client.getHabbo().getHabboStats().forumPostsCount += 1;
thread.setPostsCount(thread.getPostsCount() + 1);
this.client.sendResponse(new GuildForumThreadMessagesComposer(thread));
return;
}
if(thread == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
}
if (!((guild.canPostMessages().state == 0)
|| (guild.canPostMessages().state == 1 && member != null)
|| (guild.canPostMessages().state == 2 && member != null && (member.getRank().type < GuildRank.MEMBER.type))
|| (guild.canPostMessages().state == 3 && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId())
|| isStaff)) {
this.client.sendResponse(new ConnectionErrorComposer(403));
return;
}
ForumThreadComment comment = ForumThreadComment.create(thread, this.client.getHabbo(), message);
if(comment != null) {
thread.addComment(comment);
thread.setUpdatedAt(Emulator.getIntUnixTimestamp());
this.client.getHabbo().getHabboStats().forumPostsCount += 1;
thread.setPostsCount(thread.getPostsCount() + 1);
this.client.sendResponse(new GuildForumAddCommentComposer(comment));
}
else {
this.client.sendResponse(new ConnectionErrorComposer(500));
}
}
}

View File

@ -1,17 +1,52 @@
package com.eu.habbo.messages.incoming.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildMember;
import com.eu.habbo.habbohotel.guilds.GuildRank;
import com.eu.habbo.habbohotel.guilds.SettingsState;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadState;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumThreadsComposer;
import com.eu.habbo.messages.outgoing.guilds.forums.ThreadUpdatedMessageComposer;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
public class GuildForumThreadUpdateEvent extends MessageHandler {
@Override
public void handle() throws Exception {
int groupId = this.packet.readInt();
int guildId = this.packet.readInt();
int threadId = this.packet.readInt();
boolean isPinned = this.packet.readBoolean();
boolean isLocked = this.packet.readBoolean();
this.client.sendResponse(new ThreadUpdatedMessageComposer(Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(groupId), threadId, this.client.getHabbo(), isPinned, isLocked));
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
ForumThread thread = ForumThread.getById(threadId);
if(guild == null || thread == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
}
boolean isStaff = this.client.getHabbo().hasPermission("acc_modtool_ticket_q");
GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId());
if(member == null) {
this.client.sendResponse(new ConnectionErrorComposer(401));
return;
}
boolean isAdmin = (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().type < GuildRank.MEMBER.type);
if ((guild.canModForum() == SettingsState.OWNER && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() && !isStaff) || (guild.canModForum() == SettingsState.ADMINS && !isAdmin && !isStaff)) {
this.client.sendResponse(new ConnectionErrorComposer(403));
return;
}
this.client.sendResponse(new ThreadUpdatedMessageComposer(guild, thread, this.client.getHabbo(), isPinned, isLocked));
if(isPinned) {
this.client.sendResponse(new GuildForumThreadsComposer(guild, 0));
}
}
}

View File

@ -1,27 +1,28 @@
package com.eu.habbo.messages.incoming.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumDataComposer;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumThreadsComposer;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
public class GuildForumThreadsEvent extends MessageHandler
{
@Override
public void handle() throws Exception
{
int groupdId = packet.readInt();
int guildId = packet.readInt();
int index = packet.readInt();
GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(groupdId);
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
if(forum == null)
if(guild == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
}
this.client.sendResponse(new GuildForumDataComposer(forum, this.client.getHabbo()));
this.client.sendResponse(new GuildForumThreadsComposer(forum, index));
//TODO read guild id;
this.client.sendResponse(new GuildForumDataComposer(guild, this.client.getHabbo()));
this.client.sendResponse(new GuildForumThreadsComposer(guild, index));
}
}

View File

@ -2,12 +2,13 @@ package com.eu.habbo.messages.incoming.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadState;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumCommentsComposer;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumDataComposer;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
public class GuildForumThreadsMessagesEvent extends MessageHandler
{
@ -16,29 +17,26 @@ public class GuildForumThreadsMessagesEvent extends MessageHandler
{
int guildId = packet.readInt();
int threadId = packet.readInt();
int index = packet.readInt(); //40
int limit = packet.readInt(); //20
int index = packet.readInt(); // 40
int limit = packet.readInt(); // 20
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
ForumThread thread = ForumThread.getById(threadId);
if(guild == null)
if(guild == null || thread == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId);
if(forum == null)
return;
GuildForumThread thread = forum.getThread(threadId);
if (thread.getState() == GuildForum.ThreadState.HIDDEN_BY_ADMIN && guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId())
{
this.client.sendResponse(new BubbleAlertComposer("forums.error.access_denied"));
} else
{
this.client.sendResponse(new GuildForumCommentsComposer(guildId, threadId, index, thread.getComments(index, limit)));
}
this.client.sendResponse(new GuildForumDataComposer(forum, this.client.getHabbo()));
if ((thread.getState() == ForumThreadState.HIDDEN_BY_ADMIN || thread.getState() == ForumThreadState.HIDDEN_BY_STAFF) && guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId())
{
this.client.sendResponse(new BubbleAlertComposer("oldforums.error.access_denied"));
}
else
{
this.client.sendResponse(new GuildForumCommentsComposer(guildId, threadId, index, thread.getComments(limit, index)));
}
this.client.sendResponse(new GuildForumDataComposer(guild, this.client.getHabbo()));
}
}

View File

@ -3,11 +3,11 @@ package com.eu.habbo.messages.incoming.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.SettingsState;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumDataComposer;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
public class GuildForumUpdateSettingsEvent extends MessageHandler
{
@ -22,13 +22,15 @@ public class GuildForumUpdateSettingsEvent extends MessageHandler
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId);
if(guild == null || guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId())
if(guild == null) {
this.client.sendResponse(new ConnectionErrorComposer(404));
return;
}
GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId);
if(forum == null)
if(guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId()) {
this.client.sendResponse(new ConnectionErrorComposer(403));
return;
}
guild.setReadForum(SettingsState.fromValue(canRead));
guild.setPostMessages(SettingsState.fromValue(postMessages));
@ -41,6 +43,6 @@ public class GuildForumUpdateSettingsEvent extends MessageHandler
this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_FORUM_SETTINGS_UPDATED.key).compose());
this.client.sendResponse(new GuildForumDataComposer(forum, this.client.getHabbo()));
this.client.sendResponse(new GuildForumDataComposer(guild, this.client.getHabbo()));
}
}

View File

@ -1,16 +1,15 @@
package com.eu.habbo.messages.outgoing.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
public class GuildForumAddCommentComposer extends MessageComposer
{
private final GuildForumComment comment;
private final ForumThreadComment comment;
public GuildForumAddCommentComposer(GuildForumComment comment)
{
public GuildForumAddCommentComposer(ForumThreadComment comment) {
this.comment = comment;
}
@ -18,7 +17,7 @@ public class GuildForumAddCommentComposer extends MessageComposer
public ServerMessage compose()
{
this.response.init(Outgoing.GuildForumAddCommentComposer);
this.response.appendInt(this.comment.getGuildId()); //guild_id
this.response.appendInt(this.comment.getThread().getGuildId()); //guild_id
this.response.appendInt(this.comment.getThreadId()); //thread_id
this.comment.serialize(this.response); //Comment
return this.response;

View File

@ -1,20 +1,19 @@
package com.eu.habbo.messages.outgoing.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
import java.util.List;
import java.util.Collection;
public class GuildForumCommentsComposer extends MessageComposer
{
private final int guildId;
private final int threadId;
private final int index;
private final List<GuildForumComment> guildForumCommentList;
private final Collection<ForumThreadComment> guildForumCommentList;
public GuildForumCommentsComposer(int guildId, int threadId, int index, List<GuildForumComment> guildForumCommentList)
public GuildForumCommentsComposer(int guildId, int threadId, int index, Collection<ForumThreadComment> guildForumCommentList)
{
this.guildId = guildId;
this.threadId = threadId;
@ -32,7 +31,7 @@ public class GuildForumCommentsComposer extends MessageComposer
this.response.appendInt(this.index); //start_index
this.response.appendInt(this.guildForumCommentList.size());
for (final GuildForumComment comment : this.guildForumCommentList)
for (ForumThreadComment comment : this.guildForumCommentList)
{
comment.serialize(this.response);
}

View File

@ -4,30 +4,39 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildMember;
import com.eu.habbo.habbohotel.guilds.GuildRank;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
import gnu.trove.set.hash.THashSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class GuildForumDataComposer extends MessageComposer {
public final GuildForum forum;
public final Guild guild;
public Habbo habbo;
public GuildForumDataComposer(GuildForum forum, Habbo habbo) {
this.forum = forum;
public GuildForumDataComposer(Guild guild, Habbo habbo) {
this.guild = guild;
this.habbo = habbo;
}
@Override
public ServerMessage compose() {
this.response.init(Outgoing.GuildForumDataComposer);
{
this.forum.serializeUserForum(this.response, this.habbo);
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.forum.getGuild());
try {
this.response.init(Outgoing.GuildForumDataComposer);
serializeForumData(this.response, guild, habbo);
GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, habbo);
boolean isAdmin = member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN || guild.getOwnerId() == this.habbo.getHabboInfo().getId());
boolean isAdmin = member != null && (member.getRank().type < GuildRank.MEMBER.type || guild.getOwnerId() == this.habbo.getHabboInfo().getId());
boolean isStaff = this.habbo.hasPermission("acc_modtool_ticket_q");
String errorRead = "";
@ -46,7 +55,7 @@ public class GuildForumDataComposer extends MessageComposer {
} else if (guild.canPostMessages().state == 2 && !isAdmin && !isStaff) {
errorPost = "not_admin";
} else if (guild.canPostMessages().state == 3 && guild.getOwnerId() != this.habbo.getHabboInfo().getId() && !isStaff) {
errorPost = "now_owner";
errorPost = "not_owner";
}
if (guild.canPostThreads().state == 1 && member == null && !isStaff) {
@ -54,13 +63,14 @@ public class GuildForumDataComposer extends MessageComposer {
} else if (guild.canPostThreads().state == 2 && !isAdmin && !isStaff) {
errorStartThread = "not_admin";
} else if (guild.canPostThreads().state == 3 && guild.getOwnerId() != this.habbo.getHabboInfo().getId() && !isStaff) {
errorStartThread = "now_owner";
errorStartThread = "not_owner";
}
if (guild.canModForum().state == 2 && !isAdmin && !isStaff) {
if (guild.canModForum().state == 3 && guild.getOwnerId() != this.habbo.getHabboInfo().getId() && !isStaff) {
errorModerate = "not_owner";
}
else if (!isAdmin && !isStaff) {
errorModerate = "not_admin";
} else if (guild.canModForum().state == 3 && guild.getOwnerId() != this.habbo.getHabboInfo().getId() && !isStaff) {
errorModerate = "now_owner";
}
this.response.appendInt(guild.canReadForum().state);
@ -68,13 +78,87 @@ public class GuildForumDataComposer extends MessageComposer {
this.response.appendInt(guild.canPostThreads().state);
this.response.appendInt(guild.canModForum().state);
this.response.appendString(errorRead);
this.response.appendString(errorPost);
this.response.appendString(errorStartThread);
this.response.appendString(errorModerate);
this.response.appendString(""); //citizen
this.response.appendString("not_citizen"); //errorPost);
this.response.appendString("not_citizen"); //errorStartThread);
this.response.appendString("not_admin"); //errorModerate);
this.response.appendString("not_citizen"); //citizen
this.response.appendBoolean(guild.getOwnerId() == this.habbo.getHabboInfo().getId()); //Forum Settings
this.response.appendBoolean(guild.getOwnerId() == this.habbo.getHabboInfo().getId() || isStaff); //Can Mod (staff)
}
catch (Exception e) {
e.printStackTrace();
return new ConnectionErrorComposer(500).compose();
}
return this.response;
}
public static void serializeForumData(ServerMessage response, Guild guild, Habbo habbo) throws SQLException {
final THashSet<ForumThread> forumThreads = ForumThread.getByGuildId(guild.getId());
int lastSeenAt = 0;
int totalComments = 0;
int newComments = 0;
int totalThreads = 0;
ForumThreadComment lastComment = null;
synchronized (forumThreads) {
for (ForumThread thread : forumThreads) {
totalThreads++;
totalComments += thread.getPostsCount();
ForumThreadComment comment = thread.getLastComment();
if (comment != null && (lastComment == null || lastComment.getCreatedAt() < comment.getCreatedAt())) {
lastComment = comment;
}
}
}
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(
"SELECT COUNT(*) " +
"FROM guilds_forums_threads A " +
"JOIN ( " +
"SELECT * " +
"FROM `guilds_forums_comments` " +
"WHERE `id` IN ( " +
"SELECT id " +
"FROM `guilds_forums_comments` B " +
"ORDER BY B.`id` ASC " +
") " +
"ORDER BY `id` DESC " +
") B ON A.`id` = B.`thread_id` " +
"WHERE A.`guild_id` = ? AND B.`created_at` > ?"
))
{
statement.setInt(1, guild.getId());
statement.setInt(2, lastSeenAt);
ResultSet set = statement.executeQuery();
while(set.next()) {
newComments = set.getInt(1);
}
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
response.appendInt(guild.getId());
response.appendString(guild.getName());
response.appendString(guild.getDescription());
response.appendString(guild.getBadge());
response.appendInt(totalThreads);
response.appendInt(0); //Rating
response.appendInt(totalComments); //Total comments
response.appendInt(newComments); //Unread comments
response.appendInt(lastComment != null ? lastComment.getThreadId() : -1);
response.appendInt(lastComment != null ? lastComment.getUserId() : -1);
response.appendString(lastComment != null && lastComment.getHabbo() != null ? lastComment.getHabbo().getHabboInfo().getUsername() : "");
response.appendInt(lastComment != null ? Emulator.getIntUnixTimestamp() - lastComment.getCreatedAt() : 0);
}
}

View File

@ -1,41 +1,57 @@
package com.eu.habbo.messages.outgoing.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
import gnu.trove.set.hash.THashSet;
import java.sql.SQLException;
import java.util.Iterator;
public class GuildForumListComposer extends MessageComposer {
private final List<GuildForum> forums;
private final THashSet<Guild> guilds;
private final Habbo habbo;
private final int viewMode;
private final int startIndex;
private final int mode;
private final int index;
public GuildForumListComposer(List<GuildForum> forums, Habbo habbo, int viewMode, int page) {
this.forums = forums;
public GuildForumListComposer(THashSet<Guild> guilds, Habbo habbo, int mode, int index) {
this.guilds = guilds;
this.habbo = habbo;
this.viewMode = viewMode;
this.startIndex = page;
this.mode = mode;
this.index = index;
}
@Override
public ServerMessage compose() {
forums.removeIf(Objects::isNull);
List<Integer> guilds = forums.stream().skip(this.startIndex).limit(20).map(GuildForum::getGuild).collect(Collectors.toList());
this.response.init(Outgoing.GuildForumListComposer);
this.response.appendInt(this.viewMode);
this.response.appendInt(guilds.size());
this.response.appendInt(0);
this.response.appendInt(this.forums.size());
for (final GuildForum forum : this.forums) {
forum.serializeUserForum(this.response, this.habbo);
this.response.appendInt(this.mode);
this.response.appendInt(this.guilds.size());
this.response.appendInt(this.index);
Iterator<Guild> it = guilds.iterator();
int count = guilds.size() > 20 ? 20 : guilds.size();
this.response.appendInt(count);
for(int i = 0; i < index; i++) {
if(!it.hasNext())
break;
it.next();
}
for(int i = 0; i < count; i++) {
if(!it.hasNext())
break;
try {
GuildForumDataComposer.serializeForumData(this.response, it.next(), habbo);
} catch (SQLException e) {
return new ConnectionErrorComposer(500).compose();
}
}
return this.response;

View File

@ -1,15 +1,15 @@
package com.eu.habbo.messages.outgoing.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
public class GuildForumThreadMessagesComposer extends MessageComposer
{
public final GuildForumThread thread;
public final ForumThread thread;
public GuildForumThreadMessagesComposer(GuildForumThread thread)
public GuildForumThreadMessagesComposer(ForumThread thread)
{
this.thread = thread;
}

View File

@ -1,28 +1,61 @@
package com.eu.habbo.messages.outgoing.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer;
import java.util.*;
public class GuildForumThreadsComposer extends MessageComposer
{
public final GuildForum forum;
public final Guild guild;
public final int index;
public GuildForumThreadsComposer(GuildForum forum, int index)
public GuildForumThreadsComposer(Guild guild, int index)
{
this.forum = forum;
this.guild = guild;
this.index = index;
}
@Override
public ServerMessage compose()
{
ArrayList<ForumThread> threads;
try {
threads = new ArrayList<>(ForumThread.getByGuildId(guild.getId()));
} catch (Exception e) {
return new ConnectionErrorComposer(500).compose();
}
threads.sort(Comparator.comparingInt(o -> o.isPinned() ? Integer.MAX_VALUE : o.getUpdatedAt()));
Collections.reverse(threads);
Iterator<ForumThread> it = threads.iterator();
int count = threads.size() > 20 ? 20 : threads.size();
this.response.init(Outgoing.GuildForumThreadsComposer);
this.response.appendInt(this.forum.getGuild());
this.response.appendInt(this.guild.getId());
this.response.appendInt(this.index);
this.forum.serializeThreads(this.response);
this.response.appendInt(count);
for(int i = 0; i < index; i++) {
if(!it.hasNext())
break;
it.next();
}
for(int i = 0; i < count; i++) {
if(!it.hasNext())
break;
it.next().serialize(this.response);
}
return this.response;
}
}

View File

@ -1,6 +1,6 @@
package com.eu.habbo.messages.outgoing.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
@ -9,9 +9,9 @@ public class PostUpdateMessageComposer extends MessageComposer
{
public final int guildId;
public final int threadId;
public final GuildForumComment comment;
public final ForumThreadComment comment;
public PostUpdateMessageComposer(int guildId, int threadId, GuildForumComment comment)
public PostUpdateMessageComposer(int guildId, int threadId, ForumThreadComment comment)
{
this.guildId = guildId;
this.threadId = threadId;

View File

@ -3,8 +3,7 @@ package com.eu.habbo.messages.outgoing.guilds.forums;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.guilds.GuildRank;
import com.eu.habbo.habbohotel.guilds.forums.GuildForum;
import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
@ -13,9 +12,10 @@ import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
public class ThreadUpdatedMessageComposer extends MessageComposer {
public final GuildForumThread thread;
public final GuildForum forum;
public final Guild guild;
public final ForumThread thread;
private final Habbo habbo;
@ -23,21 +23,16 @@ public class ThreadUpdatedMessageComposer extends MessageComposer {
private final boolean isLocked;
public ThreadUpdatedMessageComposer(GuildForum forum, Integer thread, Habbo habbo, boolean isPinned, boolean isLocked) {
this.forum = forum;
public ThreadUpdatedMessageComposer(Guild guild, ForumThread thread, Habbo habbo, boolean isPinned, boolean isLocked) {
this.guild = guild;
this.habbo = habbo;
this.thread = forum.getThread(thread);
this.thread = thread;
this.isPinned = isPinned;
this.isLocked = isLocked;
}
@Override
public ServerMessage compose() {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(forum.getGuild());
if (this.thread == null)
return null;
if (isPinned != thread.isPinned()) {
this.habbo.getClient().sendResponse(new BubbleAlertComposer(isPinned ? BubbleAlertKeys.FORUMS_THREAD_PINNED.key : BubbleAlertKeys.FORUMS_THREAD_UNPINNED.key).compose());
}
@ -53,17 +48,11 @@ public class ThreadUpdatedMessageComposer extends MessageComposer {
this.thread.setPinned(isPinned);
this.thread.setLocked(isLocked);
this.response.init(Outgoing.ThreadUpdateMessageComposer);
this.response.appendInt(this.thread.getGuildId());
this.thread.serialize(this.response);
guild.needsUpdate = true;
Emulator.getThreading().run(this.thread);
Emulator.getThreading().run(guild);
this.response.init(Outgoing.ThreadUpdateMessageComposer);
this.response.appendInt(this.thread.getGuildId());
this.thread.serialize(this.response);
return this.response;
}

View File

@ -0,0 +1,35 @@
package com.eu.habbo.messages.outgoing.handshake;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
public class ConnectionErrorComposer extends MessageComposer
{
private final int messageId;
private final int errorCode;
private final String timestamp;
public ConnectionErrorComposer(int errorCode) {
this.messageId = 0;
this.errorCode = errorCode;
this.timestamp = "";
}
public ConnectionErrorComposer(int messageId, int errorCode, String timestamp) {
this.messageId = messageId;
this.errorCode = errorCode;
this.timestamp = timestamp;
}
@Override
public ServerMessage compose()
{
this.response.init(Outgoing.ConnectionErrorComposer);
this.response.appendInt(this.messageId);
this.response.appendInt(this.errorCode);
this.response.appendString(this.timestamp);
return this.response;
}
}

View File

@ -0,0 +1,19 @@
package com.eu.habbo.plugin.events.guilds.forums;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.plugin.Event;
public class GuildForumThreadBeforeCreated extends Event {
public final Guild guild;
public final Habbo opener;
public final String subject;
public final String message;
public GuildForumThreadBeforeCreated(Guild guild, Habbo opener, String subject, String message) {
this.guild = guild;
this.opener = opener;
this.subject = subject;
this.message = message;
}
}

View File

@ -0,0 +1,17 @@
package com.eu.habbo.plugin.events.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.plugin.Event;
public class GuildForumThreadCommentBeforeCreated extends Event {
public final ForumThread thread;
public final Habbo poster;
public final String message;
public GuildForumThreadCommentBeforeCreated(ForumThread thread, Habbo poster, String message) {
this.thread = thread;
this.poster = poster;
this.message = message;
}
}

View File

@ -0,0 +1,12 @@
package com.eu.habbo.plugin.events.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment;
import com.eu.habbo.plugin.Event;
public class GuildForumThreadCommentCreated extends Event {
public final ForumThreadComment comment;
public GuildForumThreadCommentCreated(ForumThreadComment comment) {
this.comment = comment;
}
}

View File

@ -0,0 +1,12 @@
package com.eu.habbo.plugin.events.guilds.forums;
import com.eu.habbo.habbohotel.guilds.forums.ForumThread;
import com.eu.habbo.plugin.Event;
public class GuildForumThreadCreated extends Event {
public final ForumThread thread;
public GuildForumThreadCreated(ForumThread thread) {
this.thread = thread;
}
}