diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 5a8cd17..5feae43 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, @@ -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() + }) + } } @@ -155,6 +159,7 @@ export const Server = ({id, className}: Props) => { + setUpdaterModalOpen(false)}> setForceStopModalOpen(false)}> @@ -185,7 +190,7 @@ export const Server = ({id, className}: Props) => { - + CheckServerInstalled(serv.id).then((val) => setIsInstalled(val)).catch((reason) => console.error(reason))}/> ) : ( setIsInstalled(true)}/>)} ); diff --git a/frontend/src/pages/server/Administration.tsx b/frontend/src/pages/server/Administration.tsx index 9e014d4..fea9db7 100644 --- a/frontend/src/pages/server/Administration.tsx +++ b/frontend/src/pages/server/Administration.tsx @@ -1,9 +1,144 @@ -import {TabPanel} from "@mui/joy"; +import { + Button, + Card, Checkbox, 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! + + + + + + + + +
+
+
+ + + Server startup + + +
+
+ setServ((p) => ({ ...p, disableUpdateOnStart: e.target.checked }))} /> +
+
+
); } \ No newline at end of file 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 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.