From ba504bfc9c7403c68185d44035a70770c2e73c8a Mon Sep 17 00:00:00 2001 From: pepijn <68758035+ItsMePepijn@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:37:00 +0100 Subject: [PATCH 01/29] Update README.md (#31) --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c2a9cff..79458ad 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # ArkAscendedServerManager # :warning: This project is in very early stages -The game itself is not released yet so for now we are working on scaffolding etc. ## Contribute Join the discord and ask for the role, or start making pull requests on this repo! From 8ba0994f78b69507e60eb5e63a0bcfa5dcd35523 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Mon, 30 Oct 2023 14:09:16 +0000 Subject: [PATCH 02/29] added workflows --- .github/workflows/nightly.yaml | 50 ++++++++++++++++++++++++++++++ .github/workflows/pull_request.yml | 37 ++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 .github/workflows/nightly.yaml create mode 100644 .github/workflows/pull_request.yml diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml new file mode 100644 index 0000000..55a864d --- /dev/null +++ b/.github/workflows/nightly.yaml @@ -0,0 +1,50 @@ +name: Nightly AASM Release + +on: + push: + branches: + - main + +jobs: + build: + strategy: + fail-fast: false + matrix: + build: + - name: Ark-Ascended-Server-Manager.exe + platform: windows/amd64 + os: windows-latest + runs-on: ${{ matrix.build.os }} + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Set direct proxy + run: go env -w GOPROXY=direct + - run: go install github.com/wailsapp/wails/cmd/wails@latest + - uses: dAppServer/wails-build-action@v2.2 + with: + build-name: ${{ matrix.build.name }} + build-platform: ${{ matrix.build.platform }} + build: true + nsis: true + package: false + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: AASM Installer + path: build/bin/*.exe + + - name: Upload Nightly Release + uses: andelf/nightly-release@main + with: + tag_name: nightly + name: 'Desktop App Nightly Release ${{ github.run_number }}' + prerelease: true + body: 'This is a nightly release of the AASM. Its unstable compared to the official releases, use it with caution!' + files: | + build/bin/*.exe + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..b9f6d9e --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,37 @@ +name: AASM Pull Request Build + +on: + pull_request: + types: + - opened + - synchronize + +jobs: + build: + strategy: + fail-fast: false + matrix: + build: + - name: Ark-Ascended-Server-Manager.exe + platform: windows/amd64 + os: windows-latest + runs-on: ${{ matrix.build.os }} + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Set direct proxy + run: go env -w GOPROXY=direct + - run: go install github.com/wailsapp/wails/cmd/wails@latest + - uses: dAppServer/wails-build-action@v2.2 + with: + build-name: ${{ matrix.build.name }} + build-platform: ${{ matrix.build.platform }} + build: true + nsis: true + package: false + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: AASM Artifacts + path: build/bin/*.exe \ No newline at end of file From 604eaba7c35ad584091cfd6fb5cf8c3c1f4a5353 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:17:39 +0100 Subject: [PATCH 03/29] Update pull_request.yml (#38) * Update pull_request.yml * Update pull_request.yml --- .github/workflows/pull_request.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b9f6d9e..c976f5a 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -5,6 +5,9 @@ on: types: - opened - synchronize + schedule: + - cron: "0 21 * * *" + jobs: build: @@ -34,4 +37,4 @@ jobs: uses: actions/upload-artifact@v2 with: name: AASM Artifacts - path: build/bin/*.exe \ No newline at end of file + path: build/bin/*.exe From 4ef591f96f93e06c8f7d2e4f4ca35d6901c4cee9 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:21:52 +0100 Subject: [PATCH 04/29] Add steamcmdpath config variable (#41) * added steamCMDPath config var for install * enhanced return val check steamCMD can return non null return value without failing --- config/config.go | 17 ++++++++++++----- installer/installer_controller.go | 18 +++++++++++++----- main.go | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 383c1ac..4ea519d 100644 --- a/config/config.go +++ b/config/config.go @@ -13,6 +13,7 @@ import ( // region Config struct type Config struct { + SteamCMDPath string `json:"steamCMDPath"` } // endregion @@ -21,7 +22,7 @@ type Config struct { type ConfigController struct { ctx context.Context configFileDir string - Config Config + Config *Config } // NewConfigController creates a new ConfigController application struct @@ -43,6 +44,10 @@ func NewConfigController() *ConfigController { func (c *ConfigController) Startup(ctx context.Context) { c.ctx = ctx + //get and set config + c.GetConfig() + c.SaveConfig() + } func (c *ConfigController) GetConfig() bool { @@ -57,12 +62,14 @@ func (c *ConfigController) GetConfig() bool { } // Check if the config file exists - _, err := os.Stat(path.Join(c.configFileDir, "config.json")) + _, err := os.Stat(path.Join(c.configFileDir)) if err != nil { if os.IsNotExist(err) { runtime.LogDebug(c.ctx, "Config file does not exist, returning new configuration") //TODO set new config - c.Config = Config{} + c.Config = &Config{} + //save so that the file exists + c.SaveConfig() return true } runtime.LogError(c.ctx, "Error reading config file: "+err.Error()) @@ -70,7 +77,7 @@ func (c *ConfigController) GetConfig() bool { } //It exists so read the file - cf, err := os.ReadFile(path.Join(c.configFileDir, "config.json")) + cf, err := os.ReadFile(path.Join(c.configFileDir)) if err != nil { runtime.LogError(c.ctx, "Error reading config file: "+err.Error()) return false @@ -84,7 +91,7 @@ func (c *ConfigController) GetConfig() bool { return false } - c.Config = conf + c.Config = &conf return true } diff --git a/installer/installer_controller.go b/installer/installer_controller.go index 861e741..f22b52a 100644 --- a/installer/installer_controller.go +++ b/installer/installer_controller.go @@ -3,6 +3,7 @@ package installer import ( "context" "fmt" + "github.com/JensvandeWiel/ArkAscendedServerManager/config" "github.com/jensvandewiel/gosteamcmd" "github.com/jensvandewiel/gosteamcmd/console" "github.com/wailsapp/wails/v2/pkg/runtime" @@ -12,11 +13,14 @@ import ( ) type InstallerController struct { - ctx context.Context + ctx context.Context + config *config.ConfigController } -func NewInstallerController() *InstallerController { - return &InstallerController{} +func NewInstallerController(c *config.ConfigController) *InstallerController { + return &InstallerController{ + config: c, + } } func (c *InstallerController) Startup(ctx context.Context) { @@ -34,13 +38,17 @@ Events: // Install installs the server and returns true is successful and error and false if failed func (c *InstallerController) Install(installPath string) error { + //get steamcmd path + c.config.GetConfig() + steamCMDPath := c.config.Config.SteamCMDPath + prompts := []*gosteamcmd.Prompt{ gosteamcmd.ForceInstallDir(installPath), gosteamcmd.Login("", "", ""), gosteamcmd.AppUpdate(2430930, "", true), } - cmd := gosteamcmd.New(io.Discard, prompts, "") + cmd := gosteamcmd.New(io.Discard, prompts, steamCMDPath) cmd.Console.Parser.OnInformationReceived = func(action console.Action, progress float64, currentWritten, total uint64) { actionString := "" @@ -80,7 +88,7 @@ func (c *InstallerController) Install(installPath string) error { } - if i != 0 { + if i != 0 && i != 7 { return fmt.Errorf("failed to install: returned non 0 return code: " + strconv.Itoa(int(i))) } return nil diff --git a/main.go b/main.go index 188c225..205dec0 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,7 @@ func main() { app := NewApp() c := config.NewConfigController() s := server.NewServerController() - i := installer.NewInstallerController() + i := installer.NewInstallerController(c) h := helpers.NewHelpersController() // Create application with options From 7b65ab8798a6a8d3a36be3e578e97b8bb9224697 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Tue, 31 Oct 2023 18:44:25 +0100 Subject: [PATCH 05/29] 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 --- frontend/src/pages/Server.tsx | 81 +++++++++++++++++++++++++------ go.mod | 1 + go.sum | 2 + installer/installer_controller.go | 3 +- server/server.go | 72 ++++++++++++++++++++++----- server/server_controller.go | 20 +++++++- 6 files changed, 150 insertions(+), 29 deletions(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 22d8164..0595fec 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -1,4 +1,17 @@ -import {Button, ButtonGroup, Card, Input, Tab, TabList, Tabs} from "@mui/joy"; +import { + Button, + ButtonGroup, + Card, DialogActions, + DialogContent, + DialogTitle, + Divider, + Input, + Modal, + ModalDialog, + Tab, + TabList, + Tabs +} from "@mui/joy"; import {Settings} from "./server/Settings"; import {General} from "./server/General"; import {useEffect, useState} from "react"; @@ -6,12 +19,14 @@ import {server} from "../../wailsjs/go/models"; import { CheckServerInstalled, ForceStopServer, - GetServer, + GetServer, GetServerStatus, SaveServer, StartServer } from "../../wailsjs/go/server/ServerController"; import {InstallUpdater} from "./InstallUpdater"; import {useAlert} from "../components/AlertProvider"; +import {EventsOff, EventsOn} from "../../wailsjs/runtime"; +import {IconAlertCircleFilled} from "@tabler/icons-react"; type Props = { @@ -30,8 +45,12 @@ export const Server = ({id, className}: Props) => { const [serv, setServ] = useState(defaultServer) const [isInstalled, setIsInstalled] = useState(false) + const [serverStatus, setServerStatus] = useState(false) + const [forceStopModalOpen, setForceStopModalOpen] = useState(false) const {addAlert} = useAlert() + //region useEffect land :) + useEffect(() => { if (serv.id >= 0) { CheckServerInstalled(serv.id).then((val) => setIsInstalled(val)).catch((reason) => console.error(reason)) @@ -40,28 +59,41 @@ export const Server = ({id, className}: Props) => { useEffect(() => { if (id !== undefined) { - GetServer(id).then((s) => setServ(s)).catch((reason) => console.error(reason)) + GetServer(id).then((s) => {setServ(s)}).catch((reason) => console.error(reason)) } }, [id]); useEffect(() => { - if (serv.id == -1) { - - } else { + if (serv.id >= 0) { SaveServer(serv).catch((reason) => console.error(reason)) } - - }, [serv]); + useEffect(() => { + EventsOn("onServerExit", () => setServerStatus(false)) + return () => EventsOff("onServerExit") + }, []); + //endregion + function onServerStartButtonClicked() { - StartServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}) + StartServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}).then(() => setTimeout(function () { + refreshServerStatus() + }, 200)) + } - function onServerStopButtonClicked() { - ForceStopServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}) + function onServerForceStopButtonClicked() { + ForceStopServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}).then(() => setServerStatus(false)) } + function refreshServerStatus() { + GetServerStatus(serv.id).catch((reason) => {console.error("serverstatus: " + reason); addAlert(reason, "danger")}).then((s) => { + if (typeof s === "boolean") { + setServerStatus(s) + } + }) + + } if (id !== undefined) { return ( @@ -73,9 +105,30 @@ export const Server = ({id, className}: Props) => {
- - + + + + setForceStopModalOpen(false)}> + + + + Confirmation + + + + Are you sure you want to forcefully stop the server? No save action will be performed! + + + + + + +
@@ -101,4 +154,4 @@ export const Server = ({id, className}: Props) => { ); } -}; \ No newline at end of file +}; diff --git a/go.mod b/go.mod index bb30606..da94d64 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.18 require ( github.com/adrg/xdg v0.4.0 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 github.com/wailsapp/wails/v2 v2.6.0 ) diff --git a/go.sum b/go.sum index 97b00bd..b4ee6bf 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4P github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= github.com/jensvandewiel/gosteamcmd v0.1.2 h1:NHichoj0v3GvSVN2Fn36dSOLosHAytpaKnLnDHTMQPI= github.com/jensvandewiel/gosteamcmd v0.1.2/go.mod h1:Y7hP+iXFIOs8II68VrbdR+W1wwpB8LXYe9lfgjyTLIw= +github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 h1:WjT3fLi9n8YWh/Ih8Q1LHAPsTqGddPcHqscN+PJ3i68= +github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ= github.com/labstack/echo/v4 v4.11.2 h1:T+cTLQxWCDfqDEoydYm5kCobjmHwOwcv4OJAPHilmdE= github.com/labstack/echo/v4 v4.11.2/go.mod h1:UcGuQ8V6ZNRmSweBIJkPvGfwCMIlFmiqrPqiEBfPYws= github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8= diff --git a/installer/installer_controller.go b/installer/installer_controller.go index f22b52a..a821207 100644 --- a/installer/installer_controller.go +++ b/installer/installer_controller.go @@ -43,13 +43,12 @@ func (c *InstallerController) Install(installPath string) error { steamCMDPath := c.config.Config.SteamCMDPath prompts := []*gosteamcmd.Prompt{ - gosteamcmd.ForceInstallDir(installPath), + gosteamcmd.ForceInstallDir("\"" + installPath + "\""), gosteamcmd.Login("", "", ""), gosteamcmd.AppUpdate(2430930, "", true), } cmd := gosteamcmd.New(io.Discard, prompts, steamCMDPath) - cmd.Console.Parser.OnInformationReceived = func(action console.Action, progress float64, currentWritten, total uint64) { actionString := "" diff --git a/server/server.go b/server/server.go index dae35ec..1edf473 100644 --- a/server/server.go +++ b/server/server.go @@ -1,8 +1,12 @@ package server import ( + "context" "fmt" + "github.com/keybase/go-ps" + "github.com/wailsapp/wails/v2/pkg/runtime" "os/exec" + "path" "strconv" ) @@ -14,6 +18,7 @@ type GameUserSettings struct { type Server struct { Command *exec.Cmd `json:"-"` + ctx context.Context //CONFIGURATION VARIABLES @@ -61,14 +66,19 @@ func (s *Server) Start() error { return fmt.Errorf("error starting server: failed updating server configuration: %v", err) } - if s.Command != nil { - return fmt.Errorf("error starting server: server is already started") - } - - s.Command = exec.Command(path.Join(s.ServerPath, "ShooterGame\\Binaries\\Win64\\ArkAscendedServer.exe"), s.CreateArguments()) - err = s.Command.Start() - if err != nil { - return fmt.Errorf("error starting server: %v", err) + if s.IsServerRunning() { + return fmt.Errorf("error starting server: server is already running") + } else { + s.Command = exec.Command(path.Join(s.ServerPath, "ShooterGame\\Binaries\\Win64\\ArkAscendedServer.exe"), s.CreateArguments()) + err = s.Command.Start() + if err != nil { + return fmt.Errorf("error starting server: %v", err) + } + go func() { + _ = s.Command.Wait() + + runtime.EventsEmit(s.ctx, "onServerExit", s.Id) + }() } return nil @@ -78,21 +88,61 @@ func (s *Server) Start() error { func (s *Server) ForceStop() error { if s.Command == nil { - return fmt.Errorf("error stopping server: s.Command is nil") + return fmt.Errorf("error stopping server: server is not running") + } + if s.Command.Process == nil { + return fmt.Errorf("error stopping server: server is not running") + } + + if !s.IsServerRunning() { + return fmt.Errorf("error stopping server: server is not running") } + err := s.Command.Process.Kill() if err != nil { return fmt.Errorf("error stopping server: %v", err) } - s.Command = nil - return nil } +// GetServerStatus returns the status of the server. +func (s *Server) IsServerRunning() bool { + + if s.Command == nil { + return false + } + + if s.Command.Process == nil { + return false + } + + // Retrieve a list of all processes. + processList, err := ps.Processes() + if err != nil { + return false + } + + // Iterate through the list of processes and check if the specified PID exists. + processFound := false + for _, process := range processList { + if process.Pid() == s.Command.Process.Pid { + processFound = true + break + } + } + + if processFound { + return true + } else { + return false + } +} + func (s *Server) CreateArguments() string { basePrompt := s.ServerMap + "?listen" basePrompt += "?MultiHome=" + s.IpAddress + basePrompt += "?SessionName=" + s.ServerName basePrompt += "?Port=" + strconv.Itoa(s.ServerPort) basePrompt += "?QueryPort=" + strconv.Itoa(s.QueryPort) basePrompt += "?RCONEnabled=true?RCONServerGameLogBuffer=600?RCONPort=" + strconv.Itoa(s.RCONPort) diff --git a/server/server_controller.go b/server/server_controller.go index a6847d2..e99396c 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -74,9 +74,11 @@ func (c *ServerController) GetServerWithError(id int, addToMap bool) (*Server, e } runtime.EventsEmit(c.ctx, "gotServer", s.Id) + s.ctx = c.ctx return &s, nil } else { runtime.EventsEmit(c.ctx, "gotServer", server.Id) + server.ctx = c.ctx return server, nil } } @@ -107,6 +109,7 @@ func (c *ServerController) CreateServerWithError(saveToConfig bool) (int, *Serve } runtime.EventsEmit(c.ctx, "serverCreated", NewServer.Id) + NewServer.ctx = c.ctx return id, &NewServer, nil } @@ -269,6 +272,7 @@ func (c *ServerController) SaveServer(server Server) error { } server.Command = oldServ.Command + server.ctx = c.ctx err = c.SaveServerWithError(&server) if err != nil { @@ -386,14 +390,14 @@ func (c *ServerController) ForceStopServer(id int) error { server, exists := c.Servers[id] if !exists { - err := fmt.Errorf("error starting server " + strconv.Itoa(id) + ": server does not exist in map") + err := fmt.Errorf("error stopping server " + strconv.Itoa(id) + ": server does not exist in map") runtime.LogError(c.ctx, err.Error()) return err } err := server.ForceStop() if err != nil { - err := fmt.Errorf("error starting server " + strconv.Itoa(id) + ": " + err.Error()) + err := fmt.Errorf("error stopping server " + strconv.Itoa(id) + ": " + err.Error()) runtime.LogError(c.ctx, err.Error()) return err } @@ -401,6 +405,18 @@ func (c *ServerController) ForceStopServer(id int) error { return nil } +func (c *ServerController) GetServerStatus(id int) (bool, error) { + server, exists := c.Servers[id] + if !exists { + err := fmt.Errorf("error getting server status " + strconv.Itoa(id) + ": server does not exist in map") + runtime.LogError(c.ctx, err.Error()) + return false, err + } + + status := server.IsServerRunning() + return status, nil +} + //endregion //region ServerController helper functions From 6aa9a0176420e0d2f3bf312849152a3e9f64340e Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Tue, 31 Oct 2023 19:30:32 +0100 Subject: [PATCH 06/29] Update README.md (#44) --- README.md | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 79458ad..85166b7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,23 @@ -# ArkAscendedServerManager -# :warning: This project is in very early stages +# Ark Ascended Server Manager +##### A multi server manager for the game: ARK: Survival Ascended + + +### Why +For ARK: SE there only existed a closed source with relic like code🧓. When they made the announcement that they won't make a new version/update their software for ARK: Ascended we stepped in to fill the void, our goal is to make this software easy to use and cross platform (when we get linux binaries for the servers). +### How to use +For now the only way is to use the [nightly](https://github.com/JensvandeWiel/ArkAscendedServerManager/releases/tag/nightly) release, this is because we are not yer ready to release a alpha. You can download the installer and install! **(nightly is unstable and does not have auto updating at this time!)** -## Contribute -Join the discord and ask for the role, or start making pull requests on this repo! -https://discord.gg/7g8Fx6wmYp +#### Setting steamcmd path for first use +Steamcmd is not yet packaged with the app, if you want to install a server you can install steamcmd to your path on your computer (e.g.: with [scoop](https://scoop.sh/#/apps?q=steamcmd&id=aed594e2b74d756901130cc098dfb2f70679d8dc)) or you can follow the guide below. -## Build -1. Follow wails installation: https://wails.io/docs/gettingstarted/installation -2. Run wails dev or wails build + 1. Install the app using the installer + 2. Run the app for the first time + 3. Click [windows key] + R and enter `%localappdata%\ArkAscendedServerManager` + 4. Open config.json + 5. Edit the "steamCMDPath" to contain something like this: `"steamCMDPath": "C:\\steamcmd\\steamcmd.exe"` (**WATCH OUT** A backslash only works like `\\` this is because `\` on its own is a ecape char) + 6. Start the app again and create a server. + 7. :tada: You can run your server! +### Contributing +Ask one of **the core contributors** in the [discord](https://discord.gg/pBfmFuK2Wa) to give you contributor role, then you can ask what to do. Or you can just make a pull request with some code you've written. +### :warning: Watch out :warning: +We have not officialy released anything yet, the alpha release is planned but not yet released! This codebase is very young and is not yet release ready. From 088830315f89d9f11931eea6f7cba43e073d5b78 Mon Sep 17 00:00:00 2001 From: pepijn <68758035+ItsMePepijn@users.noreply.github.com> Date: Tue, 31 Oct 2023 19:47:06 +0100 Subject: [PATCH 07/29] Update README.md (#45) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 85166b7..9ca4487 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@ ### Why For ARK: SE there only existed a closed source with relic like code🧓. When they made the announcement that they won't make a new version/update their software for ARK: Ascended we stepped in to fill the void, our goal is to make this software easy to use and cross platform (when we get linux binaries for the servers). ### How to use -For now the only way is to use the [nightly](https://github.com/JensvandeWiel/ArkAscendedServerManager/releases/tag/nightly) release, this is because we are not yer ready to release a alpha. You can download the installer and install! **(nightly is unstable and does not have auto updating at this time!)** +For now the only way is to use the [nightly](https://github.com/JensvandeWiel/ArkAscendedServerManager/releases/tag/nightly) release, this is because we are not yet ready to release an alpha version. You can download the installer and install! **(nightly is unstable and does not have auto updating at this time!)** #### Setting steamcmd path for first use -Steamcmd is not yet packaged with the app, if you want to install a server you can install steamcmd to your path on your computer (e.g.: with [scoop](https://scoop.sh/#/apps?q=steamcmd&id=aed594e2b74d756901130cc098dfb2f70679d8dc)) or you can follow the guide below. +Steamcmd is not yet packaged with the app, if you want to create a server with AASM you can install steamcmd to your path on your computer (e.g.: with [scoop](https://scoop.sh/#/apps?q=steamcmd&id=aed594e2b74d756901130cc098dfb2f70679d8dc)) or you can follow the guide below. 1. Install the app using the installer 2. Run the app for the first time @@ -18,6 +18,6 @@ Steamcmd is not yet packaged with the app, if you want to install a server you c 6. Start the app again and create a server. 7. :tada: You can run your server! ### Contributing -Ask one of **the core contributors** in the [discord](https://discord.gg/pBfmFuK2Wa) to give you contributor role, then you can ask what to do. Or you can just make a pull request with some code you've written. +Ask one of **the core contributors** in the [discord server](https://discord.gg/pBfmFuK2Wa) to give you contributor role, then you can ask what to do. Or you can just make a pull request with some code you've written. ### :warning: Watch out :warning: -We have not officialy released anything yet, the alpha release is planned but not yet released! This codebase is very young and is not yet release ready. +We have not officialy released anything yet, the alpha release is planned but not yet released! This codebase is very young and might be unstable. From a85bc582aea46d0910b8272f45b7cae7f3bebb39 Mon Sep 17 00:00:00 2001 From: Ivan Oonincx <103519966+Ivan0348@users.noreply.github.com> Date: Tue, 31 Oct 2023 21:15:43 +0100 Subject: [PATCH 08/29] Added button to open server files next to profile name (#47) --- frontend/src/pages/Server.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 0595fec..88d4fb2 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -4,13 +4,13 @@ import { Card, DialogActions, DialogContent, DialogTitle, - Divider, + Divider, IconButton, Input, Modal, ModalDialog, Tab, TabList, - Tabs + Tabs, Tooltip } from "@mui/joy"; import {Settings} from "./server/Settings"; import {General} from "./server/General"; @@ -25,8 +25,8 @@ import { } from "../../wailsjs/go/server/ServerController"; import {InstallUpdater} from "./InstallUpdater"; import {useAlert} from "../components/AlertProvider"; -import {EventsOff, EventsOn} from "../../wailsjs/runtime"; -import {IconAlertCircleFilled} from "@tabler/icons-react"; +import {BrowserOpenURL, EventsOff, EventsOn} from "../../wailsjs/runtime"; +import {IconAlertCircleFilled, IconExternalLink} from "@tabler/icons-react"; type Props = { @@ -100,7 +100,12 @@ export const Server = ({id, className}: Props) => { {isInstalled? (
-

{} setServ((p) => ({ ...p, serverAlias: e.target.value }))}/>

+
+ setServ((p) => ({ ...p, serverAlias: e.target.value }))}/> + + BrowserOpenURL("file:///" + serv.serverPath)}> + +
From b4e4d7cc9573aa4e3b62977f825e91e3ec1d019b Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:12:19 +0100 Subject: [PATCH 09/29] Revert "Added button to open server files next to profile name (#47)" This reverts commit a85bc582aea46d0910b8272f45b7cae7f3bebb39. --- frontend/src/pages/Server.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 88d4fb2..0595fec 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -4,13 +4,13 @@ import { Card, DialogActions, DialogContent, DialogTitle, - Divider, IconButton, + Divider, Input, Modal, ModalDialog, Tab, TabList, - Tabs, Tooltip + Tabs } from "@mui/joy"; import {Settings} from "./server/Settings"; import {General} from "./server/General"; @@ -25,8 +25,8 @@ import { } from "../../wailsjs/go/server/ServerController"; import {InstallUpdater} from "./InstallUpdater"; import {useAlert} from "../components/AlertProvider"; -import {BrowserOpenURL, EventsOff, EventsOn} from "../../wailsjs/runtime"; -import {IconAlertCircleFilled, IconExternalLink} from "@tabler/icons-react"; +import {EventsOff, EventsOn} from "../../wailsjs/runtime"; +import {IconAlertCircleFilled} from "@tabler/icons-react"; type Props = { @@ -100,12 +100,7 @@ export const Server = ({id, className}: Props) => { {isInstalled? (
-
- setServ((p) => ({ ...p, serverAlias: e.target.value }))}/> - - BrowserOpenURL("file:///" + serv.serverPath)}> - -
+

{} setServ((p) => ({ ...p, serverAlias: e.target.value }))}/>

From 46e10a1a79f741726bddfc4d956d537d11a36960 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:12:19 +0100 Subject: [PATCH 10/29] Revert "Update README.md (#45)" This reverts commit 088830315f89d9f11931eea6f7cba43e073d5b78. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9ca4487..85166b7 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@ ### Why For ARK: SE there only existed a closed source with relic like code🧓. When they made the announcement that they won't make a new version/update their software for ARK: Ascended we stepped in to fill the void, our goal is to make this software easy to use and cross platform (when we get linux binaries for the servers). ### How to use -For now the only way is to use the [nightly](https://github.com/JensvandeWiel/ArkAscendedServerManager/releases/tag/nightly) release, this is because we are not yet ready to release an alpha version. You can download the installer and install! **(nightly is unstable and does not have auto updating at this time!)** +For now the only way is to use the [nightly](https://github.com/JensvandeWiel/ArkAscendedServerManager/releases/tag/nightly) release, this is because we are not yer ready to release a alpha. You can download the installer and install! **(nightly is unstable and does not have auto updating at this time!)** #### Setting steamcmd path for first use -Steamcmd is not yet packaged with the app, if you want to create a server with AASM you can install steamcmd to your path on your computer (e.g.: with [scoop](https://scoop.sh/#/apps?q=steamcmd&id=aed594e2b74d756901130cc098dfb2f70679d8dc)) or you can follow the guide below. +Steamcmd is not yet packaged with the app, if you want to install a server you can install steamcmd to your path on your computer (e.g.: with [scoop](https://scoop.sh/#/apps?q=steamcmd&id=aed594e2b74d756901130cc098dfb2f70679d8dc)) or you can follow the guide below. 1. Install the app using the installer 2. Run the app for the first time @@ -18,6 +18,6 @@ Steamcmd is not yet packaged with the app, if you want to create a server with A 6. Start the app again and create a server. 7. :tada: You can run your server! ### Contributing -Ask one of **the core contributors** in the [discord server](https://discord.gg/pBfmFuK2Wa) to give you contributor role, then you can ask what to do. Or you can just make a pull request with some code you've written. +Ask one of **the core contributors** in the [discord](https://discord.gg/pBfmFuK2Wa) to give you contributor role, then you can ask what to do. Or you can just make a pull request with some code you've written. ### :warning: Watch out :warning: -We have not officialy released anything yet, the alpha release is planned but not yet released! This codebase is very young and might be unstable. +We have not officialy released anything yet, the alpha release is planned but not yet released! This codebase is very young and is not yet release ready. From 7dd26118b7401e3c232e293536a799bc7fa40373 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:12:19 +0100 Subject: [PATCH 11/29] Revert "Update README.md (#44)" This reverts commit 6aa9a0176420e0d2f3bf312849152a3e9f64340e. --- README.md | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 85166b7..79458ad 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,10 @@ -# Ark Ascended Server Manager -##### A multi server manager for the game: ARK: Survival Ascended - - -### Why -For ARK: SE there only existed a closed source with relic like code🧓. When they made the announcement that they won't make a new version/update their software for ARK: Ascended we stepped in to fill the void, our goal is to make this software easy to use and cross platform (when we get linux binaries for the servers). -### How to use -For now the only way is to use the [nightly](https://github.com/JensvandeWiel/ArkAscendedServerManager/releases/tag/nightly) release, this is because we are not yer ready to release a alpha. You can download the installer and install! **(nightly is unstable and does not have auto updating at this time!)** +# ArkAscendedServerManager +# :warning: This project is in very early stages -#### Setting steamcmd path for first use -Steamcmd is not yet packaged with the app, if you want to install a server you can install steamcmd to your path on your computer (e.g.: with [scoop](https://scoop.sh/#/apps?q=steamcmd&id=aed594e2b74d756901130cc098dfb2f70679d8dc)) or you can follow the guide below. +## Contribute +Join the discord and ask for the role, or start making pull requests on this repo! +https://discord.gg/7g8Fx6wmYp - 1. Install the app using the installer - 2. Run the app for the first time - 3. Click [windows key] + R and enter `%localappdata%\ArkAscendedServerManager` - 4. Open config.json - 5. Edit the "steamCMDPath" to contain something like this: `"steamCMDPath": "C:\\steamcmd\\steamcmd.exe"` (**WATCH OUT** A backslash only works like `\\` this is because `\` on its own is a ecape char) - 6. Start the app again and create a server. - 7. :tada: You can run your server! -### Contributing -Ask one of **the core contributors** in the [discord](https://discord.gg/pBfmFuK2Wa) to give you contributor role, then you can ask what to do. Or you can just make a pull request with some code you've written. -### :warning: Watch out :warning: -We have not officialy released anything yet, the alpha release is planned but not yet released! This codebase is very young and is not yet release ready. +## Build +1. Follow wails installation: https://wails.io/docs/gettingstarted/installation +2. Run wails dev or wails build From 444988d52b93601a9c3a34b4c8793e5cfd4ff31f Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:12:19 +0100 Subject: [PATCH 12/29] Revert "added better server state control" This reverts commit 7b65ab8798a6a8d3a36be3e578e97b8bb9224697. --- frontend/src/pages/Server.tsx | 81 ++++++------------------------- go.mod | 1 - go.sum | 2 - installer/installer_controller.go | 3 +- server/server.go | 72 +++++---------------------- server/server_controller.go | 20 +------- 6 files changed, 29 insertions(+), 150 deletions(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 0595fec..22d8164 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -1,17 +1,4 @@ -import { - Button, - ButtonGroup, - Card, DialogActions, - DialogContent, - DialogTitle, - Divider, - Input, - Modal, - ModalDialog, - Tab, - TabList, - Tabs -} from "@mui/joy"; +import {Button, ButtonGroup, Card, Input, Tab, TabList, Tabs} from "@mui/joy"; import {Settings} from "./server/Settings"; import {General} from "./server/General"; import {useEffect, useState} from "react"; @@ -19,14 +6,12 @@ import {server} from "../../wailsjs/go/models"; import { CheckServerInstalled, ForceStopServer, - GetServer, GetServerStatus, + GetServer, SaveServer, StartServer } from "../../wailsjs/go/server/ServerController"; import {InstallUpdater} from "./InstallUpdater"; import {useAlert} from "../components/AlertProvider"; -import {EventsOff, EventsOn} from "../../wailsjs/runtime"; -import {IconAlertCircleFilled} from "@tabler/icons-react"; type Props = { @@ -45,12 +30,8 @@ export const Server = ({id, className}: Props) => { const [serv, setServ] = useState(defaultServer) const [isInstalled, setIsInstalled] = useState(false) - const [serverStatus, setServerStatus] = useState(false) - const [forceStopModalOpen, setForceStopModalOpen] = useState(false) const {addAlert} = useAlert() - //region useEffect land :) - useEffect(() => { if (serv.id >= 0) { CheckServerInstalled(serv.id).then((val) => setIsInstalled(val)).catch((reason) => console.error(reason)) @@ -59,41 +40,28 @@ export const Server = ({id, className}: Props) => { useEffect(() => { if (id !== undefined) { - GetServer(id).then((s) => {setServ(s)}).catch((reason) => console.error(reason)) + GetServer(id).then((s) => setServ(s)).catch((reason) => console.error(reason)) } }, [id]); useEffect(() => { - if (serv.id >= 0) { + if (serv.id == -1) { + + } else { SaveServer(serv).catch((reason) => console.error(reason)) } - }, [serv]); - useEffect(() => { - EventsOn("onServerExit", () => setServerStatus(false)) - return () => EventsOff("onServerExit") - }, []); - //endregion - function onServerStartButtonClicked() { - StartServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}).then(() => setTimeout(function () { - refreshServerStatus() - }, 200)) + }, [serv]); + function onServerStartButtonClicked() { + StartServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}) } - function onServerForceStopButtonClicked() { - ForceStopServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}).then(() => setServerStatus(false)) + function onServerStopButtonClicked() { + ForceStopServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}) } - function refreshServerStatus() { - GetServerStatus(serv.id).catch((reason) => {console.error("serverstatus: " + reason); addAlert(reason, "danger")}).then((s) => { - if (typeof s === "boolean") { - setServerStatus(s) - } - }) - - } if (id !== undefined) { return ( @@ -105,30 +73,9 @@ export const Server = ({id, className}: Props) => {
- - - + + - setForceStopModalOpen(false)}> - - - - Confirmation - - - - Are you sure you want to forcefully stop the server? No save action will be performed! - - - - - - -
@@ -154,4 +101,4 @@ export const Server = ({id, className}: Props) => { ); } -}; +}; \ No newline at end of file diff --git a/go.mod b/go.mod index da94d64..bb30606 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.18 require ( github.com/adrg/xdg v0.4.0 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 github.com/wailsapp/wails/v2 v2.6.0 ) diff --git a/go.sum b/go.sum index b4ee6bf..97b00bd 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,6 @@ github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4P github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= github.com/jensvandewiel/gosteamcmd v0.1.2 h1:NHichoj0v3GvSVN2Fn36dSOLosHAytpaKnLnDHTMQPI= github.com/jensvandewiel/gosteamcmd v0.1.2/go.mod h1:Y7hP+iXFIOs8II68VrbdR+W1wwpB8LXYe9lfgjyTLIw= -github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 h1:WjT3fLi9n8YWh/Ih8Q1LHAPsTqGddPcHqscN+PJ3i68= -github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ= github.com/labstack/echo/v4 v4.11.2 h1:T+cTLQxWCDfqDEoydYm5kCobjmHwOwcv4OJAPHilmdE= github.com/labstack/echo/v4 v4.11.2/go.mod h1:UcGuQ8V6ZNRmSweBIJkPvGfwCMIlFmiqrPqiEBfPYws= github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8= diff --git a/installer/installer_controller.go b/installer/installer_controller.go index a821207..f22b52a 100644 --- a/installer/installer_controller.go +++ b/installer/installer_controller.go @@ -43,12 +43,13 @@ func (c *InstallerController) Install(installPath string) error { steamCMDPath := c.config.Config.SteamCMDPath prompts := []*gosteamcmd.Prompt{ - gosteamcmd.ForceInstallDir("\"" + installPath + "\""), + gosteamcmd.ForceInstallDir(installPath), gosteamcmd.Login("", "", ""), gosteamcmd.AppUpdate(2430930, "", true), } cmd := gosteamcmd.New(io.Discard, prompts, steamCMDPath) + cmd.Console.Parser.OnInformationReceived = func(action console.Action, progress float64, currentWritten, total uint64) { actionString := "" diff --git a/server/server.go b/server/server.go index 1edf473..dae35ec 100644 --- a/server/server.go +++ b/server/server.go @@ -1,12 +1,8 @@ package server import ( - "context" "fmt" - "github.com/keybase/go-ps" - "github.com/wailsapp/wails/v2/pkg/runtime" "os/exec" - "path" "strconv" ) @@ -18,7 +14,6 @@ type GameUserSettings struct { type Server struct { Command *exec.Cmd `json:"-"` - ctx context.Context //CONFIGURATION VARIABLES @@ -66,19 +61,14 @@ func (s *Server) Start() error { return fmt.Errorf("error starting server: failed updating server configuration: %v", err) } - if s.IsServerRunning() { - return fmt.Errorf("error starting server: server is already running") - } else { - s.Command = exec.Command(path.Join(s.ServerPath, "ShooterGame\\Binaries\\Win64\\ArkAscendedServer.exe"), s.CreateArguments()) - err = s.Command.Start() - if err != nil { - return fmt.Errorf("error starting server: %v", err) - } - go func() { - _ = s.Command.Wait() - - runtime.EventsEmit(s.ctx, "onServerExit", s.Id) - }() + if s.Command != nil { + return fmt.Errorf("error starting server: server is already started") + } + + s.Command = exec.Command(path.Join(s.ServerPath, "ShooterGame\\Binaries\\Win64\\ArkAscendedServer.exe"), s.CreateArguments()) + err = s.Command.Start() + if err != nil { + return fmt.Errorf("error starting server: %v", err) } return nil @@ -88,61 +78,21 @@ func (s *Server) Start() error { func (s *Server) ForceStop() error { if s.Command == nil { - return fmt.Errorf("error stopping server: server is not running") - } - if s.Command.Process == nil { - return fmt.Errorf("error stopping server: server is not running") - } - - if !s.IsServerRunning() { - return fmt.Errorf("error stopping server: server is not running") + return fmt.Errorf("error stopping server: s.Command is nil") } - err := s.Command.Process.Kill() if err != nil { return fmt.Errorf("error stopping server: %v", err) } - return nil -} - -// GetServerStatus returns the status of the server. -func (s *Server) IsServerRunning() bool { + s.Command = nil - if s.Command == nil { - return false - } - - if s.Command.Process == nil { - return false - } - - // Retrieve a list of all processes. - processList, err := ps.Processes() - if err != nil { - return false - } - - // Iterate through the list of processes and check if the specified PID exists. - processFound := false - for _, process := range processList { - if process.Pid() == s.Command.Process.Pid { - processFound = true - break - } - } - - if processFound { - return true - } else { - return false - } + return nil } func (s *Server) CreateArguments() string { basePrompt := s.ServerMap + "?listen" basePrompt += "?MultiHome=" + s.IpAddress - basePrompt += "?SessionName=" + s.ServerName basePrompt += "?Port=" + strconv.Itoa(s.ServerPort) basePrompt += "?QueryPort=" + strconv.Itoa(s.QueryPort) basePrompt += "?RCONEnabled=true?RCONServerGameLogBuffer=600?RCONPort=" + strconv.Itoa(s.RCONPort) diff --git a/server/server_controller.go b/server/server_controller.go index e99396c..a6847d2 100644 --- a/server/server_controller.go +++ b/server/server_controller.go @@ -74,11 +74,9 @@ func (c *ServerController) GetServerWithError(id int, addToMap bool) (*Server, e } runtime.EventsEmit(c.ctx, "gotServer", s.Id) - s.ctx = c.ctx return &s, nil } else { runtime.EventsEmit(c.ctx, "gotServer", server.Id) - server.ctx = c.ctx return server, nil } } @@ -109,7 +107,6 @@ func (c *ServerController) CreateServerWithError(saveToConfig bool) (int, *Serve } runtime.EventsEmit(c.ctx, "serverCreated", NewServer.Id) - NewServer.ctx = c.ctx return id, &NewServer, nil } @@ -272,7 +269,6 @@ func (c *ServerController) SaveServer(server Server) error { } server.Command = oldServ.Command - server.ctx = c.ctx err = c.SaveServerWithError(&server) if err != nil { @@ -390,14 +386,14 @@ func (c *ServerController) ForceStopServer(id int) error { server, exists := c.Servers[id] if !exists { - err := fmt.Errorf("error stopping server " + strconv.Itoa(id) + ": server does not exist in map") + err := fmt.Errorf("error starting server " + strconv.Itoa(id) + ": server does not exist in map") runtime.LogError(c.ctx, err.Error()) return err } err := server.ForceStop() if err != nil { - err := fmt.Errorf("error stopping server " + strconv.Itoa(id) + ": " + err.Error()) + err := fmt.Errorf("error starting server " + strconv.Itoa(id) + ": " + err.Error()) runtime.LogError(c.ctx, err.Error()) return err } @@ -405,18 +401,6 @@ func (c *ServerController) ForceStopServer(id int) error { return nil } -func (c *ServerController) GetServerStatus(id int) (bool, error) { - server, exists := c.Servers[id] - if !exists { - err := fmt.Errorf("error getting server status " + strconv.Itoa(id) + ": server does not exist in map") - runtime.LogError(c.ctx, err.Error()) - return false, err - } - - status := server.IsServerRunning() - return status, nil -} - //endregion //region ServerController helper functions From 43e34ce646574531fae0509b9a5cf7d5c3334cfa Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:12:19 +0100 Subject: [PATCH 13/29] Revert "Add steamcmdpath config variable (#41)" This reverts commit 4ef591f96f93e06c8f7d2e4f4ca35d6901c4cee9. --- config/config.go | 17 +++++------------ installer/installer_controller.go | 18 +++++------------- main.go | 2 +- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/config/config.go b/config/config.go index 4ea519d..383c1ac 100644 --- a/config/config.go +++ b/config/config.go @@ -13,7 +13,6 @@ import ( // region Config struct type Config struct { - SteamCMDPath string `json:"steamCMDPath"` } // endregion @@ -22,7 +21,7 @@ type Config struct { type ConfigController struct { ctx context.Context configFileDir string - Config *Config + Config Config } // NewConfigController creates a new ConfigController application struct @@ -44,10 +43,6 @@ func NewConfigController() *ConfigController { func (c *ConfigController) Startup(ctx context.Context) { c.ctx = ctx - //get and set config - c.GetConfig() - c.SaveConfig() - } func (c *ConfigController) GetConfig() bool { @@ -62,14 +57,12 @@ func (c *ConfigController) GetConfig() bool { } // Check if the config file exists - _, err := os.Stat(path.Join(c.configFileDir)) + _, err := os.Stat(path.Join(c.configFileDir, "config.json")) if err != nil { if os.IsNotExist(err) { runtime.LogDebug(c.ctx, "Config file does not exist, returning new configuration") //TODO set new config - c.Config = &Config{} - //save so that the file exists - c.SaveConfig() + c.Config = Config{} return true } runtime.LogError(c.ctx, "Error reading config file: "+err.Error()) @@ -77,7 +70,7 @@ func (c *ConfigController) GetConfig() bool { } //It exists so read the file - cf, err := os.ReadFile(path.Join(c.configFileDir)) + cf, err := os.ReadFile(path.Join(c.configFileDir, "config.json")) if err != nil { runtime.LogError(c.ctx, "Error reading config file: "+err.Error()) return false @@ -91,7 +84,7 @@ func (c *ConfigController) GetConfig() bool { return false } - c.Config = &conf + c.Config = conf return true } diff --git a/installer/installer_controller.go b/installer/installer_controller.go index f22b52a..861e741 100644 --- a/installer/installer_controller.go +++ b/installer/installer_controller.go @@ -3,7 +3,6 @@ package installer import ( "context" "fmt" - "github.com/JensvandeWiel/ArkAscendedServerManager/config" "github.com/jensvandewiel/gosteamcmd" "github.com/jensvandewiel/gosteamcmd/console" "github.com/wailsapp/wails/v2/pkg/runtime" @@ -13,14 +12,11 @@ import ( ) type InstallerController struct { - ctx context.Context - config *config.ConfigController + ctx context.Context } -func NewInstallerController(c *config.ConfigController) *InstallerController { - return &InstallerController{ - config: c, - } +func NewInstallerController() *InstallerController { + return &InstallerController{} } func (c *InstallerController) Startup(ctx context.Context) { @@ -38,17 +34,13 @@ Events: // Install installs the server and returns true is successful and error and false if failed func (c *InstallerController) Install(installPath string) error { - //get steamcmd path - c.config.GetConfig() - steamCMDPath := c.config.Config.SteamCMDPath - prompts := []*gosteamcmd.Prompt{ gosteamcmd.ForceInstallDir(installPath), gosteamcmd.Login("", "", ""), gosteamcmd.AppUpdate(2430930, "", true), } - cmd := gosteamcmd.New(io.Discard, prompts, steamCMDPath) + cmd := gosteamcmd.New(io.Discard, prompts, "") cmd.Console.Parser.OnInformationReceived = func(action console.Action, progress float64, currentWritten, total uint64) { actionString := "" @@ -88,7 +80,7 @@ func (c *InstallerController) Install(installPath string) error { } - if i != 0 && i != 7 { + if i != 0 { return fmt.Errorf("failed to install: returned non 0 return code: " + strconv.Itoa(int(i))) } return nil diff --git a/main.go b/main.go index 205dec0..188c225 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,7 @@ func main() { app := NewApp() c := config.NewConfigController() s := server.NewServerController() - i := installer.NewInstallerController(c) + i := installer.NewInstallerController() h := helpers.NewHelpersController() // Create application with options From 6d48621fc2f402bdae249339eb02d790c3e81a67 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:12:19 +0100 Subject: [PATCH 14/29] Revert "Update pull_request.yml (#38)" This reverts commit 604eaba7c35ad584091cfd6fb5cf8c3c1f4a5353. --- .github/workflows/pull_request.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c976f5a..b9f6d9e 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -5,9 +5,6 @@ on: types: - opened - synchronize - schedule: - - cron: "0 21 * * *" - jobs: build: @@ -37,4 +34,4 @@ jobs: uses: actions/upload-artifact@v2 with: name: AASM Artifacts - path: build/bin/*.exe + path: build/bin/*.exe \ No newline at end of file From 429b9caaa75693bc131a239781ba484c6b03f3b3 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:12:19 +0100 Subject: [PATCH 15/29] Revert "added workflows" This reverts commit 8ba0994f78b69507e60eb5e63a0bcfa5dcd35523. --- .github/workflows/nightly.yaml | 50 ------------------------------ .github/workflows/pull_request.yml | 37 ---------------------- 2 files changed, 87 deletions(-) delete mode 100644 .github/workflows/nightly.yaml delete mode 100644 .github/workflows/pull_request.yml diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml deleted file mode 100644 index 55a864d..0000000 --- a/.github/workflows/nightly.yaml +++ /dev/null @@ -1,50 +0,0 @@ -name: Nightly AASM Release - -on: - push: - branches: - - main - -jobs: - build: - strategy: - fail-fast: false - matrix: - build: - - name: Ark-Ascended-Server-Manager.exe - platform: windows/amd64 - os: windows-latest - runs-on: ${{ matrix.build.os }} - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Set direct proxy - run: go env -w GOPROXY=direct - - run: go install github.com/wailsapp/wails/cmd/wails@latest - - uses: dAppServer/wails-build-action@v2.2 - with: - build-name: ${{ matrix.build.name }} - build-platform: ${{ matrix.build.platform }} - build: true - nsis: true - package: false - - - name: Upload artifacts - uses: actions/upload-artifact@v2 - with: - name: AASM Installer - path: build/bin/*.exe - - - name: Upload Nightly Release - uses: andelf/nightly-release@main - with: - tag_name: nightly - name: 'Desktop App Nightly Release ${{ github.run_number }}' - prerelease: true - body: 'This is a nightly release of the AASM. Its unstable compared to the official releases, use it with caution!' - files: | - build/bin/*.exe - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml deleted file mode 100644 index b9f6d9e..0000000 --- a/.github/workflows/pull_request.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: AASM Pull Request Build - -on: - pull_request: - types: - - opened - - synchronize - -jobs: - build: - strategy: - fail-fast: false - matrix: - build: - - name: Ark-Ascended-Server-Manager.exe - platform: windows/amd64 - os: windows-latest - runs-on: ${{ matrix.build.os }} - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Set direct proxy - run: go env -w GOPROXY=direct - - run: go install github.com/wailsapp/wails/cmd/wails@latest - - uses: dAppServer/wails-build-action@v2.2 - with: - build-name: ${{ matrix.build.name }} - build-platform: ${{ matrix.build.platform }} - build: true - nsis: true - package: false - - name: Upload artifacts - uses: actions/upload-artifact@v2 - with: - name: AASM Artifacts - path: build/bin/*.exe \ No newline at end of file From 87ca635726b2a6493c292a273bf93049807425e7 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:12:19 +0100 Subject: [PATCH 16/29] Revert "Update README.md (#31)" This reverts commit ba504bfc9c7403c68185d44035a70770c2e73c8a. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 79458ad..c2a9cff 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # ArkAscendedServerManager # :warning: This project is in very early stages +The game itself is not released yet so for now we are working on scaffolding etc. ## Contribute Join the discord and ask for the role, or start making pull requests on this repo! From 61005bd5a8873bbd96d7e477d68d9d00c1546337 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 10:42:32 +0100 Subject: [PATCH 17/29] added parsing for servermap --- server/helpers.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/helpers.go b/server/helpers.go index 0383fa0..f537680 100644 --- a/server/helpers.go +++ b/server/helpers.go @@ -109,6 +109,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 } From 4c9bc3505640739afac2cfd755e08b73cb32b51f Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 14:29:16 +0100 Subject: [PATCH 18/29] re-ordered server tabs --- frontend/src/pages/Server.tsx | 11 ++++++----- frontend/src/pages/server/Administration.tsx | 9 +++++++++ frontend/src/pages/server/Console.tsx | 17 +++++++++++++++++ frontend/src/pages/server/General.tsx | 2 +- frontend/src/pages/server/Settings.tsx | 9 --------- 5 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 frontend/src/pages/server/Administration.tsx create mode 100644 frontend/src/pages/server/Console.tsx delete mode 100644 frontend/src/pages/server/Settings.tsx diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 88d4fb2..347c1d5 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -27,6 +27,8 @@ 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"; +import {Administration} from "./server/Administration"; type Props = { @@ -137,14 +139,13 @@ export const Server = ({id, className}: Props) => {
+ Console General - Settings - Mods - Plugins - Modifiers + Administration + - + ) : ( setIsInstalled(true)}/>)} ); diff --git a/frontend/src/pages/server/Administration.tsx b/frontend/src/pages/server/Administration.tsx new file mode 100644 index 0000000..9e014d4 --- /dev/null +++ b/frontend/src/pages/server/Administration.tsx @@ -0,0 +1,9 @@ +import {TabPanel} from "@mui/joy"; + +export function Administration() { + return ( + + + + ); +} \ No newline at end of file diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx new file mode 100644 index 0000000..327b7a5 --- /dev/null +++ b/frontend/src/pages/server/Console.tsx @@ -0,0 +1,17 @@ +import {TabPanel} from "@mui/joy"; +import React from "react"; +import {server} from "../../../wailsjs/go/models"; + +type Props = { + setServ: React.Dispatch> + serv: server.Server; + +} + +export function Console({setServ, serv}:Props) { + return ( + + sdssd + + ); +} \ No newline at end of file diff --git a/frontend/src/pages/server/General.tsx b/frontend/src/pages/server/General.tsx index 7e41562..4eb99b4 100644 --- a/frontend/src/pages/server/General.tsx +++ b/frontend/src/pages/server/General.tsx @@ -42,7 +42,7 @@ export function General({serv, setServ}: Props) { }, []); return ( - + {/* Server Name and Passwords */} diff --git a/frontend/src/pages/server/Settings.tsx b/frontend/src/pages/server/Settings.tsx deleted file mode 100644 index d254c94..0000000 --- a/frontend/src/pages/server/Settings.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import {TabPanel} from "@mui/joy"; - -export function Settings() { - return ( - - - - ); -} \ No newline at end of file From c92a472b57c01326047d13eebd6e668e1e191ce6 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 14:44:45 +0100 Subject: [PATCH 19/29] added onServerStart event --- server/server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/server.go b/server/server.go index 1edf473..859d98e 100644 --- a/server/server.go +++ b/server/server.go @@ -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() From 7257b13d6cacc1f3253801c5a2729952ea896073 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 14:44:57 +0100 Subject: [PATCH 20/29] tab refactoring --- frontend/src/pages/Server.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 347c1d5..0680fdd 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -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"; From 61ace9d80c8d9c78d04ae9236188f39e823b1249 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 14:45:11 +0100 Subject: [PATCH 21/29] added basic console layout --- frontend/src/pages/server/Console.tsx | 52 +++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx index 327b7a5..9c8d40f 100644 --- a/frontend/src/pages/server/Console.tsx +++ b/frontend/src/pages/server/Console.tsx @@ -1,6 +1,9 @@ -import {TabPanel} from "@mui/joy"; -import React from "react"; +import {TabPanel, Typography} from "@mui/joy"; +import React, {useEffect, useState} from "react"; import {server} from "../../../wailsjs/go/models"; +import {GetServerStatus} from "../../../wailsjs/go/server/ServerController"; +import {useAlert} from "../../components/AlertProvider"; +import {EventsOn} from "../../../wailsjs/runtime"; type Props = { setServ: React.Dispatch> @@ -9,9 +12,44 @@ type Props = { } export function Console({setServ, serv}:Props) { - return ( - - sdssd - - ); + + const [serverStarted, setServerStarted] = useState(false) + const {addAlert} = useAlert() + + // useEffect for checking if the server is running + useEffect(() => { + GetServerStatus(serv.id).then((status) => {setServerStarted(status)}).catch((err) => {console.error(err); addAlert(err, "danger")}) + }, []); + + // Register server status events + useEffect(() => { + EventsOn("onServerStart", (id: number) => { + if (id === serv.id) { + setServerStarted(true) + } + }) + EventsOn("onServerExit", (id: number) => { + if (id === serv.id) { + setServerStarted(false) + } + }) + }, []); + + if (serverStarted) { + return ( + + server started + + ); + } else { + return ( + +
+

Server is not running

+
+ +
+ ); + } + } \ No newline at end of file From e9cf3f5a982566bc82ae339dd566640780b87eff Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 16:15:04 +0100 Subject: [PATCH 22/29] inherit serverstatus from parent --- frontend/src/pages/Server.tsx | 3 +-- frontend/src/pages/server/Console.tsx | 26 ++++---------------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 0680fdd..3edf217 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -28,7 +28,6 @@ import {useAlert} from "../components/AlertProvider"; import {BrowserOpenURL, EventsOff, EventsOn} from "../../wailsjs/runtime"; import {IconAlertCircleFilled, IconExternalLink} from "@tabler/icons-react"; import {Console} from "./server/Console"; -import {Administration} from "./server/Administration"; type Props = { @@ -143,7 +142,7 @@ export const Server = ({id, className}: Props) => { General Administration - + ) : ( setIsInstalled(true)}/>)} diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx index 9c8d40f..6a4f929 100644 --- a/frontend/src/pages/server/Console.tsx +++ b/frontend/src/pages/server/Console.tsx @@ -8,34 +8,16 @@ import {EventsOn} from "../../../wailsjs/runtime"; type Props = { setServ: React.Dispatch> serv: server.Server; + serverStatus: boolean; } -export function Console({setServ, serv}:Props) { +export function Console({setServ, serv, serverStatus}:Props) { - const [serverStarted, setServerStarted] = useState(false) const {addAlert} = useAlert() - // useEffect for checking if the server is running - useEffect(() => { - GetServerStatus(serv.id).then((status) => {setServerStarted(status)}).catch((err) => {console.error(err); addAlert(err, "danger")}) - }, []); - - // Register server status events - useEffect(() => { - EventsOn("onServerStart", (id: number) => { - if (id === serv.id) { - setServerStarted(true) - } - }) - EventsOn("onServerExit", (id: number) => { - if (id === serv.id) { - setServerStarted(false) - } - }) - }, []); - - if (serverStarted) { + + if (serverStatus) { return ( server started From be21008dc2631a8ff4ac81586d3f8206ad54af0c Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 17:05:39 +0100 Subject: [PATCH 23/29] added basic terminal --- frontend/src/pages/server/Console.tsx | 33 +++++++++++++++++++++------ frontend/tailwind.config.cjs | 6 ++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx index 6a4f929..4a8fc4b 100644 --- a/frontend/src/pages/server/Console.tsx +++ b/frontend/src/pages/server/Console.tsx @@ -1,9 +1,8 @@ -import {TabPanel, Typography} from "@mui/joy"; -import React, {useEffect, useState} from "react"; +import {Button, Input, TabPanel, Typography} from "@mui/joy"; +import React, {useEffect, useRef, useState} from "react"; import {server} from "../../../wailsjs/go/models"; -import {GetServerStatus} from "../../../wailsjs/go/server/ServerController"; import {useAlert} from "../../components/AlertProvider"; -import {EventsOn} from "../../../wailsjs/runtime"; +import {IconArrowRight, IconChevronRight} from "@tabler/icons-react"; type Props = { setServ: React.Dispatch> @@ -14,13 +13,33 @@ type Props = { export function Console({setServ, serv, serverStatus}:Props) { - const {addAlert} = useAlert() + const { addAlert } = useAlert() + const [input, setInput] = useState("") + const terminalRef = useRef(null); - if (serverStatus) { + function writeToConsole(text: string, sender: string = "") { + if (terminalRef.current) { + + terminalRef.current.scrollTop = terminalRef.current.scrollHeight; + terminalRef.current.innerHTML += " " + sender + " > "+ text + "
" + } + } + + function handleInput() { + + } + + if (!serverStatus) { return ( - server started +
+ setInput(e.target.value)} startDecorator={} endDecorator={} onKeyPress={(e) => { + if (e.key === 'Enter') { + writeToConsole(input) + setInput("") + } + }}>
); } else { diff --git a/frontend/tailwind.config.cjs b/frontend/tailwind.config.cjs index 75fd2b7..d1b9227 100644 --- a/frontend/tailwind.config.cjs +++ b/frontend/tailwind.config.cjs @@ -4,7 +4,11 @@ module.exports = { "./src/**/*.{js,jsx,ts,tsx}", ], theme: { - extend: {}, + extend: { + fontFamily: { + 'jetbrains': ['JetBrains Mono', 'monospace'], + }, + }, }, plugins: [], From 9e443ed1388713e52aedec28dd2cbcf1b2b7553f Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 21:21:52 +0100 Subject: [PATCH 24/29] added rcon console --- frontend/src/pages/Server.tsx | 7 +++++++ frontend/src/pages/server/Console.tsx | 24 ++++++++++++++++-------- frontend/src/pages/server/General.tsx | 4 ++-- go.mod | 1 + go.sum | 2 ++ helpers/rcon.go | 22 ++++++++++++++++++++++ server/helpers.go | 4 +++- 7 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 helpers/rcon.go diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 3edf217..7fec9f6 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -74,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() { diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx index 4a8fc4b..7a788da 100644 --- a/frontend/src/pages/server/Console.tsx +++ b/frontend/src/pages/server/Console.tsx @@ -2,7 +2,8 @@ import {Button, Input, TabPanel, Typography} from "@mui/joy"; import React, {useEffect, useRef, useState} from "react"; import {server} from "../../../wailsjs/go/models"; import {useAlert} from "../../components/AlertProvider"; -import {IconArrowRight, IconChevronRight} from "@tabler/icons-react"; +import {IconArrowRight, IconChevronRight, IconCurrencyDollar} from "@tabler/icons-react"; +import {SendRconCommand} from "../../../wailsjs/go/helpers/HelpersController"; type Props = { setServ: React.Dispatch> @@ -20,23 +21,30 @@ export function Console({setServ, serv, serverStatus}:Props) { function writeToConsole(text: string, sender: string = "") { if (terminalRef.current) { - terminalRef.current.scrollTop = terminalRef.current.scrollHeight; - terminalRef.current.innerHTML += " " + sender + " > "+ text + "
" + terminalRef.current.innerHTML += "[" + sender + "]$ "+ text + "
" } } - function handleInput() { + function writeToConsoleAsServer(text: string, sender: string = "server") { + if (terminalRef.current) { + terminalRef.current.scrollTop = terminalRef.current.scrollHeight; + terminalRef.current.innerHTML += ""+ text + "
" + } + } + function doRconCommand(text: string) { + SendRconCommand(text, serv.ipAddress, serv.rconPort, serv.adminPassword).then((resp) => writeToConsoleAsServer(resp, "server")).catch((err) => writeToConsole("error sending command: " + err, "server")) } - if (!serverStatus) { + if (serverStatus) { return ( -
- setInput(e.target.value)} startDecorator={} endDecorator={} onKeyPress={(e) => { +
+ setInput(e.target.value)} startDecorator={$} endDecorator={} onKeyPress={(e) => { if (e.key === 'Enter') { - writeToConsole(input) + writeToConsole(input, "user") + doRconCommand(input) setInput("") } }}> diff --git a/frontend/src/pages/server/General.tsx b/frontend/src/pages/server/General.tsx index 4eb99b4..7a4e045 100644 --- a/frontend/src/pages/server/General.tsx +++ b/frontend/src/pages/server/General.tsx @@ -80,7 +80,7 @@ export function General({serv, setServ}: Props) { IP Address: Ports: diff --git a/go.mod b/go.mod index da94d64..ba02ec5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b4ee6bf..8450af4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/helpers/rcon.go b/helpers/rcon.go new file mode 100644 index 0000000..25ba707 --- /dev/null +++ b/helpers/rcon.go @@ -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 +} diff --git a/server/helpers.go b/server/helpers.go index f537680..94b4539 100644 --- a/server/helpers.go +++ b/server/helpers.go @@ -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 { From 8164b94621cd9cf33e62ee4e02376862e15d2793 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 21:41:35 +0100 Subject: [PATCH 25/29] refactored to do it the react way ;) --- frontend/src/pages/server/Console.tsx | 107 +++++++++++++++++--------- 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx index 7a788da..7af5ae0 100644 --- a/frontend/src/pages/server/Console.tsx +++ b/frontend/src/pages/server/Console.tsx @@ -1,64 +1,101 @@ -import {Button, Input, TabPanel, Typography} from "@mui/joy"; -import React, {useEffect, useRef, useState} from "react"; -import {server} from "../../../wailsjs/go/models"; -import {useAlert} from "../../components/AlertProvider"; -import {IconArrowRight, IconChevronRight, IconCurrencyDollar} from "@tabler/icons-react"; -import {SendRconCommand} from "../../../wailsjs/go/helpers/HelpersController"; +import { Button, Input, TabPanel } from "@mui/joy"; +import React, { useEffect, useRef, useState } from "react"; +import { server } from "../../../wailsjs/go/models"; +import { useAlert } from "../../components/AlertProvider"; +import { IconArrowRight, IconChevronRight, IconCurrencyDollar } from "@tabler/icons-react"; +import { SendRconCommand } from "../../../wailsjs/go/helpers/HelpersController"; type Props = { - setServ: React.Dispatch> + setServ: React.Dispatch>; serv: server.Server; serverStatus: boolean; +}; -} - -export function Console({setServ, serv, serverStatus}:Props) { - - const { addAlert } = useAlert() +export function Console({ setServ, serv, serverStatus }: Props) { + const { addAlert } = useAlert(); + const [input, setInput] = useState(""); + const [messages, setMessages] = useState([]); // Use JSX.Element for styling - const [input, setInput] = useState("") const terminalRef = useRef(null); - function writeToConsole(text: string, sender: string = "") { - if (terminalRef.current) { - terminalRef.current.scrollTop = terminalRef.current.scrollHeight; - terminalRef.current.innerHTML += "[" + sender + "]$ "+ text + "
" - } + function writeToConsole(text: string, sender: string = "user") { + const message = ( + + [{sender}]{" "} + $ {text} +
+
+ ); + setMessages((prevMessages) => [...prevMessages, message]); } function writeToConsoleAsServer(text: string, sender: string = "server") { - if (terminalRef.current) { - terminalRef.current.scrollTop = terminalRef.current.scrollHeight; - terminalRef.current.innerHTML += ""+ text + "
" - } + const message = ( + + {text} +
+
+ ); + setMessages((prevMessages) => [...prevMessages, message]); } function doRconCommand(text: string) { - SendRconCommand(text, serv.ipAddress, serv.rconPort, serv.adminPassword).then((resp) => writeToConsoleAsServer(resp, "server")).catch((err) => writeToConsole("error sending command: " + err, "server")) + SendRconCommand(text, serv.ipAddress, serv.rconPort, serv.adminPassword) + .then((resp) => writeToConsoleAsServer(resp, "server")) + .catch((err) => writeToConsole("error sending command: " + err, "server")); } + useEffect(() => { + if (terminalRef.current) { + terminalRef.current.scrollTop = terminalRef.current.scrollHeight; + } + }, [messages]); + if (serverStatus) { return ( -
- setInput(e.target.value)} startDecorator={$} endDecorator={} onKeyPress={(e) => { - if (e.key === 'Enter') { - writeToConsole(input, "user") - doRconCommand(input) - setInput("") +
+ {messages} +
+ setInput(e.target.value)} + startDecorator={$} + endDecorator={ + } - }}> + onKeyPress={(e) => { + if (e.key === "Enter") { + writeToConsole(input, "user"); + doRconCommand(input); + setInput(""); + } + }} + >
); } else { return ( -
-

Server is not running

+
+

Server is not running

- ); } - -} \ No newline at end of file +} From 9d01e567aab524c694db740d8b03758308299f56 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 21:43:25 +0100 Subject: [PATCH 26/29] cleaned code --- frontend/src/pages/server/Console.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx index 7af5ae0..453374c 100644 --- a/frontend/src/pages/server/Console.tsx +++ b/frontend/src/pages/server/Console.tsx @@ -1,8 +1,6 @@ import { Button, Input, TabPanel } from "@mui/joy"; import React, { useEffect, useRef, useState } from "react"; import { server } from "../../../wailsjs/go/models"; -import { useAlert } from "../../components/AlertProvider"; -import { IconArrowRight, IconChevronRight, IconCurrencyDollar } from "@tabler/icons-react"; import { SendRconCommand } from "../../../wailsjs/go/helpers/HelpersController"; type Props = { @@ -12,7 +10,6 @@ type Props = { }; export function Console({ setServ, serv, serverStatus }: Props) { - const { addAlert } = useAlert(); const [input, setInput] = useState(""); const [messages, setMessages] = useState([]); // Use JSX.Element for styling From 59b209f1748f70b00b6ee10a23f53db1d0657f8c Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 22:00:08 +0100 Subject: [PATCH 27/29] refacored it more into the react way --- frontend/src/pages/server/Console.tsx | 50 +++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx index 453374c..1936fe1 100644 --- a/frontend/src/pages/server/Console.tsx +++ b/frontend/src/pages/server/Console.tsx @@ -3,6 +3,11 @@ 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>; serv: server.Server; @@ -11,36 +16,20 @@ type Props = { export function Console({ setServ, serv, serverStatus }: Props) { const [input, setInput] = useState(""); - const [messages, setMessages] = useState([]); // Use JSX.Element for styling + const [messages, setMessages] = useState([]); const terminalRef = useRef(null); - function writeToConsole(text: string, sender: string = "user") { - const message = ( - - [{sender}]{" "} - $ {text} -
-
- ); - setMessages((prevMessages) => [...prevMessages, message]); - } - - function writeToConsoleAsServer(text: string, sender: string = "server") { - const message = ( - - {text} -
-
- ); - setMessages((prevMessages) => [...prevMessages, message]); - } + const writeToConsole = (text: string, sender: string = "user") => { + const newMessage: Message = { text, sender }; + setMessages((prevMessages) => [...prevMessages, newMessage]); + }; - function doRconCommand(text: string) { + const doRconCommand = (text: string) => { SendRconCommand(text, serv.ipAddress, serv.rconPort, serv.adminPassword) - .then((resp) => writeToConsoleAsServer(resp, "server")) + .then((resp) => writeToConsole(resp, "server")) .catch((err) => writeToConsole("error sending command: " + err, "server")); - } + }; useEffect(() => { if (terminalRef.current) { @@ -56,7 +45,18 @@ export function Console({ setServ, serv, serverStatus }: Props) { ref={terminalRef} className={"overflow-y-scroll font-jetbrains bg-black w-[100%] h-[50vh] p-4 rounded "} > - {messages} + {messages.map((message, index) => ( +
+ {message.sender === "server" ? ( + {message.text}
+ ) : ( + + [{message.sender}]{" "} + $ {message.text}
+
+ )} +
+ ))}
Date: Wed, 1 Nov 2023 22:01:09 +0100 Subject: [PATCH 28/29] use one definition type --- frontend/src/pages/Server.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 7fec9f6..36e84aa 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -145,7 +145,7 @@ export const Server = ({id, className}: Props) => {
- Console + Console General Administration From 6e54466fe4aa215f97b7f0e06da433ae67a89977 Mon Sep 17 00:00:00 2001 From: Jens van de Wiel Date: Wed, 1 Nov 2023 22:03:06 +0100 Subject: [PATCH 29/29] fix spacing --- frontend/src/pages/server/Console.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/server/Console.tsx b/frontend/src/pages/server/Console.tsx index 1936fe1..1ff5027 100644 --- a/frontend/src/pages/server/Console.tsx +++ b/frontend/src/pages/server/Console.tsx @@ -51,9 +51,9 @@ export function Console({ setServ, serv, serverStatus }: Props) { {message.text}
) : ( - [{message.sender}]{" "} + [{message.sender}]{" "} $ {message.text}
-
+ )} ))}