mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Fix research_sync sending commands before instance start
Fix commands syncing researces being sent before the instance is started up, and potential desync of research progress as a result of out of order execution of RCON commands sent.
This commit is contained in:
1 parent
2b101d594a
commit
034ca4c250
1 file changed
+13
-4
@@ -19,6 +19,8 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
this.instance.server.on("ipc-research_sync:finished", (tech) => {
|
this.instance.server.on("ipc-research_sync:finished", (tech) => {
|
||||||
this.researchFinished(tech).catch(err => this.unexpectedError(err));
|
this.researchFinished(tech).catch(err => this.unexpectedError(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.syncStarted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async researchContribution(tech) {
|
async researchContribution(tech) {
|
||||||
@@ -26,8 +28,11 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async progressEventHandler(message) {
|
async progressEventHandler(message) {
|
||||||
|
if (!this.syncStarted || !["starting", "running"].includes(this.instance.status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let techsJson = libLuaTools.escapeString(JSON.stringify(message.data.technologies));
|
let techsJson = libLuaTools.escapeString(JSON.stringify(message.data.technologies));
|
||||||
await this.sendRcon(`/sc research_sync.update_progress("${techsJson}")`, true);
|
await this.sendOrderedRcon(`/sc research_sync.update_progress("${techsJson}")`, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async researchFinished(tech) {
|
async researchFinished(tech) {
|
||||||
@@ -35,14 +40,17 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async finishedEventHandler(message) {
|
async finishedEventHandler(message) {
|
||||||
|
if (!this.syncStarted || !["starting", "running"].includes(this.instance.status)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let { name, level, researched } = message.data;
|
let { name, level, researched } = message.data;
|
||||||
await this.sendRcon(
|
await this.sendOrderedRcon(
|
||||||
`/sc research_sync.research_technology("${libLuaTools.escapeString(name)}", ${level})`, true
|
`/sc research_sync.research_technology("${libLuaTools.escapeString(name)}", ${level})`, true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onStart() {
|
async onStart() {
|
||||||
let dumpJson = await this.sendRcon("/sc research_sync.dump_technologies()");
|
let dumpJson = await this.sendOrderedRcon("/sc research_sync.dump_technologies()");
|
||||||
let techsToSend = [];
|
let techsToSend = [];
|
||||||
let instanceTechs = new Map();
|
let instanceTechs = new Map();
|
||||||
for (let tech of JSON.parse(dumpJson)) {
|
for (let tech of JSON.parse(dumpJson)) {
|
||||||
@@ -56,6 +64,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let response = await this.info.messages.syncTechnologies.send(this.instance, { technologies: techsToSend });
|
let response = await this.info.messages.syncTechnologies.send(this.instance, { technologies: techsToSend });
|
||||||
|
this.syncStarted = true;
|
||||||
let techsToSync = [];
|
let techsToSync = [];
|
||||||
for (let masterTech of response.technologies) {
|
for (let masterTech of response.technologies) {
|
||||||
let [name, level, progress, researched] = masterTech;
|
let [name, level, progress, researched] = masterTech;
|
||||||
@@ -72,7 +81,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
|||||||
|
|
||||||
if (techsToSync.length) {
|
if (techsToSync.length) {
|
||||||
let syncJson = libLuaTools.escapeString(JSON.stringify(techsToSync));
|
let syncJson = libLuaTools.escapeString(JSON.stringify(techsToSync));
|
||||||
await this.sendRcon(`/sc research_sync.sync_technologies("${syncJson}")`, true);
|
await this.sendOrderedRcon(`/sc research_sync.sync_technologies("${syncJson}")`, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user