mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Fix updating config breaking instance status
Fix broken assign instance code in slave sending of the wrong instance status to the master server.
This commit is contained in:
1 parent
fc8edeba5f
commit
a92ae95ab1
2 files changed
+29
-6
No files matched your search
+25
-6
@@ -139,6 +139,7 @@ class Instance extends libLink.Link{
|
|||||||
stripPaths: this.config.get("factorio.strip_paths"),
|
stripPaths: this.config.get("factorio.strip_paths"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._status = "stopped";
|
||||||
this._running = false;
|
this._running = false;
|
||||||
this.server = new libFactorio.FactorioServer(
|
this.server = new libFactorio.FactorioServer(
|
||||||
factorioDir, this._dir, serverOptions
|
factorioDir, this._dir, serverOptions
|
||||||
@@ -181,11 +182,23 @@ class Instance extends libLink.Link{
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifyStatus(status) {
|
notifyStatus(status) {
|
||||||
|
this._status = status;
|
||||||
libLink.messages.instanceStatusChanged.send(this, {
|
libLink.messages.instanceStatusChanged.send(this, {
|
||||||
instance_id: this.config.get("instance.id"), status,
|
instance_id: this.config.get("instance.id"), status,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current state of the instance
|
||||||
|
*
|
||||||
|
* One of stopped, starting, running, creating_save and exporting_data
|
||||||
|
*
|
||||||
|
* @returns {string} instance status.
|
||||||
|
*/
|
||||||
|
get status() {
|
||||||
|
return this._status;
|
||||||
|
}
|
||||||
|
|
||||||
notifyExit() {
|
notifyExit() {
|
||||||
this._running = false;
|
this._running = false;
|
||||||
this.notifyStatus("stopped");
|
this.notifyStatus("stopped");
|
||||||
@@ -220,6 +233,7 @@ class Instance extends libLink.Link{
|
|||||||
}
|
}
|
||||||
|
|
||||||
async init(pluginInfos) {
|
async init(pluginInfos) {
|
||||||
|
this.notifyStatus("starting");
|
||||||
await this.server.init();
|
await this.server.init();
|
||||||
|
|
||||||
// load plugins
|
// load plugins
|
||||||
@@ -1088,7 +1102,6 @@ class Slave extends libLink.Link {
|
|||||||
if (instanceInfo) {
|
if (instanceInfo) {
|
||||||
instanceInfo.config.update(serialized_config, true);
|
instanceInfo.config.update(serialized_config, true);
|
||||||
console.log(`Clusterio | Updated config for ${instanceInfo.path}`);
|
console.log(`Clusterio | Updated config for ${instanceInfo.path}`);
|
||||||
// TODO: Notify of update if instance is running
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let instanceConfig = new libConfig.InstanceConfig();
|
let instanceConfig = new libConfig.InstanceConfig();
|
||||||
@@ -1104,8 +1117,17 @@ class Slave extends libLink.Link {
|
|||||||
};
|
};
|
||||||
this.instanceInfos.set(instance_id, instanceInfo);
|
this.instanceInfos.set(instance_id, instanceInfo);
|
||||||
console.log(`Clusterio | assigned instance ${instanceConfig.get("instance.name")}`);
|
console.log(`Clusterio | assigned instance ${instanceConfig.get("instance.name")}`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Somewhat hacky, but in the event of a lost session the status is
|
||||||
|
// resent on assigment since the master server sends an assigment
|
||||||
|
// request for all the instances it knows should be on this slave.
|
||||||
|
let instanceConnection = this.instanceConnections.get(instance_id);
|
||||||
|
libLink.messages.instanceStatusChanged.send(this, {
|
||||||
|
instance_id,
|
||||||
|
status: instanceConnection ? instanceConnection.status : "stopped",
|
||||||
|
});
|
||||||
|
|
||||||
// save a copy of the instance config
|
// save a copy of the instance config
|
||||||
let warnedOutput = {
|
let warnedOutput = {
|
||||||
@@ -1116,9 +1138,6 @@ class Slave extends libLink.Link {
|
|||||||
path.join(instanceInfo.path, "instance.json"),
|
path.join(instanceInfo.path, "instance.json"),
|
||||||
JSON.stringify(warnedOutput, null, 4)
|
JSON.stringify(warnedOutput, null, 4)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Notify master the instance is no longer usassigned
|
|
||||||
libLink.messages.instanceStatusChanged.send(this, { instance_id, status: "stopped" });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1142,10 +1161,10 @@ class Slave extends libLink.Link {
|
|||||||
let instance = new Instance(
|
let instance = new Instance(
|
||||||
this, connectionClient, instanceInfo.path, this.config.get("slave.factorio_directory"), instanceInfo.config
|
this, connectionClient, instanceInfo.path, this.config.get("slave.factorio_directory"), instanceInfo.config
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.instanceConnections.set(instanceId, instanceConnection);
|
||||||
await instance.init(this.pluginInfos);
|
await instance.init(this.pluginInfos);
|
||||||
|
|
||||||
// XXX: race condition on multiple simultanious calls
|
|
||||||
this.instanceConnections.set(instanceId, instanceConnection);
|
|
||||||
return instanceConnection;
|
return instanceConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,6 +185,10 @@ describe("Integration of Clusterio", function() {
|
|||||||
assert.equal(await sendRcon(44, `/config get ${configName}`), `${expectedResult}\n`);
|
assert.equal(await sendRcon(44, `/config get ${configName}`), `${expectedResult}\n`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
it("should not change the instance status", async function() {
|
||||||
|
slowTest(this);
|
||||||
|
await checkInstanceStatus(44, "running");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("user set-admin/whitelisted/banned", function() {
|
describe("user set-admin/whitelisted/banned", function() {
|
||||||
|
|||||||
Reference in new issue
Block a user