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

Commit

Permalink
This commit adds a command page, two commands have been added as of now:
Browse files Browse the repository at this point in the history
- DestroyWildDinos
- SaveWorld

There is the possibility for expansion in the future. Though, additional
commands may require an input box for args.

Closes #86
  • Loading branch information
Jordan Dalby committed Nov 16, 2023
1 parent 75514ee commit c7bfaa4
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 6 deletions.
3 changes: 3 additions & 0 deletions frontend/src/pages/Server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -219,11 +220,13 @@ export const Server = ({id, className}: Props) => {
<Tab variant="plain" indicatorInset color="neutral">General Settings</Tab>
<Tab variant="plain" indicatorInset color="neutral">Server Settings</Tab>
<Tab variant="plain" indicatorInset color="neutral">Administration</Tab>
<Tab variant="plain" indicatorInset color="neutral">Commands</Tab>
</TabList>
<Console serv={serv} setServ={setServ} serverStatus={serverStatus}/>
<General serv={serv} setServ={setServ}/>
<Settings setServ={setServ} serv={serv}></Settings>
<Administration serv={serv} setServ={setServ} onServerFilesDeleted={() => CheckServerInstalled(serv.id).then((val) => setIsInstalled(val)).catch((reason) => console.error(reason))}/>
<Commands serv={serv} setServ={setServ} serverStatus={serverStatus}/>
</Tabs>) : (<InstallUpdater serv={serv} setServ={setServ} onInstalled={() => setIsInstalled(true)}/>)}
</Card>
);
Expand Down
55 changes: 55 additions & 0 deletions frontend/src/pages/server/Commands.tsx
Original file line number Diff line number Diff line change
@@ -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<React.SetStateAction<server.Server>>
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 (
<Card variant="soft" className={''}>
<Typography level="title-md">
Commands
</Typography>
<Divider className={'mx-2'}/>

<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<Button color={'neutral'} variant="solid" disabled={!serverStatus} onClick={()=>onCommandButtonPressed("destroywilddinos")}>Dino Wipe</Button>
</div>
<div className={'inline-block'}>
<Button color={'neutral'} variant="solid" disabled={!serverStatus} onClick={()=>onCommandButtonPressed("saveworld")}>Save World</Button>
</div>
</div>
</Card>
);
}

export function Commands({setServ, serv, serverStatus }: Props) {
return (
<TabPanel value={4} className={'space-y-8'}>
<CommandsCard setServ={setServ} serv={serv} serverStatus={serverStatus}/>
</TabPanel>
);
}
17 changes: 14 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}
Expand Down
25 changes: 22 additions & 3 deletions server/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7bfaa4

Please sign in to comment.