mirror of
https://github.com/OpenFusionProject/Client.git
synced 2024-11-14 02:30:05 +00:00
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:
parent
3d8cd79a55
commit
02f390499c
15
.gitignore
vendored
15
.gitignore
vendored
@ -1,20 +1,9 @@
|
||||
|
||||
locales/
|
||||
|
||||
*.dll
|
||||
|
||||
*.pak
|
||||
|
||||
OpenFusionClient.exe
|
||||
|
||||
*.bin
|
||||
|
||||
*.php
|
||||
OpenFusionClient.exe
|
||||
icudtl.dat
|
||||
|
||||
version
|
||||
|
||||
resources/app/files/assetInfo.php
|
||||
|
||||
resources/app/files/loginInfo.php
|
||||
|
||||
resources/app/files/rankurl.txt
|
||||
|
@ -19,6 +19,34 @@ function disableServerListButtons() {
|
||||
$('#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() {
|
||||
var versionjson = JSON.parse(remotefs.readFileSync(userdir+"\\versions.json"));
|
||||
versionarray = versionjson['versions'];
|
||||
@ -36,15 +64,17 @@ function loadServerList() {
|
||||
var serverjson = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json"));
|
||||
serverarray = serverjson['servers'];
|
||||
|
||||
$(".server-listing-entry").remove(); // clear out old stuff, if any
|
||||
disableServerListButtons();
|
||||
$(".server-listing-entry").remove(); // Clear out old stuff, if any
|
||||
disableServerListButtons(); // Disable buttons until another is selected
|
||||
|
||||
if (serverarray.length > 0) {
|
||||
// Servers were found in the JSON
|
||||
$("#server-listing-placeholder").attr("hidden",true);
|
||||
$.each(serverarray, function( key, value ) {
|
||||
// Create the row, and populate the cells
|
||||
var row = document.createElement('tr');
|
||||
row.className = 'server-listing-entry'
|
||||
row.setAttribute('id', value.uuid)
|
||||
row.setAttribute('id', value.uuid);
|
||||
var cellName = document.createElement('td');
|
||||
cellName.textContent = value.description
|
||||
var cellVersion = document.createElement('td');
|
||||
@ -53,10 +83,10 @@ function loadServerList() {
|
||||
|
||||
row.appendChild(cellName);
|
||||
row.appendChild(cellVersion);
|
||||
document.getElementById('server-tablebody').appendChild(row);
|
||||
$("#server-tablebody").append(row);
|
||||
});
|
||||
} else {
|
||||
// no servers added, make sure placeholder is visible
|
||||
// No servers are added, make sure placeholder is visible
|
||||
$("#server-listing-placeholder").attr("hidden",false);
|
||||
}
|
||||
}
|
||||
@ -71,33 +101,38 @@ function setGameInfo(serverUUID) {
|
||||
remotefs.writeFileSync(__dirname+"\\loginInfo.php", result.ip);
|
||||
|
||||
if (result.hasOwnProperty('endpoint')) {
|
||||
var rankurl = result.endpoint.replace("https://", "http://") + "getranks"
|
||||
console.log("Using rank endpoint " + rankurl)
|
||||
remotefs.writeFileSync(__dirname+"\\rankurl.txt", rankurl);
|
||||
var httpendpoint = result.endpoint.replace("https://", "http://")
|
||||
remotefs.writeFileSync(__dirname+"\\rankurl.txt", httpendpoint+"getranks");
|
||||
// Write these out too
|
||||
remotefs.writeFileSync(__dirname+"\\sponsor.php", httpendpoint+"upsell/sponsor.png");
|
||||
remotefs.writeFileSync(__dirname+"\\images.php", httpendpoint+"upsell/");
|
||||
} else {
|
||||
if (remotefs.existsSync(__dirname+"\\rankurl.txt")) {
|
||||
// delete the file, this server won't be using it
|
||||
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() {
|
||||
return $("tr.bg-primary").prop("id");
|
||||
return $("#server-tablebody > tr.bg-primary").prop("id");
|
||||
}
|
||||
|
||||
function connectToServer() {
|
||||
// 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 " + uuid);
|
||||
console.log("Connecting to server with UUID of " + getSelectedServer());
|
||||
|
||||
// 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');
|
||||
stopEasterEggs();
|
||||
$('#of-serverselector').fadeOut('slow', function() {
|
||||
setTimeout(function(){
|
||||
$('body,html').css('pointer-events','');
|
||||
setGameInfo(uuid);
|
||||
setGameInfo(getSelectedServer());
|
||||
launchGame();
|
||||
}, 200);
|
||||
});
|
||||
@ -112,3 +147,8 @@ $('#server-table').on('dblclick', '.server-listing-entry', function(event) {
|
||||
$(this).addClass('bg-primary').siblings().removeClass('bg-primary');
|
||||
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);
|
||||
});
|
||||
|
@ -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>
|
||||
</div>
|
||||
<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: </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: </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>
|
||||
</select></form>
|
||||
</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>
|
||||
@ -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>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="lead">Do you really want to delete <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 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>
|
||||
|
@ -96,6 +96,3 @@ function showMainWindow() {
|
||||
|
||||
mainWindow.webContents.openDevTools()
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user