Skip to content

Commit ecfb6bb

Browse files
committed
feat: add EnumerateSessions
1 parent 7a0f2e1 commit ecfb6bb

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,8 @@ client.v1
106106
.then(() => {
107107
// response will be an empty string if valid
108108
});
109+
110+
client.v1.EnumerateSessions().then((response) => {
111+
console.log("EnumerateSessions Response:", response);
112+
});
109113
```

src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export type {
1515
ClaimServerResponseData,
1616
CreateNewGameRequest,
1717
CreateNewGameResponse,
18+
EnumerateSessionsFailedErrorResponse,
19+
EnumerateSessionsRequest,
20+
EnumerateSessionsResponse,
21+
EnumerateSessionsResponseData,
1822
ErrorResponse,
1923
GetAdvancedGameSettingsRequest,
2024
GetAdvancedGameSettingsResponse,
@@ -46,8 +50,10 @@ export type {
4650
SaveGameFailedErrorResponse,
4751
SaveGameRequest,
4852
SaveGameResponse,
53+
SaveHeader,
4954
ServerClaimedErrorResponse,
5055
ServerNotClaimedErrorResponse,
56+
SessionSaveStruct,
5157
SetAdminPasswordRequest,
5258
SetAdminPasswordResponse,
5359
SetAutoLoadSessionNameRequest,

src/v1/EnumerateSessions.ts

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import type { ApiRequest, ApiSuccessResponse } from "./common.js";
2+
import { buildApiRequest } from "./common.js";
3+
4+
export interface SaveHeader {
5+
/**
6+
* Version of the Save Game format this file was saved with.
7+
*/
8+
saveVersion: number;
9+
/**
10+
* Changelist of the game or dedicated server this file was saved by.
11+
*/
12+
buildVersion: number;
13+
/**
14+
* Name of the save game file in the filesystem.
15+
*/
16+
saveName: string;
17+
saveLocationInfo: string;
18+
/**
19+
* Path to the map package this save game file is based on.
20+
*/
21+
mapName: string;
22+
/**
23+
* Additional Map URL options this save game was saved with.
24+
*/
25+
mapOptions: string;
26+
/**
27+
* Name of the session this save game file belongs to.
28+
*/
29+
sessionName: string;
30+
/**
31+
* Amount of seconds the game has been running for in total since the session was created.
32+
*/
33+
playDurationSeconds: number;
34+
/**
35+
* Date and time on which the save game file was saved.
36+
*/
37+
saveDateTime: string;
38+
/**
39+
* True if this save game file was saved with mods.
40+
*/
41+
isModdedSave: boolean;
42+
/**
43+
* True if this save game file has been edited by third party tools.
44+
*/
45+
isEditedSave: boolean;
46+
/**
47+
* True if Advanced Game Settings are enabled for this save game.
48+
*/
49+
isCreativeModeEnabled: boolean;
50+
}
51+
52+
export interface SessionSaveStruct {
53+
/**
54+
* Name of the save session.
55+
*/
56+
sessionName: string;
57+
/**
58+
* All save game files belonging to this session.
59+
*/
60+
saveHeaders: SaveHeader[];
61+
}
62+
63+
export type EnumerateSessionsRequest = ApiRequest<"EnumerateSessions">;
64+
65+
export type EnumerateSessionsResponseData = {
66+
/**
67+
* List of sessions available on the Dedicated Server.
68+
*/
69+
sessions: SessionSaveStruct[];
70+
/**
71+
* Index of the currently selected session in the list.
72+
*/
73+
currentSessionIndex: number;
74+
};
75+
76+
export type EnumerateSessionsResponse =
77+
ApiSuccessResponse<EnumerateSessionsResponseData>;
78+
79+
export const buildEnumerateSessions = buildApiRequest<
80+
EnumerateSessionsRequest,
81+
EnumerateSessionsResponse
82+
>("v1", {
83+
function: "EnumerateSessions",
84+
});

src/v1/error.ts

+4
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ export interface CannotResetAdminPasswordErrorResponse extends ErrorResponse {
5252
export interface SaveGameFailedErrorResponse extends ErrorResponse {
5353
errorCode: "save_game_failed";
5454
}
55+
56+
export interface EnumerateSessionsFailedErrorResponse extends ErrorResponse {
57+
errorCode: "enumerate_sessions_failed";
58+
}

src/v1/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { buildApplyServerOptions } from "./ApplyServerOptions.js";
33
import { buildClaimServer } from "./ClaimServer.js";
44
import type { InternalClientOptions } from "./common.js";
55
import { buildCreateNewGame } from "./CreateNewGame.js";
6+
import { buildEnumerateSessions } from "./EnumerateSessions.js";
67
import { buildGetAdvancedGameSettings } from "./GetAdvancedGameSettings.js";
78
import { buildGetServerOptions } from "./GetServerOptions.js";
89
import { buildHealthCheck } from "./HealthCheck.js";
@@ -158,6 +159,14 @@ export function buildV1(options: InternalClientOptions) {
158159
* Function does not return any data on success.
159160
*/
160161
SaveGame: buildSaveGame(options),
162+
/**
163+
* Enumerates all save game files available on the Dedicated Server.
164+
*
165+
* Requires Admin privileges.
166+
*
167+
* Function does not require any additional parameters.
168+
*/
169+
EnumerateSessions: buildEnumerateSessions(options),
161170
};
162171
}
163172

@@ -166,6 +175,7 @@ export type * from "./ApplyServerOptions.js";
166175
export type * from "./ClaimServer.js";
167176
export type * from "./common.js";
168177
export type * from "./CreateNewGame.js";
178+
export type * from "./EnumerateSessions.js";
169179
export type * from "./error.js";
170180
export type * from "./GetAdvancedGameSettings.js";
171181
export type * from "./GetServerOptions.js";

test.js

+4
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ client.v1
8787
.then((response) => {
8888
console.log("RenameServer Response:", typeof response);
8989
});
90+
91+
client.v1.EnumerateSessions().then((response) => {
92+
console.log("EnumerateSessions Response:", response);
93+
});

0 commit comments

Comments
 (0)