mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Fixed remoteMap stuff
This commit is contained in:
1 parent
82141ac9d7
commit
eb3bf980d3
2 files changed
+22
-4
No files matched your search
@@ -8,7 +8,9 @@ module.exports = class remoteMap {
|
|||||||
this.socket = extras.socket;
|
this.socket = extras.socket;
|
||||||
this.instances = {};
|
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 => {
|
this.socket.on("createEntity", req => {
|
||||||
// req = {name:"", position:{x,y}, ?direction:4}
|
// 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.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) => {
|
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
|
// detect new entities created/deleted on the server and update the master
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ const sanitizer = require('sanitizer');
|
|||||||
|
|
||||||
const editorSockets = [];
|
const editorSockets = [];
|
||||||
|
|
||||||
|
const blacklistedEntities = [
|
||||||
|
"fish",
|
||||||
|
"player",
|
||||||
|
]
|
||||||
|
|
||||||
class masterPlugin {
|
class masterPlugin {
|
||||||
constructor({ config, pluginConfig, pluginPath, socketio, express }) {
|
constructor({ config, pluginConfig, pluginPath, socketio, express }) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@@ -24,7 +29,8 @@ class masterPlugin {
|
|||||||
// handle websocket connections
|
// handle websocket connections
|
||||||
this.io.on("connection", socket => {
|
this.io.on("connection", socket => {
|
||||||
let instanceID = "unknown";
|
let instanceID = "unknown";
|
||||||
socket.on("registerSlave", data => {
|
socket.on("registerMapServer", data => {
|
||||||
|
console.log("Registered mapServer socket")
|
||||||
if (data.instanceID && !isNaN(Number(data.instanceID))) {
|
if (data.instanceID && !isNaN(Number(data.instanceID))) {
|
||||||
instanceID = data.instanceID;
|
instanceID = data.instanceID;
|
||||||
this.slaves[instanceID] = socket;
|
this.slaves[instanceID] = socket;
|
||||||
@@ -66,12 +72,15 @@ class masterPlugin {
|
|||||||
}}),10000)
|
}}),10000)
|
||||||
|
|
||||||
socket.on("createEntity", data => {
|
socket.on("createEntity", data => {
|
||||||
|
console.log(`Creating entity: ${JSON.stringify(data)}`)
|
||||||
this.slaves[Object.keys(this.slaves)[0]].emit("createEntity", data.entity)
|
this.slaves[Object.keys(this.slaves)[0]].emit("createEntity", data.entity)
|
||||||
})
|
})
|
||||||
socket.on("deleteEntity", data => {
|
socket.on("deleteEntity", data => {
|
||||||
|
console.log(`Deleting entity: ${JSON.stringify(data)}`)
|
||||||
this.slaves[Object.keys(this.slaves)[0]].emit("deleteEntity", data.entity)
|
this.slaves[Object.keys(this.slaves)[0]].emit("deleteEntity", data.entity)
|
||||||
})
|
})
|
||||||
socket.on("getChunk", (data, callback) => {
|
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 => {
|
this.slaves[Object.keys(this.slaves)[0]].emit("getChunk", data, resp => {
|
||||||
// parse response
|
// parse response
|
||||||
// |name:transport-belt,direction:2,x:99,y:1231|name:assembly-machine,direction:6,x:939,y:88
|
// |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("crude-oil") &&
|
||||||
!str.includes("remnants") &&
|
!str.includes("remnants") &&
|
||||||
!str.includes("cliff") &&
|
!str.includes("cliff") &&
|
||||||
!str.includes("player") &&
|
!blacklistedEntities.includes(str) &&
|
||||||
!str.includes("ore"))
|
!str.includes("ore"))
|
||||||
.map(ent => ent.split(",") // split entity into properties
|
.map(ent => ent.split(",") // split entity into properties
|
||||||
.map(prop => [prop.split(":")[0], prop.split(":")[1]]) // split properties into KV pairs
|
.map(prop => [prop.split(":")[0], prop.split(":")[1]]) // split properties into KV pairs
|
||||||
@@ -102,6 +111,11 @@ class masterPlugin {
|
|||||||
return entity
|
return entity
|
||||||
})
|
})
|
||||||
.filter(entity => Object.keys(entity).length > 1)
|
.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
|
||||||
|
})*/
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user