Add automatic DNS resolution for server addresses

This commit is contained in:
gsemaj 2022-04-27 13:44:08 -04:00
parent 6e881cbfaf
commit 8d6e546628

View File

@ -1,5 +1,6 @@
var remote = require("remote"); var remote = require("remote");
var remotefs = remote.require('fs-extra'); var remotefs = remote.require('fs-extra');
var dns = remote.require('dns');
var userdir = remote.require('app').getPath('userData'); var userdir = remote.require('app').getPath('userData');
var versionarray var versionarray
@ -167,7 +168,19 @@ function setGameInfo(serverUUID) {
address = result.ip address = result.ip
port = 23000 // default port = 23000 // default
} }
remotefs.writeFileSync(__dirname+"\\loginInfo.php", address + ":" + port);
// DNS resolution. there is no synchronous version unfortunately
// if the resolution fails, keep the original entry (includes plain IP cases)
var ip = address;
dns.resolve4(address, function(err, res) {
if(!err) {
ip = res[0];
console.log("Resolved " + address + " to " + ip);
}
var fullAddress = ip + ":" + port;
console.log("Will connect to " + fullAddress);
remotefs.writeFileSync(__dirname+"\\loginInfo.php", fullAddress);
if (result.hasOwnProperty('endpoint')) { if (result.hasOwnProperty('endpoint')) {
var httpendpoint = result.endpoint.replace("https://", "http://") var httpendpoint = result.endpoint.replace("https://", "http://")
@ -183,6 +196,7 @@ function setGameInfo(serverUUID) {
remotefs.writeFileSync(__dirname+"\\images.php", "assets/img/"); remotefs.writeFileSync(__dirname+"\\images.php", "assets/img/");
} }
} }
});
} }
// Returns the UUID of the server with the selected background color. // Returns the UUID of the server with the selected background color.