Search in sources :

Example 1 with ArchiveResponseDecoder

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());
}
Also used : HandshakeResponseType(net.runelite.protocol.api.login.HandshakeResponseType) EncryptionPacket(net.runelite.protocol.api.update.EncryptionPacket) Channel(io.netty.channel.Channel) ChannelPipeline(io.netty.channel.ChannelPipeline) ArchiveResponseDecoder(net.runelite.protocol.update.decoders.ArchiveResponseDecoder)

Example 2 with ArchiveResponseDecoder

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);
}
Also used : Container(net.runelite.cache.fs.Container) Random(java.util.Random) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) ArchiveResponsePacket(net.runelite.protocol.api.update.ArchiveResponsePacket) ArchiveResponseDecoder(net.runelite.protocol.update.decoders.ArchiveResponseDecoder) Test(org.junit.Test)

Aggregations

ArchiveResponseDecoder (net.runelite.protocol.update.decoders.ArchiveResponseDecoder)2 ByteBuf (io.netty.buffer.ByteBuf)1 Channel (io.netty.channel.Channel)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Container (net.runelite.cache.fs.Container)1 HandshakeResponseType (net.runelite.protocol.api.login.HandshakeResponseType)1 ArchiveResponsePacket (net.runelite.protocol.api.update.ArchiveResponsePacket)1 EncryptionPacket (net.runelite.protocol.api.update.EncryptionPacket)1 Test (org.junit.Test)1