2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.messages;
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
|
|
|
public class ClientMessage
|
|
|
|
{
|
|
|
|
private final int header;
|
|
|
|
private final ByteBuf buffer;
|
|
|
|
|
|
|
|
public ByteBuf getBuffer()
|
|
|
|
{
|
|
|
|
return this.buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMessageId()
|
|
|
|
{
|
|
|
|
return this.header;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ClientMessage(int messageId, ByteBuf buffer)
|
|
|
|
{
|
|
|
|
this.header = messageId;
|
|
|
|
this.buffer = ((buffer == null) || (buffer.readableBytes() == 0) ? Unpooled.EMPTY_BUFFER : buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ClientMessage clone() throws CloneNotSupportedException
|
|
|
|
{
|
|
|
|
return new ClientMessage(this.header, this.buffer.duplicate());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int readShort()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return this.buffer.readShort();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Integer readInt()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return this.buffer.readInt();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean readBoolean()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return this.buffer.readByte() == 1;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String readString()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
int length = this.readShort();
|
2018-07-06 15:30:00 +02:00
|
|
|
byte[] data = new byte[length];
|
|
|
|
this.buffer.readBytes(data);
|
2019-03-18 02:22:00 +01:00
|
|
|
return new String(data);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMessageBody()
|
|
|
|
{
|
|
|
|
String consoleText = this.buffer.toString(Charset.defaultCharset());
|
|
|
|
|
|
|
|
for (int i = -1; i < 31; i++) {
|
|
|
|
consoleText = consoleText.replace(Character.toString((char)i), "[" + i + "]");
|
|
|
|
}
|
|
|
|
|
|
|
|
return consoleText;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int bytesAvailable()
|
|
|
|
{
|
|
|
|
return this.buffer.readableBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|