mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +09:00
Forward Factorio logs to clusterctl
Add instance output event that is forwarded by the master server to control connections that are subscribing to them. Add code subscribing to the relevant instance output when dealing with instances in clusterctl.
This commit is contained in:
1 parent
f2c3006046
commit
1dea5fddbe
4 files changed
+139
-12
No files matched your search
@@ -109,11 +109,6 @@ class Instance {
|
||||
async createSave() {
|
||||
console.log("Creating save .....");
|
||||
|
||||
// XXX Move to constructor and send to master
|
||||
this.server.on('output', function(output) {
|
||||
console.log("Fact: " + output.message);
|
||||
});
|
||||
|
||||
await this.server.create("world");
|
||||
console.log("Clusterio | Successfully created save");
|
||||
}
|
||||
@@ -188,10 +183,6 @@ class Instance {
|
||||
}
|
||||
await factorio.patch(this.path("saves", latestSave), modules);
|
||||
|
||||
this.server.on('output', (output) => {
|
||||
console.log("Fact: " + output.message);
|
||||
});
|
||||
|
||||
this.server.on('rcon-ready', () => {
|
||||
console.log("Clusterio | RCON connection established");
|
||||
// Temporary measure for backwards compatibility
|
||||
@@ -317,6 +308,7 @@ class Slave extends link.Client {
|
||||
// XXX: race condition on multiple simultanious calls
|
||||
let instance = await Instance.create(id, instanceDir, this.config.factorioDir, options);
|
||||
this.instances.set(id, instance);
|
||||
this.hookInstance(instance);
|
||||
this.updateInstances();
|
||||
}
|
||||
|
||||
@@ -376,6 +368,7 @@ class Slave extends link.Client {
|
||||
console.log(`found instance ${instanceConfig.name} in ${instancePath}`);
|
||||
let instance = new Instance(instancePath, this.config.factorioDir, instanceConfig);
|
||||
await instance.init();
|
||||
this.hookInstance(instance); // XXX this is the wrong place for this
|
||||
instances.set(instanceConfig.id, instance);
|
||||
}
|
||||
}
|
||||
@@ -383,6 +376,13 @@ class Slave extends link.Client {
|
||||
return instances;
|
||||
}
|
||||
|
||||
hookInstance(instance) {
|
||||
instance.server.on('output', (output) => {
|
||||
link.events.instanceOutput.send(this, { instance_id: instance.config.id, output })
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
updateInstances() {
|
||||
let list = [];
|
||||
for (let instance of this.instances.values()) {
|
||||
|
||||
Reference in new issue
Block a user