mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Shout displays instance name now
This commit is contained in:
1 parent
1184e64467
commit
1fede26564
1 file changed
+31
-10
@@ -3,24 +3,45 @@ module.exports = class remoteCommands {
|
|||||||
this.messageInterface = messageInterface;
|
this.messageInterface = messageInterface;
|
||||||
this.config = mergedConfig;
|
this.config = mergedConfig;
|
||||||
this.socket = extras.socket;
|
this.socket = extras.socket;
|
||||||
|
this.instances = {};
|
||||||
this.socket.emit("registerChatReciever");
|
this.socket.emit("registerChatReciever");
|
||||||
this.socket.on("gameChat", data => {
|
this.socket.on("gameChat", data => {
|
||||||
if(data.instanceID && data.instanceID != this.config.unique.toString()){
|
if(data.instanceID && data.instanceID != this.config.unique.toString()){
|
||||||
if(data.data.includes("[CHAT]") && data.data.toLowerCase().includes("!shout")){
|
if(data.data.includes("[CHAT]") && (data.data.toLowerCase().includes("/shout") || data.data.toLowerCase().includes("!shout"))){
|
||||||
let message = data.data.trim().split(" ");
|
let words = data.data.trim().split(" ");
|
||||||
message.shift();
|
words.shift();
|
||||||
message.shift();
|
words.shift();
|
||||||
message.shift();
|
words.shift();
|
||||||
let chatMessage = "["+data.instanceID+"]"+ message.join(" ");
|
let message = words.join(" ").replace(/[";]/g, " ").replace(/[']/g,"").replace("/shout ", "").replace("!shout", "");
|
||||||
chatMessage = chatMessage.replace(/[^a-zA-Z0-9]+/g, " ");
|
let instance = this.instances[data.instanceID];
|
||||||
this.messageInterface("/silent-command game.print('"+chatMessage.replace("!shout ","")+"')");
|
if (!instance) {
|
||||||
|
let me = this; //to pass 'this' down to the callback
|
||||||
|
require('needle').get(this.config.masterIP + '/api/slaves', function (err, response) {
|
||||||
|
if(err || response.statusCode != 200) {
|
||||||
|
console.log("Unable to get JSON master/api/slaves, master might be unaccessible");
|
||||||
|
} else if (response && response.body) {
|
||||||
|
if(Buffer.isBuffer(response.body)) {console.log(response.body.toString("utf-8")); throw new Error();}
|
||||||
|
try {
|
||||||
|
for (let index in response.body)
|
||||||
|
me.instances[index] = response.body[index]["instanceName"];
|
||||||
|
} catch (e){
|
||||||
|
console.log(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
instance = me.instances[data.instanceID]
|
||||||
|
if (!instance)
|
||||||
|
instance = data.instanceID; //somehow the master doesn't know the instance
|
||||||
|
me.messageInterface("/silent-command game.print('[" + instance + "] " + message +"')");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.messageInterface("/silent-command game.print('[" + instance + "] " + message + "')");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
factorioOutput(data){
|
factorioOutput(data){
|
||||||
// console.log("GOT CHAT!"+data)
|
|
||||||
this.socket.emit("gameChat", {
|
this.socket.emit("gameChat", {
|
||||||
instanceID: this.config.unique.toString(),
|
instanceID: this.config.unique.toString(),
|
||||||
data,
|
data,
|
||||||
|
|||||||
Reference in new issue
Block a user