@clusterio/host
Version:
Implementation of Clusterio host server
200 lines • 8.24 kB
TypeScript
import * as lib from "@clusterio/lib";
import { FactorioServer } from "./server";
import type Host from "./Host";
import BaseInstancePlugin from "./BaseInstancePlugin";
/**
* Keeps track of the runtime parameters of an instance
* @alias module:host/src/Instance
*/
export default class Instance extends lib.Link {
/**
* ID of this instance, equivalenet to `instance.config.get("instance.id")`.
*/
readonly id: number;
plugins: Map<string, BaseInstancePlugin>;
config: lib.InstanceConfig;
logger: lib.Logger;
server: FactorioServer;
/**
* Mod pack currently running on this instance
*/
activeModPack: lib.ModPack;
/**
* Per player statistics recorded by this instance.
*/
playerStats: Map<string, lib.PlayerStats>;
/**
* Players currently online on the instance.
*/
playersOnline: Set<string>;
_host: Host;
_dir: string;
_configFieldChanged: (field: string, curr: unknown, prev: unknown) => void;
_status: "stopped" | "starting" | "running" | "stopping" | "creating_save" | "exporting_data";
_loadedSave: string | null;
_playerCheckInterval: ReturnType<typeof setInterval> | undefined;
_hadPlayersOnline: boolean;
_playerAutosaveSlot: number;
_expectedUserUpdates: {
action: string;
name: string;
reason: string;
}[];
constructor(host: Host, connector: lib.VirtualConnector, dir: string, factorioDir: string, instanceConfig: lib.InstanceConfig);
_watchServerLogActions(): void;
_watchPlayerPromote(): void;
_checkOnlinePlayers(): Promise<void>;
_recordPlayerJoin(name: string): void;
_recordPlayerLeave(name: string, reason: string): void;
handleInstanceExtractPlayersRequest(): Promise<void>;
sendRcon(message: string, expectEmpty?: boolean, plugin?: string): Promise<string>;
static listSaves(instanceId: number, savesDir: string, loadedSave: string | null): Promise<lib.SaveDetails[]>;
sendSaveListUpdate(): Promise<void>;
_autosave(name: string): Promise<void>;
notifyStatus(status: Instance["_status"]): void;
/**
* Current state of the instance
*
* One of stopped, starting, running, stopping, creating_save and exporting_data
*/
get status(): "running" | "stopping" | "stopped" | "starting" | "creating_save" | "exporting_data";
notifyExit(): void;
_loadPlugin(pluginInfo: lib.PluginNodeEnvInfo, host: Host): Promise<void>;
_loadStats(): Promise<void>;
_saveStats(): Promise<void>;
init(pluginInfos: lib.PluginNodeEnvInfo[]): Promise<void>;
/**
* Resolve the effective Factorio server settings
*
* Use the example settings as the basis and override it with all the
* entries from the given settings object.
*
* @param overrides - Server settings to override.
* @param includeCredentials - Include Factorio username and token from host/controller config.
* @returns
* server example settings with the given settings applied over it.
*/
resolveServerSettings(overrides: Record<string, unknown>, includeCredentials: boolean): Promise<any>;
/**
* Write the server-settings.json file
*
* Generate the server-settings.json file from the example file in the
* data directory and override any settings configured in the instance's
* factorio_settings config entry.
*
* @param includeCredentials - Include Factorio username and token from host/controller config.
*/
writeServerSettings(includeCredentials: boolean): Promise<void>;
/**
* Creates a new empty instance directory
*
* Ensures the neccessary files for starting up a new instance into the
* provided instance directory are present.
*
* @param instanceDir -
*/
static populate_folders(instanceDir: string): Promise<void>;
/**
* Sync instance mods directory with configured mod pack
*
* Adds, deletes, and updates all files in the instance mods folder to
* match up with the mod pack that's configured. If no mod pack is
* configured then an empty mod pack is used, esentially turning it into
* a vanilla mods folder. If the instance mods directory does't exist
* then it will be created.
*
* On Linux this creates symlinks to mods in the host's mods folder, on
* Windows hard links are used instead due to symlinks being privileged.
*/
syncMods(): Promise<void>;
/**
* Prepare instance for starting
*
* Writes server settings, admin/ban/white-lists and links mods.
*/
prepare(): Promise<void>;
/**
* Prepare a save for starting
*
* Creates a new save if no save is passed and patches it with modules.
*
* @param saveName -
* Save to prepare from the instance saves directory. Creates a new
* save if null.
* @returns Name of the save prepared.
*/
prepareSave(saveName?: string): Promise<string>;
/**
* Start Factorio server
*
* Launches the Factorio server for this instance with the given save.
*
* @param saveName - Name of save game to load.
*/
start(saveName: string): Promise<void>;
/**
* Start Factorio server by loading a scenario
*
* Launches the Factorio server for this instance with the given
* scenario.
*
* @param scenario - Name of scenario to load.
* @param seed - seed to use.
* @param mapGenSettings - MapGenSettings to use.
* @param mapSettings - MapSettings to use.
*/
startScenario(scenario: string, seed?: number, mapGenSettings?: object, mapSettings?: object): Promise<void>;
/**
* Update instance information on the Factorio side
*/
updateInstanceData(): Promise<void>;
updateFactorioSettings(current: Record<string, unknown>, previous: Record<string, unknown>): Promise<void>;
/**
* Enable or disable the player whitelist
*
* @param enable -
* True to enable the whitelist, False to disable the whitelist.
*/
updateFactorioWhitelist(enable: boolean): Promise<void>;
_recordUserUpdate(action: "BAN" | "UNBANNED" | "PROMOTE" | "DEMOTE" | "WHITELISTED" | "UNWHITELISTED", name: string, reason?: string): void;
handleInstanceAdminlistUpdateEvent(request: lib.InstanceAdminlistUpdateEvent): Promise<void>;
handleInstanceBanlistUpdateEvent(request: lib.InstanceBanlistUpdateEvent): Promise<void>;
handleInstanceWhitelistUpdateEvent(request: lib.InstanceWhitelistUpdateEvent): Promise<void>;
/**
* Stop the instance
*/
stop(): Promise<void>;
kill(): Promise<void>;
handleControllerConnectionEvent(event: lib.ControllerConnectionEvent): Promise<void>;
handlePrepareControllerDisconnectRequest(): Promise<void>;
handleInstanceMetricsRequest(): Promise<{
results: lib.CollectorResultSerialized[];
}>;
handleInstanceStartRequest(request: lib.InstanceStartRequest): Promise<void>;
handleInstanceLoadScenarioRequest(request: lib.InstanceLoadScenarioRequest): Promise<void>;
handleInstanceSaveDetailsListRequest(): Promise<lib.SaveDetails[]>;
handleInstanceCreateSaveRequest(request: lib.InstanceCreateSaveRequest): Promise<void>;
handleInstanceExportDataRequest(): Promise<void>;
handleInstanceRestartRequest(request: lib.InstanceRestartRequest): Promise<void>;
handleInstanceStopRequest(): Promise<void>;
handleInstanceKillRequest(): Promise<void>;
handleInstanceSendRconRequest(request: lib.InstanceSendRconRequest): Promise<string>;
/**
* Name of the instance
*
* This should not be used for filesystem paths. See .path() for that.
*/
get name(): string;
/**
* Return path in instance
*
* Creates a path using path.join with the given parts that's relative to
* the directory of the instance. For example instance.path("mods")
* returns a path to the mods directory of the instance. If no parts are
* given it returns a path to the directory of the instance.
*
* @returns path in instance directory.
*/
path(...parts: string[]): string;
}
//# sourceMappingURL=Instance.d.ts.map