diff --git a/src/SimConnectConnection.ts b/src/SimConnectConnection.ts index 355512e..0da42a5 100644 --- a/src/SimConnectConnection.ts +++ b/src/SimConnectConnection.ts @@ -18,10 +18,14 @@ import { ClientDataRequestFlag } from './flags/ClientDataRequestFlag'; import { SimConnectConstants } from './SimConnectConstants'; import { SimConnectPacketBuilder } from './SimConnectPacketBuilder'; import { + RecvActionCallback, RecvAirportList, RecvAssignedObjectID, RecvCloudState, + RecvControllersList, RecvCustomAction, + RecvEnumerateInputEventParams, + RecvEnumerateInputEvents, RecvEvent, RecvEventAddRemove, RecvEventEx1, @@ -34,11 +38,13 @@ import { RecvFacilityData, RecvFacilityDataEnd, RecvFacilityMinimalList, + RecvGetInputEvent, RecvJetwayData, RecvNDBList, RecvOpen, RecvReservedKey, RecvSimObjectData, + RecvSubscribeInputEvent, RecvSystemState, RecvVORList, RecvWaypointList, @@ -55,11 +61,6 @@ import { ObjectId, } from './Types'; import Timeout = NodeJS.Timeout; -import { RecvControllersList } from './recv/RecvControllersList'; -import { RecvEnumerateInputEvents } from './recv/RecvEnumerateInputEvents'; -import { RecvGetInputEvent } from './recv/RecvGetInputEvent'; -import { RecvSubscribeInputEvent } from './recv/RecvSubscribeInputEvent'; -import { RecvEnumerateInputEventParams } from './recv/RecvEnumerateInputEventParams'; type OpenPacketData = { major: number; @@ -134,6 +135,7 @@ interface SimConnectRecvEvents { facilityDataEnd: (recvFacilityDataEnd: RecvFacilityDataEnd) => void; facilityMinimalList: (recvFacilityMinimalList: RecvFacilityMinimalList) => void; jetwayData: (recvJetwayData: RecvJetwayData) => void; + actionCallback: (recvActionCallback: RecvActionCallback) => void; controllersList: (recvControllersList: RecvControllersList) => void; inputEventsList: (recvEnumerateInputEvents: RecvEnumerateInputEvents) => void; getInputEvent: (recvGetInputEvent: RecvGetInputEvent) => void; @@ -1536,7 +1538,23 @@ class SimConnectConnection extends EventEmitter { ); } - // TODO: implement 0x4e: executeAction(dataRequestID: number, actionID: string, values: RawBuffer) + /** + * See https://www.fsdeveloper.com/wiki/index.php/MSFS_Mission_Script_-_Actions + * + * @returns sendId of packet (can be used to identify packet when exception event occurs) + */ + executeAction(dataRequestID: number, actionID: string, values: RawBuffer) { + if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion); + + const paramValues = values.getBuffer(); + + const packet = this._beginPacket(0x4e) + .putInt32(dataRequestID) + .putString256(actionID) + .putInt32(paramValues.length) + .putBytes(paramValues); + return this._buildAndSend(packet); + } /** * @@ -1740,6 +1758,7 @@ class SimConnectConnection extends EventEmitter { this.emit('controllersList', new RecvControllersList(data)); break; case RecvID.ID_ACTION_CALLBACK: + this.emit('actionCallback', new RecvActionCallback(data)); break; case RecvID.ID_ENUMERATE_INPUT_EVENTS: this.emit('inputEventsList', new RecvEnumerateInputEvents(data)); diff --git a/src/recv/RecvActionCallback.ts b/src/recv/RecvActionCallback.ts new file mode 100644 index 0000000..f0643b0 --- /dev/null +++ b/src/recv/RecvActionCallback.ts @@ -0,0 +1,15 @@ +import { RawBuffer } from '../RawBuffer'; +import { RecvEvent } from './RecvEvent'; +import { DataRequestId } from '../Types'; + +export class RecvActionCallback extends RecvEvent { + requestID: DataRequestId; + + actionID: string; + + constructor(data: RawBuffer) { + super(data); + this.actionID = data.readString260(); + this.requestID = data.readInt32(); + } +} diff --git a/src/recv/RecvException.ts b/src/recv/RecvException.ts index 66c64eb..9843b25 100644 --- a/src/recv/RecvException.ts +++ b/src/recv/RecvException.ts @@ -1,4 +1,5 @@ import { RawBuffer } from '../RawBuffer'; +import { SimConnectException } from '../enums/SimConnectException'; export class RecvException { exception: number; @@ -7,10 +8,14 @@ export class RecvException { index: number; + exceptionName: string; + constructor(data: RawBuffer) { this.exception = data.readInt32(); this.sendId = data.readInt32(); this.index = data.readInt32(); + + this.exceptionName = SimConnectException[this.exception]; } } diff --git a/src/recv/index.ts b/src/recv/index.ts index 0f6b14b..fdfa278 100644 --- a/src/recv/index.ts +++ b/src/recv/index.ts @@ -24,3 +24,9 @@ export * from './RecvVORList'; export * from './RecvWaypointList'; export * from './RecvWeatherObservation'; export * from './RecvJetwayData'; +export * from './RecvControllersList'; +export * from './RecvEnumerateInputEvents'; +export * from './RecvGetInputEvent'; +export * from './RecvSubscribeInputEvent'; +export * from './RecvEnumerateInputEventParams'; +export * from './RecvActionCallback';