pushrax / node-rcon

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

Not a Issue, but a question #51

Open ECEstal opened 12 months ago

ECEstal commented 12 months ago

Is it possible to save the value of the on('response') to a variable I can pull after conn.connect(), so that it can be passed over as a return value?

var response;
const rcon = require("./rcon.js");
        var options = {
        tcp: true,
        challenge:false
        };
    var conn = new Rcon('192.168.1.101', 27020, rconPass, options);
    conn.on('auth', function() {
        conn.send("listplayers");
    }).on('response', function(str) {
        response = str;
    });
    conn.connect();
    return response;

There's an example of what I'd like to do.

Crito-VanaheimServers commented 9 months ago

function rconCall(rconCMD,callback){ var conn = new Rcon((process.env.Global_IP),(process.env.ASA_rcon_port),(process.env.ASA_password),rconoptions);

conn.on('auth', function() {
  conn.send(rconCMD);
}).on('response', function(rconInfo) {
  console.log("Response: " + rconInfo);
  conn.emit('end');
  return callback(rconInfo);
}).on('error', function(err) {
  console.log("Error: " + err);
}).on('end', function() {
  conn.disconnect();
});
conn.connect();

};

rconCall("GetChat",function(response){ Some code that uses your response here });