From 21c87145ea4e8e0c5d541387c0129789d18e3efa Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 7 Jun 2020 15:21:29 +0300 Subject: [PATCH] Prevent adding yourself as a friend --- .../java/com/eu/habbo/habbohotel/messenger/Messenger.java | 8 +++++++- .../messages/incoming/friends/FriendRequestEvent.java | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java b/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java index 15ef797a..59c6083a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java +++ b/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java @@ -214,7 +214,13 @@ public class Messenger { try (ResultSet set = statement.executeQuery()) { while (set.next()) { - this.friends.putIfAbsent(set.getInt("id"), new MessengerBuddy(set)); + MessengerBuddy buddy = new MessengerBuddy(set); + + if (buddy.getId() == habbo.getHabboInfo().getId()) { + continue; + } + + this.friends.putIfAbsent(set.getInt("id"), buddy); } } } catch (SQLException e) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/friends/FriendRequestEvent.java b/src/main/java/com/eu/habbo/messages/incoming/friends/FriendRequestEvent.java index 09f8ec6f..f595d730 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/friends/FriendRequestEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/friends/FriendRequestEvent.java @@ -25,6 +25,10 @@ public class FriendRequestEvent extends MessageHandler { String username = this.packet.readString(); Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(username); + if (habbo.getHabboInfo().getId() == this.client.getHabbo().getHabboInfo().getId()) { + return; + } + if (Emulator.getPluginManager().fireEvent(new UserRequestFriendshipEvent(this.client.getHabbo(), username, habbo)).isCancelled()) { this.client.sendResponse(new FriendRequestErrorComposer(2)); return;