Skip to content
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
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This repository currently contains:
Both implementations cover:

- Health checks
- Server lifecycle management
- Server lifecycle management, including monthly subscription reactivation
- Server lookup and runtime retrieval
- Terrain changes
- Resource metrics
Expand All @@ -30,14 +30,9 @@ Both implementations cover:
- Player kick / ban
- SRS client inspection and moderation for servers with the SRS mod installed
- Webconsole execution for servers with the webconsole mod installed
- Trigger create, list, and delete

The Rust client also includes trigger management:

- Create trigger
- List triggers
- Delete trigger

This feature is not stable yet and will change in the future.
Trigger management is not stable yet and will change in the future.

## Package-Specific Docs

Expand Down
3 changes: 2 additions & 1 deletion javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ const servers = await client.getServers();
## Implemented Capabilities

- Health checks
- Create, fetch, update, start, stop, restart, full restart, update, and delete servers
- Create, fetch, update, start, stop, restart, full restart, update, delete, and reactivate servers
- Runtime lookup, chat retrieval, and resource metrics
- Terrain changes
- File listing, directory creation, upload, download, move, and delete
- Mission upload, add, delete, select, and start
- DCS pause / resume, settings save, kick, ban, and chat send
- SRS client listing, kick, and ban for servers with the SRS mod installed
- Webconsole execution for servers with the webconsole mod installed
- Trigger create, list, and delete

## Package Exports

Expand Down
39 changes: 39 additions & 0 deletions javascript/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
BanPlayerResponse,
BillingType,
CreateInstanceRequest,
CreateTriggerRequest,
DcsChatSafe,
DcsRuntimeSafe,
DeleteMissionsResponse,
Expand All @@ -28,6 +29,7 @@ import type {
StartMissionResponse,
StartServerResponse,
Terrain,
Trigger,
WebConsoleExecuteRequest,
} from "./types.ts";

Expand Down Expand Up @@ -306,6 +308,12 @@ export default class Client {
});
}

public async reactivateServer(id: string): Promise<void> {
await this.requestVoid(this.buildUrl(`/game_servers/${id}/reactivate`), {
method: "POST",
});
}

public async getServerResources(
id: string,
period: "now" | "hour" | "day" | "week",
Expand Down Expand Up @@ -542,4 +550,35 @@ export default class Client {
},
);
}

public async createTrigger(
id: string,
request: CreateTriggerRequest,
): Promise<Trigger> {
return await this.requestJson<Trigger>(
this.buildUrl(`/game_servers/${id}/triggers`),
{
method: "POST",
body: this.createJsonBody(request),
},
);
}

public async listTriggers(id: string): Promise<Trigger[]> {
return await this.requestJson<Trigger[]>(
this.buildUrl(`/game_servers/${id}/triggers`),
{
method: "GET",
},
);
}

public async deleteTrigger(id: string, triggerId: string): Promise<void> {
await this.requestVoid(
this.buildUrl(`/game_servers/${id}/triggers/${triggerId}`),
{
method: "DELETE",
},
);
}
}
27 changes: 26 additions & 1 deletion javascript/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,14 @@ export type GetPauseServerResponse = null;

export type GetResumeServerResponse = null;

export type InstancePermissions = {
owner_user: UserResource;
permissions: Array<Permission>;
};

