Skip to content

Commit

Permalink
Changes for OpenDream support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Oct 21, 2023
1 parent ceba786 commit 012c5a1
Show file tree
Hide file tree
Showing 13 changed files with 426 additions and 188 deletions.
41 changes: 21 additions & 20 deletions src/ApiClient/ByondClient.ts → src/ApiClient/EngineClient.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { ApiClient } from "./_base";
import {
ByondInstallResponse,
ByondResponse,
EngineInstallResponse,
EngineResponse,
EngineVersion,
ErrorMessageResponse,
JobResponse,
PaginatedByondResponse
PaginatedEngineResponse
} from "./generatedcode/generated";
import InternalError, { ErrorCode, GenericErrors } from "./models/InternalComms/InternalError";
import InternalStatus, { StatusCode } from "./models/InternalComms/InternalStatus";
import ServerClient from "./ServerClient";
import TransferClient, { UploadErrors } from "./TransferClient";
import configOptions from "./util/config";

export type DeleteErrors = GenericErrors | ErrorCode.BYOND_VERSION_NOT_FOUND;
export type DeleteErrors = GenericErrors | ErrorCode.ENGINE_VERSION_NOT_FOUND;

export default new (class ByondClient extends ApiClient {
export default new (class EngineClient extends ApiClient {
public async getActiveVersion(
instance: number
): Promise<InternalStatus<ByondResponse, GenericErrors>> {
): Promise<InternalStatus<EngineResponse, GenericErrors>> {
await ServerClient.wait4Init();

let response;
try {
response = await ServerClient.apiClient!.byond.byondControllerRead({
response = await ServerClient.apiClient!.engine.engineControllerRead({

Check failure on line 26 in src/ApiClient/EngineClient.ts

View workflow job for this annotation

GitHub Actions / Run Linter (18.x)

Unsafe assignment of an any value

Check failure on line 26 in src/ApiClient/EngineClient.ts

View workflow job for this annotation

GitHub Actions / Run Linter (18.x)

Unsafe member access .engineControllerRead on an any value

Check failure on line 26 in src/ApiClient/EngineClient.ts

View workflow job for this annotation

GitHub Actions / Run Linter (18.x)

Unsafe call of an any typed value
headers: {
Instance: instance.toString()
}
Expand All @@ -38,7 +39,7 @@ export default new (class ByondClient extends ApiClient {
case 200: {
return new InternalStatus({
code: StatusCode.OK,
payload: response.data as ByondResponse
payload: response.data as EngineResponse

Check failure on line 42 in src/ApiClient/EngineClient.ts

View workflow job for this annotation

GitHub Actions / Run Linter (18.x)

Unsafe assignment of an any value

Check failure on line 42 in src/ApiClient/EngineClient.ts

View workflow job for this annotation

GitHub Actions / Run Linter (18.x)

Unsafe member access .data on an any value
});
}
default: {
Expand All @@ -57,12 +58,12 @@ export default new (class ByondClient extends ApiClient {
public async listAllVersions(
instance: number,
{ page = 1, pageSize = configOptions.itemsperpage.value as number }
): Promise<InternalStatus<PaginatedByondResponse, GenericErrors>> {
): Promise<InternalStatus<PaginatedEngineResponse, GenericErrors>> {
await ServerClient.wait4Init();

let response;
try {
response = await ServerClient.apiClient!.byond.byondControllerList(
response = await ServerClient.apiClient!.engine.engineControllerList(

Check failure on line 66 in src/ApiClient/EngineClient.ts

View workflow job for this annotation

GitHub Actions / Run Linter (18.x)

Unsafe assignment of an any value

Check failure on line 66 in src/ApiClient/EngineClient.ts

View workflow job for this annotation

GitHub Actions / Run Linter (18.x)

Unsafe call of an any typed value

Check failure on line 66 in src/ApiClient/EngineClient.ts

View workflow job for this annotation

GitHub Actions / Run Linter (18.x)

Unsafe member access .engineControllerList on an any value
{
page: page,
pageSize: pageSize
Expand All @@ -84,7 +85,7 @@ export default new (class ByondClient extends ApiClient {
case 200: {
return new InternalStatus({
code: StatusCode.OK,
payload: response.data as PaginatedByondResponse
payload: response.data as PaginatedEngineResponse
});
}
default: {
Expand All @@ -102,15 +103,15 @@ export default new (class ByondClient extends ApiClient {

public async deleteVersion(
instance: number,
version: string
engineVersion: EngineVersion
): Promise<InternalStatus<JobResponse, DeleteErrors>> {
await ServerClient.wait4Init();

let response;
try {
response = await ServerClient.apiClient!.byond.byondControllerDelete(
response = await ServerClient.apiClient!.engine.engineControllerDelete(
{
version
engineVersion
},
{
headers: {
Expand Down Expand Up @@ -144,7 +145,7 @@ export default new (class ByondClient extends ApiClient {
return new InternalStatus({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.BYOND_VERSION_NOT_FOUND,
ErrorCode.ENGINE_VERSION_NOT_FOUND,
{
errorMessage: response.data as ErrorMessageResponse
},
Expand All @@ -167,16 +168,16 @@ export default new (class ByondClient extends ApiClient {

public async switchActive(
instance: number,
version: string,
engineVersion: EngineVersion,
file?: ArrayBuffer
): Promise<InternalStatus<ByondInstallResponse, UploadErrors>> {
): Promise<InternalStatus<EngineInstallResponse, UploadErrors>> {
await ServerClient.wait4Init();

let response;
try {
response = await ServerClient.apiClient!.byond.byondControllerUpdate(
response = await ServerClient.apiClient!.engine.engineControllerUpdate(
{
version: version,
engineVersion,
uploadCustomZip: !!file
},
{
Expand All @@ -195,7 +196,7 @@ export default new (class ByondClient extends ApiClient {
switch (response.status) {
case 200:
case 202: {
const responseData = response.data as ByondInstallResponse;
const responseData = response.data as EngineInstallResponse;
if (responseData.fileTicket) {
if (file) {
const response2 = await TransferClient.Upload(
Expand Down
4 changes: 2 additions & 2 deletions src/ApiClient/models/InternalComms/InternalError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export enum ErrorCode {
//Watchdog errors
NO_DB_ENTITY = "error.no_db_entity", //errmessage

//BYOND errors
BYOND_VERSION_NOT_FOUND = "error.no_byond_version",
//Engine errors
ENGINE_VERSION_NOT_FOUND = "error.no_engine_version",

//DreamMaker errors
COMPILE_JOB_NOT_FOUND = "error.compile_job_not_found", //errmessage
Expand Down
8 changes: 4 additions & 4 deletions src/ApiClient/util/JobsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { TypedEmitter } from "tiny-typed-emitter";
import { resolvePermissionSet } from "../../utils/misc";
import {
AdministrationRights,
ByondRights,
ChatBotRights,
ConfigurationRights,
DreamDaemonRights,
DreamMakerRights,
EngineRights,
ErrorCode as TGSErrorCode,
InstanceManagerRights,
InstancePermissionSetRights,
Expand Down Expand Up @@ -415,13 +415,13 @@ export default new (class JobsController extends TypedEmitter<IEvents> {
return false;
}
}
case RightsType.Byond: {
case RightsType.Engine: {
const InstancePermissionSet = await InstancePermissionSetClient.getCurrentInstancePermissionSet(
job.instanceid
);
if (InstancePermissionSet.code === StatusCode.OK) {
const required = job.cancelRight as ByondRights;
return !!(InstancePermissionSet.payload.byondRights & required);
const required = job.cancelRight as EngineRights;
return !!(InstancePermissionSet.payload.engineRights & required);
} else {
errors.push(InstancePermissionSet.error);
return false;
Expand Down
10 changes: 3 additions & 7 deletions src/components/utils/DeploymentViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { lt as SemverLessThan } from "semver";

import { CompileJobResponse, DreamDaemonSecurity } from "../../ApiClient/generatedcode/generated";
import { InstanceEditContext } from "../../contexts/InstanceEditContext";
import Engine from "../views/Instance/Edit/Engine";
import { DebugJsonViewer } from "./JsonViewer";
import Loading from "./Loading";
import PageHelper from "./PageHelper";
Expand Down Expand Up @@ -214,12 +215,7 @@ class DeploymentViewer extends React.Component<IProps, IState> {
}

private renderCompileJob(compileJob: CompileJobResponse) {
let correctedByondVersion = compileJob.byondVersion;
if (correctedByondVersion.endsWith(".0"))
correctedByondVersion = correctedByondVersion.substring(
0,
correctedByondVersion.length - 2
);
const engineVersion = Engine.friendlyVersion(compileJob.engineVersion);

// we use en-GB so we get the fucking SANE DD/MM/YYYY
const dateFormatter: Intl.DateTimeFormatOptions = {
Expand Down Expand Up @@ -324,7 +320,7 @@ class DeploymentViewer extends React.Component<IProps, IState> {
) : null}
</td>
<td>{compileJob.id}</td>
<td>{correctedByondVersion}</td>
<td>{engineVersion}</td>
<td>
{new Date(compileJob.job.startedAt).toLocaleString("en-CA", dateFormatter)}
</td>
Expand Down
19 changes: 13 additions & 6 deletions src/components/views/Instance/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ import { FormattedMessage } from "react-intl";
import { RouteComponentProps, withRouter } from "react-router-dom";
import YAML from "yaml";

import ByondClient from "../../../ApiClient/ByondClient";
import ConfigurationFileClient from "../../../ApiClient/ConfigurationFileClient";
import DreamDaemonClient from "../../../ApiClient/DreamDaemonClient";
import DreamMakerClient from "../../../ApiClient/DreamMakerClient";
import { ConfigurationType, DreamDaemonSecurity } from "../../../ApiClient/generatedcode/generated";
import EngineClient from "../../../ApiClient/EngineClient";
import {
ConfigurationType,
DreamDaemonSecurity,
EngineType
} from "../../../ApiClient/generatedcode/generated";
import InstanceClient from "../../../ApiClient/InstanceClient";
import InternalError, { ErrorCode } from "../../../ApiClient/models/InternalComms/InternalError";
import { StatusCode } from "../../../ApiClient/models/InternalComms/InternalStatus";
Expand Down Expand Up @@ -541,18 +545,21 @@ class InstanceCreate extends React.Component<IProps, IState> {
values={{ version: yml.byond }}
/>
);
const byondResult = await ByondClient.switchActive(instanceId, yml.byond);
const engineResult = await EngineClient.switchActive(instanceId, {
version: yml.byond,
engine: EngineType.Byond
});

if (byondResult.code === StatusCode.ERROR) {
this.addError(byondResult.error);
if (engineResult.code === StatusCode.ERROR) {
this.addError(engineResult.error);
this.setState({
performingQuickSetup: false
});

return;
}

JobsController.registerJob(byondResult.payload.installJob!, instanceId);
JobsController.registerJob(engineResult.payload.installJob!, instanceId);
}

if (secLevel != DreamDaemonSecurity.Safe) {
Expand Down
Loading

0 comments on commit 012c5a1

Please sign in to comment.