From d4feb3abfa8aad18bda0d2b9fc666b42edd6d994 Mon Sep 17 00:00:00 2001 From: Ziggy Date: Sat, 2 Dec 2023 23:25:20 +0100 Subject: [PATCH] Headless SWG client will now throw an exception if the command is dequeued with an error code --- .../com/projectswg/holocore/headless/ZonedInCharacter.kt | 7 +++++-- .../java/com/projectswg/holocore/headless/exceptions.kt | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/projectswg/holocore/headless/ZonedInCharacter.kt b/src/test/java/com/projectswg/holocore/headless/ZonedInCharacter.kt index 408b25e77..18fdcfd94 100644 --- a/src/test/java/com/projectswg/holocore/headless/ZonedInCharacter.kt +++ b/src/test/java/com/projectswg/holocore/headless/ZonedInCharacter.kt @@ -38,11 +38,14 @@ import java.util.concurrent.TimeUnit */ class ZonedInCharacter internal constructor(val player: GenericPlayer) { - internal fun sendCommand(command: String, target: SWGObject? = null, args: String = ""): CommandQueueDequeue { + internal fun sendCommand(command: String, target: SWGObject? = null, args: String = "") { val targetObjectId = target?.objectId ?: 0 val commandQueueEnqueue = CommandQueueEnqueue(player.creatureObject.objectId, 0, CRC.getCrc(command.lowercase()), targetObjectId, args) sendPacket(player, commandQueueEnqueue) - return player.waitForNextPacket(CommandQueueDequeue::class.java, 80, TimeUnit.MILLISECONDS) ?: throw IllegalStateException("Failed to receive dequeue for command '$command' in time") + val packet = player.waitForNextPacket(CommandQueueDequeue::class.java, 80, TimeUnit.MILLISECONDS) ?: throw IllegalStateException("Failed to receive dequeue for command '$command' in time") + if (packet.error != CommandQueueDequeue.ErrorCode.SUCCESS) { + throw CommandFailedException("Command '$command' failed: ${packet.error}") + } } override fun toString(): String { diff --git a/src/test/java/com/projectswg/holocore/headless/exceptions.kt b/src/test/java/com/projectswg/holocore/headless/exceptions.kt index fa1bf86a6..e7325bfa0 100644 --- a/src/test/java/com/projectswg/holocore/headless/exceptions.kt +++ b/src/test/java/com/projectswg/holocore/headless/exceptions.kt @@ -29,4 +29,5 @@ package com.projectswg.holocore.headless class AccountBannedException(message: String) : Exception(message) class WrongClientVersionException(message: String) : Exception(message) class WrongCredentialsException(message: String) : Exception(message) -class TipException(message: String) : Exception(message) \ No newline at end of file +class TipException(message: String) : Exception(message) +class CommandFailedException(message: String) : Exception(message) \ No newline at end of file