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

Commit

Permalink
80: Added button to open modal to show server startup command
Browse files Browse the repository at this point in the history
* Added button to open modal to show server startup command

* changed GetServer to GetServerWithError in Administration.tsx

* fixed error

* fixes

* fixes
  • Loading branch information
Ivan0348 committed Nov 7, 2023
1 parent 722652e commit a6d3503
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
49 changes: 42 additions & 7 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 {server} from "../../../wailsjs/go/models";
import {useAlert} from "../../components/AlertProvider";
import {IconAlertCircleFilled} from "@tabler/icons-react";
import {IconAlertCircleFilled, IconInfoCircle} from "@tabler/icons-react";
import {GetServerStartupCommand} 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,44 @@ 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)
return GetServerStartupCommand(serv.id)
.then((cmd: string) => {
setServerCommand(cmd)
}).catch((err) => {
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.CreateServerCmd()
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
}

// CreateServerCmd returns the command to start the server
func (s *Server) CreateServerCmd() *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
10 changes: 10 additions & 0 deletions server/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,13 @@ func (c *ServerController) CheckServerInstalled(id int) (bool, error) {
}

//endregion

func (c *ServerController) GetServerStartupCommand(id int) (string, error) {
server, err := c.GetServerWithError(id, false)
if err != nil {
err := fmt.Errorf("error getting server startup command " + strconv.Itoa(id) + ": server does not exist")
runtime.LogError(c.ctx, err.Error())
return "error getting server startup command " + strconv.Itoa(id) + ": server does not exist", err
}
return server.CreateServerCmd().String(), nil
}

0 comments on commit a6d3503

Please sign in to comment.