I am trying to query the master server which returns the result in this format:
[
{ ip: '127.0.0.1', port: 28961 },
{ ip: '127.0.0.1', port: 28965 }
]
Then, I need to query every server and it's IP with queryDedicated which then returns the data in a callback (same as queryMaster).
If the returned data in the callback is valid, it will add it to an array, and finally print the whole servers array to the console.
var servers = {};
function blabla(host, port) {
queryMaster(host, port, function(data) {
async.forEach(data, function(key, next) {
queryDedicated(key.ip, key.port, function(srv) {
if (srv) {
// if callback data valid, add to array
servers[key.ip + ':' + key.port] = srv;
}
})
// valid or not, continue
next();
}, function(err) {
// print servers array
console.log(servers);
});
});
}
The problem is that my servers array is empty.
Final 'servers' array should output the data in this format:
{
"176.57.141.60:28960": {
"hostname": "board.landstuhl-atzel.de Schlachthaus #1",
"address": "176.57.141.60:28960",
"gametype": "war",
"mapname": "mp_rundown",
"players": "0",
"max_players": "18"
},
"176.57.142.144:28663": {
"hostname": "ClassicSnD.org No mercy for hackers. No lag. No bullshit. [B3]",
"address": "176.57.142.144:28663",
"gametype": "sd",
"mapname": "mp_favela",
"players": "0",
"max_players": "18"
}
}
Thanks!
next()synchronously. You need to go with the asyncqueryDedicatedcallback!