Revert ServerMessage release/retain.

This commit is contained in:
Mike 2020-05-13 20:55:07 +02:00
parent 40818513aa
commit 492c8f6142
18 changed files with 148 additions and 342 deletions

View File

@ -35,9 +35,6 @@ public class EventCommand extends Command {
ServerMessage msg = new BubbleAlertComposer("hotel.event", codes).compose(); ServerMessage msg = new BubbleAlertComposer("hotel.event", codes).compose();
msg.retain();
try {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
Habbo habbo = set.getValue(); Habbo habbo = set.getValue();
if (habbo.getHabboStats().blockStaffAlerts) if (habbo.getHabboStats().blockStaffAlerts)
@ -45,9 +42,6 @@ public class EventCommand extends Command {
habbo.getClient().sendResponse(msg); habbo.getClient().sendResponse(msg);
} }
} finally {
msg.release();
}
return true; return true;
} }

View File

@ -24,8 +24,7 @@ public class HotelAlertCommand extends Command {
} }
ServerMessage msg = new StaffAlertWithLinkComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername(), "").compose(); ServerMessage msg = new StaffAlertWithLinkComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername(), "").compose();
msg.retain();
try {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
Habbo habbo = set.getValue(); Habbo habbo = set.getValue();
if (habbo.getHabboStats().blockStaffAlerts) if (habbo.getHabboStats().blockStaffAlerts)
@ -33,9 +32,6 @@ public class HotelAlertCommand extends Command {
habbo.getClient().sendResponse(msg); habbo.getClient().sendResponse(msg);
} }
} finally {
msg.release();
}
} else { } else {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_ha.forgot_message"), RoomChatMessageBubbles.ALERT); gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_ha.forgot_message"), RoomChatMessageBubbles.ALERT);
} }

View File

@ -32,8 +32,7 @@ public class MassBadgeCommand extends Command {
keys.put("image", "${image.library.url}album1584/" + badge + ".gif"); keys.put("image", "${image.library.url}album1584/" + badge + ".gif");
keys.put("message", Emulator.getTexts().getValue("commands.generic.cmd_badge.received")); keys.put("message", Emulator.getTexts().getValue("commands.generic.cmd_badge.received"));
ServerMessage message = new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys).compose(); ServerMessage message = new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys).compose();
message.retain();
try {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
Habbo habbo = set.getValue(); Habbo habbo = set.getValue();
@ -49,9 +48,6 @@ public class MassBadgeCommand extends Command {
} }
} }
} }
} finally {
message.release();
}
} }
return true; return true;
} }

View File

@ -60,9 +60,6 @@ public class MassGiftCommand extends Command {
ServerMessage giftNotificiationMessage = new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys).compose(); ServerMessage giftNotificiationMessage = new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys).compose();
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
giftNotificiationMessage.retain();
try {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
Habbo habbo = set.getValue(); Habbo habbo = set.getValue();
@ -78,9 +75,6 @@ public class MassGiftCommand extends Command {
habbo.getClient().sendResponse(new InventoryRefreshComposer()); habbo.getClient().sendResponse(new InventoryRefreshComposer());
habbo.getClient().sendResponse(giftNotificiationMessage); habbo.getClient().sendResponse(giftNotificiationMessage);
} }
} finally {
giftNotificiationMessage.release();
}
}); });

View File

@ -24,14 +24,9 @@ public class ReloadRoomCommand extends Command {
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId());
ServerMessage message = new ForwardToRoomComposer(room.getId()).compose(); ServerMessage message = new ForwardToRoomComposer(room.getId()).compose();
message.retain();
try {
for (Habbo habbo : habbos) { for (Habbo habbo : habbos) {
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
} finally {
message.release();
}
} }
}, 100); }, 100);

View File

@ -96,7 +96,7 @@ public class GameClient {
return; return;
} }
this.channel.write(response.retain(), this.channel.voidPromise()); this.channel.write(response, this.channel.voidPromise());
this.channel.flush(); this.channel.flush();
} }
} }
@ -108,7 +108,7 @@ public class GameClient {
return; return;
} }
this.channel.write(response.retain()); this.channel.write(response);
} }
this.channel.flush(); this.channel.flush();

View File

