mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-22 23:10:52 +01:00
Fixes issue #588, netty IllegalReferenceCount
This commit is contained in:
parent
755c589ba6
commit
81ff35fe6e
@ -89,7 +89,7 @@ public class GameClient {
|
||||
public void sendResponse(MessageComposer composer) {
|
||||
if (this.channel.isOpen()) {
|
||||
try {
|
||||
this.channel.write(composer.compose(), this.channel.voidPromise());
|
||||
this.channel.write(composer.compose().retain(), this.channel.voidPromise());
|
||||
this.channel.flush();
|
||||
} catch (Exception e) {
|
||||
Emulator.getLogging().logPacketError(e);
|
||||
@ -103,7 +103,7 @@ public class GameClient {
|
||||
return;
|
||||
}
|
||||
|
||||
this.channel.write(response, this.channel.voidPromise());
|
||||
this.channel.write(response.retain(), this.channel.voidPromise());
|
||||
this.channel.flush();
|
||||
}
|
||||
}
|
||||
@ -115,7 +115,7 @@ public class GameClient {
|
||||
return;
|
||||
}
|
||||
|
||||
this.channel.write(response);
|
||||
this.channel.write(response.retain());
|
||||
}
|
||||
|
||||
this.channel.flush();
|
||||
|
@ -4,11 +4,14 @@ import com.eu.habbo.Emulator;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.IllegalReferenceCountException;
|
||||
import io.netty.util.ReferenceCounted;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class ServerMessage {
|
||||
public class ServerMessage implements ReferenceCounted {
|
||||
|
||||
private int header;
|
||||
private ByteBufOutputStream stream;
|
||||
private ByteBuf channelBuffer;
|
||||
@ -192,8 +195,42 @@ public class ServerMessage {
|
||||
return this.channelBuffer.copy();
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.channelBuffer.release();
|
||||
@Override
|
||||
public int refCnt() {
|
||||
return this.channelBuffer.refCnt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceCounted retain() {
|
||||
this.channelBuffer.retain();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceCounted retain(int i) {
|
||||
this.channelBuffer.retain(i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceCounted touch() {
|
||||
this.channelBuffer.touch();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceCounted touch(Object o) {
|
||||
this.channelBuffer.touch(o);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean release() {
|
||||
return this.channelBuffer.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean release(int i) {
|
||||
return this.channelBuffer.release(i);
|
||||
}
|
||||
|
||||
}
|
@ -54,6 +54,8 @@ public class GameMessageHandler extends ChannelInboundHandlerAdapter {
|
||||
if (cause instanceof TooLongFrameException) {
|
||||
Emulator.getLogging().logErrorLine("Disconnecting client, reason: \"" + cause.getMessage() + "\".");
|
||||
} else {
|
||||
cause.printStackTrace();
|
||||
|
||||
Emulator.getLogging().logErrorLine("Disconnecting client, exception in GameMessageHander:");
|
||||
Emulator.getLogging().logErrorLine(cause.toString());
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class GameServerMessageLogger extends MessageToMessageEncoder<ServerMessa
|
||||
protected void encode(ChannelHandlerContext ctx, ServerMessage message, List<Object> out) throws Exception {
|
||||
Emulator.getLogging().logPacketLine("[" + Logging.ANSI_PURPLE + "SERVER" + Logging.ANSI_RESET + "] => [" + message.getHeader() + "] -> " + message.getBodyString());
|
||||
|
||||
out.add(message);
|
||||
out.add(message.retain());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.eu.habbo.messages.ServerMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import io.netty.util.IllegalReferenceCountException;
|
||||
|
||||
public class ServerMessageEncoder extends MessageToByteEncoder<ServerMessage> {
|
||||
|
||||
@ -15,7 +16,6 @@ public class ServerMessageEncoder extends MessageToByteEncoder<ServerMessage> {
|
||||
out.writeBytes(buf);
|
||||
} finally {
|
||||
buf.release();
|
||||
message.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user