From ee5a97bbae4fe740d33c3f862c67a85c83d07a8a Mon Sep 17 00:00:00 2001 From: Mike <76-Mike@users.noreply.git.krews.org> Date: Sat, 9 May 2020 21:56:52 +0200 Subject: [PATCH] Add reliability to packets and actually clear the message buffer. --- .../com/eu/habbo/habbohotel/rooms/Room.java | 54 +++++++++++++------ .../eu/habbo/habbohotel/rooms/RoomTrade.java | 13 ++++- .../com/eu/habbo/messages/ServerMessage.java | 22 ++------ 3 files changed, 53 insertions(+), 36 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 e0d51c01..5338ce24 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3726,35 +3726,59 @@ public class Room implements Comparable, ISerialize, Runnable { } public void sendComposer(ServerMessage message) { - for (Habbo habbo : this.getHabbos()) { - if (habbo.getClient() == null) { - this.removeHabbo(habbo, true); - continue; - } + message.retain(); - habbo.getClient().sendResponse(message); + try { + for (Habbo habbo : this.getHabbos()) { + if (habbo.getClient() == null) { + this.removeHabbo(habbo, true); + continue; + } + + habbo.getClient().sendResponse(message); + } + } finally { + message.release(); } } public void sendComposerToHabbosWithRights(ServerMessage message) { - for (Habbo habbo : this.getHabbos()) { - if (this.hasRights(habbo)) { - habbo.getClient().sendResponse(message); + message.retain(); + + try { + for (Habbo habbo : this.getHabbos()) { + if (this.hasRights(habbo)) { + habbo.getClient().sendResponse(message); + } } + } finally { + message.release(); } } public void petChat(ServerMessage message) { - for (Habbo habbo : this.getHabbos()) { - if (!habbo.getHabboStats().ignorePets) - habbo.getClient().sendResponse(message); + message.retain(); + + try { + for (Habbo habbo : this.getHabbos()) { + if (!habbo.getHabboStats().ignorePets) + habbo.getClient().sendResponse(message); + } + } finally { + message.release(); } } public void botChat(ServerMessage message) { - for (Habbo habbo : this.getHabbos()) { - if (!habbo.getHabboStats().ignoreBots) - habbo.getClient().sendResponse(message); + message.retain(); + + try { + for (Habbo habbo : this.getHabbos()) { + if (!habbo.getHabboStats().ignoreBots) + habbo.getClient().sendResponse(message); + } + } finally { + message.release(); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTrade.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTrade.java index c6ba64e0..3a443447 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTrade.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTrade.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.users.Habbo; 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.inventory.AddHabboItemComposer; import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer; @@ -310,8 +311,16 @@ public class RoomTrade { } public void sendMessageToUsers(MessageComposer message) { - for (RoomTradeUser roomTradeUser : this.users) { - roomTradeUser.getHabbo().getClient().sendResponse(message); + ServerMessage messageComposed = message.compose(); + + messageComposed.retain(); + + try { + for (RoomTradeUser roomTradeUser : this.users) { + roomTradeUser.getHabbo().getClient().sendResponse(message); + } + } finally { + messageComposed.release(); } } diff --git a/src/main/java/com/eu/habbo/messages/ServerMessage.java b/src/main/java/com/eu/habbo/messages/ServerMessage.java index f43831d1..7a7e7c4f 100644 --- a/src/main/java/com/eu/habbo/messages/ServerMessage.java +++ b/src/main/java/com/eu/habbo/messages/ServerMessage.java @@ -1,6 +1,5 @@ package com.eu.habbo.messages; -import com.eu.habbo.util.DebugUtils; import com.eu.habbo.util.PacketUtils; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; @@ -194,23 +193,13 @@ public class ServerMessage implements ReferenceCounted { @Override public ReferenceCounted retain() { - int result = this.refs.incrementAndGet(); - - if (this.header == 1167 || this.header == 2024 || this.header == 2505) { - System.out.printf("retain Packet: %d Count: %d From: %s%n", this.header, result, DebugUtils.getCallerCallerStacktrace()); - } - + this.refs.incrementAndGet(); return this; } @Override public ReferenceCounted retain(int i) { - int result = this.refs.addAndGet(i); - - if (this.header == 1167 || this.header == 2024 || this.header == 2505) { - System.out.printf("retain Packet: %d Count: %d From: %s%n", this.header, result, DebugUtils.getCallerCallerStacktrace()); - } - + this.refs.addAndGet(i); return this; } @@ -232,17 +221,12 @@ public class ServerMessage implements ReferenceCounted { @Override public boolean release(int i) { int value = this.refs.addAndGet(-i); - - if (this.header == 1167 || this.header == 2024 || this.header == 2505) { - System.out.printf("release Packet: %d Count: %d From: %s%n", this.header, value, DebugUtils.getCallerCallerStacktrace()); - } - if (value < 0) { throw new IllegalReferenceCountException("Decremented below 0 (packet " + this.header + " value " + value + ")."); } if (value == 0) { - this.channelBuffer.release(); + this.channelBuffer.release(this.channelBuffer.refCnt()); return true; }