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,40 +3120,73 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return; return;
} }
final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose();
RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage); RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage);
staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage()); staffChatMessage.setMessage("To " + staffChatMessage.getTargetHabbo().getHabboInfo().getUsername() + ": " + staffChatMessage.getMessage());
final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose();
final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose(); final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose();
for (Habbo h : this.getHabbos()) { message.retain();
if (h == roomChatMessage.getTargetHabbo() || h == habbo) { staffMessage.retain();
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
if (prefixMessage != null) {
h.getClient().sendResponse(prefixMessage);
}
h.getClient().sendResponse(message);
if (clearPrefixMessage != null) { try {
h.getClient().sendResponse(clearPrefixMessage); 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) { } else if (chatType == RoomChatType.TALK) {
ServerMessage message = new RoomUserTalkComposer(roomChatMessage).compose(); ServerMessage message = new RoomUserTalkComposer(roomChatMessage).compose();
boolean noChatLimit = habbo.hasPermission("acc_chat_no_limit"); boolean noChatLimit = habbo.hasPermission("acc_chat_no_limit");
for (Habbo h : this.getHabbos()) { message.retain();
if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance ||
h.equals(habbo) || try {
this.hasRights(h) || for (Habbo h : this.getHabbos()) {
noChatLimit) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) { if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance ||
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { 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) { if (prefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(prefixMessage); h.getClient().sendResponse(prefixMessage);
} }
@ -3163,20 +3196,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
} }
} } finally {
} else if (chatType == RoomChatType.SHOUT) { message.release();
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);
}
}
} }
} }

View File

@ -5,15 +5,13 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import java.io.IOException;
public class GameServerMessageEncoder extends MessageToByteEncoder<ServerMessage> { public class GameServerMessageEncoder extends MessageToByteEncoder<ServerMessage> {
private static final Logger LOGGER = LoggerFactory.getLogger(GameServerMessageEncoder.class);
@Override @Override
protected void encode(ChannelHandlerContext ctx, ServerMessage message, ByteBuf out) { protected void encode(ChannelHandlerContext ctx, ServerMessage message, ByteBuf out) throws Exception {
try { try {
ByteBuf buf = message.get(); ByteBuf buf = message.get();
@ -24,8 +22,7 @@ public class GameServerMessageEncoder extends MessageToByteEncoder<ServerMessage
buf.release(); buf.release();
} }
} catch (IllegalReferenceCountException e) { } catch (IllegalReferenceCountException e) {
LOGGER.error("IllegalReferenceCountException happened for packet {}.", message.getHeader()); throw new IOException(String.format("IllegalReferenceCountException happened for ServerMessage with packet id %d.", message.getHeader()), e);
throw e;
} }
} }