From 6ff3b1e5e0f7908605fa9e56adca82cb33c1ea6f Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Fri, 26 Mar 2021 17:19:24 -0300 Subject: [PATCH] update via platform --- .../github/creeper123123321/viaaas/VIAaaS.kt | 19 +++++++++++-------- .../viaaas/platform/AspirinInjector.kt | 9 ++++++++- .../viaaas/platform/AspirinPlatform.kt | 4 ++-- .../viaaas/platform/AspirinViaAPI.kt | 17 ++++++----------- .../viaaas/provider/AspirinVersionProvider.kt | 4 ++-- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt index 4c8f65a..f783c82 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt @@ -36,12 +36,11 @@ import io.netty.channel.socket.nio.NioSocketChannel import io.netty.util.concurrent.Future import org.apache.logging.log4j.Level import org.apache.logging.log4j.io.IoBuilder -import us.myles.ViaVersion.ViaManager +import us.myles.ViaVersion.ViaManagerImpl import us.myles.ViaVersion.api.Via import us.myles.ViaVersion.api.data.MappingDataLoader import us.myles.ViaVersion.api.protocol.ProtocolVersion import java.io.File -import java.lang.Thread import java.net.InetAddress import java.security.KeyPairGenerator import java.util.concurrent.CompletableFuture @@ -103,11 +102,13 @@ fun main(args: Array) { System.setOut(IoBuilder.forLogger("STDOUT").setLevel(Level.INFO).buildPrintStream()); System.setErr(IoBuilder.forLogger("STDERR").setLevel(Level.ERROR).buildPrintStream()); - println("""\\ // // //\\ => //|| //|| /=====/ PROXY + println( + """\\ // // //\\ => //|| //|| /=====/ PROXY | \\ // // // \\ // || // || // | \\ // // //====\\ //==|| //==|| \====\ $viaaasVer | \\ // // // \\ // || // || // - |<= \\// // // \\ // || // || /====/""".trimMargin()) + |<= \\// // // \\ // || // || /====/""".trimMargin() + ) File("config/https.jks").apply { parentFile.mkdirs() @@ -115,14 +116,14 @@ fun main(args: Array) { } Via.init( - ViaManager.builder() + ViaManagerImpl.builder() .injector(AspirinInjector) .loader(AspirinLoader) .commandHandler(AspirinCommands) .platform(AspirinPlatform).build() ) MappingDataLoader.enableMappingsCache() - Via.getManager().init() + (Via.getManager() as ViaManagerImpl).init() ProtocolVersion.register(-2, "AUTO") AspirinRewind.init(ViaRewindConfigImpl(File("config/viarewind.yml"))) AspirinBackwards.init(File("config/viabackwards")) @@ -147,14 +148,16 @@ fun main(args: Array) { initFuture.complete(Unit) VIAaaSConsole.start() - while(runningServer) { Thread.sleep(1000L) } + while (runningServer) { + Thread.sleep(1000L) + } ktorServer?.stop(1000, 1000) httpClient.close() listOf>(future.channel().close(), parentLoop.shutdownGracefully(), childLoop.shutdownGracefully()) .forEach { it.sync() } - Via.getManager().destroy() + (Via.getManager() as ViaManagerImpl).destroy() } fun Application.mainWeb() { diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinInjector.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinInjector.kt index 2def79c..ff5d51a 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinInjector.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinInjector.kt @@ -1,13 +1,20 @@ package com.github.creeper123123321.viaaas.platform import us.myles.ViaVersion.api.platform.ViaInjector +import us.myles.ViaVersion.api.protocol.ProtocolVersion +import us.myles.viaversion.libs.fastutil.ints.IntLinkedOpenHashSet +import us.myles.viaversion.libs.fastutil.ints.IntSortedSet import us.myles.viaversion.libs.gson.JsonObject object AspirinInjector : ViaInjector { override fun getEncoderName(): String = "via-codec" override fun getDecoderName() = "via-codec" override fun getDump(): JsonObject = JsonObject() - override fun getServerProtocolVersion() = 47 // Dummy + override fun getServerProtocolVersions(): IntSortedSet = IntLinkedOpenHashSet( + sortedSetOf(ProtocolVersion.v1_16_4.version, ProtocolVersion.v1_7_1.version) + ) + + override fun getServerProtocolVersion(): Int = ProtocolVersion.v1_7_1.version override fun uninject() { } diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinPlatform.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinPlatform.kt index ff1c326..4ccc4db 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinPlatform.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinPlatform.kt @@ -23,7 +23,7 @@ import java.util.concurrent.Executors import java.util.concurrent.TimeUnit import java.util.logging.Logger -object AspirinPlatform : ViaPlatform { +object AspirinPlatform : ViaPlatform { val connMan = ViaConnectionManager() val executor = Executors.newCachedThreadPool(ThreadFactoryBuilder().setNameFormat("Via-%d").setDaemon(true).build()) val eventLoop = DefaultEventLoop(executor) @@ -52,7 +52,7 @@ object AspirinPlatform : ViaPlatform { override fun getDump(): JsonObject = JsonObject() override fun kickPlayer(p0: UUID, p1: String): Boolean = false - override fun getApi(): ViaAPI = AspirinViaAPI + override fun getApi(): ViaAPI = AspirinViaAPI override fun getDataFolder(): File = File("viaversion") override fun getConf(): ViaVersionConfig = AspirinViaConfig override fun runAsync(p0: Runnable): TaskId = AspirinTask(CompletableFuture.runAsync(p0, executor)) diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinViaAPI.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinViaAPI.kt index 4d6362e..01334c1 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinViaAPI.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/platform/AspirinViaAPI.kt @@ -1,22 +1,17 @@ package com.github.creeper123123321.viaaas.platform import io.netty.buffer.ByteBuf -import us.myles.ViaVersion.api.ViaAPI +import us.myles.ViaVersion.api.ViaAPIBase import us.myles.ViaVersion.api.boss.BossBar import us.myles.ViaVersion.api.boss.BossColor import us.myles.ViaVersion.api.boss.BossStyle -import us.myles.ViaVersion.api.protocol.ProtocolRegistry import java.util.* -import kotlin.UnsupportedOperationException -object AspirinViaAPI : ViaAPI { - override fun isInjected(p0: UUID): Boolean = false +object AspirinViaAPI : ViaAPIBase() { override fun createBossBar(p0: String, p1: BossColor, p2: BossStyle): BossBar<*> = AspirinBossBar(p0, 0f, p2, p1) - override fun createBossBar(p0: String, p1: Float, p2: BossColor, p3: BossStyle): BossBar<*> = AspirinBossBar(p0, p1, p3, p2) - override fun sendRawPacket(p0: Unit?, p1: ByteBuf?) = throw UnsupportedOperationException() - override fun sendRawPacket(p0: UUID?, p1: ByteBuf?) = throw UnsupportedOperationException() - override fun getPlayerVersion(p0: Unit?): Int = throw UnsupportedOperationException() + override fun createBossBar(p0: String, p1: Float, p2: BossColor, p3: BossStyle): BossBar<*> = + AspirinBossBar(p0, p1, p3, p2) + + override fun sendRawPacket(p0: UUID, p1: ByteBuf) = super.sendRawPacket(p0, p1) override fun getPlayerVersion(p0: UUID?): Int = throw UnsupportedOperationException() - override fun getVersion(): String = AspirinPlatform.pluginVersion - override fun getSupportedVersions(): SortedSet = ProtocolRegistry.getSupportedVersions() } \ No newline at end of file diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/provider/AspirinVersionProvider.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/provider/AspirinVersionProvider.kt index 1e88ea1..227b925 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/provider/AspirinVersionProvider.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/provider/AspirinVersionProvider.kt @@ -2,9 +2,9 @@ package com.github.creeper123123321.viaaas.provider import com.github.creeper123123321.viaaas.handler.MinecraftHandler import us.myles.ViaVersion.api.data.UserConnection -import us.myles.ViaVersion.protocols.base.VersionProvider +import us.myles.ViaVersion.protocols.base.BaseVersionProvider -object AspirinVersionProvider : VersionProvider() { +object AspirinVersionProvider : BaseVersionProvider() { override fun getServerProtocol(connection: UserConnection): Int { val ver = connection.channel!!.pipeline().get(MinecraftHandler::class.java).data.viaBackServerVer if (ver != null) return ver