Compare commits

..

4 Commits

Author SHA1 Message Date
CakeLancelot
3fc6cabe33 Disable telemetry in player dll
Co-authored-by: gsemaj <gsemaj@proton.me>
2023-09-19 08:59:13 -05:00
CakeLancelot
71e4694ff6 Misc comment cleanup, correct holiday date range, simplify JSON loading 2023-09-19 08:57:50 -05:00
CakeLancelot
76f4a05287 Move server-selector over to path.join(), fix issues with cache swapping
Before, swapping would continually fail if a cache tried to be stored at a directory that already existed. The skipping mechanism likely also didn't work as intended. Both have been fixed now.
Additionally:
* Added .editorconfig file 
* Ran prettier format
* Misc. refactoring
2023-09-19 08:57:29 -05:00
CakeLancelot
97144aad59 Remove initial setup window
Now that we only copy a few json files for the initial setup, the process is so fast the progress window isn't really needed anymore
2023-09-17 13:02:19 -05:00
7 changed files with 92 additions and 133 deletions

19
.editorconfig Normal file
View File

@ -0,0 +1,19 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# 4 space indentation
[*.js, *.css, *.html, *.json]
indent_style = space
indent_size = 4
# Don't enforce anything in vendored code
[*.min.*]
end_of_line = unset
insert_final_newline = unset
indent_style = unset
indent_style = unset

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

View File

@ -1,10 +1,8 @@
// You're kind of ruining the surprise by reading this, but whatever // You're kind of ruining the surprise by reading this, but whatever
var today = new Date(); var today = new Date();
// Check Christmas season: Date constructor in Javascript uses an index var christmasBegin = new Date(today.getFullYear(), 11, 21);
// so 11 is Dec. of this year, and 12 is Jan. of the next var christmasEnd = new Date(today.getFullYear(), 11, 31);
var christmasBegin = new Date(today.getFullYear(), 11, 23);
var christmasEnd = new Date(today.getFullYear(), 12, 8);
var sf; var sf;
if (today >= christmasBegin && today <= christmasEnd) { if (today >= christmasBegin && today <= christmasEnd) {

View File

@ -1,9 +1,13 @@
// TODO: path.join in this file, pass in json paths from index.js
var remote = require("remote"); var remote = require("remote");
var remotefs = remote.require("fs-extra"); var remotefs = remote.require("fs-extra");
var dns = remote.require("dns"); var dns = remote.require("dns");
var path = remote.require("path");
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");
var userDir = remote.require("app").getPath("userData");
var versionArray; var versionArray;
var serverArray; var serverArray;
var config; var config;
@ -29,7 +33,7 @@ function disableServerListButtons() {
function getAppVersion() { function getAppVersion() {
appVersion = remote.require("app").getVersion(); appVersion = remote.require("app").getVersion();
// simplify version, ex. 1.4.0 -> 1.4, // Simplify version, ex. 1.4.0 -> 1.4,
// but only if a revision number isn't present // but only if a revision number isn't present
if (appVersion.endsWith(".0")) { if (appVersion.endsWith(".0")) {
return appVersion.substr(0, appVersion.length - 2); return appVersion.substr(0, appVersion.length - 2);
@ -44,9 +48,7 @@ function setAppVersionText() {
} }
function addServer() { function addServer() {
var jsonToModify = JSON.parse( var jsonToModify = remotefs.readJsonSync(serversPath);
remotefs.readFileSync(userDir + "\\servers.json")
);
var server = {}; var server = {};
server["uuid"] = uuidv4(); server["uuid"] = uuidv4();
@ -63,17 +65,12 @@ function addServer() {
jsonToModify["servers"].push(server); jsonToModify["servers"].push(server);
remotefs.writeFileSync( remotefs.writeFileSync(serversPath, JSON.stringify(jsonToModify, null, 4));
userDir + "\\servers.json",
JSON.stringify(jsonToModify, null, 4)
);
loadServerList(); loadServerList();
} }
function editServer() { function editServer() {
var jsonToModify = JSON.parse( var jsonToModify = remotefs.readJsonSync(serversPath);
remotefs.readFileSync(userDir + "\\servers.json")
);
$.each(jsonToModify["servers"], function (key, value) { $.each(jsonToModify["servers"], function (key, value) {
if (value["uuid"] == getSelectedServer()) { if (value["uuid"] == getSelectedServer()) {
value["description"] = value["description"] =
@ -90,17 +87,12 @@ function editServer() {
} }
}); });
remotefs.writeFileSync( remotefs.writeFileSync(serversPath, JSON.stringify(jsonToModify, null, 4));
userDir + "\\servers.json",
JSON.stringify(jsonToModify, null, 4)
);
loadServerList(); loadServerList();
} }
function deleteServer() { function deleteServer() {
var jsonToModify = JSON.parse( var jsonToModify = remotefs.readJsonSync(serversPath);
remotefs.readFileSync(userDir + "\\servers.json")
);
var result = jsonToModify["servers"].filter(function (obj) { var result = jsonToModify["servers"].filter(function (obj) {
return obj.uuid === getSelectedServer(); return obj.uuid === getSelectedServer();
})[0]; })[0];
@ -109,25 +101,20 @@ function deleteServer() {
jsonToModify["servers"].splice(resultindex, 1); jsonToModify["servers"].splice(resultindex, 1);
remotefs.writeFileSync( remotefs.writeFileSync(serversPath, JSON.stringify(jsonToModify, null, 4));
userDir + "\\servers.json",
JSON.stringify(jsonToModify, null, 4)
);
loadServerList(); loadServerList();
} }
function restoreDefaultServers() { function restoreDefaultServers() {
remotefs.copySync( remotefs.copySync(
__dirname + "\\defaults\\servers.json", path.join(__dirname, "/defaults/servers.json"),
userDir + "\\servers.json" serversPath
); );
loadServerList(); loadServerList();
} }
function loadGameVersions() { function loadGameVersions() {
var versionJson = JSON.parse( var versionJson = remotefs.readJsonSync(versionsPath);
remotefs.readFileSync(userDir + "\\versions.json")
);
versionArray = versionJson["versions"]; versionArray = versionJson["versions"];
$.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");
@ -136,14 +123,12 @@ function loadGameVersions() {
} }
function loadConfig() { function loadConfig() {
// load config object globally // Load config object globally
config = JSON.parse(remotefs.readFileSync(userDir + "\\config.json")); config = remotefs.readJsonSync(configPath);
} }
function loadServerList() { function loadServerList() {
var serverJson = JSON.parse( var serverJson = remotefs.readJsonSync(serversPath);
remotefs.readFileSync(userDir + "\\servers.json")
);
serverArray = serverJson["servers"]; serverArray = serverJson["servers"];
$(".server-listing-entry").remove(); // Clear out old stuff, if any $(".server-listing-entry").remove(); // Clear out old stuff, if any
@ -174,47 +159,50 @@ function loadServerList() {
} }
function performCacheSwap(newVersion) { function performCacheSwap(newVersion) {
var cacheRoot = userDir + "\\..\\..\\LocalLow\\Unity\\Web Player\\Cache"; var cacheRoot = path.join(
var currentCache = cacheRoot + "\\Fusionfall"; userData,
var newCache = cacheRoot + "\\" + newVersion; "/../../LocalLow/Unity/Web Player/Cache"
var record = userDir + "\\.lastver"; );
var currentCache = path.join(cacheRoot, "FusionFall");
var newCache = path.join(cacheRoot, newVersion);
var record = path.join(userData, ".lastver");
var lastVersion = remotefs.readFileSync(record, (encoding = "utf8"));
// if cache renaming would result in a no-op (ex. launching the same version // Make note of what version we are launching for next launch
// two times), then skip it. this avoids permissions errors with multiple clients remotefs.writeFileSync(record, newVersion);
// If cache renaming would result in a no-op (ex. launching the same version
// two times), then skip it. This avoids permissions errors with multiple clients
// (file/folder is already open in another process) // (file/folder is already open in another process)
var skip = false; var skip = false;
if (remotefs.existsSync(currentCache)) { if (remotefs.existsSync(currentCache)) {
// cache already exists, find out what version it belongs to // Cache already exists, find out what version it belongs to
if (remotefs.existsSync(record)) { if (remotefs.existsSync(record)) {
lastVersion = remotefs.readFileSync(record);
if (lastVersion != newVersion) { if (lastVersion != newVersion) {
// Remove the directory we're trying to store the
// existing cache to if it already exists for whatever
// 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
remotefs.renameSync( remotefs.renameSync(
currentCache, currentCache,
cacheRoot + "\\" + lastVersion path.join(cacheRoot, lastVersion)
); );
} else { } else {
console.log( console.log("Cached version unchanged, skipping rename");
"Cached version unchanged, renaming will be skipped"
);
skip = true; skip = true;
} }
console.log("Current cache is " + lastVersion); console.log("Current cache is " + lastVersion);
} else {
console.log(
"Couldn't find last version record; cache may get overwritten"
);
} }
} }
if (remotefs.existsSync(newCache) || !skip) { if (remotefs.existsSync(newCache) && !skip) {
// rename saved cache to FusionFall // Rename saved cache to FusionFall
remotefs.renameSync(newCache, currentCache); remotefs.renameSync(newCache, currentCache);
console.log("Current cache swapped to " + newVersion); console.log("Current cache swapped to " + newVersion);
} }
// make note of what version we are launching for next launch
remotefs.writeFileSync(record, newVersion);
} }
// For writing loginInfo.php, assetInfo.php, etc. // For writing loginInfo.php, assetInfo.php, etc.
@ -226,7 +214,7 @@ function setGameInfo(serverUUID) {
return obj.name === result.version; return obj.name === result.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(gameVersion.name);
@ -239,31 +227,34 @@ function setGameInfo(serverUUID) {
window.assetUrl = gameVersion.url; // game-client.js needs to access this window.assetUrl = gameVersion.url; // game-client.js needs to access this
remotefs.writeFileSync(__dirname + "\\assetInfo.php", assetUrl); remotefs.writeFileSync(path.join(__dirname, "assetInfo.php"), assetUrl);
if (result.hasOwnProperty("endpoint")) { if (result.hasOwnProperty("endpoint")) {
var httpEndpoint = result.endpoint.replace("https://", "http://"); var httpEndpoint = result.endpoint.replace("https://", "http://");
remotefs.writeFileSync( remotefs.writeFileSync(
__dirname + "\\rankurl.txt", path.join(__dirname, "rankurl.txt"),
httpEndpoint + "getranks" httpEndpoint + "getranks"
); );
// Write these out too // Write these out too
remotefs.writeFileSync( remotefs.writeFileSync(
__dirname + "\\sponsor.php", path.join(__dirname, "sponsor.php"),
httpEndpoint + "upsell/sponsor.png" httpEndpoint + "upsell/sponsor.png"
); );
remotefs.writeFileSync( remotefs.writeFileSync(
__dirname + "\\images.php", path.join(__dirname, "images.php"),
httpEndpoint + "upsell/" httpEndpoint + "upsell/"
); );
} else { } else {
// Remove/default the endpoint related stuff, this server won't be using it // Remove/default the endpoint related stuff, this server won't be using it
if (remotefs.existsSync(__dirname + "\\rankurl.txt")) { if (remotefs.existsSync(path.join(__dirname, "rankurl.txt"))) {
remotefs.unlinkSync(__dirname + "\\rankurl.txt"); remotefs.unlinkSync(path.join(__dirname, "rankurl.txt"));
remotefs.writeFileSync( remotefs.writeFileSync(
__dirname + "\\sponsor.php", path.join(__dirname, "sponsor.php"),
"assets/img/welcome.png" "assets/img/welcome.png"
); );
remotefs.writeFileSync(__dirname + "\\images.php", "assets/img/"); remotefs.writeFileSync(
path.join(__dirname, "images.php"),
"assets/img/"
);
} }
} }
@ -281,7 +272,7 @@ function setGameInfo(serverUUID) {
// 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);
address = resolvedAddress; address = resolvedAddress;
@ -299,7 +290,7 @@ function setGameInfo(serverUUID) {
function prepConnection(address, port) { function prepConnection(address, port) {
var full = address + ":" + port; var full = address + ":" + port;
console.log("Will connect to " + full); console.log("Will connect to " + full);
remotefs.writeFileSync(__dirname + "\\loginInfo.php", full); remotefs.writeFileSync(path.join(__dirname, "loginInfo.php"), full);
launchGame(); launchGame();
} }
@ -342,8 +333,8 @@ $("#server-table").on("dblclick", ".server-listing-entry", function (event) {
}); });
$("#of-editservermodal").on("show.bs.modal", function (e) { $("#of-editservermodal").on("show.bs.modal", function (e) {
var jsonToModify = JSON.parse( var jsonToModify = remotefs.readJsonSync(
remotefs.readFileSync(userDir + "\\servers.json") path.join(userData, "servers.json")
); );
$.each(jsonToModify["servers"], function (key, value) { $.each(jsonToModify["servers"], function (key, value) {
if (value["uuid"] == getSelectedServer()) { if (value["uuid"] == getSelectedServer()) {

View File

@ -8,10 +8,8 @@ var path = require("path");
var BrowserWindow = require("browser-window"); var BrowserWindow = require("browser-window");
var mainWindow = null; var mainWindow = null;
var userData = app.getPath("userData");
var unityHomeDir = path.join(__dirname, "../../WebPlayer"); var unityHomeDir = path.join(__dirname, "../../WebPlayer");
// If running in non-packaged / development mode, this dir will be slightly different
// if running in non-packaged / development mode, this dir will be slightly different
if (process.env.npm_node_execpath) { if (process.env.npm_node_execpath) {
unityHomeDir = path.join(app.getAppPath(), "/build/WebPlayer"); unityHomeDir = path.join(app.getAppPath(), "/build/WebPlayer");
} }
@ -20,31 +18,26 @@ process.env["UNITY_HOME_DIR"] = unityHomeDir;
process.env["UNITY_DISABLE_PLUGIN_UPDATES"] = "yes"; process.env["UNITY_DISABLE_PLUGIN_UPDATES"] = "yes";
app.commandLine.appendSwitch("enable-npapi"); app.commandLine.appendSwitch("enable-npapi");
app.commandLine.appendSwitch("load-plugin", path.join(unityHomeDir, "/loader/npUnity3D32.dll")); app.commandLine.appendSwitch(
"load-plugin",
path.join(unityHomeDir, "/loader/npUnity3D32.dll")
);
app.commandLine.appendSwitch("no-proxy-server"); app.commandLine.appendSwitch("no-proxy-server");
var configPath = path.join(userData, "/config.json"); var userData = app.getPath("userData");
var serversPath = path.join(userData, "/servers.json"); var configPath = path.join(userData, "config.json");
var versionsPath = path.join(userData, "/versions.json"); var serversPath = path.join(userData, "servers.json");
var versionsPath = path.join(userData, "versions.json");
function initialSetup(firstTime) { function initialSetup(firstTime) {
// Display a small window to inform the user that the app is working
setupWindow = new BrowserWindow({
width: 275,
height: 450,
resizable: false,
center: true,
frame: false,
});
if (!firstTime) { if (!firstTime) {
// migration from pre-1.4 // Migration from pre-1.4
// Back everything up, just in case // Back everything up, just in case
setupWindow.loadUrl("file://" + __dirname + "/initial-setup.html");
fs.copySync(configPath, configPath + ".bak"); fs.copySync(configPath, configPath + ".bak");
fs.copySync(serversPath, serversPath + ".bak"); fs.copySync(serversPath, serversPath + ".bak");
fs.copySync(versionsPath, versionsPath + ".bak"); fs.copySync(versionsPath, versionsPath + ".bak");
} else { } else {
// first-time setup // First-time setup
// Copy default servers // Copy default servers
fs.copySync( fs.copySync(
path.join(__dirname, "/defaults/servers.json"), path.join(__dirname, "/defaults/servers.json"),
@ -57,7 +50,6 @@ function initialSetup(firstTime) {
fs.copySync(path.join(__dirname, "/defaults/config.json"), configPath); fs.copySync(path.join(__dirname, "/defaults/config.json"), configPath);
console.log("JSON files copied."); console.log("JSON files copied.");
setupWindow.destroy();
showMainWindow(); showMainWindow();
} }
@ -86,7 +78,7 @@ app.on("ready", function () {
height: 720, height: 720,
show: false, show: false,
"web-preferences": { "web-preferences": {
plugins: true plugins: true,
}, },
}); });
mainWindow.setMinimumSize(640, 480); mainWindow.setMinimumSize(640, 480);
@ -149,7 +141,6 @@ function showMainWindow() {
mainWindow.webContents.on("will-navigate", function (event, url) { mainWindow.webContents.on("will-navigate", function (event, url) {
event.preventDefault(); event.preventDefault();
// TODO: showMessageBox rather than showErrorBox?
switch (url) { switch (url) {
case "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow": case "https://audience.fusionfall.com/ff/regWizard.do?_flowId=fusionfall-registration-flow":
var errorMessage = var errorMessage =

View File

@ -1,40 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>OpenFusion: Initial Setup</title>
</head>
<body
style="
overflow: hidden;
background-color: #000;
user-select: none;
-webkit-user-select: none;
"
>
<center>
<div>
<img src="assets/img/of-3.png" width="256" />
<div>
<img src="assets/img/spinner.gif" width="50px" />
</div>
<div style="margin-top: 15px">
<p
style="
text-shadow: 1px 1px 8px #4349c4;
color: #4a76b7;
font-size: 18px;
font-family: -apple-system, BlinkMacSystemFont,
'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji';
"
>
OpenFusion is setting up...<br />Please wait - this
should take <br />less than a minute.
</p>
</div>
</div>
</center>
</body>
</html>