From 992a961814fd2d87d2c00f14d7cca602c4c87e18 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 11 Aug 2019 12:22:18 +0300 Subject: [PATCH] Add error to badge command if user is not found --- sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql | 1 + .../habbo/habbohotel/commands/BadgeCommand.java | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql diff --git a/sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql b/sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql new file mode 100644 index 00000000..14a12715 --- /dev/null +++ b/sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql @@ -0,0 +1 @@ +INSERT INTO `emulator_texts`(`key`, `value`) VALUES ('commands.error.cmd_badge.unknown_user', 'Failed to find the given user.'); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java index 7e5e1208..eac670e7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java @@ -4,6 +4,8 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.users.HabboManager; import java.sql.Connection; import java.sql.PreparedStatement; @@ -38,11 +40,18 @@ public class BadgeCommand extends Command { return true; } else { + HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(params[1]); + + if (habboInfo == null) { + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_badge.unknown_user"), RoomChatMessageBubbles.ALERT); + return true; + } + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { boolean found; - try (PreparedStatement statement = connection.prepareStatement("SELECT `badge_code` FROM `users_badges` INNER JOIN `users` ON `users`.`id` = `user_id` WHERE `users`.`username` = ? AND `badge_code` = ? LIMIT 1")) { - statement.setString(1, params[1]); + try (PreparedStatement statement = connection.prepareStatement("SELECT `badge_code` FROM `users_badges` WHERE `user_id` = ? AND `badge_code` = ? LIMIT 1")) { + statement.setInt(1, habboInfo.getId()); statement.setString(2, params[2]); try (ResultSet set = statement.executeQuery()) { found = set.next(); @@ -53,8 +62,8 @@ public class BadgeCommand extends Command { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_badge.already_owns").replace("%user%", params[1]).replace("%badge%", params[2]), RoomChatMessageBubbles.ALERT); return true; } else { - try (PreparedStatement statement = connection.prepareStatement("INSERT INTO users_badges (`id`, `user_id`, `slot_id`, `badge_code`) VALUES (null, (SELECT `id` FROM `users` WHERE `username` = ? LIMIT 1), 0, ?)")) { - statement.setString(1, params[1]); + try (PreparedStatement statement = connection.prepareStatement("INSERT INTO users_badges (`id`, `user_id`, `slot_id`, `badge_code`) VALUES (null, ?, 0, ?)")) { + statement.setInt(1, habboInfo.getId()); statement.setString(2, params[2]); statement.execute(); }