Im trying to get the ondemand working but I receive a BufferOverflowException
Code:
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Unknown Source)
at java.nio.HeapByteBuffer.put(Unknown Source)
at org.runesource.net.Client.handleLogin(Client.java:310)
at org.runesource.net.Client.handleIncomingData(Client.java:119)
at org.runesource.net.DedicatedReactor.run(DedicatedReactor.java:47)
Code:
case ONDEMAND:
if (inData.remaining() < 4) {
inData.compact();
return;
}
int opcode = inData.get() & 0xFF;
if (opcode == 0 || opcode == 1) {
int type = inData.get() & 0xFF;
int file = inData.getShort() & 0xFFFF;
ByteBuffer buffer;
Cache cache = Server.getSingleton().getCache();
if (type == 255 && file == 255) {
ChecksumTable table = Server.getSingleton().getChecksumTable();
Container container = new Container(Container.COMPRESSION_NONE, table.encode());
buffer = ByteBuffer.wrap(container.encode().array());
} else {
buffer = ByteBuffer.wrap(cache.getStore().read(type, file).array());
if (type != 255)
buffer = buffer.slice();
}
buffer.put((byte) type);
buffer.putShort((short) file);
int compression = buffer.get() & 0xFF;
if (opcode == 1)
compression |= 0x80;
buffer.put((byte) compression);
int bytes = buffer.remaining();
if (bytes > 508)
bytes = 508;
buffer.put(buffer.get(bytes));
for (;;) {
bytes = buffer.remaining();
if (bytes == 0)
break;
else if (bytes > 511)
bytes = 511;
buffer.put((byte) 0xFF);
buffer.put(buffer.get(bytes));
}
send(buffer);
}
break;
if you need to see anything else let me know