Download XTEA keys from HDOS

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 2 years ago
parent db1ecf3c00
commit 8f4d28393e
  1. 2
      archive/src/main/kotlin/org/openrs2/archive/ArchiveModule.kt
  2. 57
      archive/src/main/kotlin/org/openrs2/archive/key/HdosKeyDownloader.kt
  3. 3
      archive/src/main/kotlin/org/openrs2/archive/key/KeySource.kt
  4. 2
      archive/src/main/resources/org/openrs2/archive/migrations/V18__hdos.sql
  5. 1
      archive/src/main/resources/org/openrs2/archive/templates/index.html

@ -5,6 +5,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.google.inject.AbstractModule
import com.google.inject.Scopes
import com.google.inject.multibindings.Multibinder
import org.openrs2.archive.key.HdosKeyDownloader
import org.openrs2.archive.key.KeyDownloader
import org.openrs2.archive.key.OpenOsrsKeyDownloader
import org.openrs2.archive.key.PolarKeyDownloader
@ -45,6 +46,7 @@ public object ArchiveModule : AbstractModule() {
.addBinding().to(JavaTimeModule::class.java)
val keyBinder = Multibinder.newSetBinder(binder(), KeyDownloader::class.java)
keyBinder.addBinding().to(HdosKeyDownloader::class.java)
keyBinder.addBinding().to(OpenOsrsKeyDownloader::class.java)
keyBinder.addBinding().to(PolarKeyDownloader::class.java)
keyBinder.addBinding().to(RuneLiteKeyDownloader::class.java)

@ -0,0 +1,57 @@
package org.openrs2.archive.key
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.future.await
import kotlinx.coroutines.withContext
import org.openrs2.crypto.XteaKey
import org.openrs2.http.checkStatusCode
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.time.Duration
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
public class HdosKeyDownloader @Inject constructor(
private val client: HttpClient
) : KeyDownloader(KeySource.HDOS) {
override suspend fun getMissingUrls(seenUrls: Set<String>): Set<String> {
return setOf(ENDPOINT)
}
override suspend fun download(url: String): Sequence<XteaKey> {
val request = HttpRequest.newBuilder(URI(url))
.GET()
.timeout(Duration.ofSeconds(30))
.build()
val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await()
response.checkStatusCode()
return withContext(Dispatchers.IO) {
response.body().use { input ->
input.bufferedReader().use { reader ->
val keys = mutableSetOf<XteaKey>()
for (line in reader.lineSequence()) {
val parts = line.split(',')
if (parts.size < 3) {
continue
}
val key = XteaKey.fromHexOrNull(parts[2]) ?: continue
keys += key
}
keys.asSequence()
}
}
}
}
private companion object {
private const val ENDPOINT = "https://api.hdos.dev/keys/get"
}
}

@ -5,5 +5,6 @@ public enum class KeySource {
DISK,
OPENOSRS,
POLAR,
RUNELITE
RUNELITE,
HDOS
}

@ -0,0 +1,2 @@
-- @formatter:off
ALTER TYPE key_source ADD VALUE 'hdos';

@ -52,6 +52,7 @@
<ul>
<li><a href="https://displee.com/archive/">Displee's archive</a></li>
<li><a href="https://gregs.world/archive/">Greg's archive</a></li>
<li><a href="https://www.hdos.dev/">HDOS</a></li>
<li><a href="https://openosrs.com/">OpenOSRS</a></li>
<li><a href="https://archive.runestats.com/">Polar's archive</a></li>
<!-- We don't use Moparisthebest's or RS-Hacking's -->

Loading…
Cancel
Save