From 46ff22f720293720bba593426c8c9c86596a7e77 Mon Sep 17 00:00:00 2001 From: Mike <76-Mike@users.noreply.git.krews.org> Date: Sun, 10 May 2020 00:11:56 +0200 Subject: [PATCH] Fix all last edge cases. --- .../commands/HotelAlertCommand.java | 17 ++- .../commands/ReloadRoomCommand.java | 9 +- .../gameclients/GameClientManager.java | 39 +++-- .../com/eu/habbo/habbohotel/rooms/Room.java | 136 ++++++++++-------- .../habbo/habbohotel/users/HabboManager.java | 11 +- .../FloorPlanEditorSaveEvent.java | 9 +- .../eu/habbo/messages/rcon/HotelAlert.java | 15 +- 7 files changed, 146 insertions(+), 90 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/HotelAlertCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/HotelAlertCommand.java index 6be973a9..0d5bfdd1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/HotelAlertCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/HotelAlertCommand.java @@ -24,15 +24,18 @@ public class HotelAlertCommand extends Command { } ServerMessage msg = new StaffAlertWithLinkComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername(), "").compose(); + msg.retain(); + try { + for (Map.Entry set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { + Habbo habbo = set.getValue(); + if (habbo.getHabboStats().blockStaffAlerts) + continue; - for (Map.Entry set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { - Habbo habbo = set.getValue(); - if (habbo.getHabboStats().blockStaffAlerts) - continue; - - habbo.getClient().sendResponse(msg); + habbo.getClient().sendResponse(msg); + } + } finally { + msg.release(); } - } else { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_ha.forgot_message"), RoomChatMessageBubbles.ALERT); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/ReloadRoomCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/ReloadRoomCommand.java index 1ccd20d0..42c11e50 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/ReloadRoomCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/ReloadRoomCommand.java @@ -24,8 +24,13 @@ public class ReloadRoomCommand extends Command { Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); ServerMessage message = new ForwardToRoomComposer(room.getId()).compose(); - for (Habbo habbo : habbos) { - habbo.getClient().sendResponse(message); + message.retain(); + try { + for (Habbo habbo : habbos) { + habbo.getClient().sendResponse(message); + } + } finally { + message.release(); } } }, 100); diff --git a/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClientManager.java b/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClientManager.java index ad9b28ff..dfbb7273 100644 --- a/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClientManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClientManager.java @@ -134,32 +134,47 @@ public class GameClientManager { public void sendBroadcastResponse(ServerMessage message) { - for (GameClient client : this.clients.values()) { - client.sendResponse(message); + message.retain(); + try { + for (GameClient client : this.clients.values()) { + client.sendResponse(message); + } + } finally { + message.release(); } } public void sendBroadcastResponse(ServerMessage message, GameClient exclude) { - for (GameClient client : this.clients.values()) { - if (client.equals(exclude)) - continue; + message.retain(); + try { + for (GameClient client : this.clients.values()) { + if (client.equals(exclude)) + continue; - client.sendResponse(message); + client.sendResponse(message); + } + } finally { + message.release(); } } public void sendBroadcastResponse(ServerMessage message, String minPermission, GameClient exclude) { - for (GameClient client : this.clients.values()) { - if (client.equals(exclude)) - continue; + message.retain(); + try { + for (GameClient client : this.clients.values()) { + if (client.equals(exclude)) + continue; - if (client.getHabbo() != null) { - if (client.getHabbo().hasPermission(minPermission)) { - client.sendResponse(message); + if (client.getHabbo() != null) { + if (client.getHabbo().hasPermission(minPermission)) { + client.sendResponse(message); + } } } + } finally { + message.release(); } } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index 85d108a3..ada54ce5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3115,57 +3115,87 @@ public class Room implements Comparable, ISerialize, Runnable { roomChatMessage.setMessage(trimmedMessage); - if (chatType == RoomChatType.WHISPER) { - if (roomChatMessage.getTargetHabbo() == null) { - return; - } + if (prefixMessage != null) { + prefixMessage.retain(); + } - RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage); - staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage()); + if (clearPrefixMessage != null) { + clearPrefixMessage.retain(); + } - final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose(); - final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose(); + try { + if (chatType == RoomChatType.WHISPER) { + if (roomChatMessage.getTargetHabbo() == null) { + return; + } - message.retain(); - staffMessage.retain(); + RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage); + staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage()); - try { - for (Habbo h : this.getHabbos()) { - if (h == roomChatMessage.getTargetHabbo() || h == habbo) { - if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { - if (prefixMessage != null) { - h.getClient().sendResponse(prefixMessage); + final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose(); + final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose(); + + message.retain(); + staffMessage.retain(); + + try { + for (Habbo h : this.getHabbos()) { + if (h == roomChatMessage.getTargetHabbo() || h == habbo) { + if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { + if (prefixMessage != null) { + h.getClient().sendResponse(prefixMessage); + } + h.getClient().sendResponse(message); + + if (clearPrefixMessage != null) { + h.getClient().sendResponse(clearPrefixMessage); + } } - h.getClient().sendResponse(message); - if (clearPrefixMessage != null) { - h.getClient().sendResponse(clearPrefixMessage); + continue; + } + if (h.hasPermission("acc_see_whispers")) { + h.getClient().sendResponse(staffMessage); + } + } + } finally { + message.release(); + staffMessage.release(); + } + } else if (chatType == RoomChatType.TALK) { + ServerMessage message = new RoomUserTalkComposer(roomChatMessage).compose(); + boolean noChatLimit = habbo.hasPermission("acc_chat_no_limit"); + + message.retain(); + + try { + for (Habbo h : this.getHabbos()) { + if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance || + h.equals(habbo) || + this.hasRights(h) || + noChatLimit) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) { + if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { + if (prefixMessage != null && !h.getHabboStats().preferOldChat) { + h.getClient().sendResponse(prefixMessage); + } + h.getClient().sendResponse(message); + if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat) { + h.getClient().sendResponse(clearPrefixMessage); + } } } - - continue; - } - if (h.hasPermission("acc_see_whispers")) { - h.getClient().sendResponse(staffMessage); } + } finally { + message.release(); } - } finally { - message.release(); - staffMessage.release(); - } - } else if (chatType == RoomChatType.TALK) { - ServerMessage message = new RoomUserTalkComposer(roomChatMessage).compose(); - boolean noChatLimit = habbo.hasPermission("acc_chat_no_limit"); + } else if (chatType == RoomChatType.SHOUT) { + ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose(); - message.retain(); + message.retain(); - try { - for (Habbo h : this.getHabbos()) { - if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance || - h.equals(habbo) || - this.hasRights(h) || - noChatLimit) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) { - if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { + try { + for (Habbo h : this.getHabbos()) { + if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) { if (prefixMessage != null && !h.getHabboStats().preferOldChat) { h.getClient().sendResponse(prefixMessage); } @@ -3175,29 +3205,17 @@ public class Room implements Comparable, ISerialize, Runnable { } } } + } finally { + message.release(); } - } finally { - message.release(); } - } else if (chatType == RoomChatType.SHOUT) { - ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose(); + } finally { + if (prefixMessage != null) { + prefixMessage.release(); + } - message.retain(); - - try { - for (Habbo h : this.getHabbos()) { - if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) { - if (prefixMessage != null && !h.getHabboStats().preferOldChat) { - h.getClient().sendResponse(prefixMessage); - } - h.getClient().sendResponse(message); - if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat) { - h.getClient().sendResponse(clearPrefixMessage); - } - } - } - } finally { - message.release(); + if (clearPrefixMessage != null) { + clearPrefixMessage.release(); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java index 8975b888..f21e385f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java @@ -179,10 +179,15 @@ public class HabboManager { public void sendPacketToHabbosWithPermission(ServerMessage message, String perm) { synchronized (this.onlineHabbos) { - for (Habbo habbo : this.onlineHabbos.values()) { - if (habbo.hasPermission(perm)) { - habbo.getClient().sendResponse(message); + message.retain(); + try { + for (Habbo habbo : this.onlineHabbos.values()) { + if (habbo.hasPermission(perm)) { + habbo.getClient().sendResponse(message); + } } + } finally { + message.release(); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/FloorPlanEditorSaveEvent.java b/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/FloorPlanEditorSaveEvent.java index 113dd0e3..5f6279df 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/FloorPlanEditorSaveEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/FloorPlanEditorSaveEvent.java @@ -148,8 +148,13 @@ public class FloorPlanEditorSaveEvent extends MessageHandler { Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); ServerMessage message = new ForwardToRoomComposer(room.getId()).compose(); - for (Habbo habbo : habbos) { - habbo.getClient().sendResponse(message); + message.retain(); + try { + for (Habbo habbo : habbos) { + habbo.getClient().sendResponse(message); + } + } finally { + message.release(); } } } diff --git a/src/main/java/com/eu/habbo/messages/rcon/HotelAlert.java b/src/main/java/com/eu/habbo/messages/rcon/HotelAlert.java index 70989239..912c52e1 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/HotelAlert.java +++ b/src/main/java/com/eu/habbo/messages/rcon/HotelAlert.java @@ -25,12 +25,17 @@ public class HotelAlert extends RCONMessage { } if (serverMessage != null) { - for (Map.Entry set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { - Habbo habbo = set.getValue(); - if (habbo.getHabboStats().blockStaffAlerts) - continue; + serverMessage.retain(); + try { + for (Map.Entry set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { + Habbo habbo = set.getValue(); + if (habbo.getHabboStats().blockStaffAlerts) + continue; - habbo.getClient().sendResponse(serverMessage); + habbo.getClient().sendResponse(serverMessage); + } + } finally { + serverMessage.release(); } } }