From 1756399f51f88b256255301bb9d1e1057413800a Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:39:12 +0100 Subject: [PATCH] Update ark server before starting it and embed steamcmd and more (#55) * embedded steamcmd * add server auto updater * refactored console * added stop functionality * added error feedback on server save * removed useless .then --- .gitignore | 2 + frontend/src/pages/InstallUpdater.tsx | 6 +-- frontend/src/pages/Server.tsx | 38 ++++++++++++++++- frontend/src/pages/UpdaterModal.tsx | 56 ++++++++++++++++++++++++++ frontend/src/pages/server/Console.tsx | 49 ++++++++++++++++------ installer/helpers.go | 47 +++++++++++++++++++++ installer/installer_controller.go | 14 ++++++- installer/steamcmd.exe | Bin 0 -> 1687464 bytes 8 files changed, 192 insertions(+), 20 deletions(-) create mode 100644 frontend/src/pages/UpdaterModal.tsx create mode 100644 installer/helpers.go create mode 100644 installer/steamcmd.exe diff --git a/.gitignore b/.gitignore index 9e0df19..cc455ac 100644 --- a/.gitignore +++ b/.gitignore @@ -184,3 +184,5 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser +!installer/steamcmd.exe +steamcmd \ No newline at end of file diff --git a/frontend/src/pages/InstallUpdater.tsx b/frontend/src/pages/InstallUpdater.tsx index 5a9d980..076b0e8 100644 --- a/frontend/src/pages/InstallUpdater.tsx +++ b/frontend/src/pages/InstallUpdater.tsx @@ -13,7 +13,7 @@ import { } from "@mui/joy"; import {OpenDirectoryDialog} from "../../wailsjs/go/helpers/HelpersController"; import {IconDownload} from "@tabler/icons-react"; -import {Install} from "../../wailsjs/go/installer/InstallerController"; +import {InstallUpdateVerify} from "../../wailsjs/go/installer/InstallerController"; import {EventsOn} from "../../wailsjs/runtime"; import {useAlert} from "../components/AlertProvider"; @@ -40,13 +40,11 @@ export function InstallUpdater({setServ, serv, onInstalled}: Props) { return } setInstallerModalOpen(true) - Install(serv.serverPath).catch((err) => { + InstallUpdateVerify(serv.serverPath).catch((err) => { setAction("failed installing: " + err.message); setInstallerModalOpen(false); console.error(err); addAlert("Installer failed: " + err, "danger") - - }) } diff --git a/frontend/src/pages/Server.tsx b/frontend/src/pages/Server.tsx index 36e84aa..02f2fb8 100644 --- a/frontend/src/pages/Server.tsx +++ b/frontend/src/pages/Server.tsx @@ -28,6 +28,9 @@ 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 {UpdaterModal} from "./UpdaterModal"; +import {InstallUpdateVerify} from "../../wailsjs/go/installer/InstallerController"; +import {SendRconCommand} from "../../wailsjs/go/helpers/HelpersController"; type Props = { @@ -48,6 +51,7 @@ export const Server = ({id, className}: Props) => { const [isInstalled, setIsInstalled] = useState(false) const [serverStatus, setServerStatus] = useState(false) const [forceStopModalOpen, setForceStopModalOpen] = useState(false) + const [updaterModalOpen, setUpdaterModalOpen] = useState(false) const {addAlert} = useAlert() //region useEffect land :) @@ -66,7 +70,7 @@ export const Server = ({id, className}: Props) => { useEffect(() => { if (serv.id >= 0) { - SaveServer(serv).catch((reason) => console.error(reason)) + SaveServer(serv).catch((reason) => {console.error(reason); addAlert(reason, "danger")}) } }, [serv]); @@ -84,10 +88,39 @@ export const Server = ({id, className}: Props) => { //endregion function onServerStartButtonClicked() { + + if (serv.serverPath == "") { + addAlert("Server Path must be set to a path", "warning") + return + } + + setUpdaterModalOpen(true) + InstallUpdateVerify(serv.serverPath).catch((err) => { + addAlert("failed installing: " + err.message, "danger"); + setUpdaterModalOpen(false); + console.error(err); + }).then(() => { + setUpdaterModalOpen(false); + startServer() + }) + + } + + function startServer() { StartServer(serv.id).catch((err) => {addAlert(err, "danger"); console.error(err)}).then(() => setTimeout(function () { refreshServerStatus() }, 200)) + } + function onServerStopButtonClicked() { + addAlert("Stopping server...", "neutral") + SendRconCommand("saveworld", serv.ipAddress, serv.rconPort, serv.adminPassword) + .then((resp) => { + //send quit command + SendRconCommand("doexit", serv.ipAddress, serv.rconPort, serv.adminPassword) + .catch((err) => addAlert("error sending exit command: " + err, "danger")); + }) + .catch((err) => addAlert("error sending save command: " + err, "danger")); } function onServerForceStopButtonClicked() { @@ -119,9 +152,10 @@ export const Server = ({id, className}: Props) => {
%^?XK--nZMq3
z{QTu;2cExP9rOP~;{55hcmB e%F=rvc0Ji$F%0>
zdd0QEBgS9?eB*c-eqxS&$cXC0%6lDT(t(g(XQI-3mW~3Pv_13e01@f!=>?v;BeW})
z1*x{%^kJLrUNSX9Cy(^h@0StA^iQ})yYO=k%U%h!DzO4t37lY{&76JHDoZ|VoUpSx
z6npM*aj561Gnfs0hKmwHBqR2KOYHO+w!0NtmNY)x5|!J|nUT~h|DiuZa|Wk0=M8oX
zP&T^<>z};AsWM%4pCU4}Ph@V+*3cNCY!BMF4YbNz>l2(9)*__^#-j
zO01X!lDb+G=5i=h6~~6j^c-Wur}(bxi4D_34_`Kz`gG{#>0UPcz2!O^KIPTs5*t3n
zLv&Vw*f5=HewSh)wB`#RCkiAwfYlO#(er_s3bWW@DRcYf!`tLbq
LcpjJW=kItJRJ#ZyB
z_kz6m=ghZ(v>_VO*H4Euy9y>tE9k+Z6BxgGFGn_hdZZSr9&uz_ZeWPc
z79#c9r779Xwr3_AYt(J8mKV56Jpp~AhMPVL>E!QuSu+6p_)&jYq(Mx=
zqP&m5(@}Srmf5R%Y;^vr9ughCo9*C@QQAlRvT&Kog>oEnc
zbG}yd02YnYgJU4ps1SRNcIT0&{t-AOC)NX^IsF=9RW%{MkP-Yhubs!X?T5zjuVpri
z)Zaw#vpuzAd*nT*T)e$5@w#iqYxS7DK6$T(uwFBYG)xUy%
zAxunvuIUHg;vX+;UpNBmgw1-K(sDEctF&q7r%UjeP=T9dKoa!3K*;(et00y68HHtz
z_<>?JSETlQQ>&kNn=CaW*IbYxS;<}kRr7E#($MDoEUKi19QiTgP?3vbD$^(WN|?Yh
z{eODE{)aW9(oJ<46D1arq3eqr0=0e^oA
zFN@TKTZD>9N9UjYnQr2#6sKovsV*tp#7TXd5H_OR-?j%X{yP`5%c;O_NEP9kj_IX#
z-YoTIgrhasL<9*(^g15B8Zk;(I+uEPKF@VTuY}rJ5np`b2-Lrt3XJYnc`qRvXp-w)
zYT;gBQCk`_9gefJs(aKSGf^?f&fTSo1}c_{8cS27o(8vBf|kMIC18%B;hAHz4Cif+
zTZWLgodU=nrS5;CD73VdGt-s)qIkH8Bj&6|f}t_t`