From e30407c0462913c6c40bb6453612f63bc347893e Mon Sep 17 00:00:00 2001 From: Ivan Oonincx <103519966+Ivan0348@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:19:09 +0100 Subject: [PATCH 1/5] Added button to open modal to show server startup command --- frontend/src/pages/server/Administration.tsx | 50 +++++++++++++++++--- server/server.go | 11 +++-- server/server_controller.go | 8 ++++ 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/frontend/src/pages/server/Administration.tsx b/frontend/src/pages/server/Administration.tsx index d6f7223..01022da 100644 --- a/frontend/src/pages/server/Administration.tsx +++ b/frontend/src/pages/server/Administration.tsx @@ -15,7 +15,9 @@ 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 {GetServer} from "../../../wailsjs/go/server/ServerController"; +import {GetServerCommandWrapper} from "../../../wailsjs/go/server/ServerController"; type Props = { setServ: React.Dispatch> @@ -29,6 +31,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(); @@ -44,8 +48,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 ( @@ -127,9 +129,45 @@ export function Administration({setServ, serv, onServerFilesDeleted}: Props) { - - Server startup - +
+ + Server startup + + +
+
+ setShowServerCommandModalOpen(false)}> + + + + Server startup command + + + + {serverCommand} + + + + + + + +
+
+
+
diff --git a/server/server.go b/server/server.go index 76f7f3d..ea0c005 100644 --- a/server/server.go +++ b/server/server.go @@ -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() err = s.Command.Start() if err != nil { return fmt.Errorf("error starting server: %v", err) @@ -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 { diff --git a/server/server_controller.go b/server/server_controller.go index 90b4af1..9de132f 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -493,3 +493,11 @@ func (c *ServerController) CheckServerInstalled(id int) (bool, error) { } //endregion + +func (c *ServerController) GetServerCommandWrapper(id int) string { + server, err := c.GetServerWithError(id, false) + if err != nil { + return "error getting server command: " + err.Error() + } + return server.GetServerCommand().String() +} From 34288ba74f0202839e7ec713c7ec8391c913a46c Mon Sep 17 00:00:00 2001 From: Ivan Oonincx <103519966+Ivan0348@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:37:12 +0100 Subject: [PATCH 2/5] changed GetServer to GetServerWithError in Administration.tsx --- frontend/src/pages/server/Administration.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/server/Administration.tsx b/frontend/src/pages/server/Administration.tsx index 01022da..3a89f48 100644 --- a/frontend/src/pages/server/Administration.tsx +++ b/frontend/src/pages/server/Administration.tsx @@ -12,7 +12,7 @@ import { } 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, IconInfoCircle} from "@tabler/icons-react"; @@ -155,8 +155,11 @@ export function Administration({setServ, serv, onServerFilesDeleted}: Props) {
diff --git a/server/server_controller.go b/server/server_controller.go index 0feb164..84b7ddc 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -494,10 +494,12 @@ func (c *ServerController) CheckServerInstalled(id int) (bool, error) { //endregion -func (c *ServerController) GetServerStartupCommand(id int) string { +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() + return server.CreateServerCmd().String(), nil }