diff --git a/build.gradle.kts b/build.gradle.kts index f36874a..4abb7be 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ java { val gitVersion: groovy.lang.Closure by extra group = "com.github.creeper123123321.viaaas" -version = "0.1.0-SNAPSHOT+" + try { +version = "0.1.1-SNAPSHOT+" + try { gitVersion() } catch (e: Exception) { "unknown" diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudCodec.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudCodec.kt index 97c7d60..c613f0e 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudCodec.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudCodec.kt @@ -19,7 +19,6 @@ import java.util.zip.Deflater import java.util.zip.Inflater import javax.crypto.Cipher - object ChannelInit : ChannelInitializer() { override fun initChannel(ch: Channel) { ch.pipeline().addLast("timeout", ReadTimeoutHandler(30, TimeUnit.SECONDS)) @@ -27,9 +26,13 @@ object ChannelInit : ChannelInitializer() { .addLast("frame", FrameCodec()) // "compress" / dummy "decompress" .addLast("flow-handler", FlowControlHandler()) - .addLast("handler", CloudMinecraftHandler(ConnectionData( - frontChannel = ch, - ), other = null, frontEnd = true)) + .addLast( + "handler", CloudMinecraftHandler( + ConnectionData( + frontChannel = ch, + ), other = null, frontEnd = true + ) + ) } } @@ -113,8 +116,11 @@ class CloudCompressionCodec(val threshold: Int) : MessageToMessageCodec ${packet.address}:${packet.port} ($backProto)") + mcLogger.info("Connecting $playerAddr (${handler.data.frontVer}) -> ${packet.address}:${packet.port} ($backProto)") if (!hadHostname && VIAaaSConfig.requireHostName) { throw UnsupportedOperationException("This VIAaaS instance requires you to use the hostname") @@ -174,7 +174,7 @@ class HandshakeState : MinecraftConnectionState { bootstrap.addListener { if (it.isSuccess) { - chLogger.info("Connected ${frontHandler.remoteAddress} -> $socketAddr") + mcLogger.info("Connected ${frontHandler.remoteAddress} -> $socketAddr") val backChan = bootstrap.channel() as SocketChannel handler.data.backChannel = backChan diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt index 8061233..dc7c494 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt @@ -36,9 +36,6 @@ import java.util.concurrent.Future import java.util.concurrent.TimeUnit import java.util.logging.Logger -val viaaasVer = GsonUtil.getGson().fromJson(CloudPlatform::class.java.classLoader.getResourceAsStream("viaaas_info.json")!! - .reader(Charsets.UTF_8).readText(), JsonObject::class.java).get("version").asString - object CloudBackwards : ViaBackwardsPlatform { val log = LoggerWrapper(LoggerFactory.getLogger("ViaBackwards")) override fun getDataFolder() = File("config/viabackwards") @@ -78,11 +75,14 @@ object CloudInjector : ViaInjector { override fun getServerProtocolVersion() = 47 // Dummy } -class CloudBossBar(title: String, health: Float, style: BossStyle, color: BossColor) : CommonBoss(title, health, color, style) +class CloudBossBar(title: String, health: Float, style: BossStyle, color: BossColor) : + CommonBoss(title, health, color, style) + object CloudAPI : ViaAPI { override fun isInjected(p0: UUID): Boolean = false override fun createBossBar(p0: String, p1: BossColor, p2: BossStyle): BossBar<*> = CloudBossBar(p0, 0f, p2, p1) - override fun createBossBar(p0: String, p1: Float, p2: BossColor, p3: BossStyle): BossBar<*> = CloudBossBar(p0, p1, p3, p2) + override fun createBossBar(p0: String, p1: Float, p2: BossColor, p3: BossStyle): BossBar<*> = + CloudBossBar(p0, p1, p3, p2) override fun sendRawPacket(p0: Unit?, p1: ByteBuf?) { TODO("Not yet implemented") @@ -126,8 +126,12 @@ object CloudPlatform : ViaPlatform { override fun getDump(): JsonObject = JsonObject() override fun runSync(runnable: Runnable): TaskId = CloudTask(eventLoop.submit(runnable)) - override fun runSync(p0: Runnable, p1: Long): TaskId = CloudTask(eventLoop.schedule(p0, p1 * 50L, TimeUnit.MILLISECONDS)) - override fun runRepeatingSync(p0: Runnable, p1: Long): TaskId = CloudTask(eventLoop.scheduleAtFixedRate(p0, 0, p1 * 50L, TimeUnit.MILLISECONDS)) + override fun runSync(p0: Runnable, p1: Long): TaskId = + CloudTask(eventLoop.schedule(p0, p1 * 50L, TimeUnit.MILLISECONDS)) + + override fun runRepeatingSync(p0: Runnable, p1: Long): TaskId = + CloudTask(eventLoop.scheduleAtFixedRate(p0, 0, p1 * 50L, TimeUnit.MILLISECONDS)) + override fun runAsync(p0: Runnable): TaskId = CloudTask(CompletableFuture.runAsync(p0, executor)) override fun getLogger(): Logger = LoggerWrapper(LoggerFactory.getLogger("ViaVersion")) override fun getConnectionManager(): ViaConnectionManager = connMan @@ -146,7 +150,7 @@ object CloudPlatform : ViaPlatform { override fun isProxy(): Boolean = true } -class CloudConnectionManager: ViaConnectionManager() { +class CloudConnectionManager : ViaConnectionManager() { override fun isFrontEnd(conn: UserConnection): Boolean = false } @@ -168,10 +172,12 @@ object CloudConfig : AbstractViaConfig(File("config/viaversion.yml")) { override fun is1_14HitboxFix(): Boolean = false // Based on Sponge ViaVersion - private val UNSUPPORTED = listOf("anti-xray-patch", "bungee-ping-interval", - "bungee-ping-save", "bungee-servers", "quick-move-action-fix", "nms-player-ticking", - "item-cache", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", - "blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox") + private val UNSUPPORTED = listOf( + "anti-xray-patch", "bungee-ping-interval", + "bungee-ping-save", "bungee-servers", "quick-move-action-fix", "nms-player-ticking", + "item-cache", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", + "blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox" + ) init { // Load config diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt index 31b0e91..50b99f8 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaS.kt @@ -38,6 +38,8 @@ import us.myles.ViaVersion.api.command.ViaCommandSender import us.myles.ViaVersion.api.data.MappingDataLoader import us.myles.ViaVersion.api.protocol.ProtocolVersion import us.myles.ViaVersion.util.Config +import us.myles.ViaVersion.util.GsonUtil +import us.myles.viaversion.libs.gson.JsonObject import java.io.File import java.net.InetAddress import java.security.KeyPairGenerator @@ -45,6 +47,11 @@ import java.security.SecureRandom import java.util.* import java.util.concurrent.CompletableFuture +val viaaasVer = GsonUtil.getGson().fromJson( + CloudPlatform::class.java.classLoader.getResourceAsStream("viaaas_info.json")!! + .reader(Charsets.UTF_8).readText(), JsonObject::class.java +).get("version").asString + var runningServer = true val viaaasLogger = LoggerFactory.getLogger("VIAaaS") @@ -92,16 +99,23 @@ fun channelSocketFactory(): ChannelFactory { } fun main(args: Array) { + // 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"); + } + File("config/https.jks").apply { parentFile.mkdirs() if (!exists()) generateCertificate(this) } - Via.init(ViaManager.builder() + Via.init( + ViaManager.builder() .injector(CloudInjector) .loader(CloudLoader) .commandHandler(CloudCommands) - .platform(CloudPlatform).build()) + .platform(CloudPlatform).build() + ) MappingDataLoader.enableMappingsCache() Via.getManager().init() CloudRewind.init(ViaRewindConfigImpl(File("config/viarewind.yml"))) @@ -111,12 +125,12 @@ fun main(args: Array) { val child = eventLoopGroup() val future = ServerBootstrap() - .group(parent, child) - .channelFactory(channelServerSocketFactory()) - .childHandler(ChannelInit) - .childOption(ChannelOption.IP_TOS, 0x18) - .childOption(ChannelOption.TCP_NODELAY, true) - .bind(InetAddress.getByName(VIAaaSConfig.bindAddress), VIAaaSConfig.port) + .group(parent, child) + .channelFactory(channelServerSocketFactory()) + .childHandler(ChannelInit) + .childOption(ChannelOption.IP_TOS, 0x18) + .childOption(ChannelOption.TCP_NODELAY, true) + .bind(InetAddress.getByName(VIAaaSConfig.bindAddress), VIAaaSConfig.port) var ktorServer: NettyApplicationEngine? = null try { @@ -136,7 +150,7 @@ fun main(args: Array) { ktorServer?.stop(1000, 1000) httpClient.close() listOf>(future.channel().close(), parent.shutdownGracefully(), child.shutdownGracefully()) - .forEach { it.sync() } + .forEach { it.sync() } Via.getManager().destroy() } @@ -157,21 +171,29 @@ class VIAaaSConsole : SimpleTerminalConsole(), ViaCommandSender { } commands["viaver"] = commands["viaversion"]!! commands["vvcloud"] = commands["viaversion"]!! - commands["help"] = { suggestion , _, _ -> - if (suggestion == null) sendMessage(commands.keys.toString()) + commands["help"] = { suggestion, _, _ -> + if (suggestion == null) sendMessage(commands.entries.groupBy { it.value }.entries.joinToString(", ") { + it.value.joinToString("/") { it.key } + }) } commands["?"] = commands["help"]!! + commands["ver"] = { suggestion, _, _ -> + if (suggestion == null) sendMessage(viaaasVer) + } commands["list"] = { suggestion, _, _ -> if (suggestion == null) { sendMessage("List of player connections: ") Via.getPlatform().connectionManager.connections.forEach { val pAddr = it.channel?.remoteAddress() val pVer = it.protocolInfo?.protocolVersion?.let { - ProtocolVersion.getProtocol(it)} + ProtocolVersion.getProtocol(it) + } val backName = it.protocolInfo?.username val backVer = it.protocolInfo?.serverProtocolVersion?.let { - ProtocolVersion.getProtocol(it)} - val backAddr = it.channel?.pipeline()?.get(CloudMinecraftHandler::class.java)?.other?.remoteAddress() + ProtocolVersion.getProtocol(it) + } + val backAddr = + it.channel?.pipeline()?.get(CloudMinecraftHandler::class.java)?.other?.remoteAddress() val pName = it.channel?.pipeline()?.get(CloudMinecraftHandler::class.java)?.data?.frontName sendMessage("$pAddr ($pVer) ($pName) -> ($backVer) ($backName) $backAddr") } @@ -188,7 +210,7 @@ class VIAaaSConsole : SimpleTerminalConsole(), ViaCommandSender { val args = cmdArgs.filterIndexed { i, _ -> i > 0 } if (cmdArgs.size == 1) { candidates.addAll(commands.keys.filter { it.startsWith(alias, ignoreCase = true) } - .map { Candidate(it) }) + .map { Candidate(it) }) } else { val cmd = commands[alias.toLowerCase()] if (cmd != null) { @@ -305,7 +327,7 @@ class VIAaaSAddress { realAddrPart = true } } else if (parts.filterIndexed { a, _ -> a >= i } - .joinToString(".").equals(viaHostName, ignoreCase = true)) { + .joinToString(".").equals(viaHostName, ignoreCase = true)) { foundDomain = true } if (realAddrPart) {