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

@@ -4,6 +4,6 @@ This tool allows for the simple configuration, backup, and starting of a V Risin
- [x] Backup Saves
- [x] Update
- [x] Upload Config Files
- [] Check if Server Runnning
- [] Start Server
- [] Stop Server
- [x] Check if Server Runnning
- [x] Start Server
- [x] Stop Server

View File

@@ -15,6 +15,7 @@ import (
var server_sig = make(chan int, 1)
var server_started = false
var server_process = exec.Command("xvfb-run", "-a", "wine", "/root/.wine/drive_c/vrisingserver/VRisingServer.exe")
func check(err error) {
if err != nil {
@@ -39,7 +40,7 @@ func update(c *gin.Context) {
if err != nil {
c.String(http.StatusBadRequest, err.Error())
} else {
c.String(http.StatusOK, out.String())
c.String(http.StatusOK, "Update Complete")
}
}
@@ -125,11 +126,6 @@ func configure(c *gin.Context) {
}
func doIt() {
server_process := exec.Command("xvfb-run", "-a", "wine", "/root/.wine/drive_c/vrisingserver/VRisingServer.exe")
var out bytes.Buffer
server_process.Stdout = &out
err := server_process.Start()
check(err)
@@ -162,3 +158,11 @@ func stopServer(c *gin.Context) {
c.String(http.StatusOK, "Already Stopped")
}
}
func serverRunning(c *gin.Context) {
if server_started {
c.String(http.StatusOK, "true")
} else {
c.String(http.StatusOK, "false")
}
}

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>

View File

@@ -24,6 +24,7 @@ func main() {
r.GET("/update", update)
r.GET("/start", startServer)
r.GET("/stop", stopServer)
r.GET("/running", serverRunning)
r.GET("/backup.zip", backup)