Search in sources :

Example 1 with HandshakeResponseType

use of net.runelite.protocol.api.login.HandshakeResponseType 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 HandshakeResponseType

use of net.runelite.protocol.api.login.HandshakeResponseType in project runelite by runelite.

the class CacheClientTest method test.

@Test
@Ignore
public void test() throws Exception {
    try (Store store = new Store(new File("D:\\rs\\07\\temp\\cache"))) {
        store.load();
        CacheClient c = new CacheClient(store, CacheProperties.getRsVersion());
        c.connect();
        CompletableFuture<HandshakeResponseType> handshake = c.handshake();
        HandshakeResponseType result = handshake.get();
        logger.info("Handshake result: {}", result);
        Assert.assertEquals(HandshakeResponseType.RESPONSE_OK, result);
        c.download();
        c.close();
        store.save();
    }
}
Also used : HandshakeResponseType(net.runelite.protocol.api.login.HandshakeResponseType) Store(net.runelite.cache.fs.Store) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with HandshakeResponseType

use of net.runelite.protocol.api.login.HandshakeResponseType in project runelite by runelite.

the class CacheUpdater method update.

public void update() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException {
    int rsVersion = RuneLiteAPI.getRsVersion();
    try (Connection con = sql2o.beginTransaction()) {
        CacheDAO cacheDao = new CacheDAO();
        CacheEntry cache = cacheDao.findMostRecent(con);
        boolean created = false;
        if (cache == null) {
            created = true;
            cache = cacheDao.createCache(con, rsVersion, Instant.now());
        }
        CacheStorage storage = new CacheStorage(cache, cacheDao, con);
        Store store = new Store(storage);
        store.load();
        ExecutorService executor = Executors.newSingleThreadExecutor();
        CacheClient client = new CacheClient(store, rsVersion, (Archive archive, byte[] data) -> executor.submit(new CacheUploader(minioClient, minioBucket, archive, data)));
        client.connect();
        HandshakeResponseType result = client.handshake().join();
        if (result != HandshakeResponseType.RESPONSE_OK) {
            logger.warn("Out of date!");
            return;
        }
        List<IndexInfo> indexes = client.requestIndexes();
        List<IndexEntry> entries = cacheDao.findIndexesForCache(con, cache);
        if (!checkOutOfDate(indexes, entries)) {
            logger.info("All up to date.");
            return;
        }
        client.download();
        CacheEntry newCache = created ? cache : cacheDao.createCache(con, rsVersion, Instant.now());
        storage.setCacheEntry(newCache);
        store.save();
        // ensure objects are added to the store before they become
        // visible in the database
        executor.shutdown();
        while (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
            logger.debug("Waiting for termination of executor...");
        }
        // commit database
        con.commit();
    }
}
Also used : CacheClient(net.runelite.cache.client.CacheClient) Archive(net.runelite.cache.fs.Archive) HandshakeResponseType(net.runelite.protocol.api.login.HandshakeResponseType) Connection(org.sql2o.Connection) Store(net.runelite.cache.fs.Store) IndexEntry(net.runelite.cache.updater.beans.IndexEntry) IndexInfo(net.runelite.cache.client.IndexInfo) CacheEntry(net.runelite.cache.updater.beans.CacheEntry) ExecutorService(java.util.concurrent.ExecutorService)

Example 4 with HandshakeResponseType

use of net.runelite.protocol.api.login.HandshakeResponseType in project runelite by runelite.

the class HandshakeResponseEncoder method encode.

@Override
protected void encode(ChannelHandlerContext ctx, HandshakeResponsePacket handshakeResponse, ByteBuf out) throws Exception {
    HandshakeResponseType handshakeResponseType = handshakeResponse.getResponse();
    out.writeByte(handshakeResponseType.getValue());
}
Also used : HandshakeResponseType(net.runelite.protocol.api.login.HandshakeResponseType)

Aggregations

HandshakeResponseType (net.runelite.protocol.api.login.HandshakeResponseType)4 Store (net.runelite.cache.fs.Store)2 Channel (io.netty.channel.Channel)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 File (java.io.File)1 ExecutorService (java.util.concurrent.ExecutorService)1 CacheClient (net.runelite.cache.client.CacheClient)1 IndexInfo (net.runelite.cache.client.IndexInfo)1 Archive (net.runelite.cache.fs.Archive)1 CacheEntry (net.runelite.cache.updater.beans.CacheEntry)1 IndexEntry (net.runelite.cache.updater.beans.IndexEntry)1 EncryptionPacket (net.runelite.protocol.api.update.EncryptionPacket)1 ArchiveResponseDecoder (net.runelite.protocol.update.decoders.ArchiveResponseDecoder)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Connection (org.sql2o.Connection)1