mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
discard light packets
This commit is contained in:
parent
e3158f5ead
commit
a7ab19277b
21
src/main/java/de/bixilon/minosoft/protocol/PacketSkipper.kt
Normal file
21
src/main/java/de/bixilon/minosoft/protocol/PacketSkipper.kt
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.protocol
|
||||
|
||||
import de.bixilon.minosoft.protocol.network.connection.Connection
|
||||
|
||||
interface PacketSkipper {
|
||||
|
||||
fun canSkip(connection: Connection): Boolean
|
||||
}
|
@ -49,6 +49,9 @@ class PacketDecoder(
|
||||
if (packetType.clazz == S2CPacket::class.java) {
|
||||
throw S2CPacketNotImplementedException(packetId, state, version)
|
||||
}
|
||||
if (packetType.canSkip(client.connection)) {
|
||||
return
|
||||
}
|
||||
|
||||
val packet = try {
|
||||
readPacket(packetType, data)
|
||||
|
@ -24,6 +24,7 @@ import de.bixilon.kutil.reflection.KotlinReflection.kClass
|
||||
import de.bixilon.kutil.reflection.ReflectionUtil.realName
|
||||
import de.bixilon.kutil.string.StringUtil.toSnakeCase
|
||||
import de.bixilon.minosoft.protocol.PacketErrorHandler
|
||||
import de.bixilon.minosoft.protocol.PacketSkipper
|
||||
import de.bixilon.minosoft.protocol.packets.Packet
|
||||
import de.bixilon.minosoft.protocol.packets.PacketsRoot
|
||||
import de.bixilon.minosoft.protocol.packets.c2s.C2SPacket
|
||||
@ -122,6 +123,7 @@ object PacketTypeRegistry {
|
||||
val objectInstance: Any? = kClass.objectInstance ?: kClass.companionObjectInstance
|
||||
val annotation = clazz.getAnnotation(LoadPacket::class.java)
|
||||
val errorHandler = if (objectInstance is PacketErrorHandler) objectInstance else null
|
||||
val packetSkipper = if (objectInstance is PacketSkipper) objectInstance else null
|
||||
|
||||
val direction = when {
|
||||
objectInstance is PacketFactory -> objectInstance.direction
|
||||
@ -142,14 +144,15 @@ object PacketTypeRegistry {
|
||||
|
||||
if (direction == PacketDirection.SERVER_TO_CLIENT) {
|
||||
val s2cClass = clazz.unsafeCast<Class<out S2CPacket>>()
|
||||
val type = S2CPacketType(annotation.state, s2cClass, errorHandler, annotation, factory)
|
||||
val type = S2CPacketType(annotation.state, s2cClass, errorHandler, packetSkipper, annotation, factory)
|
||||
s2cClassMap[s2cClass] = type
|
||||
s2cStateMap.synchronizedGetOrPut(annotation.state) { mutableMapOf() }.put(name, type)?.let { throw IllegalStateException("Packet already mapped: $it (name=$name)") }
|
||||
if (parentClass != null && parentClass != s2cClass) {
|
||||
val parentKClass = parentClass.kClass
|
||||
val parentObject = parentKClass.objectInstance ?: parentKClass.companionObjectInstance
|
||||
val parentErrorHandler = parentObject.nullCast<PacketErrorHandler>()
|
||||
s2cClassMap[parentClass.unsafeCast()] = S2CPacketType(annotation.state, parentClass.unsafeCast(), parentErrorHandler, annotation)
|
||||
val parentPacketSkipper = parentObject.nullCast<PacketSkipper>()
|
||||
s2cClassMap[parentClass.unsafeCast()] = S2CPacketType(annotation.state, parentClass.unsafeCast(), parentErrorHandler, parentPacketSkipper, annotation)
|
||||
s2cStateMap[annotation.state]!!.putIfAbsent(parentClass.getPacketName(null), type)
|
||||
}
|
||||
} else {
|
||||
|
@ -14,6 +14,7 @@
|
||||
package de.bixilon.minosoft.protocol.packets.factory
|
||||
|
||||
import de.bixilon.minosoft.protocol.PacketErrorHandler
|
||||
import de.bixilon.minosoft.protocol.PacketSkipper
|
||||
import de.bixilon.minosoft.protocol.network.connection.Connection
|
||||
import de.bixilon.minosoft.protocol.packets.factory.factories.PacketFactory
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.S2CPacket
|
||||
@ -23,11 +24,12 @@ class S2CPacketType constructor(
|
||||
val state: ProtocolStates,
|
||||
val clazz: Class<out S2CPacket>,
|
||||
private val packetErrorHandler: PacketErrorHandler?,
|
||||
private val packetSkipper: PacketSkipper?,
|
||||
val annotation: LoadPacket?,
|
||||
val factory: PacketFactory? = null,
|
||||
override val threadSafe: Boolean = annotation!!.threadSafe,
|
||||
override val lowPriority: Boolean = annotation!!.lowPriority,
|
||||
) : AbstractPacketType, PacketErrorHandler {
|
||||
) : AbstractPacketType, PacketErrorHandler, PacketSkipper {
|
||||
override val direction = PacketDirection.SERVER_TO_CLIENT
|
||||
|
||||
|
||||
@ -35,6 +37,10 @@ class S2CPacketType constructor(
|
||||
packetErrorHandler?.onError(error, connection)
|
||||
}
|
||||
|
||||
override fun canSkip(connection: Connection): Boolean {
|
||||
return packetSkipper?.canSkip(connection) ?: false
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return clazz.toString()
|
||||
}
|
||||
|
@ -14,7 +14,10 @@ package de.bixilon.minosoft.protocol.packets.s2c.play.chunk
|
||||
|
||||
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.minosoft.config.StaticConfiguration
|
||||
import de.bixilon.minosoft.data.world.ChunkData
|
||||
import de.bixilon.minosoft.protocol.PacketSkipper
|
||||
import de.bixilon.minosoft.protocol.network.connection.Connection
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
@ -70,4 +73,11 @@ class ChunkLightS2CP @JvmOverloads constructor(buffer: PlayInByteBuffer, chunkPo
|
||||
val chunk = connection.world.getOrCreateChunk(chunkPosition)
|
||||
chunk.setData(chunkData)
|
||||
}
|
||||
|
||||
companion object : PacketSkipper {
|
||||
|
||||
override fun canSkip(connection: Connection): Boolean {
|
||||
return StaticConfiguration.IGNORE_SERVER_LIGHT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import de.bixilon.kutil.compression.zlib.ZlibUtil.decompress
|
||||
import de.bixilon.kutil.json.JsonUtil.asJsonObject
|
||||
import de.bixilon.kutil.json.JsonUtil.toJsonObject
|
||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||
import de.bixilon.minosoft.config.StaticConfiguration
|
||||
import de.bixilon.minosoft.data.entities.block.BlockEntity
|
||||
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
|
||||
import de.bixilon.minosoft.data.world.ChunkData
|
||||
@ -142,10 +143,14 @@ class ChunkS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
}
|
||||
|
||||
if (buffer.versionId >= V_21W37A) {
|
||||
if (StaticConfiguration.IGNORE_SERVER_LIGHT) {
|
||||
buffer.pointer = buffer.size
|
||||
} else {
|
||||
this.chunkData.replace(ChunkLightS2CP(buffer) { chunkPosition }.chunkData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ChunkReadingData.readChunkData() {
|
||||
if (readingData.buffer.versionId < V_21W37A) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user