From 7bd31aed7b0ec696cf3cca4fabadc700b31fe7cc Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 27 Dec 2019 14:38:45 +0200 Subject: [PATCH 1/3] Modify HabboAddedToRoomEvent --- .../habbo/habbohotel/rooms/RoomManager.java | 21 +++++++++++++------ .../events/users/HabboAddedToRoomEvent.java | 6 +++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index d1c9a692..9157886e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.core.RoomUserPetComposer; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame; import com.eu.habbo.habbohotel.games.football.FootballGame; @@ -40,6 +41,7 @@ import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer; import com.eu.habbo.messages.outgoing.rooms.promotions.RoomPromotionMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.*; import com.eu.habbo.messages.outgoing.users.MutedWhisperComposer; +import com.eu.habbo.plugin.Event; import com.eu.habbo.plugin.events.navigator.NavigatorRoomCreatedEvent; import com.eu.habbo.plugin.events.rooms.RoomUncachedEvent; import com.eu.habbo.plugin.events.rooms.UserVoteRoomEvent; @@ -710,9 +712,20 @@ public class RoomManager { List habbos = new ArrayList<>(); if (!room.getCurrentHabbos().isEmpty()) { + Collection habbosToSendEnter = room.getCurrentHabbos().values(); - room.sendComposer(new RoomUsersComposer(habbo).compose()); - room.sendComposer(new RoomUserStatusComposer(habbo.getRoomUnit()).compose()); + if (Emulator.getPluginManager().isRegistered(HabboAddedToRoomEvent.class, false)) { + HabboAddedToRoomEvent event = Emulator.getPluginManager().fireEvent(new HabboAddedToRoomEvent(habbo, room, habbosToSendEnter)); + habbosToSendEnter = event.habbosToSendEnter; + } + + for (Habbo habboToSendEnter : habbosToSendEnter) { + GameClient client = habboToSendEnter.getClient(); + if (client != null) { + client.sendResponse(new RoomUsersComposer(habbo).compose()); + habboToSendEnter.getClient().sendResponse(new RoomUserStatusComposer(habbo.getRoomUnit()).compose()); + } + } for (Habbo h : room.getHabbos()) { if (!h.getRoomUnit().isInvisible()) { @@ -890,10 +903,6 @@ public class RoomManager { if (!habbo.getHabboStats().nux && (room.isOwner(habbo) || room.isPublicRoom())) { UserNuxEvent.handle(habbo); } - - if (Emulator.getPluginManager().isRegistered(HabboAddedToRoomEvent.class, false)) { - Emulator.getPluginManager().fireEvent(new HabboAddedToRoomEvent(habbo, room)); - } } void logEnter(Habbo habbo, Room room) { diff --git a/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java index be861f8a..d31f4a6c 100644 --- a/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java @@ -3,14 +3,18 @@ package com.eu.habbo.plugin.events.users; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; +import java.util.Collection; + public class HabboAddedToRoomEvent extends UserEvent { public final Room room; + public final Collection habbosToSendEnter; - public HabboAddedToRoomEvent(Habbo habbo, Room room) { + public HabboAddedToRoomEvent(Habbo habbo, Room room, Collection habbosToSendEnter) { super(habbo); this.room = room; + this.habbosToSendEnter = habbosToSendEnter; } } From 9f8850b0bd20b2995e883b8f46733a655eec83de Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 27 Dec 2019 17:41:55 +0200 Subject: [PATCH 2/3] Add annotation to mark messages that don't need auth --- .../com/eu/habbo/messages/NoAuthMessage.java | 7 +++++++ .../com/eu/habbo/messages/PacketManager.java | 17 +++++++++++++---- .../incoming/handshake/MachineIDEvent.java | 2 ++ .../incoming/handshake/ReleaseVersionEvent.java | 2 ++ .../incoming/handshake/SecureLoginEvent.java | 2 ++ 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/eu/habbo/messages/NoAuthMessage.java diff --git a/src/main/java/com/eu/habbo/messages/NoAuthMessage.java b/src/main/java/com/eu/habbo/messages/NoAuthMessage.java new file mode 100644 index 00000000..47487068 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/NoAuthMessage.java @@ -0,0 +1,7 @@ +package com.eu.habbo.messages; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface NoAuthMessage {} diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index 989a6e6d..d5e2eb8e 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -156,11 +156,20 @@ public class PacketManager { if (client == null || Emulator.isShuttingDown) return; - if (client.getHabbo() == null && !(packet.getMessageId() == Incoming.SecureLoginEvent || packet.getMessageId() == Incoming.MachineIDEvent)) - return; - try { if (this.isRegistered(packet.getMessageId())) { + Class handlerClass = this.incoming.get(packet.getMessageId()); + + if (handlerClass == null) throw new Exception("Unknown message " + packet.getMessageId()); + + if (client.getHabbo() == null && !handlerClass.isAnnotationPresent(NoAuthMessage.class)) { + if (DEBUG_SHOW_PACKETS) { + Emulator.getLogging().logPacketLine("[\033[36mCLIENT\033[0m][\033[33mNOT LOGGED IN\033[0m][" + packet.getMessageId() + "] => " + packet.getMessageBody()); + } + + return; + } + if (PacketManager.DEBUG_SHOW_PACKETS) Emulator.getLogging().logPacketLine("[" + Logging.ANSI_CYAN + "CLIENT" + Logging.ANSI_RESET + "][" + packet.getMessageId() + "] => " + packet.getMessageBody()); @@ -168,7 +177,7 @@ public class PacketManager { System.out.println(("[" + Logging.ANSI_CYAN + "CLIENT" + Logging.ANSI_RESET + "][" + client.getHabbo().getHabboInfo().getUsername() + "][" + packet.getMessageId() + "] => " + packet.getMessageBody())); } - final MessageHandler handler = this.incoming.get(packet.getMessageId()).newInstance(); + final MessageHandler handler = handlerClass.newInstance(); handler.client = client; handler.packet = packet; diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/MachineIDEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/MachineIDEvent.java index fd50c886..7be07c04 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/MachineIDEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/MachineIDEvent.java @@ -1,8 +1,10 @@ package com.eu.habbo.messages.incoming.handshake; +import com.eu.habbo.messages.NoAuthMessage; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.handshake.MachineIDComposer; +@NoAuthMessage public class MachineIDEvent extends MessageHandler { @Override diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/ReleaseVersionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/ReleaseVersionEvent.java index 4dfe71ae..e9ea57e1 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/ReleaseVersionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/ReleaseVersionEvent.java @@ -1,7 +1,9 @@ package com.eu.habbo.messages.incoming.handshake; +import com.eu.habbo.messages.NoAuthMessage; import com.eu.habbo.messages.incoming.MessageHandler; +@NoAuthMessage public class ReleaseVersionEvent extends MessageHandler { @Override diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index a899c5b0..6759a1e6 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboManager; +import com.eu.habbo.messages.NoAuthMessage; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.achievements.AchievementListComposer; @@ -31,6 +32,7 @@ import com.eu.habbo.plugin.events.users.UserLoginEvent; import java.util.ArrayList; +@NoAuthMessage public class SecureLoginEvent extends MessageHandler { From 427fc9fb2488cd53fa69ad781a7dc4937f2bb17c Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Thu, 2 Jan 2020 11:03:06 +0200 Subject: [PATCH 3/3] Update PacketManager logging --- src/main/java/com/eu/habbo/messages/PacketManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index d5e2eb8e..7cda01db 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -164,7 +164,7 @@ public class PacketManager { if (client.getHabbo() == null && !handlerClass.isAnnotationPresent(NoAuthMessage.class)) { if (DEBUG_SHOW_PACKETS) { - Emulator.getLogging().logPacketLine("[\033[36mCLIENT\033[0m][\033[33mNOT LOGGED IN\033[0m][" + packet.getMessageId() + "] => " + packet.getMessageBody()); + Emulator.getLogging().logPacketLine("[" + Logging.ANSI_CYAN + "CLIENT" + Logging.ANSI_RESET + "][" + Logging.ANSI_RED + "NOT LOGGED IN" + Logging.ANSI_RESET + "][" + packet.getMessageId() + "] => " + packet.getMessageBody()); } return; @@ -193,7 +193,7 @@ public class PacketManager { } } else { if (PacketManager.DEBUG_SHOW_PACKETS) - Emulator.getLogging().logPacketLine("[" + Logging.ANSI_CYAN + "CLIENT" + Logging.ANSI_RESET + "][" + Logging.ANSI_RED + "UNDEFINED" + Logging.ANSI_RESET + "][" + packet.getMessageId() + "] => " + packet.getMessageBody()); + Emulator.getLogging().logPacketLine("[" + Logging.ANSI_CYAN + "CLIENT" + Logging.ANSI_RESET + "][" + Logging.ANSI_YELLOW + "UNDEFINED" + Logging.ANSI_RESET + "][" + packet.getMessageId() + "] => " + packet.getMessageBody()); } } catch (Exception e) { Emulator.getLogging().logErrorLine(e);