mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Fix code style errors
Remove extra whitespace, use more consistent spacing, add missing semicolons, using dangling commas, break up long lines, consistent multiline operator placement, add missing JSDoc strings and so on.
This commit is contained in:
1 parent
97e05c0610
commit
7314dc99c8
68 files changed
+391
-278
No files matched your search
@@ -83,18 +83,16 @@ void new lib.Gauge(
|
|||||||
"clusterio_controller_websocket_active_connections",
|
"clusterio_controller_websocket_active_connections",
|
||||||
"How many WebSocket connections are currently open to the controller",
|
"How many WebSocket connections are currently open to the controller",
|
||||||
{ callback: function(gauge:lib.Gauge) {
|
{ callback: function(gauge:lib.Gauge) {
|
||||||
gauge.set(controller.wsServer.activeConnectors.size);
|
gauge.set(controller.wsServer.activeConnectors.size);
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
void new lib.Gauge(
|
void new lib.Gauge(
|
||||||
"clusterio_controller_active_hosts",
|
"clusterio_controller_active_hosts",
|
||||||
"How many hosts are currently connected to the controller",
|
"How many hosts are currently connected to the controller",
|
||||||
{ callback: function(gauge:lib.Gauge) {
|
{ callback: function(gauge:lib.Gauge) {
|
||||||
gauge.set(controller.wsServer.hostConnections.size);
|
gauge.set(controller.wsServer.hostConnections.size);
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
void new lib.Gauge(
|
void new lib.Gauge(
|
||||||
@@ -294,7 +292,7 @@ async function initialize(): Promise<InitializeParameters> {
|
|||||||
logger.info(`Loading available plugins from ${args.pluginList}`);
|
logger.info(`Loading available plugins from ${args.pluginList}`);
|
||||||
let pluginList = new Map();
|
let pluginList = new Map();
|
||||||
try {
|
try {
|
||||||
pluginList = new Map(JSON.parse(await fs.readFile(args.pluginList, { encoding: 'utf8' })));
|
pluginList = new Map(JSON.parse(await fs.readFile(args.pluginList, { encoding: "utf8" })));
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.code !== "ENOENT") {
|
if (err.code !== "ENOENT") {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -324,7 +322,7 @@ async function initialize(): Promise<InitializeParameters> {
|
|||||||
logger.info(`Loading config from ${controllerConfigPath}`);
|
logger.info(`Loading config from ${controllerConfigPath}`);
|
||||||
const controllerConfig = new lib.ControllerConfig("controller");
|
const controllerConfig = new lib.ControllerConfig("controller");
|
||||||
try {
|
try {
|
||||||
let fileData = await fs.readFile(controllerConfigPath, { encoding: 'utf8' })
|
let fileData = await fs.readFile(controllerConfigPath, { encoding: "utf8" });
|
||||||
await controllerConfig.load(JSON.parse(fileData));
|
await controllerConfig.load(JSON.parse(fileData));
|
||||||
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -363,7 +361,7 @@ async function initialize(): Promise<InitializeParameters> {
|
|||||||
controllerConfigPath,
|
controllerConfigPath,
|
||||||
controllerConfig,
|
controllerConfig,
|
||||||
shouldRun,
|
shouldRun,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startup() {
|
async function startup() {
|
||||||
@@ -377,7 +375,7 @@ async function startup() {
|
|||||||
clusterLogger,
|
clusterLogger,
|
||||||
pluginInfos,
|
pluginInfos,
|
||||||
controllerConfigPath,
|
controllerConfigPath,
|
||||||
controllerConfig
|
controllerConfig,
|
||||||
} = await initialize();
|
} = await initialize();
|
||||||
if (!shouldRun || !pluginInfos || !controllerConfigPath || !controllerConfig) {
|
if (!shouldRun || !pluginInfos || !controllerConfigPath || !controllerConfig) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
assigned_host = undefined;
|
assigned_host = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let game_port: number|null|undefined = instance.game_port
|
let game_port: number|null|undefined = instance.game_port;
|
||||||
if (game_port === null) {
|
if (game_port === null) {
|
||||||
game_port = undefined;
|
game_port = undefined;
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
assigned_host = undefined;
|
assigned_host = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let game_port: number|null|undefined = instance.game_port
|
let game_port: number|null|undefined = instance.game_port;
|
||||||
if (game_port === null) {
|
if (game_port === null) {
|
||||||
game_port = undefined;
|
game_port = undefined;
|
||||||
}
|
}
|
||||||
@@ -434,7 +434,7 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
async handleModPackCreateRequest(request: lib.ModPackCreateRequest) {
|
async handleModPackCreateRequest(request: lib.ModPackCreateRequest) {
|
||||||
let modPack = request.modPack;
|
let modPack = request.modPack;
|
||||||
if (modPack.id === undefined) {
|
if (modPack.id === undefined) {
|
||||||
throw new lib.RequestError(`Mod pack need an ID to be created`);
|
throw new lib.RequestError("Mod pack need an ID to be created");
|
||||||
}
|
}
|
||||||
if (this._controller.modPacks!.has(modPack.id)) {
|
if (this._controller.modPacks!.has(modPack.id)) {
|
||||||
throw new lib.RequestError(`Mod pack with ID ${modPack.id} already exist`);
|
throw new lib.RequestError(`Mod pack with ID ${modPack.id} already exist`);
|
||||||
@@ -622,7 +622,7 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
controller: request.controller,
|
controller: request.controller,
|
||||||
hostIds: request.hostIds,
|
hostIds: request.hostIds,
|
||||||
instanceIds: request.instanceIds,
|
instanceIds: request.instanceIds,
|
||||||
}
|
};
|
||||||
|
|
||||||
let observeDuration = queryLogTime.startTimer();
|
let observeDuration = queryLogTime.startTimer();
|
||||||
let { all, controller, hostIds, instanceIds } = request;
|
let { all, controller, hostIds, instanceIds } = request;
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ export default class Controller {
|
|||||||
Controller.addAppRoutes(this.app, this.pluginInfos);
|
Controller.addAppRoutes(this.app, this.pluginInfos);
|
||||||
|
|
||||||
if (!args.dev) {
|
if (!args.dev) {
|
||||||
let manifestPath = path.join(__dirname, "..", "..", "web", "manifest.json")
|
let manifestPath = path.join(__dirname, "..", "..", "web", "manifest.json");
|
||||||
|
|
||||||
let manifest = await Controller.loadJsonObject(manifestPath);
|
let manifest = await Controller.loadJsonObject(manifestPath);
|
||||||
if (!manifest["main.js"]) {
|
if (!manifest["main.js"]) {
|
||||||
@@ -365,7 +365,7 @@ export default class Controller {
|
|||||||
static async loadHosts(filePath: string): Promise<Map<number, HostInfo>> {
|
static async loadHosts(filePath: string): Promise<Map<number, HostInfo>> {
|
||||||
let serialized: [number, HostInfo][];
|
let serialized: [number, HostInfo][];
|
||||||
try {
|
try {
|
||||||
serialized = JSON.parse(await fs.readFile(filePath, { encoding: 'utf8' }));
|
serialized = JSON.parse(await fs.readFile(filePath, { encoding: "utf8" }));
|
||||||
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.code !== "ENOENT") {
|
if (err.code !== "ENOENT") {
|
||||||
@@ -425,7 +425,7 @@ export default class Controller {
|
|||||||
static async loadModPacks(filePath: string): Promise<Map<number, lib.ModPack>> {
|
static async loadModPacks(filePath: string): Promise<Map<number, lib.ModPack>> {
|
||||||
let json;
|
let json;
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(await fs.readFile(filePath, { encoding : "utf8" }));
|
json = JSON.parse(await fs.readFile(filePath, { encoding: "utf8" }));
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.code !== "ENOENT") {
|
if (err.code !== "ENOENT") {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -439,7 +439,7 @@ export default class Controller {
|
|||||||
await lib.safeOutputFile(filePath, JSON.stringify([...modPacks.values()], null, 4));
|
await lib.safeOutputFile(filePath, JSON.stringify([...modPacks.values()], null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
static async loadModInfos(modsDirectory: string): Promise<Map<string,lib.ModInfo>> {
|
static async loadModInfos(modsDirectory: string): Promise<Map<string, lib.ModInfo>> {
|
||||||
let mods = new Map();
|
let mods = new Map();
|
||||||
for (let entry of await fs.readdir(modsDirectory, { withFileTypes: true })) {
|
for (let entry of await fs.readdir(modsDirectory, { withFileTypes: true })) {
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
@@ -476,7 +476,7 @@ export default class Controller {
|
|||||||
static async loadJsonObject(filePath: string, throwOnMissing: boolean = false): Promise<any> {
|
static async loadJsonObject(filePath: string, throwOnMissing: boolean = false): Promise<any> {
|
||||||
let manifest = {};
|
let manifest = {};
|
||||||
try {
|
try {
|
||||||
manifest = JSON.parse(await fs.readFile(filePath, { encoding: 'utf8' }));
|
manifest = JSON.parse(await fs.readFile(filePath, { encoding: "utf8" }));
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (!throwOnMissing && err.code !== "ENOENT") {
|
if (!throwOnMissing && err.code !== "ENOENT") {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -543,7 +543,9 @@ export default class Controller {
|
|||||||
|
|
||||||
// Set folder to serve static content from (the website)
|
// Set folder to serve static content from (the website)
|
||||||
const staticOptions = { immutable: true, maxAge: 1000 * 86400 * 365 };
|
const staticOptions = { immutable: true, maxAge: 1000 * 86400 * 365 };
|
||||||
app.use("/static", express.static(path.join(__dirname, "..", "..", "..", "dist", "web", "static"), staticOptions));
|
app.use("/static",
|
||||||
|
express.static(path.join(__dirname, "..", "..", "..", "dist", "web", "static"), staticOptions)
|
||||||
|
);
|
||||||
app.use("/static", express.static("static", staticOptions)); // Used for data export files
|
app.use("/static", express.static("static", staticOptions)); // Used for data export files
|
||||||
|
|
||||||
// Add API routes
|
// Add API routes
|
||||||
@@ -595,9 +597,10 @@ export default class Controller {
|
|||||||
* Get instance by ID for a request
|
* Get instance by ID for a request
|
||||||
*
|
*
|
||||||
* @param instanceId - ID of instance to get.
|
* @param instanceId - ID of instance to get.
|
||||||
|
* @returns Info for the given instance if it exists
|
||||||
* @throws {module:lib.RequestError} if the instance does not exist.
|
* @throws {module:lib.RequestError} if the instance does not exist.
|
||||||
*/
|
*/
|
||||||
getRequestInstance(instanceId:number):InstanceInfo {
|
getRequestInstance(instanceId:number): InstanceInfo {
|
||||||
let instance = this.instances!.get(instanceId);
|
let instance = this.instances!.get(instanceId);
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
throw new lib.RequestError(`Instance with ID ${instanceId} does not exist`);
|
throw new lib.RequestError(`Instance with ID ${instanceId} does not exist`);
|
||||||
@@ -773,7 +776,7 @@ export default class Controller {
|
|||||||
assigned_host = undefined;
|
assigned_host = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let game_port: number|null|undefined = instance.game_port
|
let game_port: number|null|undefined = instance.game_port;
|
||||||
if (game_port === null) {
|
if (game_port === null) {
|
||||||
game_port = undefined;
|
game_port = undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default class HostConnection extends BaseConnection {
|
|||||||
this.plugins = new Map(Object.entries(registerData.plugins));
|
this.plugins = new Map(Object.entries(registerData.plugins));
|
||||||
this._checkPluginVersions();
|
this._checkPluginVersions();
|
||||||
|
|
||||||
let currentHostInfo = this._controller.hosts!.get(this._id)
|
let currentHostInfo = this._controller.hosts!.get(this._id);
|
||||||
|
|
||||||
this._controller.hosts!.set(this._id, {
|
this._controller.hosts!.set(this._id, {
|
||||||
agent: this._agent,
|
agent: this._agent,
|
||||||
@@ -223,7 +223,9 @@ export default class HostConnection extends BaseConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
instanceConfig.set("instance.assigned_host", this._id);
|
instanceConfig.set("instance.assigned_host", this._id);
|
||||||
let newInstance = new InstanceInfo({ config: instanceConfig, status: instanceData.status as InstanceStatus });
|
let newInstance = new InstanceInfo(
|
||||||
|
{ config: instanceConfig, status: instanceData.status as InstanceStatus }
|
||||||
|
);
|
||||||
this._controller.instances!.set(instanceConfig.get("instance.id"), newInstance);
|
this._controller.instances!.set(instanceConfig.get("instance.id"), newInstance);
|
||||||
this._controller.addInstanceHooks(newInstance);
|
this._controller.addInstanceHooks(newInstance);
|
||||||
await this.send(
|
await this.send(
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ export default class HttpCloser {
|
|||||||
private _responses: Set<http.ServerResponse>;
|
private _responses: Set<http.ServerResponse>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server to attach this closer to.
|
* Create HttpCloser attached to a server.
|
||||||
|
* @param server - Node.js HTTP(S) server to attach to.
|
||||||
*/
|
*/
|
||||||
constructor(server: http.Server | https.Server) {
|
constructor(server: http.Server | https.Server) {
|
||||||
this._server = server;
|
this._server = server;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export default class UserManager {
|
|||||||
|
|
||||||
async load(filePath: string): Promise<void> {
|
async load(filePath: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
let content = JSON.parse(await fs.readFile(filePath, { encoding: 'utf8' }));
|
let content = JSON.parse(await fs.readFile(filePath, { encoding: "utf8" }));
|
||||||
for (let serializedRole of content.roles) {
|
for (let serializedRole of content.roles) {
|
||||||
let role = new lib.Role(serializedRole);
|
let role = new lib.Role(serializedRole);
|
||||||
this.roles.set(role.id, role);
|
this.roles.set(role.id, role);
|
||||||
@@ -65,6 +65,7 @@ export default class UserManager {
|
|||||||
/**
|
/**
|
||||||
* Creates a new user and add it to the user database.
|
* Creates a new user and add it to the user database.
|
||||||
* @param name - Name of the user to create.
|
* @param name - Name of the user to create.
|
||||||
|
* @returns The created user.
|
||||||
*/
|
*/
|
||||||
createUser(name:string): lib.User {
|
createUser(name:string): lib.User {
|
||||||
if (this.users.has(name)) {
|
if (this.users.has(name)) {
|
||||||
@@ -74,7 +75,7 @@ export default class UserManager {
|
|||||||
let roles = [];
|
let roles = [];
|
||||||
let defaultRoleId = this._config.get("controller.default_role_id");
|
let defaultRoleId = this._config.get("controller.default_role_id");
|
||||||
if (defaultRoleId !== null) {
|
if (defaultRoleId !== null) {
|
||||||
roles.push(defaultRoleId)
|
roles.push(defaultRoleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = new lib.User({ name, roles }, this.roles);
|
let user = new lib.User({ name, roles }, this.roles);
|
||||||
|
|||||||
@@ -54,7 +54,9 @@ export default class WsServer {
|
|||||||
noServer: true,
|
noServer: true,
|
||||||
path: "/api/socket",
|
path: "/api/socket",
|
||||||
});
|
});
|
||||||
this.wss.on("connection", (socket: lib.WebSocketClusterio, req: IncomingMessage) => this.handleConnection(socket, req));
|
this.wss.on("connection",
|
||||||
|
(socket: lib.WebSocketClusterio, req: IncomingMessage) => this.handleConnection(socket, req),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async stop(): Promise<void> {
|
async stop(): Promise<void> {
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ endpointHitCounter.labels = util.deprecate(
|
|||||||
"incrementing endpointHitCounter is no longer needed and has no effect"
|
"incrementing endpointHitCounter is no longer needed and has no effect"
|
||||||
);
|
);
|
||||||
|
|
||||||
export default endpointHitCounter
|
export default endpointHitCounter;
|
||||||
@@ -34,7 +34,7 @@ function mergeSamples(destinationResult: any, sourceResult: any) {
|
|||||||
|
|
||||||
// Prometheus polling endpoint
|
// Prometheus polling endpoint
|
||||||
async function getMetrics(req: Request, res: Response, next: any) {
|
async function getMetrics(req: Request, res: Response, next: any) {
|
||||||
const controller: Controller = req.app.locals.controller
|
const controller: Controller = req.app.locals.controller;
|
||||||
|
|
||||||
let results: any[] = [];
|
let results: any[] = [];
|
||||||
let pluginResults: any[] = await lib.invokeHook(controller.plugins, "onMetrics");
|
let pluginResults: any[] = await lib.invokeHook(controller.plugins, "onMetrics");
|
||||||
@@ -426,28 +426,29 @@ async function uploadSave(req: Request, res: Response) {
|
|||||||
|
|
||||||
if (contentMime === "multipart/form-data") {
|
if (contentMime === "multipart/form-data") {
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
let instanceId:number | undefined;
|
let instanceId: number | undefined;
|
||||||
let parser = busboy({ headers: req.headers });
|
function fileHandler(
|
||||||
parser.on("file", (name: string, stream: nodeStream.Readable, { filename, mimeType }: { filename: string, mimeType: string } ) => {
|
name: string,
|
||||||
|
stream: nodeStream.Readable,
|
||||||
|
{ filename, mimeType }: { filename: string, mimeType: string }
|
||||||
|
) {
|
||||||
if (instanceId === undefined) {
|
if (instanceId === undefined) {
|
||||||
requestErrors.push("instance_id must come before files uploaded");
|
requestErrors.push("instance_id must come before files uploaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!zipMimes.includes(mimeType)) {
|
if (!zipMimes.includes(mimeType)) {
|
||||||
requestErrors.push("invalid file Content-Type");
|
requestErrors.push("invalid file Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filename.endsWith(".zip")) {
|
if (!filename.endsWith(".zip")) {
|
||||||
requestErrors.push("filename must end with .zip");
|
requestErrors.push("filename must end with .zip");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errors.length || requestErrors.length) {
|
if (errors.length || requestErrors.length) {
|
||||||
stream.resume();
|
stream.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.push(handleFile(instanceId as number, stream, filename, mimeType));
|
tasks.push(handleFile(instanceId as number, stream, filename, mimeType));
|
||||||
});
|
}
|
||||||
|
let parser = busboy({ headers: req.headers });
|
||||||
|
parser.on("file", fileHandler);
|
||||||
parser.on("field", (name, value, info) => {
|
parser.on("field", (name, value, info) => {
|
||||||
if (name === "instance_id") {
|
if (name === "instance_id") {
|
||||||
instanceId = Number.parseInt(value, 10);
|
instanceId = Number.parseInt(value, 10);
|
||||||
@@ -593,23 +594,26 @@ async function uploadMod(req: Request, res: Response) {
|
|||||||
|
|
||||||
if (contentMime === "multipart/form-data") {
|
if (contentMime === "multipart/form-data") {
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
let parser = busboy({ headers: req.headers });
|
function fileHandler(
|
||||||
parser.on("file", (name:string, stream: nodeStream.Readable, { filename, mimeType }: { filename: string, mimeType: string }) => {
|
name: string,
|
||||||
|
stream: nodeStream.Readable,
|
||||||
|
{ filename, mimeType }: { filename: string, mimeType: string }
|
||||||
|
) {
|
||||||
if (!zipMimes.includes(mimeType)) {
|
if (!zipMimes.includes(mimeType)) {
|
||||||
requestErrors.push("invalid file Content-Type");
|
requestErrors.push("invalid file Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filename.endsWith(".zip")) {
|
if (!filename.endsWith(".zip")) {
|
||||||
requestErrors.push("filename must end with .zip");
|
requestErrors.push("filename must end with .zip");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errors.length || requestErrors.length) {
|
if (errors.length || requestErrors.length) {
|
||||||
stream.resume();
|
stream.resume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.push(handleFile(stream, filename));
|
tasks.push(handleFile(stream, filename));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
let parser = busboy({ headers: req.headers });
|
||||||
|
parser.on("file", fileHandler);
|
||||||
parser.on("close", resolve);
|
parser.on("close", resolve);
|
||||||
parser.on("error", (err: any) => {
|
parser.on("error", (err: any) => {
|
||||||
logger.error(`Error parsing multipart request in upload-mod:\n${err.stack}`);
|
logger.error(`Error parsing multipart request in upload-mod:\n${err.stack}`);
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ instanceConfigCommands.add(new lib.Command({
|
|||||||
});
|
});
|
||||||
await events.once(doneEmitter, "dot_on_done");
|
await events.once(doneEmitter, "dot_on_done");
|
||||||
try {
|
try {
|
||||||
await fs.unlink(tmpFile)
|
await fs.unlink(tmpFile);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
print("err: temporary file", tmpFile, "could not be deleted.");
|
print("err: temporary file", tmpFile, "could not be deleted.");
|
||||||
print("This is not fatal, but they may build up over time if the issue persists.");
|
print("This is not fatal, but they may build up over time if the issue persists.");
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import events from "events";
|
import events from "events";
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
import { FactorioServer } from "./server";
|
import { FactorioServer } from "./server";
|
||||||
import { SaveModule, patch } from "./patch";
|
import { SaveModule, patch } from "./patch";
|
||||||
import { exportData } from "./export";
|
import { exportData } from "./export";
|
||||||
import type Host from "./Host"
|
import type Host from "./Host";
|
||||||
|
|
||||||
|
|
||||||
const instanceRconCommandDuration = new lib.Histogram(
|
const instanceRconCommandDuration = new lib.Histogram(
|
||||||
@@ -99,7 +99,7 @@ export default class Instance extends lib.Link {
|
|||||||
/**
|
/**
|
||||||
* ID of this instance, equivalenet to `instance.config.get("instance.id")`.
|
* ID of this instance, equivalenet to `instance.config.get("instance.id")`.
|
||||||
*/
|
*/
|
||||||
readonly id: number
|
readonly id: number;
|
||||||
plugins: Map<string, lib.BaseInstancePlugin>;
|
plugins: Map<string, lib.BaseInstancePlugin>;
|
||||||
config: lib.InstanceConfig;
|
config: lib.InstanceConfig;
|
||||||
logger: lib.Logger;
|
logger: lib.Logger;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// Export of item icons and locale
|
// Export of item icons and locale
|
||||||
"use strict";
|
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import Jimp from "jimp";
|
import Jimp from "jimp";
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export class SaveModule {
|
|||||||
/** Module */
|
/** Module */
|
||||||
public info: lib.ModuleInfo,
|
public info: lib.ModuleInfo,
|
||||||
/** Files and their content that will be patched into the save */
|
/** Files and their content that will be patched into the save */
|
||||||
public files = new Map<string, Buffer>,
|
public files = new Map<string, Buffer>(),
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
static moduleFilePath(filePath: string, moduleName: string) {
|
static moduleFilePath(filePath: string, moduleName: string) {
|
||||||
@@ -47,7 +47,7 @@ export class SaveModule {
|
|||||||
if (entry.isFile()) {
|
if (entry.isFile()) {
|
||||||
let savePath = SaveModule.moduleFilePath(relativePath, this.info.name);
|
let savePath = SaveModule.moduleFilePath(relativePath, this.info.name);
|
||||||
this.files.set(savePath, await fs.readFile(fsPath));
|
this.files.set(savePath, await fs.readFile(fsPath));
|
||||||
if (relativePath == "module_exports.lua") {
|
if (relativePath === "module_exports.lua") {
|
||||||
this.files.set(
|
this.files.set(
|
||||||
`modules/${this.info.name}.lua`,
|
`modules/${this.info.name}.lua`,
|
||||||
Buffer.from(`return require("modules/${this.info.name}/module_exports")`, "utf-8")
|
Buffer.from(`return require("modules/${this.info.name}/module_exports")`, "utf-8")
|
||||||
@@ -96,7 +96,7 @@ export class SaveModule {
|
|||||||
version: plugin.info.version,
|
version: plugin.info.version,
|
||||||
dependencies: { "clusterio": "*" },
|
dependencies: { "clusterio": "*" },
|
||||||
...JSON.parse(await fs.readFile(moduleJsonPath, "utf8")),
|
...JSON.parse(await fs.readFile(moduleJsonPath, "utf8")),
|
||||||
}
|
};
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
throw new Error(`Loading module/module.json in plugin ${plugin.info.name} failed: ${err.message}`);
|
throw new Error(`Loading module/module.json in plugin ${plugin.info.name} failed: ${err.message}`);
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ export class PatchInfo {
|
|||||||
interface PatchInfoV0 {
|
interface PatchInfoV0 {
|
||||||
patch_number: number;
|
patch_number: number;
|
||||||
scenario: ScenarioInfoV0;
|
scenario: ScenarioInfoV0;
|
||||||
modules: { name: string, files: { path: string, load: boolean, require: boolean }[], }[];
|
modules: { name: string, files: { path: string, load: boolean, require: boolean }[], }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const info = json as unknown as PatchInfoV0;
|
const info = json as unknown as PatchInfoV0;
|
||||||
@@ -394,7 +394,7 @@ export async function patch(savePath: string, modules: SaveModule[]) {
|
|||||||
} else {
|
} else {
|
||||||
for (let module of patchInfo.modules) {
|
for (let module of patchInfo.modules) {
|
||||||
for (let file of module.files.keys()) {
|
for (let file of module.files.keys()) {
|
||||||
zip.remove(root.file(file)!.name)
|
zip.remove(root.file(file)!.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
patchInfo.modules = [];
|
patchInfo.modules = [];
|
||||||
|
|||||||
+51
-55
@@ -220,65 +220,61 @@ function parseOutput(line: string, source: "stdout" | "stderr"): lib.ParsedFacto
|
|||||||
level: secLogMatch[1],
|
level: secLogMatch[1],
|
||||||
file: secLogMatch[2],
|
file: secLogMatch[2],
|
||||||
message: secLogMatch[5],
|
message: secLogMatch[5],
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// The other possibility is that the content is a generic message
|
// The other possibility is that the content is a generic message
|
||||||
} else {
|
return {
|
||||||
|
source,
|
||||||
|
format,
|
||||||
|
time,
|
||||||
|
type: "generic",
|
||||||
|
message: secContent,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// The second category of output starts with a date stamp of the format
|
||||||
|
// "yyyy-mm-dd hh:mm:ss message"
|
||||||
|
const dateRegex = /^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d) (.*)$/;
|
||||||
|
let dateMatch = dateRegex.exec(line);
|
||||||
|
if (dateMatch) {
|
||||||
|
const format = "date";
|
||||||
|
const time = dateMatch[1];
|
||||||
|
let dateContent = dateMatch[2];
|
||||||
|
|
||||||
|
// A date output has two general formats. The first is an action
|
||||||
|
// followed by a message and has a format of "[ACTION] message"
|
||||||
|
const dateActionRegex = /^\[(\w+)\] (.*)$/;
|
||||||
|
let dateActionMatch = dateActionRegex.exec(dateContent);
|
||||||
|
if (dateActionMatch) {
|
||||||
return {
|
return {
|
||||||
source,
|
source,
|
||||||
format,
|
format,
|
||||||
time,
|
time,
|
||||||
type: "generic",
|
type: "action",
|
||||||
message: secContent,
|
action: dateActionMatch[1],
|
||||||
}
|
message: dateActionMatch[2],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// The second category of output starts with a date stamp of the format
|
// The other format is a generic message
|
||||||
// "yyyy-mm-dd hh:mm:ss message"
|
return {
|
||||||
} else {
|
source,
|
||||||
const dateRegex = /^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d) (.*)$/;
|
format,
|
||||||
let dateMatch = dateRegex.exec(line);
|
time,
|
||||||
if (dateMatch) {
|
type: "generic",
|
||||||
const format = "date";
|
message: dateContent,
|
||||||
const time = dateMatch[1];
|
};
|
||||||
let dateContent = dateMatch[2];
|
|
||||||
|
|
||||||
// A date output has two general formats. The first is an action
|
|
||||||
// followed by a message and has a format of "[ACTION] message"
|
|
||||||
const dateActionRegex = /^\[(\w+)\] (.*)$/;
|
|
||||||
let dateActionMatch = dateActionRegex.exec(dateContent);
|
|
||||||
if (dateActionMatch) {
|
|
||||||
return {
|
|
||||||
source,
|
|
||||||
format,
|
|
||||||
time,
|
|
||||||
type: "action",
|
|
||||||
action: dateActionMatch[1],
|
|
||||||
message: dateActionMatch[2],
|
|
||||||
}
|
|
||||||
|
|
||||||
// The other format is a generic message
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
source,
|
|
||||||
format,
|
|
||||||
time,
|
|
||||||
type: "generic",
|
|
||||||
message: dateContent,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The last category of output is simply a generic message with no
|
|
||||||
// formating.
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
source,
|
|
||||||
format: "none",
|
|
||||||
type: "generic",
|
|
||||||
message: line,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The last category of output is simply a generic message with no
|
||||||
|
// formating.
|
||||||
|
return {
|
||||||
|
source,
|
||||||
|
format: "none",
|
||||||
|
type: "generic",
|
||||||
|
message: line,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/a/49402091
|
// https://stackoverflow.com/a/49402091
|
||||||
@@ -465,7 +461,7 @@ export class FactorioServer extends events.EventEmitter {
|
|||||||
/** Enable Factorio.com based multiplayer bans **/
|
/** Enable Factorio.com based multiplayer bans **/
|
||||||
enableAuthserverBans: boolean;
|
enableAuthserverBans: boolean;
|
||||||
/** Enable verbose logging */
|
/** Enable verbose logging */
|
||||||
verboseLogging: boolean
|
verboseLogging: boolean;
|
||||||
/** Timeout in ms to wait for a response to a shutdown command */
|
/** Timeout in ms to wait for a response to a shutdown command */
|
||||||
hangTimeout = 5000;
|
hangTimeout = 5000;
|
||||||
|
|
||||||
@@ -852,8 +848,8 @@ export class FactorioServer extends events.EventEmitter {
|
|||||||
"--config", this.writePath("config.ini"),
|
"--config", this.writePath("config.ini"),
|
||||||
"--create", this.writePath("saves", name),
|
"--create", this.writePath("saves", name),
|
||||||
...(seed !== undefined ? ["--map-gen-seed", String(seed)] : []),
|
...(seed !== undefined ? ["--map-gen-seed", String(seed)] : []),
|
||||||
...(mapGenSettings !== undefined ?
|
...(mapGenSettings !== undefined
|
||||||
["--map-gen-settings", this.writePath("map-gen-settings.json")] : []
|
? ["--map-gen-settings", this.writePath("map-gen-settings.json")] : []
|
||||||
),
|
),
|
||||||
...(mapSettings !== undefined ? ["--map-settings", this.writePath("map-settings.json")] : []),
|
...(mapSettings !== undefined ? ["--map-settings", this.writePath("map-settings.json")] : []),
|
||||||
...(this.verboseLogging ? ["--verbose"] : []),
|
...(this.verboseLogging ? ["--verbose"] : []),
|
||||||
@@ -944,8 +940,8 @@ export class FactorioServer extends events.EventEmitter {
|
|||||||
"--config", this.writePath("config.ini"),
|
"--config", this.writePath("config.ini"),
|
||||||
"--start-server-load-scenario", scenario,
|
"--start-server-load-scenario", scenario,
|
||||||
...(seed !== undefined ? ["--map-gen-seed", String(seed)] : []),
|
...(seed !== undefined ? ["--map-gen-seed", String(seed)] : []),
|
||||||
...(mapGenSettings !== undefined ?
|
...(mapGenSettings !== undefined
|
||||||
["--map-gen-settings", this.writePath("map-gen-settings.json")] : []
|
? ["--map-gen-settings", this.writePath("map-gen-settings.json")] : []
|
||||||
),
|
),
|
||||||
...(mapSettings !== undefined ? ["--map-settings", this.writePath("map-settings.json")] : []),
|
...(mapSettings !== undefined ? ["--map-settings", this.writePath("map-settings.json")] : []),
|
||||||
"--port", String(this.gamePort),
|
"--port", String(this.gamePort),
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export * from "./src/shared_commands";
|
|||||||
export * from "./src/stream";
|
export * from "./src/stream";
|
||||||
export * from "./src/users";
|
export * from "./src/users";
|
||||||
export * from "./src/zip_ops";
|
export * from "./src/zip_ops";
|
||||||
export * from "./src/subscriptions"
|
export * from "./src/subscriptions";
|
||||||
|
|
||||||
export { default as ExponentialBackoff } from "./src/ExponentialBackoff";
|
export { default as ExponentialBackoff } from "./src/ExponentialBackoff";
|
||||||
export { default as PlayerStats } from "./src/PlayerStats";
|
export { default as PlayerStats } from "./src/PlayerStats";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Type, Static } from "@sinclair/typebox";
|
|||||||
import events from "events";
|
import events from "events";
|
||||||
|
|
||||||
import isDeepStrictEqual from "../is_deep_strict_equal";
|
import isDeepStrictEqual from "../is_deep_strict_equal";
|
||||||
import { basicType } from"../helpers";
|
import { basicType } from "../helpers";
|
||||||
|
|
||||||
|
|
||||||
export type ConfigLocation = "controller" | "host" | "instance" | "control";
|
export type ConfigLocation = "controller" | "host" | "instance" | "control";
|
||||||
|
|||||||
@@ -503,7 +503,10 @@ export class ControlConfig extends classes.Config { }
|
|||||||
ControlConfig.registerGroup(ControlGroup);
|
ControlConfig.registerGroup(ControlGroup);
|
||||||
|
|
||||||
|
|
||||||
function validateGroup(pluginInfo: PluginNodeEnvInfo|PluginWebpackEnvInfo, groupName: "ControllerConfigGroup"|"InstanceConfigGroup") {
|
function validateGroup(
|
||||||
|
pluginInfo: PluginNodeEnvInfo | PluginWebpackEnvInfo,
|
||||||
|
groupName: "ControllerConfigGroup"|"InstanceConfigGroup",
|
||||||
|
) {
|
||||||
if (!(pluginInfo[groupName]?.prototype instanceof classes.PluginConfigGroup)) {
|
if (!(pluginInfo[groupName]?.prototype instanceof classes.PluginConfigGroup)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Expected ${groupName} for ${pluginInfo.name} to be a subclass of PluginConfigGroup`
|
`Expected ${groupName} for ${pluginInfo.name} to be a subclass of PluginConfigGroup`
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
import zlib from "zlib";
|
import zlib from "zlib";
|
||||||
import { Type, Static } from "@sinclair/typebox";
|
import { Type, Static } from "@sinclair/typebox";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Type } from "@sinclair/typebox";
|
import { Type } from "@sinclair/typebox";
|
||||||
|
|
||||||
export function StringEnum<T extends string[]>(values: [...T]) {
|
export function StringEnum<T extends string[]>(values: [...T]) {
|
||||||
return Type.Unsafe<T[number]>({ type: 'string', enum: values })
|
return Type.Unsafe<T[number]>({ type: "string", enum: values });
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface JSONDeserialisable<T> {
|
export interface JSONDeserialisable<T> {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import type { ValidateFunction } from "ajv";
|
import type { ValidateFunction } from "ajv";
|
||||||
import type { Message } from "./messages_core";
|
import type { Message } from "./messages_core";
|
||||||
var message_validate: ValidateFunction<Message>;
|
const message_validate: ValidateFunction<Message>;
|
||||||
export default message_validate;
|
export default message_validate;
|
||||||
@@ -166,6 +166,7 @@ export class LogQueryRequest {
|
|||||||
json.all, json.controller, json.hostIds, json.instanceIds, json.maxLevel, json.limit, json.order
|
json.all, json.controller, json.hostIds, json.instanceIds, json.maxLevel, json.limit, json.order
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Response = class Response {
|
static Response = class Response {
|
||||||
constructor(
|
constructor(
|
||||||
public log: object[],
|
public log: object[],
|
||||||
|
|||||||
@@ -23,7 +23,15 @@ export class HostDetails {
|
|||||||
});
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||||
return new this(json.agent, json.version, json.name, json.id, json.connected, json.publicAddress, json.tokenValidAfter);
|
return new this(
|
||||||
|
json.agent,
|
||||||
|
json.version,
|
||||||
|
json.name,
|
||||||
|
json.id,
|
||||||
|
json.connected,
|
||||||
|
json.publicAddress,
|
||||||
|
json.tokenValidAfter,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ export class RawUser { // TODO refactor into lib/user.User
|
|||||||
isDeleted: this.isDeleted,
|
isDeleted: this.isDeleted,
|
||||||
};
|
};
|
||||||
if (this.playerStats) {
|
if (this.playerStats) {
|
||||||
json.playerStats = this.playerStats.toJSON()
|
json.playerStats = this.playerStats.toJSON();
|
||||||
}
|
}
|
||||||
if (this.instanceStats) {
|
if (this.instanceStats) {
|
||||||
json.instanceStats = [...this.instanceStats].map(([k, v]) => [k, v.toJSON()]);
|
json.instanceStats = [...this.instanceStats].map(([k, v]) => [k, v.toJSON()]);
|
||||||
|
|||||||
@@ -277,8 +277,9 @@ export class ItemDatabase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow to iterate through the items.
|
* Allow to iterate through the items.
|
||||||
|
* @returns array of items.
|
||||||
*/
|
*/
|
||||||
getEntries(): IterableIterator<[string, number]> {
|
getEntries(): IterableIterator<[string, number]> {
|
||||||
return this._items.entries()
|
return this._items.entries();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
import zlib from "zlib";
|
import zlib from "zlib";
|
||||||
|
|
||||||
class MapReaderState {
|
class MapReaderState {
|
||||||
@@ -72,7 +71,7 @@ function readString(state: MapReaderState) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function readOptional<T>(state: MapReaderState, readValue: (state: MapReaderState) => T) {
|
function readOptional<T>(state: MapReaderState, readValue: (s: MapReaderState) => T) {
|
||||||
let load = readUInt8(state) !== 0;
|
let load = readUInt8(state) !== 0;
|
||||||
if (!load) {
|
if (!load) {
|
||||||
return null;
|
return null;
|
||||||
@@ -80,7 +79,7 @@ function readOptional<T>(state: MapReaderState, readValue: (state: MapReaderStat
|
|||||||
return readValue(state);
|
return readValue(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
function readArray<T>(state: MapReaderState, readItem: (state: MapReaderState) => T) {
|
function readArray<T>(state: MapReaderState, readItem: (s: MapReaderState) => T) {
|
||||||
let size = readUInt32so(state);
|
let size = readUInt32so(state);
|
||||||
|
|
||||||
let array: T[] = [];
|
let array: T[] = [];
|
||||||
@@ -94,8 +93,8 @@ function readArray<T>(state: MapReaderState, readItem: (state: MapReaderState) =
|
|||||||
|
|
||||||
function readDict<K, V>(
|
function readDict<K, V>(
|
||||||
state: MapReaderState,
|
state: MapReaderState,
|
||||||
readKey: (state: MapReaderState) => K,
|
readKey: (s: MapReaderState) => K,
|
||||||
readValue: (state: MapReaderState) => V
|
readValue: (s: MapReaderState) => V
|
||||||
) {
|
) {
|
||||||
let size = readUInt32so(state);
|
let size = readUInt32so(state);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
export default function isDeepStrictEqual(a: any, b: any): boolean
|
export default function isDeepStrictEqual(a: any, b: any): boolean;
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
// Connection adapters for Links
|
// Connection adapters for Links
|
||||||
"use strict";
|
|
||||||
import { strict as assert } from "assert";
|
import { strict as assert } from "assert";
|
||||||
import events from "events";
|
import events from "events";
|
||||||
import WebSocket from "./WebSocket";
|
import WebSocket from "./WebSocket";
|
||||||
|
|
||||||
import * as libData from "../data";
|
import * as libData from "../data";
|
||||||
import * as libErrors from "../errors";
|
import * as libErrors from "../errors";
|
||||||
import { logger } from "../logging";
|
import { logger } from "../logging";
|
||||||
import ExponentialBackoff from "../ExponentialBackoff";
|
import ExponentialBackoff from "../ExponentialBackoff";
|
||||||
import type { Request, Event } from "./link";
|
import type { Request, Event } from "./link";
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
* @module lib/link
|
* @module lib/link
|
||||||
* @author Hornwitser
|
* @author Hornwitser
|
||||||
*/
|
*/
|
||||||
export * from "./link"
|
export * from "./link";
|
||||||
export * from "./connectors"
|
export * from "./connectors";
|
||||||
@@ -316,7 +316,7 @@ export class Link {
|
|||||||
if (!this.router) {
|
if (!this.router) {
|
||||||
let err = new libErrors.InvalidMessage(
|
let err = new libErrors.InvalidMessage(
|
||||||
`Received message addressed to ${(message as libData.MessageRequest).dst} but this link `+
|
`Received message addressed to ${(message as libData.MessageRequest).dst} but this link `+
|
||||||
`does not route messages`
|
"does not route messages"
|
||||||
);
|
);
|
||||||
if (message.type === "request") {
|
if (message.type === "request") {
|
||||||
this.connector.sendResponseError(
|
this.connector.sendResponseError(
|
||||||
@@ -401,8 +401,8 @@ export class Link {
|
|||||||
this.connector.sendResponseError(
|
this.connector.sendResponseError(
|
||||||
new libData.ResponseError(err.message, err.code, err.stack), message.src, spoofedSrc
|
new libData.ResponseError(err.message, err.code, err.stack), message.src, spoofedSrc
|
||||||
);
|
);
|
||||||
} catch (err: any) {
|
} catch (subErr: any) {
|
||||||
logger.error(`Unexpected error sending error response for ${message.name}:\n${err.stack}`);
|
logger.error(`Unexpected error sending error response for ${message.name}:\n${subErr.stack}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -527,7 +527,7 @@ export class Link {
|
|||||||
let requestId = this._nextRequestId;
|
let requestId = this._nextRequestId;
|
||||||
this._nextRequestId += 1;
|
this._nextRequestId += 1;
|
||||||
this._pendingRequests.set(
|
this._pendingRequests.set(
|
||||||
requestId, { request: entry, promise, resolve: resolve!, reject: reject!, dst, }
|
requestId, { request: entry, promise, resolve: resolve!, reject: reject!, dst }
|
||||||
);
|
);
|
||||||
this.connector.sendRequest(request, requestId, dst);
|
this.connector.sendRequest(request, requestId, dst);
|
||||||
return promise;
|
return promise;
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
"use strict";
|
|
||||||
import * as core from "../data/messages_core";
|
import * as core from "../data/messages_core";
|
||||||
import * as controller from "../data/messages_controller";
|
import * as controller from "../data/messages_controller";
|
||||||
import * as host from "../data/messages_host";
|
import * as host from "../data/messages_host";
|
||||||
import * as instance from "../data/messages_instance";
|
import * as instance from "../data/messages_instance";
|
||||||
import * as mod from "../data/messages_mod";
|
import * as mod from "../data/messages_mod";
|
||||||
import * as user from "../data/messages_user";
|
import * as user from "../data/messages_user";
|
||||||
import * as subscriptions from "../subscriptions"
|
import * as subscriptions from "../subscriptions";
|
||||||
import type { RequestClass, EventClass } from "./link";
|
import type { RequestClass, EventClass } from "./link";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
import winston from "winston";
|
import winston from "winston";
|
||||||
import Transport from "winston-transport";
|
import Transport from "winston-transport";
|
||||||
import { LEVEL, MESSAGE } from "triple-beam";
|
import { LEVEL, MESSAGE } from "triple-beam";
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
* @author Hornwitser
|
* @author Hornwitser
|
||||||
* @module lib/logging_utils
|
* @module lib/logging_utils
|
||||||
*/
|
*/
|
||||||
"use strict";
|
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import stream from "stream";
|
import stream from "stream";
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ export class BaseInstancePlugin {
|
|||||||
message: string,
|
message: string,
|
||||||
expectEmpty: boolean,
|
expectEmpty: boolean,
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
private _sendingRconMessages = false;
|
private _sendingRconMessages = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -655,7 +656,6 @@ export class BaseControlPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin supplied login form
|
* Plugin supplied login form
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export async function loadControllerPluginClass(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load instance plugin class of a plugin
|
* Load instance plugin class of a plugin
|
||||||
|
*
|
||||||
* @param pluginInfo -
|
* @param pluginInfo -
|
||||||
* Plugin info object returned from {@link
|
* Plugin info object returned from {@link
|
||||||
* loadPluginInfos} to load class from.
|
* loadPluginInfos} to load class from.
|
||||||
|
|||||||
@@ -1188,7 +1188,7 @@ class HistogramChild {
|
|||||||
protected _bucketValues: Map<string, number>;
|
protected _bucketValues: Map<string, number>;
|
||||||
protected _sumValues: Map<string, number>;
|
protected _sumValues: Map<string, number>;
|
||||||
protected _countValues: Map<string, number>;
|
protected _countValues: Map<string, number>;
|
||||||
protected _key: string
|
protected _key: string;
|
||||||
protected _bucketKeys: Map<number, string>;
|
protected _bucketKeys: Map<number, string>;
|
||||||
|
|
||||||
constructor(collector: Histogram, key: string) {
|
constructor(collector: Histogram, key: string) {
|
||||||
@@ -1438,6 +1438,7 @@ export class Histogram extends LabeledCollector<HistogramChild> {
|
|||||||
* Observe a given value and increment matching buckets
|
* Observe a given value and increment matching buckets
|
||||||
*
|
*
|
||||||
* Note: Only works if this is an unlabeled collector.
|
* Note: Only works if this is an unlabeled collector.
|
||||||
|
* @param value - number to count into histogram buckets.
|
||||||
*/
|
*/
|
||||||
observe(value: number) {
|
observe(value: number) {
|
||||||
this._defaultChild!.observe(value);
|
this._defaultChild!.observe(value);
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ export function compile<T>(schema: JSONSchemaType<T>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let doValidate: ValidateFunction<T>;
|
let doValidate: ValidateFunction<T>;
|
||||||
const validate = <ValidateFunction<T>>function (data) {
|
const validate = <ValidateFunction<T>> function (data) {
|
||||||
if (!doValidate) {
|
if (!doValidate) {
|
||||||
doValidate = ajv.compile(schema);
|
doValidate = ajv.compile(schema);
|
||||||
}
|
}
|
||||||
let result = doValidate(data);
|
let result = doValidate(data);
|
||||||
validate.errors = doValidate.errors;
|
validate.errors = doValidate.errors;
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
return validate
|
return validate;
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
* Implementation of commands shared between controller/host/ctl.
|
* Implementation of commands shared between controller/host/ctl.
|
||||||
* @module lib/shared_commands
|
* @module lib/shared_commands
|
||||||
*/
|
*/
|
||||||
"use strict";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
import * as libConfig from "./config";
|
import * as libConfig from "./config";
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import stream from "stream";
|
import stream from "stream";
|
||||||
|
|||||||
@@ -33,16 +33,15 @@ export class SubscriptionResponse {
|
|||||||
Type.String(),
|
Type.String(),
|
||||||
Type.Unknown(),
|
Type.Unknown(),
|
||||||
]),
|
]),
|
||||||
Type.Null()
|
Type.Null(),
|
||||||
])
|
]);
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
if (this.eventReplay) {
|
if (this.eventReplay) {
|
||||||
const entry = Link._eventsByClass.get(this.eventReplay.constructor)!;
|
const entry = Link._eventsByClass.get(this.eventReplay.constructor)!;
|
||||||
return [entry.name, this.eventReplay];
|
return [entry.name, this.eventReplay];
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof SubscriptionResponse.jsonSchema>): SubscriptionResponse {
|
static fromJSON(json: Static<typeof SubscriptionResponse.jsonSchema>): SubscriptionResponse {
|
||||||
@@ -67,7 +66,7 @@ export class SubscriptionResponse {
|
|||||||
export class SubscriptionRequest {
|
export class SubscriptionRequest {
|
||||||
declare ["constructor"]: typeof SubscriptionRequest;
|
declare ["constructor"]: typeof SubscriptionRequest;
|
||||||
static type = "request" as const;
|
static type = "request" as const;
|
||||||
static src = ["control", "instance"] as const;
|
static src = ["control", "instance"] as const;
|
||||||
static dst = "controller" as const;
|
static dst = "controller" as const;
|
||||||
static Response = SubscriptionResponse;
|
static Response = SubscriptionResponse;
|
||||||
static permission(user: User, message: MessageRequest) {
|
static permission(user: User, message: MessageRequest) {
|
||||||
@@ -100,7 +99,7 @@ export class SubscriptionRequest {
|
|||||||
Type.Boolean(),
|
Type.Boolean(),
|
||||||
Type.Array(Type.Union([Type.String(), Type.Number()])),
|
Type.Array(Type.Union([Type.String(), Type.Number()])),
|
||||||
Type.Number(),
|
Type.Number(),
|
||||||
])
|
]);
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return [this.eventName, this.allChannels, this.channels, this.lastRequestTime];
|
return [this.eventName, this.allChannels, this.channels, this.lastRequestTime];
|
||||||
@@ -130,6 +129,9 @@ export class SubscriptionController {
|
|||||||
/**
|
/**
|
||||||
* Allow clients to subscribe to an event by telling the subscription controller to accept them
|
* Allow clients to subscribe to an event by telling the subscription controller to accept them
|
||||||
* Has an optional subscription update handler which is called when any client updates their subscription
|
* Has an optional subscription update handler which is called when any client updates their subscription
|
||||||
|
* @param Event - Event class which is sent out as updates.
|
||||||
|
* @param subscriptionUpdate -
|
||||||
|
* Optional handler called when a client updates its subscriptions.
|
||||||
*/
|
*/
|
||||||
handle<T>(Event: EventClass<T>, subscriptionUpdate?: SubscriptionRequestHandler<T>) {
|
handle<T>(Event: EventClass<T>, subscriptionUpdate?: SubscriptionRequestHandler<T>) {
|
||||||
const entry = Link._eventsByClass.get(Event);
|
const entry = Link._eventsByClass.get(Event);
|
||||||
@@ -147,6 +149,7 @@ export class SubscriptionController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcast an event to all subscribers of that event, will be filtered by channel if a ChannelEvent is provided
|
* Broadcast an event to all subscribers of that event, will be filtered by channel if a ChannelEvent is provided
|
||||||
|
* @param event - Event to broadcast.
|
||||||
*/
|
*/
|
||||||
broadcast<T>(event: Event<T> | ChannelEvent<T>) {
|
broadcast<T>(event: Event<T> | ChannelEvent<T>) {
|
||||||
const entry = Link._eventsByClass.get(event.constructor);
|
const entry = Link._eventsByClass.get(event.constructor);
|
||||||
@@ -169,6 +172,11 @@ export class SubscriptionController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle incoming event subscription requests
|
* Handle incoming event subscription requests
|
||||||
|
* @param event - incomming event.
|
||||||
|
* @param src - Source address of incomming request.
|
||||||
|
* @param dst - destination address of incomming request.
|
||||||
|
* @returns Response to subscription request.
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
async _handleRequest(event: SubscriptionRequest, src: Address, dst: Address) {
|
async _handleRequest(event: SubscriptionRequest, src: Address, dst: Address) {
|
||||||
if (!Link._eventsByName.has(event.eventName)) {
|
if (!Link._eventsByName.has(event.eventName)) {
|
||||||
@@ -192,7 +200,9 @@ export class SubscriptionController {
|
|||||||
onceClose = () => eventData.subscriptions.delete(link);
|
onceClose = () => eventData.subscriptions.delete(link);
|
||||||
link.connector.once("close", onceClose);
|
link.connector.once("close", onceClose);
|
||||||
}
|
}
|
||||||
eventData.subscriptions.set(link, { all: event.allChannels, channels: event.channels, onceClose: onceClose });
|
eventData.subscriptions.set(
|
||||||
|
link, { all: event.allChannels, channels: event.channels, onceClose: onceClose },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return new SubscriptionResponse(eventReplay);
|
return new SubscriptionResponse(eventReplay);
|
||||||
}
|
}
|
||||||
@@ -204,15 +214,15 @@ export class SubscriptionController {
|
|||||||
* Multiple handlers can be subscribed at the same time, on the same or different channels
|
* Multiple handlers can be subscribed at the same time, on the same or different channels
|
||||||
*/
|
*/
|
||||||
export class EventSubscriber<T, V=T> {
|
export class EventSubscriber<T, V=T> {
|
||||||
_callbacks = new Array<EventSubscriberCallback<V>>()
|
_callbacks = new Array<EventSubscriberCallback<V>>();
|
||||||
_channelCallbacks = new Map<string | number, Array<EventSubscriberCallback<V>>>()
|
_channelCallbacks = new Map<string | number, Array<EventSubscriberCallback<V>>>();
|
||||||
lastResponse: Event<T> | null = null;
|
lastResponse: Event<T> | null = null;
|
||||||
lastResponseTime = 0;
|
lastResponseTime = 0;
|
||||||
control?: Link
|
control?: Link;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private event: EventClass<T> | ChannelEventClass<T>,
|
private event: EventClass<T> | ChannelEventClass<T>,
|
||||||
private prehandler?: (event: T) => V,
|
private prehandler?: (e: T) => V,
|
||||||
control?: Link
|
control?: Link
|
||||||
) {
|
) {
|
||||||
const entry = Link._eventsByClass.get(this.event);
|
const entry = Link._eventsByClass.get(this.event);
|
||||||
@@ -226,6 +236,8 @@ export class EventSubscriber<T, V=T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle incoming events and distribute it to the correct callbacks
|
* Handle incoming events and distribute it to the correct callbacks
|
||||||
|
* @param response - event from subscribed resource
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
async _handle(response: Event<T> | ChannelEvent<T>) {
|
async _handle(response: Event<T> | ChannelEvent<T>) {
|
||||||
this.lastResponse = response;
|
this.lastResponse = response;
|
||||||
@@ -246,10 +258,14 @@ export class EventSubscriber<T, V=T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a control link was not connected at creation, it can be connected here (normally during onControllerConnectionEvent)
|
* If a control link was not connected at creation, it can be connected
|
||||||
|
* here (normally during onControllerConnectionEvent)
|
||||||
|
* @param control - Control link to associate with.
|
||||||
*/
|
*/
|
||||||
async connectControl(control: Link) {
|
async connectControl(control: Link) {
|
||||||
if (this.control === control) return;
|
if (this.control === control) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.control = control;
|
this.control = control;
|
||||||
this.control.handle(this.event, this._handle.bind(this));
|
this.control.handle(this.event, this._handle.bind(this));
|
||||||
await this._updateSubscription();
|
await this._updateSubscription();
|
||||||
@@ -257,6 +273,8 @@ export class EventSubscriber<T, V=T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe to receive all event notifications
|
* Subscribe to receive all event notifications
|
||||||
|
* @param handler -
|
||||||
|
* callback invoked whenever the subscribed resource changes.
|
||||||
*/
|
*/
|
||||||
async subscribe(handler: EventSubscriberCallback<V>) {
|
async subscribe(handler: EventSubscriberCallback<V>) {
|
||||||
this._callbacks.push(handler);
|
this._callbacks.push(handler);
|
||||||
@@ -265,6 +283,10 @@ export class EventSubscriber<T, V=T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe to receive event notifications for the given channel
|
* Subscribe to receive event notifications for the given channel
|
||||||
|
* @param channel - Channel to subscribe to.
|
||||||
|
* @param handler -
|
||||||
|
* callback invoked whenever the subscribed resource changes on the
|
||||||
|
* given channel.
|
||||||
*/
|
*/
|
||||||
async subscribeToChannel(channel: string | number, handler: EventSubscriberCallback<V>) {
|
async subscribeToChannel(channel: string | number, handler: EventSubscriberCallback<V>) {
|
||||||
if (!this._channelCallbacks.get(channel)) {
|
if (!this._channelCallbacks.get(channel)) {
|
||||||
@@ -275,8 +297,14 @@ export class EventSubscriber<T, V=T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsubscribe from receiving all event notifications, does not effect the subscriptions of other handlers
|
* Unsubscribe from receiving all event notifications, does not effect
|
||||||
* Will throw an error if your handler is not subscribed to all channels, does not accept anonymous functions
|
* the subscriptions of other handlers.
|
||||||
|
*
|
||||||
|
* @param handler - A callback previously passed to {@link subscribe}
|
||||||
|
*
|
||||||
|
* @throws {Error}
|
||||||
|
* If your handler is not subscribed to all channels, does not
|
||||||
|
* accept anonymous functions
|
||||||
*/
|
*/
|
||||||
async unsubscribe(handler: EventSubscriberCallback<V>) {
|
async unsubscribe(handler: EventSubscriberCallback<V>) {
|
||||||
let index = this._callbacks.lastIndexOf(handler);
|
let index = this._callbacks.lastIndexOf(handler);
|
||||||
@@ -289,8 +317,15 @@ export class EventSubscriber<T, V=T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsubscribe from receiving event notifications for a given channel, does not effect the subscriptions of other handlers
|
* Unsubscribe from receiving event notifications for a given channel,
|
||||||
* Will throw an error if your handler is not subscribed to the channel, does not accept anonymous functions
|
* does not effect the subscriptions of other handlers.
|
||||||
|
*
|
||||||
|
* @param channel - A channel previously passed to {@link subscribeToChannel}
|
||||||
|
* @param handler - A callback previously passed to {@link subscribeToChannel}
|
||||||
|
*
|
||||||
|
* @throws {Error}
|
||||||
|
* If your handler is not subscribed to the channel or does not
|
||||||
|
* accept anonymous functions
|
||||||
*/
|
*/
|
||||||
async unsubscribeFromChannel(channel: string | number, handler: EventSubscriberCallback<V>) {
|
async unsubscribeFromChannel(channel: string | number, handler: EventSubscriberCallback<V>) {
|
||||||
const channelCallbacks = this._channelCallbacks.get(channel);
|
const channelCallbacks = this._channelCallbacks.get(channel);
|
||||||
@@ -315,7 +350,9 @@ export class EventSubscriber<T, V=T> {
|
|||||||
* Update the subscription with the controller based on current handler counts
|
* Update the subscription with the controller based on current handler counts
|
||||||
*/
|
*/
|
||||||
async _updateSubscription() {
|
async _updateSubscription() {
|
||||||
if (!this.control || !(this.control.connector as WebSocketClientConnector).connected) return;
|
if (!this.control || !(this.control.connector as WebSocketClientConnector).connected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const entry = Link._eventsByClass.get(this.event)!;
|
const entry = Link._eventsByClass.get(this.event)!;
|
||||||
|
|
||||||
const response = await this.control.send(new SubscriptionRequest(
|
const response = await this.control.send(new SubscriptionRequest(
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
* @author Hornwitser
|
* @author Hornwitser
|
||||||
* @module lib/users
|
* @module lib/users
|
||||||
*/
|
*/
|
||||||
"use strict";
|
|
||||||
import * as libErrors from "./errors";
|
import * as libErrors from "./errors";
|
||||||
|
|
||||||
import PlayerStats from "./PlayerStats";
|
import PlayerStats from "./PlayerStats";
|
||||||
@@ -328,6 +327,7 @@ export class User {
|
|||||||
}
|
}
|
||||||
return playerStats;
|
return playerStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set of users currently online in the cluster.
|
* Set of users currently online in the cluster.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
declare module '*.png' {
|
declare module "*.png" {
|
||||||
const value: import('react-native').ImageSourcePropType;
|
const value: import("react-native").ImageSourcePropType;
|
||||||
export default value;
|
export default value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ export default function HostViewPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let hostButtons = <Space> {
|
let hostButtons = <Space> {
|
||||||
account.hasPermission("core.host.revoke_access") &&
|
account.hasPermission("core.host.revoke_access")
|
||||||
<Popconfirm
|
&& <Popconfirm
|
||||||
title={`Revoke tokens of ${host.name}?`}
|
title={`Revoke tokens of ${host.name}?`}
|
||||||
placement="bottomRight"
|
placement="bottomRight"
|
||||||
okText="Revoke Tokens"
|
okText="Revoke Tokens"
|
||||||
@@ -50,15 +50,15 @@ export default function HostViewPage() {
|
|||||||
onConfirm={() => {
|
onConfirm={() => {
|
||||||
control.send(new lib.HostRevokeTokensRequest(host.id!))
|
control.send(new lib.HostRevokeTokensRequest(host.id!))
|
||||||
.then(() => notify("Host tokens revoked"))
|
.then(() => notify("Host tokens revoked"))
|
||||||
.catch(notifyErrorHandler(`Error revoking tokens for host id:${host.id}`))
|
.catch(notifyErrorHandler(`Error revoking tokens for host id:${host.id}`));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button danger>
|
<Button danger>
|
||||||
Revoke tokens
|
Revoke tokens
|
||||||
</Button>
|
</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
}
|
}
|
||||||
</Space>
|
</Space>;
|
||||||
|
|
||||||
return <PageLayout nav={nav}>
|
return <PageLayout nav={nav}>
|
||||||
<PageHeader
|
<PageHeader
|
||||||
@@ -75,9 +75,9 @@ export default function HostViewPage() {
|
|||||||
<Descriptions.Item label="Agent">{host["agent"]}</Descriptions.Item>
|
<Descriptions.Item label="Agent">{host["agent"]}</Descriptions.Item>
|
||||||
<Descriptions.Item label="Version">{host["version"]}</Descriptions.Item>
|
<Descriptions.Item label="Version">{host["version"]}</Descriptions.Item>
|
||||||
{
|
{
|
||||||
host.tokenValidAfter &&
|
host.tokenValidAfter
|
||||||
<Descriptions.Item label="Tokens valid after:">
|
&& <Descriptions.Item label="Tokens valid after:">
|
||||||
{formatTimestamp(host.tokenValidAfter*1000)}
|
{formatTimestamp(host.tokenValidAfter*1000)}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
}
|
}
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ function GenerateHostTokenButton() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
async function generateToken() {
|
async function generateToken() {
|
||||||
let id = undefined;
|
let id;
|
||||||
let values = form.getFieldsValue();
|
let values = form.getFieldsValue();
|
||||||
if (values.hostId) {
|
if (values.hostId) {
|
||||||
id = Number.parseInt(values.hostId, 10);
|
id = Number.parseInt(values.hostId, 10);
|
||||||
@@ -114,12 +114,12 @@ function GenerateHostTokenButton() {
|
|||||||
<div className="codeblock">
|
<div className="codeblock">
|
||||||
<CopyButton
|
<CopyButton
|
||||||
message={"Copied host setup commands to clipboard"}
|
message={"Copied host setup commands to clipboard"}
|
||||||
text={`
|
text={`\
|
||||||
mkdir clusterio
|
mkdir clusterio
|
||||||
cd clusterio
|
cd clusterio
|
||||||
`+
|
npm init "@clusterio" -- --controller-token ${token} --mode "host" --download-headless \
|
||||||
// eslint-disable-next-line max-len
|
--controller-url ${document.location.origin}/ --host-name "Host ${hostId || "?"}" \
|
||||||
`npm init "@clusterio" -- --controller-token ${token} --mode "host" --download-headless --controller-url ${document.location.origin}/ --host-name "Host ${hostId || "?"}" --public-address localhost ${pluginString.length ? "--plugins" : ""} ${pluginString}`
|
--public-address localhost ${pluginString.length ? "--plugins" : ""} ${pluginString}`
|
||||||
}/>
|
}/>
|
||||||
<p>> mkdir clusterio</p>
|
<p>> mkdir clusterio</p>
|
||||||
<p>> cd clusterio</p>
|
<p>> cd clusterio</p>
|
||||||
@@ -166,7 +166,7 @@ function CopyButton({ text, message }: { text:string, message:string }) {
|
|||||||
return result.state === "granted";
|
return result.state === "granted";
|
||||||
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
//If it fail because "clipboard-write" is not supported.
|
// If it fail because "clipboard-write" is not supported.
|
||||||
return err.name === "TypeError";
|
return err.name === "TypeError";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ export default function HostsPage() {
|
|||||||
{host.connected ? "Connected" : "Disconnected"}
|
{host.connected ? "Connected" : "Disconnected"}
|
||||||
</Tag>,
|
</Tag>,
|
||||||
sorter: (a, b) => Number(a.connected) - Number(b.connected),
|
sorter: (a, b) => Number(a.connected) - Number(b.connected),
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
dataSource={hostList}
|
dataSource={hostList}
|
||||||
rowKey={host => host.id}
|
rowKey={host => host.id}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ export default function InstanceList(props: InstanceListProps) {
|
|||||||
responsive: ["sm"],
|
responsive: ["sm"],
|
||||||
align: "right",
|
align: "right",
|
||||||
width: 100,
|
width: 100,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.hideAssignedHost) {
|
if (props.hideAssignedHost) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useContext, useState } from "react";
|
import React, { useContext, useState } from "react";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { Alert, Button, Descriptions, Dropdown, Menu, MenuProps, Modal, Space, Spin, Typography } from "antd";
|
import { Alert, Button, Descriptions, Dropdown, Menu, MenuProps, Modal, Space, Spin, Typography } from "antd";
|
||||||
import type { ItemType } from 'antd/es/menu/hooks/useItems';
|
import type { ItemType } from "antd/es/menu/hooks/useItems";
|
||||||
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
||||||
import DownOutlined from "@ant-design/icons/DownOutlined";
|
import DownOutlined from "@ant-design/icons/DownOutlined";
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ function SearchModsTable(props: SearchModsTableProps) {
|
|||||||
const [modResultPage, setModResultPage] = useState<number>(1);
|
const [modResultPage, setModResultPage] = useState<number>(1);
|
||||||
const [modResultPageSize, setModResultPageSize] = useState<number>(10);
|
const [modResultPageSize, setModResultPageSize] = useState<number>(10);
|
||||||
const [modResultCount, setModResultCount] = useState<number>(2);
|
const [modResultCount, setModResultCount] = useState<number>(2);
|
||||||
const [modResultSelectedVersion, setModResultSelectedVersion] = useState<Map<string,number>>(new Map());
|
const [modResultSelectedVersion, setModResultSelectedVersion] = useState<Map<string, number>>(new Map());
|
||||||
|
|
||||||
const factorioVersion = props.modPack.factorioVersion.split(".").slice(0, 2).join(".");
|
const factorioVersion = props.modPack.factorioVersion.split(".").slice(0, 2).join(".");
|
||||||
|
|
||||||
@@ -216,7 +216,9 @@ function SearchModsTable(props: SearchModsTableProps) {
|
|||||||
title: "Action",
|
title: "Action",
|
||||||
key: "action",
|
key: "action",
|
||||||
responsive: ["lg"],
|
responsive: ["lg"],
|
||||||
render: (result:ModResult) => actions(result.versions[modResultSelectedVersion.get(result.name) || 0]),
|
render: (result:ModResult) => (
|
||||||
|
actions(result.versions[modResultSelectedVersion.get(result.name) || 0])
|
||||||
|
),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
expandable={{
|
expandable={{
|
||||||
@@ -294,11 +296,13 @@ function ModsTable(props: ModsTableProps) {
|
|||||||
>remove</Typography.Link>}
|
>remove</Typography.Link>}
|
||||||
{(deletedMods.has(mod.name) || changedMods.has(mod.name)) && <Typography.Link
|
{(deletedMods.has(mod.name) || changedMods.has(mod.name)) && <Typography.Link
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
props.onRevert && props.onRevert({
|
if (props.onRevert) {
|
||||||
type: deletedMods.has(mod.name) ? "mods.delete" : "mods.set",
|
props.onRevert({
|
||||||
name: mod.name,
|
type: deletedMods.has(mod.name) ? "mods.delete" : "mods.set",
|
||||||
value: mod,
|
name: mod.name,
|
||||||
});
|
value: mod,
|
||||||
|
});
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>revert</Typography.Link>}
|
>revert</Typography.Link>}
|
||||||
</Space>;
|
</Space>;
|
||||||
@@ -337,7 +341,9 @@ function ModsTable(props: ModsTableProps) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const added = selectedRowKeys.filter(key => !props.modPack.mods.get(key as string)?.enabled) as string[];
|
const added = selectedRowKeys.filter(
|
||||||
|
key => !props.modPack.mods.get(key as string)?.enabled
|
||||||
|
) as string[];
|
||||||
const removed = [...props.modPack.mods.values()].filter(
|
const removed = [...props.modPack.mods.values()].filter(
|
||||||
mod => mod.enabled && selectedRowKeys.indexOf(mod.name) === -1
|
mod => mod.enabled && selectedRowKeys.indexOf(mod.name) === -1
|
||||||
).map(mod => mod.name);
|
).map(mod => mod.name);
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ import { notifyErrorHandler } from "../util/notify";
|
|||||||
|
|
||||||
|
|
||||||
export type RawRoleState = Partial<lib.RawRole> & {
|
export type RawRoleState = Partial<lib.RawRole> & {
|
||||||
loading?: Boolean;
|
loading?: boolean;
|
||||||
missing?: Boolean;
|
missing?: boolean;
|
||||||
present?: Boolean;
|
present?: boolean;
|
||||||
};
|
};
|
||||||
function useRole(id: number): [RawRoleState, () => void] {
|
function useRole(id: number): [RawRoleState, () => void] {
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import { useSaves } from "../model/saves";
|
|||||||
import { notifyErrorHandler } from "../util/notify";
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type ModalProps = {
|
type ModalProps = {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
save: lib.SaveDetails;
|
save: lib.SaveDetails;
|
||||||
@@ -150,7 +149,9 @@ function TransferModal(props: ModalProps) {
|
|||||||
<Select
|
<Select
|
||||||
autoFocus
|
autoFocus
|
||||||
showSearch
|
showSearch
|
||||||
filterOption={(input, option) => (option?.title.toLowerCase().indexOf(input.toLowerCase())??-1) >= 0}
|
filterOption={(input, option) => (
|
||||||
|
(option?.title.toLowerCase().indexOf(input.toLowerCase())??-1) >= 0
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{instanceList.filter(
|
{instanceList.filter(
|
||||||
instance => instance["id"] !== props.instanceId
|
instance => instance["id"] !== props.instanceId
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default function StartStopInstanceButton(props: StartStopInstanceButtonPr
|
|||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
let [switching, setSwitching] = useState<boolean>(false);
|
let [switching, setSwitching] = useState<boolean>(false);
|
||||||
|
|
||||||
const onClick: React.MouseEventHandler<HTMLElement> = function(event) {
|
function onClick(event: React.MouseEvent<HTMLElement>) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
setSwitching(true);
|
setSwitching(true);
|
||||||
let action;
|
let action;
|
||||||
@@ -48,7 +48,7 @@ export default function StartStopInstanceButton(props: StartStopInstanceButtonPr
|
|||||||
props.onFinish();
|
props.onFinish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
return <Button
|
return <Button
|
||||||
{...(props.buttonProps || {})}
|
{...(props.buttonProps || {})}
|
||||||
|
|||||||
@@ -96,7 +96,9 @@ export default function UsersPage() {
|
|||||||
{
|
{
|
||||||
title: "Roles",
|
title: "Roles",
|
||||||
key: "roles",
|
key: "roles",
|
||||||
render: (user: lib.RawUser) => user.roles.map(id => <Tag key={id}>{(roles.get(id) || { name: id }).name}</Tag>),
|
render: (user: lib.RawUser) => (
|
||||||
|
user.roles.map(id => <Tag key={id}>{(roles.get(id) || { name: id }).name}</Tag>)
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Online time",
|
title: "Online time",
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ export function useHost(id: number): [ HostState, () => void ] {
|
|||||||
|
|
||||||
function updateHost() {
|
function updateHost() {
|
||||||
// XXX optimize by requesting only the host in question
|
// XXX optimize by requesting only the host in question
|
||||||
control.send(new lib.HostListRequest())
|
control.send(
|
||||||
.then((hosts: lib.HostDetails[]) => {
|
new lib.HostListRequest()
|
||||||
|
).then((hosts: lib.HostDetails[]) => {
|
||||||
let match = hosts.find(i => i.id === id);
|
let match = hosts.find(i => i.id === id);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
setHost({ missing: true });
|
setHost({ missing: true });
|
||||||
@@ -35,7 +36,7 @@ export function useHost(id: number): [ HostState, () => void ] {
|
|||||||
updateHost();
|
updateHost();
|
||||||
|
|
||||||
function updateHandler(newHost: lib.HostDetails) {
|
function updateHandler(newHost: lib.HostDetails) {
|
||||||
setHost({ ...newHost, loading:false, missing:false, present:true });
|
setHost({ ...newHost, loading: false, missing: false, present: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
control.hostUpdate.subscribeToChannel(id, updateHandler);
|
control.hostUpdate.subscribeToChannel(id, updateHandler);
|
||||||
@@ -52,8 +53,9 @@ export function useHostList() {
|
|||||||
let [hostList, setHostList] = useState<lib.HostDetails[]>([]);
|
let [hostList, setHostList] = useState<lib.HostDetails[]>([]);
|
||||||
|
|
||||||
function updateHostList() {
|
function updateHostList() {
|
||||||
control.send(new lib.HostListRequest())
|
control.send(
|
||||||
.then((hosts: lib.HostDetails[]) => {
|
new lib.HostListRequest()
|
||||||
|
).then((hosts: lib.HostDetails[]) => {
|
||||||
setHostList(hosts);
|
setHostList(hosts);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ export function useItemMetadata() {
|
|||||||
let style = document.createElement("style");
|
let style = document.createElement("style");
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
for (let [name, meta] of itemMetadataCache) {
|
for (let [name, meta] of itemMetadataCache) {
|
||||||
style.sheet!.insertRule(
|
style.sheet!.insertRule(`\
|
||||||
`.item-${CSS.escape(name)} {
|
.item-${CSS.escape(name)} {
|
||||||
background-image: url("${window.staticRoot}static/${exportManifest.assets["item-spritesheet"]}");
|
background-image: url("${window.staticRoot}static/${exportManifest.assets["item-spritesheet"]}");
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: -${meta.x}px -${meta.y}px;
|
background-position: -${meta.x}px -${meta.y}px;
|
||||||
height: ${meta.size}px;
|
height: ${meta.size}px;
|
||||||
width: ${meta.size}px;
|
width: ${meta.size}px;
|
||||||
}`
|
}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
setItemMetadata(itemMetadataCache);
|
setItemMetadata(itemMetadataCache);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export function useSaves(instanceId?: number): lib.SaveDetails[] {
|
|||||||
let [saves, setSaves] = useState<lib.SaveDetails[]>([]);
|
let [saves, setSaves] = useState<lib.SaveDetails[]>([]);
|
||||||
|
|
||||||
function updateSaves() {
|
function updateSaves() {
|
||||||
control.sendTo({ instanceId:instanceId! }, new lib.InstanceListSavesRequest()).then(updatedSaves => {
|
control.sendTo({ instanceId: instanceId! }, new lib.InstanceListSavesRequest()).then(updatedSaves => {
|
||||||
setSaves(updatedSaves);
|
setSaves(updatedSaves);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
logger.error(`Failed to list instance saves: ${err}`);
|
logger.error(`Failed to list instance saves: ${err}`);
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ export function sortLastSeen(userA:RawUserState, userB:RawUserState, instanceIdA
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type RawUserState = Partial<lib.RawUser> & {
|
export type RawUserState = Partial<lib.RawUser> & {
|
||||||
loading?: Boolean;
|
loading?: boolean;
|
||||||
present?: Boolean;
|
present?: boolean;
|
||||||
missing?: Boolean;
|
missing?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useUser(name: string): [RawUserState, () => void] {
|
export function useUser(name: string): [RawUserState, () => void] {
|
||||||
|
|||||||
@@ -56,12 +56,29 @@ export class Control extends lib.Link {
|
|||||||
logHandlers: Map<lib.LogFilter, logHandler[]> = new Map();
|
logHandlers: Map<lib.LogFilter, logHandler[]> = new Map();
|
||||||
|
|
||||||
/** Updates handled by the subscription service */
|
/** Updates handled by the subscription service */
|
||||||
hostUpdate = new lib.EventSubscriber<lib.HostUpdateEvent, lib.HostDetails>(lib.HostUpdateEvent, event => event.update);
|
hostUpdate = new lib.EventSubscriber<lib.HostUpdateEvent, lib.HostDetails>(
|
||||||
instanceUpdate = new lib.EventSubscriber<lib.InstanceDetailsUpdateEvent, lib.InstanceDetails>(lib.InstanceDetailsUpdateEvent, event => event.details);
|
lib.HostUpdateEvent, event => event.update,
|
||||||
saveListUpdate = new lib.EventSubscriber<lib.InstanceSaveListUpdateEvent>(lib.InstanceSaveListUpdateEvent);
|
);
|
||||||
modPackUpdate = new lib.EventSubscriber<lib.ModPackUpdateEvent, lib.ModPack>(lib.ModPackUpdateEvent, event => event.modPack);
|
|
||||||
modUpdate = new lib.EventSubscriber<lib.ModUpdateEvent, lib.ModInfo>(lib.ModUpdateEvent, event => event.mod);
|
instanceUpdate = new lib.EventSubscriber<lib.InstanceDetailsUpdateEvent, lib.InstanceDetails>(
|
||||||
userUpdate = new lib.EventSubscriber<lib.UserUpdateEvent, lib.RawUser>(lib.UserUpdateEvent, event => event.user);
|
lib.InstanceDetailsUpdateEvent, event => event.details,
|
||||||
|
);
|
||||||
|
|
||||||
|
saveListUpdate = new lib.EventSubscriber<lib.InstanceSaveListUpdateEvent>(
|
||||||
|
lib.InstanceSaveListUpdateEvent,
|
||||||
|
);
|
||||||
|
|
||||||
|
modPackUpdate = new lib.EventSubscriber<lib.ModPackUpdateEvent, lib.ModPack>(
|
||||||
|
lib.ModPackUpdateEvent, event => event.modPack,
|
||||||
|
);
|
||||||
|
|
||||||
|
modUpdate = new lib.EventSubscriber<lib.ModUpdateEvent, lib.ModInfo>(
|
||||||
|
lib.ModUpdateEvent, event => event.mod,
|
||||||
|
);
|
||||||
|
|
||||||
|
userUpdate = new lib.EventSubscriber<lib.UserUpdateEvent, lib.RawUser>(
|
||||||
|
lib.UserUpdateEvent, event => event.user,
|
||||||
|
);
|
||||||
|
|
||||||
declare connector: ControlConnector;
|
declare connector: ControlConnector;
|
||||||
|
|
||||||
@@ -81,7 +98,7 @@ export class Control extends lib.Link {
|
|||||||
this.emitAccountUpdate();
|
this.emitAccountUpdate();
|
||||||
this.hostUpdate.connectControl(this).catch(err => logger.error(
|
this.hostUpdate.connectControl(this).catch(err => logger.error(
|
||||||
`Unexpected error updating host subscriptions:\n${err.stack}`
|
`Unexpected error updating host subscriptions:\n${err.stack}`
|
||||||
));;
|
));
|
||||||
this.instanceUpdate.connectControl(this).catch(err => logger.error(
|
this.instanceUpdate.connectControl(this).catch(err => logger.error(
|
||||||
`Unexpected error updating instance subscriptions:\n${err.stack}`
|
`Unexpected error updating instance subscriptions:\n${err.stack}`
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ const info: lib.PluginDeclaration = {
|
|||||||
messages: [
|
messages: [
|
||||||
ChatEvent,
|
ChatEvent,
|
||||||
],
|
],
|
||||||
}
|
};
|
||||||
|
|
||||||
export default info;
|
export default info;
|
||||||
@@ -60,6 +60,6 @@ const info: lib.PluginDeclaration = {
|
|||||||
],
|
],
|
||||||
webEntrypoint: "./web",
|
webEntrypoint: "./web",
|
||||||
routes: ["/inventory"],
|
routes: ["/inventory"],
|
||||||
}
|
};
|
||||||
|
|
||||||
export default info;
|
export default info;
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import { AcquireRequest, AcquireResponse, ReleaseRequest, UploadRequest, DownloadRequest, DownloadResponse } from "./messages";
|
import {
|
||||||
|
AcquireRequest, AcquireResponse, ReleaseRequest, UploadRequest, DownloadRequest, DownloadResponse,
|
||||||
|
} from "./messages";
|
||||||
|
|
||||||
type IpcPlayerName = {
|
type IpcPlayerName = {
|
||||||
player_name: string
|
player_name: string
|
||||||
}
|
}
|
||||||
export type IpcPlayerData = { //.\module\serialize.lua:serialize.serialize_player()
|
|
||||||
|
// .\module\serialize.lua:serialize.serialize_player()
|
||||||
|
export type IpcPlayerData = {
|
||||||
generation: number,
|
generation: number,
|
||||||
controller: string,
|
controller: string,
|
||||||
name: string,
|
name: string,
|
||||||
@@ -34,6 +38,7 @@ type IpcAcquireResponse = {
|
|||||||
* Splits string into array of strings with max of a certain length
|
* Splits string into array of strings with max of a certain length
|
||||||
* @param chunkSize - Max length of each chunk
|
* @param chunkSize - Max length of each chunk
|
||||||
* @param string - String to split into chunks
|
* @param string - String to split into chunks
|
||||||
|
* @returns array of substrings
|
||||||
*/
|
*/
|
||||||
function chunkify(chunkSize: number, string: string): string[] {
|
function chunkify(chunkSize: number, string: string): string[] {
|
||||||
return string.match(new RegExp(`.{1,${chunkSize}}`, "g")) || [];
|
return string.match(new RegExp(`.{1,${chunkSize}}`, "g")) || [];
|
||||||
@@ -48,14 +53,30 @@ export class InstancePlugin extends lib.BaseInstancePlugin {
|
|||||||
this.disconnecting = false;
|
this.disconnecting = false;
|
||||||
|
|
||||||
// Handle IPC from scenario script
|
// Handle IPC from scenario script
|
||||||
this.instance.server.on("ipc-inventory_sync_acquire", (request: IpcPlayerName) => this.handleAcquire(request)
|
this.instance.server.on(
|
||||||
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_acquire:\n${err.stack}`)));
|
"ipc-inventory_sync_acquire",
|
||||||
this.instance.server.on("ipc-inventory_sync_release", (request: IpcPlayerName) => this.handleRelease(request)
|
(request: IpcPlayerName) => this.handleAcquire(request).catch(
|
||||||
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_release:\n${err.stack}`)));
|
err => this.logger.error(`Error handling ipc-inventory_sync_acquire:\n${err.stack}`)
|
||||||
this.instance.server.on("ipc-inventory_sync_upload", (player_data: IpcPlayerData) => this.handleUpload(player_data)
|
),
|
||||||
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_upload:\n${err.stack}`)));
|
);
|
||||||
this.instance.server.on("ipc-inventory_sync_download", (request: IpcPlayerName) => this.handleDownload(request)
|
this.instance.server.on(
|
||||||
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_download:\n${err.stack}`)));
|
"ipc-inventory_sync_release",
|
||||||
|
(request: IpcPlayerName) => this.handleRelease(request).catch(
|
||||||
|
err => this.logger.error(`Error handling ipc-inventory_sync_release:\n${err.stack}`)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
this.instance.server.on(
|
||||||
|
"ipc-inventory_sync_upload",
|
||||||
|
(player_data: IpcPlayerData) => this.handleUpload(player_data).catch(
|
||||||
|
err => this.logger.error(`Error handling ipc-inventory_sync_upload:\n${err.stack}`)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
this.instance.server.on(
|
||||||
|
"ipc-inventory_sync_download",
|
||||||
|
(request: IpcPlayerName) => this.handleDownload(request).catch(
|
||||||
|
err => this.logger.error(`Error handling ipc-inventory_sync_download:\n${err.stack}`)
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPrepareControllerDisconnect() {
|
async onPrepareControllerDisconnect() {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { StringEnum } from "@clusterio/lib";
|
|||||||
const jsonPlayerData = Type.Object({
|
const jsonPlayerData = Type.Object({
|
||||||
generation: Type.Number(),
|
generation: Type.Number(),
|
||||||
name: Type.String(),
|
name: Type.String(),
|
||||||
})
|
});
|
||||||
|
|
||||||
export class AcquireResponse {
|
export class AcquireResponse {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -45,7 +45,7 @@ export class AcquireRequest {
|
|||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"instanceId": Type.Number(),
|
"instanceId": Type.Number(),
|
||||||
"playerName": Type.String(),
|
"playerName": Type.String(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof AcquireRequest.jsonSchema>): AcquireRequest {
|
static fromJSON(json: Static<typeof AcquireRequest.jsonSchema>): AcquireRequest {
|
||||||
return new this(json.instanceId, json.playerName);
|
return new this(json.instanceId, json.playerName);
|
||||||
@@ -68,7 +68,7 @@ export class ReleaseRequest {
|
|||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"instanceId": Type.Integer(),
|
"instanceId": Type.Integer(),
|
||||||
"playerName": Type.String(),
|
"playerName": Type.String(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof ReleaseRequest.jsonSchema>) {
|
static fromJSON(json: Static<typeof ReleaseRequest.jsonSchema>) {
|
||||||
return new this(json.instanceId, json.playerName);
|
return new this(json.instanceId, json.playerName);
|
||||||
@@ -108,7 +108,7 @@ export class DownloadResponse {
|
|||||||
|
|
||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"playerData": Type.Optional(jsonPlayerData),
|
"playerData": Type.Optional(jsonPlayerData),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof DownloadResponse.jsonSchema>): DownloadResponse {
|
static fromJSON(json: Static<typeof DownloadResponse.jsonSchema>): DownloadResponse {
|
||||||
return new this(json.playerData as IpcPlayerData);
|
return new this(json.playerData as IpcPlayerData);
|
||||||
@@ -132,7 +132,7 @@ export class DownloadRequest {
|
|||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"instanceId": Type.Integer(),
|
"instanceId": Type.Integer(),
|
||||||
"playerName": Type.String(),
|
"playerName": Type.String(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof DownloadRequest.jsonSchema>) {
|
static fromJSON(json: Static<typeof DownloadRequest.jsonSchema>) {
|
||||||
return new this(json.instanceId, json.playerName);
|
return new this(json.instanceId, json.playerName);
|
||||||
@@ -153,8 +153,8 @@ class DatabaseStatsResponse {
|
|||||||
"largestEntry": Type.Object({
|
"largestEntry": Type.Object({
|
||||||
"name": Type.String(),
|
"name": Type.String(),
|
||||||
"size": Type.Number(),
|
"size": Type.Number(),
|
||||||
})
|
}),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof DatabaseStatsResponse.jsonSchema>): DatabaseStatsResponse {
|
static fromJSON(json: Static<typeof DatabaseStatsResponse.jsonSchema>): DatabaseStatsResponse {
|
||||||
return new this(json.databaseSize, json.databaseEntries, json.largestEntry);
|
return new this(json.databaseSize, json.databaseEntries, json.largestEntry);
|
||||||
|
|||||||
@@ -56,13 +56,21 @@ export class ControllerPlugin extends lib.BaseControllerPlugin {
|
|||||||
res.send(servers);
|
res.send(servers);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.controller.app.post("/api/player_auth/player_code", express.json(), (req: Request, res: Response, next: any) => {
|
this.controller.app.post(
|
||||||
this.handlePlayerCode(req, res).catch(next);
|
"/api/player_auth/player_code",
|
||||||
});
|
express.json(),
|
||||||
|
(req: Request, res: Response, next: any) => {
|
||||||
|
this.handlePlayerCode(req, res).catch(next);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.controller.app.post("/api/player_auth/verify", express.json(), (req: Request, res: Response, next: any) => {
|
this.controller.app.post(
|
||||||
this.handleVerify(req, res).catch(next);
|
"/api/player_auth/verify",
|
||||||
});
|
express.json(),
|
||||||
|
(req: Request, res: Response, next: any) => {
|
||||||
|
this.handleVerify(req, res).catch(next);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.controller.handle(FetchPlayerCodeRequest, this.handleFetchPlayerCodeRequest.bind(this));
|
this.controller.handle(FetchPlayerCodeRequest, this.handleFetchPlayerCodeRequest.bind(this));
|
||||||
this.controller.handle(SetVerifyCodeRequest, this.handleSetVerifyCodeRequest.bind(this));
|
this.controller.handle(SetVerifyCodeRequest, this.handleSetVerifyCodeRequest.bind(this));
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
|
|
||||||
import { FetchPlayerCodeRequest, SetVerifyCodeRequest } from "./messages";
|
import { FetchPlayerCodeRequest, SetVerifyCodeRequest } from "./messages";
|
||||||
|
|
||||||
type ipcPlayerAuth = {
|
type IpcPlayerAuth = {
|
||||||
type: "open_dialog",
|
type: "open_dialog",
|
||||||
player: string,
|
player: string,
|
||||||
} | {
|
} | {
|
||||||
@@ -17,12 +17,15 @@ export class InstancePlugin extends lib.BaseInstancePlugin {
|
|||||||
throw new Error("player_auth plugin requires save patching.");
|
throw new Error("player_auth plugin requires save patching.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance.server.on("ipc-player_auth", (ipcPlayerAuth: ipcPlayerAuth) => this.handleEvent(ipcPlayerAuth).catch(
|
this.instance.server.on(
|
||||||
err => this.logger.error(`Error handling event:\n${err.stack}`)
|
"ipc-player_auth",
|
||||||
));
|
(ipcPlayerAuth: IpcPlayerAuth) => this.handleEvent(ipcPlayerAuth).catch(
|
||||||
|
err => this.logger.error(`Error handling event:\n${err.stack}`)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleEvent(event: ipcPlayerAuth) {
|
async handleEvent(event: IpcPlayerAuth) {
|
||||||
if (event.type === "open_dialog") {
|
if (event.type === "open_dialog") {
|
||||||
if (!this.host.connector.connected) {
|
if (!this.host.connector.connected) {
|
||||||
await this.sendRcon(`/web-login error ${event.player} login is temporarily unavailable`);
|
await this.sendRcon(`/web-login error ${event.player} login is temporarily unavailable`);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class FetchPlayerCodeResponse {
|
|||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"playerCode": Type.String(),
|
"playerCode": Type.String(),
|
||||||
"controllerUrl": Type.String(),
|
"controllerUrl": Type.String(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof FetchPlayerCodeResponse.jsonSchema>): FetchPlayerCodeResponse {
|
static fromJSON(json: Static<typeof FetchPlayerCodeResponse.jsonSchema>): FetchPlayerCodeResponse {
|
||||||
return new this(json.playerCode, json.controllerUrl);
|
return new this(json.playerCode, json.controllerUrl);
|
||||||
@@ -32,7 +32,7 @@ export class FetchPlayerCodeRequest {
|
|||||||
|
|
||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"player": Type.String(),
|
"player": Type.String(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof FetchPlayerCodeRequest.jsonSchema>): FetchPlayerCodeRequest {
|
static fromJSON(json: Static<typeof FetchPlayerCodeRequest.jsonSchema>): FetchPlayerCodeRequest {
|
||||||
return new this(json.player);
|
return new this(json.player);
|
||||||
@@ -55,7 +55,7 @@ export class SetVerifyCodeRequest {
|
|||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"player": Type.String(),
|
"player": Type.String(),
|
||||||
"verifyCode": Type.String(),
|
"verifyCode": Type.String(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof SetVerifyCodeRequest.jsonSchema>): SetVerifyCodeRequest {
|
static fromJSON(json: Static<typeof SetVerifyCodeRequest.jsonSchema>): SetVerifyCodeRequest {
|
||||||
return new this(json.player, json.verifyCode);
|
return new this(json.player, json.verifyCode);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class ContributionEvent {
|
|||||||
"name": Type.String(),
|
"name": Type.String(),
|
||||||
"level": Type.Integer(),
|
"level": Type.Integer(),
|
||||||
"contribution": Type.Number(),
|
"contribution": Type.Number(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof ContributionEvent.jsonSchema>): ContributionEvent {
|
static fromJSON(json: Static<typeof ContributionEvent.jsonSchema>): ContributionEvent {
|
||||||
return new this(json.name, json.level, json.contribution);
|
return new this(json.name, json.level, json.contribution);
|
||||||
@@ -39,7 +39,7 @@ export class TechnologyProgress {
|
|||||||
"name": Type.String(),
|
"name": Type.String(),
|
||||||
"level": Type.Integer(),
|
"level": Type.Integer(),
|
||||||
"progress": Type.Number(),
|
"progress": Type.Number(),
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ProgressEvent {
|
export class ProgressEvent {
|
||||||
@@ -57,8 +57,8 @@ export class ProgressEvent {
|
|||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"technologies": Type.Array(
|
"technologies": Type.Array(
|
||||||
TechnologyProgress.jsonSchema
|
TechnologyProgress.jsonSchema
|
||||||
)
|
),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof ProgressEvent.jsonSchema>): ProgressEvent {
|
static fromJSON(json: Static<typeof ProgressEvent.jsonSchema>): ProgressEvent {
|
||||||
return new this(json.technologies);
|
return new this(json.technologies);
|
||||||
@@ -81,7 +81,7 @@ export class FinishedEvent {
|
|||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"name": Type.String(),
|
"name": Type.String(),
|
||||||
"level": Type.Integer(),
|
"level": Type.Integer(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof FinishedEvent.jsonSchema>): FinishedEvent {
|
static fromJSON(json: Static<typeof FinishedEvent.jsonSchema>): FinishedEvent {
|
||||||
return new this(json.name, json.level);
|
return new this(json.name, json.level);
|
||||||
@@ -100,9 +100,10 @@ export class TechnologySync {
|
|||||||
static jsonSchema = Type.Tuple([
|
static jsonSchema = Type.Tuple([
|
||||||
Type.String(),
|
Type.String(),
|
||||||
Type.Integer(),
|
Type.Integer(),
|
||||||
Type.Union([ Type.Number(), Type.Null() ]),
|
Type.Union([Type.Number(), Type.Null()]),
|
||||||
Type.Boolean(),
|
Type.Boolean(),
|
||||||
])
|
]);
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return [this.name, this.level, this.progress, this.researched];
|
return [this.name, this.level, this.progress, this.researched];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,9 @@ export class ControllerPlugin extends lib.BaseControllerPlugin {
|
|||||||
// use fancy neural net to calculate a "fair" dole division rate.
|
// use fancy neural net to calculate a "fair" dole division rate.
|
||||||
if (method === "neural_dole") {
|
if (method === "neural_dole") {
|
||||||
for (let item of request.items) {
|
for (let item of request.items) {
|
||||||
let count = this.neuralDole.divider({ name: item.name, count: item.count, instanceId, instanceName });
|
let count = this.neuralDole.divider(
|
||||||
|
{ name: item.name, count: item.count, instanceId, instanceName }
|
||||||
|
);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
itemsRemoved.push(new Item(item.name, count));
|
itemsRemoved.push(new Item(item.name, count));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ export class NeuralDole {
|
|||||||
// If the server regularly can't fulfill requests, this number grows until
|
// If the server regularly can't fulfill requests, this number grows until
|
||||||
// it can. Then it slowly shrinks back down.
|
// it can. Then it slowly shrinks back down.
|
||||||
let _doleDivisionFactor: { [key:string]: number } = {};
|
let _doleDivisionFactor: { [key:string]: number } = {};
|
||||||
export function doleDivider({
|
export function doleDivider(
|
||||||
|
{
|
||||||
object,
|
object,
|
||||||
items,
|
items,
|
||||||
logItemTransfers,
|
logItemTransfers,
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ export class InstancePlugin extends lib.BaseInstancePlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fromIpcItems = items.map(item => new Item(item[0], item[1]))
|
|
||||||
|
const fromIpcItems = items.map(item => new Item(item[0], item[1]));
|
||||||
this.instance.sendTo("controller", new PlaceEvent(fromIpcItems));
|
this.instance.sendTo("controller", new PlaceEvent(fromIpcItems));
|
||||||
|
|
||||||
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
|
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
|
||||||
@@ -85,7 +86,7 @@ export class InstancePlugin extends lib.BaseInstancePlugin {
|
|||||||
// request items --------------------------------------------------------------
|
// request items --------------------------------------------------------------
|
||||||
async requestItems(requestItems: IpcItems) {
|
async requestItems(requestItems: IpcItems) {
|
||||||
// Request the items all at once
|
// Request the items all at once
|
||||||
let fromIpcItems = requestItems.map(item => new Item(item[0], item[1]))
|
let fromIpcItems = requestItems.map(item => new Item(item[0], item[1]));
|
||||||
let items = await this.instance.sendTo("controller", new RemoveRequest(fromIpcItems));
|
let items = await this.instance.sendTo("controller", new RemoveRequest(fromIpcItems));
|
||||||
|
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ export class PlaceEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"items": Type.Array(Item.jsonSchema)
|
"items": Type.Array(Item.jsonSchema),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof PlaceEvent.jsonSchema>): PlaceEvent {
|
static fromJSON(json: Static<typeof PlaceEvent.jsonSchema>): PlaceEvent {
|
||||||
return new this(json.items.map(item => Item.fromJSON(item)));
|
return new this(json.items.map(item => Item.fromJSON(item)));
|
||||||
@@ -58,8 +58,8 @@ export class RemoveRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"items": Type.Array(Item.jsonSchema)
|
"items": Type.Array(Item.jsonSchema),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof RemoveRequest.jsonSchema>): RemoveRequest {
|
static fromJSON(json: Static<typeof RemoveRequest.jsonSchema>): RemoveRequest {
|
||||||
return new this(json.items.map(item => Item.fromJSON(item)));
|
return new this(json.items.map(item => Item.fromJSON(item)));
|
||||||
@@ -91,8 +91,8 @@ export class UpdateStorageEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"items": Type.Array(Item.jsonSchema)
|
"items": Type.Array(Item.jsonSchema),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof UpdateStorageEvent.jsonSchema>): UpdateStorageEvent {
|
static fromJSON(json: Static<typeof UpdateStorageEvent.jsonSchema>): UpdateStorageEvent {
|
||||||
return new this(json.items.map(item => Item.fromJSON(item)));
|
return new this(json.items.map(item => Item.fromJSON(item)));
|
||||||
@@ -113,8 +113,8 @@ export class SetStorageSubscriptionRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
"storage": Type.Boolean()
|
"storage": Type.Boolean(),
|
||||||
})
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof SetStorageSubscriptionRequest.jsonSchema>): SetStorageSubscriptionRequest {
|
static fromJSON(json: Static<typeof SetStorageSubscriptionRequest.jsonSchema>): SetStorageSubscriptionRequest {
|
||||||
return new this(json.storage);
|
return new this(json.storage);
|
||||||
|
|||||||
Reference in new issue
Block a user