some sanity check when reading packet

This commit is contained in:
creeper123123321 2021-06-08 21:46:49 -03:00
parent 52392d6ed9
commit 88bfd40a9b
4 changed files with 11 additions and 12 deletions

View File

@ -3,6 +3,7 @@ package com.viaversion.aas.codec.packet.handshake
import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.protocol.packet.State
import com.viaversion.viaversion.api.type.Type
import com.viaversion.viaversion.api.type.types.StringType
import io.netty.buffer.ByteBuf
import kotlin.properties.Delegates
@ -14,7 +15,7 @@ class Handshake : Packet {
override fun decode(byteBuf: ByteBuf, protocolVersion: Int) {
protocolId = Type.VAR_INT.readPrimitive(byteBuf)
address = Type.STRING.read(byteBuf)
address = StringType(255).read(byteBuf)
port = byteBuf.readUnsignedShort()
nextState = State.values()[Type.VAR_INT.readPrimitive(byteBuf)]
}

View File

@ -2,13 +2,14 @@ package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.type.Type
import com.viaversion.viaversion.api.type.types.StringType
import io.netty.buffer.ByteBuf
class LoginStart : Packet {
lateinit var username: String
override fun decode(byteBuf: ByteBuf, protocolVersion: Int) {
username = Type.STRING.read(byteBuf)
username = StringType(16).read(byteBuf)
}
override fun encode(byteBuf: ByteBuf, protocolVersion: Int) {

View File

@ -158,7 +158,6 @@ class LoginState : MinecraftConnectionState {
}
fun handleLoginStart(handler: MinecraftHandler, loginStart: LoginStart) {
if (loginStart.username.length > 16) throw badLength
if (started) throw StacklessException("Login already started")
started = true

View File

@ -26,17 +26,15 @@ class Chunk1_8to1_7_6_10(
filteredChunks.forEach {
val blockIds = it.blockLSBArray
val nibblearray = it.metadataArray
for (ind in blockIds.indices) {
val id = blockIds[ind].toInt() and 255
val px = ind and 15
val py = ind.shr(8).and(15)
val pz = ind.shr(4).and(15)
val data = nibblearray[px, py, pz].toInt()
for (iBlock in blockIds.indices) {
val id = blockIds[iBlock].toInt() and 0xFF
val x = iBlock and 0xF
val y = iBlock.shr(8).and(0xF)
val z = iBlock.shr(4).and(0xF)
val data = nibblearray[x, y, z].toInt()
//data = SpigotDebreakifier.getCorrectedData(id, data);
val `val` = (id shl 4 or data).toChar()
buf.writeByte(`val`.toInt() and 255)
buf.writeByte(`val`.toInt().shr(8).and(255))
buf.writeShortLE(id.shl(4).or(data))
}
}
filteredChunks.forEach {