some fixes, still wip

This commit is contained in:
creeper123123321 2020-10-24 19:41:59 -03:00
parent d350f470d2
commit 4055d17858
4 changed files with 14 additions and 20 deletions

View File

@ -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<Unit> {
object CloudPlatform : ViaPlatform<Unit> {
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
}

View File

@ -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

View File

@ -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<String>) {
File("config/https.jks").apply {
@ -51,7 +44,7 @@ fun main(args: Array<String>) {
.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<String>) {
}
}
future.channel().close().sync()
boss.shutdownGracefully().sync()
worker.shutdownGracefully().sync()
ktorServer.stop(1000, 1000)
listOf<Future<*>>(future.channel().close(), boss.shutdownGracefully(), worker.shutdownGracefully())
.forEach { it.sync() }
Via.getManager().destroy()
exitProcess(0) // todo what's stucking?
}
fun Application.mainWeb() {

View File

@ -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) {