diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt index f6c0350..f8ea75f 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt @@ -1,5 +1,6 @@ package com.github.creeper123123321.viaaas +import com.google.common.util.concurrent.ThreadFactoryBuilder import de.gerrygames.viarewind.api.ViaRewindPlatform import io.netty.buffer.ByteBuf import io.netty.channel.DefaultEventLoop @@ -101,8 +102,8 @@ object CloudAPI : ViaAPI { object CloudPlatform : ViaPlatform { val connMan = ViaConnectionManager() - val executor = Executors.newCachedThreadPool() - val eventLoop = DefaultEventLoop() + val executor = Executors.newCachedThreadPool(ThreadFactoryBuilder().setNameFormat("VIAaaS").setDaemon(true).build()) + val eventLoop = DefaultEventLoop(executor) override fun sendMessage(p0: UUID, p1: String) { // todo } diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudProtocol.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudProtocol.kt index aa38cf5..2234ec8 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudProtocol.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudProtocol.kt @@ -22,7 +22,6 @@ import java.util.logging.Logger import javax.naming.NameNotFoundException import javax.naming.directory.InitialDirContext - class CloudPipeline(userConnection: UserConnection) : ProtocolPipeline(userConnection) { override fun registerPackets() { super.registerPackets() @@ -50,6 +49,9 @@ object CloudHeadProtocol : SimpleProtocol() { val nextState = wrapper.passthrough(Type.VAR_INT) val parsed = VIAaaSAddress().parse(addr, VIAaaSConfig.hostName) + if (parsed.port == 0) { + parsed.port = receivedPort + } logger.info("connecting ${wrapper.user().channel!!.remoteAddress()} ($playerVer) to ${parsed.realAddress}:${parsed.port} (${parsed.protocol})") @@ -64,7 +66,7 @@ object CloudHeadProtocol : SimpleProtocol() { val frontForwarder = wrapper.user().channel!!.pipeline().get(CloudSideForwarder::class.java) try { var srvResolvedAddr = parsed.realAddress - var srvResolvedPort = if (parsed.port != 0) parsed.port else receivedPort + var srvResolvedPort = parsed.port if (srvResolvedPort == 25565) { try { // https://github.com/GeyserMC/Geyser/blob/99e72f35b308542cf0dbfb5b58816503c3d6a129/connector/src/main/java/org/geysermc/connector/GeyserConnector.java diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt index ff894f8..b09be4c 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt @@ -2,18 +2,14 @@ package com.github.creeper123123321.viaaas import de.gerrygames.viarewind.api.ViaRewindConfigImpl import io.ktor.application.* -import io.ktor.features.* -import io.ktor.http.cio.websocket.* -import io.ktor.http.content.* import io.ktor.network.tls.certificates.* -import io.ktor.routing.* +import io.ktor.server.engine.* import io.ktor.server.netty.* -import io.ktor.websocket.* import io.netty.bootstrap.ServerBootstrap import io.netty.channel.ChannelOption import io.netty.channel.nio.NioEventLoopGroup import io.netty.channel.socket.nio.NioServerSocketChannel -import kotlinx.coroutines.channels.consumeEach +import io.netty.util.concurrent.Future import us.myles.ViaVersion.ViaManager import us.myles.ViaVersion.api.Via import us.myles.ViaVersion.api.data.MappingDataLoader @@ -21,9 +17,6 @@ import us.myles.ViaVersion.api.protocol.ProtocolVersion import us.myles.ViaVersion.util.Config import java.io.File import java.net.InetAddress -import java.time.Duration -import java.util.concurrent.ConcurrentHashMap -import kotlin.system.exitProcess fun main(args: Array) { File("config/https.jks").apply { @@ -51,7 +44,7 @@ fun main(args: Array) { .bind(InetAddress.getByName(VIAaaSConfig.bindAddress), VIAaaSConfig.port) println("Binded minecraft into " + future.sync().channel().localAddress()) - Thread { EngineMain.main(arrayOf()) }.start() + val ktorServer = embeddedServer(Netty, commandLineEnvironment(args)) {}.start(false) loop@ while (true) { try { @@ -67,11 +60,11 @@ fun main(args: Array) { } } - future.channel().close().sync() - boss.shutdownGracefully().sync() - worker.shutdownGracefully().sync() + ktorServer.stop(1000, 1000) + listOf>(future.channel().close(), boss.shutdownGracefully(), worker.shutdownGracefully()) + .forEach { it.sync() } + Via.getManager().destroy() - exitProcess(0) // todo what's stucking? } fun Application.mainWeb() { diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/ViaWeb.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/ViaWeb.kt index 2a39149..f743030 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/ViaWeb.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/ViaWeb.kt @@ -3,7 +3,6 @@ package com.github.creeper123123321.viaaas import io.ktor.application.* import io.ktor.features.* import io.ktor.http.cio.websocket.* -import io.ktor.http.cio.websocket.WebSockets import io.ktor.http.content.* import io.ktor.routing.* import io.ktor.websocket.* @@ -80,7 +79,6 @@ class WebLogin : WebState { override suspend fun start(webClient: WebClient) { webClient.ws.send("test") webClient.ws.flush() - TODO("Not yet implemented") } override suspend fun onMessage(webClient: WebClient, msg: String) {