mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Merge branch 'master' of https://github.com/veladon/factorioClusterio
This commit is contained in:
commit
fea9fb28ca
4 files changed
+69
-29
No files matched your search
@@ -235,7 +235,7 @@ const db = {};
|
|||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
try{
|
try{
|
||||||
let x = fs.statSync(path.resolve(config.databaseDirectory, "/slaves.json"));
|
let x = fs.statSync(path.resolve(config.databaseDirectory, "slaves.json"));
|
||||||
console.log(`loading slaves from path.resolve(config.databaseDirectory, "slaves.json")`);
|
console.log(`loading slaves from path.resolve(config.databaseDirectory, "slaves.json")`);
|
||||||
slaves = JSON.parse(fs.readFileSync(path.resolve(config.databaseDirectory, "slaves.json")));
|
slaves = JSON.parse(fs.readFileSync(path.resolve(config.databaseDirectory, "slaves.json")));
|
||||||
} catch (e){
|
} catch (e){
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
local data = {};
|
local data = {};
|
||||||
|
|
||||||
for _, tech in pairs(game.forces["player"].technologies) do
|
for _, tech in pairs(game.forces["player"].technologies) do
|
||||||
table.insert(data, tech.name .. ":" .. tostring(tech.researched) .. ":" .. tostring(tech.level));
|
if tech.enabled == true and tech.prototype.max_level == 4294967295 then
|
||||||
|
table.insert(data, tech.name .. ":" .. tostring(tech.researched) .. ":" .. tostring(tech.level) .. ":true");
|
||||||
|
else
|
||||||
|
table.insert(data, tech.name .. ":" .. tostring(tech.researched) .. ":" .. tostring(tech.level) .. ":false");
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
game.write_file("researchSync.txt", table.concat(data, "\n"), false, 0)
|
game.write_file("researchSync.txt", table.concat(data, "\n"), false, 0)
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
/silent-command
|
/silent-command
|
||||||
if game.forces['player'].technologies['{tech_name}'] then
|
if game.forces['player'].technologies['{tech_name}'] then
|
||||||
if game.forces['player'].technologies['{tech_name}'].researched ~= {tech_researched} then
|
if 1 == {tech_infinite} then
|
||||||
game.forces['player'].technologies['{tech_name}'].researched = {tech_researched}
|
|
||||||
end
|
|
||||||
if game.forces['player'].technologies['{tech_name}'].level ~= {tech_level} then
|
|
||||||
game.forces['player'].technologies['{tech_name}'].level = {tech_level}
|
game.forces['player'].technologies['{tech_name}'].level = {tech_level}
|
||||||
|
else
|
||||||
|
game.forces['player'].technologies['{tech_name}'].researched = true
|
||||||
end
|
end
|
||||||
script.raise_event(defines.events.on_research_finished, {research=game.forces['player'].technologies['{tech_name}'], by_script=true})
|
script.raise_event(defines.events.on_research_finished, {research=game.forces['player'].technologies['{tech_name}'], by_script=true})
|
||||||
game.play_sound({path="utility/research_completed"})
|
if {notify} then
|
||||||
if game.forces['player'].technologies['{tech_name}'].researched == false then
|
if 1 == {tech_infinite} then
|
||||||
game.print("Technology {tech_name} synced at level {tech_level}")
|
game.print("Infinite technology {tech_name} level {tech_level} unlocked")
|
||||||
else
|
else
|
||||||
game.print("Technology {tech_name} synced")
|
game.print("Technology {tech_name} researched")
|
||||||
|
end
|
||||||
|
game.play_sound({path="utility/research_completed"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const needle = require("needle");
|
const needle = require("needle");
|
||||||
|
|
||||||
|
|
||||||
class ResearchSync {
|
class ResearchSync {
|
||||||
constructor(slaveConfig, messageInterface, extras = {}) {
|
constructor(slaveConfig, messageInterface, extras = {}) {
|
||||||
this.config = slaveConfig;
|
this.config = slaveConfig;
|
||||||
@@ -10,10 +9,13 @@ class ResearchSync {
|
|||||||
|
|
||||||
this.research = {};
|
this.research = {};
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(
|
||||||
|
() => {
|
||||||
this.pollResearch();
|
this.pollResearch();
|
||||||
setTimeout(this.doSync.bind(this), 2000);
|
setTimeout(this.doSync.bind(this), 5000);
|
||||||
}, extras.researchSyncPollInterval || 5000);
|
},
|
||||||
|
extras.researchSyncPollInterval || 30000
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pollResearch() {
|
pollResearch() {
|
||||||
@@ -38,25 +40,39 @@ class ResearchSync {
|
|||||||
if (slaveData[instanceKey].unique === this.config.unique.toString()) {
|
if (slaveData[instanceKey].unique === this.config.unique.toString()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!slaveData[instanceKey].hasOwnProperty('meta') || !slaveData[instanceKey].meta.hasOwnProperty('research')) {
|
if (!slaveData[instanceKey].hasOwnProperty('meta')
|
||||||
|
|| !slaveData[instanceKey].meta.hasOwnProperty('research')
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let researchList = slaveData[instanceKey].meta.research;
|
let researchList = slaveData[instanceKey].meta.research;
|
||||||
if (researchList) {
|
if (researchList) {
|
||||||
Object.keys(researchList).forEach(researchName => {
|
Object.keys(researchList).forEach(researchName => {
|
||||||
if (isNaN(researchList[researchName].researched) || isNaN(researchList[researchName].level)) {
|
if (
|
||||||
|
isNaN(researchList[researchName].researched)
|
||||||
|
|| isNaN(researchList[researchName].level)
|
||||||
|
|| isNaN(researchList[researchName].infinite))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (needResearch.hasOwnProperty(researchName)) {
|
if (needResearch.hasOwnProperty(researchName)) {
|
||||||
if (needResearch[researchName].researched === 0) {
|
if (
|
||||||
needResearch[researchName].researched = parseInt(researchList[researchName].researched);
|
needResearch[researchName].infinite === 1
|
||||||
}
|
&& needResearch[researchName].level < parseInt(researchList[researchName].level)
|
||||||
if (needResearch[researchName].level < parseInt(researchList[researchName].level)) {
|
) {
|
||||||
needResearch[researchName].level = parseInt(researchList[researchName].level);
|
needResearch[researchName].level = parseInt(researchList[researchName].level);
|
||||||
|
} else if (
|
||||||
|
needResearch[researchName].researched === 0
|
||||||
|
&& parseInt(researchList[researchName].researched) === 1
|
||||||
|
) {
|
||||||
|
needResearch[researchName].researched = 1
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
needResearch[researchName] = {
|
||||||
needResearch[researchName] = {researched: parseInt(researchList[researchName].researched), level: parseInt(researchList[researchName].level)};
|
researched: parseInt(researchList[researchName].researched),
|
||||||
|
level : parseInt(researchList[researchName].level),
|
||||||
|
infinite : parseInt(researchList[researchName].infinite)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -64,6 +80,8 @@ class ResearchSync {
|
|||||||
|
|
||||||
let difference = this.filterResearchDiff(this.research, needResearch);
|
let difference = this.filterResearchDiff(this.research, needResearch);
|
||||||
|
|
||||||
|
let count = Object.keys(difference).length;
|
||||||
|
let counter = 1;
|
||||||
Object.keys(difference).forEach((key) => {
|
Object.keys(difference).forEach((key) => {
|
||||||
if (this.research[key]) {
|
if (this.research[key]) {
|
||||||
let command = this.functions.enableResearch;
|
let command = this.functions.enableResearch;
|
||||||
@@ -71,11 +89,20 @@ class ResearchSync {
|
|||||||
command = command.replace("{tech_name}", key);
|
command = command.replace("{tech_name}", key);
|
||||||
command = command.replace("{tech_researched}", difference[key].researched);
|
command = command.replace("{tech_researched}", difference[key].researched);
|
||||||
command = command.replace("{tech_level}", difference[key].level);
|
command = command.replace("{tech_level}", difference[key].level);
|
||||||
|
command = command.replace("{tech_infinite}", difference[key].infinite);
|
||||||
|
command = command.replace("{notify}", count > 1 || count === counter ? 'false' : 'true');
|
||||||
}
|
}
|
||||||
this.messageInterface(command);
|
this.messageInterface(command);
|
||||||
console.log('Unlocking '+ key + ': ' + (difference[key].researched === 0 ? 'false' : 'true') + ' and level ' + difference[key].level + ', was '+ (this.research[key].researched === 0 ? 'false' : 'true') + ' at level ' + this.research[key].level);
|
let log_message = '';
|
||||||
this.messageInterface("Unlocking research: " + key + " at research state = " + (difference[key].researched === 0 ? 'false' : 'true') + ' and level ' + difference[key].level);
|
if (difference[key].infinite === 1) {
|
||||||
|
log_message = 'Unlocking infinite research ' + key + 'at level ' + this.research[key].level;
|
||||||
|
} else {
|
||||||
|
log_message = 'Unlocking research ' + key;
|
||||||
|
}
|
||||||
|
console.log(log_message);
|
||||||
|
this.messageInterface(log_message);
|
||||||
this.research[key] = difference[key];
|
this.research[key] = difference[key];
|
||||||
|
++counter;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -93,9 +120,13 @@ class ResearchSync {
|
|||||||
let diff = {};
|
let diff = {};
|
||||||
Object.keys(localResearch).forEach((key) => {
|
Object.keys(localResearch).forEach((key) => {
|
||||||
if (remoteResearch.hasOwnProperty(key)) {
|
if (remoteResearch.hasOwnProperty(key)) {
|
||||||
if ((localResearch[key].researched === 0 && localResearch[key].researched !== remoteResearch[key].researched) || localResearch[key].level < remoteResearch[key].level) {
|
if (
|
||||||
if (!isNaN(remoteResearch[key].researched) && !isNaN(remoteResearch[key].level)) {
|
(localResearch[key].infinite === 0 && localResearch[key].researched === 0 && remoteResearch[key].researched === 1)
|
||||||
diff[key] = {researched: remoteResearch[key].researched, level: remoteResearch[key].level};
|
||
|
||||||
|
(localResearch[key].infinite === 1 && localResearch[key].level < remoteResearch[key].level)
|
||||||
|
) {
|
||||||
|
if (!isNaN(remoteResearch[key].researched) && !isNaN(remoteResearch[key].level) && !isNaN(remoteResearch[key].infinite)) {
|
||||||
|
diff[key] = {researched: remoteResearch[key].researched, level: remoteResearch[key].level, infinite: remoteResearch[key].infinite};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,6 +144,7 @@ class ResearchSync {
|
|||||||
loadFunc(path) {
|
loadFunc(path) {
|
||||||
return fs.readFileSync("sharedPlugins/researchSync/" + path, 'utf-8').replace(/\r?\n|\r/g, ' ');
|
return fs.readFileSync("sharedPlugins/researchSync/" + path, 'utf-8').replace(/\r?\n|\r/g, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptOutput(data) {
|
scriptOutput(data) {
|
||||||
let kv = data.split(":");
|
let kv = data.split(":");
|
||||||
let name = kv[0];
|
let name = kv[0];
|
||||||
@@ -120,8 +152,11 @@ class ResearchSync {
|
|||||||
? 0
|
? 0
|
||||||
: 1);
|
: 1);
|
||||||
let level = parseInt(kv[2]);
|
let level = parseInt(kv[2]);
|
||||||
|
let infinite = ('true' !== kv[3]
|
||||||
|
? 0
|
||||||
|
: 1);
|
||||||
if (!isNaN(level) && !isNaN(researched)) {
|
if (!isNaN(level) && !isNaN(researched)) {
|
||||||
this.research[name] = {researched: researched, level: level};
|
this.research[name] = {researched: researched, level: level, infinite: infinite};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user