Skip to content

Commit

Permalink
feat: add SaveGame
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Sep 14, 2024
1 parent 675cce9 commit e03542b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export type {
RunCommandRequest,
RunCommandResponse,
RunCommandResponseData,
SaveGameFailedErrorResponse,
SaveGameRequest,
SaveGameResponse,
ServerClaimedErrorResponse,
ServerNotClaimedErrorResponse,
SetAdminPasswordRequest,
Expand Down
23 changes: 23 additions & 0 deletions src/v1/SaveGame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ApiRequest } from "./common.js";
import { buildApiRequest } from "./common.js";

export type SaveGameRequest = ApiRequest<
"SaveGame",
{
/**
* Name of the save game file to create.
*
* Passed name might be sanitized.
*/
saveName: string;
}
>;

export type SaveGameResponse = string;

export const buildSaveGame = buildApiRequest<SaveGameRequest, SaveGameResponse>(
"v1",
{
function: "SaveGame",
}
);
4 changes: 4 additions & 0 deletions src/v1/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ export interface PasswordInUseErrorResponse extends ErrorResponse {
export interface CannotResetAdminPasswordErrorResponse extends ErrorResponse {
errorCode: "cannot_reset_admin_password";
}

export interface SaveGameFailedErrorResponse extends ErrorResponse {
errorCode: "save_game_failed";
}
12 changes: 12 additions & 0 deletions src/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { buildPasswordLogin } from "./PasswordLogin.js";
import { buildQueryServerState } from "./QueryServerState.js";
import { buildRenameServer } from "./RenameServer.js";
import { buildRunCommand } from "./RunCommand.js";
import { buildSaveGame } from "./SaveGame.js";
import { buildSetAdminPassword } from "./SetAdminPassword.js";
import { buildSetAutoLoadSessionName } from "./SetAutoLoadSessionName.js";
import { buildSetClientPassword } from "./SetClientPassword.js";
Expand Down Expand Up @@ -147,6 +148,16 @@ export function buildV1(options: InternalClientOptions) {
* Function does not return any data on success.
*/
CreateNewGame: buildCreateNewGame(options),
/**
* Saves the currently loaded session into the new save game file named as the argument.
*
* Requires Admin privileges.
*
* SaveName might be changed to satisfy file system restrictions on file names.
*
* Function does not return any data on success.
*/
SaveGame: buildSaveGame(options),
};
}

Expand All @@ -164,6 +175,7 @@ export type * from "./PasswordLogin.js";
export type * from "./QueryServerState.js";
export type * from "./RenameServer.js";
export type * from "./RunCommand.js";
export type * from "./SaveGame.js";
export type * from "./SetAdminPassword.js";
export type * from "./SetAutoLoadSessionName.js";
export type * from "./SetClientPassword.js";
Expand Down

0 comments on commit e03542b

Please sign in to comment.