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

Commit

Permalink
Added rcon panel (#51)
Browse files Browse the repository at this point in the history
* Update README.md (#31)

* added workflows

* Update pull_request.yml (#38)

* Update pull_request.yml

* Update pull_request.yml

* Add steamcmdpath config variable (#41)

* added steamCMDPath config var for install

* enhanced return val check

steamCMD can return non null return value without failing

* added better server state control

* added support for spaces in server path

wouldn't install to correct path because i had spaces in my username e.g.: C://Users/jens van de wiel
the above would result in a error

* initial version

* added event when server exits outside of app

* added confirmation modal for force stop

* Update Server.tsx

* Update README.md (#44)

* Update README.md (#45)

* Added button to open server files next to profile name (#47)

* Revert "Added button to open server files next to profile name (#47)"

This reverts commit a85bc58.

* Revert "Update README.md (#45)"

This reverts commit 0888303.

* Revert "Update README.md (#44)"

This reverts commit 6aa9a01.

* Revert "added better server state control"

This reverts commit 7b65ab8.

* Revert "Add steamcmdpath config variable (#41)"

This reverts commit 4ef591f.

* Revert "Update pull_request.yml (#38)"

This reverts commit 604eaba.

* Revert "added workflows"

This reverts commit 8ba0994.

* Revert "Update README.md (#31)"

This reverts commit ba504bf.

* added parsing for servermap

* re-ordered server tabs

* added onServerStart event

* tab refactoring

* added basic console layout

* inherit serverstatus from parent

* added basic terminal

* added rcon console

* refactored to do it the react way ;)

* cleaned code

* refacored it more into the react way

* use one definition type

* fix spacing

---------

Co-authored-by: pepijn <[email protected]>
Co-authored-by: Ivan Oonincx <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2023
1 parent f9066fa commit 05535e7
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 20 deletions.
19 changes: 13 additions & 6 deletions frontend/src/pages/Server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TabList,
Tabs, Tooltip
} from "@mui/joy";
import {Settings} from "./server/Settings";
import {Administration} from "./server/Administration";
import {General} from "./server/General";
import {useEffect, useState} from "react";
import {server} from "../../wailsjs/go/models";
Expand All @@ -27,6 +27,7 @@ import {InstallUpdater} from "./InstallUpdater";
import {useAlert} from "../components/AlertProvider";
import {BrowserOpenURL, EventsOff, EventsOn} from "../../wailsjs/runtime";
import {IconAlertCircleFilled, IconExternalLink} from "@tabler/icons-react";
import {Console} from "./server/Console";


type Props = {
Expand Down Expand Up @@ -73,6 +74,13 @@ export const Server = ({id, className}: Props) => {
EventsOn("onServerExit", () => setServerStatus(false))
return () => EventsOff("onServerExit")
}, []);

useEffect(() => {
if (serv.id >= 0) {
refreshServerStatus()
}
}, [serv]);

//endregion

function onServerStartButtonClicked() {
Expand Down Expand Up @@ -137,14 +145,13 @@ export const Server = ({id, className}: Props) => {
</div>
</div>
<TabList className={'w-full'}>
<Tab variant="plain" indicatorInset color="neutral">Console</Tab>
<Tab variant="plain" indicatorInset color="neutral">General</Tab>
<Tab variant="plain" indicatorInset color="neutral">Settings</Tab>
<Tab variant="plain" indicatorInset color="neutral">Mods</Tab>
<Tab variant="plain" indicatorInset color="neutral">Plugins</Tab>
<Tab variant="plain" indicatorInset color="neutral">Modifiers</Tab>
<Tab variant="plain" indicatorInset color="neutral">Administration</Tab>
</TabList>
<Console serv={serv} setServ={setServ} serverStatus={serverStatus}/>
<General serv={serv} setServ={setServ}/>
<Settings/>
<Administration/>
</Tabs>) : (<InstallUpdater serv={serv} setServ={setServ} onInstalled={() => setIsInstalled(true)}/>)}
</Card>
);
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/pages/server/Administration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {TabPanel} from "@mui/joy";

export function Administration() {
return (
<TabPanel value={2} className={''}>

</TabPanel>
);
}
98 changes: 98 additions & 0 deletions frontend/src/pages/server/Console.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Button, Input, TabPanel } from "@mui/joy";
import React, { useEffect, useRef, useState } from "react";
import { server } from "../../../wailsjs/go/models";
import { SendRconCommand } from "../../../wailsjs/go/helpers/HelpersController";

type Message = {
text: string;
sender: string;
};

type Props = {
setServ: React.Dispatch<React.SetStateAction<server.Server>>;
serv: server.Server;
serverStatus: boolean;
};

export function Console({ setServ, serv, serverStatus }: Props) {
const [input, setInput] = useState("");
const [messages, setMessages] = useState<Message[]>([]);

const terminalRef = useRef<HTMLDivElement>(null);

const writeToConsole = (text: string, sender: string = "user") => {
const newMessage: Message = { text, sender };
setMessages((prevMessages) => [...prevMessages, newMessage]);
};

const doRconCommand = (text: string) => {
SendRconCommand(text, serv.ipAddress, serv.rconPort, serv.adminPassword)
.then((resp) => writeToConsole(resp, "server"))
.catch((err) => writeToConsole("error sending command: " + err, "server"));
};

useEffect(() => {
if (terminalRef.current) {
terminalRef.current.scrollTop = terminalRef.current.scrollHeight;
}
}, [messages]);

if (serverStatus) {
return (
<TabPanel value={0}>
<div
id={"terminal"}
ref={terminalRef}
className={"overflow-y-scroll font-jetbrains bg-black w-[100%] h-[50vh] p-4 rounded "}
>
{messages.map((message, index) => (
<div key={index}>
{message.sender === "server" ? (
<span>{message.text}<br /></span>
) : (
<span>
<span style={{ color: "blue" }}>[{message.sender}]</span>{" "}
<span style={{ color: "green" }}>$</span> {message.text}<br />
</span>
)}
</div>
))}
</div>
<Input
className={"my-2 font-jetbrains"}
value={input}
onChange={(e) => setInput(e.target.value)}
startDecorator={<span className={"text-green-400"}>$</span>}
endDecorator={
<Button
color={"neutral"}
onClick={(e) => {
writeToConsole(input);
setInput("");
doRconCommand(input);
}}
className={"m-1"}
>
Send
</Button>
}
onKeyPress={(e) => {
if (e.key === "Enter") {
writeToConsole(input, "user");
doRconCommand(input);
setInput("");
}
}}
></Input>
</TabPanel>
);
} else {
return (
<TabPanel value={0}>
<div className={"h-16 flex w-full"}>
<p className={"text-lg font-bold ml-8"}>Server is not running</p>
</div>
</TabPanel>
);
}
}
6 changes: 3 additions & 3 deletions frontend/src/pages/server/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function General({serv, setServ}: Props) {
}, []);

return (
<TabPanel className={'space-y-8'}>
<TabPanel value={1} className={'space-y-8'}>
{/* Server Name and Passwords */}
<Card variant="soft" className={''}>
<Typography level="title-md">
Expand Down Expand Up @@ -80,7 +80,7 @@ export function General({serv, setServ}: Props) {
<Divider className={'mx-2'}/>
<FormLabel>IP Address:</FormLabel>
<Select
value={serv.ipAddress?? '0.0.0.0'}
value={serv.ipAddress}
onChange={(e, value) => {
const newValue = value;
setServ(
Expand All @@ -93,7 +93,7 @@ export function General({serv, setServ}: Props) {
)
}}
>
<Option value={"0.0.0.0"}>0.0.0.0 - All</Option>
{/*<Option value={"0.0.0.0"}>0.0.0.0 - All</Option>*/}
{interfaceElements}
</Select>
<FormLabel>Ports: </FormLabel>
Expand Down
9 changes: 0 additions & 9 deletions frontend/src/pages/server/Settings.tsx

This file was deleted.

6 changes: 5 additions & 1 deletion frontend/tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ module.exports = {
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
extend: {
fontFamily: {
'jetbrains': ['JetBrains Mono', 'monospace'],
},
},
},
plugins: [],

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/adrg/xdg v0.4.0
github.com/gorcon/rcon v1.3.4
github.com/jensvandewiel/gosteamcmd v0.1.2
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19
github.com/sethvargo/go-password v0.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorcon/rcon v1.3.4 h1:TExNhWI2mJlqpCg49vajUgznvEZbEzQWKujY1Sy+/AY=
github.com/gorcon/rcon v1.3.4/go.mod h1:46+oSXgPwlRAkcAPStkNnIL1dlcxJweKVNWshy3hDJI=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
github.com/jensvandewiel/gosteamcmd v0.1.2 h1:NHichoj0v3GvSVN2Fn36dSOLosHAytpaKnLnDHTMQPI=
Expand Down
22 changes: 22 additions & 0 deletions helpers/rcon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package helpers

import (
"fmt"
"github.com/gorcon/rcon"
"strconv"
)

func (c *HelpersController) SendRconCommand(command string, ip string, port int, password string) (string, error) {
conn, err := rcon.Dial(ip+":"+strconv.Itoa(port), password)
if err != nil {
return "", fmt.Errorf("failed connectting to rcon server: %v", err)
}
defer conn.Close()

response, err := conn.Execute(command)
if err != nil {
return "", fmt.Errorf("failed executing rcon command: %v", err)
}

return response, nil
}
10 changes: 9 additions & 1 deletion server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func CheckIfServerCorrect(server Server) error {
return fmt.Errorf("Checks failed: Server.AdminPassword is too short.")
}

if server.IpAddress != "0.0.0.0" {
if server.IpAddress == "" {
return fmt.Errorf("Check failed: Ip address is empty")
} else {
interfaces, err := helpers.GetNetworkInterfaces()

if err != nil {
Expand All @@ -109,6 +111,12 @@ func CheckIfServerCorrect(server Server) error {
}
}

if server.ServerMap == "" {
return fmt.Errorf("server.serverMap is empty")
} else if server.ServerMap != "TheIsland_WP" {
return fmt.Errorf("server.serverMap has invalid value: %v", server.ServerMap)
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (s *Server) Start() error {
if err != nil {
return fmt.Errorf("error starting server: %v", err)
}
runtime.EventsEmit(s.ctx, "onServerStart", s.Id)
go func() {
_ = s.Command.Wait()

Expand Down

0 comments on commit 05535e7

Please sign in to comment.