From 60a63e48323f11da8feaa8f0e9b37c919fabe5e3 Mon Sep 17 00:00:00 2001 From: Swirny Date: Tue, 19 May 2020 14:26:45 +0200 Subject: [PATCH 1/4] User can no longer ignore staffs --- sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql | 6 ++++- .../eu/habbo/habbohotel/users/HabboStats.java | 27 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql b/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql index 2f68174f..86864df5 100644 --- a/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql +++ b/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql @@ -8,4 +8,8 @@ INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('flood.with.rights', '0 ALTER TABLE `permissions` ADD `cmd_softkick` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `cmd_kickall`; INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.keys.cmd_softkick', 'softkick'); INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_softkick_not_found', '%user% not found'); -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_softkick_error_self', 'You can not softkick yourself!'); \ No newline at end of file +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_softkick_error_self', 'You can not softkick yourself!'); + +-- Rank ignoring +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('generic.error.higher_rank', 'You can\'t ignore this user.'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.ignore.staffs', '0'); \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java index 0b7797b6..29f68f17 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.users; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.achievements.Achievement; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.achievements.TalentTrackType; @@ -602,17 +603,23 @@ public class HabboStats implements Runnable { return 0; } - public void ignoreUser(int userId) { - if (!this.userIgnored(userId)) { - this.ignoredUsers.add(userId); + public void ignoreUser(GameClient gameClient, int userId) { + Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); + if (target.getHabboInfo().getRank().getId() >= gameClient.getHabbo().getHabboInfo().getRank().getId()) { + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("generic.error.higher_rank"), RoomChatMessageBubbles.ALERT); + } + else { + if (!this.userIgnored(userId)) { + this.ignoredUsers.add(userId); - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); - PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) { - statement.setInt(1, this.habboInfo.getId()); - statement.setInt(2, userId); - statement.execute(); - } catch (SQLException e) { - LOGGER.error("Caught SQL exception", e); + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); + PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) { + statement.setInt(1, this.habboInfo.getId()); + statement.setInt(2, userId); + statement.execute(); + } catch (SQLException e) { + LOGGER.error("Caught SQL exception", e); + } } } } From b638e04737c3ca1b83475065c834a079014b355a Mon Sep 17 00:00:00 2001 From: Swirny Date: Mon, 25 May 2020 18:49:42 +0200 Subject: [PATCH 2/4] Made ignore staff optional, active by default --- .../eu/habbo/habbohotel/users/HabboStats.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java index 29f68f17..3edea69f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java @@ -605,11 +605,25 @@ public class HabboStats implements Runnable { public void ignoreUser(GameClient gameClient, int userId) { Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); - if (target.getHabboInfo().getRank().getId() >= gameClient.getHabbo().getHabboInfo().getRank().getId()) { - gameClient.getHabbo().whisper(Emulator.getTexts().getValue("generic.error.higher_rank"), RoomChatMessageBubbles.ALERT); + if (!Emulator.getConfig().getBoolean("hotel.ignore.staffs")) { + if (target.getHabboInfo().getRank().getId() >= gameClient.getHabbo().getHabboInfo().getRank().getId()) { + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("generic.error.higher_rank"), RoomChatMessageBubbles.ALERT); + } else { + if (!this.userIgnored(userId)) { + this.ignoredUsers.add(userId); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); + PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) { + statement.setInt(1, this.habboInfo.getId()); + statement.setInt(2, userId); + statement.execute(); + } catch (SQLException e) { + LOGGER.error("Caught SQL exception", e); + } + } + } } - else { - if (!this.userIgnored(userId)) { + else if (!this.userIgnored(userId)) { this.ignoredUsers.add(userId); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); @@ -621,8 +635,8 @@ public class HabboStats implements Runnable { LOGGER.error("Caught SQL exception", e); } } + } - } public void unignoreUser(int userId) { if (this.userIgnored(userId)) { From d2d3dcc78c1e6ac95a349b3d06ea61faebf90642 Mon Sep 17 00:00:00 2001 From: Swirny Date: Mon, 25 May 2020 18:54:07 +0200 Subject: [PATCH 3/4] Fixed if-else statement --- src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java index 3edea69f..cf536f93 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java @@ -608,8 +608,7 @@ public class HabboStats implements Runnable { if (!Emulator.getConfig().getBoolean("hotel.ignore.staffs")) { if (target.getHabboInfo().getRank().getId() >= gameClient.getHabbo().getHabboInfo().getRank().getId()) { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("generic.error.higher_rank"), RoomChatMessageBubbles.ALERT); - } else { - if (!this.userIgnored(userId)) { + } else if (!this.userIgnored(userId)) { this.ignoredUsers.add(userId); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); @@ -622,7 +621,7 @@ public class HabboStats implements Runnable { } } } - } + else if (!this.userIgnored(userId)) { this.ignoredUsers.add(userId); From 5b52ece5e37d745489e030b8d02dd60f1496d810 Mon Sep 17 00:00:00 2001 From: Mike <76-Mike@users.noreply.git.krews.org> Date: Wed, 3 Jun 2020 04:26:07 +0200 Subject: [PATCH 4/4] Clean up code, fix bug showing it succeeded while it didn't --- sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql | 4 +- .../eu/habbo/habbohotel/users/HabboStats.java | 62 ++++++++++--------- .../incoming/modtool/ReportEvent.java | 14 +++-- .../rooms/users/IgnoreRoomUserEvent.java | 3 +- .../eu/habbo/messages/rcon/IgnoreUser.java | 2 +- 5 files changed, 44 insertions(+), 41 deletions(-) diff --git a/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql b/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql index 86864df5..2f406602 100644 --- a/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql +++ b/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql @@ -11,5 +11,5 @@ INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_softki INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_softkick_error_self', 'You can not softkick yourself!'); -- Rank ignoring -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('generic.error.higher_rank', 'You can\'t ignore this user.'); -INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.ignore.staffs', '0'); \ No newline at end of file +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('generic.error.ignore_higher_rank', 'You can\'t ignore this user.'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.allow.ignore.staffs', '1'); \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java index cf536f93..d40f1682 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java @@ -603,40 +603,42 @@ public class HabboStats implements Runnable { return 0; } - public void ignoreUser(GameClient gameClient, int userId) { - Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); - if (!Emulator.getConfig().getBoolean("hotel.ignore.staffs")) { - if (target.getHabboInfo().getRank().getId() >= gameClient.getHabbo().getHabboInfo().getRank().getId()) { - gameClient.getHabbo().whisper(Emulator.getTexts().getValue("generic.error.higher_rank"), RoomChatMessageBubbles.ALERT); - } else if (!this.userIgnored(userId)) { - this.ignoredUsers.add(userId); + /** + * Ignore an user. + * + * @param gameClient The client to which this HabboStats instance belongs. + * @param userId The user to ignore. + * @return true if successfully ignored, false otherwise. + */ + public boolean ignoreUser(GameClient gameClient, int userId) { + final Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); - PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) { - statement.setInt(1, this.habboInfo.getId()); - statement.setInt(2, userId); - statement.execute(); - } catch (SQLException e) { - LOGGER.error("Caught SQL exception", e); - } - } + if (!Emulator.getConfig().getBoolean("hotel.allow.ignore.staffs")) { + final int ownRank = gameClient.getHabbo().getHabboInfo().getRank().getId(); + final int targetRank = target.getHabboInfo().getRank().getId(); + + if (targetRank >= ownRank) { + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("generic.error.ignore_higher_rank"), RoomChatMessageBubbles.ALERT); + return false; } - - else if (!this.userIgnored(userId)) { - this.ignoredUsers.add(userId); - - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); - PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) { - statement.setInt(1, this.habboInfo.getId()); - statement.setInt(2, userId); - statement.execute(); - } catch (SQLException e) { - LOGGER.error("Caught SQL exception", e); - } - } - } + if (!this.userIgnored(userId)) { + this.ignoredUsers.add(userId); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); + PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) { + statement.setInt(1, this.habboInfo.getId()); + statement.setInt(2, userId); + statement.execute(); + } catch (SQLException e) { + LOGGER.error("Caught SQL exception", e); + } + } + + return true; + } + public void unignoreUser(int userId) { if (this.userIgnored(userId)) { this.ignoredUsers.remove(userId); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportEvent.java index 8b2122e5..22a81fc1 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ReportEvent.java @@ -73,8 +73,9 @@ public class ReportEvent extends MessageHandler { Emulator.getThreading().run(() -> { if (issue.state == ModToolTicketState.OPEN) { if (cfhTopic.action == CfhActionType.AUTO_IGNORE) { - ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(reported.getHabboInfo().getId()); - ReportEvent.this.client.sendResponse(new RoomUserIgnoredComposer(reported, RoomUserIgnoredComposer.IGNORED)); + if (ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(ReportEvent.this.client, reported.getHabboInfo().getId())) { + ReportEvent.this.client.sendResponse(new RoomUserIgnoredComposer(reported, RoomUserIgnoredComposer.IGNORED)); + } } ReportEvent.this.client.sendResponse(new ModToolIssueHandledComposer(cfhTopic.reply).compose()); @@ -99,10 +100,11 @@ public class ReportEvent extends MessageHandler { Emulator.getThreading().run(() -> { if (issue.state == ModToolTicketState.OPEN) { if (cfhTopic.action == CfhActionType.AUTO_IGNORE) { - ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(issue.reportedId); - Habbo reported = Emulator.getGameEnvironment().getHabboManager().getHabbo(issue.reportedId); - if (reported != null) { - ReportEvent.this.client.sendResponse(new RoomUserIgnoredComposer(reported, RoomUserIgnoredComposer.IGNORED)); + if (ReportEvent.this.client.getHabbo().getHabboStats().ignoreUser(ReportEvent.this.client, issue.reportedId)) { + Habbo reported = Emulator.getGameEnvironment().getHabboManager().getHabbo(issue.reportedId); + if (reported != null) { + ReportEvent.this.client.sendResponse(new RoomUserIgnoredComposer(reported, RoomUserIgnoredComposer.IGNORED)); + } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/IgnoreRoomUserEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/IgnoreRoomUserEvent.java index 2cd65c81..88621035 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/IgnoreRoomUserEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/IgnoreRoomUserEvent.java @@ -21,8 +21,7 @@ public class IgnoreRoomUserEvent extends MessageHandler { if (habbo == this.client.getHabbo()) return; - { - this.client.getHabbo().getHabboStats().ignoreUser(habbo.getHabboInfo().getId()); + if (this.client.getHabbo().getHabboStats().ignoreUser(this.client, habbo.getHabboInfo().getId())) { this.client.sendResponse(new RoomUserIgnoredComposer(habbo, RoomUserIgnoredComposer.IGNORED)); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("SelfModIgnoreSeen")); } diff --git a/src/main/java/com/eu/habbo/messages/rcon/IgnoreUser.java b/src/main/java/com/eu/habbo/messages/rcon/IgnoreUser.java index 7a4799d4..852a1764 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/IgnoreUser.java +++ b/src/main/java/com/eu/habbo/messages/rcon/IgnoreUser.java @@ -22,7 +22,7 @@ public class IgnoreUser extends RCONMessage { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(object.user_id); if (habbo != null) { - habbo.getHabboStats().ignoreUser(object.target_id); + habbo.getHabboStats().ignoreUser(habbo.getClient(), object.target_id); } else { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) {