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-09-18 21:49:31 +00:00
|
|
|
var url = remote.require("url");
|
|
|
|
var http = remote.require("http");
|
|
|
|
var createHash = remote.require("crypto").createHash;
|
2023-09-21 15:01:55 +00:00
|
|
|
var async = remote.require("async");
|
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");
|
2023-09-21 15:01:55 +00:00
|
|
|
var hashPath = path.join(userData, "hash.txt");
|
2021-05-17 02:00:27 +00:00
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
var chunkSize = 1 << 16;
|
2023-09-18 21:49:31 +00:00
|
|
|
var gb = 1 << 30;
|
|
|
|
var cdn = "cdn.dexlabs.systems";
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
var versionArray;
|
2023-09-18 21:49:31 +00:00
|
|
|
var versionHashes;
|
2023-09-03 09:56:24 +00:00
|
|
|
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
|
|
|
|
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());
|
|
|
|
$("#of-versionnumber").text("v" + getAppVersion());
|
2023-02-09 11:32:21 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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"];
|
|
|
|
$.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);
|
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
|
|
|
|
|
|
|
$(".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-18 21:49:31 +00:00
|
|
|
function getCacheElemID(versionString, cacheMode, elementName) {
|
|
|
|
return [versionString, cacheMode, "cache", elementName].filter(function (value) {
|
|
|
|
return typeof value !== "undefined";
|
|
|
|
}).join("-");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCacheButtonID(versionString, cacheMode, buttonMode) {
|
|
|
|
return [getCacheElemID(versionString, cacheMode), buttonMode, "button"].join("-");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCacheLabelText(sizes) {
|
|
|
|
var labelText = (sizes.intact / gb).toFixed(2) + " / " + (sizes.total / gb).toFixed(2) + " GB";
|
|
|
|
|
|
|
|
if (sizes.altered > 0) {
|
2023-09-21 15:01:55 +00:00
|
|
|
labelText += "\n(" + (sizes.altered / gb).toFixed(2) + " GB Altered)";
|
2023-09-18 21:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return labelText;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCacheInfoCell(versionString, cacheMode) {
|
|
|
|
var downloadFuncName = "download" + cacheMode.charAt(0).toUpperCase() + cacheMode.slice(1) + "Cache";
|
|
|
|
var deleteFuncName = "delete" + cacheMode.charAt(0).toUpperCase() + cacheMode.slice(1) + "Cache";
|
|
|
|
|
|
|
|
var divID = getCacheElemID(versionString, cacheMode, "div");
|
|
|
|
var labelID = getCacheElemID(versionString, cacheMode, "label");
|
|
|
|
|
|
|
|
var settings = {
|
|
|
|
download: {
|
|
|
|
fn: downloadFuncName,
|
|
|
|
icon: "fas fa-download",
|
|
|
|
class: "btn btn-success mr-1",
|
|
|
|
tooltip: "Download Cache"
|
|
|
|
},
|
|
|
|
fix: {
|
|
|
|
fn: downloadFuncName,
|
|
|
|
icon: "fas fa-hammer",
|
|
|
|
class: "btn btn-warning mr-1",
|
|
|
|
tooltip: "Fix Altered Files in Cache"
|
|
|
|
},
|
|
|
|
delete: {
|
|
|
|
fn: deleteFuncName,
|
|
|
|
icon: "fas fa-trash-alt",
|
|
|
|
class: "btn btn-danger mr-1",
|
|
|
|
tooltip: "Delete Cache"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var cellCache = document.createElement("td");
|
|
|
|
var divCacheAll = document.createElement("div");
|
|
|
|
|
|
|
|
var labelCache = document.createElement("label");
|
|
|
|
labelCache.setAttribute("id", labelID);
|
|
|
|
labelCache.setAttribute("for", divID);
|
|
|
|
|
|
|
|
var divCacheButtons = document.createElement("div");
|
|
|
|
divCacheButtons.setAttribute("id", labelID);
|
|
|
|
|
|
|
|
$.each(settings, function (buttonMode, config) {
|
|
|
|
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");
|
|
|
|
buttonCache.setAttribute("onclick", config.fn + "(\"" + versionString + "\");");
|
|
|
|
buttonCache.appendChild(iconItalic);
|
|
|
|
|
|
|
|
divCacheButtons.appendChild(buttonCache);
|
|
|
|
});
|
|
|
|
|
|
|
|
divCacheAll.appendChild(labelCache);
|
|
|
|
divCacheAll.appendChild(divCacheButtons);
|
|
|
|
cellCache.appendChild(divCacheAll);
|
|
|
|
|
|
|
|
return cellCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFileHash(filePath) {
|
2023-09-21 15:01:55 +00:00
|
|
|
var readCount = 0;
|
|
|
|
var buff = new Buffer(chunkSize);
|
2023-09-18 21:49:31 +00:00
|
|
|
var hash = createHash("sha256");
|
|
|
|
var file = remotefs.openSync(filePath, "r");
|
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
while ((readCount = remotefs.readSync(file, buff, 0, chunkSize, null)) > 0) {
|
2023-09-18 21:49:31 +00:00
|
|
|
hash.update(buff.slice(0, readCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
remotefs.closeSync(file);
|
|
|
|
return hash.digest(encoding="hex");
|
|
|
|
}
|
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
/*
|
2023-09-18 21:49:31 +00:00
|
|
|
function downloadFiles(root, client, sizes, hashes, updateCallback, endCallback) {
|
|
|
|
if (hashes.length === 0) {
|
|
|
|
endCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var filePath = Object.keys(hashes)[0];
|
|
|
|
var fileHash = hashes[filePath];
|
|
|
|
delete hashes[filePath];
|
|
|
|
|
|
|
|
var fullFilePath = path.join(root, filePath);
|
2023-09-21 15:01:55 +00:00
|
|
|
var fullCDNPath = "http://" + [cdn, "ff", "big", filePath].join("/");
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
if (remotefs.existsSync(fullFilePath) && fileHash === getFileHash(fullFilePath)) {
|
|
|
|
console.log(fullFilePath + " is intact, skipping...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadFile(client, fullCDNPath, fullFilePath, function () {
|
|
|
|
var sizeRead = remotefs.statSync(fullFilePath).size;
|
|
|
|
|
|
|
|
if (fileHash === getFileHash(fullFilePath)) {
|
|
|
|
sizes.intact += sizeRead;
|
|
|
|
} else {
|
|
|
|
sizes.altered += sizeRead;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(fullFilePath + " was downloaded from " + fullCDNPath);
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
updateCallback(sizes);
|
|
|
|
downloadFiles(root, client, sizes, hashes, updateCallback, endCallback);
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloadFile(client, fullCDNPath, fullFilePath, callback) {
|
|
|
|
remotefs.ensureDirSync(path.dirname(fullFilePath));
|
|
|
|
|
|
|
|
var urlParts = url.parse(fullCDNPath);
|
|
|
|
var req = client.request("GET", urlParts.path, {
|
2023-09-21 15:01:55 +00:00
|
|
|
"Host": urlParts.hostname,
|
|
|
|
"Content-Type": "application/octet-stream",
|
|
|
|
"Referer": fullCDNPath.split("/").slice(0, 4).join("/") + "/",
|
|
|
|
"Connection": "keep-alive",
|
2023-09-18 21:49:31 +00:00
|
|
|
});
|
|
|
|
var writeStream = remotefs.createWriteStream(fullFilePath);
|
|
|
|
|
|
|
|
var retry = function (err) {
|
|
|
|
writeStream.end();
|
|
|
|
writeStream.destroy();
|
|
|
|
|
|
|
|
remotefs.removeSync(fullFilePath);
|
|
|
|
|
|
|
|
console.log("Error writing file " + fullFilePath + "\n" + err);
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
console.log("Retrying " + fullCDNPath);
|
|
|
|
downloadFile(client, fullCDNPath, fullFilePath, callback);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
writeStream.on("error", retry);
|
|
|
|
|
|
|
|
req.on("response", function (res) {
|
2023-09-21 15:01:55 +00:00
|
|
|
if (res.statusCode >= 300) {
|
2023-09-18 21:49:31 +00:00
|
|
|
console.log("Error in fetching file " + fullFilePath + " from " + fullCDNPath);
|
|
|
|
retry("Status Code: " + res.statusCode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res.pipe(writeStream);
|
|
|
|
|
|
|
|
res.on("end", callback);
|
|
|
|
res.on("error", retry);
|
|
|
|
});
|
|
|
|
|
|
|
|
req.on("error", retry);
|
|
|
|
|
|
|
|
req.end();
|
|
|
|
}
|
2023-09-21 15:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function downloadFile(nginxDir, localDir, relativePath, callback) {
|
|
|
|
var nginxUrl = path.dirname(nginxDir) + "/" + relativePath;
|
|
|
|
var localPath = path.join(localDir, relativePath);
|
|
|
|
|
|
|
|
// Create directories if they don't exist
|
|
|
|
var dirName = path.dirname(localPath);
|
|
|
|
remotefs.ensureDirSync(dirName);
|
|
|
|
|
|
|
|
// HTTP request to download the file
|
|
|
|
var fileStream = remotefs.createWriteStream(localPath);
|
|
|
|
var urlParse = url.parse(nginxUrl);
|
|
|
|
var client = http.createClient(80, urlParse.hostname);
|
|
|
|
var options = {
|
|
|
|
url: urlParse.hostname,
|
|
|
|
port: 80,
|
|
|
|
path: urlParse.path,
|
|
|
|
headers: {
|
|
|
|
"Host": urlParse.hostname,
|
|
|
|
"Content-Type": "application/octet-stream",
|
|
|
|
"Referer": nginxDir,
|
|
|
|
"Connection": "keep-alive",
|
|
|
|
}
|
|
|
|
};
|
2023-09-18 21:49:31 +00:00
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
var request = client.request("GET", urlParse.path, options, function(response) {
|
|
|
|
// Handle errors
|
|
|
|
response.on("error", function(err) {
|
|
|
|
console.error("Error downloading " + relativePath + ": " + err.message);
|
|
|
|
retryDownload(nginxDir, localDir, relativePath, callback); // Retry download
|
|
|
|
});
|
|
|
|
|
|
|
|
response.pipe(fileStream);
|
|
|
|
|
|
|
|
// When the download is complete, invoke the callback
|
|
|
|
response.on("end", function() {
|
|
|
|
fileStream.end();
|
|
|
|
callback(null, relativePath);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle HTTP errors
|
|
|
|
request.on("error", function(err) {
|
|
|
|
console.error("Error downloading " + relativePath + ": " + err.message);
|
|
|
|
retryDownload(nginxDir, localDir, relativePath, callback); // Retry download
|
|
|
|
});
|
|
|
|
|
|
|
|
request.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to retry downloading a file after a delay
|
|
|
|
function retryDownload(nginxDir, localDir, relativePath, callback) {
|
|
|
|
setTimeout(function() {
|
|
|
|
downloadFile(nginxDir, localDir, relativePath, callback);
|
|
|
|
}, 1000); // Retry after 1 second
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to download multiple files in parallel
|
|
|
|
function downloadFiles(nginxDir, localDir, fileRelativePaths, allDoneCallback) {
|
|
|
|
async.eachLimit(
|
|
|
|
fileRelativePaths,
|
|
|
|
5, // Number of parallel downloads
|
|
|
|
function(relativePath, callback) {
|
|
|
|
downloadFile(nginxDir, localDir, relativePath, callback);
|
|
|
|
},
|
|
|
|
function(err) {
|
|
|
|
if (err) {
|
|
|
|
console.error("Download failed: " + err);
|
|
|
|
} else {
|
|
|
|
console.log("All files downloaded successfully.");
|
|
|
|
allDoneCallback();
|
|
|
|
}
|
|
|
|
}
|
2023-09-18 21:49:31 +00:00
|
|
|
);
|
2023-09-21 15:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function loadCacheList() {
|
|
|
|
var versionjson = remotefs.readJsonSync(versionsPath);
|
2023-09-18 21:49:31 +00:00
|
|
|
versionArray = versionjson["versions"];
|
|
|
|
|
|
|
|
versionHashes = { playable: {}, offline: {} };
|
2023-09-21 15:01:55 +00:00
|
|
|
var hashlines = remotefs.readFileSync(hashPath, ( encoding = "utf-8" ));
|
2023-09-18 21:49:31 +00:00
|
|
|
$.each(hashlines.split(/\r\n|\r|\n/), function (key, line) {
|
|
|
|
if (line.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var linearr = line.split(" ", 2);
|
|
|
|
var fileHash = linearr[0];
|
|
|
|
var filePath = linearr[1].substr(3);
|
|
|
|
var pathArray = filePath.split("/");
|
|
|
|
var hashDict = (pathArray[0] === "Offline") ?
|
|
|
|
versionHashes.offline :
|
|
|
|
versionHashes.playable;
|
|
|
|
var versionString = (pathArray[0] === "Offline") ?
|
|
|
|
pathArray[1] :
|
|
|
|
pathArray[0];
|
|
|
|
|
|
|
|
if (!hashDict.hasOwnProperty(versionString)) {
|
|
|
|
hashDict[versionString] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
hashDict[versionString][filePath.replace("Offline/", "")] = fileHash;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".cache-listing-entry").remove();
|
|
|
|
|
|
|
|
$.each(versionArray, function (key, value) {
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
row.className = "cache-listing-entry"
|
|
|
|
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);
|
|
|
|
|
|
|
|
checkPlayableCache(value.name);
|
|
|
|
checkOfflineCache(value.name);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletePlayableCache(versionString) {
|
2023-09-21 15:01:55 +00:00
|
|
|
var cacheRoot = path.join(
|
|
|
|
userData,
|
|
|
|
"/../../LocalLow/Unity/Web Player/Cache"
|
|
|
|
);
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
resetCacheNames();
|
|
|
|
|
|
|
|
if (versionString === "Offline") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
remotefs.removeSync(path.join(cacheRoot, versionString));
|
2023-09-18 21:49:31 +00:00
|
|
|
console.log("Playable cache " + versionString + " has been removed!");
|
|
|
|
|
|
|
|
checkPlayableCache(versionString);
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloadOfflineCache(versionString) {
|
2023-09-21 15:01:55 +00:00
|
|
|
var offlineRoot = path.join(
|
|
|
|
userData,
|
|
|
|
"/../../LocalLow/Unity/Web Player/Cache/Offline"
|
|
|
|
);
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
var buttonDownload = document.getElementById(getCacheButtonID(versionString, "offline", "download"));
|
|
|
|
var buttonFix = document.getElementById(getCacheButtonID(versionString, "offline", "fix"));
|
|
|
|
var buttonDelete = document.getElementById(getCacheButtonID(versionString, "offline", "delete"));
|
|
|
|
var label = document.getElementById(getCacheElemID(versionString, "offline", "label"));
|
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
var version = versionArray.filter(function (value) {
|
|
|
|
return value.name === versionString;
|
|
|
|
})[0];
|
2023-09-18 21:49:31 +00:00
|
|
|
var sizes = {
|
|
|
|
intact: 0,
|
|
|
|
altered: 0,
|
2023-09-21 15:01:55 +00:00
|
|
|
total: version.offline_size
|
2023-09-18 21:49:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
buttonDownload.setAttribute("disabled", "");
|
|
|
|
buttonFix.setAttribute("disabled", "");
|
|
|
|
buttonDelete.setAttribute("disabled", "");
|
|
|
|
|
|
|
|
buttonDownload.children[0].setAttribute("class", "fas fa-spinner fa-spin fa-fw");
|
|
|
|
buttonFix.children[0].setAttribute("class", "fas fa-spinner fa-spin fa-fw");
|
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
/*
|
|
|
|
var client = http.createClient(80, cdn);
|
|
|
|
|
2023-09-18 21:49:31 +00:00
|
|
|
downloadFiles(
|
2023-09-21 15:01:55 +00:00
|
|
|
offlineRoot,
|
|
|
|
client,
|
2023-09-18 21:49:31 +00:00
|
|
|
sizes,
|
|
|
|
JSON.parse(JSON.stringify(versionHashes.offline[versionString])),
|
|
|
|
function (sizesNow) {
|
|
|
|
label.innerHTML = getCacheLabelText(sizesNow);
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
buttonDownload.children[0].setAttribute("class", "fas fa-download");
|
|
|
|
buttonFix.children[0].setAttribute("class", "fas fa-hammer");
|
|
|
|
checkOfflineCache(versionString);
|
|
|
|
}
|
|
|
|
);
|
2023-09-21 15:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
downloadFiles(
|
|
|
|
version.url,
|
|
|
|
offlineRoot,
|
|
|
|
Object.keys(JSON.parse(JSON.stringify(versionHashes.offline[versionString]))),
|
|
|
|
function () {
|
|
|
|
buttonDownload.children[0].setAttribute("class", "fas fa-download");
|
|
|
|
buttonFix.children[0].setAttribute("class", "fas fa-hammer");
|
|
|
|
checkOfflineCache(versionString);
|
|
|
|
}
|
|
|
|
);
|
2023-09-18 21:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteOfflineCache(versionString) {
|
2023-09-21 15:01:55 +00:00
|
|
|
var offlineRoot = path.join(
|
|
|
|
userData,
|
|
|
|
"/../../LocalLow/Unity/Web Player/Cache/Offline"
|
|
|
|
);
|
2023-09-18 21:49:31 +00:00
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
remotefs.removeSync(path.join(offlineRoot, versionString));
|
2023-09-18 21:49:31 +00:00
|
|
|
console.log("Offline cache " + versionString + " has been removed!");
|
|
|
|
|
|
|
|
checkOfflineCache(versionString);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkPlayableCache(versionString) {
|
2023-09-21 15:01:55 +00:00
|
|
|
var cacheRoot = path.join(
|
|
|
|
userData,
|
|
|
|
"/../../LocalLow/Unity/Web Player/Cache"
|
|
|
|
);
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
var button = document.getElementById(getCacheButtonID(versionString, "playable", "delete"));
|
|
|
|
var label = document.getElementById(getCacheElemID(versionString, "playable", "label"));
|
|
|
|
|
|
|
|
var sizes = {
|
|
|
|
intact: 0,
|
|
|
|
altered: 0,
|
|
|
|
total: versionArray.filter(function (value) {
|
|
|
|
return value.name === versionString;
|
|
|
|
})[0].playable_size
|
|
|
|
};
|
|
|
|
|
|
|
|
resetCacheNames();
|
|
|
|
|
|
|
|
$.each(versionHashes.playable[versionString], function (filePath, fileHash) {
|
2023-09-21 15:01:55 +00:00
|
|
|
var fullFilePath = path.join(cacheRoot, filePath);
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
if (remotefs.existsSync(fullFilePath)) {
|
|
|
|
var fileSize = remotefs.statSync(fullFilePath).size;
|
|
|
|
|
|
|
|
if (fileHash === getFileHash(fullFilePath)) {
|
|
|
|
sizes.intact += fileSize;
|
|
|
|
} else {
|
|
|
|
sizes.altered += fileSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (sizes.intact > 0 || sizes.altered > 0) {
|
|
|
|
button.removeAttribute("disabled");
|
|
|
|
} else {
|
|
|
|
button.setAttribute("disabled", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
label.innerHTML = getCacheLabelText(sizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkOfflineCache(versionString) {
|
2023-09-21 15:01:55 +00:00
|
|
|
var offlineRoot = path.join(
|
|
|
|
userData,
|
|
|
|
"/../../LocalLow/Unity/Web Player/Cache/Offline"
|
|
|
|
);
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
var buttonDownload = document.getElementById(getCacheButtonID(versionString, "offline", "download"));
|
|
|
|
var buttonFix = document.getElementById(getCacheButtonID(versionString, "offline", "fix"));
|
|
|
|
var buttonDelete = document.getElementById(getCacheButtonID(versionString, "offline", "delete"));
|
|
|
|
var label = document.getElementById(getCacheElemID(versionString, "offline", "label"));
|
|
|
|
|
|
|
|
var sizes = {
|
|
|
|
intact: 0,
|
|
|
|
altered: 0,
|
|
|
|
total: versionArray.filter(function (value) {
|
|
|
|
return value.name === versionString;
|
|
|
|
})[0].offline_size
|
|
|
|
};
|
|
|
|
|
|
|
|
$.each(versionHashes.offline[versionString], function (filePath, fileHash) {
|
2023-09-21 15:01:55 +00:00
|
|
|
var fullFilePath = path.join(offlineRoot, filePath);
|
2023-09-18 21:49:31 +00:00
|
|
|
|
|
|
|
if (remotefs.existsSync(fullFilePath)) {
|
|
|
|
var fileSize = remotefs.statSync(fullFilePath).size;
|
|
|
|
|
|
|
|
if (fileHash === getFileHash(fullFilePath)) {
|
|
|
|
sizes.intact += fileSize;
|
|
|
|
} else {
|
|
|
|
sizes.altered += fileSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (sizes.intact > 0 || sizes.altered > 0) {
|
|
|
|
buttonDownload.setAttribute("disabled", "");
|
|
|
|
buttonDelete.removeAttribute("disabled");
|
|
|
|
} else {
|
|
|
|
buttonDownload.removeAttribute("disabled");
|
|
|
|
buttonDelete.setAttribute("disabled", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sizes.altered > 0) {
|
|
|
|
buttonFix.removeAttribute("disabled");
|
|
|
|
} else {
|
|
|
|
buttonFix.setAttribute("disabled", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
label.innerHTML = getCacheLabelText(sizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetCacheNames() {
|
2023-09-21 15:01:55 +00:00
|
|
|
var cacheRoot = path.join(
|
|
|
|
userData,
|
|
|
|
"/../../LocalLow/Unity/Web Player/Cache"
|
|
|
|
);
|
|
|
|
var currentCache = path.join(cacheRoot, "Fusionfall");
|
|
|
|
var record = path.join(userData, ".lastver");
|
2023-09-18 21:49:31 +00:00
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
if (!remotefs.existsSync(currentCache)) {
|
2023-09-18 21:49:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-21 15:01:55 +00:00
|
|
|
var lastVersion = remotefs.readFileSync(record, (encoding = "utf8"));
|
2023-09-18 21:49:31 +00:00
|
|
|
remotefs.renameSync(
|
2023-09-21 15:01:55 +00:00
|
|
|
currentCache,
|
|
|
|
path.join(cacheRoot, lastVersion)
|
2023-09-18 21:49:31 +00:00
|
|
|
);
|
2023-09-21 15:01:55 +00:00
|
|
|
console.log("Current cache " + lastVersion + " has been renamed to its original name.");
|
2023-09-18 21:49:31 +00:00
|
|
|
}
|
|
|
|
|
2023-09-03 09:56:24 +00:00
|
|
|
function performCacheSwap(newVersion) {
|
2023-09-19 12:29:56 +00:00
|
|
|
var cacheRoot = path.join(
|
|
|
|
userData,
|
|
|
|
"/../../LocalLow/Unity/Web Player/Cache"
|
|
|
|
);
|
|
|
|
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)) {
|
2023-09-27 10:01:22 +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-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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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-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-19 12:29:56 +00:00
|
|
|
remotefs.writeFileSync(path.join(__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(
|
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;
|
|
|
|
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-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);
|
|
|
|
});
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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-19 12:44:35 +00:00
|
|
|
var jsonToModify = remotefs.readJsonSync(
|
|
|
|
path.join(userData, "servers.json")
|
|
|
|
);
|
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
|
|
|
});
|