mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
#41 Basic plugins can now send commands to game
This commit is contained in:
1 parent
27148053ae
commit
d73bfbc1eb
3 files changed
+40
-6
No files matched your search
@@ -29,7 +29,12 @@ function deleteFolderRecursive(path) {
|
|||||||
|
|
||||||
// function to handle sending commands into the game
|
// function to handle sending commands into the game
|
||||||
function messageInterface(command, callback) {
|
function messageInterface(command, callback) {
|
||||||
if(client && client.exec && typeof client.exec == "function") {
|
// try to save us if you send a buffer instead of string
|
||||||
|
if(typeof command == "object") {
|
||||||
|
command = command.toString('utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof command == "string" && client && client.exec && typeof client.exec == "function") {
|
||||||
try {
|
try {
|
||||||
client.exec(command, callback);
|
client.exec(command, callback);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -43,12 +48,29 @@ function messageInterface(command, callback) {
|
|||||||
let pluginDirectories = getDirectories("./sharedPlugins/");
|
let pluginDirectories = getDirectories("./sharedPlugins/");
|
||||||
let plugins = [];
|
let plugins = [];
|
||||||
for(i=0; i<pluginDirectories.length; i++) {
|
for(i=0; i<pluginDirectories.length; i++) {
|
||||||
function log(t) {
|
let I = i
|
||||||
console.log("clusterio | "+ pluginDirectories[i] + " | " + t)
|
let log = function(t) {
|
||||||
|
console.log("Clusterio | "+ pluginDirectories[I] + " | " + t)
|
||||||
}
|
}
|
||||||
plugins.push(require("./sharedPlugins/"+pluginDirectories[i]));
|
// plugins.push(require("./sharedPlugins/"+pluginDirectories[i]));
|
||||||
console.log("clusterio | Loaded plugin " + pluginDirectories[i]);
|
|
||||||
plugins[i].onLoad(undefined, log, {language: "english"})
|
let pluginConfig = require("./sharedPlugins/" + pluginDirectories[i] + "/config.js")
|
||||||
|
plugins.push(child_process.spawn(pluginConfig.binary, [], {
|
||||||
|
cwd: "./sharedPlugins/"+pluginDirectories[i],
|
||||||
|
stdio: ['pipe', 'pipe', 'pipe'],
|
||||||
|
}));
|
||||||
|
//plugins.push();
|
||||||
|
console.log("Clusterio | Loaded plugin " + pluginDirectories[i]);
|
||||||
|
plugins[i].stdout.on("data", (data) => {
|
||||||
|
log("Stdout: " + data);
|
||||||
|
messageInterface(data.toString('utf8'));
|
||||||
|
});
|
||||||
|
plugins[i].stderr.on("data", (data) => {
|
||||||
|
log("STDERR: " + data);
|
||||||
|
})
|
||||||
|
plugins[i].on('close', (code) => {
|
||||||
|
console.log(`child process exited with code ${code}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerPluginEvent(event, plugins, data) {
|
function triggerPluginEvent(event, plugins, data) {
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
Example config file for example Clusterio plugin
|
||||||
|
Binary will be spawned using child_process.fork and get input from stdin and text from stdout will be ran as
|
||||||
|
commands in the factorio server.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "clusterioPluginExample.exe",
|
||||||
|
version: "1.0.0",
|
||||||
|
binary: "clusterioPluginExample",
|
||||||
|
description: "Example plugin for Clusterio to show easy interface integration with factorio servers.",
|
||||||
|
}
|
||||||
Reference in new issue
Block a user