Fixed remoteMap stuff

This commit is contained in:
Daniel Vestøl committed 2019-04-22 13:40:50 +02:00
1 parent 82141ac9d7
commit eb3bf980d3
2 files changed
+22 -4

No files matched your search

+6 -2
View File
@@ -8,7 +8,9 @@ module.exports = class remoteMap {
this.socket = extras.socket;
this.instances = {};
this.socket.on("hello", () => this.socket.emit("registerMapServer"));
this.socket.on("hello", () => this.socket.emit("registerMapServer", {
instanceID: this.config.unique, // instanceID
}));
this.socket.on("createEntity", req => {
// req = {name:"", position:{x,y}, ?direction:4}
@@ -29,7 +31,9 @@ module.exports = class remoteMap {
this.messageInterface('/silent-command local toDelete = game.surfaces[1].find_entities({{'+req.position.x+','+req.position.y+'},{'+(req.position.x+0.5)+','+(req.position.y+0.5)+'}}) for i, entity in pairs(toDelete) do entity.destroy() end');
})
this.socket.on("getChunk", async (data, callback) => {
callback(await this.messageInterface(`/silent-command remote.call("remoteMap", "exportChunk", ${data.x}, ${data.y})`));
let chunkData = await this.messageInterface(`/silent-command remote.call("remoteMap", "exportChunk", ${data.x}, ${data.y})`)
console.log(`Sending chunk data: ${chunkData}`)
callback(chunkData);
})
// detect new entities created/deleted on the server and update the master
+16 -2
View File
@@ -4,6 +4,11 @@ const sanitizer = require('sanitizer');
const editorSockets = [];
const blacklistedEntities = [
"fish",
"player",
]
class masterPlugin {
constructor({ config, pluginConfig, pluginPath, socketio, express }) {
this.config = config;
@@ -24,7 +29,8 @@ class masterPlugin {
// handle websocket connections
this.io.on("connection", socket => {
let instanceID = "unknown";
socket.on("registerSlave", data => {
socket.on("registerMapServer", data => {
console.log("Registered mapServer socket")
if (data.instanceID && !isNaN(Number(data.instanceID))) {
instanceID = data.instanceID;
this.slaves[instanceID] = socket;
@@ -66,12 +72,15 @@ class masterPlugin {
}}),10000)
socket.on("createEntity", data => {
console.log(`Creating entity: ${JSON.stringify(data)}`)
this.slaves[Object.keys(this.slaves)[0]].emit("createEntity", data.entity)
})
socket.on("deleteEntity", data => {
console.log(`Deleting entity: ${JSON.stringify(data)}`)
this.slaves[Object.keys(this.slaves)[0]].emit("deleteEntity", data.entity)
})
socket.on("getChunk", (data, callback) => {
console.log(`Getting chunk x:${data.x} y:${data.y} from slave`)
this.slaves[Object.keys(this.slaves)[0]].emit("getChunk", data, resp => {
// parse response
// |name:transport-belt,direction:2,x:99,y:1231|name:assembly-machine,direction:6,x:939,y:88
@@ -87,7 +96,7 @@ class masterPlugin {
!str.includes("crude-oil") &&
!str.includes("remnants") &&
!str.includes("cliff") &&
!str.includes("player") &&
!blacklistedEntities.includes(str) &&
!str.includes("ore"))
.map(ent => ent.split(",") // split entity into properties
.map(prop => [prop.split(":")[0], prop.split(":")[1]]) // split properties into KV pairs
@@ -102,6 +111,11 @@ class masterPlugin {
return entity
})
.filter(entity => Object.keys(entity).length > 1)
.filter(entity => !blacklistedEntities.includes(entity.name))
/*.map(entity => {
if(entity.name.includes("tree")) entity.name = "tree"
return entity
})*/
)
})
})