From 04d22b2e7be65ffa1de10147f78af00f4eab7e2a Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Fri, 3 Nov 2023 10:39:12 +0100 Subject: [PATCH 1/6] updated server config struct --- server/helpers.go | 5 ++++- server/server.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/helpers.go b/server/helpers.go index f7752f6..4336270 100644 --- a/server/helpers.go +++ b/server/helpers.go @@ -41,7 +41,10 @@ func generateNewDefaultServer(id int) Server { }*/ return Server{ - Id: id, + Id: id, + + DisableUpdateOnStart: false, + ServerAlias: "Server " + strconv.Itoa(id), ServerName: "A server managed by ArkAscendedServerManager", diff --git a/server/server.go b/server/server.go index 859d98e..3d5698a 100644 --- a/server/server.go +++ b/server/server.go @@ -20,6 +20,10 @@ type Server struct { Command *exec.Cmd `json:"-"` ctx context.Context + //PREFERENCES + + DisableUpdateOnStart bool `json:"disableUpdateOnStart"` + //CONFIGURATION VARIABLES // Id is the id of the server From bdfc34a9a0f7cc7ef71a5e7d68bd7cc8f08173ee Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Fri, 3 Nov 2023 11:31:23 +0100 Subject: [PATCH 2/6] Revert "updated server config struct" This reverts commit 04d22b2e7be65ffa1de10147f78af00f4eab7e2a. --- server/helpers.go | 5 +---- server/server.go | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/server/helpers.go b/server/helpers.go index 4336270..f7752f6 100644 --- a/server/helpers.go +++ b/server/helpers.go @@ -41,10 +41,7 @@ func generateNewDefaultServer(id int) Server { }*/ return Server{ - Id: id, - - DisableUpdateOnStart: false, - + Id: id, ServerAlias: "Server " + strconv.Itoa(id), ServerName: "A server managed by ArkAscendedServerManager", diff --git a/server/server.go b/server/server.go index 3d5698a..859d98e 100644 --- a/server/server.go +++ b/server/server.go @@ -20,10 +20,6 @@ type Server struct { Command *exec.Cmd `json:"-"` ctx context.Context - //PREFERENCES - - DisableUpdateOnStart bool `json:"disableUpdateOnStart"` - //CONFIGURATION VARIABLES // Id is the id of the server From b22d0cdb89056de57eb2e1bc55508ab63acb0628 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Fri, 3 Nov 2023 11:31:51 +0100 Subject: [PATCH 3/6] Revert "Revert "updated server config struct"" This reverts commit bdfc34a9a0f7cc7ef71a5e7d68bd7cc8f08173ee. --- server/helpers.go | 5 ++++- server/server.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/helpers.go b/server/helpers.go index f7752f6..4336270 100644 --- a/server/helpers.go +++ b/server/helpers.go @@ -41,7 +41,10 @@ func generateNewDefaultServer(id int) Server { }*/ return Server{ - Id: id, + Id: id, + + DisableUpdateOnStart: false, + ServerAlias: "Server " + strconv.Itoa(id), ServerName: "A server managed by ArkAscendedServerManager", diff --git a/server/server.go b/server/server.go index 859d98e..3d5698a 100644 --- a/server/server.go +++ b/server/server.go @@ -20,6 +20,10 @@ type Server struct { Command *exec.Cmd `json:"-"` ctx context.Context + //PREFERENCES + + DisableUpdateOnStart bool `json:"disableUpdateOnStart"` + //CONFIGURATION VARIABLES // Id is the id of the server From aea4edf6e451af313ee926d0fc0ab5e351c0a3ba Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Fri, 3 Nov 2023 11:43:24 +0100 Subject: [PATCH 4/6] added delete buttons --- frontend/src/pages/Server.tsx | 5 +- frontend/src/pages/server/Administration.tsx | 127 ++++++++++++++++++- server/server_controller.go | 55 ++++++++ 3 files changed, 183 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 5a8cd17..c99ab00 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -1,7 +1,7 @@ import { Button, ButtonGroup, - Card, DialogActions, + Card, Checkbox, DialogActions, DialogContent, DialogTitle, Divider, IconButton, @@ -155,6 +155,7 @@ export const Server = ({id, className}: Props) => { + setUpdaterModalOpen(false)}> setForceStopModalOpen(false)}> @@ -185,7 +186,7 @@ export const Server = ({id, className}: Props) => { - + ) : ( setIsInstalled(true)}/>)} ); diff --git a/frontend/src/pages/server/Administration.tsx b/frontend/src/pages/server/Administration.tsx index 9e014d4..85d5946 100644 --- a/frontend/src/pages/server/Administration.tsx +++ b/frontend/src/pages/server/Administration.tsx @@ -1,9 +1,132 @@ -import {TabPanel} from "@mui/joy"; +import { + Button, + Card, DialogActions, + DialogContent, + DialogTitle, + Divider, + FormLabel, + Input, Modal, + ModalDialog, + TabPanel, + Typography +} from "@mui/joy"; +import {PasswordInput} from "../../components/PasswordInput"; +import React, {useState} from "react"; +import {DeleteProfile, DeleteServerFiles} from "../../../wailsjs/go/server/ServerController"; +import {server} from "../../../wailsjs/go/models"; +import {useAlert} from "../../components/AlertProvider"; +import {IconAlertCircleFilled} from "@tabler/icons-react"; + +type Props = { + setServ: React.Dispatch> + serv: server.Server; + onServerFilesDeleted: () => void; + +} + +export function Administration({setServ, serv, onServerFilesDeleted}: Props) { + + const [deleteServerFilesModalOpen, setDeleteServerFilesModalOpen] = useState(false) + const [deleteProfileModalOpen, setDeleteProfileModalOpen] = useState(false) + const [deleteEverythingModalOpen, setDeleteEverythingModalOpen] = useState(false) + + const {addAlert} = useAlert(); + + function onDeleteServerFilesButtonClicked() { + DeleteServerFiles(serv.id).then(() => {addAlert("Deleted server files", "success"); setServ(serv); onServerFilesDeleted()}).catch((err) => {console.error(err); addAlert(err, "danger")}) + } + + function onDeleteProfileButtonClicked() { + DeleteProfile(serv.id).then(() => {addAlert("Deleted profile", "success"); location.reload()}).catch((err) => {console.error(err); addAlert(err, "danger")}) + } + + function onDeleteEverythingButtonClicked() { + DeleteServerFiles(serv.id).then(() => DeleteProfile(serv.id)).then(() => {addAlert("Deleted everything", "success"); location.reload()}).catch((err) => {console.error(err); addAlert(err, "danger")}) + } + + + -export function Administration() { return ( + + + Server Administration + + +
+
+ setDeleteServerFilesModalOpen(false)}> + + + + Confirmation + + + + Are you sure you want to delete the server files? You cannot reverse this action! + + + + + + + + +
+
+ setDeleteProfileModalOpen(false)}> + + + + Confirmation + + + + Are you sure you want to delete the profile? You cannot reverse this action! + + + + + + + + +
+
+ setDeleteEverythingModalOpen(false)}> + + + + Confirmation + + + + Are you sure you want to delete everything? You cannot reverse this action! + + + + + + + + +
+
+
); } \ No newline at end of file diff --git a/server/server_controller.go b/server/server_controller.go index e99396c..90b4af1 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -238,6 +238,37 @@ func (c *ServerController) GetAllServersFromDir() (map[int]*Server, error) { return c.Servers, nil } +// DeleteServerFilesWithError deletes the server files from the server with the given id. If it fails it returns an error which is catch-able +func (c *ServerController) DeleteServerFilesWithError(id int) error { + server, err := c.GetServerWithError(id, false) + if err != nil { + return fmt.Errorf("Failed to get server: " + strconv.Itoa(id) + " error: " + err.Error()) + } + serverPath := server.ServerPath + + err = os.RemoveAll(serverPath) + if err != nil { + return fmt.Errorf("Failed to delete server " + strconv.Itoa(id) + " files: " + serverPath + " error: " + err.Error()) + } + + return nil +} + +// DeleteProfileWithError deletes the profile with the given id. If it fails it returns an error which is catch-able +func (c *ServerController) DeleteProfileWithError(id int) error { + + serverDir := path.Join(c.serverDir, strconv.Itoa(id)) + + err := os.RemoveAll(serverDir) + if err != nil { + return fmt.Errorf("Failed to delete server " + strconv.Itoa(id) + " profile error: " + err.Error()) + } + + delete(c.Servers, id) + + return nil +} + //region Boilerplate functions // GetAllServers gets all servers and saves them to ServerController.Servers and also returns them, if it fails it returns nil and error. If they already exist in the map it will just get that. @@ -306,6 +337,30 @@ func (c *ServerController) CreateServer(saveToConfig bool) (Server, error) { } +// DeleteServerFiles deletes the server files from the server with the given id. If it fails it returns an error which is catch-able +func (c *ServerController) DeleteServerFiles(id int) error { + err := c.DeleteServerFilesWithError(id) + if err != nil { + newErr := fmt.Errorf("Failed deleting server: " + err.Error()) + runtime.LogError(c.ctx, newErr.Error()) + return newErr + } + return nil + +} + +// DeleteProfile deletes the profile with the given id. If it fails it returns an error which is catch-able +func (c *ServerController) DeleteProfile(id int) error { + err := c.DeleteProfileWithError(id) + if err != nil { + newErr := fmt.Errorf("Failed deleting profile: " + err.Error()) + runtime.LogError(c.ctx, newErr.Error()) + return newErr + } + return nil + +} + //region Private // getServerFromDir gets the server from the server dir if it does not exist and shouldReturnNew is true it returns a new server. From a2f2efceb9db14759435fa980129a7f609400de9 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Fri, 3 Nov 2023 11:48:16 +0100 Subject: [PATCH 5/6] added relead on files deleted --- frontend/src/pages/Server.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index c99ab00..4cc9775 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -186,7 +186,7 @@ export const Server = ({id, className}: Props) => { - + CheckServerInstalled(serv.id).then((val) => setIsInstalled(val)).catch((reason) => console.error(reason))}/> ) : ( setIsInstalled(true)}/>)} ); From b086267958ae751233011cbf911a28e991490f97 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Fri, 3 Nov 2023 12:18:09 +0100 Subject: [PATCH 6/6] added option to disable update on startup --- frontend/src/pages/Server.tsx | 20 ++++++++++++-------- frontend/src/pages/server/Administration.tsx | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 4cc9775..5feae43 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -94,15 +94,19 @@ export const Server = ({id, className}: Props) => { return } - setUpdaterModalOpen(true) - InstallUpdateVerify(serv.serverPath).catch((err) => { - addAlert("failed installing: " + err.message, "danger"); - setUpdaterModalOpen(false); - console.error(err); - }).then(() => { - setUpdaterModalOpen(false); + if (serv.disableUpdateOnStart) { startServer() - }) + } else { + setUpdaterModalOpen(true) + InstallUpdateVerify(serv.serverPath).catch((err) => { + addAlert("failed installing: " + err.message, "danger"); + setUpdaterModalOpen(false); + console.error(err); + }).then(() => { + setUpdaterModalOpen(false); + startServer() + }) + } } diff --git a/frontend/src/pages/server/Administration.tsx b/frontend/src/pages/server/Administration.tsx index 85d5946..fea9db7 100644 --- a/frontend/src/pages/server/Administration.tsx +++ b/frontend/src/pages/server/Administration.tsx @@ -1,6 +1,6 @@ import { Button, - Card, DialogActions, + Card, Checkbox, DialogActions, DialogContent, DialogTitle, Divider, @@ -48,7 +48,7 @@ export function Administration({setServ, serv, onServerFilesDeleted}: Props) { return ( - + Server Administration @@ -127,6 +127,18 @@ export function Administration({setServ, serv, onServerFilesDeleted}: Props) { + + + Server startup + + + +
+
+ setServ((p) => ({ ...p, disableUpdateOnStart: e.target.checked }))} /> +
+
+
); } \ No newline at end of file