Merge pull request #996 from bbassie/feature/instance-udp

Add UDP communication support for instances
This commit is contained in:
Cooldude2606 authored and GitHub committed 2026-10-17 20:47:54 +01:00
commit ba800e853d
19 files changed
+708 -25

No files matched your search

+21 -1
View File
@@ -233,6 +233,8 @@ export default class Instance extends lib.Link {
gamePort: this.config.get("factorio.game_port") ?? host.assignGamePort(this.id),
rconPort: this.config.get("factorio.rcon_port") ?? undefined,
rconPassword: this.config.get("factorio.rcon_password") ?? undefined,
enableLuaUdp: this.config.get("factorio.enable_lua_udp"),
luaUdpPort: this.config.get("factorio.lua_udp_port") ?? undefined,
enableWhitelist: this.config.get("factorio.enable_whitelist"),
enableAuthserverBans: this.config.get("factorio.enable_authserver_bans"),
verboseLogging: this.config.get("factorio.verbose_logging"),
@@ -506,6 +508,23 @@ end`.replace(/\r?\n/g, " ");
}
}
/**
* Send UDP message to the Factorio server
*
* Delivered in-game as an on_udp_packet_received event. Requires
* factorio.enable_lua_udp to be enabled on the instance.
*
* @param message - payload of the packet to send.
*/
async sendUdp(message: string | Buffer) {
if (!this.config.get("factorio.enable_lua_udp")) {
throw new Error(
"Attempted to send UDP message while Lua UDP is disabled. See config factorio.enable_lua_udp."
);
}
await this.server.sendUdp(message);
}
static async listSaves(instanceId: number, savesDir: string, loadedSave: string | null) {
let defaultSave = null;
if (loadedSave === null) {
@@ -1090,7 +1109,8 @@ end`.replace(/\r?\n/g, " ");
*/
async updateInstanceData() {
let name = lib.escapeString(this.name);
await this.sendRcon(`/sc clusterio_private.update_instance(${this.id}, "${name}")`, true);
let hostUdpPort = this.server.hostUdpPort ?? "nil";
await this.sendRcon(`/sc clusterio_private.update_instance(${this.id}, "${name}", ${hostUdpPort})`, true);
}
async updateFactorioSettings(current: Record<string, unknown>, previous: Record<string, unknown>) {