From eb3bf980d3b72f26b1b78f28ecc38e5d16108d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vest=C3=B8l?= Date: Mon, 22 Apr 2019 13:40:50 +0200 Subject: [PATCH] Fixed remoteMap stuff --- sharedPlugins/remoteMap/index.js | 8 ++++++-- sharedPlugins/remoteMap/masterPlugin.js | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sharedPlugins/remoteMap/index.js b/sharedPlugins/remoteMap/index.js index efc97116..eeca6f56 100644 --- a/sharedPlugins/remoteMap/index.js +++ b/sharedPlugins/remoteMap/index.js @@ -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 diff --git a/sharedPlugins/remoteMap/masterPlugin.js b/sharedPlugins/remoteMap/masterPlugin.js index 4fd54522..1494bbe4 100644 --- a/sharedPlugins/remoteMap/masterPlugin.js +++ b/sharedPlugins/remoteMap/masterPlugin.js @@ -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 + })*/ ) }) })