Fix more edge cases.

This commit is contained in:
Mike 2020-05-09 23:05:51 +02:00
parent a93ffbbbac
commit 4c140d9402
2 changed files with 60 additions and 42 deletions

View File

@ -3120,11 +3120,16 @@ public class Room implements Comparable<Room>, 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();
message.retain();
staffMessage.retain();
try {
for (Habbo h : this.getHabbos()) {
if (h == roomChatMessage.getTargetHabbo() || h == habbo) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
@ -3144,10 +3149,17 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
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) ||
@ -3164,9 +3176,15 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
}
} 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) {
@ -3178,6 +3196,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
}
} finally {
message.release();
}
}
if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) {

View File

@ -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<ServerMessage> {
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<ServerMessage
buf.release();
}
} catch (IllegalReferenceCountException e) {
LOGGER.error("IllegalReferenceCountException happened for packet {}.", message.getHeader());
throw e;
throw new IOException(String.format("IllegalReferenceCountException happened for ServerMessage with packet id %d.", message.getHeader()), e);
}
}