Compare commits

..

No commits in common. "7956f653fbaff553e665ee15b885c1807e2eed5f" and "e11023df54d6787fb92d474b7ed0a0ec2b234501" have entirely different histories.

3 changed files with 109 additions and 700 deletions

View File

@ -312,7 +312,6 @@ function editConfig() {
remotefs.writeFileSync(configPath, JSON.stringify(jsonToModify, null, 4)); remotefs.writeFileSync(configPath, JSON.stringify(jsonToModify, null, 4));
loadConfig(); loadConfig();
// check all offline caches if the offline root changes
if (shouldChangeRoot) handleCache("hash-check", null, "offline"); if (shouldChangeRoot) handleCache("hash-check", null, "offline");
} }
@ -332,10 +331,6 @@ function validateCacheLocation() {
function loadGameVersions() { function loadGameVersions() {
var versionJson = remotefs.readJsonSync(versionsPath); var versionJson = remotefs.readJsonSync(versionsPath);
versionArray = versionJson["versions"]; versionArray = versionJson["versions"];
$("#addserver-versionselect").empty();
$("#editserver-versionselect").empty();
$.each(versionArray, function (key, value) { $.each(versionArray, function (key, value) {
$(new Option(value.name, "val")).appendTo("#addserver-versionselect"); $(new Option(value.name, "val")).appendTo("#addserver-versionselect");
$(new Option(value.name, "val")).appendTo("#editserver-versionselect"); $(new Option(value.name, "val")).appendTo("#editserver-versionselect");
@ -351,7 +346,6 @@ function loadConfig() {
$("#editconfig-enableofflinecache").prop("checked", config["enable-offline-cache"]); $("#editconfig-enableofflinecache").prop("checked", config["enable-offline-cache"]);
$("#editconfig-verifyofflinecache").prop("checked", config["verify-offline-cache"]); $("#editconfig-verifyofflinecache").prop("checked", config["verify-offline-cache"]);
// alter offline root globally
offlineRoot = config["offline-cache-location"] || offlineRootDefault; offlineRoot = config["offline-cache-location"] || offlineRootDefault;
$("#editconfig-offlinecachelocation:text").val(offlineRoot); $("#editconfig-offlinecachelocation:text").val(offlineRoot);
@ -362,7 +356,7 @@ function loadServerList() {
var serverJson = remotefs.readJsonSync(serversPath); var serverJson = remotefs.readJsonSync(serversPath);
serverArray = serverJson["servers"]; serverArray = serverJson["servers"];
deselectServer(); // Remove selection and disable buttons until another server is selected deselectServer(); // Disable buttons until another server is selected
$(".server-listing-entry").remove(); // Clear out old stuff, if any $(".server-listing-entry").remove(); // Clear out old stuff, if any
if (serverArray.length > 0) { if (serverArray.length > 0) {
@ -390,10 +384,9 @@ function loadServerList() {
} }
function loadCacheList() { function loadCacheList() {
// we might want to use a new version right away, so reload them var versionjson = remotefs.readJsonSync(versionsPath);
loadGameVersions(); versionArray = versionjson["versions"];
// load default hashes.json for reference while running the cache handler
if (!defaultHashes) { if (!defaultHashes) {
defaultHashes = remotefs.readJsonSync(path.join( defaultHashes = remotefs.readJsonSync(path.join(
__dirname, __dirname,
@ -401,8 +394,8 @@ function loadCacheList() {
)); ));
} }
deselectVersion(); // Remove selection and disable buttons until another server is selected deselectVersion();
$(".cache-listing-entry").remove(); // Clear out old stuff, if any $(".cache-listing-entry").remove();
$.each(versionArray, function (key, value) { $.each(versionArray, function (key, value) {
var row = document.createElement("tr"); var row = document.createElement("tr");
@ -423,7 +416,6 @@ function loadCacheList() {
$("#cache-tablebody").append(row); $("#cache-tablebody").append(row);
}); });
// simulate a cache handler run so that the buttons update properly
storageLoadingStart(); storageLoadingStart();
storageLoadingUpdate(cacheSizes); storageLoadingUpdate(cacheSizes);
storageLoadingComplete(cacheSizes); storageLoadingComplete(cacheSizes);
@ -481,7 +473,6 @@ function getCacheInfoCell(versionString, cacheMode) {
var labelCache = document.createElement("label"); var labelCache = document.createElement("label");
labelCache.setAttribute("id", labelID); labelCache.setAttribute("id", labelID);
labelCache.setAttribute("for", divID); labelCache.setAttribute("for", divID);
// pull existing info from cacheSizes when available
labelCache.innerHTML = getCacheLabelText( labelCache.innerHTML = getCacheLabelText(
(cacheSizes && cacheSizes[versionString]) ? (cacheSizes && cacheSizes[versionString]) ?
cacheSizes[versionString][cacheMode] : cacheSizes[versionString][cacheMode] :
@ -492,7 +483,6 @@ function getCacheInfoCell(versionString, cacheMode) {
divCacheButtons.setAttribute("id", labelID); divCacheButtons.setAttribute("id", labelID);
$.each(settings, function (buttonMode, config) { $.each(settings, function (buttonMode, config) {
// only delete allowed for playable game caches
if (cacheMode === "playable" && buttonMode !== "delete") { if (cacheMode === "playable" && buttonMode !== "delete") {
return; return;
} }
@ -507,7 +497,6 @@ function getCacheInfoCell(versionString, cacheMode) {
buttonCache.setAttribute("class", config.class); buttonCache.setAttribute("class", config.class);
buttonCache.setAttribute("title", config.tooltip); buttonCache.setAttribute("title", config.tooltip);
buttonCache.setAttribute("type", "button"); buttonCache.setAttribute("type", "button");
// handler setup
buttonCache.setAttribute("onclick", "handleCache(\"" + buttonMode + "\", \"" + versionString + "\", \"" + cacheMode + "\");"); buttonCache.setAttribute("onclick", "handleCache(\"" + buttonMode + "\", \"" + versionString + "\", \"" + cacheMode + "\");");
buttonCache.appendChild(iconItalic); buttonCache.appendChild(iconItalic);
@ -522,7 +511,6 @@ function getCacheInfoCell(versionString, cacheMode) {
} }
function storageLoadingStart(vString, cMode) { function storageLoadingStart(vString, cMode) {
// determine which cache versions and modes to visually update
var versionStrings = []; var versionStrings = [];
$.each(versionArray, function (key, value) { $.each(versionArray, function (key, value) {
if (vString) { if (vString) {
@ -534,11 +522,9 @@ function storageLoadingStart(vString, cMode) {
}); });
var cacheModes = (cMode) ? [cMode] : ["offline", "playable"]; var cacheModes = (cMode) ? [cMode] : ["offline", "playable"];
// deselect and disable the add version button until they are re-enabled
deselectVersion(); deselectVersion();
disableVersionAddButton(); disableVersionAddButton();
// turn buttons into spinners
$.each(versionStrings, function (vKey, versionString) { $.each(versionStrings, function (vKey, versionString) {
$.each(cacheModes, function (cKey, cacheMode) { $.each(cacheModes, function (cKey, cacheMode) {
var buttonDelete = document.getElementById(getCacheButtonID(versionString, cacheMode, "delete")); var buttonDelete = document.getElementById(getCacheButtonID(versionString, cacheMode, "delete"));
@ -562,7 +548,6 @@ function storageLoadingStart(vString, cMode) {
} }
function storageLoadingUpdate(allSizes) { function storageLoadingUpdate(allSizes) {
// update cacheSizes and display results
$.each(allSizes, function (versionString, vSizes) { $.each(allSizes, function (versionString, vSizes) {
$.each(vSizes, function (cacheMode, sizes) { $.each(vSizes, function (cacheMode, sizes) {
var label = document.getElementById(getCacheElemID(versionString, cacheMode, "label")); var label = document.getElementById(getCacheElemID(versionString, cacheMode, "label"));
@ -579,7 +564,6 @@ function storageLoadingUpdate(allSizes) {
} }
function storageLoadingComplete(allSizes) { function storageLoadingComplete(allSizes) {
// re-enable buttons according to the sizes that were read
$.each(allSizes, function (versionString, vSizes) { $.each(allSizes, function (versionString, vSizes) {
$.each(vSizes, function (cacheMode, sizes) { $.each(vSizes, function (cacheMode, sizes) {
var buttonDelete = document.getElementById(getCacheButtonID(versionString, cacheMode, "delete")); var buttonDelete = document.getElementById(getCacheButtonID(versionString, cacheMode, "delete"));
@ -616,33 +600,24 @@ function storageLoadingComplete(allSizes) {
}); });
}); });
// finally, re-enable the version add button
enableVersionAddButton(); enableVersionAddButton();
} }
function handleCache(operation, versionString, cacheMode, callback) { function handleCache(operation, versionString, cacheMode, callback) {
// see if any versions match (could be undefined or null)
var versions = versionArray.filter(function (obj) { var versions = versionArray.filter(function (obj) {
return obj.name === versionString; return obj.name === versionString;
}); });
// pull version url from the found object, if none found, use the default cdn link
var cdnRoot = (versions.length === 0) ? cdnString : versions[0].url; var cdnRoot = (versions.length === 0) ? cdnString : versions[0].url;
var lastSizes = { intact: 0, altered: 0, total: 0 }; var lastSizes = { intact: 0, altered: 0, total: 0 };
var buf = ""; var buf = "";
// start loading on the given version and mode (could be undefined or null, which means 'all')
storageLoadingStart(versionString, cacheMode); storageLoadingStart(versionString, cacheMode);
// create the server and socket listener
var server = net.createServer(function (sock) { var server = net.createServer(function (sock) {
sock.setEncoding("utf8"); sock.setEncoding("utf8");
sock.on("data", function (data) { sock.on("data", function (data) {
// 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
buf += data; buf += data;
var end = buf.indexOf("\n"); var end = buf.indexOf("\n");
@ -651,7 +626,6 @@ function handleCache(operation, versionString, cacheMode, callback) {
var sub = buf.substring(0, end); var sub = buf.substring(0, end);
buf = buf.substring(end + 1); buf = buf.substring(end + 1);
// run a storage update here
lastSizes = JSON.parse(sub); lastSizes = JSON.parse(sub);
storageLoadingUpdate(lastSizes); storageLoadingUpdate(lastSizes);
@ -660,7 +634,6 @@ function handleCache(operation, versionString, cacheMode, callback) {
}); });
}); });
// start listening on a randomly acquired port, and spawn cache handler when ready
server.listen(0, "localhost", function () { server.listen(0, "localhost", function () {
spawn( spawn(
path.join(__dirname, "lib", "cache_handler.exe"), path.join(__dirname, "lib", "cache_handler.exe"),
@ -674,9 +647,7 @@ function handleCache(operation, versionString, cacheMode, callback) {
"--cdn-root", cdnRoot, "--cdn-root", cdnRoot,
"--cache-mode", cacheMode || "all", "--cache-mode", cacheMode || "all",
"--cache-version", versionString || "all", "--cache-version", versionString || "all",
// learn port from the server object and tell the script where to connect
"--port", server.address().port, "--port", server.address().port,
// tell the script which versions and caches are official
"--official-caches" "--official-caches"
].concat(Object.keys(defaultHashes)), ].concat(Object.keys(defaultHashes)),
{ {
@ -690,12 +661,10 @@ function handleCache(operation, versionString, cacheMode, callback) {
); );
} }
// when the script exits, close the server
server.close(); server.close();
// set button state accordingly
storageLoadingComplete(lastSizes); storageLoadingComplete(lastSizes);
// then run the given callback (if any) if (callback)
if (callback) callback(lastSizes); callback(lastSizes);
}); });
}); });
} }
@ -780,7 +749,7 @@ function prepGameInfo(serverUUID) {
return; return;
} }
// otherwise, if main.unity3d is present, use the offline cache // if main.unity3d is present, use the offline cache
var mainPath = path.join(offlinePath, "main.unity3d"); var mainPath = path.join(offlinePath, "main.unity3d");
var versionURL = remotefs.existsSync(mainPath) ? versionInfo.url : offlineURL; var versionURL = remotefs.existsSync(mainPath) ? versionInfo.url : offlineURL;
setGameInfo(serverInfo, versionURL); setGameInfo(serverInfo, versionURL);
@ -788,7 +757,6 @@ function prepGameInfo(serverUUID) {
// For writing loginInfo.php, assetInfo.php, etc. // For writing loginInfo.php, assetInfo.php, etc.
function setGameInfo(serverInfo, versionURL) { function setGameInfo(serverInfo, versionURL) {
// slash fix if people mess it up via text editors
var versionURLRoot = versionURL.endsWith("/") ? versionURL : versionURL + "/"; var versionURLRoot = versionURL.endsWith("/") ? versionURL : versionURL + "/";
window.assetUrl = versionURLRoot; // game-client.js needs to access this window.assetUrl = versionURLRoot; // game-client.js needs to access this
console.log("Cache will expand from " + versionURLRoot); console.log("Cache will expand from " + versionURLRoot);
@ -866,7 +834,6 @@ function getSelectedServer() {
return $("#server-tablebody > tr.bg-primary").prop("id"); return $("#server-tablebody > tr.bg-primary").prop("id");
} }
// Returns the name of the version with the selected background color.
function getSelectedVersion() { function getSelectedVersion() {
return $("#cache-tablebody > tr.bg-primary").prop("id"); return $("#cache-tablebody > tr.bg-primary").prop("id");
} }
@ -892,19 +859,16 @@ function deselectServer() {
$(".server-listing-entry").removeClass("bg-primary"); $(".server-listing-entry").removeClass("bg-primary");
} }
// If applicable, deselect currently selected version.
function deselectVersion() { function deselectVersion() {
disableVersionListButtons(); disableVersionListButtons();
$(".cache-listing-entry").removeClass("bg-primary"); $(".cache-listing-entry").removeClass("bg-primary");
} }
// Select a server
$("#server-table").on("click", ".server-listing-entry", function (event) { $("#server-table").on("click", ".server-listing-entry", function (event) {
enableServerListButtons(); enableServerListButtons();
$(this).addClass("bg-primary").siblings().removeClass("bg-primary"); $(this).addClass("bg-primary").siblings().removeClass("bg-primary");
}); });
// Select a version (if allowed)
$("#cache-table").on("click", ".cache-listing-entry", function (event) { $("#cache-table").on("click", ".cache-listing-entry", function (event) {
// wait for the add button to be re-enabled first // wait for the add button to be re-enabled first
if ($("#of-addversion-button").prop("disabled")) return; if ($("#of-addversion-button").prop("disabled")) return;
@ -930,7 +894,6 @@ $("#of-addversionmodal").on("show.bs.modal", function (e) {
}); });
$("#of-editservermodal").on("show.bs.modal", function (e) { $("#of-editservermodal").on("show.bs.modal", function (e) {
// populate the edit modal with existing values
var jsonToModify = remotefs.readJsonSync(serversPath); var jsonToModify = remotefs.readJsonSync(serversPath);
$.each(jsonToModify["servers"], function (key, value) { $.each(jsonToModify["servers"], function (key, value) {
@ -952,7 +915,6 @@ $("#of-editservermodal").on("show.bs.modal", function (e) {
}); });
$("#of-editversionmodal").on("show.bs.modal", function (e) { $("#of-editversionmodal").on("show.bs.modal", function (e) {
// populate the edit modal with existing values
var jsonToModify = remotefs.readJsonSync(versionsPath); var jsonToModify = remotefs.readJsonSync(versionsPath);
$.each(jsonToModify["versions"], function (key, value) { $.each(jsonToModify["versions"], function (key, value) {
@ -965,7 +927,6 @@ $("#of-editversionmodal").on("show.bs.modal", function (e) {
validateVersionSave("edit"); validateVersionSave("edit");
}); });
// Replace server name to delete
$("#of-deleteservermodal").on("show.bs.modal", function (e) { $("#of-deleteservermodal").on("show.bs.modal", function (e) {
var result = serverArray.filter(function (obj) { var result = serverArray.filter(function (obj) {
return obj.uuid === getSelectedServer(); return obj.uuid === getSelectedServer();
@ -973,7 +934,6 @@ $("#of-deleteservermodal").on("show.bs.modal", function (e) {
$("#deleteserver-servername").html(result.description); $("#deleteserver-servername").html(result.description);
}); });
// Replace version name to delete
$("#of-deleteversionmodal").on("show.bs.modal", function (e) { $("#of-deleteversionmodal").on("show.bs.modal", function (e) {
var result = versionArray.filter(function (obj) { var result = versionArray.filter(function (obj) {
return obj.name === getSelectedVersion(); return obj.name === getSelectedVersion();
@ -981,13 +941,11 @@ $("#of-deleteversionmodal").on("show.bs.modal", function (e) {
$("#deleteversion-versionname").html(result.name); $("#deleteversion-versionname").html(result.name);
}); });
// Run the global hash check once and only if the cache modal is ever shown
$("#of-editcacheconfigmodal").on("show.bs.modal", function (e) { $("#of-editcacheconfigmodal").on("show.bs.modal", function (e) {
if (!cacheSizes) handleCache("hash-check"); if (!cacheSizes) handleCache("hash-check");
}); });
// Keep all config values synced on modal show
// Avoids cases where people forget that they changed the offline root but did not save
$("#of-editconfigmodal").on("show.bs.modal", function (e) { $("#of-editconfigmodal").on("show.bs.modal", function (e) {
// best to keep this synced on modal show
loadConfig(); loadConfig();
}); });

File diff suppressed because it is too large Load Diff

BIN
lib/cache_handler.exe vendored

Binary file not shown.