mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-11 15:54:52 +09:00
Merge pull request #514 from bbassie/fix/clusterio-master-compat
Update for clusterio master (Vite, error classes, async factories)
This commit is contained in:
68 files changed
+217
-570
No files matched your search
+1
-1
@@ -1,3 +1,3 @@
|
||||
webpack.config.js
|
||||
vite.config.js
|
||||
dist/web/build
|
||||
dist/browser
|
||||
@@ -197,7 +197,7 @@ export class AutoRestart {
|
||||
} catch (err: any) {
|
||||
this.pending.delete(host.id);
|
||||
// The host refusing is final for this process, anything else is retried
|
||||
if (!(err instanceof lib.RequestError)) {
|
||||
if (!(err instanceof lib.ClientError)) {
|
||||
this.requested.delete(host.id);
|
||||
}
|
||||
this.logger.error(`Failed to restart host ${host.name}: ${err.message}`);
|
||||
|
||||
@@ -13,7 +13,6 @@ export const plugin: lib.PluginDeclaration = {
|
||||
name: "exp_auto_restart",
|
||||
title: "ExpGaming - Auto Restart",
|
||||
description: "Clusterio plugin restarting hosts and the controller once no players are online",
|
||||
webEntrypoint: "./web",
|
||||
|
||||
controllerEntrypoint: "./dist/node/controller.js",
|
||||
controllerConfigFields: {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production",
|
||||
"prepare": "tsc --build && vite build",
|
||||
"test": "tap --type-strip-only --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"coverage": "tap --coverage-report=text test/*.test.js"
|
||||
},
|
||||
@@ -27,12 +27,11 @@
|
||||
"devDependencies": {
|
||||
"@clusterio/controller": "workspace:^",
|
||||
"@clusterio/lib": "workspace:^",
|
||||
"@clusterio/web_ui": "workspace:^",
|
||||
"@types/node": "catalog:",
|
||||
"tap": "^21.1.0",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
@@ -219,7 +219,7 @@ t.test("class AutoRestart", t2 => {
|
||||
addInstance(controller, 10, 1);
|
||||
addSystem(controller, 1);
|
||||
|
||||
controller.sendTo = async () => { throw new lib.RequestError("Cannot restart"); };
|
||||
controller.sendTo = async () => { throw new lib.ConflictError("Cannot restart"); };
|
||||
await plugin.check(now);
|
||||
await plugin.check(now + 10_000);
|
||||
t3.strictSame(logs.filter(([level]) => level === "error").length, 1, "a refusal is logged once");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.browser.json",
|
||||
"include": [ "web/**/*.tsx", "web/**/*.ts", "package.json" ],
|
||||
"include": [ "index.ts", "package.json" ],
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
export default function() {};
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_auto_restart",
|
||||
library: { type: "window", name: "plugin_exp_auto_restart" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -5,5 +5,4 @@ export const plugin: lib.PluginDeclaration = {
|
||||
title: "ExpGaming - Commands",
|
||||
description: "Clusterio plugin providing a Lua command processing library.",
|
||||
instanceEntrypoint: "./dist/node/instance.js",
|
||||
webEntrypoint: "./web",
|
||||
};
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production"
|
||||
"prepare": "tsc --build && vite build"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
@@ -25,11 +25,10 @@
|
||||
"devDependencies": {
|
||||
"@clusterio/host": "workspace:^",
|
||||
"@clusterio/lib": "workspace:^",
|
||||
"@clusterio/web_ui": "workspace:^",
|
||||
"@types/node": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@expcluster/lib_util": "workspace:^",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.browser.json",
|
||||
"include": [ "web/**/*.tsx", "web/**/*.ts", "package.json" ],
|
||||
"include": [ "index.ts", "package.json" ],
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
export default function() {};
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_commands",
|
||||
library: { type: "window", name: "plugin_exp_commands" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -95,12 +95,10 @@ export class ControllerPlugin {
|
||||
const controller = context.controller;
|
||||
const databaseDirectory = controller.config.get("controller.database_directory");
|
||||
|
||||
const accounts = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_discord_auth", "accounts.json"),
|
||||
messages.DiscordAccountRecord.fromJSON.bind(messages.DiscordAccountRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const accounts = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_discord_auth", "accounts.json"),
|
||||
messages.DiscordAccountRecord.fromJSON.bind(messages.DiscordAccountRecord),
|
||||
));
|
||||
|
||||
return new ControllerPlugin(controller, context.logger, context.plugin.name, accounts);
|
||||
}
|
||||
@@ -387,7 +385,7 @@ export class ControllerPlugin {
|
||||
const entry = this.codes.get(code);
|
||||
const session = entry ? this.sessions.get(entry.sessionId) : undefined;
|
||||
if (!entry || !session || entry.expiresMs < Date.now()) {
|
||||
throw new lib.RequestError(
|
||||
throw new lib.ValidationError(
|
||||
`This code is invalid or has expired, get a new one from ${this.controller.getControllerUrl()}`
|
||||
);
|
||||
}
|
||||
@@ -405,7 +403,7 @@ export class ControllerPlugin {
|
||||
const alreadyLinked = existing?.factorioNames.some(linked => linked.toLowerCase() === name);
|
||||
const maxAccounts = this.controller.config.get("exp_discord_auth.max_accounts");
|
||||
if (!alreadyLinked && (existing?.factorioNames.length ?? 0) >= maxAccounts) {
|
||||
throw new lib.RequestError(
|
||||
throw new lib.ConflictError(
|
||||
`${discordUser.name} already has ${maxAccounts} Factorio accounts linked, unlink one first`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production",
|
||||
"prepare": "tsc --build && vite build",
|
||||
"test": "tap --type-strip-only --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"coverage": "tap --coverage-report=text test/*.test.js"
|
||||
},
|
||||
@@ -40,11 +40,9 @@
|
||||
"react": "catalog:",
|
||||
"react-dom": "catalog:",
|
||||
"react-router-dom": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"tap": "^21.1.0",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"typescript": "catalog:",
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "catalog:",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_discord_auth",
|
||||
library: { type: "window", name: "plugin_exp_discord_auth" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"antd": { import: false },
|
||||
"react": { import: false },
|
||||
"react-dom": { import: false },
|
||||
"react-router": { import: false },
|
||||
"react-router-dom": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
+23
-29
@@ -26,26 +26,20 @@ export class ControllerPlugin {
|
||||
const controller = context.controller;
|
||||
const databaseDirectory = controller.config.get("controller.database_directory");
|
||||
|
||||
const groups = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_groups", "groups.json"),
|
||||
messages.GroupRecord.fromJSON.bind(messages.GroupRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const groups = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_groups", "groups.json"),
|
||||
messages.GroupRecord.fromJSON.bind(messages.GroupRecord),
|
||||
));
|
||||
|
||||
const roleMappings = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_groups", "role_mappings.json"),
|
||||
messages.RoleMappingRecord.fromJSON.bind(messages.RoleMappingRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const roleMappings = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_groups", "role_mappings.json"),
|
||||
messages.RoleMappingRecord.fromJSON.bind(messages.RoleMappingRecord),
|
||||
));
|
||||
|
||||
const manualAssignments = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_groups", "assignments.json"),
|
||||
messages.AssignmentRecord.fromJSON.bind(messages.AssignmentRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const manualAssignments = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_groups", "assignments.json"),
|
||||
messages.AssignmentRecord.fromJSON.bind(messages.AssignmentRecord),
|
||||
));
|
||||
|
||||
const plugin = new ControllerPlugin(
|
||||
controller, context.logger, context.plugin.name, groups, roleMappings, manualAssignments,
|
||||
@@ -239,7 +233,7 @@ export class ControllerPlugin {
|
||||
|
||||
async handleGroupCreateRequest(request: messages.GroupCreateRequest) {
|
||||
if ([...this.groups.values()].some(g => g.name === request.name)) {
|
||||
throw new lib.RequestError(`Group with name '${request.name}' already exists`);
|
||||
throw new lib.ConflictError(`Group with name '${request.name}' already exists`);
|
||||
}
|
||||
|
||||
let id = Math.random() * 2**31 | 0;
|
||||
@@ -255,7 +249,7 @@ export class ControllerPlugin {
|
||||
async handleGroupUpdateRequest(request: messages.GroupUpdateRequest) {
|
||||
const group = request.group;
|
||||
if (group.id === undefined || !this.groups.has(group.id)) {
|
||||
throw new lib.RequestError(`Group with ID ${group.id} does not exist`);
|
||||
throw new lib.NotFoundError(`Group with ID ${group.id} does not exist`);
|
||||
}
|
||||
|
||||
this.groups.set(group);
|
||||
@@ -266,7 +260,7 @@ export class ControllerPlugin {
|
||||
|
||||
const group = this.groups.getMutable(groupId);
|
||||
if (!group) {
|
||||
throw new lib.RequestError(`Group with ID ${groupId} does not exist`);
|
||||
throw new lib.NotFoundError(`Group with ID ${groupId} does not exist`);
|
||||
}
|
||||
|
||||
this.groups.delete(group);
|
||||
@@ -275,7 +269,7 @@ export class ControllerPlugin {
|
||||
async handleGroupGetRequest(request: messages.GroupGetRequest) {
|
||||
const group = this.groups.get(request.groupId);
|
||||
if (!group) {
|
||||
throw new lib.RequestError(`Group with ID ${request.groupId} does not exist`);
|
||||
throw new lib.NotFoundError(`Group with ID ${request.groupId} does not exist`);
|
||||
}
|
||||
|
||||
return group;
|
||||
@@ -292,7 +286,7 @@ export class ControllerPlugin {
|
||||
async handleAssignmentCreateRequest(request: messages.AssignmentCreateRequest) {
|
||||
const { name, groupId } = request;
|
||||
if (this.manualAssignments.has(name)) {
|
||||
throw new lib.RequestError(`Assignment for '${name}' already exists`);
|
||||
throw new lib.ConflictError(`Assignment for '${name}' already exists`);
|
||||
}
|
||||
|
||||
const assignment = new messages.AssignmentRecord(name, groupId);
|
||||
@@ -303,7 +297,7 @@ export class ControllerPlugin {
|
||||
async handleAssignmentUpdateRequest(request: messages.AssignmentUpdateRequest) {
|
||||
const assignment = request.assignment;
|
||||
if (!this.manualAssignments.has(assignment.name)) {
|
||||
throw new lib.RequestError(`Assignment for '${assignment.name}' does not exist`);
|
||||
throw new lib.NotFoundError(`Assignment for '${assignment.name}' does not exist`);
|
||||
}
|
||||
|
||||
this.manualAssignments.set(assignment);
|
||||
@@ -314,7 +308,7 @@ export class ControllerPlugin {
|
||||
|
||||
const assignment = this.manualAssignments.getMutable(name);
|
||||
if (!assignment) {
|
||||
throw new lib.RequestError(`Assignment for '${name}' does not exist`);
|
||||
throw new lib.NotFoundError(`Assignment for '${name}' does not exist`);
|
||||
}
|
||||
|
||||
this.manualAssignments.delete(assignment);
|
||||
@@ -333,7 +327,7 @@ export class ControllerPlugin {
|
||||
|
||||
const assignment = this.manualAssignments.get(request.name);
|
||||
if (!assignment) {
|
||||
throw new lib.RequestError(`Assignment for '${request.name}' does not exist`);
|
||||
throw new lib.NotFoundError(`Assignment for '${request.name}' does not exist`);
|
||||
}
|
||||
|
||||
return assignment;
|
||||
@@ -370,7 +364,7 @@ export class ControllerPlugin {
|
||||
async handleRoleMappingUpdateRequest(request: messages.RoleMappingUpdateRequest) {
|
||||
const roleMapping = request.roleMapping;
|
||||
if (roleMapping.id === undefined || !this.roleMappings.has(roleMapping.id)) {
|
||||
throw new lib.RequestError(`Role mapping with ID ${roleMapping.id} does not exist`);
|
||||
throw new lib.NotFoundError(`Role mapping with ID ${roleMapping.id} does not exist`);
|
||||
}
|
||||
|
||||
const existing = new Set(
|
||||
@@ -392,7 +386,7 @@ export class ControllerPlugin {
|
||||
|
||||
const mapping = this.roleMappings.getMutable(id);
|
||||
if (!mapping) {
|
||||
throw new lib.RequestError(`Role mapping with ID ${id} does not exist`);
|
||||
throw new lib.NotFoundError(`Role mapping with ID ${id} does not exist`);
|
||||
}
|
||||
|
||||
this.roleMappings.delete(mapping);
|
||||
@@ -401,7 +395,7 @@ export class ControllerPlugin {
|
||||
async handleRoleMappingGetRequest(request: messages.RoleMappingGetRequest) {
|
||||
const mapping = this.roleMappings.get(request.id);
|
||||
if (!mapping) {
|
||||
throw new lib.RequestError(`Role mapping with ID ${request.id} does not exist`);
|
||||
throw new lib.NotFoundError(`Role mapping with ID ${request.id} does not exist`);
|
||||
}
|
||||
|
||||
return mapping;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production"
|
||||
"prepare": "tsc --build && vite build"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
@@ -39,9 +39,7 @@
|
||||
"react-dom": "catalog:",
|
||||
"react-router-dom": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "catalog:"
|
||||
@@ -54,4 +52,4 @@
|
||||
"clusterio-plugin",
|
||||
"factorio"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_groups",
|
||||
library: { type: "window", name: "plugin_exp_groups" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"antd": { import: false },
|
||||
"react": { import: false },
|
||||
"react-dom": { import: false },
|
||||
"react-router": { import: false },
|
||||
"react-router-dom": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -5,5 +5,4 @@ export const plugin: lib.PluginDeclaration = {
|
||||
title: "ExpGaming - GUI",
|
||||
description: "Clusterio plugin providing a Lua GUI definition library.",
|
||||
instanceEntrypoint: "./dist/node/instance.js",
|
||||
webEntrypoint: "./web",
|
||||
};
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production"
|
||||
"prepare": "tsc --build && vite build"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
@@ -25,11 +25,10 @@
|
||||
"devDependencies": {
|
||||
"@clusterio/host": "workspace:^",
|
||||
"@clusterio/lib": "workspace:^",
|
||||
"@clusterio/web_ui": "workspace:^",
|
||||
"@types/node": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@expcluster/lib_util": "workspace:^",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.browser.json",
|
||||
"include": [ "web/**/*.tsx", "web/**/*.ts", "package.json" ],
|
||||
"include": [ "index.ts", "package.json" ],
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
export default function() {};
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_gui",
|
||||
library: { type: "window", name: "plugin_exp_gui" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -7,12 +7,10 @@ import * as path from "node:path";
|
||||
export default async function (context: ControllerPluginContext) {
|
||||
const { controller, plugin } = context;
|
||||
const databaseDirectory = controller.config.get("controller.database_directory");
|
||||
const players = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_player_statistics", "players.json"),
|
||||
messages.PlayerStatistics.fromJSON.bind(messages.PlayerStatistics),
|
||||
).bootstrap()
|
||||
);
|
||||
const players = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_player_statistics", "players.json"),
|
||||
messages.PlayerStatistics.fromJSON.bind(messages.PlayerStatistics),
|
||||
));
|
||||
|
||||
function addDeltas(deltas: messages.StatisticsDelta[]) {
|
||||
const changed = new Map<string, messages.PlayerStatistics>();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production",
|
||||
"prepare": "tsc --build && vite build",
|
||||
"test": "tap --type-strip-only --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"coverage": "tap --coverage-report=text test/*.test.js"
|
||||
},
|
||||
@@ -42,9 +42,7 @@
|
||||
"react-router-dom": "catalog:",
|
||||
"tap": "^21.1.0",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "catalog:",
|
||||
|
||||
@@ -29,15 +29,16 @@ async function startPlugin(t2, { status = "running", stats = { Kills: 3 } } = {}
|
||||
instanceConfig.set("instance.id", 1);
|
||||
instanceConfig.set("instance.name", "test");
|
||||
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), "factorioDir", instanceConfig
|
||||
);
|
||||
|
||||
const state = { sent: [], rcons: [], warnings: [] };
|
||||
const ipc = new Map();
|
||||
instance.server = {
|
||||
const server = {
|
||||
on: () => {},
|
||||
handle: (name, handler) => ipc.set(name, handler),
|
||||
};
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), instanceConfig, server
|
||||
);
|
||||
instance.sendRcon = async command => {
|
||||
state.rcons.push(command);
|
||||
return "";
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_player_statistics",
|
||||
library: { type: "window", name: "plugin_exp_player_statistics" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"antd": { import: false },
|
||||
"react": { import: false },
|
||||
"react-dom": { import: false },
|
||||
"react-router": { import: false },
|
||||
"react-router-dom": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
+19
-23
@@ -11,19 +11,15 @@ function migrateReports(rawJson: unknown[]) {
|
||||
export default async function (context: ControllerPluginContext) {
|
||||
const { controller, logger, plugin } = context;
|
||||
const databaseDirectory = controller.config.get("controller.database_directory");
|
||||
const reports = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_reports", "reports.json"),
|
||||
messages.ReportRecord.fromJSON.bind(messages.ReportRecord),
|
||||
migrateReports,
|
||||
).bootstrap()
|
||||
);
|
||||
const watchList = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_reports", "watch_list.json"),
|
||||
messages.WatchListRecord.fromJSON.bind(messages.WatchListRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const reports = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_reports", "reports.json"),
|
||||
messages.ReportRecord.fromJSON.bind(messages.ReportRecord),
|
||||
migrateReports,
|
||||
));
|
||||
const watchList = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_reports", "watch_list.json"),
|
||||
messages.WatchListRecord.fromJSON.bind(messages.WatchListRecord),
|
||||
));
|
||||
|
||||
/** Every report, or only those against one player. */
|
||||
function listReports(playerName?: string) {
|
||||
@@ -162,7 +158,7 @@ export default async function (context: ControllerPluginContext) {
|
||||
controller.handle(messages.ReportGetRequest, async (request: messages.ReportGetRequest) => {
|
||||
const report = reports.get(request.id);
|
||||
if (!report) {
|
||||
throw new lib.RequestError(`Report with ID ${request.id} does not exist`);
|
||||
throw new lib.NotFoundError(`Report with ID ${request.id} does not exist`);
|
||||
}
|
||||
return report;
|
||||
});
|
||||
@@ -178,13 +174,13 @@ export default async function (context: ControllerPluginContext) {
|
||||
}
|
||||
|
||||
if (!byPlayerName) {
|
||||
throw new lib.RequestError("A report needs the name of the player making it");
|
||||
throw new lib.ValidationError("A report needs the name of the player making it");
|
||||
}
|
||||
if (!request.reason.trim()) {
|
||||
throw new lib.RequestError("A report needs a reason");
|
||||
throw new lib.ValidationError("A report needs a reason");
|
||||
}
|
||||
if (listReports(request.playerName).some(report => report.byPlayerName === byPlayerName)) {
|
||||
throw new lib.RequestError(`${byPlayerName} has already reported ${request.playerName}`);
|
||||
throw new lib.ConflictError(`${byPlayerName} has already reported ${request.playerName}`);
|
||||
}
|
||||
|
||||
let id = Math.random() * 2 ** 31 | 0;
|
||||
@@ -203,7 +199,7 @@ export default async function (context: ControllerPluginContext) {
|
||||
controller.handle(messages.ReportDeleteRequest, async (request: messages.ReportDeleteRequest) => {
|
||||
const report = reports.getMutable(request.id);
|
||||
if (!report) {
|
||||
throw new lib.RequestError(`Report with ID ${request.id} does not exist`);
|
||||
throw new lib.NotFoundError(`Report with ID ${request.id} does not exist`);
|
||||
}
|
||||
reports.delete(report);
|
||||
});
|
||||
@@ -211,7 +207,7 @@ export default async function (context: ControllerPluginContext) {
|
||||
controller.handle(messages.ReportSetReadRequest, async (request: messages.ReportSetReadRequest) => {
|
||||
const report = reports.getMutable(request.id);
|
||||
if (!report) {
|
||||
throw new lib.RequestError(`Report with ID ${request.id} does not exist`);
|
||||
throw new lib.NotFoundError(`Report with ID ${request.id} does not exist`);
|
||||
}
|
||||
report.isRead = request.isRead;
|
||||
reports.set(report);
|
||||
@@ -220,14 +216,14 @@ export default async function (context: ControllerPluginContext) {
|
||||
controller.handle(messages.WatchListAddRequest, async (request: messages.WatchListAddRequest, src: lib.Address) => {
|
||||
const playerName = request.playerName.trim();
|
||||
if (!playerName) {
|
||||
throw new lib.RequestError("A player name is required");
|
||||
throw new lib.ValidationError("A player name is required");
|
||||
}
|
||||
if (!request.reason.trim()) {
|
||||
throw new lib.RequestError("A reason is required");
|
||||
throw new lib.ValidationError("A reason is required");
|
||||
}
|
||||
const existing = watchList.get(playerName.toLowerCase());
|
||||
if (existing) {
|
||||
throw new lib.RequestError(`${existing.playerName} is already on the watch list`);
|
||||
throw new lib.ConflictError(`${existing.playerName} is already on the watch list`);
|
||||
}
|
||||
|
||||
const entry = new messages.WatchListRecord(playerName, request.reason.trim(), controlUserName(src), Date.now());
|
||||
@@ -238,7 +234,7 @@ export default async function (context: ControllerPluginContext) {
|
||||
controller.handle(messages.WatchListRemoveRequest, async (request: messages.WatchListRemoveRequest) => {
|
||||
const entry = watchList.getMutable(request.playerName.toLowerCase());
|
||||
if (!entry) {
|
||||
throw new lib.RequestError(`${request.playerName} is not on the watch list`);
|
||||
throw new lib.NotFoundError(`${request.playerName} is not on the watch list`);
|
||||
}
|
||||
watchList.delete(entry);
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production",
|
||||
"prepare": "tsc --build && vite build",
|
||||
"test": "tap --type-strip-only --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"coverage": "tap --coverage-report=text test/*.test.js"
|
||||
},
|
||||
@@ -37,15 +37,13 @@
|
||||
"@types/node": "catalog:",
|
||||
"@types/react": "catalog:",
|
||||
"antd": "catalog:",
|
||||
"fengari": "^0.1.5",
|
||||
"react": "catalog:",
|
||||
"react-dom": "catalog:",
|
||||
"react-router-dom": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"fengari": "^0.1.5",
|
||||
"tap": "^21.1.0",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"typescript": "catalog:",
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "catalog:",
|
||||
|
||||
@@ -31,20 +31,20 @@ async function startPlugin(t2, { reports = [report(1, "bob", "alice"), report(2,
|
||||
instanceConfig.set("instance.id", 1);
|
||||
instanceConfig.set("instance.name", "test");
|
||||
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), "factorioDir", instanceConfig
|
||||
);
|
||||
|
||||
// Spies which record the messages and commands leaving the instance
|
||||
const state = { sent: [], rcons: [], failNext: null };
|
||||
const ipc = new Map();
|
||||
instance.server = {
|
||||
const server = {
|
||||
on: () => {},
|
||||
handle: (name, handler) => ipc.set(name, handler),
|
||||
sendRcon: async command => {
|
||||
state.rcons.push(command);
|
||||
return "";
|
||||
},
|
||||
};
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), instanceConfig, server
|
||||
);
|
||||
instance.sendTo = async (dst, request) => {
|
||||
state.sent.push(request);
|
||||
if (state.failNext) {
|
||||
@@ -102,7 +102,7 @@ t.test("instance plugin", t2 => {
|
||||
|
||||
t2.test("exp_reports:create prints a refusal to the reporter", async t3 => {
|
||||
const { state, createIPC } = await startPlugin(t3);
|
||||
state.failNext = new lib.RequestError("dave has already reported bob");
|
||||
state.failNext = new lib.ConflictError("dave has already reported bob");
|
||||
await createIPC({ player_name: "bob", by_player_name: "dave", reason: "griefing" });
|
||||
|
||||
const { receiver, payload } = decodeRcon(state.rcons[0]);
|
||||
@@ -113,7 +113,7 @@ t.test("instance plugin", t2 => {
|
||||
t2.test("text that closes a long bracket stays inside the json", async t3 => {
|
||||
const { state, createIPC } = await startPlugin(t3);
|
||||
const message = "]=]) game.print(1) --[==[ ]==] ]===]";
|
||||
state.failNext = new lib.RequestError(message);
|
||||
state.failNext = new lib.ConflictError(message);
|
||||
await createIPC({ player_name: "bob", by_player_name: "dave", reason: message });
|
||||
|
||||
const { payload } = decodeRcon(state.rcons[0]);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_reports",
|
||||
library: { type: "window", name: "plugin_exp_reports" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"antd": { import: false },
|
||||
"react": { import: false },
|
||||
"react-dom": { import: false },
|
||||
"react-router": { import: false },
|
||||
"react-router-dom": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -22,12 +22,10 @@ export class ControllerPlugin {
|
||||
const controller = context.controller;
|
||||
const databaseDirectory = controller.config.get("controller.database_directory");
|
||||
|
||||
const roleMeta = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_roles", "role_meta.json"),
|
||||
messages.RoleMetaRecord.fromJSON.bind(messages.RoleMetaRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const roleMeta = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_roles", "role_meta.json"),
|
||||
messages.RoleMetaRecord.fromJSON.bind(messages.RoleMetaRecord),
|
||||
));
|
||||
|
||||
const plugin = new ControllerPlugin(controller, context.logger, context.plugin.name, roleMeta);
|
||||
loaded.set(controller, plugin);
|
||||
@@ -149,7 +147,7 @@ export class ControllerPlugin {
|
||||
async handleRoleMetaUpdateRequest(request: messages.RoleMetaUpdateRequest) {
|
||||
const meta = request.meta;
|
||||
if (!this.controller.roles.has(meta.id)) {
|
||||
throw new lib.RequestError(`Role with ID ${meta.id} does not exist`);
|
||||
throw new lib.NotFoundError(`Role with ID ${meta.id} does not exist`);
|
||||
}
|
||||
|
||||
this.roleMeta.set(meta);
|
||||
@@ -250,12 +248,12 @@ export class ControllerPlugin {
|
||||
async handleAssignmentUpdateRequest(request: messages.AssignmentUpdateRequest) {
|
||||
const user = this.controller.users.getByNameMutable(request.name);
|
||||
if (!user) {
|
||||
throw new lib.RequestError(`User '${request.name}' does not exist`);
|
||||
throw new lib.NotFoundError(`User '${request.name}' does not exist`);
|
||||
}
|
||||
|
||||
for (const roleId of [...request.assign, ...request.unassign]) {
|
||||
if (!this.controller.roles.has(roleId)) {
|
||||
throw new lib.RequestError(`Role with ID ${roleId} does not exist`);
|
||||
throw new lib.NotFoundError(`Role with ID ${roleId} does not exist`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production",
|
||||
"prepare": "tsc --build && vite build",
|
||||
"test": "tap --type-strip-only --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"coverage": "tap --coverage-report=text test/*.test.js"
|
||||
},
|
||||
@@ -37,15 +37,13 @@
|
||||
"@types/node": "catalog:",
|
||||
"@types/react": "catalog:",
|
||||
"antd": "catalog:",
|
||||
"fengari": "^0.1.5",
|
||||
"react": "catalog:",
|
||||
"react-dom": "catalog:",
|
||||
"react-router-dom": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"fengari": "^0.1.5",
|
||||
"tap": "^21.1.0",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"typescript": "catalog:",
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "catalog:"
|
||||
|
||||
@@ -40,21 +40,21 @@ async function startPlugin(t2, { syncMode = "bidirectional", roles = sampleRoles
|
||||
instanceConfig.set("instance.name", "test");
|
||||
instanceConfig.set("exp_roles.sync_mode", syncMode);
|
||||
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), "factorioDir", instanceConfig
|
||||
);
|
||||
|
||||
// Spies which record the messages and commands leaving the instance
|
||||
const state = { sent: [], rcons: [], warnings: [], failNext: null };
|
||||
const handlers = new Map();
|
||||
instance.handle = (Event, handler) => handlers.set(Event, handler);
|
||||
instance.server = {
|
||||
const server = {
|
||||
on: () => {},
|
||||
handle: (name, handler) => handlers.set(name, handler),
|
||||
sendRcon: async command => {
|
||||
state.rcons.push(command);
|
||||
return "";
|
||||
},
|
||||
};
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), instanceConfig, server
|
||||
);
|
||||
instance.handle = (Event, handler) => handlers.set(Event, handler);
|
||||
instance.sendTo = async (dst, request) => {
|
||||
state.sent.push(request);
|
||||
if (state.failNext) {
|
||||
@@ -96,10 +96,10 @@ t.test("entrypoint", async t2 => {
|
||||
const instanceConfig = new lib.InstanceConfig("host");
|
||||
instanceConfig.set("instance.id", 1);
|
||||
instanceConfig.set("instance.name", "test");
|
||||
const server = { on: () => {}, handle: () => {} };
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), "factorioDir", instanceConfig
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), instanceConfig, server
|
||||
);
|
||||
instance.server = { handle: () => {} };
|
||||
await entrypoint({ instance, host: {}, logger, plugin: { name: "exp_roles" } });
|
||||
for (const hook of ["instanceConfigFieldChanged", "start"]) {
|
||||
t2.ok([...instance.hooks[hook].attached].includes("exp_roles"), `attached to ${hook}`);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_roles",
|
||||
library: { type: "window", name: "plugin_exp_roles" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"antd": { import: false },
|
||||
"react": { import: false },
|
||||
"react-dom": { import: false },
|
||||
"react-router": { import: false },
|
||||
"react-router-dom": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
+10
-14
@@ -12,18 +12,14 @@ import { SeedRole, SeedGroup, seedRoles, seedGroups, flattenSeedPermissions } fr
|
||||
export default async function (context: ControllerPluginContext) {
|
||||
const { controller, logger, plugin } = context;
|
||||
const databaseDirectory = controller.config.get("controller.database_directory");
|
||||
const featureStore = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_scenario", "features.json"),
|
||||
messages.FeatureRecord.fromJSON.bind(messages.FeatureRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const playerStore = new lib.SubscribableDatastore(
|
||||
...await new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_scenario", "players.json"),
|
||||
messages.PlayerRecord.fromJSON.bind(messages.PlayerRecord),
|
||||
).bootstrap()
|
||||
);
|
||||
const featureStore = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_scenario", "features.json"),
|
||||
messages.FeatureRecord.fromJSON.bind(messages.FeatureRecord),
|
||||
));
|
||||
const playerStore = await lib.SubscribableDatastore.fromProvider(new lib.JsonIdDatastoreProvider(
|
||||
path.join(databaseDirectory, "exp_scenario", "players.json"),
|
||||
messages.PlayerRecord.fromJSON.bind(messages.PlayerRecord),
|
||||
));
|
||||
|
||||
type PlayerSettings = Pick<messages.PlayerRecord, "joinMessage" | "toolbar">;
|
||||
|
||||
@@ -179,7 +175,7 @@ export default async function (context: ControllerPluginContext) {
|
||||
const rolesPlugin = RolesPlugin.get(controller);
|
||||
const groupsPlugin = GroupsPlugin.get(controller);
|
||||
if (!rolesPlugin || !groupsPlugin) {
|
||||
throw new lib.RequestError("Seeding requires the exp_roles and exp_groups plugins");
|
||||
throw new lib.UnavailableError("Seeding requires the exp_roles and exp_groups plugins");
|
||||
}
|
||||
|
||||
const roleIds = new Map<string, number>();
|
||||
@@ -218,7 +214,7 @@ export default async function (context: ControllerPluginContext) {
|
||||
try {
|
||||
values = validateFeatureValues(request.id, request.values);
|
||||
} catch (err: any) {
|
||||
throw new lib.RequestError(err.message);
|
||||
throw new lib.ValidationError(err.message);
|
||||
}
|
||||
|
||||
const feature = new messages.FeatureRecord(request.id, request.enabled, values);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production",
|
||||
"prepare": "tsc --build && vite build",
|
||||
"test": "tap --type-strip-only --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"coverage": "tap --coverage-report=text test/*.test.js"
|
||||
},
|
||||
@@ -41,9 +41,7 @@
|
||||
"react-dom": "catalog:",
|
||||
"tap": "^21.1.0",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@expcluster/lib_commands": "workspace:^",
|
||||
|
||||
@@ -32,19 +32,19 @@ async function startPlugin(
|
||||
instanceConfig.set("instance.id", 1);
|
||||
instanceConfig.set("instance.name", "test");
|
||||
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), "factorioDir", instanceConfig
|
||||
);
|
||||
|
||||
const state = { sent: [], rcons: [] };
|
||||
const ipcHandlers = new Map();
|
||||
instance.server = {
|
||||
const server = {
|
||||
on: () => {},
|
||||
handle: (channel, handler) => ipcHandlers.set(channel, handler),
|
||||
sendRcon: async command => {
|
||||
state.rcons.push(command);
|
||||
return "";
|
||||
},
|
||||
};
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), instanceConfig, server
|
||||
);
|
||||
instance.sendTo = async (dst, request) => {
|
||||
state.sent.push(request);
|
||||
if (request instanceof messages.PlayerGetRequest) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_scenario",
|
||||
library: { type: "window", name: "plugin_exp_scenario" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
"antd": { import: false },
|
||||
"react": { import: false },
|
||||
"react-dom": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -24,7 +24,6 @@ export const plugin: lib.PluginDeclaration = {
|
||||
name: "exp_server_list",
|
||||
title: "ExpGaming - Server List",
|
||||
description: "Clusterio plugin sharing the details of every instance with the others",
|
||||
webEntrypoint: "./web",
|
||||
|
||||
controllerEntrypoint: "./dist/node/controller.js",
|
||||
instanceEntrypoint: "./dist/node/instance.js",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production",
|
||||
"prepare": "tsc --build && vite build",
|
||||
"test": "tap --type-strip-only --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"coverage": "tap --coverage-report=text test/*.test.js"
|
||||
},
|
||||
@@ -37,9 +37,7 @@
|
||||
"fengari": "^0.1.5",
|
||||
"tap": "^21.1.0",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "catalog:",
|
||||
|
||||
@@ -35,18 +35,19 @@ async function startPlugin(t2, servers = [server(1), server(2)]) {
|
||||
instanceConfig.set("instance.id", 1);
|
||||
instanceConfig.set("instance.name", "test");
|
||||
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), "factorioDir", instanceConfig
|
||||
);
|
||||
|
||||
const state = { sent: [], rcons: [] };
|
||||
instance.server = {
|
||||
const server = {
|
||||
on: () => {},
|
||||
handle: () => {},
|
||||
sendRcon: async command => {
|
||||
state.rcons.push(command);
|
||||
return "";
|
||||
},
|
||||
};
|
||||
const instance = new Instance(
|
||||
{ assignGamePort: () => 1 }, new TestConnector(), t2.testdir(), instanceConfig, server
|
||||
);
|
||||
instance.sendTo = async (dst, request) => {
|
||||
if (request instanceof lib.InstanceStatusChangedEvent) {
|
||||
return undefined;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.browser.json",
|
||||
"include": [ "web/**/*.tsx", "web/**/*.ts", "index.ts", "messages.ts", "package.json" ],
|
||||
"include": [ "index.ts", "messages.ts", "package.json" ],
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
export default function() {};
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_server_list",
|
||||
library: { type: "window", name: "plugin_exp_server_list" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -11,7 +11,6 @@ export const plugin: lib.PluginDeclaration = {
|
||||
name: "exp_server_ups",
|
||||
title: "ExpGaming - Server UPS",
|
||||
description: "Clusterio plugin providing in game server ups counter",
|
||||
webEntrypoint: "./web",
|
||||
|
||||
instanceEntrypoint: "./dist/node/instance.js",
|
||||
instanceConfigFields: {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production"
|
||||
"prepare": "tsc --build && vite build"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
@@ -25,11 +25,10 @@
|
||||
"devDependencies": {
|
||||
"@clusterio/host": "workspace:^",
|
||||
"@clusterio/lib": "workspace:^",
|
||||
"typescript": "catalog:",
|
||||
"@clusterio/web_ui": "workspace:^",
|
||||
"@types/node": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"typescript": "catalog:",
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "catalog:",
|
||||
@@ -45,4 +44,4 @@
|
||||
"clusterio-plugin",
|
||||
"factorio"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.browser.json",
|
||||
"include": [ "web/**/*.tsx", "web/**/*.ts", "package.json" ],
|
||||
"include": [ "index.ts", "package.json" ],
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
export default function() {};
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_server_ups",
|
||||
library: { type: "window", name: "plugin_exp_server_ups" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -5,5 +5,4 @@ export const plugin: lib.PluginDeclaration = {
|
||||
title: "ExpGaming - Module Utilities",
|
||||
description: "Provides extensions and overrides of base Lua library functions, and provides utility modules for improved module compatibly",
|
||||
instanceEntrypoint: "./dist/node/instance.js",
|
||||
webEntrypoint: "./web",
|
||||
};
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production"
|
||||
"prepare": "tsc --build && vite build"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
@@ -25,11 +25,10 @@
|
||||
"devDependencies": {
|
||||
"@clusterio/host": "workspace:^",
|
||||
"@clusterio/lib": "workspace:^",
|
||||
"@clusterio/web_ui": "workspace:^",
|
||||
"@types/node": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"webpack": "catalog:",
|
||||
"webpack-cli": "catalog:",
|
||||
"webpack-merge": "catalog:"
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "catalog:"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.browser.json",
|
||||
"include": [ "web/**/*.tsx", "web/**/*.ts", "package.json" ],
|
||||
"include": [ "index.ts", "package.json" ],
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { clusterioPlugin } from "@clusterio/web_ui/vite.mjs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [clusterioPlugin()],
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
export default function() {};
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
const common = require("@clusterio/web_ui/webpack.common");
|
||||
|
||||
module.exports = (env = {}) => merge(common(env), {
|
||||
context: __dirname,
|
||||
entry: "./web/index.tsx",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist", "web"),
|
||||
},
|
||||
plugins: [
|
||||
new webpack.container.ModuleFederationPlugin({
|
||||
name: "exp_util",
|
||||
library: { type: "window", name: "plugin_exp_util" },
|
||||
exposes: {
|
||||
"./": "./index.ts",
|
||||
"./package.json": "./package.json",
|
||||
"./web": "./web/index.tsx",
|
||||
},
|
||||
shared: {
|
||||
"@clusterio/lib": { import: false },
|
||||
"@clusterio/web_ui": { import: false },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
Reference in new issue
Block a user