use of net.runelite.protocol.update.decoders.ArchiveResponseDecoder in project runelite by runelite.
the class HandshakeResponseHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, HandshakeResponsePacket handshakeResponse) throws Exception {
Channel channel = ctx.channel();
ChannelPipeline p = ctx.pipeline();
CompletableFuture<HandshakeResponseType> handshakeFuture = client.getHandshakeFuture();
assert handshakeFuture != null;
if (handshakeResponse.getResponse() != HandshakeResponseType.RESPONSE_OK) {
logger.warn("Non-ok response from server {}", handshakeResponse.getResponse());
ctx.close();
return;
}
// Send encryption packet
EncryptionPacket encryptionPacket = new EncryptionPacket();
encryptionPacket.setKey((byte) 0);
channel.writeAndFlush(encryptionPacket);
client.setState(ClientState.CONNECTED);
logger.info("Client is now connected!");
p.replace("decoder", "decoder", new ArchiveResponseDecoder());
handshakeFuture.complete(handshakeResponse.getResponse());
}
use of net.runelite.protocol.update.decoders.ArchiveResponseDecoder in project runelite by runelite.
the class ArchiveResponseEncoderTest method testEncode.
@Test
public void testEncode() throws Exception {
byte[] data = new byte[1000];
Random random = new Random(42L);
random.nextBytes(data);
Container container = new Container(CompressionType.NONE, -1);
container.compress(data, null);
byte[] compressedData = container.data;
ArchiveResponsePacket archiveResponse = new ArchiveResponsePacket();
archiveResponse.setIndex(0);
archiveResponse.setArchive(1);
archiveResponse.setData(compressedData);
ByteBuf buf = Unpooled.buffer(1024);
ArchiveResponseEncoder encoder = new ArchiveResponseEncoder();
encoder.encode(null, archiveResponse, buf);
ArchiveResponseDecoder decoder = new ArchiveResponseDecoder();
List<Object> out = new ArrayList<>();
decoder.decode(null, buf, out);
Assert.assertEquals(1, out.size());
ArchiveResponsePacket response = (ArchiveResponsePacket) out.get(0);
Assert.assertEquals(archiveResponse.getIndex(), response.getIndex());
Assert.assertEquals(archiveResponse.getArchive(), response.getArchive());
Assert.assertArrayEquals(archiveResponse.getData(), response.getData());
byte[] decompressedData = Container.decompress(response.getData(), null).data;
Assert.assertArrayEquals(data, decompressedData);
}
Aggregations