From 4c140d940255992af2d69ff0799e3e4b9afa130b Mon Sep 17 00:00:00 2001 From: Mike <76-Mike@users.noreply.git.krews.org> Date: Sat, 9 May 2020 23:05:51 +0200 Subject: [PATCH] Fix more edge cases. --- .../com/eu/habbo/habbohotel/rooms/Room.java | 91 ++++++++++++------- .../encoders/GameServerMessageEncoder.java | 11 +-- 2 files changed, 60 insertions(+), 42 deletions(-) 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 5338ce24..85d108a3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3120,40 +3120,73 @@ public class Room implements Comparable, ISerialize, Runnable { return; } - final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose(); RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage); staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage()); + + final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose(); final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose(); - 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); + message.retain(); + staffMessage.retain(); - if (clearPrefixMessage != null) { - h.getClient().sendResponse(clearPrefixMessage); + 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); + } } + + continue; + } + if (h.hasPermission("acc_see_whispers")) { + h.getClient().sendResponse(staffMessage); } - - 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"); - 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())) { + 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); + } + } + } + } + } finally { + message.release(); + } + } else if (chatType == RoomChatType.SHOUT) { + ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose(); + + 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); } @@ -3163,20 +3196,8 @@ public class Room implements Comparable, ISerialize, Runnable { } } } - } - } else if (chatType == RoomChatType.SHOUT) { - ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose(); - - 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(); } } diff --git a/src/main/java/com/eu/habbo/networking/gameserver/encoders/GameServerMessageEncoder.java b/src/main/java/com/eu/habbo/networking/gameserver/encoders/GameServerMessageEncoder.java index 3b706fa6..51fdacf9 100644 --- a/src/main/java/com/eu/habbo/networking/gameserver/encoders/GameServerMessageEncoder.java +++ b/src/main/java/com/eu/habbo/networking/gameserver/encoders/GameServerMessageEncoder.java @@ -5,15 +5,13 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; import io.netty.util.IllegalReferenceCountException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import java.io.IOException; public class GameServerMessageEncoder extends MessageToByteEncoder { - private static final Logger LOGGER = LoggerFactory.getLogger(GameServerMessageEncoder.class); - @Override - protected void encode(ChannelHandlerContext ctx, ServerMessage message, ByteBuf out) { + protected void encode(ChannelHandlerContext ctx, ServerMessage message, ByteBuf out) throws Exception { try { ByteBuf buf = message.get(); @@ -24,8 +22,7 @@ public class GameServerMessageEncoder extends MessageToByteEncoder