From 25d8ffba96aabea9d7d93a1d7975a66f2680f3d5 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Thu, 30 May 2019 21:05:25 +0300 Subject: [PATCH] Add forum thread/comment reporting --- sqlupdates/2_0_0_TO_2_1_0-RC-1.sql | 7 ++- .../habbohotel/modtool/ModToolChatLog.java | 10 +++++ .../habbohotel/modtool/ModToolIssue.java | 3 ++ .../modtool/ModToolIssueChatlogType.java | 21 +++++++++ .../com/eu/habbo/messages/PacketManager.java | 2 + .../eu/habbo/messages/incoming/Incoming.java | 2 + .../ModToolRequestIssueChatlogEvent.java | 34 ++++++++++++--- .../incoming/modtool/ReportCommentEvent.java | 43 +++++++++++++++++++ .../incoming/modtool/ReportThreadEvent.java | 41 ++++++++++++++++++ .../modtool/ModToolIssueChatlogComposer.java | 43 +++++++++++++------ .../runnables/InsertModToolIssue.java | 5 ++- 11 files changed, 191 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssueChatlogType.java create mode 100644 src/main/java/com/eu/habbo/messages/incoming/modtool/ReportCommentEvent.java create mode 100644 src/main/java/com/eu/habbo/messages/incoming/modtool/ReportThreadEvent.java diff --git a/sqlupdates/2_0_0_TO_2_1_0-RC-1.sql b/sqlupdates/2_0_0_TO_2_1_0-RC-1.sql index f046fdf2..b751625b 100644 --- a/sqlupdates/2_0_0_TO_2_1_0-RC-1.sql +++ b/sqlupdates/2_0_0_TO_2_1_0-RC-1.sql @@ -10,4 +10,9 @@ ALTER TABLE `users_settings` ADD COLUMN `ui_flags` int(11) NOT NULL DEFAULT 1 AFTER `forums_post_count`; ALTER TABLE `users_settings` -ADD COLUMN `has_gotten_default_saved_searches` tinyint(1) NOT NULL DEFAULT 0 AFTER `ui_flags`; \ No newline at end of file +ADD COLUMN `has_gotten_default_saved_searches` tinyint(1) NOT NULL DEFAULT 0 AFTER `ui_flags`; + +ALTER TABLE `support_tickets` +ADD COLUMN `group_id` int(11) NOT NULL AFTER `category`, +ADD COLUMN `thread_id` int(11) NOT NULL AFTER `group_id`, +ADD COLUMN `comment_id` int(11) NOT NULL AFTER `thread_id`; \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolChatLog.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolChatLog.java index 8663e27d..0ba469f7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolChatLog.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolChatLog.java @@ -5,12 +5,22 @@ public class ModToolChatLog implements Comparable { public final int habboId; public final String username; public final String message; + public final boolean highlighted; public ModToolChatLog(int timestamp, int habboId, String username, String message) { this.timestamp = timestamp; this.habboId = habboId; this.username = username; this.message = message; + this.highlighted = false; + } + + public ModToolChatLog(int timestamp, int habboId, String username, String message, boolean highlighted) { + this.timestamp = timestamp; + this.habboId = habboId; + this.username = username; + this.message = message; + this.highlighted = highlighted; } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssue.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssue.java index 5e73e86c..531ffb7c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssue.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssue.java @@ -25,6 +25,9 @@ public class ModToolIssue implements ISerialize { public volatile String modName = ""; public String message; public ArrayList chatLogs = null; + public int groupId = -1; + public int threadId = -1; + public int commentId = -1; public ModToolIssue(ResultSet set) throws SQLException { this.id = set.getInt("id"); diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssueChatlogType.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssueChatlogType.java new file mode 100644 index 00000000..35db44b7 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssueChatlogType.java @@ -0,0 +1,21 @@ +package com.eu.habbo.habbohotel.modtool; + +public enum ModToolIssueChatlogType { + NORMAL(0), + CHAT(1), + IM(2), + FORUM_THREAD(3), + FORUM_COMMENT(4), + SELFIE(5), + PHOTO(6); + + private int type; + + ModToolIssueChatlogType(int type) { + this.type = type; + } + + public int getType() { + return type; + } +} diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index 96dfbb30..f92cd743 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -466,6 +466,8 @@ public class PacketManager { this.registerHandler(Incoming.ReportBullyEvent, ReportBullyEvent.class); this.registerHandler(Incoming.ReportEvent, ReportEvent.class); this.registerHandler(Incoming.ReportFriendPrivateChatEvent, ReportFriendPrivateChatEvent.class); + this.registerHandler(Incoming.ReportThreadEvent, ReportThreadEvent.class); + this.registerHandler(Incoming.ReportCommentEvent, ReportCommentEvent.class); } void registerTrading() throws Exception { diff --git a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java index a47fd162..ba2e48b7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java +++ b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java @@ -290,6 +290,8 @@ public class Incoming { public static final int SaveWindowSettingsEvent = 3159; public static final int GetHabboGuildBadgesMessageEvent = 21; public static final int UpdateUIFlagsEvent = 2313; + public static final int ReportThreadEvent = 534; + public static final int ReportCommentEvent = 1412; public static final int RequestCraftingRecipesEvent = 1173; public static final int RequestCraftingRecipesAvailableEvent = 3086; diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestIssueChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestIssueChatlogEvent.java index 2b4b31f0..50757290 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestIssueChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestIssueChatlogEvent.java @@ -1,16 +1,16 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.modtool.ModToolChatLog; -import com.eu.habbo.habbohotel.modtool.ModToolIssue; -import com.eu.habbo.habbohotel.modtool.ModToolTicketType; -import com.eu.habbo.habbohotel.modtool.ScripterManager; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.modtool.*; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.modtool.ModToolIssueChatlogComposer; import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; public class ModToolRequestIssueChatlogEvent extends MessageHandler { @Override @@ -19,11 +19,33 @@ public class ModToolRequestIssueChatlogEvent extends MessageHandler { ModToolIssue issue = Emulator.getGameEnvironment().getModToolManager().getTicket(this.packet.readInt()); if (issue != null) { - ArrayList chatlog; + List chatlog = new ArrayList<>(); + ModToolIssueChatlogType chatlogType = ModToolIssueChatlogType.CHAT; if (issue.type == ModToolTicketType.IM) { chatlog = Emulator.getGameEnvironment().getModToolManager().getMessengerChatlog(issue.reportedId, issue.senderId); + chatlogType = ModToolIssueChatlogType.IM; + } else if (issue.type == ModToolTicketType.DISCUSSION) { + if (issue.commentId == -1) { + chatlogType = ModToolIssueChatlogType.FORUM_THREAD; + + ForumThread thread = ForumThread.getById(issue.threadId); + + if (thread != null) { + chatlog = thread.getComments().stream().map(c -> new ModToolChatLog(c.getCreatedAt(), c.getHabbo().getHabboInfo().getId(), c.getHabbo().getHabboInfo().getUsername(), c.getMessage())).collect(Collectors.toList()); + } + } else { + chatlogType = ModToolIssueChatlogType.FORUM_COMMENT; + + ForumThread thread = ForumThread.getById(issue.threadId); + + if (thread != null) { + chatlog = thread.getComments().stream().map(c -> new ModToolChatLog(c.getCreatedAt(), c.getHabbo().getHabboInfo().getId(), c.getHabbo().getHabboInfo().getUsername(), c.getMessage(), c.getCommentId() == issue.commentId)).collect(Collectors.toList()); + } + } } else { + chatlogType = ModToolIssueChatlogType.CHAT; + if (issue.roomId > 0) { chatlog = Emulator.getGameEnvironment().getModToolManager().getRoomChatlog(issue.roomId); } else { @@ -39,7 +61,7 @@ public class ModToolRequestIssueChatlogEvent extends MessageHandler { if (room != null) { roomName = room.getName(); } - this.client.sendResponse(new ModToolIssueChatlogComposer(issue, chatlog, roomName)); + this.client.sendResponse(new ModToolIssueChatlogComposer(issue, chatlog, roomName, chatlogType)); } } else { ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportCommentEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportCommentEvent.java new file mode 100644 index 00000000..b21849ba --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportCommentEvent.java @@ -0,0 +1,43 @@ +package com.eu.habbo.messages.incoming.modtool; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.modtool.CfhTopic; +import com.eu.habbo.habbohotel.modtool.ModToolIssue; +import com.eu.habbo.habbohotel.modtool.ModToolTicketType; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.modtool.ModToolReportReceivedAlertComposer; +import com.eu.habbo.threading.runnables.InsertModToolIssue; + +public class ReportCommentEvent extends MessageHandler { + @Override + public void handle() throws Exception { + int groupId = this.packet.readInt(); + int threadId = this.packet.readInt(); + int commentId = this.packet.readInt(); + int topicId = this.packet.readInt(); + String message = this.packet.readString(); + + CfhTopic topic = Emulator.getGameEnvironment().getModToolManager().getCfhTopic(topicId); + + if (topic == null) return; + + ForumThread thread = ForumThread.getById(threadId); + + if (thread == null) return; + + Habbo opener = Emulator.getGameEnvironment().getHabboManager().getHabbo(thread.getOpenerId()); + + ModToolIssue issue = new ModToolIssue(this.client.getHabbo().getHabboInfo().getId(), this.client.getHabbo().getHabboInfo().getUsername(), thread.getOpenerId(), opener == null ? "" : opener.getHabboInfo().getUsername(), 0, message, ModToolTicketType.DISCUSSION); + issue.category = topicId; + issue.groupId = groupId; + issue.threadId = threadId; + issue.commentId = commentId; + new InsertModToolIssue(issue).run(); + + this.client.sendResponse(new ModToolReportReceivedAlertComposer(ModToolReportReceivedAlertComposer.REPORT_RECEIVED, message)); + Emulator.getGameEnvironment().getModToolManager().addTicket(issue); + Emulator.getGameEnvironment().getModToolManager().updateTicketToMods(issue); + } +} diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportThreadEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportThreadEvent.java new file mode 100644 index 00000000..50bcab89 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportThreadEvent.java @@ -0,0 +1,41 @@ +package com.eu.habbo.messages.incoming.modtool; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.modtool.CfhTopic; +import com.eu.habbo.habbohotel.modtool.ModToolIssue; +import com.eu.habbo.habbohotel.modtool.ModToolTicketType; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.modtool.ModToolReportReceivedAlertComposer; +import com.eu.habbo.threading.runnables.InsertModToolIssue; + +public class ReportThreadEvent extends MessageHandler { + @Override + public void handle() throws Exception { + int groupId = this.packet.readInt(); + int threadId = this.packet.readInt(); + int topicId = this.packet.readInt(); + String message = this.packet.readString(); + + CfhTopic topic = Emulator.getGameEnvironment().getModToolManager().getCfhTopic(topicId); + + if (topic == null) return; + + ForumThread thread = ForumThread.getById(threadId); + + if (thread == null) return; + + Habbo opener = Emulator.getGameEnvironment().getHabboManager().getHabbo(thread.getOpenerId()); + + ModToolIssue issue = new ModToolIssue(this.client.getHabbo().getHabboInfo().getId(), this.client.getHabbo().getHabboInfo().getUsername(), thread.getOpenerId(), opener == null ? "" : opener.getHabboInfo().getUsername(), 0, message, ModToolTicketType.DISCUSSION); + issue.category = topicId; + issue.groupId = groupId; + issue.threadId = threadId; + new InsertModToolIssue(issue).run(); + + this.client.sendResponse(new ModToolReportReceivedAlertComposer(ModToolReportReceivedAlertComposer.REPORT_RECEIVED, message)); + Emulator.getGameEnvironment().getModToolManager().addTicket(issue); + Emulator.getGameEnvironment().getModToolManager().updateTicketToMods(issue); + } +} diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolIssueChatlogComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolIssueChatlogComposer.java index 1aac7aea..8eef3dc8 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolIssueChatlogComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolIssueChatlogComposer.java @@ -1,9 +1,8 @@ package com.eu.habbo.messages.outgoing.modtool; -import com.eu.habbo.habbohotel.modtool.ModToolChatLog; -import com.eu.habbo.habbohotel.modtool.ModToolChatRecordDataContext; -import com.eu.habbo.habbohotel.modtool.ModToolIssue; -import com.eu.habbo.habbohotel.modtool.ModToolTicketType; +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.*; +import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -11,19 +10,28 @@ import com.eu.habbo.messages.outgoing.Outgoing; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.List; public class ModToolIssueChatlogComposer extends MessageComposer { public static SimpleDateFormat format = new SimpleDateFormat("HH:mm"); private final ModToolIssue issue; - private final ArrayList chatlog; + private final List chatlog; private final String roomName; + private ModToolIssueChatlogType type = ModToolIssueChatlogType.CHAT; - public ModToolIssueChatlogComposer(ModToolIssue issue, ArrayList chatlog, String roomName) { + public ModToolIssueChatlogComposer(ModToolIssue issue, List chatlog, String roomName) { this.issue = issue; this.chatlog = chatlog; this.roomName = roomName; } + public ModToolIssueChatlogComposer(ModToolIssue issue, List chatlog, String roomName, ModToolIssueChatlogType type) { + this.issue = issue; + this.chatlog = chatlog; + this.roomName = roomName; + this.type = type; + } + @Override public ServerMessage compose() { this.response.init(Outgoing.ModToolIssueChatlogComposer); @@ -37,16 +45,26 @@ public class ModToolIssueChatlogComposer extends MessageComposer { if (this.chatlog.isEmpty()) return null; - //ChatRecordData - //for(ModToolRoomVisit visit : chatlog) - //{ - this.response.appendByte(1); //Report Type + this.response.appendByte(this.type.getType()); //Report Type if (this.issue.type == ModToolTicketType.IM) { this.response.appendShort(1); ModToolChatRecordDataContext.MESSAGE_ID.append(this.response); this.response.appendInt(this.issue.senderId); + } else if (this.issue.type == ModToolTicketType.DISCUSSION) { + this.response.appendShort(this.type == ModToolIssueChatlogType.FORUM_COMMENT ? 3 : 2); + + ModToolChatRecordDataContext.GROUP_ID.append(this.response); + this.response.appendInt(this.issue.groupId); + + ModToolChatRecordDataContext.THREAD_ID.append(this.response); + this.response.appendInt(this.issue.threadId); + + if (this.type == ModToolIssueChatlogType.FORUM_COMMENT) { + ModToolChatRecordDataContext.GROUP_ID.append(this.response); + this.response.appendInt(this.issue.commentId); + } } else { this.response.appendShort(3); //Context Count @@ -57,7 +75,8 @@ public class ModToolIssueChatlogComposer extends MessageComposer { this.response.appendInt(this.issue.roomId); ModToolChatRecordDataContext.GROUP_ID.append(this.response); - this.response.appendInt(12); + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.issue.roomId); + this.response.appendInt(room == null ? 0 : room.getGuildId()); } this.response.appendShort(this.chatlog.size()); @@ -66,7 +85,7 @@ public class ModToolIssueChatlogComposer extends MessageComposer { this.response.appendInt(chatLog.habboId); this.response.appendString(chatLog.username); this.response.appendString(chatLog.message); - this.response.appendBoolean(false); + this.response.appendBoolean(chatLog.highlighted); } //} diff --git a/src/main/java/com/eu/habbo/threading/runnables/InsertModToolIssue.java b/src/main/java/com/eu/habbo/threading/runnables/InsertModToolIssue.java index cda020d6..af335844 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/InsertModToolIssue.java +++ b/src/main/java/com/eu/habbo/threading/runnables/InsertModToolIssue.java @@ -14,7 +14,7 @@ public class InsertModToolIssue implements Runnable { @Override public void run() { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO support_tickets (state, timestamp, score, sender_id, reported_id, room_id, mod_id, issue, category) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO support_tickets (state, timestamp, score, sender_id, reported_id, room_id, mod_id, issue, category, group_id, thread_id, comment_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { statement.setInt(1, this.issue.state.getState()); statement.setInt(2, this.issue.timestamp); statement.setInt(3, this.issue.priority); @@ -24,6 +24,9 @@ public class InsertModToolIssue implements Runnable { statement.setInt(7, this.issue.modId); statement.setString(8, this.issue.message); statement.setInt(9, this.issue.category); + statement.setInt(10, this.issue.groupId); + statement.setInt(11, this.issue.threadId); + statement.setInt(12, this.issue.commentId); statement.execute(); try (ResultSet key = statement.getGeneratedKeys()) {