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