pushrax / node-rcon

A generic RCON protocol client for node.js
MIT License
132 stars 31 forks source link

Example for less adept users #44

Open surpriseassociate opened 2 years ago

surpriseassociate commented 2 years ago

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.

eX-C0n commented 1 year ago

I am also trying to do the same thing. Respond if you figured something out!

-- @eX#1996 on disc.