mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2025-01-09 19:48:37 +01:00
fix backend address with non socks5 proxy
This commit is contained in:
parent
8da87cb070
commit
61cd7b0b44
@ -7,7 +7,7 @@ import com.viaversion.viaversion.exception.CancelCodecException
|
||||
import io.netty.channel.Channel
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import io.netty.channel.SimpleChannelInboundHandler
|
||||
import io.netty.handler.proxy.Socks5ProxyHandler
|
||||
import io.netty.handler.proxy.ProxyHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
@ -24,13 +24,12 @@ class MinecraftHandler(
|
||||
val coroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
|
||||
override fun channelRead0(ctx: ChannelHandlerContext, packet: Packet) {
|
||||
if (ctx.channel().isActive) {
|
||||
data.state.handlePacket(this, ctx, packet)
|
||||
}
|
||||
if (!ctx.channel().isActive) return
|
||||
data.state.handlePacket(this, ctx, packet)
|
||||
}
|
||||
|
||||
override fun channelActive(ctx: ChannelHandlerContext) {
|
||||
endRemoteAddress = ctx.channel().pipeline().get(Socks5ProxyHandler::class.java)?.destinationAddress()
|
||||
endRemoteAddress = (ctx.channel().pipeline().get("proxy") as? ProxyHandler)?.destinationAddress()
|
||||
?: ctx.channel().remoteAddress()
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.viaversion.aas.handler
|
||||
|
||||
import com.viaversion.aas.AspirinServer
|
||||
import com.viaversion.aas.config.VIAaaSConfig
|
||||
import com.viaversion.aas.codec.packet.Packet
|
||||
import com.viaversion.aas.config.VIAaaSConfig
|
||||
import com.viaversion.aas.readRemainingBytes
|
||||
import com.viaversion.aas.send
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
|
||||
@ -27,11 +27,13 @@ fun addProxyHandler(pipe: ChannelPipeline) {
|
||||
val socket = InetSocketAddress(AspirinServer.dnsResolver.resolve(proxyUri.host).get(), proxyUri.port)
|
||||
val user = proxyUri.userInfo?.substringBefore(':')
|
||||
val pass = proxyUri.userInfo?.substringAfter(':')
|
||||
when (proxyUri.scheme) {
|
||||
"socks5" -> pipe.addFirst(Socks5ProxyHandler(socket, user, pass))
|
||||
"socks4" -> pipe.addFirst(Socks4ProxyHandler(socket, user))
|
||||
"http" -> pipe.addFirst(if (user != null) HttpProxyHandler(socket, user, pass) else HttpProxyHandler(socket))
|
||||
val handler = when (proxyUri.scheme) {
|
||||
"socks5" -> Socks5ProxyHandler(socket, user, pass)
|
||||
"socks4" -> Socks4ProxyHandler(socket, user)
|
||||
"http" -> if (user != null) HttpProxyHandler(socket, user, pass) else HttpProxyHandler(socket)
|
||||
else -> null
|
||||
}
|
||||
if (handler != null) pipe.addFirst("proxy", handler)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user