code cleanup

This commit is contained in:
creeper123123321 2021-02-12 17:53:02 -03:00
parent 428d47a9b9
commit d3325612a8
4 changed files with 4 additions and 6 deletions

View File

@ -19,6 +19,6 @@ class BackEndInit(val connectionData: ConnectionData) : ChannelInitializer<Chann
// compress
.addLast("via-codec", ViaCodec(user))
.addLast("mc", MinecraftCodec())
.addLast("handler", MinecraftHandler(connectionData, connectionData.frontChannel, frontEnd = false))
.addLast("handler", MinecraftHandler(connectionData, frontEnd = false))
}
}

View File

@ -19,7 +19,7 @@ object FrontEndInit : ChannelInitializer<Channel>() {
.addLast("mc", MinecraftCodec())
.addLast(
"handler", MinecraftHandler(
ConnectionData(frontChannel = ch), other = null, frontEnd = true
ConnectionData(frontChannel = ch), frontEnd = true
)
)
}

View File

@ -11,10 +11,10 @@ import java.net.SocketAddress
class MinecraftHandler(
val data: ConnectionData,
var other: Channel?,
val frontEnd: Boolean
) : SimpleChannelInboundHandler<Packet>() {
var remoteAddress: SocketAddress? = null
val other: Channel? get() = if (frontEnd) data.backChannel else data.frontChannel
override fun channelRead0(ctx: ChannelHandlerContext, packet: Packet) {
if (ctx.channel().isActive) {

View File

@ -89,9 +89,7 @@ class HandshakeState : MinecraftConnectionState {
if (it.isSuccess) {
mcLogger.info("Connected ${handler.remoteAddress} -> $socketAddr")
val backChan = future.channel() as SocketChannel
handler.data.backChannel = backChan
handler.other = backChan
handler.data.backChannel = future.channel() as SocketChannel
forward(handler, packet, true)