Headless SWG client will now throw an exception if the command is dequeued with an error code

This commit is contained in:
Ziggy
2023-12-02 23:25:20 +01:00
parent 4544935852
commit d4feb3abfa
2 changed files with 7 additions and 3 deletions
@@ -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 {
@@ -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)
class TipException(message: String) : Exception(message)
class CommandFailedException(message: String) : Exception(message)