don't use LoggerWrapper, separate some code

This commit is contained in:
creeper123123321 2021-06-27 09:20:33 -03:00
parent 330364750a
commit 76fdf2a8a7
17 changed files with 189 additions and 178 deletions

View File

@ -75,13 +75,14 @@ dependencies {
implementation("org.yaml:snakeyaml:1.29")
val log4jVer = "2.14.1"
val slf4jVer = "1.7.31"
implementation("net.minecrell:terminalconsoleappender:1.2.0")
implementation("org.apache.logging.log4j:log4j-core:$log4jVer")
implementation("org.apache.logging.log4j:log4j-iostreams:$log4jVer")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVer")
implementation("org.apache.logging.log4j:log4j-jul:$log4jVer")
implementation("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVer")
implementation("org.jline:jline-terminal-jansi:3.20.0")
implementation("org.slf4j:slf4j-api:1.7.30")
implementation("org.slf4j:slf4j-api:$slf4jVer")
val ktorVersion = "1.6.0"
implementation("io.ktor:ktor-network-tls-certificates:$ktorVersion")

View File

@ -0,0 +1,123 @@
package com.viaversion.aas
import com.google.gson.JsonParser
import com.velocitypowered.natives.util.Natives
import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.FrontEndInit
import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.platform.AspirinPlatform
import com.viaversion.aas.web.WebDashboardServer
import com.viaversion.viaversion.ViaManagerImpl
import com.viaversion.viaversion.api.Via
import io.ktor.client.*
import io.ktor.client.engine.java.*
import io.ktor.client.features.*
import io.ktor.client.features.json.*
import io.ktor.network.tls.certificates.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.ChannelFuture
import io.netty.channel.ChannelOption
import io.netty.channel.WriteBufferWaterMark
import io.netty.resolver.dns.DnsNameResolverBuilder
import io.netty.util.concurrent.Future
import java.io.File
import java.net.InetAddress
import java.security.KeyPairGenerator
import java.util.concurrent.CompletableFuture
object AspirinServer {
var ktorServer: NettyApplicationEngine? = null
val version = JsonParser.parseString(
AspirinPlatform::class.java.classLoader
.getResourceAsStream("viaaas_info.json")!!
.reader(Charsets.UTF_8)
.readText()
).asJsonObject.get("version").asString
var viaWebServer = WebDashboardServer()
private var serverFinishing = CompletableFuture<Unit>()
private var finishedFuture = CompletableFuture<Unit>()
private val initFuture = CompletableFuture<Unit>()
val bufferWaterMark = WriteBufferWaterMark(512 * 1024, 2048 * 1024)
// Minecraft doesn't have forward secrecy
val mcCryptoKey = KeyPairGenerator.getInstance("RSA").let {
it.initialize(VIAaaSConfig.mcRsaSize) // https://stackoverflow.com/questions/1904516/is-1024-bit-rsa-secure
it.genKeyPair()
}
val parentLoop = eventLoopGroup()
val childLoop = eventLoopGroup()
var chFuture: ChannelFuture? = null
val dnsResolver = DnsNameResolverBuilder(childLoop.next())
.socketChannelFactory(channelSocketFactory(childLoop))
.channelFactory(channelDatagramFactory(childLoop))
.build()
val httpClient = HttpClient(Java) {
install(UserAgent) {
agent = "VIAaaS/${version.substringBefore("+")}"
}
install(JsonFeature) {
serializer = GsonSerializer()
}
}
fun finish() {
try {
Via.getManager().connectionManager.connections.forEach {
it.channel?.pipeline()?.get(MinecraftHandler::class.java)?.disconnect("Stopping")
}
(Via.getManager() as ViaManagerImpl).destroy()
} finally {
mainFinishSignal()
ktorServer?.stop(1000, 1000)
httpClient.close()
listOf<Future<*>?>(
chFuture?.channel()?.close(),
parentLoop.shutdownGracefully(),
childLoop.shutdownGracefully()
)
.forEach { it?.sync() }
}
}
fun waitStopSignal() = serverFinishing.join()
fun waitMainFinish() = finishedFuture.join()
fun waitMainStart() = initFuture.join()
fun wasStopSignalFired() = serverFinishing.isDone
fun stopSignal() = serverFinishing.complete(Unit)
fun mainFinishSignal() = finishedFuture.complete(Unit)
fun mainStartSigal() = initFuture.complete(Unit)
fun listenPorts(args: Array<String>) {
chFuture = ServerBootstrap()
.group(parentLoop, childLoop)
.channelFactory(channelServerSocketFactory(parentLoop))
.childHandler(FrontEndInit)
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, bufferWaterMark)
.childOption(ChannelOption.IP_TOS, 0x18)
.childOption(ChannelOption.TCP_NODELAY, true)
.bind(InetAddress.getByName(VIAaaSConfig.bindAddress), VIAaaSConfig.port)
viaaasLogger.info("Using compression: ${Natives.compress.loadedVariant}")
viaaasLogger.info("Binded minecraft into " + chFuture!!.sync().channel().localAddress())
ktorServer = embeddedServer(Netty, commandLineEnvironment(args)) {}.start(false)
}
fun generateCert() {
File("config/https.jks").apply {
parentFile.mkdirs()
if (!exists()) generateCertificate(this)
}
}
fun addShutdownHook() {
Runtime.getRuntime().addShutdownHook(Thread {
stopSignal()
waitMainFinish()
})
}
}

