forked from openrs2/openrs2
parent
e4776f7c3c
commit
ae88bca924
@ -0,0 +1,32 @@ |
|||||||
|
package org.openrs2.archive.key |
||||||
|
|
||||||
|
import com.github.ajalt.clikt.core.CliktCommand |
||||||
|
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) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
package org.openrs2.archive.key |
||||||
|
|
||||||
|
import org.openrs2.crypto.XteaKey |
||||||
|
import org.openrs2.db.Database |
||||||
|
import javax.inject.Inject |
||||||
|
import javax.inject.Singleton |
||||||
|
|
||||||
|
@Singleton |
||||||
|
public class KeyExporter @Inject constructor( |
||||||
|
private val database: Database |
||||||
|
) { |
||||||
|
public suspend fun exportValid(): List<XteaKey> { |
||||||
|
return database.execute { connection -> |
||||||
|
connection.prepareStatement( |
||||||
|
""" |
||||||
|
SELECT (k.key).k0, (k.key).k1, (k.key).k2, (k.key).k3 |
||||||
|
FROM keys k |
||||||
|
JOIN containers c ON c.key_id = k.id |
||||||
|
ORDER BY k.id ASC |
||||||
|
""".trimIndent() |
||||||
|
).use { stmt -> |
||||||
|
stmt.executeQuery().use { rows -> |
||||||
|
val keys = mutableListOf<XteaKey>() |
||||||
|
|
||||||
|
while (rows.next()) { |
||||||
|
val k0 = rows.getInt(1) |
||||||
|
val k1 = rows.getInt(2) |
||||||
|
val k2 = rows.getInt(3) |
||||||
|
val k3 = rows.getInt(4) |
||||||
|
keys += XteaKey(k0, k1, k2, k3) |
||||||
|
} |
||||||
|
|
||||||
|
keys |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue