From c7bfaa42b75da3f9f4519737c9f901b1bf4a2626 Mon Sep 17 00:00:00 2001 From: Jordan Dalby Date: Thu, 16 Nov 2023 20:22:46 +0000 Subject: [PATCH] This commit adds a command page, two commands have been added as of now: - DestroyWildDinos - SaveWorld There is the possibility for expansion in the future. Though, additional commands may require an input box for args. Closes #86 --- frontend/src/pages/Server.tsx | 3 ++ frontend/src/pages/server/Commands.tsx | 55 ++++++++++++++++++++++++++ server/server.go | 17 ++++++-- server/server_controller.go | 25 ++++++++++-- 4 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 frontend/src/pages/server/Commands.tsx diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 2bfeecc..f3fb1e0 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -32,6 +32,7 @@ import {UpdaterModal} from "./UpdaterModal"; import {InstallUpdateVerify} from "../../wailsjs/go/installer/InstallerController"; import {SendRconCommand} from "../../wailsjs/go/helpers/HelpersController"; import {Settings} from "./server/Settings"; +import {Commands} from "./server/Commands"; type Props = { @@ -219,11 +220,13 @@ export const Server = ({id, className}: Props) => { General Settings Server Settings Administration + Commands CheckServerInstalled(serv.id).then((val) => setIsInstalled(val)).catch((reason) => console.error(reason))}/> + ) : ( setIsInstalled(true)}/>)} ); diff --git a/frontend/src/pages/server/Commands.tsx b/frontend/src/pages/server/Commands.tsx new file mode 100644 index 0000000..6696a80 --- /dev/null +++ b/frontend/src/pages/server/Commands.tsx @@ -0,0 +1,55 @@ +import { + Button, + Divider, + Typography, + Card, + TabPanel +} from "@mui/joy"; +import {server} from "../../../wailsjs/go/models"; +import React from "react"; +import { + IssueRCONCommand +} from "../../../wailsjs/go/server/ServerController"; +import {useAlert} from "../../components/AlertProvider"; + +type Props = { + setServ: React.Dispatch> + serv: server.Server; + serverStatus: boolean; +} + +export function CommandsCard({ setServ, serv, serverStatus }: Props) { + + const {addAlert} = useAlert() + + function onCommandButtonPressed(command: string) { + addAlert("Running command '" + command + "'", "neutral") + IssueRCONCommand(serv.id, command).then(() => addAlert("RCON command ran successfully", "success")).catch((err) => addAlert("error running command: " + err, "danger")); + } + + return ( + + + Commands + + + +
+
+ +
+
+ +
+
+
+ ); +} + +export function Commands({setServ, serv, serverStatus }: Props) { + return ( + + + + ); +} \ No newline at end of file diff --git a/server/server.go b/server/server.go index 9dc5fac..497d193 100644 --- a/server/server.go +++ b/server/server.go @@ -3,15 +3,16 @@ package server import ( "context" "fmt" - "github.com/JensvandeWiel/ArkAscendedServerManager/helpers" - "github.com/keybase/go-ps" - "github.com/wailsapp/wails/v2/pkg/runtime" "os/exec" "path" "path/filepath" "strconv" "strings" "time" + + "github.com/JensvandeWiel/ArkAscendedServerManager/helpers" + "github.com/keybase/go-ps" + "github.com/wailsapp/wails/v2/pkg/runtime" ) // Server contains the server "stuff" @@ -224,6 +225,16 @@ func (s *Server) IsServerRunning() bool { } } +// IssueRCONCommand issues an RCON command +func (s *Server) IssueRCONCommand(command string) error { + + _, err := s.helpers.SendRconCommand(command, s.IpAddress, s.RCONPort, s.AdminPassword) + if err != nil { + return err + } + return nil +} + // returns questionamrk arguments for the server and dash arguments for the server func (s *Server) CreateArguments() []string { var args []string = []string{} diff --git a/server/server_controller.go b/server/server_controller.go index f90cff9..f8f239a 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -15,12 +15,13 @@ import ( "context" "encoding/json" "fmt" - "github.com/JensvandeWiel/ArkAscendedServerManager/helpers" - "github.com/adrg/xdg" - "github.com/wailsapp/wails/v2/pkg/runtime" "os" "path" "strconv" + + "github.com/JensvandeWiel/ArkAscendedServerManager/helpers" + "github.com/adrg/xdg" + "github.com/wailsapp/wails/v2/pkg/runtime" ) const ( @@ -521,6 +522,24 @@ func (c *ServerController) GetServerStatus(id int) (bool, error) { return status, nil } +func (c *ServerController) IssueRCONCommand(id int, command string) error { + server, exists := c.Servers[id] + if !exists { + err := fmt.Errorf("error running rcon command '" + command + "' " + strconv.Itoa(id) + ": server does not exist in map") + runtime.LogError(c.ctx, err.Error()) + return err + } + + err := server.IssueRCONCommand(command) + if err != nil { + err := fmt.Errorf("error running rcon command '" + command + "' " + strconv.Itoa(id) + ": " + err.Error()) + runtime.LogError(c.ctx, err.Error()) + return err + } + + return nil +} + //endregion //region ServerController helper functions