Added factorio.enable_script_commands

This commit is contained in:
Cooldude2606 authored and Daniel committed 2024-11-21 08:46:22 -08:00
1 parent feb09a6fe0
commit 762212747e
7 files changed
+46

No files matched your search

+16
View File
@@ -14,6 +14,12 @@ import { exportData } from "./export";
import type Host from "./Host";
import BaseInstancePlugin from "./BaseInstancePlugin";
const scriptCommands = [
"/cheat", "/editor",
"/command", "/c",
"/measured-command", "/mc",
"/silent-command", "/sc"
];
const instanceRconCommandDuration = new lib.Histogram(
"clusterio_instance_rcon_command_duration_seconds",
@@ -371,6 +377,16 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " ");
}
async sendRcon(message: string, expectEmpty = false, plugin = "") {
if (
!this.config.get("factorio.enable_script_commands")
&& scriptCommands.find(cmd => message.startsWith(cmd))
) {
throw new Error(
"Attempted to use script command while disabled. See config factorio.enable_script_commands.\n" +
`Command: ${message}`
);
}
let instanceId = String(this.id);
let observeDuration = instanceRconCommandDuration.labels(instanceId).startTimer();
try {
+10
View File
@@ -319,6 +319,7 @@ export interface InstanceConfigFields {
"factorio.player_online_autosave_slots": number;
"factorio.mod_pack_id": number | null;
"factorio.enable_save_patching": boolean;
"factorio.enable_script_commands": boolean;
"factorio.enable_whitelist": boolean;
"factorio.enable_authserver_bans": boolean;
"factorio.settings": Record<string, unknown>;
@@ -427,6 +428,15 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
type: "boolean",
initialValue: true,
},
"factorio.enable_script_commands": {
description:
"Allows achievement breaking commands to be executed over rcon. " +
"Required for Clusterio integrations and most plugins. " +
"This does not prevent players using script commands.",
restartRequired: true,
type: "boolean",
initialValue: true,
},
"factorio.enable_whitelist": {
description: "Turn on whitelist for joining the server.",
type: "boolean",
+4
View File
@@ -16,6 +16,10 @@ export class InstancePlugin extends BaseInstancePlugin {
messageQueue: string[] = [];
async init() {
if (!this.instance.config.get("factorio.enable_script_commands")) {
throw new Error("global_chat plugin requires script commands.");
}
this.instance.handle(ChatEvent, this.handleChatEvent.bind(this));
}
+6
View File
@@ -31,6 +31,12 @@ export class InstancePlugin extends BaseInstancePlugin {
disconnecting!: boolean;
async init() {
if (!this.instance.config.get("factorio.enable_save_patching")) {
throw new Error("inventory_sync plugin requires save patching.");
}
if (!this.instance.config.get("factorio.enable_script_commands")) {
throw new Error("inventory_sync plugin requires script commands.");
}
this.playersToRelease = new Set();
this.disconnecting = false;
+3
View File
@@ -30,6 +30,9 @@ export class InstancePlugin extends BaseInstancePlugin {
if (!this.instance.config.get("factorio.enable_save_patching")) {
throw new Error("research_sync plugin requires save patching.");
}
if (!this.instance.config.get("factorio.enable_script_commands")) {
throw new Error("research_sync plugin requires script commands.");
}
this.instance.server.on("ipc-research_sync:contribution", (tech: IpcContribution) => {
this.researchContribution(tech).catch(err => this.unexpectedError(err));
+3
View File
@@ -66,6 +66,9 @@ export class InstancePlugin extends BaseInstancePlugin {
if (!this.instance.config.get("factorio.enable_save_patching")) {
throw new Error("statistics_exporter plugin requires save patching.");
}
if (!this.instance.config.get("factorio.enable_script_commands")) {
throw new Error("statistics_exporter plugin requires script commands.");
}
}
async gatherMetrics() {
+4
View File
@@ -20,6 +20,10 @@ export class InstancePlugin extends BaseInstancePlugin {
}
async init() {
if (!this.instance.config.get("factorio.enable_script_commands")) {
throw new Error("subspace_storage plugin requires script commands.");
}
this.pendingTasks = new Set();
this.instance.server.on("ipc-subspace_storage:output", (output: IpcItems) => {
this.provideItems(output).catch(err => this.unexpectedError(err));