Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Add a option to disable update on start #69

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions frontend/src/pages/Server.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Button,
ButtonGroup,
Card, DialogActions,
Card, Checkbox, DialogActions,
DialogContent,
DialogTitle,
Divider, IconButton,
Expand Down Expand Up @@ -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()
})
}

}

Expand Down Expand Up @@ -155,6 +159,7 @@ export const Server = ({id, className}: Props) => {
<Button color={'danger'} variant="solid" disabled={!serverStatus} onClick={onServerStopButtonClicked}>Stop</Button>
<Button color={'danger'} variant="solid" disabled={!serverStatus} onClick={() => setForceStopModalOpen(true)}>Force stop</Button>
</ButtonGroup>

<UpdaterModal open={updaterModalOpen} onCompleted={() => setUpdaterModalOpen(false)}></UpdaterModal>
<Modal open={forceStopModalOpen} onClose={() => setForceStopModalOpen(false)}>
<ModalDialog variant="outlined" role="alertdialog">
Expand Down Expand Up @@ -185,7 +190,7 @@ export const Server = ({id, className}: Props) => {
</TabList>
<Console serv={serv} setServ={setServ} serverStatus={serverStatus}/>
<General serv={serv} setServ={setServ}/>
<Administration/>
<Administration serv={serv} setServ={setServ} onServerFilesDeleted={() => CheckServerInstalled(serv.id).then((val) => setIsInstalled(val)).catch((reason) => console.error(reason))}/>
</Tabs>) : (<InstallUpdater serv={serv} setServ={setServ} onInstalled={() => setIsInstalled(true)}/>)}
</Card>
);
Expand Down
141 changes: 138 additions & 3 deletions frontend/src/pages/server/Administration.tsx
Original file line number Diff line number Diff line change
@@ -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<React.SetStateAction<server.Server>>
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 (
<TabPanel value={2} className={''}>
<TabPanel value={2} className={'space-y-8'}>
<Card variant="soft" className={''}>
<Typography level="title-md">
Server Administration
</Typography>
<Divider className={'mx-2'}/>

<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<Modal open={deleteServerFilesModalOpen} onClose={() => setDeleteServerFilesModalOpen(false)}>
<ModalDialog variant="outlined" role="alertdialog">
<DialogTitle>
<IconAlertCircleFilled/>
Confirmation
</DialogTitle>
<Divider />
<DialogContent>
Are you sure you want to delete the server files? You cannot reverse this action!
</DialogContent>
<DialogActions>
<Button variant="solid" color="danger" onClick={() => {setDeleteServerFilesModalOpen(false); onDeleteServerFilesButtonClicked()}}>
Delete Server Files
</Button>
<Button variant="plain" color="neutral" onClick={() => setDeleteServerFilesModalOpen(false)}>
Cancel
</Button>
</DialogActions>
</ModalDialog>
</Modal>
<Button color='danger' onClick={() => setDeleteServerFilesModalOpen(true)}>Delete server files</Button>
</div>
<div className={'inline-block'}>
<Modal open={deleteProfileModalOpen} onClose={() => setDeleteProfileModalOpen(false)}>
<ModalDialog variant="outlined" role="alertdialog">
<DialogTitle>
<IconAlertCircleFilled/>
Confirmation
</DialogTitle>
<Divider />
<DialogContent>
Are you sure you want to delete the profile? You cannot reverse this action!
</DialogContent>
<DialogActions>
<Button variant="solid" color="danger" onClick={() => {setDeleteProfileModalOpen(false); onDeleteProfileButtonClicked()}}>
Delete Profile
</Button>
<Button variant="plain" color="neutral" onClick={() => setDeleteProfileModalOpen(false)}>
Cancel
</Button>
</DialogActions>
</ModalDialog>
</Modal>
<Button color='danger' onClick={() => setDeleteProfileModalOpen(true)}>Delete profile</Button>
</div>
<div className={'inline-block'}>
<Modal open={deleteEverythingModalOpen} onClose={() => setDeleteEverythingModalOpen(false)}>
<ModalDialog variant="outlined" role="alertdialog">
<DialogTitle>
<IconAlertCircleFilled/>
Confirmation
</DialogTitle>
<Divider />
<DialogContent>
Are you sure you want to delete everything? You cannot reverse this action!
</DialogContent>
<DialogActions>
<Button variant="solid" color="danger" onClick={() => {setDeleteEverythingModalOpen(false); onDeleteEverythingButtonClicked()}}>
Delete Everything
</Button>
<Button variant="plain" color="neutral" onClick={() => setDeleteEverythingModalOpen(false)}>
Cancel
</Button>
</DialogActions>
</ModalDialog>
</Modal>
<Button color='danger' onClick={() => setDeleteEverythingModalOpen(true)}>Delete Everything</Button>
</div>
</div>
</Card>
<Card variant="soft" className={''}>
<Typography level="title-md">
Server startup
</Typography>
<Divider className={'mx-2'}/>

<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<Checkbox label="Disable update on server start" checked={serv?.disableUpdateOnStart} onChange={(e) => setServ((p) => ({ ...p, disableUpdateOnStart: e.target.checked }))} />
</div>
</div>
</Card>
</TabPanel>
);
}
5 changes: 4 additions & 1 deletion server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions server/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading