diff --git a/client.js b/client.js index e1c1f44a..050d4b39 100644 --- a/client.js +++ b/client.js @@ -29,7 +29,12 @@ function deleteFolderRecursive(path) { // function to handle sending commands into the game 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 { client.exec(command, callback); } catch (err) { @@ -43,12 +48,29 @@ function messageInterface(command, callback) { let pluginDirectories = getDirectories("./sharedPlugins/"); let plugins = []; for(i=0; i { + 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) { diff --git a/sharedPlugins/clusterioPluginExample-1.0.0/clusterioPluginExample.exe b/sharedPlugins/clusterioPluginExample-1.0.0/clusterioPluginExample.exe new file mode 100644 index 00000000..6c8e628d Binary files /dev/null and b/sharedPlugins/clusterioPluginExample-1.0.0/clusterioPluginExample.exe differ diff --git a/sharedPlugins/clusterioPluginExample-1.0.0/config.js b/sharedPlugins/clusterioPluginExample-1.0.0/config.js new file mode 100644 index 00000000..72af910e --- /dev/null +++ b/sharedPlugins/clusterioPluginExample-1.0.0/config.js @@ -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.", +} \ No newline at end of file