some fixes, viarewind and viabackwards

This commit is contained in:
creeper123123321 2020-08-16 19:07:17 -03:00
parent e3295abc6d
commit 51aac3b302
10 changed files with 66 additions and 63 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
gradle
.idea .idea
.gradle .gradle
build build

View File

@ -23,8 +23,8 @@ repositories {
} }
dependencies { dependencies {
implementation("us.myles:viaversion:3.1.0") implementation("us.myles:viaversion:3.1.1-SNAPSHOT")
implementation("nl.matsv:viabackwards-all:3.1.0") implementation("nl.matsv:viabackwards-all:3.1.1-SNAPSHOT")
implementation("de.gerrygames:viarewind-all:1.5.1") implementation("de.gerrygames:viarewind-all:1.5.1")
implementation("io.netty:netty-all:4.1.51.Final") implementation("io.netty:netty-all:4.1.51.Final")
implementation(kotlin("stdlib-jdk8")) implementation(kotlin("stdlib-jdk8"))

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

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

51
gradlew vendored
View File

@ -1,21 +1,5 @@
#!/usr/bin/env sh #!/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 ## Gradle start up script for UN*X
@ -44,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"` 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. # 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. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum" 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\"" GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi fi
# For Cygwin or MSYS, switch paths to Windows format before running java # For Cygwin, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
@ -154,19 +138,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else else
eval `echo args$i`="\"$arg\"" eval `echo args$i`="\"$arg\""
fi fi
i=`expr $i + 1` i=$((i+1))
done done
case $i in case $i in
0) set -- ;; (0) set -- ;;
1) set -- "$args0" ;; (1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;; (2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;; (3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
@ -175,9 +159,14 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " " echo " "
} }
APP_ARGS=`save "$@"` APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules # 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" 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" "$@" exec "$JAVACMD" "$@"

18
gradlew.bat vendored
View File

@ -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 @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@ -30,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% 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. @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 @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome

View File

@ -9,7 +9,9 @@ import io.netty.channel.SimpleChannelInboundHandler
import us.myles.ViaVersion.api.data.UserConnection import us.myles.ViaVersion.api.data.UserConnection
import us.myles.ViaVersion.api.type.Type import us.myles.ViaVersion.api.type.Type
import us.myles.ViaVersion.packets.State 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<ByteBuf>() { class CloudSideForwarder(val userConnection: UserConnection, var other: Channel?) : SimpleChannelInboundHandler<ByteBuf>() {
override fun channelRead0(ctx: ChannelHandlerContext, msg: ByteBuf) { override fun channelRead0(ctx: ChannelHandlerContext, msg: ByteBuf) {
@ -18,7 +20,7 @@ class CloudSideForwarder(val userConnection: UserConnection, var other: Channel?
override fun channelInactive(ctx: ChannelHandlerContext) { override fun channelInactive(ctx: ChannelHandlerContext) {
super.channelInactive(ctx) super.channelInactive(ctx)
println(userConnection.channel?.remoteAddress().toString() + " was disconnected") logger.info(userConnection.channel?.remoteAddress().toString() + " was disconnected")
other?.close() other?.close()
} }
@ -41,7 +43,7 @@ class CloudSideForwarder(val userConnection: UserConnection, var other: Channel?
if (userConnection.channel?.isActive != true) return if (userConnection.channel?.isActive != true) return
val msg = "[VIAaaS] $s"; val msg = "[VIAaaS] $s";
println("Disconnecting " + userConnection.channel!!.remoteAddress() + ": " + s) logger.info("Disconnecting " + userConnection.channel!!.remoteAddress() + ": " + s)
when (userConnection.protocolInfo!!.state) { when (userConnection.protocolInfo!!.state) {
State.LOGIN -> { State.LOGIN -> {
val packet = ByteBufAllocator.DEFAULT.buffer() val packet = ByteBufAllocator.DEFAULT.buffer()

View File

@ -1,8 +1,10 @@
package com.github.creeper123123321.viaaas package com.github.creeper123123321.viaaas
import de.gerrygames.viarewind.api.ViaRewindPlatform
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import io.netty.channel.DefaultEventLoop import io.netty.channel.DefaultEventLoop
import io.netty.channel.socket.SocketChannel import io.netty.channel.socket.SocketChannel
import nl.matsv.viabackwards.api.ViaBackwardsPlatform
import us.myles.ViaVersion.AbstractViaConfig import us.myles.ViaVersion.AbstractViaConfig
import us.myles.ViaVersion.api.Via import us.myles.ViaVersion.api.Via
import us.myles.ViaVersion.api.ViaAPI import us.myles.ViaVersion.api.ViaAPI
@ -32,6 +34,19 @@ import java.util.concurrent.Future
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import java.util.logging.Logger 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 { object CloudLoader : ViaPlatformLoader {
override fun unload() { override fun unload() {
} }
@ -40,7 +55,6 @@ object CloudLoader : ViaPlatformLoader {
Via.getManager().providers.use(MovementTransmitterProvider::class.java, BungeeMovementTransmitter()) Via.getManager().providers.use(MovementTransmitterProvider::class.java, BungeeMovementTransmitter())
Via.getManager().providers.use(VersionProvider::class.java, CloudVersionProvider) Via.getManager().providers.use(VersionProvider::class.java, CloudVersionProvider)
} }
} }
object CloudCommands : ViaCommandHandler() object CloudCommands : ViaCommandHandler()

View File

@ -15,15 +15,17 @@ import us.myles.ViaVersion.api.type.Type
import us.myles.ViaVersion.packets.State import us.myles.ViaVersion.packets.State
import java.net.InetAddress import java.net.InetAddress
import java.net.InetSocketAddress import java.net.InetSocketAddress
import java.util.logging.Logger
class CloudHandlerProtocol : SimpleProtocol() { class CloudHandlerProtocol : SimpleProtocol() {
val logger = Logger.getLogger("CloudHandlerProtocol")
override fun registerPackets() { override fun registerPackets() {
this.registerIncoming(State.HANDSHAKE, 0, 0, object : PacketRemapper() { this.registerIncoming(State.HANDSHAKE, 0, 0, object : PacketRemapper() {
override fun registerMap() { override fun registerMap() {
handler { wrapper: PacketWrapper -> 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 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 nextState = wrapper.passthrough(Type.VAR_INT)
val addrParts = addr.split(0.toChar())[0].split(".") val addrParts = addr.split(0.toChar())[0].split(".")
@ -65,7 +67,7 @@ class CloudHandlerProtocol : SimpleProtocol() {
} }
backAddr = backAddr.replace(Regex("\\.$"), "") 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().channel!!.setAutoRead(false)
wrapper.user().put(CloudData( wrapper.user().put(CloudData(
@ -77,7 +79,7 @@ class CloudHandlerProtocol : SimpleProtocol() {
Via.getPlatform().runAsync { Via.getPlatform().runAsync {
val frontForwarder = wrapper.user().channel!!.pipeline().get(CloudSideForwarder::class.java) val frontForwarder = wrapper.user().channel!!.pipeline().get(CloudSideForwarder::class.java)
try { try {
val socketAddr = InetSocketAddress(InetAddress.getByName(backAddr), svPort) val socketAddr = InetSocketAddress(InetAddress.getByName(backAddr), port)
val addrInfo = socketAddr.address val addrInfo = socketAddr.address
if (addrInfo.isSiteLocalAddress if (addrInfo.isSiteLocalAddress
|| addrInfo.isLoopbackAddress || addrInfo.isLoopbackAddress
@ -90,7 +92,7 @@ class CloudHandlerProtocol : SimpleProtocol() {
bootstrap.addListener { bootstrap.addListener {
if (it.isSuccess) { 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 val chann = bootstrap.channel() as SocketChannel
chann.pipeline().get(CloudSideForwarder::class.java).other = wrapper.user().channel chann.pipeline().get(CloudSideForwarder::class.java).other = wrapper.user().channel
frontForwarder.other = chann frontForwarder.other = chann
@ -98,9 +100,9 @@ class CloudHandlerProtocol : SimpleProtocol() {
try { try {
backHandshake.writeByte(0) // Packet 0 handshake backHandshake.writeByte(0) // Packet 0 handshake
val connProto = val connProto =
if (ProtocolRegistry.getProtocolPath(protVer, backProtocol) != null) { if (ProtocolRegistry.getProtocolPath(playerVer, backProtocol) != null) {
backProtocol backProtocol
} else protVer } else playerVer
Type.VAR_INT.writePrimitive(backHandshake, connProto) Type.VAR_INT.writePrimitive(backHandshake, connProto)
val nullPos = addr.indexOf(0.toChar()) val nullPos = addr.indexOf(0.toChar())
Type.STRING.write(backHandshake, backAddr Type.STRING.write(backHandshake, backAddr

View File

@ -1,11 +1,14 @@
package com.github.creeper123123321.viaaas package com.github.creeper123123321.viaaas
import de.gerrygames.viarewind.api.ViaRewindConfigImpl
import io.netty.bootstrap.ServerBootstrap import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.nio.NioEventLoopGroup import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.nio.NioServerSocketChannel import io.netty.channel.socket.nio.NioServerSocketChannel
import us.myles.ViaVersion.ViaManager import us.myles.ViaVersion.ViaManager
import us.myles.ViaVersion.api.Via import us.myles.ViaVersion.api.Via
import us.myles.ViaVersion.api.data.MappingDataLoader import us.myles.ViaVersion.api.data.MappingDataLoader
import java.io.File
import kotlin.system.exitProcess
fun main() { fun main() {
Via.init(ViaManager.builder() Via.init(ViaManager.builder()
@ -18,6 +21,10 @@ fun main() {
Via.getManager().init() Via.getManager().init()
CloudRewind.init(ViaRewindConfigImpl(File("config/viarewind.yml")))
CloudBackwards.init(File("config/viabackwards.yml"))
val boss = NioEventLoopGroup() val boss = NioEventLoopGroup()
val worker = NioEventLoopGroup() val worker = NioEventLoopGroup()
val future = ServerBootstrap().group(boss, worker) val future = ServerBootstrap().group(boss, worker)
@ -42,8 +49,9 @@ fun main() {
} }
future.channel().close().sync() future.channel().close().sync()
boss.shutdownGracefully() boss.shutdownGracefully().sync()
worker.shutdownGracefully() worker.shutdownGracefully().sync()
Via.getManager().destroy() Via.getManager().destroy()
exitProcess(0) // todo what's stucking?
} }