Adding and deleting servers works.

Still need to fix the add server validation
Other changes:
* Convert all files to spaces and fix indentation
* We now write out the images.php and sponsor.php files if an endpoint url is defined for a server
* Added comments
This commit is contained in:
CakeLancelot 2020-12-23 04:05:29 -06:00
parent 3d8cd79a55
commit 02f390499c
7 changed files with 201 additions and 175 deletions

15
.gitignore vendored
View File

@ -1,20 +1,9 @@
locales/ locales/
*.dll *.dll
*.pak *.pak
OpenFusionClient.exe
*.bin *.bin
*.php
OpenFusionClient.exe
icudtl.dat icudtl.dat
version version
resources/app/files/assetInfo.php
resources/app/files/loginInfo.php
resources/app/files/rankurl.txt resources/app/files/rankurl.txt

View File

@ -1,5 +1,5 @@
{ {
"autoupdate-check": true, "autoupdate-check": true,
"cache-swapping": false, "cache-swapping": false,
"initial-setup-completed": true "initial-setup-completed": true
} }

View File

@ -1,19 +1,19 @@
{ {
"servers": [ "servers": [
{ {
"uuid": "d9773558-6ddf-4d00-8803-d830a22a842b", "uuid": "d9773558-6ddf-4d00-8803-d830a22a842b",
"description": "OpenFusion Public Server - Original", "description": "OpenFusion Public Server - Original",
"ip": "144.202.52.9:23000", "ip": "144.202.52.9:23000",
"version": "beta-20100104", "version": "beta-20100104",
"endpoint": "https://api.dexlabs.systems/" "endpoint": "https://api.dexlabs.systems/"
}, },
{ {
"uuid": "b84f6859-f500-41f2-bdfa-8e3746639ee9", "uuid": "b84f6859-f500-41f2-bdfa-8e3746639ee9",
"description": "OpenFusion Public Server - Academy", "description": "OpenFusion Public Server - Academy",
"ip": "144.202.52.9:24000", "ip": "144.202.52.9:24000",
"version": "beta-20111013", "version": "beta-20111013",
"endpoint": "https://api.dexlabs.systems/academy/" "endpoint": "https://api.dexlabs.systems/academy/"
} }
], ],
"favorites": [] "favorites": []
} }

View File

