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

80: Added button to open modal to show server startup command #81

Merged
Show file tree
Hide file tree
Changes from 3 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
56 changes: 48 additions & 8 deletions frontend/src/pages/server/Administration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
TabPanel,
Typography
} from "@mui/joy";
import {PasswordInput} from "../../components/PasswordInput";
import React, {useState} from "react";
import {DeleteProfile, DeleteServerFiles} from "../../../wailsjs/go/server/ServerController";
import {DeleteProfile, DeleteServerFiles, GetServerWithError} from "../../../wailsjs/go/server/ServerController";
import {server} from "../../../wailsjs/go/models";
import {useAlert} from "../../components/AlertProvider";
import {IconAlertCircleFilled} from "@tabler/icons-react";
import {IconAlertCircleFilled, IconInfoCircle} from "@tabler/icons-react";
import {GetServerCommandWrapper} from "../../../wailsjs/go/server/ServerController";

type Props = {
setServ: React.Dispatch<React.SetStateAction<server.Server>>
Expand All @@ -29,6 +29,8 @@ export function Administration({setServ, serv, onServerFilesDeleted}: Props) {
const [deleteServerFilesModalOpen, setDeleteServerFilesModalOpen] = useState(false)
const [deleteProfileModalOpen, setDeleteProfileModalOpen] = useState(false)
const [deleteEverythingModalOpen, setDeleteEverythingModalOpen] = useState(false)
const [showServerCommandModalOpen, setShowServerCommandModalOpen] = useState(false)
const [serverCommand, setServerCommand] = useState("");

const {addAlert} = useAlert();

Expand All @@ -44,8 +46,6 @@ export function Administration({setServ, serv, onServerFilesDeleted}: Props) {
DeleteServerFiles(serv.id).then(() => DeleteProfile(serv.id)).then(() => {addAlert("Deleted everything", "success"); location.reload()}).catch((err) => {console.error(err); addAlert(err, "danger")})
}



return (
<TabPanel value={3} className={'space-y-8'}>
<Card variant="soft" className={''}>
Expand Down Expand Up @@ -127,9 +127,49 @@ export function Administration({setServ, serv, onServerFilesDeleted}: Props) {
</div>
</Card>
<Card variant="soft" className={''}>
<Typography level="title-md">
Server startup
</Typography>
<div className={'space-x-4 w-full flex justify-between'}>
<Typography level="title-md">
Server startup
</Typography>
<Typography level="title-md">
<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<Modal open={showServerCommandModalOpen} onClose={() => setShowServerCommandModalOpen(false)}>
<ModalDialog variant="outlined" role="dialog">
<DialogTitle>
<IconInfoCircle/>
Server startup command
</DialogTitle>
<Divider />
<DialogContent>
{serverCommand}
</DialogContent>
<DialogActions>
<Button variant="solid" color="neutral" onClick={() => setShowServerCommandModalOpen(false)}>
Close
</Button>
</DialogActions>
</ModalDialog>
</Modal>
<Button color='neutral' onClick={() => {
setShowServerCommandModalOpen(true)
GetServerWithError(serv.id, false).then(() => {
Ivan0348 marked this conversation as resolved.
Show resolved Hide resolved
return GetServerCommandWrapper(serv.id)
.then((cmd: string) => {
setServerCommand(cmd)
}).catch((err) => {
console.error(err);
addAlert(err, "danger");
});
}).catch((err: string) => {
console.error(err);
addAlert(err, "danger");
});
}}>Show startup command</Button>
</div>
</div>
</Typography>
</div>
<Divider className={'mx-2'}/>

<div className={'space-x-4 w-full flex'}>
Expand Down
11 changes: 7 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ func (s *Server) Start() error {
if s.IsServerRunning() {
return fmt.Errorf("error starting server: server is already running")
} else {

args := s.CreateArguments()

s.Command = exec.Command(path.Join(s.ServerPath, "ShooterGame\\Binaries\\Win64\\ArkAscendedServer.exe"), args...)
s.Command = s.GetServerCommand()
Ivan0348 marked this conversation as resolved.
Show resolved Hide resolved
err = s.Command.Start()
if err != nil {
return fmt.Errorf("error starting server: %v", err)
Expand Down Expand Up @@ -111,6 +108,12 @@ func (s *Server) Start() error {
return nil
}

// GetServerCommand returns the command to start the server
func (s *Server) GetServerCommand() *exec.Cmd {
args := s.CreateArguments()
return exec.Command(path.Join(s.ServerPath, "ShooterGame\\Binaries\\Win64\\ArkAscendedServer.exe"), args...)
}

// ForceStop forces the server to stop "quitting/killing the process"
func (s *Server) ForceStop() error {

Expand Down
8 changes: 8 additions & 0 deletions server/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,11 @@ func (c *ServerController) CheckServerInstalled(id int) (bool, error) {
}

//endregion

func (c *ServerController) GetServerCommandWrapper(id int) string {
Ivan0348 marked this conversation as resolved.
Show resolved Hide resolved
server, err := c.GetServerWithError(id, false)
if err != nil {
return "error getting server command: " + err.Error()
Ivan0348 marked this conversation as resolved.
Show resolved Hide resolved
}
return server.GetServerCommand().String()
}
Loading