minor cleanup

This commit is contained in:
creeper123123321 2021-05-14 08:21:11 -03:00
parent 64083ea4f3
commit 75e899168e
33 changed files with 72 additions and 79 deletions

View File

@ -1,23 +1,23 @@
package com.viaversion.aas.codec package com.viaversion.aas.codec
import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.DecoderException
import io.netty.handler.codec.MessageToMessageCodec import io.netty.handler.codec.MessageToMessageCodec
import java.util.zip.Deflater import java.util.zip.Deflater
import java.util.zip.Inflater import java.util.zip.Inflater
class CompressionCodec(val threshold: Int) : MessageToMessageCodec<ByteBuf, ByteBuf>() { class CompressionCodec(val threshold: Int) : MessageToMessageCodec<ByteBuf, ByteBuf>() {
// https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/netty/CompressionEncoder.java // https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/netty/CompressionEncoder.java
private val inflater: Inflater = private val inflater: Inflater = Inflater()
Inflater()// https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/netty/CompressionEncoder.java
private val deflater: Deflater = Deflater() private val deflater: Deflater = Deflater()
@Throws(Exception::class) @Throws(Exception::class)
override fun encode(ctx: ChannelHandlerContext, input: ByteBuf, out: MutableList<Any>) { override fun encode(ctx: ChannelHandlerContext, input: ByteBuf, out: MutableList<Any>) {
val frameLength = input.readableBytes() val frameLength = input.readableBytes()
val outBuf = ctx.alloc().buffer() val outBuf = ctx.alloc().buffer()
outBuf.skipBytes(5) // reserve varint
try { try {
if (frameLength < threshold) { if (frameLength < threshold) {
outBuf.writeByte(0) outBuf.writeByte(0)
@ -50,19 +50,17 @@ class CompressionCodec(val threshold: Int) : MessageToMessageCodec<ByteBuf, Byte
} }
if (outLength < threshold) { if (outLength < threshold) {
throw DecoderException("Badly compressed packet - size of $outLength is below server threshold of $threshold") throw StacklessException("Badly compressed packet - size of $outLength is below server threshold of $threshold")
} }
if (outLength > 2097152) { if (outLength > 2097152) {
throw DecoderException("Badly compressed packet - size of $outLength is larger than protocol maximum of 2097152") throw StacklessException("Badly compressed packet - size of $outLength is larger than protocol maximum of 2097152")
} }
inflater.setInput(input.nioBuffer()) inflater.setInput(input.nioBuffer())
val output = ctx.alloc().buffer(outLength, outLength) val output = ctx.alloc().buffer(outLength, outLength)
try { try {
output.writerIndex( output.writerIndex(
output.writerIndex() + inflater.inflate( output.writerIndex() + inflater.inflate(output.nioBuffer(output.writerIndex(), output.writableBytes()))
output.nioBuffer(output.writerIndex(), output.writableBytes())
)
) )
out.add(output.retain()) out.add(output.retain())
} finally { } finally {

View File

@ -1,8 +1,8 @@
package com.viaversion.aas.codec package com.viaversion.aas.codec
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.packet.PacketRegistry import com.viaversion.aas.codec.packet.PacketRegistry
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.Direction import com.viaversion.viaversion.api.protocol.packet.Direction
import com.viaversion.viaversion.exception.CancelEncoderException import com.viaversion.viaversion.exception.CancelEncoderException

View File

@ -1,4 +1,4 @@
package com.viaversion.aas.packet package com.viaversion.aas.codec.packet
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,14 +1,14 @@
package com.viaversion.aas.packet package com.viaversion.aas.codec.packet
import com.google.common.collect.Range import com.google.common.collect.Range
import com.viaversion.aas.packet.handshake.Handshake import com.viaversion.aas.codec.packet.handshake.Handshake
import com.viaversion.aas.packet.login.* import com.viaversion.aas.codec.packet.login.*
import com.viaversion.aas.packet.play.Kick import com.viaversion.aas.codec.packet.play.Kick
import com.viaversion.aas.packet.play.PluginMessage import com.viaversion.aas.codec.packet.play.PluginMessage
import com.viaversion.aas.packet.status.StatusPing import com.viaversion.aas.codec.packet.status.StatusPing
import com.viaversion.aas.packet.status.StatusPong import com.viaversion.aas.codec.packet.status.StatusPong
import com.viaversion.aas.packet.status.StatusRequest import com.viaversion.aas.codec.packet.status.StatusRequest
import com.viaversion.aas.packet.status.StatusResponse import com.viaversion.aas.codec.packet.status.StatusResponse
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.Direction import com.viaversion.viaversion.api.protocol.packet.Direction
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State

View File

@ -1,4 +1,4 @@
package com.viaversion.aas.packet package com.viaversion.aas.codec.packet
import com.viaversion.aas.readRemainingBytes import com.viaversion.aas.readRemainingBytes
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.handshake package com.viaversion.aas.codec.packet.handshake
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.login package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.readByteArray import com.viaversion.aas.readByteArray
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.login package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.readByteArray import com.viaversion.aas.readByteArray
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.login package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.login package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.login package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.parseUndashedId import com.viaversion.aas.parseUndashedId
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.login package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.readRemainingBytes import com.viaversion.aas.readRemainingBytes
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.login package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.readRemainingBytes import com.viaversion.aas.readRemainingBytes
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.login package com.viaversion.aas.codec.packet.login
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import kotlin.properties.Delegates import kotlin.properties.Delegates

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.play package com.viaversion.aas.codec.packet.play
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.play package com.viaversion.aas.codec.packet.play
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.readByteArray import com.viaversion.aas.readByteArray
import com.viaversion.aas.readRemainingBytes import com.viaversion.aas.readRemainingBytes
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import com.viaversion.viaversion.api.protocol.version.ProtocolVersion

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.status package com.viaversion.aas.codec.packet.status
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import kotlin.properties.Delegates import kotlin.properties.Delegates

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.status package com.viaversion.aas.codec.packet.status
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import kotlin.properties.Delegates import kotlin.properties.Delegates

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.status package com.viaversion.aas.codec.packet.status
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
class StatusRequest : Packet { class StatusRequest : Packet {

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.packet.status package com.viaversion.aas.codec.packet.status
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf

View File

@ -1,7 +1,7 @@
package com.viaversion.aas.handler package com.viaversion.aas.handler
import com.viaversion.aas.mcLogger import com.viaversion.aas.mcLogger
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.setAutoRead import com.viaversion.aas.setAutoRead
import com.viaversion.viaversion.exception.CancelCodecException import com.viaversion.viaversion.exception.CancelCodecException
import io.netty.channel.Channel import io.netty.channel.Channel

View File

@ -1,7 +1,7 @@
package com.viaversion.aas.handler package com.viaversion.aas.handler
import com.viaversion.aas.config.VIAaaSConfig import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.send import com.viaversion.aas.send
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import io.netty.channel.ChannelPipeline import io.netty.channel.ChannelPipeline

View File

@ -4,8 +4,8 @@ import com.google.gson.JsonParser
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.handler.state.MinecraftConnectionState import com.viaversion.aas.handler.state.MinecraftConnectionState
import com.viaversion.aas.mcLogger import com.viaversion.aas.mcLogger
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.packet.status.StatusResponse import com.viaversion.aas.codec.packet.status.StatusResponse
import com.viaversion.aas.parseProtocol import com.viaversion.aas.parseProtocol
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State

View File

@ -10,8 +10,8 @@ import com.viaversion.aas.handler.ConnectionData
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.handler.addSocks5 import com.viaversion.aas.handler.addSocks5
import com.viaversion.aas.mcLogger import com.viaversion.aas.mcLogger
import com.viaversion.aas.packet.handshake.Handshake import com.viaversion.aas.codec.packet.handshake.Handshake
import com.viaversion.aas.packet.status.StatusRequest import com.viaversion.aas.codec.packet.status.StatusRequest
import com.viaversion.aas.send import com.viaversion.aas.send
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import com.viaversion.viaversion.api.protocol.version.ProtocolVersion

View File

@ -8,8 +8,8 @@ import com.viaversion.aas.VIAaaSAddress
import com.viaversion.aas.config.VIAaaSConfig import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.mcLogger import com.viaversion.aas.mcLogger
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.packet.handshake.Handshake import com.viaversion.aas.codec.packet.handshake.Handshake
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelHandlerContext

View File

@ -7,8 +7,8 @@ import com.viaversion.aas.codec.CompressionCodec
import com.viaversion.aas.codec.CryptoCodec import com.viaversion.aas.codec.CryptoCodec
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.handler.forward import com.viaversion.aas.handler.forward
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.packet.login.* import com.viaversion.aas.codec.packet.login.*
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
import io.netty.channel.Channel import io.netty.channel.Channel

View File

@ -2,7 +2,7 @@ package com.viaversion.aas.handler.state
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.mcLogger import com.viaversion.aas.mcLogger
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelHandlerContext

View File

@ -5,10 +5,10 @@ import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.handler.forward import com.viaversion.aas.handler.forward
import com.viaversion.aas.handler.is1_7 import com.viaversion.aas.handler.is1_7
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.packet.UnknownPacket import com.viaversion.aas.codec.packet.UnknownPacket
import com.viaversion.aas.packet.play.Kick import com.viaversion.aas.codec.packet.play.Kick
import com.viaversion.aas.packet.play.PluginMessage import com.viaversion.aas.codec.packet.play.PluginMessage
import com.viaversion.aas.parseProtocol import com.viaversion.aas.parseProtocol
import com.viaversion.aas.readRemainingBytes import com.viaversion.aas.readRemainingBytes
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException

View File

@ -6,9 +6,9 @@ import com.google.gson.JsonParser
import com.viaversion.aas.config.VIAaaSConfig import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.handler.forward import com.viaversion.aas.handler.forward
import com.viaversion.aas.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.packet.UnknownPacket import com.viaversion.aas.codec.packet.UnknownPacket
import com.viaversion.aas.packet.status.StatusResponse import com.viaversion.aas.codec.packet.status.StatusResponse
import com.viaversion.aas.parseProtocol import com.viaversion.aas.parseProtocol
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.aas.writeFlushClose import com.viaversion.aas.writeFlushClose

View File

@ -6,7 +6,7 @@ import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.BackEndInit import com.viaversion.aas.handler.BackEndInit
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.handler.forward import com.viaversion.aas.handler.forward
import com.viaversion.aas.packet.handshake.Handshake import com.viaversion.aas.codec.packet.handshake.Handshake
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
import io.netty.bootstrap.Bootstrap import io.netty.bootstrap.Bootstrap

View File

@ -5,7 +5,6 @@ import io.netty.buffer.ByteBuf
import java.util.* import java.util.*
object AspirinViaAPI : ViaAPIBase<UUID>() { object AspirinViaAPI : ViaAPIBase<UUID>() {
override fun getPlayerVersion(p0: UUID): Int = super.getPlayerVersion(p0)
override fun sendRawPacket(p0: UUID, p1: ByteBuf) = super.sendRawPacket(p0, p1) override fun sendRawPacket(p0: UUID, p1: ByteBuf) = super.sendRawPacket(p0, p1)
override fun getPlayerVersion(p0: UUID?): Int = throw UnsupportedOperationException()
} }

View File

@ -7,7 +7,7 @@ import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol
// Based on https://github.com/Gerrygames/ClientViaVersion // Based on https://github.com/Gerrygames/ClientViaVersion
object Protocol1_8To1_7_6 : AbstractSimpleProtocol() { object Protocol1_8To1_7_6 : AbstractSimpleProtocol() {
private val placeable = ArrayList<Int>() private val placeable = hashSetOf<Int>()
init { init {
placeable.add(6) placeable.add(6)

View File

@ -5,9 +5,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper
import com.viaversion.viaversion.api.type.Type import com.viaversion.viaversion.api.type.Type
import com.viaversion.viaversion.api.type.types.CustomByteType import com.viaversion.viaversion.api.type.types.CustomByteType
import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl
import java.io.IOException
import java.util.stream.IntStream import java.util.stream.IntStream
import java.util.zip.DataFormatException
import java.util.zip.Inflater import java.util.zip.Inflater
import kotlin.streams.toList import kotlin.streams.toList
@ -72,8 +70,6 @@ object ChunkPacketTransformer {
inflater.setInput(buildBuffer, 0, compressedSize) inflater.setInput(buildBuffer, 0, compressedSize)
try { try {
inflater.inflate(data) inflater.inflate(data)
} catch (ex: DataFormatException) {
throw IOException("Bad compressed data format")
} finally { } finally {
inflater.end() inflater.end()
} }
@ -138,7 +134,7 @@ object ChunkPacketTransformer {
val y = encodedPos.and(0xFF) val y = encodedPos.and(0xFF)
val z = encodedPos.ushr(8).and(0xF) val z = encodedPos.ushr(8).and(0xF)
BlockChangeRecord1_8(x, y, z, blocks[it].toInt()) BlockChangeRecord1_8(x, y, z, blocks[it].toInt())
} }.toList().toTypedArray()
.toList().toTypedArray()) )
} }
} }