diff --git a/.gitignore b/.gitignore index 082c19d..6702f32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -gradle .idea .gradle build diff --git a/build.gradle.kts b/build.gradle.kts index 7279116..ac2a780 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,8 +23,8 @@ repositories { } dependencies { - implementation("us.myles:viaversion:3.1.0") - implementation("nl.matsv:viabackwards-all:3.1.0") + implementation("us.myles:viaversion:3.1.1-SNAPSHOT") + implementation("nl.matsv:viabackwards-all:3.1.1-SNAPSHOT") implementation("de.gerrygames:viarewind-all:1.5.1") implementation("io.netty:netty-all:4.1.51.Final") implementation(kotlin("stdlib-jdk8")) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d9b7505 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..727d0a7 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 2fe81a7..cccdd3d 100755 --- a/gradlew +++ b/gradlew @@ -1,21 +1,5 @@ #!/usr/bin/env sh -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - ############################################################################## ## ## Gradle start up script for UN*X @@ -44,7 +28,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -125,8 +109,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -154,19 +138,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=`expr $i + 1` + i=$((i+1)) done case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -175,9 +159,14 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=`save "$@"` +APP_ARGS=$(save "$@") # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 24467a1..e95643d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,19 +1,3 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -30,7 +14,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" +set DEFAULT_JVM_OPTS= @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudHandler.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudHandler.kt index 143147e..f7acb31 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudHandler.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudHandler.kt @@ -9,7 +9,9 @@ import io.netty.channel.SimpleChannelInboundHandler import us.myles.ViaVersion.api.data.UserConnection import us.myles.ViaVersion.api.type.Type import us.myles.ViaVersion.packets.State +import java.util.logging.Logger +val logger = Logger.getLogger("CloudHandler") class CloudSideForwarder(val userConnection: UserConnection, var other: Channel?) : SimpleChannelInboundHandler() { override fun channelRead0(ctx: ChannelHandlerContext, msg: ByteBuf) { @@ -18,7 +20,7 @@ class CloudSideForwarder(val userConnection: UserConnection, var other: Channel? override fun channelInactive(ctx: ChannelHandlerContext) { super.channelInactive(ctx) - println(userConnection.channel?.remoteAddress().toString() + " was disconnected") + logger.info(userConnection.channel?.remoteAddress().toString() + " was disconnected") other?.close() } @@ -41,7 +43,7 @@ class CloudSideForwarder(val userConnection: UserConnection, var other: Channel? if (userConnection.channel?.isActive != true) return val msg = "[VIAaaS] $s"; - println("Disconnecting " + userConnection.channel!!.remoteAddress() + ": " + s) + logger.info("Disconnecting " + userConnection.channel!!.remoteAddress() + ": " + s) when (userConnection.protocolInfo!!.state) { State.LOGIN -> { val packet = ByteBufAllocator.DEFAULT.buffer() diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt index 9c7e222..f6c0350 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudPlatform.kt @@ -1,8 +1,10 @@ package com.github.creeper123123321.viaaas +import de.gerrygames.viarewind.api.ViaRewindPlatform import io.netty.buffer.ByteBuf import io.netty.channel.DefaultEventLoop import io.netty.channel.socket.SocketChannel +import nl.matsv.viabackwards.api.ViaBackwardsPlatform import us.myles.ViaVersion.AbstractViaConfig import us.myles.ViaVersion.api.Via import us.myles.ViaVersion.api.ViaAPI @@ -32,6 +34,19 @@ import java.util.concurrent.Future import java.util.concurrent.TimeUnit import java.util.logging.Logger +object CloudBackwards: ViaBackwardsPlatform { + val log = Logger.getLogger("ViaBackwards") + override fun getDataFolder() = File("config/viabackwards") + override fun getLogger(): Logger = log + override fun disable() { + } +} + +object CloudRewind: ViaRewindPlatform { + val log = Logger.getLogger("ViaRewind") + override fun getLogger(): Logger = log +} + object CloudLoader : ViaPlatformLoader { override fun unload() { } @@ -40,7 +55,6 @@ object CloudLoader : ViaPlatformLoader { Via.getManager().providers.use(MovementTransmitterProvider::class.java, BungeeMovementTransmitter()) Via.getManager().providers.use(VersionProvider::class.java, CloudVersionProvider) } - } object CloudCommands : ViaCommandHandler() diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudProtocol.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudProtocol.kt index c9d06a6..1d83a4b 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/CloudProtocol.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/CloudProtocol.kt @@ -15,15 +15,17 @@ import us.myles.ViaVersion.api.type.Type import us.myles.ViaVersion.packets.State import java.net.InetAddress import java.net.InetSocketAddress +import java.util.logging.Logger class CloudHandlerProtocol : SimpleProtocol() { + val logger = Logger.getLogger("CloudHandlerProtocol") override fun registerPackets() { this.registerIncoming(State.HANDSHAKE, 0, 0, object : PacketRemapper() { override fun registerMap() { handler { wrapper: PacketWrapper -> - val protVer = wrapper.passthrough(Type.VAR_INT) + val playerVer = wrapper.passthrough(Type.VAR_INT) val addr = wrapper.passthrough(Type.STRING) // Server Address - val svPort = wrapper.passthrough(Type.UNSIGNED_SHORT) + wrapper.passthrough(Type.UNSIGNED_SHORT) val nextState = wrapper.passthrough(Type.VAR_INT) val addrParts = addr.split(0.toChar())[0].split(".") @@ -65,7 +67,7 @@ class CloudHandlerProtocol : SimpleProtocol() { } backAddr = backAddr.replace(Regex("\\.$"), "") - println("connecting ${wrapper.user().channel!!.remoteAddress()} ($protVer) to $backAddr:$port ($backProtocol)") + logger.info("connecting ${wrapper.user().channel!!.remoteAddress()} ($playerVer) to $backAddr:$port ($backProtocol)") wrapper.user().channel!!.setAutoRead(false) wrapper.user().put(CloudData( @@ -77,7 +79,7 @@ class CloudHandlerProtocol : SimpleProtocol() { Via.getPlatform().runAsync { val frontForwarder = wrapper.user().channel!!.pipeline().get(CloudSideForwarder::class.java) try { - val socketAddr = InetSocketAddress(InetAddress.getByName(backAddr), svPort) + val socketAddr = InetSocketAddress(InetAddress.getByName(backAddr), port) val addrInfo = socketAddr.address if (addrInfo.isSiteLocalAddress || addrInfo.isLoopbackAddress @@ -90,7 +92,7 @@ class CloudHandlerProtocol : SimpleProtocol() { bootstrap.addListener { if (it.isSuccess) { - println("conected ${wrapper.user().channel?.remoteAddress()} to $socketAddr") + logger.info("conected ${wrapper.user().channel?.remoteAddress()} to $socketAddr") val chann = bootstrap.channel() as SocketChannel chann.pipeline().get(CloudSideForwarder::class.java).other = wrapper.user().channel frontForwarder.other = chann @@ -98,9 +100,9 @@ class CloudHandlerProtocol : SimpleProtocol() { try { backHandshake.writeByte(0) // Packet 0 handshake val connProto = - if (ProtocolRegistry.getProtocolPath(protVer, backProtocol) != null) { + if (ProtocolRegistry.getProtocolPath(playerVer, backProtocol) != null) { backProtocol - } else protVer + } else playerVer Type.VAR_INT.writePrimitive(backHandshake, connProto) val nullPos = addr.indexOf(0.toChar()) Type.STRING.write(backHandshake, backAddr diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/ViaaaS.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/ViaaaS.kt index 52b987b..1fe3369 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/ViaaaS.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/ViaaaS.kt @@ -1,11 +1,14 @@ package com.github.creeper123123321.viaaas +import de.gerrygames.viarewind.api.ViaRewindConfigImpl import io.netty.bootstrap.ServerBootstrap import io.netty.channel.nio.NioEventLoopGroup import io.netty.channel.socket.nio.NioServerSocketChannel import us.myles.ViaVersion.ViaManager import us.myles.ViaVersion.api.Via import us.myles.ViaVersion.api.data.MappingDataLoader +import java.io.File +import kotlin.system.exitProcess fun main() { Via.init(ViaManager.builder() @@ -18,6 +21,10 @@ fun main() { Via.getManager().init() + CloudRewind.init(ViaRewindConfigImpl(File("config/viarewind.yml"))) + + CloudBackwards.init(File("config/viabackwards.yml")) + val boss = NioEventLoopGroup() val worker = NioEventLoopGroup() val future = ServerBootstrap().group(boss, worker) @@ -42,8 +49,9 @@ fun main() { } future.channel().close().sync() - boss.shutdownGracefully() - worker.shutdownGracefully() + boss.shutdownGracefully().sync() + worker.shutdownGracefully().sync() Via.getManager().destroy() + exitProcess(0) // todo what's stucking? }