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

Added rcon panel #51

Merged
merged 30 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba504bf
Update README.md (#31)
ItsMePepijn Oct 30, 2023
8ba0994
added workflows
JensvandeWiel Oct 30, 2023
604eaba
Update pull_request.yml (#38)
JensvandeWiel Oct 31, 2023
4ef591f
Add steamcmdpath config variable (#41)
JensvandeWiel Oct 31, 2023
7b65ab8
added better server state control
JensvandeWiel Oct 31, 2023
6aa9a01
Update README.md (#44)
JensvandeWiel Oct 31, 2023
0888303
Update README.md (#45)
ItsMePepijn Oct 31, 2023
a85bc58
Added button to open server files next to profile name (#47)
Ivan0348 Oct 31, 2023
b4e4d7c
Revert "Added button to open server files next to profile name (#47)"
JensvandeWiel Nov 1, 2023
46e10a1
Revert "Update README.md (#45)"
JensvandeWiel Nov 1, 2023
7dd2611
Revert "Update README.md (#44)"
JensvandeWiel Nov 1, 2023
444988d
Revert "added better server state control"
JensvandeWiel Nov 1, 2023
43e34ce
Revert "Add steamcmdpath config variable (#41)"
JensvandeWiel Nov 1, 2023
6d48621
Revert "Update pull_request.yml (#38)"
JensvandeWiel Nov 1, 2023
429b9ca
Revert "added workflows"
JensvandeWiel Nov 1, 2023
87ca635
Revert "Update README.md (#31)"
JensvandeWiel Nov 1, 2023
d48d1e5
Merge branch 'main' into 28-add-rcon-panel
JensvandeWiel Nov 1, 2023
61005bd
added parsing for servermap
JensvandeWiel Nov 1, 2023
4c9bc35
re-ordered server tabs
JensvandeWiel Nov 1, 2023
c92a472
added onServerStart event
JensvandeWiel Nov 1, 2023
7257b13
tab refactoring
JensvandeWiel Nov 1, 2023
61ace9d
added basic console layout
JensvandeWiel Nov 1, 2023
e9cf3f5
inherit serverstatus from parent
JensvandeWiel Nov 1, 2023
be21008
added basic terminal
JensvandeWiel Nov 1, 2023
9e443ed
added rcon console
JensvandeWiel Nov 1, 2023
8164b94
refactored to do it the react way ;)
JensvandeWiel Nov 1, 2023
9d01e56
cleaned code
JensvandeWiel Nov 1, 2023
59b209f
refacored it more into the react way
JensvandeWiel Nov 1, 2023
41b4f49
use one definition type
JensvandeWiel Nov 1, 2023
6e54466
fix spacing
JensvandeWiel Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
JensvandeWiel marked this conversation as resolved.
Show resolved Hide resolved
</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()
ItsMePepijn marked this conversation as resolved.
Show resolved Hide resolved

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)
JensvandeWiel marked this conversation as resolved.
Show resolved Hide resolved
go func() {
_ = s.Command.Wait()

Expand Down
Loading