View File

@ -60,7 +60,7 @@ suspend fun resolveSrv(hostAndPort: HostAndPort): HostAndPort {
if (hostAndPort.port == 25565) {
try {
// stolen from PacketLib (MIT) https://github.com/Camotoy/PacketLib/blob/312cff5f975be54cf2d92208ae2947dbda8b9f59/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java
val records = dnsResolver
val records = AspirinServer.dnsResolver
.resolveAll(DefaultDnsQuestion("_minecraft._tcp.${hostAndPort.host}", DnsRecordType.SRV))
.suspendAwait()
try {
@ -198,7 +198,7 @@ fun ByteBuf.readByteArray(length: Int) = ByteArray(length).also { readBytes(it)
suspend fun hasJoined(username: String, hash: String): JsonObject {
return try {
httpClient.get(
AspirinServer.httpClient.get(
"https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" +
UrlEscapers.urlFormParameterEscaper().escape(username) + "&serverId=$hash"
)

View File

@ -1,107 +1,51 @@
package com.viaversion.aas
import com.google.gson.JsonParser
import com.velocitypowered.natives.util.Natives
import com.viaversion.aas.command.VIAaaSConsole
import com.viaversion.aas.command.ViaAspirinCommand
import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.FrontEndInit
import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.platform.*
import com.viaversion.aas.protocol.registerAspirinProtocols
import com.viaversion.aas.web.ViaWebApp
import com.viaversion.aas.web.WebDashboardServer
import com.viaversion.viaversion.ViaManagerImpl
import com.viaversion.viaversion.api.Via
import com.viaversion.viaversion.api.data.MappingDataLoader
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import de.gerrygames.viarewind.api.ViaRewindConfigImpl
import io.ktor.application.*
import io.ktor.client.*
import io.ktor.client.engine.java.*
import io.ktor.client.features.*
import io.ktor.client.features.json.*
import io.ktor.network.tls.certificates.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.ChannelFuture
import io.netty.channel.ChannelOption
import io.netty.channel.WriteBufferWaterMark
import io.netty.resolver.dns.DnsNameResolverBuilder
import io.netty.util.concurrent.Future
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.io.IoBuilder
import java.io.File
import java.net.InetAddress
import java.security.KeyPairGenerator
import java.util.concurrent.CompletableFuture
val viaaasVer = JsonParser.parseString(
AspirinPlatform::class.java.classLoader.getResourceAsStream("viaaas_info.json")!!.reader(Charsets.UTF_8).readText()
).asJsonObject.get("version").asString
var viaWebServer = WebDashboardServer()
var serverFinishing = CompletableFuture<Unit>()
var finishedFuture = CompletableFuture<Unit>()
val httpClient = HttpClient(Java) {
install(UserAgent) {
agent = "VIAaaS/${viaaasVer.substringBefore("+")}"
}
install(JsonFeature) {
serializer = GsonSerializer()
}
}
val initFuture = CompletableFuture<Unit>()
val bufferWaterMark = WriteBufferWaterMark(512 * 1024, 2048 * 1024)
// Minecraft doesn't have forward secrecy
val mcCryptoKey = KeyPairGenerator.getInstance("RSA").let {
it.initialize(VIAaaSConfig.mcRsaSize) // https://stackoverflow.com/questions/1904516/is-1024-bit-rsa-secure
it.genKeyPair()
}
val parentLoop = eventLoopGroup()
val childLoop = eventLoopGroup()
var chFuture: ChannelFuture? = null
var ktorServer: NettyApplicationEngine? = null
val dnsResolver = DnsNameResolverBuilder(childLoop.next())
.socketChannelFactory(channelSocketFactory(childLoop))
.channelFactory(channelDatagramFactory(childLoop))
.build()
fun main(args: Array<String>) {
try {
setupSystem()
printSplash()
generateCert()
AspirinServer.generateCert()
initVia()
bindPorts(args)
AspirinServer.listenPorts(args)
initFuture.complete(Unit)
addShutdownHook()
AspirinServer.mainStartSigal()
AspirinServer.addShutdownHook()
Thread { VIAaaSConsole.start() }.start()
serverFinishing.join()
AspirinServer.waitStopSignal()
} catch (e: Exception) {
e.printStackTrace()
} finally {
stopServer()
AspirinServer.finish()
}
}
private fun addShutdownHook() {
Runtime.getRuntime().addShutdownHook(Thread {
serverFinishing.complete(Unit)
finishedFuture.join()
})
}
private fun setupSystem() {
// Stolen from https://github.com/VelocityPowered/Velocity/blob/dev/1.1.0/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java
if (System.getProperty("io.netty.allocator.maxOrder") == null) {
System.setProperty("io.netty.allocator.maxOrder", "9")
}
// https://logging.apache.org/log4j/2.x/log4j-jul/index.html
if (System.getProperty("java.util.logging.manager") == null) {
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
}
// Also stolen from Velocity
System.setOut(IoBuilder.forLogger("STDOUT").setLevel(Level.INFO).buildPrintStream())
System.setErr(IoBuilder.forLogger("STDERR").setLevel(Level.ERROR).buildPrintStream())
@ -111,18 +55,12 @@ private fun printSplash() {
println(
"""\\ // // //\\ => //|| //|| /=====/ PROXY
| \\ // // // \\ // || // || //
| \\ // // //====\\ //==|| //==|| \====\ $viaaasVer
| \\ // // //====\\ //==|| //==|| \====\ ${AspirinServer.version}
| \\ // // // \\ // || // || //
|<= \\// // // \\ // || // || /====/""".trimMargin()
)
}
private fun generateCert() {
File("config/https.jks").apply {
parentFile.mkdirs()
if (!exists()) generateCertificate(this)
}
}
private fun initVia() {
Via.init(
@ -141,41 +79,6 @@ private fun initVia() {
registerAspirinProtocols()
}
private fun bindPorts(args: Array<String>) {
chFuture = ServerBootstrap()
.group(parentLoop, childLoop)
.channelFactory(channelServerSocketFactory(parentLoop))
.childHandler(FrontEndInit)
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, bufferWaterMark)
.childOption(ChannelOption.IP_TOS, 0x18)
.childOption(ChannelOption.TCP_NODELAY, true)
.bind(InetAddress.getByName(VIAaaSConfig.bindAddress), VIAaaSConfig.port)
viaaasLogger.info("Using compression: ${Natives.compress.loadedVariant}")
viaaasLogger.info("Binded minecraft into " + chFuture!!.sync().channel().localAddress())
ktorServer = embeddedServer(Netty, commandLineEnvironment(args)) {}.start(false)
}
private fun stopServer() {
try {
Via.getManager().connectionManager.connections.forEach {
it.channel?.pipeline()?.get(MinecraftHandler::class.java)?.disconnect("Stopping")
}
(Via.getManager() as ViaManagerImpl).destroy()
} finally {
finishedFuture.complete(Unit)
ktorServer?.stop(1000, 1000)
httpClient.close()
listOf<Future<*>?>(
chFuture?.channel()?.close(),
parentLoop.shutdownGracefully(),
childLoop.shutdownGracefully()
)
.forEach { it?.sync() }
}
}
fun Application.mainWeb() {
ViaWebApp().apply { main() }
ViaWebApp(AspirinServer.viaWebServer).apply { main() }
}

View File

@ -1,7 +1,7 @@
package com.viaversion.aas.command
import com.viaversion.aas.AspirinServer
import com.viaversion.aas.command.sub.StopSubCommand
import com.viaversion.aas.serverFinishing
import com.viaversion.viaversion.api.command.ViaCommandSender
import net.minecrell.terminalconsole.SimpleTerminalConsole
import org.jline.reader.Candidate
@ -12,7 +12,7 @@ import java.util.*
object VIAaaSConsole : SimpleTerminalConsole(), ViaCommandSender {
val commands = hashMapOf<String, Command>()
override fun isRunning(): Boolean = !serverFinishing.isDone
override fun isRunning(): Boolean = !AspirinServer.wasStopSignalFired()
init {
commands["viaversion"] = ViaAspirinCommand

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.command.sub
import com.viaversion.aas.serverFinishing
import com.viaversion.aas.AspirinServer
import com.viaversion.viaversion.api.command.ViaCommandSender
import com.viaversion.viaversion.api.command.ViaSubCommand
@ -9,7 +9,7 @@ object StopSubCommand : ViaSubCommand() {
override fun description(): String = "Stops VIAaaS"
override fun execute(sender: ViaCommandSender, p1: Array<String>): Boolean {
sender.sendMessage("Shutting down...")
serverFinishing.complete(Unit)
AspirinServer.stopSignal()
return true
}
}

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.command.sub
import com.viaversion.aas.viaaasVer
import com.viaversion.aas.AspirinServer
import com.viaversion.viaversion.api.command.ViaCommandSender
import com.viaversion.viaversion.api.command.ViaSubCommand
@ -8,7 +8,7 @@ object VIAaaSSubCommand : ViaSubCommand() {
override fun name(): String = "viaaas"
override fun description(): String = "Info about VIAaaS"
override fun execute(p0: ViaCommandSender, p1: Array<out String>): Boolean {
p0.sendMessage("VIAaaS version $viaaasVer")
p0.sendMessage("VIAaaS version ${AspirinServer.version}")
return true
}
}

View File

@ -2,8 +2,8 @@ package com.viaversion.aas.handler.autoprotocol
import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader
import com.viaversion.aas.AspirinServer
import com.viaversion.aas.channelSocketFactory
import com.viaversion.aas.childLoop
import com.viaversion.aas.codec.FrameCodec
import com.viaversion.aas.codec.MinecraftCodec
import com.viaversion.aas.codec.packet.handshake.Handshake
@ -32,9 +32,9 @@ object ProtocolDetector {
val future = CompletableFuture<ProtocolVersion>()
try {
val ch = Bootstrap()
.group(childLoop)
.group(AspirinServer.childLoop)
.resolver(NoopAddressResolverGroup.INSTANCE)
.channelFactory(channelSocketFactory(childLoop))
.channelFactory(channelSocketFactory(AspirinServer.childLoop))
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.IP_TOS, 0x18)
.handler(object : ChannelInitializer<Channel>() {

View File

@ -11,7 +11,6 @@ import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.handler.forward
import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.Via
import com.viaversion.viaversion.api.protocol.packet.State
import io.netty.channel.Channel
import io.netty.channel.ChannelHandlerContext
@ -83,7 +82,7 @@ class LoginState : MinecraftConnectionState {
val cryptoRequest = CryptoRequest()
cryptoRequest.serverId = frontServerId
cryptoRequest.publicKey = mcCryptoKey.public
cryptoRequest.publicKey = AspirinServer.mcCryptoKey.public
cryptoRequest.token = frontToken
send(frontChannel, cryptoRequest, true)
@ -108,7 +107,7 @@ class LoginState : MinecraftConnectionState {
val backHash = generateServerHash(backServerId, backKey, backPublicKey)
mcLogger.info("Session req: ${handler.data.frontHandler.endRemoteAddress} ($playerId $frontName) $backName")
viaWebServer.requestSessionJoin(
AspirinServer.viaWebServer.requestSessionJoin(
playerId,
backName!!,
backHash,
@ -132,8 +131,8 @@ class LoginState : MinecraftConnectionState {
fun handleCryptoResponse(handler: MinecraftHandler, cryptoResponse: CryptoResponse) {
val frontHash = let {
val frontKey = decryptRsa(mcCryptoKey.private, cryptoResponse.encryptedKey)
val decryptedToken = decryptRsa(mcCryptoKey.private, cryptoResponse.encryptedToken)
val frontKey = decryptRsa(AspirinServer.mcCryptoKey.private, cryptoResponse.encryptedKey)
val decryptedToken = decryptRsa(AspirinServer.mcCryptoKey.private, cryptoResponse.encryptedToken)
if (!decryptedToken.contentEquals(frontToken)) throw StacklessException("Invalid verification token!")
@ -141,7 +140,7 @@ class LoginState : MinecraftConnectionState {
val aesDe = mcCfb8(frontKey, Cipher.DECRYPT_MODE)
handler.data.frontChannel.pipeline().addBefore("frame", "crypto", CryptoCodec(aesDe, aesEn))
generateServerHash(frontServerId, frontKey, mcCryptoKey.public)
generateServerHash(frontServerId, frontKey, AspirinServer.mcCryptoKey.public)
}
handler.data.frontChannel.setAutoRead(false)

View File

@ -33,7 +33,7 @@ private suspend fun createBackChannel(
.handler(BackEndInit(handler.data))
.channelFactory(channelSocketFactory(loop.parent()))
.group(loop)
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, bufferWaterMark)
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, AspirinServer.bufferWaterMark)
.option(ChannelOption.IP_TOS, 0x18)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000) // We need to show the error before the client timeout
@ -116,7 +116,7 @@ private suspend fun resolveBackendAddresses(hostAndPort: HostAndPort): List<Inet
return when {
removedEndDot.endsWith(".onion", ignoreCase = true) ->
listOf(InetSocketAddress.createUnresolved(removedEndDot, srvResolved.port))
else -> dnsResolver
else -> AspirinServer.dnsResolver
.resolveAll(srvResolved.host)
.suspendAwait()
.groupBy { it is Inet4Address }

View File

@ -1,15 +1,11 @@
package com.viaversion.aas.platform
import com.viaversion.viabackwards.api.ViaBackwardsPlatform
import com.viaversion.viaversion.sponge.util.LoggerWrapper
import org.slf4j.LoggerFactory
import java.io.File
import java.util.logging.Logger
object AspirinBackwards : ViaBackwardsPlatform {
val log = LoggerWrapper(LoggerFactory.getLogger("ViaBackwards"))
override fun getDataFolder() = File("config/viabackwards")
override fun getLogger(): Logger = log
override fun disable() {
}
override fun getLogger() = Logger.getLogger("ViaBackwards")
override fun disable() = Unit
}

View File

@ -4,15 +4,14 @@ import com.viaversion.aas.provider.AspirinVersionProvider
import com.viaversion.viaversion.api.Via
import com.viaversion.viaversion.api.platform.ViaPlatformLoader
import com.viaversion.viaversion.api.protocol.version.VersionProvider
import com.viaversion.viaversion.bungee.providers.BungeeMovementTransmitter
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider
import com.viaversion.viaversion.velocity.providers.VelocityMovementTransmitter
object AspirinLoader : ViaPlatformLoader {
override fun unload() {
}
override fun unload() = Unit
override fun load() {
Via.getManager().providers.use(MovementTransmitterProvider::class.java, BungeeMovementTransmitter())
Via.getManager().providers.use(MovementTransmitterProvider::class.java, VelocityMovementTransmitter())
Via.getManager().providers.use(VersionProvider::class.java, AspirinVersionProvider)
}
}

View File

@ -1,19 +1,15 @@
package com.viaversion.aas.platform
import com.google.common.util.concurrent.ThreadFactoryBuilder
import com.viaversion.aas.AspirinServer
import com.viaversion.aas.config.AspirinViaConfig
import com.viaversion.aas.initFuture
import com.viaversion.aas.viaaasVer
import com.viaversion.viaversion.api.ViaAPI
import com.viaversion.viaversion.api.command.ViaCommandSender
import com.viaversion.viaversion.api.configuration.ConfigurationProvider
import com.viaversion.viaversion.api.configuration.ViaVersionConfig
import com.viaversion.viaversion.api.platform.ViaPlatform
import com.viaversion.viaversion.libs.gson.JsonObject
import com.viaversion.viaversion.sponge.util.LoggerWrapper
import com.viaversion.viaversion.util.VersionInfo
import io.netty.channel.DefaultEventLoop
import org.slf4j.LoggerFactory
import java.io.File
import java.util.*
import java.util.concurrent.CompletableFuture
@ -26,16 +22,13 @@ object AspirinPlatform : ViaPlatform<UUID> {
val eventLoop = DefaultEventLoop(executor)
init {
eventLoop.execute(initFuture::join)
}
override fun sendMessage(p0: UUID, p1: String) {
// todo
}
override fun onReload() {
eventLoop.execute {
AspirinServer.waitMainStart()
}
}
override fun sendMessage(p0: UUID, p1: String) = Unit
override fun onReload() = Unit
override fun runSync(runnable: Runnable): AspirinTask = AspirinTask(eventLoop.submit(runnable))
override fun runSync(p0: Runnable, p1: Long): AspirinTask =
AspirinTask(eventLoop.schedule(p0, p1 * 50L, TimeUnit.MILLISECONDS))
@ -43,19 +36,19 @@ object AspirinPlatform : ViaPlatform<UUID> {
override fun runRepeatingSync(p0: Runnable, p1: Long): AspirinTask =
AspirinTask(eventLoop.scheduleAtFixedRate(p0, 0, p1 * 50L, TimeUnit.MILLISECONDS))
override fun getDump(): JsonObject = JsonObject()
override fun kickPlayer(p0: UUID, p1: String): Boolean = false
override fun getApi(): ViaAPI<UUID> = AspirinViaAPI
override fun getDataFolder(): File = File("viaversion")
override fun getDump() = JsonObject()
override fun kickPlayer(p0: UUID, p1: String) = false
override fun getApi() = AspirinViaAPI
override fun getDataFolder() = File("viaversion")
override fun getConf(): ViaVersionConfig = AspirinViaConfig
override fun runAsync(p0: Runnable): AspirinTask = AspirinTask(CompletableFuture.runAsync(p0, executor))
override fun getLogger(): Logger = LoggerWrapper(LoggerFactory.getLogger("ViaVersion"))
override fun getLogger() = Logger.getLogger("ViaVersion")
override fun getOnlinePlayers(): Array<ViaCommandSender> = arrayOf()
override fun isPluginEnabled(): Boolean = true
override fun isPluginEnabled() = true
override fun getConfigurationProvider(): ConfigurationProvider = AspirinViaConfig
override fun getPlatformName(): String = "VIAaaS"
override fun getPlatformVersion(): String = viaaasVer
override fun getPluginVersion(): String = VersionInfo.VERSION
override fun isOldClientsAllowed(): Boolean = true
override fun isProxy(): Boolean = true
override fun getPlatformName() = "VIAaaS"
override fun getPlatformVersion(): String = AspirinServer.version
override fun getPluginVersion() = VersionInfo.VERSION
override fun isOldClientsAllowed() = true
override fun isProxy() = true
}

View File

@ -1,11 +1,8 @@
package com.viaversion.aas.platform
import com.viaversion.viaversion.sponge.util.LoggerWrapper
import de.gerrygames.viarewind.api.ViaRewindPlatform
import org.slf4j.LoggerFactory
import java.util.logging.Logger
object AspirinRewind : ViaRewindPlatform {
val log = LoggerWrapper(LoggerFactory.getLogger("ViaRewind"))
override fun getLogger(): Logger = log
override fun getLogger() = Logger.getLogger("ViaRewind")
}

View File

@ -1,6 +1,5 @@
package com.viaversion.aas.web
import com.viaversion.aas.viaWebServer
import io.ktor.application.*
import io.ktor.features.*
import io.ktor.http.*
@ -13,7 +12,7 @@ import org.slf4j.event.Level
import java.nio.channels.ClosedChannelException
import java.time.Duration
class ViaWebApp {
class ViaWebApp(val viaWebServer: WebDashboardServer) {
fun Application.main() {
install(DefaultHeaders)
install(ConditionalHeaders)
@ -41,6 +40,11 @@ class ViaWebApp {
install(Compression)
routing {
static {
defaultResource("index.html", "web")
resources("web")
}
webSocket("/ws") {
try {
viaWebServer.connected(this)
@ -57,11 +61,6 @@ class ViaWebApp {
viaWebServer.disconnected(this)
}
}
static {
defaultResource("index.html", "web")
resources("web")
}
}
}
}

View File

@ -71,7 +71,8 @@ class WebDashboardServer {
.expireAfterWrite(1, TimeUnit.HOURS)
.build<String, CompletableFuture<UUID?>>(CacheLoader.from { name ->
CoroutineScope(Dispatchers.IO).async {
httpClient.get<JsonObject?>("https://api.mojang.com/users/profiles/minecraft/$name")
AspirinServer.httpClient
.get<JsonObject?>("https://api.mojang.com/users/profiles/minecraft/$name")
?.get("id")?.asString?.let { parseUndashedId(it) }
}.asCompletableFuture()
})
@ -97,7 +98,7 @@ class WebDashboardServer {
val ipLookup = async(Dispatchers.IO) {
ipInfo.lookupIP(it.address!!.hostAddress!!.substringBefore("%"))
}
val dnsQuery = dnsResolver.resolveAll(
val dnsQuery = AspirinServer.dnsResolver.resolveAll(
DefaultDnsQuestion(reverseLookup(it.address), DnsRecordType.PTR)
)
info = ipLookup.await()

View File

@ -48,7 +48,7 @@ class WebLogin : WebState {
val username = obj.get("username").asString
val code = obj.get("code").asString
val check = httpClient.submitForm<JsonObject>(
val check = AspirinServer.httpClient.submitForm<JsonObject>(
"https://api.minecraft.id/gateway/verify/${URLEncoder.encode(username, Charsets.UTF_8)}",
formParameters = parametersOf("code", code),
)