Search in sources :

Example 1 with XteaKey

use of net.runelite.http.api.xtea.XteaKey in project runelite by runelite.

the class XteaKeyManager method loadKeys.

public void loadKeys() {
    XteaClient xteaClient = new XteaClient();
    try {
        for (XteaKey key : xteaClient.get()) {
            keys.put(key.getRegion(), key.getKeys());
        }
    } catch (IOException ex) {
        // happens on release when it is not deployed yet
        logger.debug("unable to load xtea keys", ex);
        return;
    }
    logger.info("Loaded {} keys", keys.size());
}
Also used : XteaKey(net.runelite.http.api.xtea.XteaKey) IOException(java.io.IOException) XteaClient(net.runelite.http.api.xtea.XteaClient)

Example 2 with XteaKey

use of net.runelite.http.api.xtea.XteaKey in project runelite by runelite.

the class XteaService method submit.

@RequestMapping(method = POST)
public void submit(@RequestBody XteaRequest xteaRequest) {
    try (Connection con = sql2o.beginTransaction()) {
        CacheEntry cache = cacheService.findMostRecent();
        if (cache == null) {
            throw new InternalServerErrorException("No most recent cache");
        }
        Query query = con.createQuery("insert into xtea (region, rev, key1, key2, key3, key4) " + "values (:region, :rev, :key1, :key2, :key3, :key4)");
        for (XteaKey key : xteaRequest.getKeys()) {
            int region = key.getRegion();
            int[] keys = key.getKeys();
            XteaEntry xteaEntry = findLatestXtea(con, region);
            if (keys.length != 4) {
                throw new IllegalArgumentException("Key length must be 4");
            }
            // already have these?
            if (xteaEntry != null && xteaEntry.getKey1() == keys[0] && xteaEntry.getKey2() == keys[1] && xteaEntry.getKey3() == keys[2] && xteaEntry.getKey4() == keys[3]) {
                continue;
            }
            if (!checkKeys(cache, region, keys)) {
                continue;
            }
            query.addParameter("region", region).addParameter("rev", xteaRequest.getRevision()).addParameter("key1", keys[0]).addParameter("key2", keys[1]).addParameter("key3", keys[2]).addParameter("key4", keys[3]).addToBatch();
        }
        query.executeBatch();
        con.commit();
    }
}
Also used : Query(org.sql2o.Query) XteaKey(net.runelite.http.api.xtea.XteaKey) Connection(org.sql2o.Connection) InternalServerErrorException(net.runelite.http.service.util.exception.InternalServerErrorException) CacheEntry(net.runelite.http.service.cache.beans.CacheEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with XteaKey

use of net.runelite.http.api.xtea.XteaKey in project runelite by runelite.

the class XteaService method entryToKey.

private static XteaKey entryToKey(XteaEntry xe) {
    XteaKey xteaKey = new XteaKey();
    xteaKey.setRegion(xe.getRegion());
    xteaKey.setKeys(new int[] { xe.getKey1(), xe.getKey2(), xe.getKey3(), xe.getKey4() });
    return xteaKey;
}
Also used : XteaKey(net.runelite.http.api.xtea.XteaKey)

Aggregations

XteaKey (net.runelite.http.api.xtea.XteaKey)3 IOException (java.io.IOException)1 XteaClient (net.runelite.http.api.xtea.XteaClient)1 CacheEntry (net.runelite.http.service.cache.beans.CacheEntry)1 InternalServerErrorException (net.runelite.http.service.util.exception.InternalServerErrorException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 Connection (org.sql2o.Connection)1 Query (org.sql2o.Query)1