node-rcon icon indicating copy to clipboard operation
node-rcon copied to clipboard

Example for less adept users

Open surpriseassociate opened this issue 2 years ago • 1 comments

Hi!

Full disclaimer; I'm not very good at Javascript. I did a bit with jQuery/Javascript for web, but I'm just starting out with NodeJS.

I'm trying to build a forever looping service that just polls my Ark servers for the chat log, and posts it to my Discord server via webhooks. Unfortunately, I'm having issues using the response back from RCON outside of the .on() functions.

I used both examples to create something like this, and it fails because 'response' is not specified.

var Rcon = require('../node-rcon');

var conn = new Rcon('localhost', 1234, 'password');

conn.on('auth', function() {
  console.log("Authenticated");
  console.log("Sending command: help")
  conn.send("help");
}).on('response', function(str) {
  var response = str;
  console.log("Response: " + str);
}).on('error', function(err) {
  console.log("Error: " + err);
}).on('end', function() {
  console.log("Connection closed");
  process.exit();
});

conn.connect();

if (response == "some response") {
    console.log("Do something with " + response);
}

It would be nice to have an example that shows how to use the data outside of the .on() function. It may be seen as baby sitting but server admins aren't always the most saavy nodejs devs, and it's rather inhibiting getting stuck on things like this.

Googling didn't provide extraordinarily great assistance because I could use promises, but I don't know how that applies in context to this module.

surpriseassociate avatar May 04 '22 12:05 surpriseassociate