Websockets for listening to factorio logs and global chat plugin

You can now !shout things across the cluster
This commit is contained in:
Danielv123 committed 2018-04-26 18:33:29 +02:00
1 parent 641f980741
commit ce0deef83b
5 files changed
+54 -1

No files matched your search

+1
View File
@@ -48,3 +48,4 @@ sharedPlugins/*
!sharedPlugins/remoteMap/
!sharedPlugins/remoteCommands/
!sharedPlugins/researchSync/
!sharedPlugins/globalChat/
+4
View File
@@ -469,6 +469,10 @@ function instanceManagement() {
}, { // extra functions to pass in object. Should have done it like this from the start, but won't break backwards compat.
socket, // socket.io connection to master (and ES6 destructuring, yay)
});
if(plugins[I].factorioOutput && typeof plugins[I].factorioOutput === "function"){
// when factorio logs a line, send it to the plugin. This includes things like autosaves, chat, errors etc
serverprocess.stdout.on("data", data => plugins[I].factorioOutput(data.toString()));
}
if(pluginConfig.scriptOutputFileSubscription && typeof pluginConfig.scriptOutputFileSubscription == "string"){
if(global.subscribedFiles[pluginConfig.scriptOutputFileSubscription]) {
// please choose a unique file to subscribe to. If you need plugins to share this interface, set up a direct communication
+15 -1
View File
@@ -940,6 +940,16 @@ class wsSlave {
delete this.commandsWaitingForReturn[resp.commandID];
}
});
this.socket.on("gameChat", data => {
if(typeof data === "object"){
data.timestamp = Date.now();
if(!global.wsChatRecievers) global.wsChatRecievers = [];
global.wsChatRecievers.forEach(socket => {
socket.emit("gameChat", data);
});
}
});
}
runCommand(command, callback){
let commandID = Math.random().toString();
@@ -988,7 +998,11 @@ io.on('connection', function (socket) {
console.log("SOCKET | Created new wsSlave: "+ data.instanceID);
}
});
socket.on("registerChatReciever", function(data){
prometheusWsUsageCounter.labels("registerChatReciever").inc();
if(!global.wsChatRecievers) global.wsChatRecievers = [];
global.wsChatRecievers.push(socket);
});
});
module.exports = app;
+10
View File
@@ -0,0 +1,10 @@
/*
Clusterio plugin to allow for chat between instances.
*/
module.exports = {
// Name of package. For display somewhere I guess.
name: "globalChat",
version: "1.0.0",
binary: "nodePackage",
description: "Clusterio plugin to allow for chat between instances.",
}
+24
View File
@@ -0,0 +1,24 @@
module.exports = class remoteCommands {
constructor(mergedConfig, messageInterface, extras){
this.messageInterface = messageInterface;
this.config = mergedConfig;
this.socket = extras.socket;
this.socket.emit("registerChatReciever");
this.socket.on("gameChat", data => {
if(data.instanceID && data.instanceID != this.config.unique.toString()){
if(data.data.includes("[CHAT]") && data.data.toLowerCase().includes("!shout")){
let chatMessage = "["+data.instanceID+"]"+ data.data.trim().split(" ").shift().shift().shift().join(" ");
this.messageInterface("/c game.print('"+chatMessage+"')");
}
}
});
}
factorioOutput(data){
// console.log("GOT CHAT!"+data)
this.socket.emit("gameChat", {
instanceID: this.config.unique.toString(),
data,
});
}
}