diff --git a/CHANGELOG.md b/CHANGELOG.md index b7459edf..455a34e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `MarkupToCoalition` API - `GetTheatre` API - `GetUnitType` API +- `ReloadCurrentMission` API +- `LoadNextMission` API +- `LoadMission` API ### Fixed - Fixed event handler error log missing actual error message (contained `nil` instead of the message). diff --git a/STATUS.md b/STATUS.md index ca76f4b3..49d17bc7 100644 --- a/STATUS.md +++ b/STATUS.md @@ -110,8 +110,9 @@ should use their independent logging and tracing functions. - [ ] `trace` (client applications should use their own logging) #### GameGUI API -- [ ] `load_mission` -- [ ] `load_next_mission` +- [x] `reload_current_mission` Custom API +- [x] `load_mission` +- [x] `load_next_mission` ### Timer Service - [x] `getTime` diff --git a/lua/DCS-gRPC/methods/hook.lua b/lua/DCS-gRPC/methods/hook.lua index d49d35e5..eadc52db 100644 --- a/lua/DCS-gRPC/methods/hook.lua +++ b/lua/DCS-gRPC/methods/hook.lua @@ -3,7 +3,9 @@ -- Docs: /DCS World/API/DCS_ControlAPI.html -- +local DCS = DCS local GRPC = GRPC +local net = net GRPC.methods.getMissionName = function() return GRPC.success({name = DCS.getMissionName()}) @@ -17,6 +19,19 @@ GRPC.methods.getMissionDescription = function() return GRPC.success({description = DCS.getMissionDescription()}) end +GRPC.methods.reloadCurrentMission = function() + net.load_mission(DCS.getMissionFilename()) + return GRPC.success({}) +end + +GRPC.methods.loadNextMission = function() + return GRPC.success({loaded = net.load_next_mission()}) +end + +GRPC.methods.loadMission = function(params) + return GRPC.success({loaded = net.load_mission(params.fileName)}) +end + GRPC.methods.getPaused = function() return GRPC.success({paused = DCS.getPause()}) end diff --git a/protos/dcs/hook/v0/hook.proto b/protos/dcs/hook/v0/hook.proto index d39f08a8..7ca236bf 100644 --- a/protos/dcs/hook/v0/hook.proto +++ b/protos/dcs/hook/v0/hook.proto @@ -25,6 +25,21 @@ service HookService { // https://wiki.hoggitworld.com/view/DCS_func_stopMission rpc StopMission(StopMissionRequest) returns (StopMissionResponse) {} + // Reload the currently running mission + rpc ReloadCurrentMission(ReloadCurrentMissionRequest) + returns (ReloadCurrentMissionResponse) {} + + // Load the next mission in the server mission list. Note that it does + // not loop back to the first mission once the end of the mission list + // has been reached + rpc LoadNextMission(LoadNextMissionRequest) + returns (LoadNextMissionResponse) {} + + // Load a specific mission file. This does not need to be in the mission + // list. + rpc LoadMission(LoadMissionRequest) + returns (LoadMissionResponse) {} + // Evaluate some Lua inside of the hook environment and return the result as a // JSON string. Disabled by default. rpc Eval(EvalRequest) returns (EvalResponse) {} @@ -87,6 +102,30 @@ message SetPausedRequest { message SetPausedResponse { } +message ReloadCurrentMissionRequest { +} + +message ReloadCurrentMissionResponse { +} + +message LoadNextMissionRequest { +} + +message LoadNextMissionResponse { + // Was the next mission successfully loaded. SHOULD return false when the + // end of the mission list has been reached but DCS appears to always + // return true + bool loaded = 1; +} + +message LoadMissionRequest { + // The full path to the .miz file to be loaded + string file_name = 1; +} + +message LoadMissionResponse { +} + message StopMissionRequest { } diff --git a/src/rpc/hook.rs b/src/rpc/hook.rs index e2903705..9a79ca98 100644 --- a/src/rpc/hook.rs +++ b/src/rpc/hook.rs @@ -45,6 +45,30 @@ impl HookService for HookRpc { Ok(Response::new(res)) } + async fn reload_current_mission( + &self, + request: Request, + ) -> Result, Status> { + let res = self.request("reloadCurrentMission", request).await?; + Ok(Response::new(res)) + } + + async fn load_next_mission( + &self, + request: Request, + ) -> Result, Status> { + let res = self.request("loadNextMission", request).await?; + Ok(Response::new(res)) + } + + async fn load_mission( + &self, + request: Request, + ) -> Result, Status> { + let res = self.request("loadMission", request).await?; + Ok(Response::new(res)) + } + async fn stop_mission( &self, request: Request,