mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +09:00
#61 chunkStore is getting filled/emptied on demand
This commit is contained in:
1 parent
b1f35c9b72
commit
8fce9a2cfe
6 files changed
+72
-62
No files matched your search
@@ -1,57 +1,59 @@
|
||||
const needle = require("needle");
|
||||
const io = require("socket.io");
|
||||
const ioClient = require("socket.io-client");
|
||||
|
||||
const chunkStore = require("./../../lib/chunkStore.js");
|
||||
|
||||
const moduleConfig = require("./config"); // not to be confused with clusterio config. This config is private to this plugin.
|
||||
console.log("/silent-command game.print('"+moduleConfig.name+" version "+moduleConfig.version+" enabled')");
|
||||
|
||||
// initialize chunk database
|
||||
const chunkMap = new chunkStore(config.unique, 64, "./chunkStore/"+config.unique);
|
||||
|
||||
/*setInterval(function(){
|
||||
console.log("/silent-command game.write_file('"+moduleConfig.scriptOutputFileSubscription+"', game.tick, true, 0)");
|
||||
},1000);*/
|
||||
|
||||
var config = {};
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('readable', () => {
|
||||
var chunk = process.stdin.read();
|
||||
if (chunk !== null && !isNaN(chunk) && !chunk.includes("objects")){
|
||||
console.log(chunk);
|
||||
throw chunk;
|
||||
// objects -29,-35;-28,-34: ,inserter -28.5 -34.5
|
||||
class remoteMap {
|
||||
constructor(slaveConfig, messageInterface){
|
||||
this.config = slaveConfig;
|
||||
this.messageInterface = messageInterface;
|
||||
|
||||
let data = chunk.split(",");
|
||||
data.shift();data.shift();data.shift();
|
||||
if(data && data[0] == undefined){
|
||||
// this position is now empty, delete whatever was there from DB
|
||||
console.log("empty: ")
|
||||
console.log(chunk)
|
||||
}
|
||||
data.forEach(entity => {
|
||||
let name = entity.split(" ")[0];
|
||||
let xPos = entity.split(" ")[1];
|
||||
let yPos = entity.split(" ")[2];
|
||||
if(xPos && yPos && name){
|
||||
chunkMap.setEntity(xPos, yPos, name).then(chunk => {
|
||||
console.log("Added "+name+" to chunk "+chunk.position.x+", "+chunk.position.y);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
// config is the same config as client.js and master.js uses
|
||||
config = JSON.parse(chunk);
|
||||
// initialize chunk database
|
||||
this.chunkMap = new chunkStore(this.config.unique, 64, "./database/chunkStore/");
|
||||
|
||||
// set up websocket communication and handle requests from web interface users (which are going through master)
|
||||
// socket should be a global
|
||||
socket = io.connect("http://"+config.masterIP+":"+config.masterPort);
|
||||
socket.on("hello", data => {
|
||||
socket.emit("registerSlaveMapper", {instanceID: config.unique});
|
||||
this.socket = ioClient("http://"+this.config.masterIP+":"+this.config.masterPort);
|
||||
this.socket.on("hello", data => {
|
||||
this.socket.emit("registerSlaveMapper", {instanceID: this.config.unique});
|
||||
});
|
||||
this.socket.on("getChunk", req => {
|
||||
|
||||
});
|
||||
|
||||
this.messageInterface("/silent-command game.print('"+moduleConfig.name+" version "+moduleConfig.version+" enabled')");
|
||||
}
|
||||
});
|
||||
process.stdin.on('end', () => {
|
||||
process.stdout.write('end');
|
||||
});
|
||||
scriptOutput(data){
|
||||
if(data){
|
||||
this.messageInterface(data);
|
||||
// express-transport-belt -35.5 -14.5
|
||||
|
||||
data = data.split(" ");
|
||||
if(data && data[0] == undefined){
|
||||
// this position is now empty, delete whatever was there from DB
|
||||
console.log("empty: ");
|
||||
console.log(data);
|
||||
return
|
||||
}
|
||||
let name = data[0];
|
||||
let xPos = data[1];
|
||||
let yPos = data[2];
|
||||
if(xPos && yPos && name){
|
||||
if(name == "deleted"){
|
||||
this.chunkMap.setEntity(xPos, yPos, "delete this entity").then(data => {
|
||||
this.messageInterface("Deleted data "+data.position.x+", "+data.position.y);
|
||||
}).catch((err)=>messageInterface(err));
|
||||
} else {
|
||||
this.chunkMap.setEntity(xPos, yPos, {name}).then(data => {
|
||||
this.messageInterface("Added "+name+" to data "+data.position.x+", "+data.position.y);
|
||||
}).catch((err)=>messageInterface(err));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = remoteMap;
|
||||
Reference in new issue
Block a user