export type InstanceResource = {
runtime: GameRuntime | null;
permissions: InstancePermissions | null;
id: string;
node_id: string;
user_id: string;
Expand All @@ -197,6 +203,7 @@ export type InstanceResource = {
rented_at: number;
rented_until: number | null;
active_mods: Array<string>;
subscription_cancel_at_period_end: boolean;
created_at: string;
dcs_settings: DcsSettingsSafe | null;
region: Region;
Expand All @@ -223,6 +230,7 @@ export type InstanceSafe = {
rented_at: number;
rented_until: number | null;
active_mods: Array<string>;
subscription_cancel_at_period_end: boolean;
created_at: string;
dcs_settings: DcsSettingsSafe | null;
};
Expand All @@ -242,7 +250,8 @@ export type InstanceStatus =
is_post_creation: boolean;
};
}
| "InstallingMods"
| { InstallingMods: { is_post_creation: boolean } }
| "UninstallingMods"
| "InstallingPost"
| {
UninstallingTerrains: {
Expand All @@ -269,6 +278,7 @@ export type InstanceStoppedReason =
| "ServerUpdating"
| "RebootRequestedThroughFile"
| "DcsSessionExpired"
| "DcsAuthFailed"
| { StoppedForRestart: { scheduled: boolean } };

export type InstancesResponse = Array<InstanceResource>;
Expand All @@ -279,6 +289,19 @@ export type KickPlayerResponse = boolean;

export type MoveFileRequest = { source: string; destination: string };

export type Permission =
| "instance:view"
| "instance:actions"
| "instance:chat"
| "instance:players:manage"
| "instance:missions"
| "instance:settings"
| "instance:infrastructure"
| "instance:mods"
| "instance:scheduled_tasks"
| "instance:file:read"
| "instance:file:write";

export type Player = {
ping: number;
side: number;
Expand Down Expand Up @@ -407,4 +430,6 @@ export type TriggerCondition =
| { type: "OnEvent"; config: { event_type: string } }
| { type: "Schedule"; config: { cron_expression: string } };

export type UserResource = { id: string; name: string };

export type WebConsoleExecuteRequest = { code: string };
8 changes: 2 additions & 6 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn main() -> anyhow::Result<()> {
## Implemented Capabilities

- Health checks
- Create, fetch, update, start, stop, restart, full restart, update, and delete servers
- Create, fetch, update, start, stop, restart, full restart, update, delete, and reactivate servers
- Runtime lookup, chat retrieval, and resource metrics
- Terrain changes
- File listing, directory creation, upload, download, move, and delete
Expand All @@ -39,11 +39,7 @@ async fn main() -> anyhow::Result<()> {
- Webconsole execution for servers with the webconsole mod installed
- Trigger create, list, and delete

## Trigger Support

Trigger management is currently Rust-only in this repository.

This feature is not stable yet and will change in the future.
Trigger management is not stable yet and will change in the future.

## Development

Expand Down
14 changes: 12 additions & 2 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ pub use types::files::{
FileDownloadResponse, FileInfo, FileListResponse, FileUploadRequest, MoveFileRequest,
};
pub use types::instance::{
ApiError, GameRuntime, GameType, Instance, InstanceNodeResource, InstanceResource,
InstanceStatus, InstanceStoppedReason, InstancesResponse, Terrain,
ApiError, GameRuntime, GameType, Instance, InstanceNodeResource, InstancePermissions,
InstanceResource, InstanceStatus, InstanceStoppedReason, InstancesResponse, Permission,
Terrain, UserResource,
};
pub use types::region::Region;
pub use types::srs::{SrsClient, SrsModRequest, SrsServerInfo};
Expand Down Expand Up @@ -292,6 +293,15 @@ impl Client {
.await
}

pub async fn reactivate_server(&self, id: &Uuid) -> Result<()> {
self.send_unit(
self.reqwest_client
.post(format!("{}/game_servers/{}/reactivate", Self::BASE_URL, id)),
"failed to reactivate server",
)
.await
}

pub async fn list_files(&self, id: &Uuid, path: impl Into<String>) -> Result<FileListResponse> {
self.send_json(self.reqwest_client.get(format!(
"{}/game_servers/{}/files?path={}",
Expand Down
46 changes: 45 additions & 1 deletion rust/src/types/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct Instance {
pub rented_at: i64,
pub rented_until: Option<i64>,
pub active_mods: Vec<String>,
pub subscription_cancel_at_period_end: bool,
pub created_at: String,
pub dcs_settings: Option<DcsSettings>,
}
Expand All @@ -50,6 +51,7 @@ pub struct InstanceResource {
#[serde(flatten)]
pub node: InstanceNodeResource,
pub runtime: Option<GameRuntime>,
pub permissions: Option<InstancePermissions>,
}

pub type InstancesResponse = Vec<InstanceResource>;
Expand Down Expand Up @@ -78,6 +80,44 @@ pub enum Terrain {
GermanyCW,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct InstancePermissions {
pub owner_user: UserResource,
pub permissions: Vec<Permission>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct UserResource {
pub id: Uuid,
pub name: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum Permission {
#[serde(rename = "instance:view")]
InstanceView,
#[serde(rename = "instance:actions")]
InstanceActions,
#[serde(rename = "instance:chat")]
InstanceChat,
#[serde(rename = "instance:players:manage")]
InstancePlayersManage,
#[serde(rename = "instance:missions")]
InstanceMissions,
#[serde(rename = "instance:settings")]
InstanceSettings,
#[serde(rename = "instance:infrastructure")]
InstanceInfrastructure,
#[serde(rename = "instance:mods")]
InstanceMods,
#[serde(rename = "instance:scheduled_tasks")]
InstanceScheduledTasks,
#[serde(rename = "instance:file:read")]
InstanceFileRead,
#[serde(rename = "instance:file:write")]
InstanceFileWrite,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum InstanceStatus {
AwaitingContainer,
Expand All @@ -90,7 +130,10 @@ pub enum InstanceStatus {
processing_progress: Option<u8>,
is_post_creation: bool,
},
InstallingMods,
InstallingMods {
is_post_creation: bool,
},
UninstallingMods,
InstallingPost,
UninstallingTerrains {
want_uninstall: Vec<Terrain>,
Expand Down Expand Up @@ -122,6 +165,7 @@ pub enum InstanceStoppedReason {
ServerUpdating,
RebootRequestedThroughFile,
DcsSessionExpired,
DcsAuthFailed,
StoppedForRestart { scheduled: bool },
}

Expand Down