diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/network/packets/serverbound/DamageTileGroupPacket.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/network/packets/serverbound/DamageTileGroupPacket.kt index ed25533f..ed0550ac 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/network/packets/serverbound/DamageTileGroupPacket.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/network/packets/serverbound/DamageTileGroupPacket.kt @@ -42,6 +42,6 @@ class DamageTileGroupPacket(val tiles: Collection, val isBackground: B } override fun play(connection: ServerConnection) { - connection.tracker?.damageTiles(tiles, isBackground, sourcePosition, damage) + connection.tracker?.damageTiles(tiles, isBackground, sourcePosition, damage, source) } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorldTracker.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorldTracker.kt index 80751753..9bb2c236 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorldTracker.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorldTracker.kt @@ -81,7 +81,7 @@ class ServerWorldTracker(val world: ServerWorld, val client: ServerConnection, p client.worldID = world.worldID } - private data class DamageTileEntry(val positions: Collection, val isBackground: Boolean, val sourcePosition: Vector2d, val damage: TileDamage, val source: AbstractEntity? = null) + private data class DamageTileEntry(val positions: Collection, val isBackground: Boolean, val sourcePosition: Vector2d, val damage: TileDamage, val source: Int? = null) private val damageTilesQueue = Channel(64) // 64 pending tile group damage requests should be more than enough private val tileModificationBudget = ActionPacer(actions = 512, handicap = 2048) // TODO: make this configurable private val modifyTilesQueue = Channel>, Boolean>>(64) @@ -91,7 +91,7 @@ class ServerWorldTracker(val world: ServerWorld, val client: ServerConnection, p val (positions, isBackground, sourcePosition, damage, source) = damageTilesQueue.receive() try { - world.damageTiles(positions, isBackground, sourcePosition, damage, source, tileModificationBudget) + world.damageTiles(positions, isBackground, sourcePosition, damage, world.entities[source], tileModificationBudget) } catch (err: Throwable) { LOGGER.error("Exception in player damage tiles loop", err) client.disconnect("Exception in player damage tiles loop: $err") @@ -99,7 +99,7 @@ class ServerWorldTracker(val world: ServerWorld, val client: ServerConnection, p } } - fun damageTiles(positions: Collection, isBackground: Boolean, sourcePosition: Vector2d, damage: TileDamage, source: AbstractEntity? = null) { + fun damageTiles(positions: Collection, isBackground: Boolean, sourcePosition: Vector2d, damage: TileDamage, source: Int? = null) { damageTilesQueue.trySend(DamageTileEntry(positions, isBackground, sourcePosition, damage, source)) } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt index 6c5a8e97..10cd5f5c 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt @@ -585,11 +585,11 @@ abstract class World, ChunkType : Chunk> = Caffeine.newBuilder() - .maximumSize(32000L) // some unreachable value unless there is a malicious actor + .maximumSize(200_000L) // some unreachable value unless there is a malicious actor .expireAfterWrite(1L, TimeUnit.MINUTES) .executor(Starbound.EXECUTOR) .scheduler(Starbound) - .removalListener> { key, value, cause -> if (!cause.wasEvicted()) value?.completeExceptionally(TimeoutException("Did not receive response from remote in time")) } + .removalListener> { key, value, cause -> if (cause.wasEvicted()) value?.completeExceptionally(TimeoutException("Did not receive response from remote in time")) } .build() companion object {