2023-09-17 01:51:33 +00:00
|
|
|
// TODO: path.join in this file, pass in json paths from index.js
|
2021-05-17 02:00:27 +00:00
|
|
|
var remote = require("remote");
|
2022-07-26 14:48:33 +00:00
|
|
|
var remotefs = remote.require("fs-extra");
|
|
|
|
var dns = remote.require("dns");
|
2021-05-17 02:00:27 +00:00
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
var userDir = remote.require("app").getPath("userData");
|
|
|
|
var versionArray;
|
|
|
|
var serverArray;
|
2022-06-28 22:57:30 +00:00
|
|
|
var config;
|
2021-05-17 02:00:27 +00:00
|
|
|
|
|
|
|
function enableServerListButtons() {
|
2022-07-26 14:48:33 +00:00
|
|
|
$("#of-connect-button").removeClass("disabled");
|
|
|
|
$("#of-connect-button").prop("disabled", false);
|
|
|
|
$("#of-editserver-button").removeClass("disabled");
|
|
|
|
$("#of-editserver-button").prop("disabled", false);
|
|
|
|
$("#of-deleteserver-button").removeClass("disabled");
|
|
|
|
$("#of-deleteserver-button").prop("disabled", false);
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function disableServerListButtons() {
|
2022-07-26 14:48:33 +00:00
|
|
|
$("#of-connect-button").addClass("disabled");
|
|
|
|
$("#of-connect-button").prop("disabled", true);
|
|
|
|
$("#of-editserver-button").addClass("disabled");
|
|
|
|
$("#of-editserver-button").prop("disabled", true);
|
|
|
|
$("#of-deleteserver-button").addClass("disabled");
|
|
|
|
$("#of-deleteserver-button").prop("disabled", true);
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
2023-02-09 11:32:21 +00:00
|
|
|
function getAppVersion() {
|
2023-09-03 09:56:24 +00:00
|
|
|
appVersion = remote.require("app").getVersion();
|
2023-02-09 18:52:57 +00:00
|
|
|
|
|
|
|
// simplify version, ex. 1.4.0 -> 1.4,
|
|
|
|
// but only if a revision number isn't present
|
2023-09-03 09:56:24 +00:00
|
|
|
if (appVersion.endsWith(".0")) {
|
|
|
|
return appVersion.substr(0, appVersion.length - 2);
|
2023-02-09 18:52:57 +00:00
|
|
|
} else {
|
2023-09-03 09:56:24 +00:00
|
|
|
return appVersion;
|
2023-02-09 18:52:57 +00:00
|
|
|
}
|
2023-02-09 11:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setAppVersionText() {
|
2023-02-09 18:52:57 +00:00
|
|
|
$("#of-aboutversionnumber").text("Version " + getAppVersion());
|
|
|
|
$("#of-versionnumber").text("v" + getAppVersion());
|
2023-02-09 11:32:21 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 02:00:27 +00:00
|
|
|
function addServer() {
|
2023-09-03 09:56:24 +00:00
|
|
|
var jsonToModify = JSON.parse(
|
|
|
|
remotefs.readFileSync(userDir + "\\servers.json")
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
var server = {};
|
|
|
|
server["uuid"] = uuidv4();
|
|
|
|
server["description"] =
|
|
|
|
$("#addserver-descinput").val().length == 0
|
|
|
|
? "My OpenFusion Server"
|
|
|
|
: $("#addserver-descinput").val();
|
|
|
|
server["ip"] =
|
|
|
|
$("#addserver-ipinput").val().length == 0
|
|
|
|
? "127.0.0.1:23000"
|
|
|
|
: $("#addserver-ipinput").val();
|
|
|
|
server["version"] = $("#addserver-versionselect option:selected").text();
|
|
|
|
//server['endpoint'] =
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
jsonToModify["servers"].push(server);
|
2022-07-26 14:48:33 +00:00
|
|
|
|
|
|
|
remotefs.writeFileSync(
|
2023-09-03 09:56:24 +00:00
|
|
|
userDir + "\\servers.json",
|
|
|
|
JSON.stringify(jsonToModify, null, 4)
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
loadServerList();
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
2021-09-18 17:47:20 +00:00
|
|
|
function editServer() {
|
2023-09-03 09:56:24 +00:00
|
|
|
var jsonToModify = JSON.parse(
|
|
|
|
remotefs.readFileSync(userDir + "\\servers.json")
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
2023-09-03 09:56:24 +00:00
|
|
|
$.each(jsonToModify["servers"], function (key, value) {
|
2022-07-26 14:48:33 +00:00
|
|
|
if (value["uuid"] == getSelectedServer()) {
|
|
|
|
value["description"] =
|
|
|
|
$("#editserver-descinput").val().length == 0
|
|
|
|
? value["description"]
|
|
|
|
: $("#editserver-descinput").val();
|
|
|
|
value["ip"] =
|
|
|
|
$("#editserver-ipinput").val().length == 0
|
|
|
|
? value["ip"]
|
|
|
|
: $("#editserver-ipinput").val();
|
|
|
|
value["version"] = $(
|
|
|
|
"#editserver-versionselect option:selected"
|
|
|
|
).text();
|
|
|
|
}
|
|
|
|
});
|
2021-09-18 17:47:20 +00:00
|
|
|
|
2022-07-26 14:48:33 +00:00
|
|
|
remotefs.writeFileSync(
|
2023-09-03 09:56:24 +00:00
|
|
|
userDir + "\\servers.json",
|
|
|
|
JSON.stringify(jsonToModify, null, 4)
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
loadServerList();
|
2021-09-18 17:47:20 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 02:00:27 +00:00
|
|
|
function deleteServer() {
|
2023-09-03 09:56:24 +00:00
|
|
|
var jsonToModify = JSON.parse(
|
|
|
|
remotefs.readFileSync(userDir + "\\servers.json")
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
2023-09-03 09:56:24 +00:00
|
|
|
var result = jsonToModify["servers"].filter(function (obj) {
|
2022-07-26 14:48:33 +00:00
|
|
|
return obj.uuid === getSelectedServer();
|
|
|
|
})[0];
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
var resultindex = jsonToModify["servers"].indexOf(result);
|
2022-07-26 14:48:33 +00:00
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
jsonToModify["servers"].splice(resultindex, 1);
|
2022-07-26 14:48:33 +00:00
|
|
|
|
|
|
|
remotefs.writeFileSync(
|
2023-09-03 09:56:24 +00:00
|
|
|
userDir + "\\servers.json",
|
|
|
|
JSON.stringify(jsonToModify, null, 4)
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
loadServerList();
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 00:28:57 +00:00
|
|
|
function restoreDefaultServers() {
|
2022-07-26 14:48:33 +00:00
|
|
|
remotefs.copySync(
|
|
|
|
__dirname + "\\defaults\\servers.json",
|
2023-09-03 09:56:24 +00:00
|
|
|
userDir + "\\servers.json"
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
loadServerList();
|
2021-09-19 00:28:57 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 02:00:27 +00:00
|
|
|
function loadGameVersions() {
|
2023-09-03 09:56:24 +00:00
|
|
|
var versionJson = JSON.parse(
|
|
|
|
remotefs.readFileSync(userDir + "\\versions.json")
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
2023-09-03 09:56:24 +00:00
|
|
|
versionArray = versionJson["versions"];
|
|
|
|
$.each(versionArray, function (key, value) {
|
2022-07-26 14:48:33 +00:00
|
|
|
$(new Option(value.name, "val")).appendTo("#addserver-versionselect");
|
|
|
|
$(new Option(value.name, "val")).appendTo("#editserver-versionselect");
|
|
|
|
});
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadConfig() {
|
2022-07-26 14:48:33 +00:00
|
|
|
// load config object globally
|
2023-09-03 09:56:24 +00:00
|
|
|
config = JSON.parse(remotefs.readFileSync(userDir + "\\config.json"));
|
2021-09-18 22:21:41 +00:00
|
|
|
}
|
2021-05-17 02:00:27 +00:00
|
|
|
|
|
|
|
function loadServerList() {
|
2023-09-03 09:56:24 +00:00
|
|
|
var serverJson = JSON.parse(
|
|
|
|
remotefs.readFileSync(userDir + "\\servers.json")
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
2023-09-03 09:56:24 +00:00
|
|
|
serverArray = serverJson["servers"];
|
2022-07-26 14:48:33 +00:00
|
|
|
|
|
|
|
$(".server-listing-entry").remove(); // Clear out old stuff, if any
|
|
|
|
disableServerListButtons(); // Disable buttons until another server is selected
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
if (serverArray.length > 0) {
|
2022-07-26 14:48:33 +00:00
|
|
|
// Servers were found in the JSON
|
|
|
|
$("#server-listing-placeholder").attr("hidden", true);
|
2023-09-03 09:56:24 +00:00
|
|
|
$.each(serverArray, function (key, value) {
|
2022-07-26 14:48:33 +00:00
|
|
|
// Create the row, and populate the cells
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
row.className = "server-listing-entry";
|
|
|
|
row.setAttribute("id", value.uuid);
|
|
|
|
var cellName = document.createElement("td");
|
|
|
|
cellName.textContent = value.description;
|
|
|
|
var cellVersion = document.createElement("td");
|
|
|
|
cellVersion.textContent = value.version;
|
|
|
|
cellVersion.className = "text-monospace";
|
|
|
|
|
|
|
|
row.appendChild(cellName);
|
|
|
|
row.appendChild(cellVersion);
|
|
|
|
$("#server-tablebody").append(row);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// No servers are added, make sure placeholder is visible
|
|
|
|
$("#server-listing-placeholder").attr("hidden", false);
|
|
|
|
}
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
function performCacheSwap(newVersion) {
|
|
|
|
var cacheRoot = userDir + "\\..\\..\\LocalLow\\Unity\\Web Player\\Cache";
|
|
|
|
var currentCache = cacheRoot + "\\Fusionfall";
|
|
|
|
var newCache = cacheRoot + "\\" + newVersion;
|
|
|
|
var record = userDir + "\\.lastver";
|
2023-02-08 20:06:54 +00:00
|
|
|
|
|
|
|
// if cache renaming would result in a no-op (ex. launching the same version
|
|
|
|
// two times), then skip it. this avoids permissions errors with multiple clients
|
|
|
|
// (file/folder is already open in another process)
|
|
|
|
var skip = false;
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
if (remotefs.existsSync(currentCache)) {
|
2023-02-08 20:06:54 +00:00
|
|
|
// cache already exists, find out what version it belongs to
|
|
|
|
if (remotefs.existsSync(record)) {
|
2023-09-03 09:56:24 +00:00
|
|
|
lastVersion = remotefs.readFileSync(record);
|
|
|
|
if (lastVersion != newVersion) {
|
2023-02-08 20:06:54 +00:00
|
|
|
remotefs.renameSync(
|
2023-09-03 09:56:24 +00:00
|
|
|
currentCache,
|
|
|
|
cacheRoot + "\\" + lastVersion
|
2023-02-08 20:06:54 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.log(
|
|
|
|
"Cached version unchanged, renaming will be skipped"
|
|
|
|
);
|
|
|
|
skip = true;
|
|
|
|
}
|
2023-09-03 09:56:24 +00:00
|
|
|
console.log("Current cache is " + lastVersion);
|
2023-02-08 20:06:54 +00:00
|
|
|
} else {
|
|
|
|
console.log(
|
|
|
|
"Couldn't find last version record; cache may get overwritten"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
if (remotefs.existsSync(newCache) || !skip) {
|
2023-02-08 20:06:54 +00:00
|
|
|
// rename saved cache to FusionFall
|
2023-09-03 09:56:24 +00:00
|
|
|
remotefs.renameSync(newCache, currentCache);
|
|
|
|
console.log("Current cache swapped to " + newVersion);
|
2023-02-08 20:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make note of what version we are launching for next launch
|
2023-09-03 09:56:24 +00:00
|
|
|
remotefs.writeFileSync(record, newVersion);
|
2023-02-08 20:06:54 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 02:00:27 +00:00
|
|
|
// For writing loginInfo.php, assetInfo.php, etc.
|
|
|
|
function setGameInfo(serverUUID) {
|
2023-09-03 09:56:24 +00:00
|
|
|
var result = serverArray.filter(function (obj) {
|
2022-07-26 14:48:33 +00:00
|
|
|
return obj.uuid === serverUUID;
|
|
|
|
})[0];
|
2023-09-03 09:56:24 +00:00
|
|
|
var gameVersion = versionArray.filter(function (obj) {
|
2022-07-26 14:48:33 +00:00
|
|
|
return obj.name === result.version;
|
|
|
|
})[0];
|
|
|
|
|
2023-02-08 20:06:54 +00:00
|
|
|
// if cache swapping property exists AND is `true`, run cache swapping logic
|
2022-07-26 14:48:33 +00:00
|
|
|
if (config["cache-swapping"]) {
|
2023-02-08 20:06:54 +00:00
|
|
|
try {
|
2023-09-03 09:56:24 +00:00
|
|
|
performCacheSwap(gameVersion.name);
|
2023-02-08 20:06:54 +00:00
|
|
|
} catch (ex) {
|
|
|
|
console.log(
|
|
|
|
"Error when swapping cache, it may get overwritten:\n" + ex
|
|
|
|
);
|
2022-07-26 14:48:33 +00:00
|
|
|
}
|
2021-09-18 22:21:41 +00:00
|
|
|
}
|
2021-05-06 18:39:09 +00:00
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
window.assetUrl = gameVersion.url; // game-client.js needs to access this
|
2022-07-26 14:48:33 +00:00
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
remotefs.writeFileSync(__dirname + "\\assetInfo.php", assetUrl);
|
2022-07-26 14:48:33 +00:00
|
|
|
if (result.hasOwnProperty("endpoint")) {
|
2023-09-03 09:56:24 +00:00
|
|
|
var httpEndpoint = result.endpoint.replace("https://", "http://");
|
2022-07-26 14:48:33 +00:00
|
|
|
remotefs.writeFileSync(
|
|
|
|
__dirname + "\\rankurl.txt",
|
2023-09-03 09:56:24 +00:00
|
|
|
httpEndpoint + "getranks"
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
// Write these out too
|
|
|
|
remotefs.writeFileSync(
|
|
|
|
__dirname + "\\sponsor.php",
|
2023-09-03 09:56:24 +00:00
|
|
|
httpEndpoint + "upsell/sponsor.png"
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
remotefs.writeFileSync(
|
|
|
|
__dirname + "\\images.php",
|
2023-09-03 09:56:24 +00:00
|
|
|
httpEndpoint + "upsell/"
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Remove/default the endpoint related stuff, this server won't be using it
|
|
|
|
if (remotefs.existsSync(__dirname + "\\rankurl.txt")) {
|
|
|
|
remotefs.unlinkSync(__dirname + "\\rankurl.txt");
|
|
|
|
remotefs.writeFileSync(
|
|
|
|
__dirname + "\\sponsor.php",
|
|
|
|
"assets/img/welcome.png"
|
|
|
|
);
|
|
|
|
remotefs.writeFileSync(__dirname + "\\images.php", "assets/img/");
|
|
|
|
}
|
2022-04-28 00:50:23 +00:00
|
|
|
}
|
2022-07-26 14:48:33 +00:00
|
|
|
|
|
|
|
// Server address parsing
|
|
|
|
var address;
|
|
|
|
var port;
|
|
|
|
var sepPos = result.ip.indexOf(":");
|
|
|
|
if (sepPos > -1) {
|
|
|
|
address = result.ip.substr(0, sepPos);
|
|
|
|
port = result.ip.substr(sepPos + 1);
|
2022-04-27 17:44:08 +00:00
|
|
|
} else {
|
2022-07-26 14:48:33 +00:00
|
|
|
address = result.ip;
|
|
|
|
port = 23000; // default
|
|
|
|
}
|
|
|
|
|
|
|
|
// DNS resolution. there is no synchronous version for some stupid reason
|
|
|
|
if (!address.match(/^[0-9.]+$/))
|
2023-09-14 11:44:11 +00:00
|
|
|
dns.lookup(address, family=4, function (err, resolvedAddress) {
|
2022-07-26 14:48:33 +00:00
|
|
|
if (!err) {
|
2023-09-14 11:44:11 +00:00
|
|
|
console.log("Resolved " + address + " to " + resolvedAddress);
|
|
|
|
address = resolvedAddress;
|
2022-07-26 14:48:33 +00:00
|
|
|
} else {
|
|
|
|
console.log("Err: " + err.code);
|
|
|
|
}
|
|
|
|
prepConnection(address, port);
|
|
|
|
});
|
|
|
|
else {
|
|
|
|
console.log(address + " is an IP; skipping DNS lookup");
|
|
|
|
prepConnection(address, port);
|
2022-04-27 17:44:08 +00:00
|
|
|
}
|
2022-04-28 00:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepConnection(address, port) {
|
2022-07-26 14:48:33 +00:00
|
|
|
var full = address + ":" + port;
|
|
|
|
console.log("Will connect to " + full);
|
|
|
|
remotefs.writeFileSync(__dirname + "\\loginInfo.php", full);
|
|
|
|
launchGame();
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the UUID of the server with the selected background color.
|
|
|
|
// Yes, there are probably better ways to go about this, but it works well enough.
|
|
|
|
function getSelectedServer() {
|
2022-07-26 14:48:33 +00:00
|
|
|
return $("#server-tablebody > tr.bg-primary").prop("id");
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function connectToServer() {
|
2022-07-26 14:48:33 +00:00
|
|
|
// Get ID of the selected server, which corresponds to its UUID in the json
|
|
|
|
console.log("Connecting to server with UUID of " + getSelectedServer());
|
|
|
|
|
|
|
|
// Prevent the user from clicking anywhere else during the transition
|
|
|
|
$("body,html").css("pointer-events", "none");
|
|
|
|
stopEasterEggs();
|
|
|
|
$("#of-serverselector").fadeOut("slow", function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
$("body,html").css("pointer-events", "");
|
|
|
|
setGameInfo(getSelectedServer());
|
|
|
|
}, 200);
|
|
|
|
});
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 22:57:30 +00:00
|
|
|
// If applicable, deselect currently selected server.
|
|
|
|
function deselectServer() {
|
2022-07-26 14:48:33 +00:00
|
|
|
disableServerListButtons();
|
|
|
|
$(".server-listing-entry").removeClass("bg-primary");
|
2022-06-28 22:57:30 +00:00
|
|
|
}
|
2021-09-18 16:31:40 +00:00
|
|
|
|
2022-07-26 14:48:33 +00:00
|
|
|
$("#server-table").on("click", ".server-listing-entry", function (event) {
|
|
|
|
enableServerListButtons();
|
|
|
|
$(this).addClass("bg-primary").siblings().removeClass("bg-primary");
|
2021-05-17 02:00:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// QoL feature: if you double click on a server it will connect
|
2022-07-26 14:48:33 +00:00
|
|
|
$("#server-table").on("dblclick", ".server-listing-entry", function (event) {
|
|
|
|
$(this).addClass("bg-primary").siblings().removeClass("bg-primary");
|
|
|
|
connectToServer();
|
2021-05-17 02:00:27 +00:00
|
|
|
});
|
|
|
|
|
2022-07-26 14:48:33 +00:00
|
|
|
$("#of-editservermodal").on("show.bs.modal", function (e) {
|
2023-09-03 09:56:24 +00:00
|
|
|
var jsonToModify = JSON.parse(
|
|
|
|
remotefs.readFileSync(userDir + "\\servers.json")
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
2023-09-03 09:56:24 +00:00
|
|
|
$.each(jsonToModify["servers"], function (key, value) {
|
2022-07-26 14:48:33 +00:00
|
|
|
if (value["uuid"] == getSelectedServer()) {
|
|
|
|
$("#editserver-descinput")[0].value = value["description"];
|
|
|
|
$("#editserver-ipinput")[0].value = value["ip"];
|
|
|
|
|
|
|
|
var versionIndex = -1;
|
|
|
|
$.each($("#editserver-versionselect")[0], function (key, val) {
|
|
|
|
if (val.text === value["version"]) {
|
|
|
|
versionIndex = key;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#editserver-versionselect")[0].selectedIndex = versionIndex;
|
2021-09-18 17:47:20 +00:00
|
|
|
}
|
2022-07-26 14:48:33 +00:00
|
|
|
});
|
2021-09-18 17:47:20 +00:00
|
|
|
});
|
|
|
|
|
2022-07-26 14:48:33 +00:00
|
|
|
$("#of-deleteservermodal").on("show.bs.modal", function (e) {
|
2023-09-03 09:56:24 +00:00
|
|
|
var result = serverArray.filter(function (obj) {
|
2022-07-26 14:48:33 +00:00
|
|
|
return obj.uuid === getSelectedServer();
|
|
|
|
})[0];
|
|
|
|
$("#deleteserver-servername").html(result.description);
|
2021-05-17 02:00:27 +00:00
|
|
|
});
|