fix -1 (disable viaversion) cases

This commit is contained in:
creeper123123321 2024-03-07 10:19:19 -03:00
parent ed24df38a8
commit 89f8295e0a
4 changed files with 7 additions and 16 deletions

View File

@ -117,10 +117,7 @@ public class AddressParser {
if (protocolId == null) { if (protocolId == null) {
protocol = ProtocolVersion.getClosest(arg.replace("_", ".")); protocol = ProtocolVersion.getClosest(arg.replace("_", "."));
} else { } else {
final ProtocolVersion ver = ProtocolVersion.getProtocol(protocolId); protocol = ProtocolVersion.getProtocol(protocolId);
if (ver.isKnown()) {
protocol = ver;
}
} }
} }
} }

View File

@ -48,9 +48,8 @@ class HandshakeState : ConnectionState {
} }
private fun handleNextState(handler: MinecraftHandler, packet: Handshake) { private fun handleNextState(handler: MinecraftHandler, packet: Handshake) {
ProtocolVersion.getProtocol(packet.protocolId).apply { handler.data.frontVer = ProtocolVersion.getProtocol(packet.protocolId)
if (this.isKnown) handler.data.frontVer = this
}
when (packet.nextState.ordinal) { when (packet.nextState.ordinal) {
1 -> handler.data.state = StatusState() 1 -> handler.data.state = StatusState()
2 -> handler.data.state = LoginState() 2 -> handler.data.state = LoginState()
@ -87,7 +86,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 == AUTO) handler.data.autoDetectProtocol = true handler.data.autoDetectProtocol = backProto == AUTO
(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

View File

@ -269,7 +269,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 == AUTO) handler.data.autoDetectProtocol = true handler.data.autoDetectProtocol = info.backVersion == AUTO
frontOnline = info.frontOnline frontOnline = info.frontOnline
info.backName?.also { backName = info.backName } info.backName?.also { backName = info.backName }
} }

View File

@ -148,13 +148,8 @@ class WebLogin : WebState {
webClient.server.addressCallbacks[callback].complete( webClient.server.addressCallbacks[callback].complete(
AddressInfo( AddressInfo(
backVersion = obj["version"].asString.let { backVersion = obj["version"].asString.let {
val number = Ints.tryParse(it) Ints.tryParse(it)?.let { ProtocolVersion.getProtocol(it) }
val protocol = if (number == null) { ?: ProtocolVersion.getClosest(it) ?: AUTO
ProtocolVersion.getClosest(it)
} else {
ProtocolVersion.getProtocol(number)
} ?: AUTO
if (!protocol.isKnown) AUTO else protocol
}, },
backHostAndPort = HostAndPort.fromParts(obj["host"].asString, obj["port"].asInt), backHostAndPort = HostAndPort.fromParts(obj["host"].asString, obj["port"].asInt),
frontOnline = obj["frontOnline"].asString.toBooleanStrictOrNull(), frontOnline = obj["frontOnline"].asString.toBooleanStrictOrNull(),