@ -134,35 +134,23 @@ public class GameClientManager {
public void sendBroadcastResponse(ServerMessage message) { public void sendBroadcastResponse(ServerMessage message) {
message.retain();
try {
for (GameClient client : this.clients.values()) { for (GameClient client : this.clients.values()) {
client.sendResponse(message); client.sendResponse(message);
} }
} finally {
message.release();
}
} }
public void sendBroadcastResponse(ServerMessage message, GameClient exclude) { public void sendBroadcastResponse(ServerMessage message, GameClient exclude) {
message.retain();
try {
for (GameClient client : this.clients.values()) { for (GameClient client : this.clients.values()) {
if (client.equals(exclude)) if (client.equals(exclude))
continue; continue;
client.sendResponse(message); client.sendResponse(message);
} }
} finally {
message.release();
}
} }
public void sendBroadcastResponse(ServerMessage message, String minPermission, GameClient exclude) { public void sendBroadcastResponse(ServerMessage message, String minPermission, GameClient exclude) {
message.retain();
try {
for (GameClient client : this.clients.values()) { for (GameClient client : this.clients.values()) {
if (client.equals(exclude)) if (client.equals(exclude))
continue; continue;
@ -173,8 +161,5 @@ public class GameClientManager {
} }
} }
} }
} finally {
message.release();
}
} }
} }

View File

