mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2025-01-19 21:11:30 +01:00
0.1.1, steal code from velocity
This commit is contained in:
parent
3344fca1c8
commit
686a6344af
@ -18,7 +18,7 @@ java {
|
||||
val gitVersion: groovy.lang.Closure<String> by extra
|
||||
|
||||
group = "com.github.creeper123123321.viaaas"
|
||||
version = "0.1.0-SNAPSHOT+" + try {
|
||||
version = "0.1.1-SNAPSHOT+" + try {
|
||||
gitVersion()
|
||||
} catch (e: Exception) {
|
||||
"unknown"
|
||||
|
@ -19,7 +19,6 @@ import java.util.zip.Deflater
|
||||
import java.util.zip.Inflater
|
||||
import javax.crypto.Cipher
|
||||
|
||||
|
||||
object ChannelInit : ChannelInitializer<Channel>() {
|
||||
override fun initChannel(ch: Channel) {
|
||||
ch.pipeline().addLast("timeout", ReadTimeoutHandler(30, TimeUnit.SECONDS))
|
||||
@ -27,9 +26,13 @@ object ChannelInit : ChannelInitializer<Channel>() {
|
||||
.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<ByteBuf,
|
||||
inflater.setInput(input.nioBuffer())
|
||||
val output = ctx.alloc().buffer(outLength, outLength)
|
||||
try {
|
||||
output.writerIndex(output.writerIndex() + inflater.inflate(
|
||||
output.nioBuffer(output.writerIndex(), output.writableBytes())))
|
||||
output.writerIndex(
|
||||
output.writerIndex() + inflater.inflate(
|
||||
output.nioBuffer(output.writerIndex(), output.writableBytes())
|
||||
)
|
||||
)
|
||||
out.add(output.retain())
|
||||
} finally {
|
||||
inflater.reset()
|
||||
|
@ -34,7 +34,7 @@ import javax.crypto.spec.SecretKeySpec
|
||||
import javax.naming.NameNotFoundException
|
||||
import javax.naming.directory.InitialDirContext
|
||||
|
||||
val chLogger = LoggerFactory.getLogger("VIAaaS MC Handler")
|
||||
val mcLogger = LoggerFactory.getLogger("VIAaaS MC")
|
||||
|
||||
class ConnectionData(
|
||||
val frontChannel: Channel,
|
||||
@ -90,7 +90,7 @@ class CloudMinecraftHandler(
|
||||
override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {
|
||||
if (cause is CancelCodecException) return
|
||||
disconnect("Exception: $cause")
|
||||
chLogger.debug("Exception: ", cause)
|
||||
mcLogger.debug("Exception: ", cause)
|
||||
}
|
||||
|
||||
fun disconnect(s: String) {
|
||||
@ -105,11 +105,11 @@ interface MinecraftConnectionState {
|
||||
)
|
||||
|
||||
fun disconnect(handler: CloudMinecraftHandler, msg: String) {
|
||||
chLogger.info("Disconnected ${handler.remoteAddress}: $msg")
|
||||
mcLogger.info("Disconnected ${handler.remoteAddress}: $msg")
|
||||
}
|
||||
|
||||
fun onInactivated(handler: CloudMinecraftHandler) {
|
||||
chLogger.info(handler.remoteAddress?.toString() + " inactivated")
|
||||
mcLogger.info(handler.remoteAddress?.toString() + " inactivated")
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ class HandshakeState : MinecraftConnectionState {
|
||||
handler.data.backName = parsed.altUsername
|
||||
|
||||
val playerAddr = handler.data.frontHandler.remoteAddress
|
||||
chLogger.info("Connecting $playerAddr (${handler.data.frontVer}) -> ${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
|
||||
|
@ -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<Unit>(title, health, color, style)
|
||||
class CloudBossBar(title: String, health: Float, style: BossStyle, color: BossColor) :
|
||||
CommonBoss<Unit>(title, health, color, style)
|
||||
|
||||
object CloudAPI : ViaAPI<Unit> {
|
||||
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<Unit> {
|
||||
|
||||
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<Unit> {
|
||||
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
|
||||
|
@ -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<SocketChannel> {
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
// 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<String>) {
|
||||
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<String>) {
|
||||
ktorServer?.stop(1000, 1000)
|
||||
httpClient.close()
|
||||
listOf<Future<*>>(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) {
|
||||
|
Loading…
Reference in New Issue
Block a user