WIP added offline cache pointing logic

This commit is contained in:
FinnHornhoover 2023-10-08 18:37:25 +03:00
parent e3f16d8fc9
commit f28c9c0bb8
2 changed files with 43 additions and 20 deletions

View File

@ -363,19 +363,18 @@ function performCacheSwap(newVersion) {
} }
} }
// For writing loginInfo.php, assetInfo.php, etc. function prepGameInfo(serverUUID) {
function setGameInfo(serverUUID) { var serverInfo = serverArray.filter(function (obj) {
var result = serverArray.filter(function (obj) {
return obj.uuid === serverUUID; return obj.uuid === serverUUID;
})[0]; })[0];
var gameVersion = versionArray.filter(function (obj) { var versionInfo = versionArray.filter(function (obj) {
return obj.name === result.version; return obj.name === serverInfo.version;
})[0]; })[0];
// If cache swapping property exists AND is `true`, run cache swapping logic // If cache swapping property exists AND is `true`, run cache swapping logic
if (config["cache-swapping"]) { if (config["cache-swapping"]) {
try { try {
performCacheSwap(gameVersion.name); performCacheSwap(versionInfo.name);
} catch (ex) { } catch (ex) {
console.log( console.log(
"Error when swapping cache, it may get overwritten:\n" + ex "Error when swapping cache, it may get overwritten:\n" + ex
@ -383,11 +382,20 @@ function setGameInfo(serverUUID) {
} }
} }
window.assetUrl = gameVersion.url; // game-client.js needs to access this ipc.send("adjust-game-info", {
localDir: offlineRoot,
serverInfo: JSON.stringify(serverInfo),
versionInfo: JSON.stringify(versionInfo),
});
}
// For writing loginInfo.php, assetInfo.php, etc.
function setGameInfo(serverInfo, versionInfo) {
window.assetUrl = versionInfo.url; // game-client.js needs to access this
remotefs.writeFileSync(path.join(__dirname, "assetInfo.php"), assetUrl); remotefs.writeFileSync(path.join(__dirname, "assetInfo.php"), assetUrl);
if (result.hasOwnProperty("endpoint")) { if (serverInfo.hasOwnProperty("endpoint")) {
var httpEndpoint = result.endpoint.replace("https://", "http://"); var httpEndpoint = serverInfo.endpoint.replace("https://", "http://");
remotefs.writeFileSync( remotefs.writeFileSync(
path.join(__dirname, "rankurl.txt"), path.join(__dirname, "rankurl.txt"),
httpEndpoint + "getranks" httpEndpoint + "getranks"
@ -419,17 +427,17 @@ function setGameInfo(serverUUID) {
// Server address parsing // Server address parsing
var address; var address;
var port; var port;
var sepPos = result.ip.indexOf(":"); var sepPos = serverInfo.ip.indexOf(":");
if (sepPos > -1) { if (sepPos > -1) {
address = result.ip.substr(0, sepPos); address = serverInfo.ip.substr(0, sepPos);
port = result.ip.substr(sepPos + 1); port = serverInfo.ip.substr(sepPos + 1);
} else { } else {
address = result.ip; address = serverInfo.ip;
port = 23000; // default port = 23000; // default
} }
// DNS resolution. there is no synchronous version for some stupid reason // DNS resolution. there is no synchronous version for some stupid reason
if (!address.match(/^[0-9.]+$/)) if (!address.match(/^[0-9.]+$/)) {
dns.lookup(address, (family = 4), function (err, resolvedAddress) { dns.lookup(address, (family = 4), function (err, resolvedAddress) {
if (!err) { if (!err) {
console.log("Resolved " + address + " to " + resolvedAddress); console.log("Resolved " + address + " to " + resolvedAddress);
@ -439,7 +447,7 @@ function setGameInfo(serverUUID) {
} }
prepConnection(address, port); prepConnection(address, port);
}); });
else { } else {
console.log(address + " is an IP; skipping DNS lookup"); console.log(address + " is an IP; skipping DNS lookup");
prepConnection(address, port); prepConnection(address, port);
} }
@ -468,7 +476,7 @@ function connectToServer() {
$("#of-serverselector").fadeOut("slow", function () { $("#of-serverselector").fadeOut("slow", function () {
setTimeout(function () { setTimeout(function () {
$("body,html").css("pointer-events", ""); $("body,html").css("pointer-events", "");
setGameInfo(getSelectedServer()); prepGameInfo(getSelectedServer());
}, 200); }, 200);
}); });
} }
@ -573,3 +581,7 @@ ipc.on("storage-loading-complete", function (arg) {
} }
} }
}); });
ipc.on("set-game-info", function (arg) {
setGameInfo(JSON.parse(arg.serverInfo), JSON.parse(arg.versionInfo));
});

View File

@ -4,8 +4,6 @@ var fs = require("fs-extra");
var ipc = require("ipc"); var ipc = require("ipc");
var os = require("os"); var os = require("os");
var path = require("path"); var path = require("path");
var url = require("url");
var http = require("http");
var async = require("async"); var async = require("async");
var createHash = require("crypto").createHash; var createHash = require("crypto").createHash;
var spawn = require("child_process").spawn; var spawn = require("child_process").spawn;
@ -21,7 +19,6 @@ if (process.env.npm_node_execpath) {
process.env["UNITY_HOME_DIR"] = unityHomeDir; process.env["UNITY_HOME_DIR"] = unityHomeDir;
process.env["UNITY_DISABLE_PLUGIN_UPDATES"] = "yes"; process.env["UNITY_DISABLE_PLUGIN_UPDATES"] = "yes";
process.env["WINE_LARGE_ADDRESS_AWARE"] = "1";
app.commandLine.appendSwitch("enable-npapi"); app.commandLine.appendSwitch("enable-npapi");
app.commandLine.appendSwitch( app.commandLine.appendSwitch(
@ -111,7 +108,6 @@ app.on("ready", function () {
show: false, show: false,
"web-preferences": { "web-preferences": {
plugins: true, plugins: true,
nodeIntegration: true,
}, },
}); });
mainWindow.setMinimumSize(640, 480); mainWindow.setMinimumSize(640, 480);
@ -250,6 +246,21 @@ app.on("ready", function () {
} }
); );
}); });
ipc.on("adjust-game-info", function (event, arg) {
var serverInfo = JSON.parse(arg.serverInfo);
var versionInfo = JSON.parse(arg.versionInfo);
var currentSizes = versionSizes[versionInfo.name]["offline"];
var localURL = "file:///" + path.join(arg.localDir, versionInfo.name).replace(/\\/g, "/") + "/";
mainWindow.webContents.send("set-game-info", {
serverInfo: JSON.stringify(serverInfo),
versionInfo: JSON.stringify({
name: versionInfo.name,
url: (currentSizes.intact === currentSizes.total) ? localURL : versionInfo.url,
}),
});
});
}); });
function showMainWindow() { function showMainWindow() {