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

@ -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'];
@ -36,15 +64,17 @@ 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) {
// Servers were found in the JSON
$("#server-listing-placeholder").attr("hidden",true); $("#server-listing-placeholder").attr("hidden",true);
$.each(serverarray, function( key, value ) { $.each(serverarray, function( key, value ) {
// Create the row, and populate the cells
var row = document.createElement('tr'); var row = document.createElement('tr');
row.className = 'server-listing-entry' row.className = 'server-listing-entry'
row.setAttribute('id', value.uuid) row.setAttribute('id', value.uuid);
var cellName = document.createElement('td'); var cellName = document.createElement('td');
cellName.textContent = value.description cellName.textContent = value.description
var cellVersion = document.createElement('td'); var cellVersion = document.createElement('td');
@ -53,10 +83,10 @@ function loadServerList() {
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);
}); });
@ -112,3 +147,8 @@ $('#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()
} }