xtea: skip unknown map regions
The client will include keys 0,0,0,0 for unknown map regions, which should just be skipped over instead of failing the entire request
This commit is contained in:
@@ -25,8 +25,10 @@
|
||||
package net.runelite.http.service.xtea;
|
||||
|
||||
import java.time.Instant;
|
||||
import lombok.Data;
|
||||
|
||||
public class XteaEntry
|
||||
@Data
|
||||
class XteaEntry
|
||||
{
|
||||
private int region;
|
||||
private Instant time;
|
||||
@@ -35,75 +37,4 @@ public class XteaEntry
|
||||
private int key2;
|
||||
private int key3;
|
||||
private int key4;
|
||||
|
||||
public int getRegion()
|
||||
{
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(int region)
|
||||
{
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public Instant getTime()
|
||||
{
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Instant time)
|
||||
{
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getRev()
|
||||
{
|
||||
return rev;
|
||||
}
|
||||
|
||||
public void setRev(int rev)
|
||||
{
|
||||
this.rev = rev;
|
||||
}
|
||||
|
||||
public int getKey1()
|
||||
{
|
||||
return key1;
|
||||
}
|
||||
|
||||
public void setKey1(int key1)
|
||||
{
|
||||
this.key1 = key1;
|
||||
}
|
||||
|
||||
public int getKey2()
|
||||
{
|
||||
return key2;
|
||||
}
|
||||
|
||||
public void setKey2(int key2)
|
||||
{
|
||||
this.key2 = key2;
|
||||
}
|
||||
|
||||
public int getKey3()
|
||||
{
|
||||
return key3;
|
||||
}
|
||||
|
||||
public void setKey3(int key3)
|
||||
{
|
||||
this.key3 = key3;
|
||||
}
|
||||
|
||||
public int getKey4()
|
||||
{
|
||||
return key4;
|
||||
}
|
||||
|
||||
public void setKey4(int key4)
|
||||
{
|
||||
this.key4 = key4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.cache.IndexType;
|
||||
import net.runelite.cache.fs.Container;
|
||||
import net.runelite.cache.util.Djb2;
|
||||
@@ -45,6 +46,7 @@ import org.sql2o.Query;
|
||||
import org.sql2o.Sql2o;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class XteaService
|
||||
{
|
||||
private static final String CREATE_SQL = "CREATE TABLE IF NOT EXISTS `xtea` (\n"
|
||||
@@ -101,6 +103,11 @@ public class XteaService
|
||||
int region = key.getRegion();
|
||||
int[] keys = key.getKeys();
|
||||
|
||||
if (keys.length != 4)
|
||||
{
|
||||
throw new IllegalArgumentException("Key length must be 4");
|
||||
}
|
||||
|
||||
XteaCache xteaCache = keyCache.getIfPresent(region);
|
||||
if (xteaCache == null
|
||||
|| xteaCache.getKey1() != keys[0]
|
||||
@@ -136,11 +143,6 @@ public class XteaService
|
||||
|
||||
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]
|
||||
@@ -151,7 +153,14 @@ public class XteaService
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!checkKeys(cache, region, keys))
|
||||
ArchiveEntry archiveEntry = archiveForRegion(cache, region);
|
||||
if (archiveEntry == null)
|
||||
{
|
||||
// the client sends 0,0,0,0 for non-existent regions, just ignore them
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!checkKeys(archiveEntry, keys))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -169,6 +178,8 @@ public class XteaService
|
||||
.addParameter("key3", keys[2])
|
||||
.addParameter("key4", keys[3])
|
||||
.addToBatch();
|
||||
|
||||
log.debug("Inserted keys for {}: {}, {}, {}, {}", region, keys[0], keys[1], keys[2], keys[3]);
|
||||
}
|
||||
|
||||
if (query != null)
|
||||
@@ -202,7 +213,7 @@ public class XteaService
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkKeys(CacheEntry cache, int regionId, int[] keys)
|
||||
private ArchiveEntry archiveForRegion(CacheEntry cache, int regionId)
|
||||
{
|
||||
int x = regionId >>> 8;
|
||||
int y = regionId & 0xFF;
|
||||
@@ -215,16 +226,15 @@ public class XteaService
|
||||
.toString();
|
||||
int archiveNameHash = Djb2.hash(archiveName);
|
||||
|
||||
ArchiveEntry archiveEntry = cacheService.findArchiveForTypeAndName(cache, IndexType.MAPS, archiveNameHash);
|
||||
if (archiveEntry == null)
|
||||
{
|
||||
throw new InternalServerErrorException("Unable to find archive for region");
|
||||
}
|
||||
return cacheService.findArchiveForTypeAndName(cache, IndexType.MAPS, archiveNameHash);
|
||||
}
|
||||
|
||||
private boolean checkKeys(ArchiveEntry archiveEntry, int[] keys)
|
||||
{
|
||||
byte[] data = cacheService.getArchive(archiveEntry);
|
||||
if (data == null)
|
||||
{
|
||||
throw new InternalServerErrorException("Unable to get archive data");
|
||||
throw new InternalServerErrorException("Unable to get archive data for archive " + archiveEntry.getArchiveId());
|
||||
}
|
||||
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user