Cleaned up logic

This commit is contained in:
2022-05-25 15:48:06 -05:00
parent a8c5f0a1f0
commit e4cb23b58c
5 changed files with 74 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
<!DOCTYPE html>
<head>
<title>Rod</title>
<style>
@@ -489,13 +490,16 @@
<body>
<main>
<p id="console">V Rising Daemon</p>
<h3 id="console">V Rising Daemon</h3>
<form>
<button id="start_stop" type="button">Start Server</button>
</form>
<form>
<button id="download" type="button">Download Saves Backup</button>
</form>
<form>
<button id="update" type="button">Update Game</button>
</form>
<form method="get" action="backup.zip">
<button type="submit">Download Backup</button>
</form>
<form method="post" action="configure" enctype="multipart/form-data">
<label>ServerHostSettings.json</label>
<input type="file" id="ServerHostSettings.json" name="ServerHostSettings.json">
@@ -505,26 +509,73 @@
<input type="file" id="adminlist.txt" name="adminlist.txt">
<label>banlist.txt</label>
<input type="file" id="banlist.txt" name="banlist.txt">
<button type="submit">Upload Configuration</button>
<button id="config" type="submit">Upload Configuration</button>
</form>
</main>
</body>
<script>
let server_running = false
let start_stop_button = document.getElementById("start_stop")
let update_button = document.getElementById("update")
let start_button = document.getElementById("start")
let console = document.getElementById("console")
let download_button = document.getElementById("download")
let config_button = document.getElementById("config")
let console_elm = document.getElementById("console")
start_stop_button.addEventListener("click", start_stop)
update_button.addEventListener("click", update)
download_button.addEventListener("click", download)
document.addEventListener("DOMContentLoaded", async function () {
updateState()
})
async function start_stop() {
if (server_running) {
await fetch("/stop")
} else {
await fetch("/start")
}
updateState()
}
async function update() {
update_button.disabled = true
console.innerText = "Updating"
console_elm.innerText = "Updating"
let resp = await fetch("/update")
let body = await resp.text()
console.innerText = body
console_elm.innerText = body
update_button.disabled = false
}
async function download() {
window.open("backup.zip")
}
async function updateState() {
res = await fetch("/running")
state = await res.text()
if (state === "true") {
server_running = true
start_stop_button.innerText = "Stop Server"
update_button.disabled = true
config_button.disabled = true
update_button.innerText = "Cannot Update While Server Running"
config_button.innerText = "Cannot Configure While Server Running"
} else {
server_running = false
start_stop_button.innerText = "Start Server"
update_button.disabled = false
config_button.disabled = false
update_button.innerText = "Update Game"
config_button.innerText = "Download Saves Backup"
}
}
</script>
</html>

View File

@@ -1,10 +0,0 @@
<!DOCTYPE html>
<header>
<title>Successful</title>
</header>
<body>
<h3>Update Successful</h3>
</body>
</html>