@ -3115,15 +3115,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
roomChatMessage.setMessage(trimmedMessage); roomChatMessage.setMessage(trimmedMessage);
if (prefixMessage != null) {
prefixMessage.retain();
}
if (clearPrefixMessage != null) {
clearPrefixMessage.retain();
}
try {
if (chatType == RoomChatType.WHISPER) { if (chatType == RoomChatType.WHISPER) {
if (roomChatMessage.getTargetHabbo() == null) { if (roomChatMessage.getTargetHabbo() == null) {
return; return;
@ -3135,10 +3126,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose(); final ServerMessage message = new RoomUserWhisperComposer(roomChatMessage).compose();
final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose(); final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose();
message.retain();
staffMessage.retain();
try {
for (Habbo h : this.getHabbos()) { for (Habbo h : this.getHabbos()) {
if (h == roomChatMessage.getTargetHabbo() || h == habbo) { if (h == roomChatMessage.getTargetHabbo() || h == habbo) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
@ -3158,17 +3145,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
h.getClient().sendResponse(staffMessage); 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");
message.retain();
try {
for (Habbo h : this.getHabbos()) { for (Habbo h : this.getHabbos()) {
if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance || if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance ||
h.equals(habbo) || h.equals(habbo) ||
@ -3185,15 +3165,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
} }
} finally {
message.release();
}
} else if (chatType == RoomChatType.SHOUT) { } else if (chatType == RoomChatType.SHOUT) {
ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose(); ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose();
message.retain();
try {
for (Habbo h : this.getHabbos()) { for (Habbo h : this.getHabbos()) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) { 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) {
@ -3205,18 +3179,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
} }
} finally {
message.release();
}
}
} finally {
if (prefixMessage != null) {
prefixMessage.release();
}
if (clearPrefixMessage != null) {
clearPrefixMessage.release();
}
} }
if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) { if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) {
@ -3765,9 +3727,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public void sendComposer(ServerMessage message) { public void sendComposer(ServerMessage message) {
message.retain();
try {
for (Habbo habbo : this.getHabbos()) { for (Habbo habbo : this.getHabbos()) {
if (habbo.getClient() == null) { if (habbo.getClient() == null) {
this.removeHabbo(habbo, true); this.removeHabbo(habbo, true);
@ -3776,36 +3735,21 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
} finally {
message.release();
}
} }
public void sendComposerToHabbosWithRights(ServerMessage message) { public void sendComposerToHabbosWithRights(ServerMessage message) {
message.retain();
try {
for (Habbo habbo : this.getHabbos()) { for (Habbo habbo : this.getHabbos()) {
if (this.hasRights(habbo)) { if (this.hasRights(habbo)) {
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
} }
} finally {
message.release();
}
} }
public void petChat(ServerMessage message) { public void petChat(ServerMessage message) {
message.retain();
try {
for (Habbo habbo : this.getHabbos()) { for (Habbo habbo : this.getHabbos()) {
if (!habbo.getHabboStats().ignorePets) if (!habbo.getHabboStats().ignorePets)
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
} finally {
message.release();
}
} }
public void botChat(ServerMessage message) { public void botChat(ServerMessage message) {
@ -3813,16 +3757,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return; return;
} }
message.retain();
try {
for (Habbo habbo : this.getHabbos()) { for (Habbo habbo : this.getHabbos()) {
if (!habbo.getHabboStats().ignoreBots) if (!habbo.getHabboStats().ignoreBots)
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
} finally {
message.release();
}
} }
private void loadRights(Connection connection) { private void loadRights(Connection connection) {

View File

@ -3,7 +3,6 @@ package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer; import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer; import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
@ -311,17 +310,9 @@ public class RoomTrade {
} }
public void sendMessageToUsers(MessageComposer message) { public void sendMessageToUsers(MessageComposer message) {
ServerMessage messageComposed = message.compose();
messageComposed.retain();
try {
for (RoomTradeUser roomTradeUser : this.users) { for (RoomTradeUser roomTradeUser : this.users) {
roomTradeUser.getHabbo().getClient().sendResponse(message); roomTradeUser.getHabbo().getClient().sendResponse(message);
} }
} finally {
messageComposed.release();
}
} }
public List<RoomTradeUser> getRoomTradeUsers() { public List<RoomTradeUser> getRoomTradeUsers() {

View File

@ -179,16 +179,11 @@ public class HabboManager {
public void sendPacketToHabbosWithPermission(ServerMessage message, String perm) { public void sendPacketToHabbosWithPermission(ServerMessage message, String perm) {
synchronized (this.onlineHabbos) { synchronized (this.onlineHabbos) {
message.retain();
try {
for (Habbo habbo : this.onlineHabbos.values()) { for (Habbo habbo : this.onlineHabbos.values()) {
if (habbo.hasPermission(perm)) { if (habbo.hasPermission(perm)) {
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
} }
} finally {
message.release();
}
} }
} }

View File

@ -4,15 +4,13 @@ import com.eu.habbo.util.PacketUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.util.IllegalReferenceCountException;
import io.netty.util.ReferenceCounted;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
public class ServerMessage implements ReferenceCounted { public class ServerMessage {
private static final Logger LOGGER = LoggerFactory.getLogger(ServerMessage.class); private static final Logger LOGGER = LoggerFactory.getLogger(ServerMessage.class);
private boolean initialized; private boolean initialized;
@ -35,6 +33,7 @@ public class ServerMessage implements ReferenceCounted {
throw new ServerMessageException("ServerMessage was already initialized."); throw new ServerMessageException("ServerMessage was already initialized.");
} }
this.initialized = true;
this.header = id; this.header = id;
this.refs = new AtomicInteger(0); this.refs = new AtomicInteger(0);
this.channelBuffer = Unpooled.buffer(); this.channelBuffer = Unpooled.buffer();
@ -186,51 +185,4 @@ public class ServerMessage implements ReferenceCounted {
return this.channelBuffer.copy(); return this.channelBuffer.copy();
} }
@Override
public int refCnt() {
return this.refs.get();
}
@Override
public ReferenceCounted retain() {
this.refs.incrementAndGet();
return this;
}
@Override
public ReferenceCounted retain(int i) {
this.refs.addAndGet(i);
return this;
}
@Override
public ReferenceCounted touch() {
return this;
}
@Override
public ReferenceCounted touch(Object o) {
return this;
}
@Override
public boolean release() {
return this.release(1);
}
@Override
public boolean release(int i) {
int value = this.refs.addAndGet(-i);
if (value < 0) {
throw new IllegalReferenceCountException("Decremented below 0 (packet " + this.header + " value " + value + ").");
}
if (value == 0) {
this.channelBuffer.release(this.channelBuffer.refCnt());
return true;
}
return false;
}
} }

View File

@ -148,14 +148,9 @@ public class FloorPlanEditorSaveEvent extends MessageHandler {
Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); Emulator.getGameEnvironment().getRoomManager().unloadRoom(room);
room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId());
ServerMessage message = new ForwardToRoomComposer(room.getId()).compose(); ServerMessage message = new ForwardToRoomComposer(room.getId()).compose();
message.retain();
try {
for (Habbo habbo : habbos) { for (Habbo habbo : habbos) {
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
} finally {
message.release();
}
} }
} }
} }

View File

@ -25,8 +25,6 @@ public class HotelAlert extends RCONMessage<HotelAlert.JSONHotelAlert> {
} }
if (serverMessage != null) { if (serverMessage != null) {
serverMessage.retain();
try {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
Habbo habbo = set.getValue(); Habbo habbo = set.getValue();
if (habbo.getHabboStats().blockStaffAlerts) if (habbo.getHabboStats().blockStaffAlerts)
@ -34,9 +32,6 @@ public class HotelAlert extends RCONMessage<HotelAlert.JSONHotelAlert> {
habbo.getClient().sendResponse(serverMessage); habbo.getClient().sendResponse(serverMessage);
} }
} finally {
serverMessage.release();
}
} }
} }

View File

@ -43,8 +43,7 @@ public class ImageHotelAlert extends RCONMessage<ImageHotelAlert.JSON> {
} }
ServerMessage message = new BubbleAlertComposer(json.bubble_key, keys).compose(); ServerMessage message = new BubbleAlertComposer(json.bubble_key, keys).compose();
message.retain();
try {
for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) { for (Map.Entry<Integer, Habbo> set : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().entrySet()) {
Habbo habbo = set.getValue(); Habbo habbo = set.getValue();
if (habbo.getHabboStats().blockStaffAlerts) if (habbo.getHabboStats().blockStaffAlerts)
@ -52,9 +51,6 @@ public class ImageHotelAlert extends RCONMessage<ImageHotelAlert.JSON> {
habbo.getClient().sendResponse(message); habbo.getClient().sendResponse(message);
} }
} finally {
message.release();
}
} }
static class JSON { static class JSON {

View File

@ -30,9 +30,6 @@ public class GameServer extends Server {
public void initChannel(SocketChannel ch) throws Exception { public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("logger", new LoggingHandler()); ch.pipeline().addLast("logger", new LoggingHandler());
// Logger.
// Decoders. // Decoders.
ch.pipeline().addLast(new GamePolicyDecoder()); ch.pipeline().addLast(new GamePolicyDecoder());
ch.pipeline().addLast(new GameByteFrameDecoder()); ch.pipeline().addLast(new GameByteFrameDecoder());

View File

@ -63,14 +63,7 @@ public class GameMessageHandler extends ChannelInboundHandlerAdapter {
if (cause instanceof TooLongFrameException) { if (cause instanceof TooLongFrameException) {
LOGGER.error("Disconnecting client, reason: \"" + cause.getMessage() + "\"."); LOGGER.error("Disconnecting client, reason: \"" + cause.getMessage() + "\".");
} else { } else {
cause.printStackTrace(); LOGGER.error("Disconnecting client, exception in GameMessageHander.", cause);
LOGGER.error("Disconnecting client, exception in GameMessageHander:");
LOGGER.error(cause.toString());
for (StackTraceElement element : cause.getStackTrace()) {
LOGGER.error(element.toString());
}
} }
ctx.channel().close(); ctx.channel().close();

View File

@ -27,7 +27,7 @@ public class GameServerMessageLogger extends MessageToMessageEncoder<ServerMessa
this.names.getOutgoingName(message.getHeader()), this.names.getOutgoingName(message.getHeader()),
message.getBodyString())); message.getBodyString()));
out.add(message.retain()); out.add(message);
} }
} }

View File

@ -38,9 +38,6 @@ public class CannonKickAction implements Runnable {
ServerMessage message = new BubbleAlertComposer("cannon.png", dater).compose(); ServerMessage message = new BubbleAlertComposer("cannon.png", dater).compose();
message.retain();
try {
for (RoomTile t : tiles) { for (RoomTile t : tiles) {
for (Habbo habbo : this.room.getHabbosAt(t.x, t.y)) { for (Habbo habbo : this.room.getHabbosAt(t.x, t.y)) {
if (!habbo.hasPermission(Permission.ACC_UNKICKABLE) && !this.room.isOwner(habbo)) { if (!habbo.hasPermission(Permission.ACC_UNKICKABLE) && !this.room.isOwner(habbo)) {
@ -49,8 +46,5 @@ public class CannonKickAction implements Runnable {
} }
} }
} }
} finally {
message.release();
}
} }
} }