From 40d6ccbb61e2e38bf106fb566ddd491a1f652031 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 3 Apr 2021 13:31:26 +0100 Subject: [PATCH] Add ent's output to the keys page Signed-off-by: Graham --- .../org/openrs2/archive/key/EntCommand.kt | 23 +-------------- .../org/openrs2/archive/key/KeyExporter.kt | 28 +++++++++++++++++++ .../org/openrs2/archive/web/KeysController.kt | 3 +- .../openrs2/archive/templates/keys/index.html | 19 +++++++++++-- 4 files changed, 48 insertions(+), 25 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/key/EntCommand.kt b/archive/src/main/kotlin/org/openrs2/archive/key/EntCommand.kt index 2b328eb5aa..ac1f15193c 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/key/EntCommand.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/key/EntCommand.kt @@ -5,33 +5,12 @@ import com.google.inject.Guice import kotlinx.coroutines.runBlocking import org.openrs2.archive.ArchiveModule import org.openrs2.inject.CloseableInjector -import java.io.BufferedOutputStream -import java.io.DataOutputStream public class EntCommand : CliktCommand(name = "ent") { override fun run(): Unit = runBlocking { CloseableInjector(Guice.createInjector(ArchiveModule)).use { injector -> val exporter = injector.getInstance(KeyExporter::class.java) - val keys = exporter.exportValid() - - val process = ProcessBuilder("ent") - .redirectOutput(ProcessBuilder.Redirect.INHERIT) - .redirectError(ProcessBuilder.Redirect.INHERIT) - .start() - - DataOutputStream(BufferedOutputStream(process.outputStream)).use { out -> - for (key in keys) { - out.writeInt(key.k0) - out.writeInt(key.k1) - out.writeInt(key.k2) - out.writeInt(key.k3) - } - } - - val status = process.waitFor() - if (status != 0) { - throw Exception("ent failed: $status") - } + println(exporter.analyse()) } } } diff --git a/archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt b/archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt index f41b0d6538..5d7526d481 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt @@ -2,6 +2,8 @@ package org.openrs2.archive.key import org.openrs2.crypto.XteaKey import org.openrs2.db.Database +import java.io.BufferedOutputStream +import java.io.DataOutputStream import javax.inject.Inject import javax.inject.Singleton @@ -77,6 +79,32 @@ public class KeyExporter @Inject constructor( return export(validOnly = true) } + public suspend fun analyse(): String { + val keys = exportValid() + + val process = ProcessBuilder("ent") + .redirectError(ProcessBuilder.Redirect.INHERIT) + .start() + + DataOutputStream(BufferedOutputStream(process.outputStream)).use { out -> + for (key in keys) { + out.writeInt(key.k0) + out.writeInt(key.k1) + out.writeInt(key.k2) + out.writeInt(key.k3) + } + } + + val analysis = process.inputStream.readAllBytes().toString(Charsets.UTF_8) + + val status = process.waitFor() + if (status != 0) { + throw Exception("ent failed: $status") + } + + return analysis + } + private suspend fun export(validOnly: Boolean): List { return database.execute { connection -> val query = if (validOnly) { diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt b/archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt index 6025f0c586..88ab3bbf23 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt @@ -13,7 +13,8 @@ public class KeysController @Inject constructor( ) { public suspend fun index(call: ApplicationCall) { val stats = exporter.count() - call.respond(ThymeleafContent("keys/index.html", mapOf("stats" to stats))) + val analysis = exporter.analyse() + call.respond(ThymeleafContent("keys/index.html", mapOf("stats" to stats, "analysis" to analysis))) } public suspend fun exportAll(call: ApplicationCall) { diff --git a/archive/src/main/resources/org/openrs2/archive/templates/keys/index.html b/archive/src/main/resources/org/openrs2/archive/templates/keys/index.html index 7ebf7017bd..c67d7cf5d2 100644 --- a/archive/src/main/resources/org/openrs2/archive/templates/keys/index.html +++ b/archive/src/main/resources/org/openrs2/archive/templates/keys/index.html @@ -29,6 +29,7 @@ have a validated key. This is equal to the total number of validated keys if and only if keys are not re-used.

+

Download

This page allows all raw keys in the database to be exported in @@ -37,12 +38,26 @@ the cache, use the download link on the caches page instead.

- +

+ +

Analysis

+

+ The output of piping all validated keys in binary format into + ent + is: +

+ +
+

+ The keys are sorted in import order, which does not match the + order they were generated in. This could influence portions of + ent's output. +