diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt index 97f788794a..6bfc3213d6 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt @@ -20,9 +20,7 @@ import world.gregs.voidps.engine.entity.item.drop.DropTables import world.gregs.voidps.engine.entity.item.floor.FloorItemTracking import world.gregs.voidps.engine.entity.item.floor.FloorItems import world.gregs.voidps.engine.entity.obj.GameObjects -import world.gregs.voidps.engine.map.collision.CollisionStrategyProvider -import world.gregs.voidps.engine.map.collision.Collisions -import world.gregs.voidps.engine.map.collision.GameObjectCollision +import world.gregs.voidps.engine.map.collision.* import world.gregs.voidps.engine.map.zone.DynamicZones import world.gregs.voidps.network.client.ConnectionQueue import world.gregs.voidps.type.Tile @@ -34,7 +32,7 @@ val engineModule = module { // Entities single { NPCs(get(), get(), get()) } single { Players() } - single { GameObjects(get(), get(), get(), getProperty("loadUnusedObjects") == "true").apply { get().register(this) } } + single { GameObjects(get(), get(), get(), get(), getProperty("loadUnusedObjects") == "true").apply { get().register(this) } } single { FloorItems(get(), get()).apply { get().register(this) } } single { FloorItemTracking(get(), get(), get()) } single { Hunting(get(), get(), get(), get(), get(), get()) } @@ -77,7 +75,8 @@ val engineModule = module { single { ConnectionQueue(getIntProperty("connectionPerTickCap", 1)) } - single(createdAtStart = true) { GameObjectCollision(get()) } + single(createdAtStart = true) { GameObjectCollisionAdd(get()) } + single(createdAtStart = true) { GameObjectCollisionRemove(get()) } // Collision single { Collisions() } single { CollisionStrategyProvider() } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/GameLoop.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/GameLoop.kt index 4d33510ede..c841cd6a87 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/GameLoop.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/GameLoop.kt @@ -3,34 +3,29 @@ package world.gregs.voidps.engine import com.github.michaelbull.logging.InlineLogger import kotlinx.coroutines.* import java.util.concurrent.TimeUnit -import kotlin.coroutines.CoroutineContext class GameLoop( private val stages: List, - override val coroutineContext: CoroutineContext = Contexts.Game -) : CoroutineScope { - + private val delay: Long = ENGINE_DELAY +) { private val logger = InlineLogger() - private lateinit var job: Job - fun start() { + fun start(scope: CoroutineScope) = scope.launch { + var start: Long + var took: Long try { - var start: Long - var took: Long - job = launch { - while (isActive) { - start = System.nanoTime() - tick() - took = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) - if (took > MILLI_THRESHOLD) { - logger.info { "Tick $tick took ${took}ms" } - } - delay(ENGINE_DELAY - took) - tick++ + while (isActive) { + start = System.nanoTime() + tick() + took = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start) + if (took > MILLI_THRESHOLD) { + logger.info { "Tick $tick took ${took}ms" } } + delay(delay - took) + tick++ } - } catch (t: Throwable) { - logger.error(t) { "Error in game loop!" } + } catch (e: Exception) { + logger.error(e) { "Error in game loop!" } } } @@ -49,10 +44,6 @@ class GameLoop( } } - fun stop() { - job.cancel() - } - companion object { var tick: Int = 0 private const val ENGINE_DELAY = 600L diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoader.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoader.kt index 32ffd41930..bca563b181 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoader.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoader.kt @@ -2,7 +2,7 @@ package world.gregs.voidps.engine.client import com.github.michaelbull.logging.InlineLogger import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.withContext import world.gregs.voidps.engine.data.AccountManager import world.gregs.voidps.engine.data.AccountStorage @@ -40,7 +40,7 @@ class PlayerAccountLoader( /** * @return flow of instructions for the player to be controlled with */ - override suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): MutableSharedFlow? { + override suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): SendChannel? { try { val saving = saveQueue.saving(username) if (saving) { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionTask.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionTask.kt index 53efb9d28d..cda592a76a 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionTask.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionTask.kt @@ -1,7 +1,14 @@ package world.gregs.voidps.engine.client.instruction import com.github.michaelbull.logging.InlineLogger -import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.buffer +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.produceIn +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import world.gregs.voidps.engine.data.definition.InterfaceDefinitions import world.gregs.voidps.engine.data.definition.ItemDefinitions import world.gregs.voidps.engine.data.definition.NPCDefinitions @@ -36,11 +43,10 @@ class InstructionTask( handler ) - @OptIn(ExperimentalCoroutinesApi::class) override fun run() { for (player in players) { - val instructions = player.instructions - for (instruction in instructions.replayCache) { + for (i in 0 until MAX_INSTRUCTIONS) { + val instruction = player.instructions.tryReceive().getOrNull() ?: break if (player["debug", false]) { logger.debug { "${player.accountName} ${player.tile} - $instruction" } } @@ -50,7 +56,36 @@ class InstructionTask( logger.error(e) { "Error in instruction $instruction" } } } - instructions.resetReplayCache() + } + } + + companion object { + const val MAX_INSTRUCTIONS = 20 + + fun Flow.test() { + + flow> { + coroutineScope { + val upstreamChannel = buffer(10).produceIn(this) + upstreamChannel.tryReceive().getOrNull() + } + } + } + + @JvmStatic + fun main(args: Array): Unit = runBlocking { + + val channel = Channel(5) + + for (i in 0 until 4) { + channel.send(i) + } + launch { + for (i in 0 until 5) { + val it = channel.tryReceive().getOrNull() ?: break + println(it) + } + } } } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt index d85e328d77..62f78dde64 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt @@ -22,6 +22,8 @@ class InterfaceOnInterfaceOptionHandler( val (toId, toComponent, toItem, toInventory) = handler.getInterfaceItem(player, toInterfaceId, toComponentId, toItemId, toSlot) ?: return player.closeInterfaces() + player.queue.clearWeak() + player.suspension = null player.emit( ItemOnItem( fromItem, diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/WalkHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/WalkHandler.kt index d0dbd694b5..c418874a1f 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/WalkHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/WalkHandler.kt @@ -16,6 +16,8 @@ class WalkHandler : InstructionHandler() { } player.closeInterfaces() player.clearWatch() + player.queue.clearWeak() + player.suspension = null player.walkTo(player.tile.copy(instruction.x, instruction.y)) } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/data/SaveQueue.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/data/SaveQueue.kt index e706a2f5b7..03fca98a8a 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/data/SaveQueue.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/data/SaveQueue.kt @@ -1,45 +1,55 @@ package world.gregs.voidps.engine.data import com.github.michaelbull.logging.InlineLogger -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch +import kotlinx.coroutines.* import world.gregs.voidps.engine.client.ui.chat.plural import world.gregs.voidps.engine.entity.character.player.Player +import java.lang.Runnable import java.util.concurrent.ConcurrentHashMap -import kotlin.coroutines.CoroutineContext import kotlin.system.measureTimeMillis class SaveQueue( private val storage: AccountStorage, private val fallback: AccountStorage = storage, - override val coroutineContext: CoroutineContext = Dispatchers.IO -) : Runnable, CoroutineScope { + private val scope: CoroutineScope = CoroutineScope(Dispatchers.IO) +) : Runnable { private val pending = ConcurrentHashMap() private val logger = InlineLogger() + private val handler = CoroutineExceptionHandler { _, exception -> + logger.error(exception) { "Error saving players!" } + scope.fallback(pending.values.toList()) + } + private val fallbackHandler = CoroutineExceptionHandler { _, exception -> + logger.error(exception) { "Fallback save failed!" } + } + override fun run() { if (pending.isEmpty()) { return } - val accounts = pending.values.toList() - launch { - try { - val took = measureTimeMillis { - storage.save(accounts) - for (account in accounts) { - pending.remove(account.name) - } - } - logger.info { "Saved ${accounts.size} ${"account".plural(accounts.size)} in ${took}ms" } - } catch (e: Exception) { - logger.error(e) { "Error saving players!" } - fallback.save(accounts) + scope.save(pending.values.toList()) + } + + private fun CoroutineScope.save(accounts: List) = launch(handler) { + val took = measureTimeMillis { + withContext(NonCancellable) { + storage.save(accounts) for (account in accounts) { pending.remove(account.name) } } } + logger.info { "Saved ${accounts.size} ${"account".plural(accounts.size)} in ${took}ms" } + } + + private fun CoroutineScope.fallback(accounts: List) = launch(fallbackHandler) { + withContext(NonCancellable) { + fallback.save(accounts) + for (account in accounts) { + pending.remove(account.name) + } + } } fun save(player: Player) { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/data/definition/AreaDefinitions.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/data/definition/AreaDefinitions.kt index 80310b3622..48d527ddb9 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/data/definition/AreaDefinitions.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/data/definition/AreaDefinitions.kt @@ -17,7 +17,6 @@ class AreaDefinitions( private var areas: Map> = Int2ObjectOpenHashMap() ) { - fun getOrNull(name: String): AreaDefinition? { return named[name] } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt index 63b8f37cd1..82a815c5c3 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt @@ -1,7 +1,8 @@ package world.gregs.voidps.engine.entity.character.player -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.Channel import org.rsmod.game.pathfinder.collision.CollisionStrategy +import world.gregs.voidps.engine.client.instruction.InstructionTask import world.gregs.voidps.engine.client.ui.InterfaceOptions import world.gregs.voidps.engine.client.ui.Interfaces import world.gregs.voidps.engine.client.update.view.Viewport @@ -53,7 +54,7 @@ class Player( } override lateinit var visuals: PlayerVisuals - val instructions = MutableSharedFlow(replay = 20) + val instructions = Channel(capacity = InstructionTask.MAX_INSTRUCTIONS) lateinit var options: PlayerOptions lateinit var interfaces: Interfaces lateinit var interfaceOptions: InterfaceOptions diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/obj/GameObjects.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/obj/GameObjects.kt index cc5e23ae5a..1286011947 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/obj/GameObjects.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/obj/GameObjects.kt @@ -9,7 +9,8 @@ import world.gregs.voidps.engine.entity.Despawn import world.gregs.voidps.engine.entity.Spawn import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.get -import world.gregs.voidps.engine.map.collision.GameObjectCollision +import world.gregs.voidps.engine.map.collision.GameObjectCollisionAdd +import world.gregs.voidps.engine.map.collision.GameObjectCollisionRemove import world.gregs.voidps.network.login.protocol.encode.send import world.gregs.voidps.network.login.protocol.encode.zone.ObjectAddition import world.gregs.voidps.network.login.protocol.encode.zone.ObjectRemoval @@ -25,7 +26,8 @@ import world.gregs.voidps.type.Zone * @param storeUnused store non-interactive and objects without configs for debugging and content dev (uses ~240MB more ram). */ class GameObjects( - private val collisions: GameObjectCollision, + private val collisionAdd: GameObjectCollisionAdd, + private val collisionRemove: GameObjectCollisionRemove, private val batches: ZoneBatchUpdates, private val definitions: ObjectDefinitions, private val storeUnused: Boolean = false @@ -62,7 +64,7 @@ class GameObjects( map.remove(obj, REPLACED) batches.add(obj.tile.zone, ObjectAddition(obj.tile.id, obj.intId, obj.shape, obj.rotation)) if (collision) { - collisions.modify(obj, add = true) + collisionAdd.modify(obj) } size++ } else { @@ -83,7 +85,7 @@ class GameObjects( replacements[obj.index] = obj.value(replaced = true) batches.add(obj.tile.zone, ObjectAddition(obj.tile.id, obj.intId, obj.shape, obj.rotation)) if (collision) { - collisions.modify(obj, add = true) + collisionAdd.modify(obj) } size++ obj.emit(Spawn) @@ -94,7 +96,7 @@ class GameObjects( val gameObject = GameObject(id(objectValue), obj.x, obj.y, obj.level, shape(objectValue), rotation(objectValue)) batches.add(obj.tile.zone, ObjectRemoval(obj.tile.id, gameObject.shape, gameObject.rotation)) if (collision) { - collisions.modify(gameObject, add = false) + collisionRemove.modify(gameObject) } size-- return gameObject @@ -104,7 +106,7 @@ class GameObjects( * Sets the original placement of a game object */ fun set(id: Int, x: Int, y: Int, level: Int, shape: Int, rotation: Int, definition: ObjectDefinition) { - collisions.modify(definition, x, y, level, shape, rotation, add = true) + collisionAdd.modify(definition, x, y, level, shape, rotation) if (interactive(definition)) { map[x, y, level, ObjectLayer.layer(shape)] = value(false, id, shape, rotation) size++ @@ -143,7 +145,7 @@ class GameObjects( replacements.remove(obj.index) batches.add(obj.tile.zone, ObjectRemoval(obj.tile.id, obj.shape, obj.rotation)) if (collision) { - collisions.modify(obj, add = false) + collisionRemove.modify(obj) } size-- obj.emit(Despawn) @@ -153,7 +155,7 @@ class GameObjects( val originalObj = GameObject(id(original), obj.x, obj.y, obj.level, shape(original), rotation(original)) batches.add(obj.tile.zone, ObjectAddition(obj.tile.id, originalObj.intId, originalObj.shape, originalObj.rotation)) if (collision) { - collisions.modify(originalObj, add = true) + collisionAdd.modify(originalObj) } size++ } @@ -162,7 +164,7 @@ class GameObjects( map.add(obj, REPLACED) batches.add(obj.tile.zone, ObjectRemoval(obj.tile.id, obj.shape, obj.rotation)) if (collision) { - collisions.modify(obj, add = false) + collisionRemove.modify(obj) } size-- } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/Events.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/Events.kt index 107246eb05..6b64bf672e 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/Events.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/Events.kt @@ -8,7 +8,6 @@ import net.pearx.kasechange.toSnakeCase import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.type.Area import world.gregs.voidps.type.Tile -import kotlin.coroutines.CoroutineContext /** * Events is a Trie used for efficient storage and retrieval of handlers based on an arbitrary list of parameters. @@ -19,8 +18,9 @@ import kotlin.coroutines.CoroutineContext * any characters, and the "#" wildcard which matches a single digit 0-9 * - Default match; Always matches every input */ -class Events : CoroutineScope { - override val coroutineContext: CoroutineContext = Dispatchers.Unconfined + errorHandler +class Events( + private val scope: CoroutineScope = CoroutineScope(Dispatchers.Unconfined) +) { private val roots: MutableMap = Int2ObjectOpenHashMap(8) var all: ((Player, Event) -> Unit)? = null private val logger = InlineLogger() @@ -84,7 +84,7 @@ class Events : CoroutineScope { if (dispatcher is Player && dispatcher.contains("bot")) { all?.invoke(dispatcher, event) } - launch { + scope.launch(errorHandler) { for (handler in handlers) { if (event is CancellableEvent && event.cancelled) { break diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollision.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollision.kt index bb48d36bd4..57b68d6bb3 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollision.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollision.kt @@ -4,88 +4,77 @@ import world.gregs.voidps.cache.definition.data.ObjectDefinition import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.obj.ObjectShape import world.gregs.voidps.type.Direction -import world.gregs.voidps.type.Tile -import world.gregs.voidps.type.Zone -class GameObjectCollision( - private val collisions: Collisions -) { - fun modify(obj: GameObject, add: Boolean) { - modify(obj.def, obj.x, obj.y, obj.level, obj.shape, obj.rotation, add) +abstract class GameObjectCollision { + fun modify(obj: GameObject) { + modify(obj.def, obj.x, obj.y, obj.level, obj.shape, obj.rotation) } - fun modify(def: ObjectDefinition, x: Int, y: Int, level: Int, shape: Int, rotation: Int, add: Boolean) { + fun modify(def: ObjectDefinition, x: Int, y: Int, level: Int, shape: Int, rotation: Int) { if (def.solid == 0) { return } when (shape) { - ObjectShape.WALL_STRAIGHT -> modifyWall(x, y, level, def.block, cardinal[(rotation + 3) and 0x3], add) - ObjectShape.WALL_DIAGONAL_CORNER, ObjectShape.WALL_SQUARE_CORNER -> modifyWall(x, y, level, def.block, ordinal[rotation], add) - ObjectShape.WALL_CORNER -> modifyWallCorner(x, y, level, def.block, ordinal[rotation], add) - in ObjectShape.WALL_DIAGONAL until ObjectShape.GROUND_DECOR -> modifyObject(def, x, y, level, rotation, def.block, add) - ObjectShape.GROUND_DECOR -> if (def.interactive == 1 && def.solid == 1) modifyCardinal(x, y, level, def.block, add) + ObjectShape.WALL_STRAIGHT -> modifyWall(x, y, level, def.block, cardinal[(rotation + 3) and 0x3]) + ObjectShape.WALL_DIAGONAL_CORNER, ObjectShape.WALL_SQUARE_CORNER -> modifyWall(x, y, level, def.block, ordinal[rotation]) + ObjectShape.WALL_CORNER -> modifyWallCorner(x, y, level, def.block, ordinal[rotation]) + in ObjectShape.WALL_DIAGONAL until ObjectShape.GROUND_DECOR -> modifyObject(def, x, y, level, rotation, def.block) + ObjectShape.GROUND_DECOR -> if (def.interactive == 1 && def.solid == 1) modifyCardinal(x, y, level, def.block) } } - private fun modifyWall(x: Int, y: Int, level: Int, block: Int, direction: Int, add: Boolean) { - modifyTile(x, y, level, block, direction, add) - modifyTile(x + deltaX[direction], y + deltaY[direction], level, block, inverse[direction], add) + private fun modifyWall(x: Int, y: Int, level: Int, block: Int, direction: Int) { + modifyTile(x, y, level, block, direction) + modifyTile(x + deltaX[direction], y + deltaY[direction], level, block, inverse[direction]) } - private fun modifyWallCorner(x: Int, y: Int, level: Int, block: Int, direction: Int, add: Boolean) { - modifyWall(x, y, level, block, vertical[direction], add) - modifyWall(x, y, level, block, horizontal[direction], add) + private fun modifyWallCorner(x: Int, y: Int, level: Int, block: Int, direction: Int) { + modifyWall(x, y, level, block, vertical[direction]) + modifyWall(x, y, level, block, horizontal[direction]) } - private fun modifyObject(def: ObjectDefinition, x: Int, y: Int, level: Int, rotation: Int, block: Int, add: Boolean) { + private fun modifyObject(def: ObjectDefinition, x: Int, y: Int, level: Int, rotation: Int, block: Int) { if (def.sizeX == 1 && def.sizeY == 1) { - modifyCardinal(x, y, level, block, add) + modifyCardinal(x, y, level, block) } else if (def.sizeX == 2 && def.sizeY == 2) { - modifyCardinal(x, y, level, block, add) - modifyCardinal(x + 1, y, level, block, add) - modifyCardinal(x, y + 1, level, block, add) - modifyCardinal(x + 1, y + 1, level, block, add) + modifyCardinal(x, y, level, block) + modifyCardinal(x + 1, y, level, block) + modifyCardinal(x, y + 1, level, block) + modifyCardinal(x + 1, y + 1, level, block) } else if (def.sizeX == 3 && def.sizeY == 3) { - modifyCardinal(x, y + 1, level, block, add) - modifyCardinal(x, y + 2, level, block, add) - modifyCardinal(x + 1, y, level, block, add) - modifyCardinal(x + 1, y + 1, level, block, add) - modifyCardinal(x + 2, y, level, block, add) - modifyCardinal(x + 2, y + 2, level, block, add) + modifyCardinal(x, y + 1, level, block) + modifyCardinal(x, y + 2, level, block) + modifyCardinal(x + 1, y, level, block) + modifyCardinal(x + 1, y + 1, level, block) + modifyCardinal(x + 2, y, level, block) + modifyCardinal(x + 2, y + 2, level, block) } else { val width = if (rotation and 0x1 == 1) def.sizeY else def.sizeX val height = if (rotation and 0x1 == 1) def.sizeX else def.sizeY if (width == 1 && height == 2) { - modifyCardinal(x, y, level, block, add) - modifyCardinal(x, y + 1, level, block, add) + modifyCardinal(x, y, level, block) + modifyCardinal(x, y + 1, level, block) } else if (width == 2 && height == 1) { - modifyCardinal(x, y, level, block, add) - modifyCardinal(x + 1, y, level, block, add) + modifyCardinal(x, y, level, block) + modifyCardinal(x + 1, y, level, block) } else { for (dx in 0 until width) { for (dy in 0 until height) { - modifyCardinal(x + dx, y + dy, level, block, add) + modifyCardinal(x + dx, y + dy, level, block) } } } } } - private fun modifyCardinal(x: Int, y: Int, level: Int, block: Int, add: Boolean) { - modifyTile(x, y, level, block, 1, add) - modifyTile(x, y, level, block, 3, add) - modifyTile(x, y, level, block, 5, add) - modifyTile(x, y, level, block, 7, add) + private fun modifyCardinal(x: Int, y: Int, level: Int, block: Int) { + modifyTile(x, y, level, block, 1) + modifyTile(x, y, level, block, 3) + modifyTile(x, y, level, block, 5) + modifyTile(x, y, level, block, 7) } - private fun modifyTile(x: Int, y: Int, level: Int, block: Int, direction: Int, add: Boolean) { - val flags = collisions.flags[Zone.tileIndex(x, y, level)] ?: return - if (add) { - flags[Tile.index(x, y)] = flags[Tile.index(x, y)] or CollisionFlags.blocked[direction or block] - } else { - flags[Tile.index(x, y)] = flags[Tile.index(x, y)] and CollisionFlags.inverse[direction or block] - } - } + abstract fun modifyTile(x: Int, y: Int, level: Int, block: Int, direction: Int) companion object { // For performance reasons diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollisionAdd.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollisionAdd.kt new file mode 100644 index 0000000000..a751a1f39c --- /dev/null +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollisionAdd.kt @@ -0,0 +1,17 @@ +package world.gregs.voidps.engine.map.collision + +import world.gregs.voidps.type.Tile +import world.gregs.voidps.type.Zone + +class GameObjectCollisionAdd( + private val collisions: Collisions +) : GameObjectCollision() { + + override fun modifyTile(x: Int, y: Int, level: Int, block: Int, direction: Int) { + var flags = collisions.flags[Zone.tileIndex(x, y, level)] + if (flags == null) { + flags = collisions.allocateIfAbsent(x, y, level) + } + flags[Tile.index(x, y)] = flags[Tile.index(x, y)] or CollisionFlags.blocked[direction or block] + } +} \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollisionRemove.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollisionRemove.kt new file mode 100644 index 0000000000..44ea45704e --- /dev/null +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/map/collision/GameObjectCollisionRemove.kt @@ -0,0 +1,17 @@ +package world.gregs.voidps.engine.map.collision + +import world.gregs.voidps.type.Tile +import world.gregs.voidps.type.Zone + +class GameObjectCollisionRemove( + private val collisions: Collisions +) : GameObjectCollision() { + + override fun modifyTile(x: Int, y: Int, level: Int, block: Int, direction: Int) { + var flags = collisions.flags[Zone.tileIndex(x, y, level)] + if (flags == null) { + flags = collisions.allocateIfAbsent(x, y, level) + } + flags[Tile.index(x, y)] = flags[Tile.index(x, y)] and CollisionFlags.inverse[direction or block] + } +} \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/queue/ActionQueue.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/queue/ActionQueue.kt index 8262464075..29faa68567 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/queue/ActionQueue.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/queue/ActionQueue.kt @@ -13,13 +13,15 @@ import world.gregs.voidps.engine.suspend.resumeSuspension import java.util.concurrent.ConcurrentLinkedQueue import kotlin.coroutines.resume -class ActionQueue(private val character: Character) : CoroutineScope { +class ActionQueue( + private val character: Character, + private val scope: CoroutineScope = CoroutineScope(Dispatchers.Unconfined) +) { private val errorHandler = CoroutineExceptionHandler { _, throwable -> if (throwable !is CancellationException) { throwable.printStackTrace() } } - override val coroutineContext = Dispatchers.Unconfined + errorHandler private val pending = ConcurrentLinkedQueue() private val queue = ConcurrentLinkedQueue() @@ -90,7 +92,7 @@ class ActionQueue(private val character: Character) : CoroutineScope { (character as? Player)?.closeMenu() } if (canProcess(action) && action.process()) { - launch(action) + scope.launch(action) } return action.removed } @@ -101,7 +103,7 @@ class ActionQueue(private val character: Character) : CoroutineScope { private fun noInterrupt() = character is NPC || (character is Player && !character.hasMenuOpen() && character.dialogue == null) - private fun launch(action: Action) { + private fun CoroutineScope.launch(action: Action) { if (character.resumeSuspension() || (character is Player && character.dialogueSuspension != null)) { return } @@ -111,7 +113,7 @@ class ActionQueue(private val character: Character) : CoroutineScope { suspension.resume(Unit) return } - launch { + launch(errorHandler) { try { this@ActionQueue.action = action action.action.invoke(action) @@ -129,7 +131,7 @@ class ActionQueue(private val character: Character) : CoroutineScope { queuePending() queue.removeIf { if (it.behaviour == LogoutBehaviour.Accelerate) { - launch(it) + scope.launch(it) while (character.delay != null) { character.delay?.resume(Unit) character.delay = null diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/GameLoopTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/GameLoopTest.kt index 38e51fe9c7..3eec747d6e 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/GameLoopTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/GameLoopTest.kt @@ -1,34 +1,73 @@ package world.gregs.voidps.engine -import io.mockk.impl.annotations.RelaxedMockK -import io.mockk.junit5.MockKExtension -import io.mockk.verify -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.UnconfinedTestDispatcher +import kotlinx.coroutines.cancelAndJoin +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue -@ExtendWith(MockKExtension::class) -@OptIn(ExperimentalCoroutinesApi::class) internal class GameLoopTest { private lateinit var loop: GameLoop - @RelaxedMockK - private lateinit var stage: Runnable + private val stages = mutableListOf() @BeforeEach fun setup() { - loop = GameLoop(listOf(stage), UnconfinedTestDispatcher()) + loop = GameLoop(stages, 1L) } @Test - fun `Game loop`() { - loop.tick(stage) + fun `Start game loop`() = runTest { + var count = 0 + stages.add(Runnable { + count++ + }) + + val job = loop.start(this) + delay(5) + + // Then + assertEquals(5, count) + job.cancelAndJoin() + } + + @Test + fun `Cancel job early`() = runTest { + var count = 0 + stages.add(Runnable { + count++ + }) + + val job = loop.start(this) + delay(2) + job.cancel() + delay(2) + + // Then + assertEquals(2, count) + job.join() + } + + @Test + fun `Exception in stage`() = runTest { + var count = 0 + stages.add(Runnable { + count++ + }) + stages.add(Runnable { + throw IllegalStateException("Test") + }) + + val job = loop.start(this) + delay(5) + // Then - verify { - stage.run() - } + assertFalse(job.isActive) + assertEquals(1, count) } } \ No newline at end of file diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoaderTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoaderTest.kt index d3d6e6a2e4..33e7e2f9e0 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoaderTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoaderTest.kt @@ -2,7 +2,8 @@ package world.gregs.voidps.engine.client import io.mockk.* import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.TestCoroutineDispatcher +import kotlinx.coroutines.test.StandardTestDispatcher +import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.BeforeEach @@ -56,7 +57,7 @@ internal class PlayerAccountLoaderTest : KoinMock() { return playerSave } } - saveQueue = SaveQueue(storage, coroutineContext = TestCoroutineDispatcher()) + saveQueue = SaveQueue(storage, scope = TestScope()) definitions = AccountDefinitions(mutableMapOf("name" to AccountDefinition("name", "oldName", "", "hash"))) accounts = mockk(relaxed = true) loader = PlayerAccountLoader(queue, storage, accounts, saveQueue, definitions, UnconfinedTestDispatcher()) diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/obj/GameObjectsTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/obj/GameObjectsTest.kt index 9e58b51272..49515f425f 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/obj/GameObjectsTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/obj/GameObjectsTest.kt @@ -1,6 +1,8 @@ package world.gregs.voidps.engine.entity.obj import io.mockk.* +import kotlinx.coroutines.test.TestScope +import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import world.gregs.voidps.cache.definition.data.ObjectDefinition @@ -12,6 +14,7 @@ import world.gregs.voidps.engine.event.Events import world.gregs.voidps.network.login.protocol.encode.zone.ObjectAddition import world.gregs.voidps.network.login.protocol.encode.zone.ObjectRemoval import world.gregs.voidps.type.Tile +import kotlin.coroutines.EmptyCoroutineContext import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertNull @@ -30,8 +33,8 @@ class GameObjectsTest { every { definitions.get("test") } returns ObjectDefinition(123) every { definitions.get("test2") } returns ObjectDefinition(456) updates = mockk(relaxed = true) - objects = GameObjects(mockk(relaxed = true), updates, definitions, storeUnused = true) - events = spyk(Events()) + objects = GameObjects(mockk(relaxed = true), mockk(relaxed = true), updates, definitions, storeUnused = true) + events = spyk(Events(TestScope())) Events.setEvents(events) } diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/map/obj/MapObjectsDecoderTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/map/obj/MapObjectsDecoderTest.kt index f8c9839fad..e5162d117b 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/map/obj/MapObjectsDecoderTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/map/obj/MapObjectsDecoderTest.kt @@ -12,7 +12,8 @@ import world.gregs.voidps.engine.data.definition.ObjectDefinitions import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.entity.obj.ObjectShape import world.gregs.voidps.engine.map.collision.Collisions -import world.gregs.voidps.engine.map.collision.GameObjectCollision +import world.gregs.voidps.engine.map.collision.GameObjectCollisionAdd +import world.gregs.voidps.engine.map.collision.GameObjectCollisionRemove import world.gregs.voidps.type.Tile class MapObjectsDecoderTest { @@ -25,7 +26,8 @@ class MapObjectsDecoderTest { @BeforeEach fun setup() { definitions = ObjectDefinitions(Array(10_000) { ObjectDefinition.EMPTY }) - objects = GameObjects(GameObjectCollision(Collisions()), ZoneBatchUpdates(), definitions, storeUnused = true) + val collisions = Collisions() + objects = GameObjects(GameObjectCollisionAdd(collisions), GameObjectCollisionRemove(collisions), ZoneBatchUpdates(), definitions, storeUnused = true) decoder = MapObjectsDecoder(objects, definitions) tiles = LongArray(64 * 64 * 4) } diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/map/obj/MapObjectsRotatedDecoderTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/map/obj/MapObjectsRotatedDecoderTest.kt index 9e72626cc5..50bb342d61 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/map/obj/MapObjectsRotatedDecoderTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/map/obj/MapObjectsRotatedDecoderTest.kt @@ -11,7 +11,8 @@ import world.gregs.voidps.engine.data.definition.ObjectDefinitions import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.entity.obj.ObjectShape import world.gregs.voidps.engine.map.collision.Collisions -import world.gregs.voidps.engine.map.collision.GameObjectCollision +import world.gregs.voidps.engine.map.collision.GameObjectCollisionAdd +import world.gregs.voidps.engine.map.collision.GameObjectCollisionRemove import world.gregs.voidps.type.Tile import world.gregs.voidps.type.area.Rectangle @@ -25,7 +26,8 @@ class MapObjectsRotatedDecoderTest { @BeforeEach fun setup() { definitions = ObjectDefinitions(Array(10_000) { ObjectDefinition.EMPTY }) - objects = GameObjects(GameObjectCollision(Collisions()), ZoneBatchUpdates(), definitions, storeUnused = true) + val collisions = Collisions() + objects = GameObjects(GameObjectCollisionAdd(collisions), GameObjectCollisionRemove(collisions), ZoneBatchUpdates(), definitions, storeUnused = true) decoder = MapObjectsRotatedDecoder(objects, definitions) tiles = LongArray(64 * 64 * 4) } diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/map/zone/ZoneBatchUpdatesTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/map/zone/ZoneBatchUpdatesTest.kt index 395ce10a05..a16cef93fb 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/map/zone/ZoneBatchUpdatesTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/map/zone/ZoneBatchUpdatesTest.kt @@ -15,7 +15,8 @@ import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.entity.obj.ObjectShape import world.gregs.voidps.engine.map.collision.Collisions -import world.gregs.voidps.engine.map.collision.GameObjectCollision +import world.gregs.voidps.engine.map.collision.GameObjectCollisionAdd +import world.gregs.voidps.engine.map.collision.GameObjectCollisionRemove import world.gregs.voidps.engine.script.KoinMock import world.gregs.voidps.network.client.Client import world.gregs.voidps.network.login.protocol.encode.clearZone @@ -56,7 +57,8 @@ internal class ZoneBatchUpdatesTest : KoinMock() { val zone = Zone(2, 2) batches.add(zone, update) player.tile = Tile(20, 20) - val objects = GameObjects(GameObjectCollision(Collisions()), ZoneBatchUpdates(), mockk(relaxed = true), storeUnused = true) + val collisions = Collisions() + val objects = GameObjects(GameObjectCollisionAdd(collisions), GameObjectCollisionRemove(collisions), ZoneBatchUpdates(), mockk(relaxed = true), storeUnused = true) objects.set(id = 1234, x = 21, y = 20, level = 0, shape = ObjectShape.WALL_DECOR_STRAIGHT_NO_OFFSET, rotation = 0, definition = ObjectDefinition.EMPTY) batches.register(objects) val added = GameObject(4321, Tile(20, 21), ObjectShape.CENTRE_PIECE_STRAIGHT, 0) diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/queue/ActionQueueTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/queue/ActionQueueTest.kt index 19959f3cc9..921b2f90e9 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/queue/ActionQueueTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/queue/ActionQueueTest.kt @@ -3,6 +3,8 @@ package world.gregs.voidps.engine.queue import io.mockk.every import io.mockk.mockk import io.mockk.verify +import kotlinx.coroutines.test.TestScope +import kotlinx.coroutines.test.UnconfinedTestDispatcher import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import world.gregs.voidps.engine.client.variable.start diff --git a/game/src/main/kotlin/world/gregs/voidps/Main.kt b/game/src/main/kotlin/world/gregs/voidps/Main.kt index d3ce8edc80..67baa74730 100644 --- a/game/src/main/kotlin/world/gregs/voidps/Main.kt +++ b/game/src/main/kotlin/world/gregs/voidps/Main.kt @@ -64,16 +64,16 @@ object Main : CoroutineScope { // Game world val stages = getTickStages() - val engine = GameLoop(stages) World.start(properties) - engine.start() + val scope = CoroutineScope(Contexts.Game) + val engine = GameLoop(stages).start(scope) server.loginServer = loginServer logger.info { "$name loaded in ${System.currentTimeMillis() - startTime}ms" } runBlocking { try { job.join() } finally { - engine.stop() + engine.cancel() server.stop() } } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/Bots.kt b/game/src/main/kotlin/world/gregs/voidps/bot/Bots.kt index 42d1e37195..4806fd7e7f 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/Bots.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/Bots.kt @@ -68,7 +68,7 @@ fun Bot.equip(item: String) { } val index = player.inventory.indexOf(item) if (index != -1) { - player.instructions.tryEmit(InteractInterface(interfaceId = 149, componentId = 0, itemId = def.id, itemSlot = index, option = 1)) + player.instructions.trySend(InteractInterface(interfaceId = 149, componentId = 0, itemId = def.id, itemSlot = index, option = 1)) } } @@ -76,23 +76,23 @@ fun Bot.inventoryOption(item: String, option: String) { val index = player.inventory.indexOf(item) if (index != -1) { val def = get().getOrNull(item) ?: return - player.instructions.tryEmit(InteractInterface(interfaceId = 149, componentId = 0, itemId = def.id, itemSlot = index, option = def.options.indexOf(option))) + player.instructions.trySend(InteractInterface(interfaceId = 149, componentId = 0, itemId = def.id, itemSlot = index, option = def.options.indexOf(option))) } } suspend fun Bot.npcOption(npc: NPC, option: String) { - player.instructions.emit(InteractNPC(npc.index, npc.def.options.indexOf(option) + 1)) + player.instructions.send(InteractNPC(npc.index, npc.def.options.indexOf(option) + 1)) } suspend fun Bot.objectOption(obj: GameObject, option: String) { - player.instructions.emit(InteractObject(obj.def.id, obj.tile.x, obj.tile.y, obj.def.optionsIndex(option) + 1)) + player.instructions.send(InteractObject(obj.def.id, obj.tile.x, obj.tile.y, obj.def.optionsIndex(option) + 1)) } suspend fun Bot.dialogueOption(option: String) { val current = player.dialogue!! val definitions = get() val def = definitions.get(current) - player.instructions.emit(InteractDialogue(def.id, definitions.getComponentId(current, option)!!, -1)) + player.instructions.send(InteractDialogue(def.id, definitions.getComponentId(current, option)!!, -1)) await("tick") } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/InterfaceBot.kt b/game/src/main/kotlin/world/gregs/voidps/bot/InterfaceBot.kt index 97a2953df9..da548f5bb1 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/InterfaceBot.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/InterfaceBot.kt @@ -8,14 +8,14 @@ import world.gregs.voidps.network.client.instruction.InteractInterfaceObject import world.gregs.voidps.network.client.instruction.InterfaceClosedInstruction suspend fun Bot.closeInterface(id: Int, component: Int) { - player.instructions.emit(InterfaceClosedInstruction) + player.instructions.send(InterfaceClosedInstruction) clickInterface(id, component, 0) } suspend fun Bot.clickInterface(id: Int, component: Int, option: Int = 0, itemId: Int = -1, itemSlot: Int = -1) { - player.instructions.emit(InteractInterface(interfaceId = id, componentId = component, itemId = itemId, itemSlot = itemSlot, option = option)) + player.instructions.send(InteractInterface(interfaceId = id, componentId = component, itemId = itemId, itemSlot = itemSlot, option = option)) } suspend fun Bot.itemOnObject(item: Item, obj: GameObject, interfaceId: Int = 149, component: Int = 0) { - player.instructions.emit(InteractInterfaceObject(obj.def.id, obj.tile.x, obj.tile.y, interfaceId, component, item.def.id, player.inventory.indexOf(item.id))) + player.instructions.send(InteractInterfaceObject(obj.def.id, obj.tile.x, obj.tile.y, interfaceId, component, item.def.id, player.inventory.indexOf(item.id))) } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/WalkingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/WalkingBot.kts index ee1b3dae46..6f84a0f32a 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/WalkingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/WalkingBot.kts @@ -13,7 +13,7 @@ worldSpawn { block = { while (true) { val tile = tile.toCuboid(10).random() - instructions.emit(Walk(tile.x, tile.y)) + instructions.send(Walk(tile.x, tile.y)) bot.await("tick") } }, diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/bank/BankBot.kt b/game/src/main/kotlin/world/gregs/voidps/bot/bank/BankBot.kt index 74e737c291..0a33b06532 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/bank/BankBot.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/bank/BankBot.kt @@ -47,7 +47,7 @@ suspend fun Bot.depositAll(item: String, slot: Int = player.inventory.indexOf(it if (slot == -1) { return } - player.instructions.emit(InteractInterface(interfaceId = 763, componentId = 0, itemId = getItemId(item) ?: return, itemSlot = slot, option = 5)) + player.instructions.send(InteractInterface(interfaceId = 763, componentId = 0, itemId = getItemId(item) ?: return, itemSlot = slot, option = 5)) await("tick") } @@ -61,10 +61,10 @@ suspend fun Bot.deposit(item: String, slot: Int = player.inventory.indexOf(item) 10 -> 2 else -> 4 } - player.instructions.emit(InteractInterface(interfaceId = 763, componentId = 0, itemId = getItemId(item) ?: return, itemSlot = slot, option = option)) + player.instructions.send(InteractInterface(interfaceId = 763, componentId = 0, itemId = getItemId(item) ?: return, itemSlot = slot, option = option)) if (option == 4) { await("tick") - player.instructions.emit(EnterInt(value = amount)) + player.instructions.send(EnterInt(value = amount)) } await("tick") } @@ -79,10 +79,10 @@ suspend fun Bot.withdraw(item: String, slot: Int = player.bank.indexOf(item), am 10 -> 2 else -> 4 } - player.instructions.emit(InteractInterface(interfaceId = 762, componentId = 93, itemId = getItemId(item) ?: return, itemSlot = slot, option = option)) + player.instructions.send(InteractInterface(interfaceId = 762, componentId = 93, itemId = getItemId(item) ?: return, itemSlot = slot, option = option)) if (option == 4) { await("tick") - player.instructions.emit(EnterInt(value = amount)) + player.instructions.send(EnterInt(value = amount)) } await("tick") } @@ -105,7 +105,7 @@ suspend fun Bot.withdrawAll(item: String, slot: Int = player.bank.indexOf(item)) if (slot == -1) { return } - player.instructions.emit(InteractInterface(interfaceId = 762, componentId = 93, itemId = getItemId(item) ?: return, itemSlot = slot, option = 5)) + player.instructions.send(InteractInterface(interfaceId = 762, componentId = 93, itemId = getItemId(item) ?: return, itemSlot = slot, option = 5)) await("tick") } @@ -113,7 +113,7 @@ suspend fun Bot.withdrawAllButOne(item: String, slot: Int = player.bank.indexOf( if (slot == -1) { return } - player.instructions.emit(InteractInterface(interfaceId = 762, componentId = 93, itemId = getItemId(item) ?: return, itemSlot = slot, option = 6)) + player.instructions.send(InteractInterface(interfaceId = 762, componentId = 93, itemId = getItemId(item) ?: return, itemSlot = slot, option = 6)) await("tick") } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/item/FloorItemBot.kt b/game/src/main/kotlin/world/gregs/voidps/bot/item/FloorItemBot.kt index d833b16ee1..de1a01cbba 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/item/FloorItemBot.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/item/FloorItemBot.kt @@ -9,7 +9,7 @@ import world.gregs.voidps.engine.timer.TICKS import world.gregs.voidps.network.client.instruction.InteractFloorItem suspend fun Bot.pickup(floorItem: FloorItem) { - player.instructions.emit(InteractFloorItem(floorItem.def.id, floorItem.tile.x, floorItem.tile.y, 2)) + player.instructions.send(InteractFloorItem(floorItem.def.id, floorItem.tile.x, floorItem.tile.y, 2)) if (player.inventory.isFull()) { return } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/navigation/GoTo.kt b/game/src/main/kotlin/world/gregs/voidps/bot/navigation/GoTo.kt index e03318bda0..c7b8287c38 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/navigation/GoTo.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/navigation/GoTo.kt @@ -85,12 +85,12 @@ private fun updateGraph(bot: Bot) { private suspend fun Bot.rest() { val musician = get().firstOrNull { it.tile.within(player.tile, VIEW_RADIUS) && it.def.options.contains("Listen-to") } if (musician != null && player.tile.distanceTo(musician) < 10) { - player.instructions.emit(InteractNPC(npcIndex = 49, option = musician.def.options.indexOfFirst { it == "Listen-to" } + 1)) + player.instructions.send(InteractNPC(npcIndex = 49, option = musician.def.options.indexOfFirst { it == "Listen-to" } + 1)) repeat(32) { await("tick") } } else { - player.instructions.emit(InteractInterface(interfaceId = 750, componentId = 1, itemId = -1, itemSlot = -1, option = 1)) + player.instructions.send(InteractInterface(interfaceId = 750, componentId = 1, itemId = -1, itemSlot = -1, option = 1)) repeat(50) { await("tick") } @@ -98,7 +98,7 @@ private suspend fun Bot.rest() { } private suspend fun Bot.run() { - player.instructions.emit(InteractInterface(interfaceId = 750, componentId = 1, itemId = -1, itemSlot = -1, option = 0)) + player.instructions.send(InteractInterface(interfaceId = 750, componentId = 1, itemId = -1, itemSlot = -1, option = 0)) } private suspend fun Bot.navigate() { @@ -112,7 +112,7 @@ private suspend fun Bot.navigate() { run() } this.step = step - player.instructions.emit(step) + player.instructions.send(step) val timeout = withTimeoutOrNull(TICKS.toMillis(20)) { if (step is InteractObject && get()[player.tile.copy(step.x, step.y), step.objectId] == null) { await("tick") diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/shop/ShopBot.kt b/game/src/main/kotlin/world/gregs/voidps/bot/shop/ShopBot.kt index 4cf0388cf9..3dadebe56f 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/shop/ShopBot.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/shop/ShopBot.kt @@ -32,7 +32,7 @@ suspend fun Bot.openShop(map: AreaDefinition): NPC { private suspend fun Bot.openShop(): NPC { val shop = get().first { it.tile.within(player.tile, Viewport.VIEW_RADIUS) && it.def.options.contains("Trade") } - player.instructions.emit(InteractNPC(npcIndex = shop.index, option = shop.def.options.indexOfFirst { it == "Trade" } + 1)) + player.instructions.send(InteractNPC(npcIndex = shop.index, option = shop.def.options.indexOfFirst { it == "Trade" } + 1)) await("shop") return shop } @@ -55,7 +55,7 @@ suspend fun Bot.buy(item: String, amount: Int = 1) { remaining >= 5 -> 2 else -> 1 } - player.instructions.emit(InteractInterface(interfaceId = 620, componentId = 25, itemId = -1, itemSlot = slot, option = option)) + player.instructions.send(InteractInterface(interfaceId = 620, componentId = 25, itemId = -1, itemSlot = slot, option = option)) remaining -= when { remaining >= 500 -> 500 remaining >= 50 -> 50 diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/SkillBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/SkillBot.kts index ccb1b3974e..bb9beca8ab 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/SkillBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/SkillBot.kts @@ -4,5 +4,5 @@ import world.gregs.voidps.engine.client.ui.event.interfaceOpen import world.gregs.voidps.network.client.instruction.InteractDialogue interfaceOpen("dialogue_level_up") { bot -> - bot.instructions.tryEmit(InteractDialogue(interfaceId = 740, componentId = 3, option = -1)) + bot.instructions.trySend(InteractDialogue(interfaceId = 740, componentId = 3, option = -1)) } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/CombatBot.kt b/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/CombatBot.kt index 67c17f28f6..67cd2aa80f 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/CombatBot.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/CombatBot.kt @@ -18,9 +18,9 @@ suspend fun Bot.setAttackStyle(skill: Skill) { suspend fun Bot.setAutoCast(spell: String) { val definitions = get() val def = definitions.get(player.spellBook) - player.instructions.emit(InteractInterface(def.id, definitions.getComponentId(player.spellBook, spell) ?: return, -1, -1, 0)) + player.instructions.send(InteractInterface(def.id, definitions.getComponentId(player.spellBook, spell) ?: return, -1, -1, 0)) } suspend fun Bot.setAttackStyle(style: Int) { - player.instructions.emit(InteractInterface(interfaceId = 884, componentId = style + 11, itemId = -1, itemSlot = -1, option = 0)) + player.instructions.send(InteractInterface(interfaceId = 884, componentId = style + 11, itemId = -1, itemSlot = -1, option = 0)) } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/cooking/CookingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/cooking/CookingBot.kts index 74bde40c1c..8f7a51d2a2 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/cooking/CookingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/cooking/CookingBot.kts @@ -63,18 +63,18 @@ suspend fun Bot.cook(map: AreaDefinition, rawItem: Item, set: GearDefinition) { return } // Use item on range - player.instructions.emit(InteractInterfaceObject(range.def.id, range.tile.x, range.tile.y, 149, 0, rawItem.def.id, player.inventory.indexOf(rawItem.id))) + player.instructions.send(InteractInterfaceObject(range.def.id, range.tile.x, range.tile.y, 149, 0, rawItem.def.id, player.inventory.indexOf(rawItem.id))) await("tick") await("tick") if (rawItem.id == "raw_beef") { - player.instructions.emit(InteractDialogue(228, 3, -1)) + player.instructions.send(InteractDialogue(228, 3, -1)) await("tick") } // Select all clickInterface(916, 8, 0) await("tick") // First option - player.instructions.emit(InteractDialogue(905, 14, -1)) + player.instructions.send(InteractDialogue(905, 14, -1)) } var count = 0 while (player.inventory.contains(rawItem.id)) { diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/firemaking/FiremakingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/firemaking/FiremakingBot.kts index 92bae9849b..8b1867ca16 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/firemaking/FiremakingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/firemaking/FiremakingBot.kts @@ -77,7 +77,7 @@ suspend fun Bot.light(map: AreaDefinition, lighter: Item, logs: Item) { if (logIndex == -1) { break } - player.instructions.emit(InteractInterfaceItem(lighter.def.id, logs.def.id, lighterIndex, logIndex, 149, 0, 149, 0)) + player.instructions.send(InteractInterfaceItem(lighter.def.id, logs.def.id, lighterIndex, logIndex, 149, 0, 149, 0)) await("firemaking") } } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/fishing/FishingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/fishing/FishingBot.kts index fd280e354b..a6bcc90dfd 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/fishing/FishingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/fishing/FishingBot.kts @@ -82,7 +82,7 @@ suspend fun Bot.fish(map: AreaDefinition, option: String, bait: String, set: Gea } continue } - player.instructions.emit(InteractNPC(spot.index, spot.def.options.indexOf(option) + 1)) + player.instructions.send(InteractNPC(spot.index, spot.def.options.indexOf(option) + 1)) await("fishing") } } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/mining/MiningBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/mining/MiningBot.kts index e33b51ab9f..794ab5b9f2 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/mining/MiningBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/mining/MiningBot.kts @@ -69,7 +69,7 @@ suspend fun Bot.mineRocks(map: AreaDefinition, type: String) { } continue } - player.instructions.emit(InteractObject(rock.def.id, rock.tile.x, rock.tile.y, 1)) + player.instructions.send(InteractObject(rock.def.id, rock.tile.x, rock.tile.y, 1)) await("mining") } } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/runecrafting/RunecraftingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/runecrafting/RunecraftingBot.kts index af6b20abae..8db4e24ffa 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/runecrafting/RunecraftingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/runecrafting/RunecraftingBot.kts @@ -47,7 +47,7 @@ suspend fun Bot.craftRunes(map: AreaDefinition) { await("tick") val altar = getObjects { isAltar(map, it) } .first() - player.instructions.emit(InteractObject(altar.def.id, altar.tile.x, altar.tile.y, 1)) + player.instructions.send(InteractObject(altar.def.id, altar.tile.x, altar.tile.y, 1)) awaitInteract() } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmeltingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmeltingBot.kts index 93e251d0ef..6bab9583bb 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmeltingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmeltingBot.kts @@ -83,7 +83,7 @@ suspend fun Bot.smelt(map: AreaDefinition, set: GearDefinition) { break } } - player.instructions.emit(InteractDialogue(905, 14 + index, -1)) + player.instructions.send(InteractDialogue(905, 14 + index, -1)) await("smelting") } } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/woodcutting/WoodcuttingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/woodcutting/WoodcuttingBot.kts index a6f7e5c343..ac74d7a34f 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/woodcutting/WoodcuttingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/woodcutting/WoodcuttingBot.kts @@ -68,7 +68,7 @@ suspend fun Bot.cutTrees(map: AreaDefinition, type: String? = null) { } continue } - player.instructions.emit(InteractObject(tree.def.id, tree.tile.x, tree.tile.y, 1)) + player.instructions.send(InteractObject(tree.def.id, tree.tile.x, tree.tile.y, 1)) await("woodcutting") } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/PlayerDeath.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/PlayerDeath.kts index e9d72792bb..d658b7811b 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/PlayerDeath.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/PlayerDeath.kts @@ -1,5 +1,3 @@ -@file:Suppress("OPT_IN_USAGE") - package world.gregs.voidps.world.interact.entity.death import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap @@ -57,7 +55,9 @@ playerDeath { player -> player.steps.clear() val dealer = player.damageDealers.maxByOrNull { it.value } val killer = dealer?.key - player.instructions.resetReplayCache() + while (true) { + player.instructions.tryReceive().getOrNull() ?: break + } val tile = player.tile.copy() val wilderness = player.inWilderness retribution(player) diff --git a/game/src/test/kotlin/world/gregs/voidps/world/community/clan/ClanTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/community/clan/ClanTest.kt index 733d25e966..6903b5e801 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/community/clan/ClanTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/community/clan/ClanTest.kt @@ -39,7 +39,7 @@ internal class ClanTest : WorldTest() { createPlayer("player") val (joiner, client) = createClient("joiner") - joiner.instructions.emit(ClanChatJoin("player")) + joiner.instructions.send(ClanChatJoin("player")) tick() verify { @@ -51,7 +51,7 @@ internal class ClanTest : WorldTest() { fun `Can't join non existent clan chat`() = runTest { val (player, client) = createClient("player") - player.instructions.emit(ClanChatJoin("non-existent")) + player.instructions.send(ClanChatJoin("non-existent")) tick() verify { @@ -66,7 +66,7 @@ internal class ClanTest : WorldTest() { owner.ownClan?.joinRank = ClanRank.General val (joiner, client) = createClient("joiner") - joiner.instructions.emit(ClanChatJoin("player")) + joiner.instructions.send(ClanChatJoin("player")) tick() verify { @@ -79,10 +79,10 @@ internal class ClanTest : WorldTest() { val (player, client) = createClient("player") val clan = player.ownClan!! - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() assertEquals("player", clan.name) @@ -97,7 +97,7 @@ internal class ClanTest : WorldTest() { val player = createPlayer("player") val clan = player.ownClan!! clan.name = "clan" - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() player.interfaceOption("clan_chat", "settings", "Clan Setup") @@ -116,7 +116,7 @@ internal class ClanTest : WorldTest() { owner.friends["joiner"] = ClanRank.Corporeal val (joiner, client) = createClient("joiner") - joiner.instructions.emit(ClanChatJoin("player")) + joiner.instructions.send(ClanChatJoin("player")) tick() verify { @@ -129,10 +129,10 @@ internal class ClanTest : WorldTest() { val owner = createPlayer("player") owner.ownClan?.name = "clan" val (joiner, client) = createClient("joiner") - joiner.instructions.emit(ClanChatJoin("player")) + joiner.instructions.send(ClanChatJoin("player")) tick() - joiner.instructions.emit(ClanChatJoin("")) + joiner.instructions.send(ClanChatJoin("")) tick() verify { @@ -147,7 +147,7 @@ internal class ClanTest : WorldTest() { owner.ownClan?.name = "clan" owner.friends["friend"] = ClanRank.Friend - owner.instructions.emit(ClanChatRank("friend", 2)) + owner.instructions.send(ClanChatRank("friend", 2)) tick() assertEquals(ClanRank.Corporeal, owner.friends["friend"]) @@ -160,10 +160,10 @@ internal class ClanTest : WorldTest() { owner.ownClan?.joinRank = ClanRank.Corporeal owner.friends["joiner"] = ClanRank.Corporeal val (joiner, client) = createClient("joiner") - joiner.instructions.emit(ClanChatJoin("player")) + joiner.instructions.send(ClanChatJoin("player")) tick() - owner.instructions.emit(FriendDelete("joiner")) + owner.instructions.send(FriendDelete("joiner")) tick() verify { @@ -178,11 +178,11 @@ internal class ClanTest : WorldTest() { clan.name = "clan" owner.friends["joiner"] = ClanRank.Friend val (joiner, client) = createClient("joiner") - owner.instructions.emit(ClanChatJoin("player")) - joiner.instructions.emit(ClanChatJoin("player")) + owner.instructions.send(ClanChatJoin("player")) + joiner.instructions.send(ClanChatJoin("player")) tick() - owner.instructions.emit(ClanChatKick("joiner")) + owner.instructions.send(ClanChatKick("joiner")) tick() assertFalse(clan.members.contains(joiner)) @@ -198,10 +198,10 @@ internal class ClanTest : WorldTest() { clan.name = "clan" val admin = createPlayer("admin") admin.rights = PlayerRights.Admin - admin.instructions.emit(ClanChatJoin("player")) + admin.instructions.send(ClanChatJoin("player")) tick() - owner.instructions.emit(ClanChatKick("admin")) + owner.instructions.send(ClanChatKick("admin")) tick() assertTrue(clan.members.contains(admin)) @@ -217,7 +217,7 @@ internal class ClanTest : WorldTest() { clan.name = "clan" val admin = createPlayer("admin") admin.rights = PlayerRights.Admin - admin.instructions.emit(ClanChatJoin("player")) + admin.instructions.send(ClanChatJoin("player")) tick() owner.interfaceOption("clan_chat", "settings", "Clan Setup") @@ -232,7 +232,7 @@ internal class ClanTest : WorldTest() { val clan = owner.ownClan!! clan.name = "clan" val (member, client) = createClient("member") - member.instructions.emit(ClanChatJoin("player")) + member.instructions.send(ClanChatJoin("player")) tick() member.interfaceOption("clan_chat", "settings", "Clan Setup") @@ -251,10 +251,10 @@ internal class ClanTest : WorldTest() { clan.talkRank = ClanRank.Corporeal val (player, client) = createClient("player") owner.friends["player"] = ClanRank.Corporeal - player.instructions.emit(ClanChatJoin("owner")) + player.instructions.send(ClanChatJoin("owner")) - player.instructions.emit(ChatTypeChange(1)) - player.instructions.emit(ChatPublic("Hi", 0)) + player.instructions.send(ChatTypeChange(1)) + player.instructions.send(ChatPublic("Hi", 0)) tick() verify { @@ -269,10 +269,10 @@ internal class ClanTest : WorldTest() { val (player, client) = createClient("player") clan.name = "clan" clan.talkRank = ClanRank.General - player.instructions.emit(ClanChatJoin("owner")) + player.instructions.send(ClanChatJoin("owner")) - player.instructions.emit(ChatTypeChange(1)) - player.instructions.emit(ChatPublic("Hi", 0)) + player.instructions.send(ChatTypeChange(1)) + player.instructions.send(ChatPublic("Hi", 0)) tick() verify { diff --git a/game/src/test/kotlin/world/gregs/voidps/world/community/clan/LootShareTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/community/clan/LootShareTest.kt index 95f9b25ba1..121f4f1894 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/community/clan/LootShareTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/community/clan/LootShareTest.kt @@ -39,7 +39,7 @@ internal class LootShareTest : WorldTest() { fun `Can't toggle loot share if it's disabled`() = runTest { val (player, client) = createClient("player") repeat(2) { - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() } @@ -55,7 +55,7 @@ internal class LootShareTest : WorldTest() { fun `Activate loot share`() = runTest { val (player, client) = createClient("player") repeat(2) { - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() } player.clan?.lootRank = ClanRank.Anyone @@ -73,7 +73,7 @@ internal class LootShareTest : WorldTest() { fun `Activate coin share while sharing loot`() = runTest { val (player, client) = createClient("player") repeat(2) { - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() } player["loot_share"] = true @@ -93,7 +93,7 @@ internal class LootShareTest : WorldTest() { fun `Disable coin share`() = runTest { val (player, client) = createClient("player") repeat(2) { - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() } val clan = player.clan!! @@ -116,7 +116,7 @@ internal class LootShareTest : WorldTest() { mockkStatic("world.gregs.voidps.world.interact.entity.combat.WildernessKt") val (player, client) = createClient("player", emptyTile) repeat(2) { - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() } val clan = player.clan!! @@ -147,12 +147,12 @@ internal class LootShareTest : WorldTest() { player.experience.set(Skill.Attack, Experience.MAXIMUM_EXPERIENCE) val member = createPlayer("member", emptyTile) repeat(2) { - player.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) tick() } val clan = player.clan!! clan.lootRank = ClanRank.Anyone - member.instructions.emit(ClanChatJoin("player")) + member.instructions.send(ClanChatJoin("player")) tick() member["loot_share"] = true val npc = createNPC("rat", emptyTile.addY(1)) diff --git a/game/src/test/kotlin/world/gregs/voidps/world/community/friend/FriendTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/community/friend/FriendTest.kt index 4452987386..df34f5a732 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/community/friend/FriendTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/community/friend/FriendTest.kt @@ -30,7 +30,7 @@ internal class FriendTest : WorldTest() { val (_, client) = createClient("friend") player["private_status"] = "friends" - player.instructions.emit(FriendAdd("friend")) + player.instructions.send(FriendAdd("friend")) tick() @@ -48,7 +48,7 @@ internal class FriendTest : WorldTest() { player.friends[it.toString()] = ClanRank.Friend } - player.instructions.emit(FriendAdd("friend")) + player.instructions.send(FriendAdd("friend")) tick() verify { @@ -60,7 +60,7 @@ internal class FriendTest : WorldTest() { fun `Add non-existent friend`() = runTest { val player = createPlayer("player") - player.instructions.emit(FriendAdd("non-existent")) + player.instructions.send(FriendAdd("non-existent")) tick() verify { @@ -74,7 +74,7 @@ internal class FriendTest : WorldTest() { createPlayer("friend") player.friends["friend"] = ClanRank.Friend - player.instructions.emit(FriendAdd("friend")) + player.instructions.send(FriendAdd("friend")) tick() verify { @@ -88,7 +88,7 @@ internal class FriendTest : WorldTest() { createPlayer("friend") player.ignores.add("friend") - player.instructions.emit(FriendAdd("friend")) + player.instructions.send(FriendAdd("friend")) tick() verify { @@ -103,7 +103,7 @@ internal class FriendTest : WorldTest() { val (_, client) = createClient("friend") player.friends["friend"] = ClanRank.Friend - player.instructions.emit(FriendDelete("friend")) + player.instructions.send(FriendDelete("friend")) tick() verify { diff --git a/game/src/test/kotlin/world/gregs/voidps/world/community/friend/IgnoreTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/community/friend/IgnoreTest.kt index d86dafee4b..2404278fa0 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/community/friend/IgnoreTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/community/friend/IgnoreTest.kt @@ -34,7 +34,7 @@ internal class IgnoreTest : WorldTest() { val (player, client) = createClient("player") createPlayer("nuisance") - player.instructions.emit(IgnoreAdd("nuisance")) + player.instructions.send(IgnoreAdd("nuisance")) tick() verify { @@ -51,7 +51,7 @@ internal class IgnoreTest : WorldTest() { } createPlayer("nuisance") - player.instructions.emit(IgnoreAdd("nuisance")) + player.instructions.send(IgnoreAdd("nuisance")) tick() verify { @@ -63,7 +63,7 @@ internal class IgnoreTest : WorldTest() { fun `Add non-existent player`() = runTest { val (player, client) = createClient("player") - player.instructions.emit(IgnoreAdd("random")) + player.instructions.send(IgnoreAdd("random")) tick() verify { @@ -77,7 +77,7 @@ internal class IgnoreTest : WorldTest() { createPlayer("nuisance") player.ignores.add("nuisance") - player.instructions.emit(IgnoreAdd("nuisance")) + player.instructions.send(IgnoreAdd("nuisance")) tick() verify { @@ -91,7 +91,7 @@ internal class IgnoreTest : WorldTest() { createPlayer("friend") player.friends["friend"] = ClanRank.Friend - player.instructions.emit(IgnoreAdd("friend")) + player.instructions.send(IgnoreAdd("friend")) tick() verify { @@ -107,7 +107,7 @@ internal class IgnoreTest : WorldTest() { player.ignores.add("nuisance") nuisance.friends["player"] = ClanRank.Friend - player.instructions.emit(IgnoreDelete("nuisance")) + player.instructions.send(IgnoreDelete("nuisance")) tick() verify { @@ -122,7 +122,7 @@ internal class IgnoreTest : WorldTest() { val (nuisance, nuisanceClient) = createClient("nuisance") player.ignores.add("nuisance") - nuisance.instructions.emit(ChatPublic("rude", 0)) + nuisance.instructions.send(ChatPublic("rude", 0)) tick() verify { @@ -139,7 +139,7 @@ internal class IgnoreTest : WorldTest() { val (nuisance, client) = createClient("nuisance") player.ignores.add("nuisance") - nuisance.instructions.emit(ChatPrivate("player", "rude")) + nuisance.instructions.send(ChatPrivate("player", "rude")) tick() verify { @@ -152,13 +152,13 @@ internal class IgnoreTest : WorldTest() { val (player, playerClient) = createClient("player") val (nuisance, nuisanceClient) = createClient("nuisance") player.ownClan?.name = "clan" - player.instructions.emit(ClanChatJoin("player")) - nuisance.instructions.emit(ClanChatJoin("player")) + player.instructions.send(ClanChatJoin("player")) + nuisance.instructions.send(ClanChatJoin("player")) tick() player.ignores.add("nuisance") - nuisance.instructions.emit(ChatTypeChange(1)) - nuisance.instructions.emit(ChatPublic("rude", 0)) + nuisance.instructions.send(ChatTypeChange(1)) + nuisance.instructions.send(ChatPublic("rude", 0)) tick() verify { diff --git a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatTest.kt index 89137bc92d..51b207b4d9 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatTest.kt @@ -220,7 +220,7 @@ internal class CombatTest : WorldTest() { player.interfaceOption("combat_styles", "style3") runTest { - player.instructions.emit(InteractPlayer(target.index, 1)) + player.instructions.send(InteractPlayer(target.index, 1)) } tick(2) diff --git a/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt b/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt index d66dcaaee9..52fa2005f2 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt @@ -134,11 +134,11 @@ private fun getOptionIndex(id: String, componentId: String, option: String): Int } fun Player.playerOption(player: Player, option: String) = runTest { - instructions.emit(InteractPlayer(player.index, options.indexOf(option))) + instructions.send(InteractPlayer(player.index, options.indexOf(option))) } fun Player.walk(toTile: Tile) = runTest { - instructions.emit(Walk(toTile.x, toTile.y)) + instructions.send(Walk(toTile.x, toTile.y)) } fun Player.itemOnObject(obj: GameObject, itemSlot: Int, id: String, component: String = "inventory", inventory: String = "inventory") { @@ -171,16 +171,16 @@ fun Player.itemOnItem( } fun Player.npcOption(npc: NPC, option: String) = runTest { - instructions.emit(InteractNPC(npc.index, npc.def.options.indexOf(option) + 1)) + instructions.send(InteractNPC(npc.index, npc.def.options.indexOf(option) + 1)) } fun Player.objectOption(gameObject: GameObject, option: String, optionIndex: Int? = null) = runTest { val def = get().get(gameObject.intId) - instructions.emit(InteractObject(gameObject.intId, gameObject.tile.x, gameObject.tile.y, (optionIndex ?: def.optionsIndex(option)) + 1)) + instructions.send(InteractObject(gameObject.intId, gameObject.tile.x, gameObject.tile.y, (optionIndex ?: def.optionsIndex(option)) + 1)) } fun Player.floorItemOption(floorItem: FloorItem, option: String) = runTest { - instructions.emit(InteractFloorItem(floorItem.def.id, floorItem.tile.x, floorItem.tile.y, floorItem.def.floorOptions.indexOf(option))) + instructions.send(InteractFloorItem(floorItem.def.id, floorItem.tile.x, floorItem.tile.y, floorItem.def.floorOptions.indexOf(option))) } fun Inventory.set(index: Int, id: String, amount: Int = 1) = transaction { set(index, Item(id, amount)) } \ No newline at end of file diff --git a/game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt index 33ef4b5488..9cd27a57dd 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt @@ -40,7 +40,8 @@ import world.gregs.voidps.engine.event.Events import world.gregs.voidps.engine.inv.Inventory import world.gregs.voidps.engine.map.collision.CollisionDecoder import world.gregs.voidps.engine.map.collision.Collisions -import world.gregs.voidps.engine.map.collision.GameObjectCollision +import world.gregs.voidps.engine.map.collision.GameObjectCollisionAdd +import world.gregs.voidps.engine.map.collision.GameObjectCollisionRemove import world.gregs.voidps.gameModule import world.gregs.voidps.getTickStages import world.gregs.voidps.network.client.Client @@ -158,7 +159,8 @@ abstract class WorldTest : KoinTest { single { gameObjects } single { mapDefinitions } single { collisions } - single { objectCollision } + single { objectCollisionAdd } + single { objectCollisionRemove } }) } loadScripts() @@ -182,7 +184,7 @@ abstract class WorldTest : KoinTest { get(), handler, sequential = true) - engine = GameLoop(tickStages, mockk(relaxed = true)) + engine = GameLoop(tickStages) World.start(true) } players = get() @@ -240,8 +242,9 @@ abstract class WorldTest : KoinTest { private val weaponAnimationDefinitions: WeaponAnimationDefinitions by lazy { WeaponAnimationDefinitions().load() } private val enumDefinitions: EnumDefinitions by lazy { EnumDefinitions(EnumDecoder().load(cache), structDefinitions).load() } private val collisions: Collisions by lazy { Collisions() } - private val objectCollision: GameObjectCollision by lazy { GameObjectCollision(collisions) } - private val gameObjects: GameObjects by lazy { GameObjects(objectCollision, ZoneBatchUpdates(), objectDefinitions, storeUnused = true) } + private val objectCollisionAdd: GameObjectCollisionAdd by lazy { GameObjectCollisionAdd(collisions) } + private val objectCollisionRemove: GameObjectCollisionRemove by lazy { GameObjectCollisionRemove(collisions) } + private val gameObjects: GameObjects by lazy { GameObjects(objectCollisionAdd, objectCollisionRemove, ZoneBatchUpdates(), objectDefinitions, storeUnused = true) } private val mapDefinitions: MapDefinitions by lazy { MapDefinitions(CollisionDecoder( collisions), objectDefinitions, gameObjects, cache).loadCache() } private val fontDefinitions: FontDefinitions by lazy { FontDefinitions(FontDecoder().load(cache)).load() } val emptyTile = Tile(2655, 4640) diff --git a/network/src/main/kotlin/world/gregs/voidps/network/GameServer.kt b/network/src/main/kotlin/world/gregs/voidps/network/GameServer.kt index 87b006c4df..22e70b2a7d 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/GameServer.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/GameServer.kt @@ -43,7 +43,7 @@ class GameServer( val scope = CoroutineScope(dispatcher) job = scope.launch { try { - supervisorScope { + supervisorScope { logger.info { "Listening for requests on port ${port}..." } while (isActive) { val socket = server.accept() @@ -54,7 +54,7 @@ class GameServer( connect(read, write, socket.remoteAddress.toJavaAddress().hostname) } } - } + } } finally { stop() } diff --git a/network/src/main/kotlin/world/gregs/voidps/network/LoginServer.kt b/network/src/main/kotlin/world/gregs/voidps/network/LoginServer.kt index 2e7b0d1cad..b7f92dfe7d 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/LoginServer.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/LoginServer.kt @@ -3,7 +3,7 @@ package world.gregs.voidps.network import com.github.michaelbull.logging.InlineLogger import io.ktor.utils.io.* import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.SendChannel import world.gregs.voidps.cache.secure.RSA import world.gregs.voidps.cache.secure.Xtea import world.gregs.voidps.network.client.Client @@ -140,7 +140,7 @@ class LoginServer( } } - private suspend fun readPackets(client: Client, instructions: MutableSharedFlow, read: ByteReadChannel) { + private suspend fun readPackets(client: Client, instructions: SendChannel, read: ByteReadChannel) { while (!client.disconnected) { val cipher = client.cipherIn.nextInt() val opcode = (read.readUByte() - cipher) and 0xff @@ -155,7 +155,7 @@ class LoginServer( else -> decoder.length } val packet = read.readPacket(size = size) - decoder.decode(instructions, packet) + instructions.send(decoder.decode(packet) ?: continue) } } diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/AccountLoader.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/AccountLoader.kt index 6cd5153309..a6210e1c47 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/AccountLoader.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/AccountLoader.kt @@ -1,6 +1,6 @@ package world.gregs.voidps.network.login -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.SendChannel import world.gregs.voidps.network.client.Client import world.gregs.voidps.network.client.Instruction @@ -10,5 +10,5 @@ import world.gregs.voidps.network.client.Instruction interface AccountLoader { fun password(username: String): String? - suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): MutableSharedFlow? + suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): SendChannel? } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/Decoder.kt index e2ebce4bbd..5d8f9176bf 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/Decoder.kt @@ -1,12 +1,11 @@ package world.gregs.voidps.network.login.protocol import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction abstract class Decoder(val length: Int) { - abstract suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) + abstract suspend fun decode(packet: ByteReadPacket) : Instruction? companion object { const val BYTE = -1 diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/APCoordinateDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/APCoordinateDecoder.kt index 14564e3492..4902dbcd38 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/APCoordinateDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/APCoordinateDecoder.kt @@ -1,19 +1,19 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder import world.gregs.voidps.network.login.protocol.readShortAdd class APCoordinateDecoder : Decoder(12) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val x = packet.readShortLittleEndian() val first = packet.readShortAdd() val third = packet.readShortLittleEndian() val fourth = packet.readInt() val y = packet.readShortAdd() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AddFriendDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AddFriendDecoder.kt index 919a977be4..269de66f46 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AddFriendDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AddFriendDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.FriendAdd import world.gregs.voidps.network.login.protocol.Decoder @@ -9,8 +8,8 @@ import world.gregs.voidps.network.login.protocol.readString class AddFriendDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(FriendAdd(packet.readString())) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return FriendAdd(packet.readString()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AddIgnoreDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AddIgnoreDecoder.kt index ab505c5d75..d8863aefca 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AddIgnoreDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AddIgnoreDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.IgnoreAdd import world.gregs.voidps.network.login.protocol.Decoder @@ -9,8 +8,8 @@ import world.gregs.voidps.network.login.protocol.readString class AddIgnoreDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(IgnoreAdd(packet.readString())) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return IgnoreAdd(packet.readString()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AntiCheatDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AntiCheatDecoder.kt index d74b7d4238..d155f61df6 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AntiCheatDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/AntiCheatDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class AntiCheatDecoder : Decoder(2) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val packetsReceived = packet.readShort() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ChatTypeDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ChatTypeDecoder.kt index 83f058d9e2..4db37fb7b1 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ChatTypeDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ChatTypeDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ChatTypeChange import world.gregs.voidps.network.login.protocol.Decoder @@ -13,8 +12,8 @@ import world.gregs.voidps.network.login.protocol.Decoder class ChatTypeDecoder : Decoder(1) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(ChatTypeChange(packet.readUByte().toInt())) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return ChatTypeChange(packet.readUByte().toInt()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatJoinDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatJoinDecoder.kt index 136faffeaf..18262d70e1 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatJoinDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatJoinDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ClanChatJoin import world.gregs.voidps.network.login.protocol.Decoder @@ -9,8 +8,8 @@ import world.gregs.voidps.network.login.protocol.readString class ClanChatJoinDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(ClanChatJoin(packet.readString())) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return ClanChatJoin(packet.readString()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatKickDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatKickDecoder.kt index 1ffee7e6b2..c80ab7600b 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatKickDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatKickDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ClanChatKick import world.gregs.voidps.network.login.protocol.Decoder @@ -9,8 +8,8 @@ import world.gregs.voidps.network.login.protocol.readString class ClanChatKickDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(ClanChatKick(packet.readString())) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return ClanChatKick(packet.readString()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatNameDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatNameDecoder.kt index de7ca2b4f1..b93683390f 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatNameDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatNameDecoder.kt @@ -1,16 +1,16 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder import world.gregs.voidps.network.login.protocol.readString class ClanChatNameDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val index = packet.readInt() val name = packet.readString() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatRankDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatRankDecoder.kt index 612ff94862..e3028b1859 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatRankDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ClanChatRankDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ClanChatRank import world.gregs.voidps.network.login.protocol.Decoder @@ -10,10 +9,10 @@ import world.gregs.voidps.network.login.protocol.readString class ClanChatRankDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val rank = packet.readByteSubtract() val name = packet.readString() - instructions.emit(ClanChatRank(name, rank)) + return ClanChatRank(name, rank) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ConsoleCommandDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ConsoleCommandDecoder.kt index fa66d7ad1b..f28ffa7535 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ConsoleCommandDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ConsoleCommandDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ExecuteCommand import world.gregs.voidps.network.login.protocol.Decoder @@ -10,13 +9,13 @@ import world.gregs.voidps.network.login.protocol.readString class ConsoleCommandDecoder : Decoder(BYTE) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { packet.readUByte() packet.readUByte() val command = packet.readString() val parts = command.split(" ") val prefix = parts[0] - instructions.emit(ExecuteCommand(prefix, command.removePrefix(prefix).trim())) + return ExecuteCommand(prefix, command.removePrefix(prefix).trim()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DeleteFriendDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DeleteFriendDecoder.kt index 452ee5b75a..55878509d7 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DeleteFriendDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DeleteFriendDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.FriendDelete import world.gregs.voidps.network.login.protocol.Decoder @@ -9,8 +8,8 @@ import world.gregs.voidps.network.login.protocol.readString class DeleteFriendDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(FriendDelete(packet.readString())) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return FriendDelete(packet.readString()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DeleteIgnoreDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DeleteIgnoreDecoder.kt index 20b2757f76..89f70df3f9 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DeleteIgnoreDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DeleteIgnoreDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.IgnoreDelete import world.gregs.voidps.network.login.protocol.Decoder @@ -9,8 +8,8 @@ import world.gregs.voidps.network.login.protocol.readString class DeleteIgnoreDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(IgnoreDelete(packet.readString())) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return IgnoreDelete(packet.readString()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DialogueContinueDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DialogueContinueDecoder.kt index 2f656cf5dd..a399edf398 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DialogueContinueDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/DialogueContinueDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.definition.data.InterfaceDefinition import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractDialogue @@ -11,10 +10,10 @@ import world.gregs.voidps.network.login.protocol.readUnsignedIntMiddle class DialogueContinueDecoder : Decoder(6) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val button = packet.readShortAdd() val packed = packet.readUnsignedIntMiddle() - instructions.emit(InteractDialogue(InterfaceDefinition.id(packed), InterfaceDefinition.componentId(packed), button)) + return InteractDialogue(InterfaceDefinition.id(packed), InterfaceDefinition.componentId(packed), button) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemExamineDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemExamineDecoder.kt index bf87051b04..7169519407 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemExamineDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemExamineDecoder.kt @@ -1,16 +1,15 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ExamineItem import world.gregs.voidps.network.login.protocol.Decoder class FloorItemExamineDecoder : Decoder(2) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val itemId = packet.readShort().toInt() - instructions.emit(ExamineItem(itemId)) + return ExamineItem(itemId) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption1Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption1Decoder.kt index d732f63bf1..ad4f7fb3d3 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption1Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption1Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractFloorItem import world.gregs.voidps.network.login.protocol.Decoder @@ -9,12 +8,12 @@ import world.gregs.voidps.network.login.protocol.readBooleanSubtract class FloorItemOption1Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val id = packet.readShort().toInt() val x = packet.readShort().toInt() val y = packet.readShort().toInt() val run = packet.readBooleanSubtract() - instructions.emit(InteractFloorItem(id, x, y, 0)) + return InteractFloorItem(id, x, y, 0) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption2Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption2Decoder.kt index 31549c61dd..0944b82487 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption2Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption2Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractFloorItem import world.gregs.voidps.network.login.protocol.Decoder @@ -11,12 +10,12 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class FloorItemOption2Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val y = packet.readUnsignedShortAdd() val id = packet.readShortAdd() val x = packet.readShortLittleEndian().toInt() val run = packet.readBooleanInverse() - instructions.emit(InteractFloorItem(id, x, y, 1)) + return InteractFloorItem(id, x, y, 1) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption3Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption3Decoder.kt index 73aff75fc5..3c7f71490a 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption3Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption3Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractFloorItem import world.gregs.voidps.network.login.protocol.Decoder @@ -11,12 +10,12 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAddLittle class FloorItemOption3Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val id = packet.readShort().toInt() val x = packet.readUnsignedShortAdd() val run = packet.readBoolean() val y = packet.readUnsignedShortAddLittle() - instructions.emit(InteractFloorItem(id, x, y, 2)) + return InteractFloorItem(id, x, y, 2) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption4Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption4Decoder.kt index 6a1c001f70..0d0872d5bc 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption4Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption4Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractFloorItem import world.gregs.voidps.network.login.protocol.Decoder @@ -10,12 +9,12 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class FloorItemOption4Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val run = packet.readBooleanSubtract() val x = packet.readUnsignedShortAdd() val y = packet.readShortLittleEndian().toInt() val id = packet.readShort().toInt() - instructions.emit(InteractFloorItem(id, x, y, 3)) + return InteractFloorItem(id, x, y, 3) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption5Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption5Decoder.kt index 589398cd3c..73e118097d 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption5Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/FloorItemOption5Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractFloorItem import world.gregs.voidps.network.login.protocol.Decoder @@ -10,12 +9,12 @@ import world.gregs.voidps.network.login.protocol.readShortAdd class FloorItemOption5Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val y = packet.readShort().toInt() val x = packet.readShortAdd() val run = packet.readBooleanInverse() val id = packet.readShortAdd() - instructions.emit(InteractFloorItem(id, x, y, 4)) + return InteractFloorItem(id, x, y, 4) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/HyperlinkDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/HyperlinkDecoder.kt index 861b8be712..7ebddcabdf 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/HyperlinkDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/HyperlinkDecoder.kt @@ -1,17 +1,17 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder import world.gregs.voidps.network.login.protocol.readString class HyperlinkDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val name = packet.readString() val script = packet.readString() val third = packet.readByte() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/IntegerEntryDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/IntegerEntryDecoder.kt index f606bf7c95..29339d3184 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/IntegerEntryDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/IntegerEntryDecoder.kt @@ -1,16 +1,15 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.EnterInt import world.gregs.voidps.network.login.protocol.Decoder class IntegerEntryDecoder : Decoder(4) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val integer = packet.readInt() - instructions.emit(EnterInt(integer)) + return EnterInt(integer) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceClosedDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceClosedDecoder.kt index 7b7083590f..d1d4b72003 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceClosedDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceClosedDecoder.kt @@ -1,15 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InterfaceClosedInstruction import world.gregs.voidps.network.login.protocol.Decoder class InterfaceClosedDecoder : Decoder(0) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(InterfaceClosedInstruction) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return InterfaceClosedInstruction } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnFloorItemDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnFloorItemDecoder.kt index 85bd86b455..e126967acb 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnFloorItemDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnFloorItemDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.definition.data.InterfaceDefinition import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractInterfaceFloorItem @@ -12,7 +11,7 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class InterfaceOnFloorItemDecoder : Decoder(15) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val x = packet.readShortLittleEndian().toInt() val floorItem = packet.readUnsignedShortAdd() val itemSlot = packet.readShortLittleEndian().toInt() @@ -20,7 +19,7 @@ class InterfaceOnFloorItemDecoder : Decoder(15) { val run = packet.readBoolean() val item = packet.readUnsignedShortAdd() val packed = packet.readUnsignedIntMiddle() - instructions.emit(InteractInterfaceFloorItem( + return InteractInterfaceFloorItem( floorItem, x, y, @@ -28,7 +27,7 @@ class InterfaceOnFloorItemDecoder : Decoder(15) { InterfaceDefinition.componentId(packed), item, itemSlot - )) + ) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnInterfaceDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnInterfaceDecoder.kt index 23c9d43a5e..fc3557ab6e 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnInterfaceDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnInterfaceDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.definition.data.InterfaceDefinition import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractInterfaceItem @@ -11,24 +10,22 @@ import world.gregs.voidps.network.login.protocol.readUnsignedIntInverseMiddle class InterfaceOnInterfaceDecoder : Decoder(16) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val toPacked = packet.readInt() val fromPacked = packet.readUnsignedIntInverseMiddle() val fromSlot = packet.readShortAdd() val fromItem = packet.readShort().toInt() val toSlot = packet.readShortAdd() val toItem = packet.readShort().toInt() - instructions.emit( - InteractInterfaceItem( - fromItem, - toItem, - fromSlot, - toSlot, - InterfaceDefinition.id(fromPacked), - InterfaceDefinition.componentId(fromPacked), - InterfaceDefinition.id(toPacked), - InterfaceDefinition.componentId(toPacked) - ) + return InteractInterfaceItem( + fromItem, + toItem, + fromSlot, + toSlot, + InterfaceDefinition.id(fromPacked), + InterfaceDefinition.componentId(fromPacked), + InterfaceDefinition.id(toPacked), + InterfaceDefinition.componentId(toPacked) ) } diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnNpcDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnNpcDecoder.kt index 732c29a8ac..dcfd5c1345 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnNpcDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnNpcDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.definition.data.InterfaceDefinition import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractInterfaceNPC @@ -12,19 +11,19 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class InterfaceOnNpcDecoder : Decoder(11) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val slot = packet.readShortAddLittle() val packed = packet.readInt() val npc = packet.readShortLittleEndian().toInt() val run = packet.readBooleanAdd() val itemId = packet.readUnsignedShortAdd() - instructions.emit(InteractInterfaceNPC( + return InteractInterfaceNPC( npc, InterfaceDefinition.id(packed), InterfaceDefinition.componentId(packed), itemId, slot - )) + ) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnObjectDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnObjectDecoder.kt index 7a2bdf478e..e3aac39fde 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnObjectDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnObjectDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.definition.data.InterfaceDefinition import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractInterfaceObject @@ -9,7 +8,7 @@ import world.gregs.voidps.network.login.protocol.* class InterfaceOnObjectDecoder : Decoder(15) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val item = packet.readShort().toInt() val x = packet.readShortAddLittle() val packed = packet.readIntLittleEndian() @@ -17,7 +16,7 @@ class InterfaceOnObjectDecoder : Decoder(15) { val run = packet.readBooleanSubtract() val index = packet.readShortLittleEndian().toInt() val objectId = packet.readUnsignedShortLittle() - instructions.emit(InteractInterfaceObject( + return InteractInterfaceObject( objectId, x, y, @@ -25,7 +24,7 @@ class InterfaceOnObjectDecoder : Decoder(15) { InterfaceDefinition.componentId(packed), item, index - )) + ) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnPlayerDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnPlayerDecoder.kt index 1e1412afa1..2f3830b263 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnPlayerDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOnPlayerDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.definition.data.InterfaceDefinition import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractInterfacePlayer @@ -12,19 +11,19 @@ import world.gregs.voidps.network.login.protocol.readUnsignedIntInverseMiddle class InterfaceOnPlayerDecoder : Decoder(11) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val slot = packet.readShortAddLittle() val index = packet.readShortLittleEndian().toInt() val itemId = packet.readShortLittleEndian().toInt() val packed = packet.readUnsignedIntInverseMiddle() val run = packet.readBooleanInverse() - instructions.emit(InteractInterfacePlayer( + return InteractInterfacePlayer( index, InterfaceDefinition.id(packed), InterfaceDefinition.componentId(packed), itemId, slot - )) + ) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOptionDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOptionDecoder.kt index acc1174376..0626dbd70c 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOptionDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceOptionDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.definition.data.InterfaceDefinition import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractInterface @@ -9,15 +8,15 @@ import world.gregs.voidps.network.login.protocol.Decoder class InterfaceOptionDecoder(private val index: Int) : Decoder(8) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val packed = packet.readInt() - instructions.emit(InteractInterface( + return InteractInterface( interfaceId = InterfaceDefinition.id(packed), componentId = InterfaceDefinition.componentId(packed), itemId = packet.readShort().toInt(), itemSlot = packet.readShort().toInt(), option = index - )) + ) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceSwitchComponentsDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceSwitchComponentsDecoder.kt index 3dcfd875fa..153a0f2237 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceSwitchComponentsDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/InterfaceSwitchComponentsDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.definition.data.InterfaceDefinition import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.MoveInventoryItem @@ -11,14 +10,14 @@ import world.gregs.voidps.network.login.protocol.readUnsignedIntMiddle class InterfaceSwitchComponentsDecoder : Decoder(16) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val fromPacked = packet.readInt() val toSlot = packet.readShortLittleEndian().toInt() val toPacked = packet.readUnsignedIntMiddle() val toItemId = packet.readShort().toInt() val fromSlot = packet.readShortAddLittle() val fromItemId = packet.readShortAddLittle() - instructions.emit(MoveInventoryItem( + return MoveInventoryItem( fromId = InterfaceDefinition.id(fromPacked), fromComponentId = InterfaceDefinition.componentId(fromPacked), fromItemId = fromItemId, @@ -27,7 +26,7 @@ class InterfaceSwitchComponentsDecoder : Decoder(16) { toComponentId = InterfaceDefinition.componentId(toPacked), toItemId = toItemId, toSlot = toSlot - )) + ) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/KeysPressedDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/KeysPressedDecoder.kt index 727c753e80..35a251effb 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/KeysPressedDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/KeysPressedDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder @@ -11,11 +10,12 @@ import world.gregs.voidps.network.login.protocol.Decoder class KeysPressedDecoder : Decoder(BYTE) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val keys = ArrayList>() while (packet.remaining > 0) { keys.add(packet.readUByte().toInt() to packet.readUShort().toInt()) } + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LatencyDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LatencyDecoder.kt index db997641af..bdc622a1d7 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LatencyDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LatencyDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class LatencyDecoder : Decoder(2) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val value = packet.readShort().toInt() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LobbyOnlineStatusDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LobbyOnlineStatusDecoder.kt index e7f6df320c..640f1a7541 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LobbyOnlineStatusDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LobbyOnlineStatusDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder @@ -10,10 +9,11 @@ import world.gregs.voidps.network.login.protocol.Decoder */ class LobbyOnlineStatusDecoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val first = packet.readByte() val status = packet.readByte() val second = packet.readByte() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LobbyWorldListRefreshDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LobbyWorldListRefreshDecoder.kt index 5b69c27a39..9d400a4935 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LobbyWorldListRefreshDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/LobbyWorldListRefreshDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder @@ -10,8 +9,9 @@ import world.gregs.voidps.network.login.protocol.Decoder */ class LobbyWorldListRefreshDecoder : Decoder(4) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val latency = packet.readInt() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/MovedCameraDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/MovedCameraDecoder.kt index 690536bdc8..eda6b7b1e5 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/MovedCameraDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/MovedCameraDecoder.kt @@ -1,16 +1,16 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class MovedCameraDecoder : Decoder(4) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val pitch = packet.readUShort().toInt() val yaw = packet.readUShort().toInt() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/MovedMouseDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/MovedMouseDecoder.kt index e9ca6359f9..5222c09b0d 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/MovedMouseDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/MovedMouseDecoder.kt @@ -1,12 +1,12 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class MovedMouseDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCExamineDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCExamineDecoder.kt index 81cf70f233..be1f21a173 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCExamineDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCExamineDecoder.kt @@ -1,16 +1,15 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ExamineNpc import world.gregs.voidps.network.login.protocol.Decoder class NPCExamineDecoder : Decoder(2) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val npcId = packet.readShort().toInt() - instructions.emit(ExamineNpc(npcId)) + return ExamineNpc(npcId) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption1Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption1Decoder.kt index e01174559f..49d23c51b2 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption1Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption1Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractNPC import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readBoolean class NPCOption1Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val run = packet.readBoolean() val npcIndex = packet.readShortLittleEndian().toInt() - instructions.emit(InteractNPC(npcIndex, 1)) + return InteractNPC(npcIndex, 1) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption2Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption2Decoder.kt index df1ade26fe..6a66aab78f 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption2Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption2Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractNPC import world.gregs.voidps.network.login.protocol.Decoder @@ -10,10 +9,10 @@ import world.gregs.voidps.network.login.protocol.readShortAddLittle class NPCOption2Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val npcIndex = packet.readShortAddLittle() val run = packet.readBooleanAdd() - instructions.emit(InteractNPC(npcIndex, 2)) + return InteractNPC(npcIndex, 2) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption3Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption3Decoder.kt index ee67487a0a..20b96b2995 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption3Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption3Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractNPC import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readBoolean class NPCOption3Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val npcIndex = packet.readShort().toInt() val run = packet.readBoolean() - instructions.emit(InteractNPC(npcIndex, 3)) + return InteractNPC(npcIndex, 3) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption4Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption4Decoder.kt index a1edacb4f5..1357dc6cdb 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption4Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption4Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractNPC import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readBooleanAdd class NPCOption4Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val npcIndex = packet.readShortLittleEndian().toInt() val run = packet.readBooleanAdd() - instructions.emit(InteractNPC(npcIndex, 4)) + return InteractNPC(npcIndex, 4) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption5Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption5Decoder.kt index be1d6b0411..c748988a43 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption5Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/NPCOption5Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractNPC import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readBooleanAdd class NPCOption5Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val run = packet.readBooleanAdd() val npcIndex = packet.readShortLittleEndian().toInt() - instructions.emit(InteractNPC(npcIndex, 5)) + return InteractNPC(npcIndex, 5) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectExamineDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectExamineDecoder.kt index 5d384ebaed..8881e26057 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectExamineDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectExamineDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ExamineObject import world.gregs.voidps.network.login.protocol.Decoder @@ -9,9 +8,9 @@ import world.gregs.voidps.network.login.protocol.Decoder class ObjectExamineDecoder : Decoder(2) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val objectId = packet.readUShort().toInt() - instructions.emit(ExamineObject(objectId)) + return ExamineObject(objectId) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption1Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption1Decoder.kt index 80ffdff681..aac6d19f8d 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption1Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption1Decoder.kt @@ -2,7 +2,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.bits.* import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractObject import world.gregs.voidps.network.login.protocol.Decoder @@ -12,12 +11,12 @@ import world.gregs.voidps.network.login.protocol.readShortAddLittle class ObjectOption1Decoder : Decoder(7) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val run = packet.readBooleanSubtract() val x = packet.readShortAddLittle() val y = packet.readUShort().reverseByteOrder().toInt() val objectId = packet.readUShort().toInt() - instructions.emit(InteractObject(objectId, x, y, 1)) + return InteractObject(objectId, x, y, 1) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption2Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption2Decoder.kt index bf3e3ae8eb..038bf6faad 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption2Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption2Decoder.kt @@ -1,19 +1,18 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractObject import world.gregs.voidps.network.login.protocol.* class ObjectOption2Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val y = packet.readShortAddLittle() val x = packet.readUnsignedShortAdd() val run = packet.readBooleanSubtract() val objectId = packet.readUnsignedShortAddLittle() - instructions.emit(InteractObject(objectId, x, y, 2)) + return InteractObject(objectId, x, y, 2) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption3Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption3Decoder.kt index e052027ff5..470f323758 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption3Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption3Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractObject import world.gregs.voidps.network.login.protocol.Decoder @@ -11,12 +10,12 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAddLittle class ObjectOption3Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val y = packet.readUnsignedShortAdd() val objectId = packet.readUnsignedShortAddLittle() val x = packet.readShortLittleEndian().toInt() val run = packet.readBooleanAdd() - instructions.emit(InteractObject(objectId, x, y, 3)) + return InteractObject(objectId, x, y, 3) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption4Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption4Decoder.kt index 0f342f9a6f..c01cff1641 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption4Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption4Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractObject import world.gregs.voidps.network.login.protocol.Decoder @@ -10,12 +9,12 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class ObjectOption4Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val run = packet.readBooleanAdd() val objectId = packet.readUnsignedShortAdd() val x = packet.readUnsignedShortAdd() val y = packet.readShortLittleEndian().toInt() - instructions.emit(InteractObject(objectId, x, y, 4)) + return InteractObject(objectId, x, y, 4) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption5Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption5Decoder.kt index da05c76ff9..173d59ff5e 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption5Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ObjectOption5Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractObject import world.gregs.voidps.network.login.protocol.Decoder @@ -11,12 +10,12 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class ObjectOption5Decoder : Decoder(7) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val y = packet.readShortLittleEndian().toInt() val run = packet.readBooleanAdd() val x = packet.readShortAddLittle() val objectId = packet.readUnsignedShortAdd() and 0xffff - instructions.emit(InteractObject(objectId, x, y, 5)) + return InteractObject(objectId, x, y, 5) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PingDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PingDecoder.kt index 598f3a72f1..08ede3f259 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PingDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PingDecoder.kt @@ -1,13 +1,13 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class PingDecoder : Decoder(0) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption1Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption1Decoder.kt index a07e20e8b4..29ec3d9023 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption1Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption1Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractPlayer import world.gregs.voidps.network.login.protocol.Decoder @@ -10,10 +9,10 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAddLittle class PlayerOption1Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val index = packet.readUnsignedShortAddLittle() packet.readByteInverse() - instructions.emit(InteractPlayer(index, 1)) + return InteractPlayer(index, 1) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption2Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption2Decoder.kt index 6f83a7b9bc..67bbb00f8d 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption2Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption2Decoder.kt @@ -1,17 +1,16 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractPlayer import world.gregs.voidps.network.login.protocol.Decoder class PlayerOption2Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { packet.readByte() val index = packet.readShort().toInt() - instructions.emit(InteractPlayer(index, 2)) + return InteractPlayer(index, 2) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption3Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption3Decoder.kt index 395b87e25c..90d0972edf 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption3Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption3Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractPlayer import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readByteSubtract class PlayerOption3Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { packet.readByteSubtract() val index = packet.readShortLittleEndian().toInt() - instructions.emit(InteractPlayer(index, 3)) + return InteractPlayer(index, 3) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption4Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption4Decoder.kt index a4913ca124..e6bd6876aa 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption4Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption4Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractPlayer import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readByteAdd class PlayerOption4Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val index = packet.readShort().toInt() packet.readByteAdd() - instructions.emit(InteractPlayer(index, 4)) + return InteractPlayer(index, 4) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption5Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption5Decoder.kt index 974ce0b907..6ca61c917c 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption5Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption5Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractPlayer import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class PlayerOption5Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val index = packet.readUnsignedShortAdd() packet.readByte() - instructions.emit(InteractPlayer(index, 5)) + return InteractPlayer(index, 5) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption6Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption6Decoder.kt index 5c32df0064..d45b881a08 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption6Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption6Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractPlayer import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class PlayerOption6Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { packet.readByte() val index = packet.readUnsignedShortAdd() - instructions.emit(InteractPlayer(index, 6)) + return InteractPlayer(index, 6) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption7Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption7Decoder.kt index e7d1d98f77..6e5db37e3d 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption7Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption7Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractPlayer import world.gregs.voidps.network.login.protocol.Decoder @@ -10,10 +9,10 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class PlayerOption7Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val index = packet.readUnsignedShortAdd() packet.readByteAdd() - instructions.emit(InteractPlayer(index, 7)) + return InteractPlayer(index, 7) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption8Decoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption8Decoder.kt index 71c7401053..43759876f7 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption8Decoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PlayerOption8Decoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.InteractPlayer import world.gregs.voidps.network.login.protocol.Decoder @@ -9,10 +8,10 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class PlayerOption8Decoder : Decoder(3) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { packet.readByte() val index = packet.readUnsignedShortAdd() - instructions.emit(InteractPlayer(index, 8)) + return InteractPlayer(index, 8) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PrivateDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PrivateDecoder.kt index eea86245db..4d5a9c109e 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PrivateDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PrivateDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.secure.Huffman import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ChatPrivate @@ -11,10 +10,10 @@ import world.gregs.voidps.network.login.protocol.readString class PrivateDecoder(private val huffman: Huffman) : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val name = packet.readString() val message = huffman.decompress(length = packet.readSmart(), message = packet.readBytes(packet.remaining.toInt())) ?: "" - instructions.emit(ChatPrivate(name, message)) + return ChatPrivate(name, message) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PrivateQuickChatDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PrivateQuickChatDecoder.kt index c212a20616..e6426c422d 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PrivateQuickChatDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PrivateQuickChatDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.QuickChatPrivate import world.gregs.voidps.network.login.protocol.Decoder @@ -10,11 +9,11 @@ import world.gregs.voidps.network.login.protocol.readString class PrivateQuickChatDecoder : Decoder(BYTE) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val name = packet.readString() val file = packet.readUShort().toInt() val data = packet.readBytes(packet.remaining.toInt()) - instructions.emit(QuickChatPrivate(name, file, data)) + return QuickChatPrivate(name, file, data) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PublicDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PublicDecoder.kt index dd88bb8473..beb6027745 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PublicDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PublicDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.cache.secure.Huffman import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ChatPublic @@ -11,10 +10,10 @@ import world.gregs.voidps.network.login.protocol.readSmart class PublicDecoder(private val huffman: Huffman) : Decoder(BYTE) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val effects = (packet.readUByte().toInt() shl 8) or packet.readUByte().toInt() val message = huffman.decompress(length = packet.readSmart(), message = packet.readBytes(packet.remaining.toInt())) ?: "" - instructions.emit(ChatPublic(message, effects)) + return ChatPublic(message, effects) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PublicQuickChatDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PublicQuickChatDecoder.kt index 2b6329caa4..42ff6e1b27 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PublicQuickChatDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/PublicQuickChatDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.QuickChatPublic import world.gregs.voidps.network.login.protocol.Decoder @@ -9,11 +8,11 @@ import world.gregs.voidps.network.login.protocol.Decoder class PublicQuickChatDecoder : Decoder(BYTE) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val script = packet.readByte().toInt() val file = packet.readUShort().toInt() val data = packet.readBytes(packet.remaining.toInt()) - instructions.emit(QuickChatPublic(script, file, data)) + return QuickChatPublic(script, file, data) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ReflectionResponseDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ReflectionResponseDecoder.kt index 8df48b088f..d74091ce79 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ReflectionResponseDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ReflectionResponseDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class ReflectionResponseDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { packet.readByte() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/RegionLoadedDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/RegionLoadedDecoder.kt index 5b4fb7af82..fe099eecc9 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/RegionLoadedDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/RegionLoadedDecoder.kt @@ -1,15 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.FinishRegionLoad import world.gregs.voidps.network.login.protocol.Decoder class RegionLoadedDecoder : Decoder(0) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(FinishRegionLoad) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return FinishRegionLoad } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/RegionLoadingDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/RegionLoadingDecoder.kt index 3ce6da9c97..dca0c4deb5 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/RegionLoadingDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/RegionLoadingDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class RegionLoadingDecoder : Decoder(4) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { packet.readInt() // 1057001181 + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ReportAbuseDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ReportAbuseDecoder.kt index fd265e6004..e452ad600c 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ReportAbuseDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ReportAbuseDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ReportAbuse import world.gregs.voidps.network.login.protocol.Decoder @@ -9,12 +8,12 @@ import world.gregs.voidps.network.login.protocol.readString class ReportAbuseDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val name = packet.readString() val type = packet.readByte().toInt() val integer = packet.readByte().toInt() val string = packet.readString() - instructions.emit(ReportAbuse(name, type, integer, string)) + return ReportAbuse(name, type, integer, string) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ResumeObjDialogueDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ResumeObjDialogueDecoder.kt index accb5a3d3d..df0fbef019 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ResumeObjDialogueDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ResumeObjDialogueDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class ResumeObjDialogueDecoder : Decoder(2) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val value = packet.readShort().toInt() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ScreenChangeDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ScreenChangeDecoder.kt index 55900f794e..324bfe13c4 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ScreenChangeDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ScreenChangeDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.ChangeDisplayMode import world.gregs.voidps.network.login.protocol.Decoder @@ -9,13 +8,13 @@ import world.gregs.voidps.network.login.protocol.Decoder class ScreenChangeDecoder : Decoder(6) { @OptIn(ExperimentalUnsignedTypes::class) - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(ChangeDisplayMode( + override suspend fun decode(packet: ByteReadPacket): Instruction { + return ChangeDisplayMode( displayMode = packet.readUByte().toInt(), width = packet.readUShort().toInt(), height = packet.readUShort().toInt(), antialiasLevel = packet.readUByte().toInt() - )) + ) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/SecondaryTeleportDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/SecondaryTeleportDecoder.kt index ce90d6f6c1..4f5b3720bb 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/SecondaryTeleportDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/SecondaryTeleportDecoder.kt @@ -1,16 +1,16 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder import world.gregs.voidps.network.login.protocol.readShortAddLittle class SecondaryTeleportDecoder : Decoder(4) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val x = packet.readShortAddLittle() val y = packet.readShortLittleEndian().toInt() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/StringEntryDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/StringEntryDecoder.kt index f2a85ae6a0..5da795a0d1 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/StringEntryDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/StringEntryDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.EnterString import world.gregs.voidps.network.login.protocol.Decoder @@ -9,8 +8,8 @@ import world.gregs.voidps.network.login.protocol.readString class StringEntryDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { - instructions.emit(EnterString(packet.readString())) + override suspend fun decode(packet: ByteReadPacket): Instruction { + return EnterString(packet.readString()) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ToolkitPreferencesDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ToolkitPreferencesDecoder.kt index 7667ad7fe4..6dfaa0165e 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ToolkitPreferencesDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/ToolkitPreferencesDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class ToolkitPreferencesDecoder : Decoder(BYTE) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { packet.readByte() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/UnknownDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/UnknownDecoder.kt index 35c5c308fd..3cf4484aa3 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/UnknownDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/UnknownDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class UnknownDecoder : Decoder(2) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val unknown = packet.readShort() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WalkMapDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WalkMapDecoder.kt index 7298951a05..17d7bb99f1 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WalkMapDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WalkMapDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.Walk import world.gregs.voidps.network.login.protocol.Decoder @@ -10,11 +9,11 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class WalkMapDecoder : Decoder(5) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val y = packet.readShortLittleEndian().toInt() val running = packet.readBooleanAdd() val x = packet.readUnsignedShortAdd() - instructions.emit(Walk(x, y)) + return Walk(x, y) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WalkMiniMapDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WalkMiniMapDecoder.kt index 3b53ad0a4d..6272bffcda 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WalkMiniMapDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WalkMiniMapDecoder.kt @@ -1,7 +1,6 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.client.instruction.Walk import world.gregs.voidps.network.login.protocol.Decoder @@ -10,7 +9,7 @@ import world.gregs.voidps.network.login.protocol.readUnsignedShortAdd class WalkMiniMapDecoder : Decoder(18) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val y = packet.readShortLittleEndian().toInt() val running = packet.readBooleanAdd() val x = packet.readUnsignedShortAdd() @@ -24,7 +23,7 @@ class WalkMiniMapDecoder : Decoder(18) { packet.readShort()//X in region? packet.readShort()//Y in region? packet.readByte()//63 - instructions.emit(Walk(x, y)) + return Walk(x, y) } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowClickDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowClickDecoder.kt index 6ee612147d..43c3633c3a 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowClickDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowClickDecoder.kt @@ -1,15 +1,15 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class WindowClickDecoder : Decoder(6) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val packed = packet.readShort().toInt() val position = packet.readInt() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowFocusDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowFocusDecoder.kt index 693b8084f9..b3966df2b0 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowFocusDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowFocusDecoder.kt @@ -1,15 +1,15 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder import world.gregs.voidps.network.login.protocol.readBoolean class WindowFocusDecoder : Decoder(1) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val focused = packet.readBoolean() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowHoveredDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowHoveredDecoder.kt index 646b110e8d..99cf23bfc8 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowHoveredDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WindowHoveredDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class WindowHoveredDecoder : Decoder(4) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { val unknown = packet.readInt() + return null } } \ No newline at end of file diff --git a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WorldMapCloseDecoder.kt b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WorldMapCloseDecoder.kt index 9c31e6d44c..6f2a4658ae 100644 --- a/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WorldMapCloseDecoder.kt +++ b/network/src/main/kotlin/world/gregs/voidps/network/login/protocol/decode/WorldMapCloseDecoder.kt @@ -1,14 +1,14 @@ package world.gregs.voidps.network.login.protocol.decode import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow import world.gregs.voidps.network.client.Instruction import world.gregs.voidps.network.login.protocol.Decoder class WorldMapCloseDecoder : Decoder(4) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction? { packet.readInt() + return null } } \ No newline at end of file diff --git a/network/src/test/kotlin/world/gregs/voidps/network/LoginServerTest.kt b/network/src/test/kotlin/world/gregs/voidps/network/LoginServerTest.kt index a4a90ad716..805502e6a1 100644 --- a/network/src/test/kotlin/world/gregs/voidps/network/LoginServerTest.kt +++ b/network/src/test/kotlin/world/gregs/voidps/network/LoginServerTest.kt @@ -3,9 +3,10 @@ package world.gregs.voidps.network import io.ktor.utils.io.* import io.ktor.utils.io.core.* import kotlinx.coroutines.cancelAndJoin +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.ClosedReceiveChannelException +import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.* @@ -31,7 +32,7 @@ internal class LoginServerTest { private val protocol = Array(10) { null } private lateinit var accounts: AccountLoader private lateinit var passwordManager: PasswordManager - private lateinit var instructions: MutableSharedFlow + private lateinit var instructions: Channel private var client: Client? = null private var password: String? = null @@ -41,11 +42,11 @@ internal class LoginServerTest { fun setup() { client = null password = null - instructions = MutableSharedFlow(replay = 1) + instructions = Channel(capacity = 1) accounts = object : AccountLoader { override fun password(username: String) = password - override suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): MutableSharedFlow? { + override suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): SendChannel { this@LoginServerTest.client = client client.send(0) { writeByte(Response.SUCCESS) @@ -54,9 +55,9 @@ internal class LoginServerTest { } } protocol[0] = object : Decoder(4) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val value = packet.readInt() - instructions.emit(TestInstruction(value)) + return TestInstruction(value) } } passwordManager = PasswordManager(accounts) @@ -74,9 +75,9 @@ internal class LoginServerTest { val readChannel = ByteChannel(autoFlush = true) val writeChannel = ByteChannel(autoFlush = true) protocol[0] = object : Decoder(size) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val value = packet.readInt() - instructions.emit(TestInstruction(value)) + return TestInstruction(value) } } @@ -89,7 +90,7 @@ internal class LoginServerTest { assertEquals(118, writeChannel.readByte().toInt()) // packet 0 assertEquals(Response.SUCCESS, writeChannel.readByte().toInt()) writeTestPacket(readChannel, size) - val instruction = instructions.replayCache.first() + val instruction = instructions.tryReceive().getOrNull() assertNotNull(instruction) assertEquals(TestInstruction(42), instruction) job.cancelAndJoin() @@ -225,7 +226,7 @@ internal class LoginServerTest { accounts = object : AccountLoader { override fun password(username: String) = null - override suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): MutableSharedFlow? { + override suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): SendChannel? { client.disconnect(Response.ACCOUNT_ONLINE) return null } @@ -273,7 +274,7 @@ internal class LoginServerTest { assertEquals(118, writeChannel.readByte().toInt()) // packet 0 assertEquals(Response.SUCCESS, writeChannel.readByte().toInt()) writeTestPacket(readChannel) - assertTrue(instructions.replayCache.isEmpty()) + assertNull(instructions.tryReceive().getOrNull()) assertTrue(writeChannel.isClosedForRead) job.cancelAndJoin() @@ -349,9 +350,9 @@ internal class LoginServerTest { val readChannel = ByteChannel(autoFlush = true) val writeChannel = ByteChannel(autoFlush = true) protocol[0] = object : Decoder(4) { - override suspend fun decode(instructions: MutableSharedFlow, packet: ByteReadPacket) { + override suspend fun decode(packet: ByteReadPacket): Instruction { val value = packet.readInt() - instructions.emit(TestInstruction(value)) + return TestInstruction(value) } } @@ -364,7 +365,7 @@ internal class LoginServerTest { assertEquals(118, writeChannel.readByte().toInt()) // packet 0 assertEquals(Response.SUCCESS, writeChannel.readByte().toInt()) writeTestPacket(readChannel) - val instruction = instructions.replayCache.first() + val instruction = instructions.tryReceive().getOrNull() assertNotNull(instruction) assertEquals(TestInstruction(42), instruction) job.cancelAndJoin() diff --git a/network/src/test/kotlin/world/gregs/voidps/network/PasswordManagerTest.kt b/network/src/test/kotlin/world/gregs/voidps/network/PasswordManagerTest.kt index 5fb39e1d0d..70e0e05841 100644 --- a/network/src/test/kotlin/world/gregs/voidps/network/PasswordManagerTest.kt +++ b/network/src/test/kotlin/world/gregs/voidps/network/PasswordManagerTest.kt @@ -1,6 +1,6 @@ package world.gregs.voidps.network -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.SendChannel import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.BeforeEach @@ -96,7 +96,7 @@ class PasswordManagerTest { return accountMap[username] } - override suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): MutableSharedFlow? { + override suspend fun load(client: Client, username: String, passwordHash: String, displayMode: Int): SendChannel? { return null } } diff --git a/network/src/test/kotlin/world/gregs/voidps/network/login/protocol/DecoderTest.kt b/network/src/test/kotlin/world/gregs/voidps/network/login/protocol/DecoderTest.kt index 0ec6c2514d..9978de74af 100644 --- a/network/src/test/kotlin/world/gregs/voidps/network/login/protocol/DecoderTest.kt +++ b/network/src/test/kotlin/world/gregs/voidps/network/login/protocol/DecoderTest.kt @@ -1,7 +1,7 @@ package world.gregs.voidps.network.login.protocol import io.ktor.utils.io.core.* -import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.DynamicTest.dynamicTest @@ -125,10 +125,10 @@ class DecoderTest { Decoder.SHORT -> assertTrue(data.size <= Short.MAX_VALUE) else -> assertEquals(decoder.length, data.size) } - val instructions = MutableSharedFlow(replay = 1) + val instructions = Channel(capacity = 1) val packet = ByteReadPacket(data) - decoder.decode(instructions, packet) - val instruction = instructions.replayCache.firstOrNull() + instructions.send(decoder.decode(packet) ?: return@runTest) + val instruction = instructions.tryReceive().getOrNull() assertEquals(expected, instruction) assertTrue(packet.isEmpty) } diff --git a/tools/src/main/kotlin/world/gregs/voidps/tools/graph/MapGraphLoader.kt b/tools/src/main/kotlin/world/gregs/voidps/tools/graph/MapGraphLoader.kt index d788922971..b6727881f8 100644 --- a/tools/src/main/kotlin/world/gregs/voidps/tools/graph/MapGraphLoader.kt +++ b/tools/src/main/kotlin/world/gregs/voidps/tools/graph/MapGraphLoader.kt @@ -7,7 +7,8 @@ import world.gregs.voidps.engine.client.update.batch.ZoneBatchUpdates import world.gregs.voidps.engine.data.definition.ObjectDefinitions import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.map.collision.Collisions -import world.gregs.voidps.engine.map.collision.GameObjectCollision +import world.gregs.voidps.engine.map.collision.GameObjectCollisionAdd +import world.gregs.voidps.engine.map.collision.GameObjectCollisionRemove import world.gregs.voidps.tools.cache.Xteas import world.gregs.voidps.tools.property import world.gregs.yaml.Yaml @@ -20,7 +21,7 @@ object MapGraphLoader { val collisions: Collisions = Collisions() val objectDefinitions = ObjectDefinitions(ObjectDecoder(member = true, lowDetail = false).load(cache)) .load(Yaml(), property("objectDefinitionsPath")) - val objects = GameObjects(GameObjectCollision(Collisions()), ZoneBatchUpdates(), objectDefinitions) + val objects = GameObjects(GameObjectCollisionAdd(collisions), GameObjectCollisionRemove(collisions), ZoneBatchUpdates(), objectDefinitions) val xteas: Xteas = Xteas().load() val graph = MapGraph(objects, xteas, cache, collisions) graph.load(12342) diff --git a/tools/src/main/kotlin/world/gregs/voidps/tools/map/obj/WorldMapLinkIdentifier.kt b/tools/src/main/kotlin/world/gregs/voidps/tools/map/obj/WorldMapLinkIdentifier.kt index e376cf7b68..856b36da6a 100644 --- a/tools/src/main/kotlin/world/gregs/voidps/tools/map/obj/WorldMapLinkIdentifier.kt +++ b/tools/src/main/kotlin/world/gregs/voidps/tools/map/obj/WorldMapLinkIdentifier.kt @@ -9,9 +9,7 @@ import world.gregs.voidps.engine.client.update.batch.ZoneBatchUpdates import world.gregs.voidps.engine.data.definition.ObjectDefinitions import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.obj.GameObjects -import world.gregs.voidps.engine.map.collision.CollisionDecoder -import world.gregs.voidps.engine.map.collision.Collisions -import world.gregs.voidps.engine.map.collision.GameObjectCollision +import world.gregs.voidps.engine.map.collision.* import world.gregs.voidps.tools.cache.Xteas import world.gregs.voidps.tools.map.view.graph.MutableNavigationGraph import world.gregs.voidps.tools.property @@ -38,7 +36,7 @@ object WorldMapLinkIdentifier { val graph = MutableNavigationGraph() val linker = ObjectLinker(collisions) val clientScriptDecoder = ClientScriptDecoder().load(cache) - val objects = GameObjects(GameObjectCollision(collisions), ZoneBatchUpdates(), definitions) + val objects = GameObjects(GameObjectCollisionAdd(collisions), GameObjectCollisionRemove(collisions), ZoneBatchUpdates(), definitions) val regions = mutableListOf() for (regionX in 0 until 256) { for (regionY in 0 until 256) { @@ -52,7 +50,7 @@ object WorldMapLinkIdentifier { }) } val start = System.currentTimeMillis() - val objCollision = GameObjectCollision(collisions) + val objCollision = GameObjectCollisionAdd(collisions) val list = mutableListOf() for (region in regions) { val def = mapDecoder.getOrNull(region.id) ?: continue @@ -61,7 +59,7 @@ object WorldMapLinkIdentifier { val obj = GameObject(loc.id, tile, loc.shape, loc.rotation) list.add(obj) objects.add(obj) - objCollision.modify(obj, add = true) + objCollision.modify(obj) } collisionDecoder.decode(region, def) }