This commit is contained in:
creeper123123321 2020-11-21 06:27:00 -03:00
parent 6a6bbe28d3
commit b5e00e1413

View File

@ -56,7 +56,7 @@ class CloudMinecraftHandler(val user: UserConnection,
var address: SocketAddress? = null var address: SocketAddress? = null
override fun channelRead0(ctx: ChannelHandlerContext, msg: ByteBuf) { override fun channelRead0(ctx: ChannelHandlerContext, msg: ByteBuf) {
if (ctx.channel().isActive && !user.isPendingDisconnect) { if (ctx.channel().isActive && !user.isPendingDisconnect && msg.isReadable) {
data!!.state.handleMessage(this, ctx, msg) data!!.state.handleMessage(this, ctx, msg)
if (msg.isReadable) throw IllegalStateException("Remaining bytes!!!") if (msg.isReadable) throw IllegalStateException("Remaining bytes!!!")
//other?.write(msg.retain()) //other?.write(msg.retain())
@ -369,10 +369,7 @@ object LoginState : MinecraftConnectionState {
object StatusState : MinecraftConnectionState { object StatusState : MinecraftConnectionState {
override fun handleMessage(handler: CloudMinecraftHandler, ctx: ChannelHandlerContext, msg: ByteBuf) { override fun handleMessage(handler: CloudMinecraftHandler, ctx: ChannelHandlerContext, msg: ByteBuf) {
val i = msg.readerIndex() val i = msg.readerIndex()
when (Type.VAR_INT.readPrimitive(msg)) { if (Type.VAR_INT.readPrimitive(msg) !in 0..1) throw IllegalArgumentException("Invalid packet id!")
0, 1 -> {}
else -> throw IllegalArgumentException("Invalid packet id!")
}
msg.readerIndex(i) msg.readerIndex(i)
handler.other!!.write(msg.retain()) handler.other!!.write(msg.retain())
} }
@ -395,6 +392,9 @@ object StatusState : MinecraftConnectionState {
object PlayState : MinecraftConnectionState { object PlayState : MinecraftConnectionState {
override fun handleMessage(handler: CloudMinecraftHandler, ctx: ChannelHandlerContext, msg: ByteBuf) { override fun handleMessage(handler: CloudMinecraftHandler, ctx: ChannelHandlerContext, msg: ByteBuf) {
val i = msg.readerIndex()
if (Type.VAR_INT.readPrimitive(msg) !in 0..127) throw IllegalArgumentException("Invalid packet id!")
msg.readerIndex(i)
handler.other!!.write(msg.retain()) handler.other!!.write(msg.retain())
} }