mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-11-21 11:55:15 +01:00
fix protocol detection when ipv6 fails
This commit is contained in:
parent
f09da91810
commit
d5931ccb7c
@ -53,6 +53,8 @@ private fun printSplash() {
|
||||
println("VIAaaS ${AspirinServer.version}")
|
||||
}
|
||||
|
||||
val autoProtocolId = -2
|
||||
|
||||
private fun initVia() {
|
||||
AspirinPlatform.initVia {
|
||||
AspirinRewind().init()
|
||||
@ -61,7 +63,7 @@ private fun initVia() {
|
||||
AspirinLegacy().init()
|
||||
}
|
||||
|
||||
ProtocolVersion.register(-2, "AUTO")
|
||||
ProtocolVersion.register(autoProtocolId, "AUTO")
|
||||
registerAspirinProtocols()
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ class ConnectionData(
|
||||
var state: ConnectionState = HandshakeState(),
|
||||
var frontVer: Int? = null,
|
||||
var backServerVer: Int? = null,
|
||||
var autoDetectProtocol: Boolean = false
|
||||
) {
|
||||
val frontHandler get() = frontChannel.pipeline()[MinecraftHandler::class.java]
|
||||
val backHandler get() = backChannel?.pipeline()?.get(MinecraftHandler::class.java)
|
||||
|
@ -8,6 +8,7 @@ import com.viaversion.aas.codec.packet.Packet
|
||||
import com.viaversion.aas.codec.packet.handshake.Handshake
|
||||
import com.viaversion.aas.config.VIAaaSConfig
|
||||
import com.viaversion.aas.handler.MinecraftHandler
|
||||
import com.viaversion.aas.autoProtocolId
|
||||
import com.viaversion.aas.mcLogger
|
||||
import com.viaversion.aas.util.AddressParser
|
||||
import com.viaversion.aas.util.StacklessException
|
||||
@ -72,7 +73,7 @@ class HandshakeState : ConnectionState {
|
||||
}
|
||||
}
|
||||
|
||||
val backProto = parsed.protocol ?: -2
|
||||
val backProto = parsed.protocol ?: autoProtocolId
|
||||
|
||||
val backAddress = parsed.serverAddress!!
|
||||
val port = parsed.port ?: VIAaaSConfig.defaultBackendPort ?: virtualPort
|
||||
@ -83,6 +84,7 @@ class HandshakeState : ConnectionState {
|
||||
val addressFromWeb = VIAaaSConfig.hostName.any { parsed.serverAddress.equals(it, ignoreCase = true) }
|
||||
|
||||
handler.data.backServerVer = backProto
|
||||
if (backProto == autoProtocolId) handler.data.autoDetectProtocol = true
|
||||
(handler.data.state as? LoginState)?.also {
|
||||
it.frontOnline = frontOnline
|
||||
it.backName = parsed.username
|
||||
|
@ -266,6 +266,7 @@ class LoginState : ConnectionState {
|
||||
val info = AspirinServer.viaWebServer.requestAddressInfo(frontName).await()
|
||||
backAddress = info.backHostAndPort
|
||||
handler.data.backServerVer = info.backVersion
|
||||
if (info.backVersion == autoProtocolId) handler.data.autoDetectProtocol = true
|
||||
frontOnline = info.frontOnline
|
||||
info.backName?.also { backName = info.backName }
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ private suspend fun createBackChannel(
|
||||
mcLogger.debug("+ {} {} -> {}", state.name[0], handler.endRemoteAddress, socketAddr)
|
||||
}
|
||||
handler.data.backChannel = channel as SocketChannel
|
||||
|
||||
|
||||
val packet = Handshake()
|
||||
packet.nextState = state
|
||||
packet.protocolId = handler.data.frontVer!!
|
||||
@ -74,7 +74,7 @@ private suspend fun createBackChannel(
|
||||
}
|
||||
|
||||
private suspend fun autoDetectVersion(handler: MinecraftHandler, socketAddr: InetSocketAddress) {
|
||||
if (handler.data.backServerVer == -2) { // Auto
|
||||
if (handler.data.autoDetectProtocol) { // Auto
|
||||
var detectedProtocol: ProtocolVersion? = null
|
||||
try {
|
||||
detectedProtocol = withTimeout(10_000) {
|
||||
@ -85,14 +85,10 @@ private suspend fun autoDetectVersion(handler: MinecraftHandler, socketAddr: Ine
|
||||
mcLogger.debug("Stacktrace: ", e)
|
||||
}
|
||||
|
||||
if (detectedProtocol != null
|
||||
handler.data.backServerVer = if (detectedProtocol != null
|
||||
&& detectedProtocol.version !in arrayOf(-1, -2)
|
||||
&& ProtocolVersion.isRegistered(detectedProtocol.version)
|
||||
) {
|
||||
handler.data.backServerVer = detectedProtocol.version
|
||||
} else {
|
||||
handler.data.backServerVer = 47 // fallback 1.8
|
||||
}
|
||||
) detectedProtocol.version else 47 // fallback 1.8
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,6 +132,7 @@ private suspend fun resolveBackendAddresses(hostAndPort: HostAndPort): List<Inet
|
||||
return when {
|
||||
removedEndDot.endsWith(".onion", ignoreCase = true) ->
|
||||
listOf(InetSocketAddress.createUnresolved(removedEndDot, srvResolved.port))
|
||||
|
||||
else -> AspirinServer.dnsResolver
|
||||
.resolveAll(srvResolved.host)
|
||||
.suspendAwait()
|
||||
|
Loading…
Reference in New Issue
Block a user