@ -1,108 +1,108 @@
{ {
"versions": [ "versions": [
{ {
"name": "beta-20100104", "name": "beta-20100104",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100104/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100104/"
}, },
{ {
"name": "beta-20100119", "name": "beta-20100119",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100119/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100119/"
}, },
{ {
"name": "beta-20100207", "name": "beta-20100207",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100207/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100207/"
}, },
{ {
"name": "beta-20100307", "name": "beta-20100307",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100307/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100307/"
}, },
{ {
"name": "beta-20100322", "name": "beta-20100322",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100322/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100322/"
}, },
{ {
"name": "beta-20100413", "name": "beta-20100413",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100413/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100413/"
}, },
{ {
"name": "beta-20100502", "name": "beta-20100502",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100502/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100502/"
}, },
{ {
"name": "beta-20100524", "name": "beta-20100524",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100524/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100524/"
}, },
{ {
"name": "beta-20100604", "name": "beta-20100604",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100604/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100604/"
}, },
{ {
"name": "beta-20100616", "name": "beta-20100616",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100616/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100616/"
}, },
{ {
"name": "beta-20100711", "name": "beta-20100711",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100711/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100711/"
}, },
{ {
"name": "beta-20100728", "name": "beta-20100728",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100728/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100728/"
}, },
{ {
"name": "beta-20100909", "name": "beta-20100909",
"url": "http://ht.cdn.turner.com/ff/big/beta-20100909/" "url": "http://ht.cdn.turner.com/ff/big/beta-20100909/"
}, },
{ {
"name": "beta-20101003", "name": "beta-20101003",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101003/" "url": "http://ht.cdn.turner.com/ff/big/beta-20101003/"
}, },
{ {
"name": "beta-20101011", "name": "beta-20101011",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101011/" "url": "http://ht.cdn.turner.com/ff/big/beta-20101011/"
}, },
{ {
"name": "beta-20101028", "name": "beta-20101028",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101028/" "url": "http://ht.cdn.turner.com/ff/big/beta-20101028/"
}, },
{ {
"name": "beta-20101123", "name": "beta-20101123",
"url": "http://ht.cdn.turner.com/ff/big/beta-20101123/" "url": "http://ht.cdn.turner.com/ff/big/beta-20101123/"
}, },
{ {
"name": "beta-20110213", "name": "beta-20110213",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110213/" "url": "http://ht.cdn.turner.com/ff/big/beta-20110213/"
}, },
{ {
"name": "beta-20110314", "name": "beta-20110314",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110314/" "url": "http://ht.cdn.turner.com/ff/big/beta-20110314/"
}, },
{ {
"name": "beta-20110330", "name": "beta-20110330",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110330/" "url": "http://ht.cdn.turner.com/ff/big/beta-20110330/"
}, },
{ {
"name": "beta-20110424", "name": "beta-20110424",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110424/" "url": "http://ht.cdn.turner.com/ff/big/beta-20110424/"
}, },
{ {
"name": "beta-20110523", "name": "beta-20110523",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110523/" "url": "http://ht.cdn.turner.com/ff/big/beta-20110523/"
}, },
{ {
"name": "beta-20110725", "name": "beta-20110725",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110725/" "url": "http://ht.cdn.turner.com/ff/big/beta-20110725/"
}, },
{ {
"name": "beta-20110818", "name": "beta-20110818",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110818/" "url": "http://ht.cdn.turner.com/ff/big/beta-20110818/"
}, },
{ {
"name": "beta-20110912", "name": "beta-20110912",
"url": "http://ht.cdn.turner.com/ff/big/beta-20110912/" "url": "http://ht.cdn.turner.com/ff/big/beta-20110912/"
}, },
{ {
"name": "beta-20111013", "name": "beta-20111013",
"url": "http://ht.cdn.turner.com/ff/big/beta-20111013/" "url": "http://ht.cdn.turner.com/ff/big/beta-20111013/"
} }
] ]
} }

View File

