Skip to content

Example for less adept users #44

@surpriseassociate

Description

@surpriseassociate

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions