Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mission Management APIs #153

Merged
merged 1 commit into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

## [0.5.0] - 2022-04-19
### Added
Expand Down
5 changes: 3 additions & 2 deletions STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ should use their independent logging and tracing functions.
- [ ] <del>`trace`</del> (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`
Expand Down
15 changes: 15 additions & 0 deletions lua/DCS-gRPC/methods/hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions protos/dcs/hook/v0/hook.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -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;
rurounijones marked this conversation as resolved.
Show resolved Hide resolved
}

message LoadMissionResponse {
}

message StopMissionRequest {
}

Expand Down
24 changes: 24 additions & 0 deletions src/rpc/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ impl HookService for HookRpc {
Ok(Response::new(res))
}

async fn reload_current_mission(
&self,
request: Request<hook::v0::ReloadCurrentMissionRequest>,
) -> Result<Response<hook::v0::ReloadCurrentMissionResponse>, Status> {
let res = self.request("reloadCurrentMission", request).await?;
Ok(Response::new(res))
}

async fn load_next_mission(
&self,
request: Request<hook::v0::LoadNextMissionRequest>,
) -> Result<Response<hook::v0::LoadNextMissionResponse>, Status> {
let res = self.request("loadNextMission", request).await?;
Ok(Response::new(res))
}

async fn load_mission(
&self,
request: Request<hook::v0::LoadMissionRequest>,
) -> Result<Response<hook::v0::LoadMissionResponse>, Status> {
let res = self.request("loadMission", request).await?;
Ok(Response::new(res))
}

async fn stop_mission(
&self,
request: Request<hook::v0::StopMissionRequest>,
Expand Down