@ -19,6 +19,34 @@ function disableServerListButtons() {
$('#of-deleteserver-button').prop('disabled', true); $('#of-deleteserver-button').prop('disabled', true);
} }
function addServer() {
var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
var server = {};
server['uuid'] = uuidv4();
server['description'] = $("#addserver-descinput").val();
server['ip'] = $("#addserver-ipinput").val();
server['version'] = $("#addserver-versionselect option:selected").text();
//server['endpoint'] =
jsontomodify['servers'].push(server)
remotefs.writeFileSync(userdir+"\\servers.json", JSON.stringify(jsontomodify, null, 4));
loadServerList();
}
function deleteServer() {
var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
var result = jsontomodify['servers'].filter(function(obj) {return (obj.uuid === getSelectedServer())})[0];
var resultindex = jsontomodify['servers'].indexOf(result);
jsontomodify['servers'].splice(resultindex, 1);
remotefs.writeFileSync(userdir+"\\servers.json", JSON.stringify(jsontomodify, null, 4));
loadServerList();
}
function loadGameVersions() { function loadGameVersions() {
var versionjson = JSON.parse(remotefs.readFileSync(userdir+"\\versions.json")); var versionjson = JSON.parse(remotefs.readFileSync(userdir+"\\versions.json"));
versionarray = versionjson['versions']; versionarray = versionjson['versions'];
@ -33,30 +61,32 @@ function loadConfig() {
} }
function loadServerList() { function loadServerList() {
var serverjson = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json")); var serverjson = JSON.parse(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
disableServerListButtons(); disableServerListButtons(); // Disable buttons until another is selected
if (serverarray.length > 0) { if (serverarray.length > 0) {
$("#server-listing-placeholder").attr("hidden",true); // Servers were found in the JSON
$.each(serverarray, function( key, value ) { $("#server-listing-placeholder").attr("hidden",true);
var row = document.createElement('tr'); $.each(serverarray, function( key, value ) {
row.className = 'server-listing-entry' // Create the row, and populate the cells
row.setAttribute('id', value.uuid) var row = document.createElement('tr');
var cellName = document.createElement('td'); row.className = 'server-listing-entry'
cellName.textContent = value.description row.setAttribute('id', value.uuid);
var cellVersion = document.createElement('td'); var cellName = document.createElement('td');
cellVersion.textContent = value.version cellName.textContent = value.description
cellVersion.className = 'text-monospace' var cellVersion = document.createElement('td');
cellVersion.textContent = value.version
cellVersion.className = 'text-monospace'
row.appendChild(cellName); row.appendChild(cellName);
row.appendChild(cellVersion); row.appendChild(cellVersion);
document.getElementById('server-tablebody').appendChild(row); $("#server-tablebody").append(row);
}); });
} else { } else {
// no servers added, make sure placeholder is visible // No servers are added, make sure placeholder is visible
$("#server-listing-placeholder").attr("hidden",false); $("#server-listing-placeholder").attr("hidden",false);
} }
} }
@ -71,33 +101,38 @@ function setGameInfo(serverUUID) {
remotefs.writeFileSync(__dirname+"\\loginInfo.php", result.ip); remotefs.writeFileSync(__dirname+"\\loginInfo.php", result.ip);
if (result.hasOwnProperty('endpoint')) { if (result.hasOwnProperty('endpoint')) {
var rankurl = result.endpoint.replace("https://", "http://") + "getranks" var httpendpoint = result.endpoint.replace("https://", "http://")
console.log("Using rank endpoint " + rankurl) remotefs.writeFileSync(__dirname+"\\rankurl.txt", httpendpoint+"getranks");
remotefs.writeFileSync(__dirname+"\\rankurl.txt", rankurl); // Write these out too
remotefs.writeFileSync(__dirname+"\\sponsor.php", httpendpoint+"upsell/sponsor.png");
remotefs.writeFileSync(__dirname+"\\images.php", httpendpoint+"upsell/");
} else { } else {
if (remotefs.existsSync(__dirname+"\\rankurl.txt")) { if (remotefs.existsSync(__dirname+"\\rankurl.txt")) {
// delete the file, this server won't be using it // delete the file, this server won't be using it
remotefs.unlinkSync(__dirname+"\\rankurl.txt"); remotefs.unlinkSync(__dirname+"\\rankurl.txt");
remotefs.writeFileSync(__dirname+"\\sponsor.php", "assets/img/welcome.png");
remotefs.writeFileSync(__dirname+"\\images.php", "assets/img/");
} }
} }
} }
// 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() { function getSelectedServer() {
return $("tr.bg-primary").prop("id"); return $("#server-tablebody > tr.bg-primary").prop("id");
} }
function connectToServer() { function connectToServer() {
// Get ID of the selected server, which corresponds to its UUID in the json // Get ID of the selected server, which corresponds to its UUID in the json
var uuid = getSelectedServer(); console.log("Connecting to server with UUID of " + getSelectedServer());
console.log("Connecting to server with UUID of " + uuid);
// prevent the user from clicking anywhere else during the transition // Prevent the user from clicking anywhere else during the transition
$('body,html').css('pointer-events','none'); $('body,html').css('pointer-events','none');
stopEasterEggs(); stopEasterEggs();
$('#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(uuid); setGameInfo(getSelectedServer());
launchGame(); launchGame();
}, 200); }, 200);
}); });
@ -111,4 +146,9 @@ $('#server-table').on('click', '.server-listing-entry', function(event) {
$('#server-table').on('dblclick', '.server-listing-entry', function(event) { $('#server-table').on('dblclick', '.server-listing-entry', function(event) {
$(this).addClass('bg-primary').siblings().removeClass('bg-primary'); $(this).addClass('bg-primary').siblings().removeClass('bg-primary');
connectToServer(); connectToServer();
}); });
$('#of-deleteservermodal').on('show.bs.modal', function (e) {
var result = serverarray.filter(function(obj) {return (obj.uuid === getSelectedServer());})[0];
$("#deleteserver-servername").html(result.description);
});

View File

@ -69,11 +69,11 @@
<h4 class="modal-title">Add Server</h4><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Add Server</h4><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form id="addserver-form" class="needs-validation"><label for="addserver-descinput">Server Description</label><input class="form-control form-row w-75" type="text" id="addserver-descinput" name="of-serverdesc-field" placeholder="My OpenFusion Server" required="" minlength="1" maxlength="70"><label for="addserver-ipinput">Server IP</label><input class="form-control form-row w-75" type="text" id="addserver-ipinput" name="of-serverip-field" placeholder="127.0.0.1:23000" required="" pattern="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9]+$"><label for="addserver-versionselect">Game Version:&nbsp;</label><select class="form-control w-50" id="addserver-versionselect" required="" style="margin-left: -5px;"> <form id="addserver-form" class="needs-validation"><label for="addserver-descinput">Server Description</label><input class="form-control form-row w-75" type="text" id="addserver-descinput" placeholder="My OpenFusion Server" required="" minlength="1" maxlength="70"><label for="addserver-ipinput">Server IP</label><input class="form-control form-row w-75" type="text" id="addserver-ipinput" placeholder="127.0.0.1:23000" required="" pattern="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9]+$"><label for="addserver-versionselect">Game Version:&nbsp;</label><select class="form-control w-50" id="addserver-versionselect" required="" style="margin-left: -5px;">
<option value="" selected="" id="addserver-versionlist-placeholder" disabled="">Please select a verison...</option> <option value="" selected="" id="addserver-versionlist-placeholder" disabled="">Please select a verison...</option>
</select></form> </select></form>
</div> </div>
<div class="modal-footer"><button class="btn btn-primary border rounded border-primary btn-danger border-danger" id="addserver-cancel" type="button" data-dismiss="modal">Cancel</button><button class="btn btn-primary disabled border rounded border-primary btn-success border-success" id="addserver-savebutton" type="submit" data-dismiss="modal" disabled="" form="addserver-form" onclick="addServer();">Save</button></div> <div class="modal-footer"><button class="btn btn-primary border rounded border-primary btn-danger border-danger" id="addserver-cancel" type="button" data-dismiss="modal">Cancel</button><button class="btn btn-primary border rounded border-primary btn-success border-success" id="addserver-savebutton" type="submit" data-dismiss="modal" form="addserver-form" onclick="addServer();">Save</button></div>
</div> </div>
</div> </div>
</div> </div>
@ -84,7 +84,7 @@
<h4 class="modal-title">Are you sure?</h4><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Are you sure?</h4><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p class="lead">Do you really want to delete&nbsp;<a id="deleteserver-servername">SERVER_NAME</a>?<br>You could always re-add it later.</p> <p class="lead">Do you really want to delete<br>"<a id="deleteserver-servername">SERVER_NAME</a>"?<br><br>You could always re-add it later.</p>
</div> </div>
<div class="modal-footer"><button class="btn btn-primary border rounded border-primary" type="button" data-dismiss="modal">Cancel</button><button class="btn btn-primary border rounded border-primary btn-danger border-danger" id="deleteserver-button" type="button" data-dismiss="modal" onclick="deleteServer();">Yes, Delete</button></div> <div class="modal-footer"><button class="btn btn-primary border rounded border-primary" type="button" data-dismiss="modal">Cancel</button><button class="btn btn-primary border rounded border-primary btn-danger border-danger" id="deleteserver-button" type="button" data-dismiss="modal" onclick="deleteServer();">Yes, Delete</button></div>
</div> </div>

View File

@ -96,6 +96,3 @@ function showMainWindow() {
mainWindow.webContents.openDevTools() mainWindow.webContents.openDevTools()
} }