Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not a Issue, but a question #51

Open
ECEstal opened this issue Nov 5, 2023 · 1 comment
Open

Not a Issue, but a question #51

ECEstal opened this issue Nov 5, 2023 · 1 comment

Comments

@ECEstal
Copy link

ECEstal commented Nov 5, 2023

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
Copy link

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
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants