Cleaned up logic
This commit is contained in:
@@ -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
|
||||
16
handlers.go
16
handlers.go
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<header>
|
||||
<title>Successful</title>
|
||||
</header>
|
||||
|
||||
<body>
|
||||
<h3>Update Successful</h3>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user