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");
|
2023-09-19 12:29:56 +00:00
|
|
|
var path = remote.require("path");
|
2023-10-15 19:40:44 +00:00
|
|
|
var dialog = remote.require("dialog");
|
2023-10-18 10:01:25 +00:00
|
|
|
var net = remote.require("net");
|
2023-10-15 19:40:44 +00:00
|
|
|
var spawn = require("child_process").spawn;
|
2023-09-19 12:29:56 +00:00
|
|
|
|
|
|
|
var userData = remote.require("app").getPath("userData");
|
|
|
|
var configPath = path.join(userData, "config.json");
|
|
|
|
var serversPath = path.join(userData, "servers.json");
|
|
|
|
var versionsPath = path.join(userData, "versions.json");
|
2024-07-15 01:54:29 +00:00
|
|
|
var cacheRoot = path.join(userData, "/../../LocalLow/Unity/Web Player/Cache");
|
2024-10-06 01:59:13 +00:00
|
|
|
var offlineRootDefault = path.join(cacheRoot, "../OfflineCache");
|
2023-11-12 21:15:45 +00:00
|
|
|
var offlineRoot = offlineRootDefault;
|
2021-05-17 02:00:27 +00:00
|
|
|
|
2023-10-22 20:10:10 +00:00
|
|
|
var cdnString = "http://cdn.dexlabs.systems/ff/big";
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
var versionArray;
|
|
|
|
var serverArray;
|
2023-10-21 21:30:35 +00:00
|
|
|
var cacheSizes;
|
2023-10-22 20:10:10 +00:00
|
|
|
var defaultHashes;
|
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-10-22 20:10:10 +00:00
|
|
|
function enableVersionAddButton() {
|
|
|
|
$("#of-addversion-button").removeClass("disabled");
|
|
|
|
$("#of-addversion-button").prop("disabled", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableVersionListButtons() {
|
|
|
|
$("#of-editversion-button").removeClass("disabled");
|
|
|
|
$("#of-editversion-button").prop("disabled", false);
|
|
|
|
$("#of-deleteversion-button").removeClass("disabled");
|
|
|
|
$("#of-deleteversion-button").prop("disabled", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableVersionAddButton() {
|
|
|
|
$("#of-addversion-button").addClass("disabled");
|
|
|
|
$("#of-addversion-button").prop("disabled", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableVersionListButtons() {
|
|
|
|
$("#of-editversion-button").addClass("disabled");
|
|
|
|
$("#of-editversion-button").prop("disabled", true);
|
|
|
|
$("#of-deleteversion-button").addClass("disabled");
|
|
|
|
$("#of-deleteversion-button").prop("disabled", true);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-09-19 13:51:19 +00:00
|
|
|
// Simplify version, ex. 1.4.0 -> 1.4,
|
2023-02-09 18:52:57 +00:00
|
|
|
// 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());
|
2023-02-09 11:32:21 +00:00
|
|
|
}
|
|
|
|
|
2024-10-06 10:35:06 +00:00
|
|
|
function checkForNewAppVersion() {
|
|
|
|
$("#of-about-button").removeClass("pulsing");
|
|
|
|
setAppVersionText();
|
|
|
|
if (config["autoupdate-check"] === true) {
|
|
|
|
$.getJSON(
|
|
|
|
"https://api.github.com/repos/OpenFusionProject/OpenFusionClient/releases/latest",
|
|
|
|
{},
|
|
|
|
function (data) {
|
|
|
|
$.each(data, function (index, element) {
|
|
|
|
if (index === "tag_name" && element > getAppVersion()) {
|
|
|
|
console.log("New version available: " + element);
|
|
|
|
var downloadPage =
|
|
|
|
"https://github.com/OpenFusionProject/OpenFusionClient/releases/latest";
|
|
|
|
$("#of-aboutversionnumber").html(
|
|
|
|
"Version " +
|
|
|
|
getAppVersion() +
|
|
|
|
`<br>A new version is available! ` +
|
|
|
|
`Click <a href="#" onclick='remote.require("shell").openExternal("` +
|
|
|
|
downloadPage +
|
|
|
|
`");'>here</a> to download.`
|
|
|
|
);
|
|
|
|
$("#of-about-button").addClass("pulsing");
|
|
|
|
return false; // break out of loop early
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-11 20:52:23 +00:00
|
|
|
function validateServerSave(modalName) {
|
|
|
|
// works everytime a key is entered into the server save form
|
|
|
|
var descInput = document.getElementById(modalName + "server-descinput");
|
|
|
|
var ipInput = document.getElementById(modalName + "server-ipinput");
|
|
|
|
var button = document.getElementById(modalName + "server-savebutton");
|
|
|
|
var valid = true;
|
|
|
|
|
|
|
|
descInput.classList.remove("invalidinput");
|
|
|
|
ipInput.classList.remove("invalidinput");
|
|
|
|
|
|
|
|
if (
|
2024-07-15 01:54:29 +00:00
|
|
|
descInput.value.length <
|
|
|
|
parseInt(descInput.getAttribute("minlength")) ||
|
2023-11-11 20:52:23 +00:00
|
|
|
descInput.value.length > parseInt(descInput.getAttribute("maxlength"))
|
|
|
|
) {
|
|
|
|
descInput.classList.add("invalidinput");
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
2024-07-15 01:54:29 +00:00
|
|
|
if (!new RegExp(ipInput.getAttribute("pattern")).test(ipInput.value)) {
|
2023-11-11 20:52:23 +00:00
|
|
|
ipInput.classList.add("invalidinput");
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
button.removeAttribute("disabled");
|
|
|
|
} else {
|
|
|
|
button.setAttribute("disabled", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 02:00:27 +00:00
|
|
|
function addServer() {
|
2023-10-18 17:47:41 +00:00
|
|
|
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath));
|
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
|
|
|
|
2023-09-19 12:29:56 +00:00
|
|
|
remotefs.writeFileSync(serversPath, 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-10-18 17:47:41 +00:00
|
|
|
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath));
|
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
|
|
|
|
2023-09-19 12:29:56 +00:00
|
|
|
remotefs.writeFileSync(serversPath, 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-10-18 17:47:41 +00:00
|
|
|
var jsonToModify = JSON.parse(remotefs.readFileSync(serversPath));
|
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
|
|
|
|
2023-09-19 12:29:56 +00:00
|
|
|
remotefs.writeFileSync(serversPath, 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(
|
2023-09-19 12:29:56 +00:00
|
|
|
path.join(__dirname, "/defaults/servers.json"),
|
|
|
|
serversPath
|
2022-07-26 14:48:33 +00:00
|
|
|
);
|
|
|
|
loadServerList();
|
2021-09-19 00:28:57 +00:00
|
|
|
}
|
|
|
|
|
2023-11-11 20:52:23 +00:00
|
|
|
function validateVersionSave(modalName) {
|
2023-11-12 12:00:11 +00:00
|
|
|
// works everytime a key is entered into the version save form
|
2023-11-11 20:52:23 +00:00
|
|
|
var nameInput = document.getElementById(modalName + "version-nameinput");
|
|
|
|
var urlInput = document.getElementById(modalName + "version-urlinput");
|
|
|
|
var button = document.getElementById(modalName + "version-savebutton");
|
|
|
|
var valid = true;
|
|
|
|
|
|
|
|
nameInput.classList.remove("invalidinput");
|
|
|
|
urlInput.classList.remove("invalidinput");
|
|
|
|
|
2023-11-12 12:00:11 +00:00
|
|
|
var matchingVersions = versionArray.filter(function (obj) {
|
|
|
|
return obj.name === nameInput.value;
|
|
|
|
});
|
2024-07-15 01:54:29 +00:00
|
|
|
var allowedMatches = modalName === "edit" ? 1 : 0;
|
2023-11-12 12:00:11 +00:00
|
|
|
|
2023-11-11 20:52:23 +00:00
|
|
|
if (
|
2023-11-12 12:00:11 +00:00
|
|
|
matchingVersions.length > allowedMatches ||
|
2024-07-15 01:54:29 +00:00
|
|
|
!new RegExp(nameInput.getAttribute("pattern")).test(nameInput.value)
|
2023-11-11 20:52:23 +00:00
|
|
|
) {
|
|
|
|
nameInput.classList.add("invalidinput");
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
2024-07-15 01:54:29 +00:00
|
|
|
if (!new RegExp(urlInput.getAttribute("pattern")).test(urlInput.value)) {
|
2023-11-11 20:52:23 +00:00
|
|
|
urlInput.classList.add("invalidinput");
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
button.removeAttribute("disabled");
|
|
|
|
} else {
|
|
|
|
button.setAttribute("disabled", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-22 20:10:10 +00:00
|
|
|
function addVersion() {
|
|
|
|
var jsonToModify = JSON.parse(remotefs.readFileSync(versionsPath));
|
|
|
|
|
|
|
|
var version = {};
|
|
|
|
version["name"] =
|
|
|
|
$("#addversion-nameinput").val().length == 0
|
|
|
|
? "custom-build-" + uuidv4().substring(0, 8)
|
|
|
|
: $("#addversion-nameinput").val();
|
|
|
|
version["url"] =
|
|
|
|
$("#addversion-urlinput").val().length == 0
|
|
|
|
? cdnString + "/" + version["name"] + "/"
|
|
|
|
: $("#addversion-urlinput").val();
|
|
|
|
|
|
|
|
var matchingVersions = jsonToModify["versions"].filter(function (obj) {
|
|
|
|
return obj.name === version["name"];
|
|
|
|
});
|
|
|
|
|
|
|
|
if (matchingVersions.length > 0) return;
|
|
|
|
|
2023-11-11 20:52:23 +00:00
|
|
|
jsonToModify["versions"].unshift(version);
|
2023-10-22 20:10:10 +00:00
|
|
|
|
|
|
|
remotefs.writeFileSync(versionsPath, JSON.stringify(jsonToModify, null, 4));
|
|
|
|
loadCacheList();
|
2023-11-11 20:52:23 +00:00
|
|
|
handleCache("hash-check", version["name"]);
|
2023-10-22 20:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function editVersion() {
|
|
|
|
var jsonToModify = JSON.parse(remotefs.readFileSync(versionsPath));
|
2023-11-11 20:52:23 +00:00
|
|
|
var editedVersionString = null;
|
2023-10-22 20:10:10 +00:00
|
|
|
|
|
|
|
$.each(jsonToModify["versions"], function (key, value) {
|
2024-07-15 01:54:29 +00:00
|
|
|
if (
|
|
|
|
value["name"] == getSelectedVersion() &&
|
|
|
|
!defaultHashes.hasOwnProperty(value["name"])
|
|
|
|
) {
|
2023-10-22 20:10:10 +00:00
|
|
|
value["name"] =
|
|
|
|
$("#editversion-nameinput").val().length == 0
|
|
|
|
? value["name"]
|
|
|
|
: $("#editversion-nameinput").val();
|
|
|
|
value["url"] =
|
|
|
|
$("#editversion-urlinput").val().length == 0
|
|
|
|
? value["url"]
|
|
|
|
: $("#editversion-urlinput").val();
|
2023-11-11 20:52:23 +00:00
|
|
|
editedVersionString = value["name"];
|
2023-10-22 20:10:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-11-11 20:52:23 +00:00
|
|
|
if (!editedVersionString) return;
|
2023-10-22 20:10:10 +00:00
|
|
|
|
|
|
|
remotefs.writeFileSync(versionsPath, JSON.stringify(jsonToModify, null, 4));
|
|
|
|
loadCacheList();
|
2023-11-11 20:52:23 +00:00
|
|
|
handleCache("hash-check", editedVersionString);
|
2023-10-22 20:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteVersion() {
|
|
|
|
var jsonToModify = JSON.parse(remotefs.readFileSync(versionsPath));
|
|
|
|
|
|
|
|
var result = jsonToModify["versions"].filter(function (obj) {
|
|
|
|
return obj.name === getSelectedVersion();
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
if (defaultHashes.hasOwnProperty(result.name)) return;
|
|
|
|
|
|
|
|
var resultindex = jsonToModify["versions"].indexOf(result);
|
|
|
|
|
|
|
|
jsonToModify["versions"].splice(resultindex, 1);
|
|
|
|
|
|
|
|
remotefs.writeFileSync(versionsPath, JSON.stringify(jsonToModify, null, 4));
|
|
|
|
loadCacheList();
|
2023-11-11 20:52:23 +00:00
|
|
|
delete cacheSizes[result.name];
|
2023-10-22 20:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function restoreDefaultVersions() {
|
|
|
|
remotefs.copySync(
|
|
|
|
path.join(__dirname, "/defaults/versions.json"),
|
|
|
|
versionsPath
|
|
|
|
);
|
|
|
|
loadCacheList();
|
2023-11-11 20:52:23 +00:00
|
|
|
handleCache("hash-check");
|
2023-10-22 20:10:10 +00:00
|
|
|
}
|
|
|
|
|
2023-11-12 21:15:45 +00:00
|
|
|
function editConfig() {
|
2023-11-13 20:06:38 +00:00
|
|
|
var jsonToModify = JSON.parse(remotefs.readFileSync(configPath));
|
2023-11-12 21:15:45 +00:00
|
|
|
|
2024-07-15 01:54:29 +00:00
|
|
|
jsonToModify["autoupdate-check"] = $("#editconfig-autoupdate").prop(
|
|
|
|
"checked"
|
|
|
|
);
|
|
|
|
jsonToModify["cache-swapping"] = $("#editconfig-cacheswapping").prop(
|
|
|
|
"checked"
|
|
|
|
);
|
|
|
|
jsonToModify["enable-offline-cache"] = $(
|
|
|
|
"#editconfig-enableofflinecache"
|
|
|
|
).prop("checked");
|
|
|
|
jsonToModify["verify-offline-cache"] = $(
|
|
|
|
"#editconfig-verifyofflinecache"
|
|
|
|
).prop("checked");
|
2023-11-12 21:15:45 +00:00
|
|
|
|
|
|
|
var dirInput = $("#editconfig-offlinecachelocation:text").val();
|
2024-07-15 01:54:29 +00:00
|
|
|
var shouldChangeRoot =
|
2023-11-12 21:15:45 +00:00
|
|
|
remotefs.existsSync(dirInput) &&
|
2024-07-15 01:54:29 +00:00
|
|
|
remotefs.statSync(dirInput).isDirectory();
|
2023-11-13 17:05:02 +00:00
|
|
|
|
2024-07-15 01:54:29 +00:00
|
|
|
jsonToModify["offline-cache-location"] = shouldChangeRoot
|
|
|
|
? dirInput
|
|
|
|
: offlineRoot;
|
2023-11-12 21:15:45 +00:00
|
|
|
|
|
|
|
remotefs.writeFileSync(configPath, JSON.stringify(jsonToModify, null, 4));
|
2023-11-12 22:46:23 +00:00
|
|
|
|
2023-11-12 21:15:45 +00:00
|
|
|
loadConfig();
|
2023-11-17 22:21:31 +00:00
|
|
|
// check all offline caches if the offline root changes
|
2023-11-13 20:06:38 +00:00
|
|
|
if (shouldChangeRoot) handleCache("hash-check", null, "offline");
|
2023-11-12 21:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateCacheLocation() {
|
|
|
|
var input = document.getElementById("editconfig-offlinecachelocation");
|
|
|
|
var button = document.getElementById("editconfig-savebutton");
|
2024-10-06 01:59:13 +00:00
|
|
|
var parent = path.join(input.value, "/..");
|
2023-11-12 21:15:45 +00:00
|
|
|
|
|
|
|
input.classList.remove("invalidinput");
|
|
|
|
button.removeAttribute("disabled");
|
|
|
|
|
2024-10-06 01:59:13 +00:00
|
|
|
// Parent MUST exist and be a directory
|
|
|
|
// If the target exists, check that is also a directory
|
|
|
|
// Also, prevent putting the offline cache inside of
|
|
|
|
// the normal cache folder to prevent shenanigans
|
2024-07-15 01:54:29 +00:00
|
|
|
if (
|
2024-10-06 01:59:13 +00:00
|
|
|
!remotefs.existsSync(parent) ||
|
|
|
|
!remotefs.statSync(parent).isDirectory() ||
|
|
|
|
(remotefs.existsSync(input.value) &&
|
|
|
|
!remotefs.statSync(input.value).isDirectory()) ||
|
|
|
|
path.join(input.value, ".") === path.join(cacheRoot, "/..") ||
|
|
|
|
path.join(input.value, ".").startsWith(path.join(cacheRoot))
|
2024-07-15 01:54:29 +00:00
|
|
|
) {
|
2023-11-12 21:15:45 +00:00
|
|
|
input.classList.add("invalidinput");
|
|
|
|
button.setAttribute("disabled", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 02:00:27 +00:00
|
|
|
function loadGameVersions() {
|
2023-09-19 13:51:19 +00:00
|
|
|
var versionJson = remotefs.readJsonSync(versionsPath);
|
2023-09-03 09:56:24 +00:00
|
|
|
versionArray = versionJson["versions"];
|
2023-11-17 21:47:23 +00:00
|
|
|
|
|
|
|
$("#addserver-versionselect").empty();
|
|
|
|
$("#editserver-versionselect").empty();
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
$.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() {
|
2023-09-19 13:51:19 +00:00
|
|
|
// Load config object globally
|
|
|
|
config = remotefs.readJsonSync(configPath);
|
2023-11-12 21:15:45 +00:00
|
|
|
|
|
|
|
$("#editconfig-autoupdate").prop("checked", config["autoupdate-check"]);
|
|
|
|
$("#editconfig-cacheswapping").prop("checked", config["cache-swapping"]);
|
2024-07-15 01:54:29 +00:00
|
|
|
$("#editconfig-enableofflinecache").prop(
|
|
|
|
"checked",
|
|
|
|
config["enable-offline-cache"]
|
|
|
|
);
|
|
|
|
$("#editconfig-verifyofflinecache").prop(
|
|
|
|
"checked",
|
|
|
|
config["verify-offline-cache"]
|
|
|
|
);
|
2023-11-12 21:15:45 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// alter offline root globally
|
2023-11-12 21:15:45 +00:00
|
|
|
offlineRoot = config["offline-cache-location"] || offlineRootDefault;
|
|
|
|
$("#editconfig-offlinecachelocation:text").val(offlineRoot);
|
|
|
|
|
2024-10-06 10:35:06 +00:00
|
|
|
checkForNewAppVersion();
|
2023-11-12 21:15:45 +00:00
|
|
|
validateCacheLocation();
|
2021-09-18 22:21:41 +00:00
|
|
|
}
|
2021-05-17 02:00:27 +00:00
|
|
|
|
|
|
|
function loadServerList() {
|
2023-09-19 13:51:19 +00:00
|
|
|
var serverJson = remotefs.readJsonSync(serversPath);
|
2023-09-03 09:56:24 +00:00
|
|
|
serverArray = serverJson["servers"];
|
2022-07-26 14:48:33 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
deselectServer(); // Remove selection and disable buttons until another server is selected
|
2022-07-26 14:48:33 +00:00
|
|
|
$(".server-listing-entry").remove(); // Clear out old stuff, if any
|
|
|
|
|
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-10-22 20:10:10 +00:00
|
|
|
function loadCacheList() {
|
2023-11-17 21:47:23 +00:00
|
|
|
// we might want to use a new version right away, so reload them
|
|
|
|
loadGameVersions();
|
2023-10-22 20:10:10 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// load default hashes.json for reference while running the cache handler
|
2023-10-22 20:10:10 +00:00
|
|
|
if (!defaultHashes) {
|
2024-07-15 01:54:29 +00:00
|
|
|
defaultHashes = remotefs.readJsonSync(
|
|
|
|
path.join(__dirname, "/defaults/hashes.json")
|
|
|
|
);
|
2023-10-22 20:10:10 +00:00
|
|
|
}
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
deselectVersion(); // Remove selection and disable buttons until another server is selected
|
|
|
|
$(".cache-listing-entry").remove(); // Clear out old stuff, if any
|
2023-10-22 20:10:10 +00:00
|
|
|
|
|
|
|
$.each(versionArray, function (key, value) {
|
|
|
|
var row = document.createElement("tr");
|
2024-07-15 01:54:29 +00:00
|
|
|
row.className = "cache-listing-entry";
|
2023-10-22 20:10:10 +00:00
|
|
|
row.setAttribute("id", value.name);
|
|
|
|
|
|
|
|
var cellVersion = document.createElement("td");
|
|
|
|
cellVersion.textContent = value.name;
|
|
|
|
cellVersion.className = "text-monospace";
|
|
|
|
|
|
|
|
var cellPlayableCache = getCacheInfoCell(value.name, "playable");
|
|
|
|
var cellOfflineCache = getCacheInfoCell(value.name, "offline");
|
|
|
|
|
|
|
|
row.appendChild(cellVersion);
|
|
|
|
row.appendChild(cellPlayableCache);
|
|
|
|
row.appendChild(cellOfflineCache);
|
|
|
|
|
|
|
|
$("#cache-tablebody").append(row);
|
|
|
|
});
|
2023-11-11 20:52:23 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// simulate a cache handler run so that the buttons update properly
|
2023-11-11 20:52:23 +00:00
|
|
|
storageLoadingStart();
|
|
|
|
storageLoadingUpdate(cacheSizes);
|
|
|
|
storageLoadingComplete(cacheSizes);
|
2023-10-22 20:10:10 +00:00
|
|
|
}
|
|
|
|
|
2023-09-18 21:49:31 +00:00
|
|
|
function getCacheElemID(versionString, cacheMode, elementName) {
|
2024-07-15 01:54:29 +00:00
|
|
|
return [versionString, cacheMode, "cache", elementName]
|
|
|
|
.filter(function (value) {
|
|
|
|
return typeof value !== "undefined";
|
|
|
|
})
|
|
|
|
.join("-");
|
2023-09-18 21:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCacheButtonID(versionString, cacheMode, buttonMode) {
|
2024-07-15 01:54:29 +00:00
|
|
|
return [
|
|
|
|
getCacheElemID(versionString, cacheMode),
|
|
|
|
buttonMode,
|
|
|
|
"button",
|
|
|
|
].join("-");
|
2023-09-18 21:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCacheLabelText(sizes) {
|
2024-07-15 01:54:29 +00:00
|
|
|
if (!sizes || sizes.total === 0) return "?.?? GB / ?.?? GB";
|
2023-10-22 20:10:10 +00:00
|
|
|
|
2023-09-28 23:46:12 +00:00
|
|
|
var gb = 1 << 30;
|
2024-07-15 01:54:29 +00:00
|
|
|
var labelText =
|
|
|
|
(sizes.intact / gb).toFixed(2) +
|
|
|
|
" / " +
|
|
|
|
(sizes.total / gb).toFixed(2) +
|
|
|
|
" GB";
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
if (sizes.altered > 0) {
|
2024-07-15 01:54:29 +00:00
|
|
|
labelText +=
|
|
|
|
"<br/>(" + (sizes.altered / gb).toFixed(2) + " GB Altered)";
|
2023-09-18 21:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return labelText;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCacheInfoCell(versionString, cacheMode) {
|
|
|
|
var divID = getCacheElemID(versionString, cacheMode, "div");
|
|
|
|
var labelID = getCacheElemID(versionString, cacheMode, "label");
|
|
|
|
|
|
|
|
var settings = {
|
|
|
|
download: {
|
|
|
|
icon: "fas fa-download",
|
|
|
|
class: "btn btn-success mr-1",
|
2024-07-15 01:54:29 +00:00
|
|
|
tooltip: "Download Cache",
|
2023-09-18 21:49:31 +00:00
|
|
|
},
|
|
|
|
fix: {
|
|
|
|
icon: "fas fa-hammer",
|
|
|
|
class: "btn btn-warning mr-1",
|
2024-07-15 01:54:29 +00:00
|
|
|
tooltip: "Fix Altered Files in Cache",
|
2023-09-18 21:49:31 +00:00
|
|
|
},
|
|
|
|
delete: {
|
|
|
|
icon: "fas fa-trash-alt",
|
|
|
|
class: "btn btn-danger mr-1",
|
2024-07-15 01:54:29 +00:00
|
|
|
tooltip: "Delete Cache",
|
|
|
|
},
|
2023-09-18 21:49:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var cellCache = document.createElement("td");
|
|
|
|
var divCacheAll = document.createElement("div");
|
|
|
|
|
|
|
|
var labelCache = document.createElement("label");
|
|
|
|
labelCache.setAttribute("id", labelID);
|
|
|
|
labelCache.setAttribute("for", divID);
|
2023-11-17 22:21:31 +00:00
|
|
|
// pull existing info from cacheSizes when available
|
2023-11-11 20:52:23 +00:00
|
|
|
labelCache.innerHTML = getCacheLabelText(
|
2024-07-15 01:54:29 +00:00
|
|
|
cacheSizes && cacheSizes[versionString]
|
|
|
|
? cacheSizes[versionString][cacheMode]
|
|
|
|
: null
|
2023-11-11 20:52:23 +00:00
|
|
|
);
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
var divCacheButtons = document.createElement("div");
|
|
|
|
divCacheButtons.setAttribute("id", labelID);
|
|
|
|
|
|
|
|
$.each(settings, function (buttonMode, config) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// only delete allowed for playable game caches
|
2023-09-18 21:49:31 +00:00
|
|
|
if (cacheMode === "playable" && buttonMode !== "delete") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var buttonID = getCacheButtonID(versionString, cacheMode, buttonMode);
|
|
|
|
|
|
|
|
var iconItalic = document.createElement("i");
|
|
|
|
iconItalic.setAttribute("class", config.icon);
|
|
|
|
|
|
|
|
var buttonCache = document.createElement("button");
|
|
|
|
buttonCache.setAttribute("id", buttonID);
|
|
|
|
buttonCache.setAttribute("class", config.class);
|
|
|
|
buttonCache.setAttribute("title", config.tooltip);
|
|
|
|
buttonCache.setAttribute("type", "button");
|
2023-11-17 22:21:31 +00:00
|
|
|
// handler setup
|
2024-07-15 01:54:29 +00:00
|
|
|
buttonCache.setAttribute(
|
|
|
|
"onclick",
|
|
|
|
'handleCache("' +
|
|
|
|
buttonMode +
|
|
|
|
'", "' +
|
|
|
|
versionString +
|
|
|
|
'", "' +
|
|
|
|
cacheMode +
|
|
|
|
'");'
|
|
|
|
);
|
2023-09-18 21:49:31 +00:00
|
|
|
buttonCache.appendChild(iconItalic);
|
|
|
|
|
|
|
|
divCacheButtons.appendChild(buttonCache);
|
|
|
|
});
|
|
|
|
|
|
|
|
divCacheAll.appendChild(labelCache);
|
|
|
|
divCacheAll.appendChild(divCacheButtons);
|
|
|
|
cellCache.appendChild(divCacheAll);
|
|
|
|
|
|
|
|
return cellCache;
|
|
|
|
}
|
|
|
|
|
2023-10-15 19:40:44 +00:00
|
|
|
function storageLoadingStart(vString, cMode) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// determine which cache versions and modes to visually update
|
2023-10-15 19:40:44 +00:00
|
|
|
var versionStrings = [];
|
|
|
|
$.each(versionArray, function (key, value) {
|
|
|
|
if (vString) {
|
2024-07-15 01:54:29 +00:00
|
|
|
if (vString === value.name) versionStrings.push(value.name);
|
2023-10-15 19:40:44 +00:00
|
|
|
} else {
|
|
|
|
versionStrings.push(value.name);
|
|
|
|
}
|
|
|
|
});
|
2024-07-15 01:54:29 +00:00
|
|
|
var cacheModes = cMode ? [cMode] : ["offline", "playable"];
|
2023-10-15 19:40:44 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// deselect and disable the add version button until they are re-enabled
|
2023-10-22 20:10:10 +00:00
|
|
|
deselectVersion();
|
|
|
|
disableVersionAddButton();
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// turn buttons into spinners
|
2023-10-15 19:40:44 +00:00
|
|
|
$.each(versionStrings, function (vKey, versionString) {
|
|
|
|
$.each(cacheModes, function (cKey, cacheMode) {
|
2024-07-15 01:54:29 +00:00
|
|
|
var buttonDelete = document.getElementById(
|
|
|
|
getCacheButtonID(versionString, cacheMode, "delete")
|
|
|
|
);
|
|
|
|
var buttonDownload = document.getElementById(
|
|
|
|
getCacheButtonID(versionString, cacheMode, "download")
|
|
|
|
);
|
|
|
|
var buttonFix = document.getElementById(
|
|
|
|
getCacheButtonID(versionString, cacheMode, "fix")
|
|
|
|
);
|
2023-10-15 19:40:44 +00:00
|
|
|
|
|
|
|
if (!buttonDelete) return;
|
|
|
|
|
|
|
|
buttonDelete.setAttribute("disabled", "");
|
2024-07-15 01:54:29 +00:00
|
|
|
buttonDelete.children[0].setAttribute(
|
|
|
|
"class",
|
|
|
|
"fas fa-spinner fa-spin fa-fw"
|
|
|
|
);
|
2023-10-15 19:40:44 +00:00
|
|
|
|
|
|
|
if (cacheMode === "offline") {
|
|
|
|
buttonDownload.setAttribute("disabled", "");
|
2024-07-15 01:54:29 +00:00
|
|
|
buttonDownload.children[0].setAttribute(
|
|
|
|
"class",
|
|
|
|
"fas fa-spinner fa-spin fa-fw"
|
|
|
|
);
|
2023-10-15 19:40:44 +00:00
|
|
|
|
|
|
|
buttonFix.setAttribute("disabled", "");
|
2024-07-15 01:54:29 +00:00
|
|
|
buttonFix.children[0].setAttribute(
|
|
|
|
"class",
|
|
|
|
"fas fa-spinner fa-spin fa-fw"
|
|
|
|
);
|
2023-10-15 19:40:44 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function storageLoadingUpdate(allSizes) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// update cacheSizes and display results
|
2023-10-15 19:40:44 +00:00
|
|
|
$.each(allSizes, function (versionString, vSizes) {
|
|
|
|
$.each(vSizes, function (cacheMode, sizes) {
|
2024-07-15 01:54:29 +00:00
|
|
|
var label = document.getElementById(
|
|
|
|
getCacheElemID(versionString, cacheMode, "label")
|
|
|
|
);
|
2023-10-21 21:30:35 +00:00
|
|
|
|
|
|
|
cacheSizes = cacheSizes || {};
|
|
|
|
cacheSizes[versionString] = cacheSizes[versionString] || {};
|
|
|
|
cacheSizes[versionString][cacheMode] = sizes || {};
|
|
|
|
|
2023-10-21 19:31:46 +00:00
|
|
|
if (!label) return;
|
2023-10-21 21:30:35 +00:00
|
|
|
|
2023-10-21 19:31:46 +00:00
|
|
|
label.innerHTML = getCacheLabelText(sizes);
|
2023-10-15 19:40:44 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function storageLoadingComplete(allSizes) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// re-enable buttons according to the sizes that were read
|
2023-10-15 19:40:44 +00:00
|
|
|
$.each(allSizes, function (versionString, vSizes) {
|
|
|
|
$.each(vSizes, function (cacheMode, sizes) {
|
2024-07-15 01:54:29 +00:00
|
|
|
var buttonDelete = document.getElementById(
|
|
|
|
getCacheButtonID(versionString, cacheMode, "delete")
|
|
|
|
);
|
|
|
|
var buttonDownload = document.getElementById(
|
|
|
|
getCacheButtonID(versionString, cacheMode, "download")
|
|
|
|
);
|
|
|
|
var buttonFix = document.getElementById(
|
|
|
|
getCacheButtonID(versionString, cacheMode, "fix")
|
|
|
|
);
|
2023-10-15 19:40:44 +00:00
|
|
|
|
|
|
|
if (!buttonDelete) return;
|
|
|
|
|
|
|
|
buttonDelete.children[0].setAttribute("class", "fas fa-trash-alt");
|
|
|
|
|
|
|
|
if (cacheMode === "offline") {
|
2024-07-15 01:54:29 +00:00
|
|
|
buttonDownload.children[0].setAttribute(
|
|
|
|
"class",
|
|
|
|
"fas fa-download"
|
|
|
|
);
|
2023-10-15 19:40:44 +00:00
|
|
|
buttonFix.children[0].setAttribute("class", "fas fa-hammer");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sizes.intact > 0 || sizes.altered > 0) {
|
|
|
|
buttonDelete.removeAttribute("disabled");
|
|
|
|
|
|
|
|
if (cacheMode === "offline") {
|
|
|
|
buttonDownload.setAttribute("disabled", "");
|
|
|
|
|
|
|
|
if (sizes.altered > 0 || sizes.intact < sizes.total) {
|
|
|
|
buttonFix.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
buttonDelete.setAttribute("disabled", "");
|
|
|
|
|
|
|
|
if (cacheMode === "offline") {
|
|
|
|
buttonDownload.removeAttribute("disabled");
|
|
|
|
buttonFix.setAttribute("disabled", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-10-22 20:10:10 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// finally, re-enable the version add button
|
2023-10-22 20:10:10 +00:00
|
|
|
enableVersionAddButton();
|
2023-10-15 19:40:44 +00:00
|
|
|
}
|
|
|
|
|
2023-10-29 13:41:07 +00:00
|
|
|
function handleCache(operation, versionString, cacheMode, callback) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// see if any versions match (could be undefined or null)
|
2023-10-15 19:40:44 +00:00
|
|
|
var versions = versionArray.filter(function (obj) {
|
|
|
|
return obj.name === versionString;
|
|
|
|
});
|
2023-11-17 22:21:31 +00:00
|
|
|
// pull version url from the found object, if none found, use the default cdn link
|
2024-07-15 01:54:29 +00:00
|
|
|
var cdnRoot = versions.length === 0 ? cdnString : versions[0].url;
|
2023-10-15 19:40:44 +00:00
|
|
|
|
2023-10-21 19:31:46 +00:00
|
|
|
var lastSizes = { intact: 0, altered: 0, total: 0 };
|
2023-10-18 12:39:44 +00:00
|
|
|
var buf = "";
|
2023-10-15 19:40:44 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// start loading on the given version and mode (could be undefined or null, which means 'all')
|
2023-10-15 19:40:44 +00:00
|
|
|
storageLoadingStart(versionString, cacheMode);
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// create the server and socket listener
|
2023-10-18 10:01:25 +00:00
|
|
|
var server = net.createServer(function (sock) {
|
|
|
|
sock.setEncoding("utf8");
|
2023-10-15 19:40:44 +00:00
|
|
|
|
2023-10-18 10:01:25 +00:00
|
|
|
sock.on("data", function (data) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// read data until the next \n, and keep reading
|
|
|
|
// sometimes the updates are buffered, so there might be multiple objects
|
|
|
|
// per update, and partial objects as well
|
|
|
|
// buffer parsing allows us to handle these cases
|
2023-10-18 12:39:44 +00:00
|
|
|
buf += data;
|
2023-10-18 10:01:25 +00:00
|
|
|
|
2023-10-18 12:39:44 +00:00
|
|
|
var end = buf.indexOf("\n");
|
|
|
|
|
|
|
|
while (end > 0) {
|
|
|
|
var sub = buf.substring(0, end);
|
|
|
|
buf = buf.substring(end + 1);
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// run a storage update here
|
2023-10-18 12:39:44 +00:00
|
|
|
lastSizes = JSON.parse(sub);
|
2023-10-18 10:01:25 +00:00
|
|
|
storageLoadingUpdate(lastSizes);
|
2023-10-18 12:39:44 +00:00
|
|
|
|
|
|
|
end = buf.indexOf("\n");
|
|
|
|
}
|
2023-10-18 10:01:25 +00:00
|
|
|
});
|
2023-10-15 19:40:44 +00:00
|
|
|
});
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// start listening on a randomly acquired port, and spawn cache handler when ready
|
2023-10-18 10:01:25 +00:00
|
|
|
server.listen(0, "localhost", function () {
|
2023-10-22 20:10:10 +00:00
|
|
|
spawn(
|
|
|
|
path.join(__dirname, "lib", "cache_handler.exe"),
|
|
|
|
[
|
2024-07-15 01:54:29 +00:00
|
|
|
"--operation",
|
|
|
|
operation,
|
2023-11-11 20:52:23 +00:00
|
|
|
// roots below contain version-agnostic main directories for caches
|
2024-07-15 01:54:29 +00:00
|
|
|
"--playable-root",
|
|
|
|
cacheRoot,
|
|
|
|
"--offline-root",
|
|
|
|
offlineRoot,
|
|
|
|
"--user-dir",
|
|
|
|
userData,
|
2023-11-11 20:52:23 +00:00
|
|
|
// CDN root contains version-specific directory, unless cacheMode is "all"
|
2024-07-15 01:54:29 +00:00
|
|
|
"--cdn-root",
|
|
|
|
cdnRoot,
|
|
|
|
"--cache-mode",
|
|
|
|
cacheMode || "all",
|
|
|
|
"--cache-version",
|
|
|
|
versionString || "all",
|
2023-11-17 22:21:31 +00:00
|
|
|
// learn port from the server object and tell the script where to connect
|
2024-07-15 01:54:29 +00:00
|
|
|
"--port",
|
|
|
|
server.address().port,
|
2023-11-17 22:21:31 +00:00
|
|
|
// tell the script which versions and caches are official
|
2024-07-15 01:54:29 +00:00
|
|
|
"--official-caches",
|
2023-10-29 13:41:07 +00:00
|
|
|
].concat(Object.keys(defaultHashes)),
|
|
|
|
{
|
2024-07-15 01:54:29 +00:00
|
|
|
stdio: "inherit",
|
2023-10-29 13:41:07 +00:00
|
|
|
}
|
2023-10-22 20:10:10 +00:00
|
|
|
).on("exit", function (code, signal) {
|
2023-10-18 10:01:25 +00:00
|
|
|
if (code !== 0 || signal) {
|
|
|
|
dialog.showErrorBox(
|
|
|
|
"Sorry!",
|
2024-07-15 01:54:29 +00:00
|
|
|
'Process "' +
|
|
|
|
operation +
|
|
|
|
'" failed with code ' +
|
|
|
|
code +
|
|
|
|
" and signal " +
|
|
|
|
signal +
|
|
|
|
"."
|
2023-10-18 10:01:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// when the script exits, close the server
|
2023-10-18 10:01:25 +00:00
|
|
|
server.close();
|
2023-11-17 22:21:31 +00:00
|
|
|
// set button state accordingly
|
2023-10-18 10:01:25 +00:00
|
|
|
storageLoadingComplete(lastSizes);
|
2023-11-17 22:21:31 +00:00
|
|
|
// then run the given callback (if any)
|
|
|
|
if (callback) callback(lastSizes);
|
2023-10-18 10:01:25 +00:00
|
|
|
});
|
2023-09-28 23:46:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
function performCacheSwap(newVersion) {
|
2023-09-19 12:29:56 +00:00
|
|
|
var currentCache = path.join(cacheRoot, "FusionFall");
|
|
|
|
var newCache = path.join(cacheRoot, newVersion);
|
|
|
|
var record = path.join(userData, ".lastver");
|
2023-02-08 20:06:54 +00:00
|
|
|
|
2023-09-19 12:29:56 +00:00
|
|
|
// If cache renaming would result in a no-op (ex. launching the same version
|
2023-09-19 13:51:19 +00:00
|
|
|
// two times), then skip it. This avoids permissions errors with multiple clients
|
2023-02-08 20:06:54 +00:00
|
|
|
// (file/folder is already open in another process)
|
|
|
|
var skip = false;
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
if (remotefs.existsSync(currentCache)) {
|
2023-09-19 13:51:19 +00:00
|
|
|
// Cache already exists, find out what version it belongs to
|
2023-02-08 20:06:54 +00:00
|
|
|
if (remotefs.existsSync(record)) {
|
2024-07-15 01:54:29 +00:00
|
|
|
var lastVersion = remotefs.readFileSync(
|
|
|
|
record,
|
|
|
|
(encoding = "utf8")
|
|
|
|
);
|
2023-09-03 09:56:24 +00:00
|
|
|
if (lastVersion != newVersion) {
|
2023-09-19 12:44:35 +00:00
|
|
|
// Remove the directory we're trying to store the
|
|
|
|
// existing cache to if it already exists for whatever
|
2023-09-19 12:29:56 +00:00
|
|
|
// reason, as it would cause an EPERM error otherwise.
|
|
|
|
// This is a no-op if the directory doesn't exist
|
|
|
|
remotefs.removeSync(path.join(cacheRoot, lastVersion));
|
|
|
|
// Store old cache to named directory
|
2023-02-08 20:06:54 +00:00
|
|
|
remotefs.renameSync(
|
2023-09-03 09:56:24 +00:00
|
|
|
currentCache,
|
2023-09-19 12:29:56 +00:00
|
|
|
path.join(cacheRoot, lastVersion)
|
2023-02-08 20:06:54 +00:00
|
|
|
);
|
|
|
|
} else {
|
2023-09-19 12:29:56 +00:00
|
|
|
console.log("Cached version unchanged, skipping rename");
|
2023-02-08 20:06:54 +00:00
|
|
|
skip = true;
|
|
|
|
}
|
2023-09-03 09:56:24 +00:00
|
|
|
console.log("Current cache is " + lastVersion);
|
2023-02-08 20:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-27 10:01:22 +00:00
|
|
|
// Make note of what version we are launching for next launch
|
|
|
|
remotefs.writeFileSync(record, newVersion);
|
2023-10-01 10:49:59 +00:00
|
|
|
|
2023-09-19 12:29:56 +00:00
|
|
|
if (remotefs.existsSync(newCache) && !skip) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-08 15:37:25 +00:00
|
|
|
function prepGameInfo(serverUUID) {
|
|
|
|
var serverInfo = serverArray.filter(function (obj) {
|
2022-07-26 14:48:33 +00:00
|
|
|
return obj.uuid === serverUUID;
|
|
|
|
})[0];
|
2023-10-08 15:37:25 +00:00
|
|
|
var versionInfo = versionArray.filter(function (obj) {
|
|
|
|
return obj.name === serverInfo.version;
|
2022-07-26 14:48:33 +00:00
|
|
|
})[0];
|
|
|
|
|
2023-09-19 13:51:19 +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-10-08 15:37:25 +00:00
|
|
|
performCacheSwap(versionInfo.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-11-12 21:15:45 +00:00
|
|
|
if (!config["enable-offline-cache"]) {
|
2023-10-21 21:30:35 +00:00
|
|
|
// if we always ignore the offline cache, just use the URL
|
|
|
|
setGameInfo(serverInfo, versionInfo.url);
|
|
|
|
return;
|
|
|
|
}
|
2023-10-15 19:40:44 +00:00
|
|
|
|
2023-10-21 21:30:35 +00:00
|
|
|
var offlinePath = path.join(offlineRoot, versionInfo.name);
|
|
|
|
var offlineURL = "file:///" + offlinePath.replace(/\\/g, "/") + "/";
|
|
|
|
|
|
|
|
if (config["verify-offline-cache"]) {
|
|
|
|
// if required, do a full hash check, and use the offline cache only if it is fully intact
|
2024-07-15 01:54:29 +00:00
|
|
|
handleCache(
|
|
|
|
"hash-check",
|
|
|
|
versionInfo.name,
|
|
|
|
"offline",
|
|
|
|
function (sizes) {
|
|
|
|
var versionURL =
|
|
|
|
sizes.intact < sizes.total ? versionInfo.url : offlineURL;
|
|
|
|
setGameInfo(serverInfo, versionURL);
|
|
|
|
}
|
|
|
|
);
|
2023-10-21 21:30:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// otherwise, if main.unity3d is present, use the offline cache
|
2023-10-21 21:30:35 +00:00
|
|
|
var mainPath = path.join(offlinePath, "main.unity3d");
|
2024-07-15 01:54:29 +00:00
|
|
|
var versionURL = !remotefs.existsSync(mainPath)
|
|
|
|
? versionInfo.url
|
|
|
|
: offlineURL;
|
2023-10-21 21:30:35 +00:00
|
|
|
setGameInfo(serverInfo, versionURL);
|
2023-10-08 15:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// For writing loginInfo.php, assetInfo.php, etc.
|
2023-10-15 19:40:44 +00:00
|
|
|
function setGameInfo(serverInfo, versionURL) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// slash fix if people mess it up via text editors
|
2024-07-15 01:54:29 +00:00
|
|
|
var versionURLRoot = versionURL.endsWith("/")
|
|
|
|
? versionURL
|
|
|
|
: versionURL + "/";
|
2023-11-11 20:52:23 +00:00
|
|
|
window.assetUrl = versionURLRoot; // game-client.js needs to access this
|
|
|
|
console.log("Cache will expand from " + versionURLRoot);
|
2022-07-26 14:48:33 +00:00
|
|
|
|
2023-09-19 12:29:56 +00:00
|
|
|
remotefs.writeFileSync(path.join(__dirname, "assetInfo.php"), assetUrl);
|
2023-10-08 15:37:25 +00:00
|
|
|
if (serverInfo.hasOwnProperty("endpoint")) {
|
|
|
|
var httpEndpoint = serverInfo.endpoint.replace("https://", "http://");
|
2022-07-26 14:48:33 +00:00
|
|
|
remotefs.writeFileSync(
|
2023-09-19 12:29:56 +00:00
|
|
|
path.join(__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(
|
2023-09-19 12:29:56 +00:00
|
|
|
path.join(__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(
|
2023-09-19 12:29:56 +00:00
|
|
|
path.join(__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
|
2023-09-19 12:29:56 +00:00
|
|
|
if (remotefs.existsSync(path.join(__dirname, "rankurl.txt"))) {
|
|
|
|
remotefs.unlinkSync(path.join(__dirname, "rankurl.txt"));
|
2022-07-26 14:48:33 +00:00
|
|
|
remotefs.writeFileSync(
|
2023-09-19 12:29:56 +00:00
|
|
|
path.join(__dirname, "sponsor.php"),
|
2022-07-26 14:48:33 +00:00
|
|
|
"assets/img/welcome.png"
|
|
|
|
);
|
2023-09-19 12:29:56 +00:00
|
|
|
remotefs.writeFileSync(
|
|
|
|
path.join(__dirname, "images.php"),
|
|
|
|
"assets/img/"
|
|
|
|
);
|
2022-07-26 14:48:33 +00:00
|
|
|
}
|
2022-04-28 00:50:23 +00:00
|
|
|
}
|
2022-07-26 14:48:33 +00:00
|
|
|
|
|
|
|
// Server address parsing
|
|
|
|
var address;
|
|
|
|
var port;
|
2023-10-08 15:37:25 +00:00
|
|
|
var sepPos = serverInfo.ip.indexOf(":");
|
2022-07-26 14:48:33 +00:00
|
|
|
if (sepPos > -1) {
|
2023-10-08 15:37:25 +00:00
|
|
|
address = serverInfo.ip.substr(0, sepPos);
|
|
|
|
port = serverInfo.ip.substr(sepPos + 1);
|
2022-04-27 17:44:08 +00:00
|
|
|
} else {
|
2023-10-08 15:37:25 +00:00
|
|
|
address = serverInfo.ip;
|
2022-07-26 14:48:33 +00:00
|
|
|
port = 23000; // default
|
|
|
|
}
|
|
|
|
|
|
|
|
// DNS resolution. there is no synchronous version for some stupid reason
|
2023-10-08 15:37:25 +00:00
|
|
|
if (!address.match(/^[0-9.]+$/)) {
|
2023-09-19 12:29:56 +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);
|
|
|
|
});
|
2023-10-08 15:37:25 +00:00
|
|
|
} else {
|
2022-07-26 14:48:33 +00:00
|
|
|
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);
|
2023-09-19 12:29:56 +00:00
|
|
|
remotefs.writeFileSync(path.join(__dirname, "loginInfo.php"), full);
|
2022-07-26 14:48:33 +00:00
|
|
|
launchGame();
|
2021-05-17 02:00:27 +00:00
|
|
|
}
|
|
|
|
|
2024-10-06 01:59:13 +00:00
|
|
|
function browseOfflineCache() {
|
|
|
|
var browsePath = dialog.showOpenDialog({ properties: ["openDirectory"] });
|
|
|
|
var offlineCacheInput = document.getElementById(
|
|
|
|
"editconfig-offlinecachelocation"
|
|
|
|
);
|
|
|
|
if (browsePath && offlineCacheInput) {
|
|
|
|
offlineCacheInput.value = browsePath;
|
|
|
|
validateCacheLocation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// Returns the name of the version with the selected background color.
|
2023-10-22 20:10:10 +00:00
|
|
|
function getSelectedVersion() {
|
|
|
|
return $("#cache-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", "");
|
2023-10-08 15:37:25 +00:00
|
|
|
prepGameInfo(getSelectedServer());
|
2022-07-26 14:48:33 +00:00
|
|
|
}, 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
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// If applicable, deselect currently selected version.
|
2023-10-22 20:10:10 +00:00
|
|
|
function deselectVersion() {
|
|
|
|
disableVersionListButtons();
|
|
|
|
$(".cache-listing-entry").removeClass("bg-primary");
|
|
|
|
}
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// Select a server
|
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
|
|
|
});
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// Select a version (if allowed)
|
2023-10-22 20:10:10 +00:00
|
|
|
$("#cache-table").on("click", ".cache-listing-entry", function (event) {
|
|
|
|
// wait for the add button to be re-enabled first
|
|
|
|
if ($("#of-addversion-button").prop("disabled")) return;
|
|
|
|
// do not select default builds
|
|
|
|
if (defaultHashes.hasOwnProperty($(this).attr("id"))) return;
|
|
|
|
|
|
|
|
enableVersionListButtons();
|
|
|
|
$(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
|
|
|
});
|
|
|
|
|
2023-11-12 12:00:11 +00:00
|
|
|
$("#of-addservermodal").on("show.bs.modal", function (e) {
|
|
|
|
validateServerSave("add");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#of-addversionmodal").on("show.bs.modal", function (e) {
|
|
|
|
validateVersionSave("add");
|
|
|
|
});
|
|
|
|
|
2022-07-26 14:48:33 +00:00
|
|
|
$("#of-editservermodal").on("show.bs.modal", function (e) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// populate the edit modal with existing values
|
2023-10-22 20:10:10 +00:00
|
|
|
var jsonToModify = remotefs.readJsonSync(serversPath);
|
|
|
|
|
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
|
|
|
});
|
2023-11-12 12:00:11 +00:00
|
|
|
|
|
|
|
validateServerSave("edit");
|
2021-09-18 17:47:20 +00:00
|
|
|
});
|
|
|
|
|
2023-10-22 20:10:10 +00:00
|
|
|
$("#of-editversionmodal").on("show.bs.modal", function (e) {
|
2023-11-17 22:21:31 +00:00
|
|
|
// populate the edit modal with existing values
|
2023-10-22 20:10:10 +00:00
|
|
|
var jsonToModify = remotefs.readJsonSync(versionsPath);
|
|
|
|
|
|
|
|
$.each(jsonToModify["versions"], function (key, value) {
|
|
|
|
if (value["name"] == getSelectedVersion()) {
|
|
|
|
$("#editversion-nameinput")[0].value = value["name"];
|
|
|
|
$("#editversion-urlinput")[0].value = value["url"];
|
|
|
|
}
|
|
|
|
});
|
2023-11-12 12:00:11 +00:00
|
|
|
|
|
|
|
validateVersionSave("edit");
|
2023-10-22 20:10:10 +00:00
|
|
|
});
|
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// Replace server name to delete
|
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
|
|
|
});
|
2023-10-22 20:10:10 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// Replace version name to delete
|
2023-10-22 20:10:10 +00:00
|
|
|
$("#of-deleteversionmodal").on("show.bs.modal", function (e) {
|
|
|
|
var result = versionArray.filter(function (obj) {
|
|
|
|
return obj.name === getSelectedVersion();
|
|
|
|
})[0];
|
|
|
|
$("#deleteversion-versionname").html(result.name);
|
|
|
|
});
|
2023-11-12 13:27:11 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// Run the global hash check once and only if the cache modal is ever shown
|
2023-11-12 13:27:11 +00:00
|
|
|
$("#of-editcacheconfigmodal").on("show.bs.modal", function (e) {
|
|
|
|
if (!cacheSizes) handleCache("hash-check");
|
|
|
|
});
|
2023-11-12 21:15:45 +00:00
|
|
|
|
2023-11-17 22:21:31 +00:00
|
|
|
// Keep all config values synced on modal show
|
|
|
|
// Avoids cases where people forget that they changed the offline root but did not save
|
2023-11-12 21:15:45 +00:00
|
|
|
$("#of-editconfigmodal").on("show.bs.modal", function (e) {
|
|
|
|
loadConfig();
|
|
|
|
});
|