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

Refactored almost all code #110

Merged
merged 6 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion frontend/src/components/ServerList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Card, List, ListItem, ListItemButton } from "@mui/joy";
import { server } from "../../wailsjs/go/models";
import { LogError } from "../../wailsjs/runtime/runtime";
import { LogError } from "../../wailsjs/runtime";
import { IconPlus } from "@tabler/icons-react";

enum ServerListType {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/InstallUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function InstallUpdater({setServ, serv, onInstalled}: Props) {
useEffect(() => {
EventsOn("installingUpdateAction", (data) => {setAction(data);})
EventsOn("installingUpdateProgress", (data) => {setProgress(data);})
EventsOn("appInstalled", (i) => {setIsCompleted(true); setAction("Done"); setProgress(100)})
EventsOn("appInstalled", () => {setIsCompleted(true); setAction("Done"); setProgress(100)})
}, []);


Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Server.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Button,
ButtonGroup,
Card, Checkbox, DialogActions,
Card, DialogActions,
DialogContent,
DialogTitle,
Divider, IconButton,
Expand Down
345 changes: 198 additions & 147 deletions frontend/src/pages/server/Administration.tsx

Large diffs are not rendered by default.

153 changes: 79 additions & 74 deletions frontend/src/pages/server/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,35 @@ type Props = {

}

function ServerNameAndPasswordsCard({ setServ, serv }: {setServ: React.Dispatch<React.SetStateAction<server.Server>>, serv: server.Server}) {
return (
<Card variant="soft" className={''}>
<Typography level="title-md">
Server Name and Passwords
</Typography>
<Divider className={'mx-2'}/>

<FormLabel>Server Name:</FormLabel>
<Input className={'w-2/3'} required value={serv?.serverName} onChange={(e) => setServ((p) => ({ ...p, serverName: e.target.value, convertValues: p.convertValues }))} ></Input>
<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<FormLabel>Server Password:</FormLabel>
<PasswordInput value={serv?.serverPassword} disabled={true} onChange={(e) => setServ((p) => ({ ...p, serverPassword: e.target.value, convertValues: p.convertValues }))} ></PasswordInput>
</div>
<div className={'inline-block'}>
<FormLabel>Admin Password:</FormLabel>
<PasswordInput value={serv?.adminPassword} onChange={(e) => setServ((p) => ({ ...p, adminPassword: e.target.value, convertValues: p.convertValues }))} ></PasswordInput>
</div>
<div className={'inline-block'}>
<FormLabel>Spectator Password:</FormLabel>
<PasswordInput value={serv?.spectatorPassword} disabled={true} onChange={(e) => setServ((p) => ({ ...p, spectatorPassword: e.target.value, convertValues: p.convertValues }))} ></PasswordInput>
</div>
</div>
</Card>
)
}
function NetworkingCard({ setServ, serv }: {setServ: React.Dispatch<React.SetStateAction<server.Server>>, serv: server.Server}) {

export function General({serv, setServ}: Props) {
const defInter: {[p: string]: string} = {
"none": ""
}
Expand All @@ -42,81 +69,59 @@ export function General({serv, setServ}: Props) {
}, []);

return (
<TabPanel value={1} className={'space-y-8'}>
{/* Server Name and Passwords */}
<Card variant="soft" className={''}>
<Typography level="title-md">
Server Name and Passwords
</Typography>
<Divider className={'mx-2'}/>

{/*
<Portal container={document.getElementById("alert-root")}><Alert className={"fixed"}>dsadasd</Alert></Portal>
*/}

<FormLabel>Server Name:</FormLabel>
<Input className={'w-2/3'} required value={serv?.serverName} onChange={(e) => setServ((p) => ({ ...p, serverName: e.target.value, convertValues: p.convertValues }))} ></Input>
<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<FormLabel>Server Password:</FormLabel>
<PasswordInput value={serv?.serverPassword} disabled={true} onChange={(e) => setServ((p) => ({ ...p, serverPassword: e.target.value, convertValues: p.convertValues }))} ></PasswordInput>
</div>
<div className={'inline-block'}>
<FormLabel>Admin Password:</FormLabel>
<PasswordInput value={serv?.adminPassword} onChange={(e) => setServ((p) => ({ ...p, adminPassword: e.target.value, convertValues: p.convertValues }))} ></PasswordInput>
</div>
<div className={'inline-block'}>
<FormLabel>Spectator Password:</FormLabel>
<PasswordInput value={serv?.spectatorPassword} disabled={true} onChange={(e) => setServ((p) => ({ ...p, spectatorPassword: e.target.value, convertValues: p.convertValues }))} ></PasswordInput>
</div>
<Card variant="soft" className={''}>
<Typography level="title-md">
Networking
</Typography>
<Divider className={'mx-2'}/>
<FormLabel>IP Address:</FormLabel>
<Select
value={serv.ipAddress?? "0.0.0.0"}
onChange={(e, value) => {
const newValue = value;
setServ(
prevState =>{
return{
...prevState,
ipAddress: newValue?? "0.0.0.0",
convertValues: prevState.convertValues
}
}
)
}}
>
<Option value={"0.0.0.0"}>0.0.0.0 - All</Option>
{interfaceElements}
</Select>
<FormLabel>Ports: </FormLabel>
<div className={'space-x-4 w-11/12'}>
<div className={'w-32 inline-block'}>
<FormLabel>Server Port:</FormLabel>
<Input className={''} type={'number'} required value={serv?.serverPort} onChange={(e) => (parseInt(e.target.value) >= 1 && parseInt(e.target.value) <= 65535) ? setServ((p) => ({ ...p, serverPort: parseInt(e.target.value), peerPort: parseInt(e.target.value) + 1, convertValues: p.convertValues })) : null} ></Input>
</div>
<div className={'w-32 inline-block'}>
<FormLabel>Peer Port:</FormLabel>
<Input className={''} disabled type={'number'} value={serv.peerPort} ></Input>
</div>
</Card>

{/* Server Name and Passwords */}
<Card variant="soft" className={''}>
<Typography level="title-md">
Networking
</Typography>
<Divider className={'mx-2'}/>
<FormLabel>IP Address:</FormLabel>
<Select
value={serv.ipAddress?? "0.0.0.0"}
onChange={(e, value) => {
const newValue = value;
setServ(
prevState =>{
return{
...prevState,
ipAddress: newValue?? "0.0.0.0",
convertValues: prevState.convertValues
}
}
)
}}
>
<Option value={"0.0.0.0"}>0.0.0.0 - All</Option>
{interfaceElements}
</Select>
<FormLabel>Ports: </FormLabel>
<div className={'space-x-4 w-11/12'}>
<div className={'w-32 inline-block'}>
<FormLabel>Server Port:</FormLabel>
<Input className={''} type={'number'} required value={serv?.serverPort} onChange={(e) => (parseInt(e.target.value) >= 1 && parseInt(e.target.value) <= 65535) ? setServ((p) => ({ ...p, serverPort: parseInt(e.target.value), peerPort: parseInt(e.target.value) + 1, convertValues: p.convertValues })) : null} ></Input>
</div>
<div className={'w-32 inline-block'}>
<FormLabel>Peer Port:</FormLabel>
<Input className={''} disabled type={'number'} value={serv.peerPort} ></Input>
</div>
<div className={'w-32 inline-block'}>
<FormLabel>Query Port:</FormLabel>
<Input className={''} type={'number'} value={serv?.queryPort} onChange={(e) => (parseInt(e.target.value) >= 1 && parseInt(e.target.value) <= 65535) ? setServ((p) => ({ ...p, queryPort: parseInt(e.target.value), convertValues: p.convertValues})) : null}></Input>
</div>
<div className={'w-32 inline-block'}>
<FormLabel>RCON Port:</FormLabel>
<Input className={''} value={serv?.rconPort} onChange={(e) => (parseInt(e.target.value) >= 1 && parseInt(e.target.value) <= 65535) ? setServ((p) => ({ ...p, rconPort: parseInt(e.target.value), convertValues: p.convertValues})) : null} type={'number'}></Input >
</div>
<div className={'w-32 inline-block'}>
<FormLabel>Query Port:</FormLabel>
<Input className={''} type={'number'} value={serv?.queryPort} onChange={(e) => (parseInt(e.target.value) >= 1 && parseInt(e.target.value) <= 65535) ? setServ((p) => ({ ...p, queryPort: parseInt(e.target.value), convertValues: p.convertValues})) : null}></Input>
</div>
</Card>
<div className={'w-32 inline-block'}>
<FormLabel>RCON Port:</FormLabel>
<Input className={''} value={serv?.rconPort} onChange={(e) => (parseInt(e.target.value) >= 1 && parseInt(e.target.value) <= 65535) ? setServ((p) => ({ ...p, rconPort: parseInt(e.target.value), convertValues: p.convertValues})) : null} type={'number'}></Input >
</div>
</div>
</Card>
)
}


export function General({serv, setServ}: Props) {
return (
<TabPanel value={1} className={'space-y-8'}>
<ServerNameAndPasswordsCard setServ={setServ} serv={serv} />
<NetworkingCard setServ={setServ} serv={serv} />
</TabPanel>
);
}
50 changes: 24 additions & 26 deletions frontend/src/pages/server/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
import React from "react";
import {server} from "../../../wailsjs/go/models";
import {
Button,
Card, Checkbox,
DialogActions,
DialogContent,
DialogTitle,
Card,
Divider, FormLabel, Input,
Modal,
ModalDialog,
TabPanel,
Typography
} from "@mui/joy";
import {IconAlertCircleFilled} from "@tabler/icons-react";

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

function GeneralServerSettingsCard({ setServ, serv }: {setServ: React.Dispatch<React.SetStateAction<server.Server>>, serv: server.Server}) {
return (
<Card variant="soft" className={''}>
<Typography level="title-md">
General Server Settings
</Typography>
<Divider className={'mx-2'}/>

<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<FormLabel>Mods (e.g.: modid1,modid2,modid3) (for now you need to set "ACTIVEMODS" to ini manually)</FormLabel>
<Input className={"w-[60vw]"} value={serv?.mods} onChange={(e) => setServ((p) => ({ ...p, mods: e.target.value, convertValues: p.convertValues }))}></Input>
<FormLabel>Player limit</FormLabel>
<Input className={"w-3/12"} value={serv?.maxPlayers} type={"number"} onChange={(e) => {
if (parseInt(e.target.value) > 0) {
setServ((p) => ({...p, maxPlayers: parseInt(e.target.value), convertValues: p.convertValues}))
}}}></Input>
</div>
</div>
</Card>
)
}

export function Settings({setServ, serv}: Props) {
return (
<TabPanel value={2} className={'space-y-8'}>
<Card variant="soft" className={''}>
<Typography level="title-md">
General Server Settings
</Typography>
<Divider className={'mx-2'}/>

<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<FormLabel>Mods (e.g.: modid1,modid2,modid3) (for now you need to set "ACTIVEMODS" to ini manually)</FormLabel>
<Input className={"w-[60vw]"} value={serv?.mods} onChange={(e) => setServ((p) => ({ ...p, mods: e.target.value, convertValues: p.convertValues }))}></Input>
<FormLabel>Player limit</FormLabel>
<Input className={"w-3/12"} value={serv?.maxPlayers} type={"number"} onChange={(e) => {
if (parseInt(e.target.value) > 0) {
setServ((p) => ({...p, maxPlayers: parseInt(e.target.value), convertValues: p.convertValues}))
}}}></Input>
</div>
</div>
</Card>
<GeneralServerSettingsCard setServ={setServ} serv={serv}/>
</TabPanel>
);
}
File renamed without changes.
14 changes: 8 additions & 6 deletions server/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,21 @@ func (s *Server) SaveGameIni() error {
if err != nil {
return err
}
}

runtime.EventsEmit(s.ctx, "reloadServers")
} else {
err = gIni.ReflectFrom(&s.Game)
if err != nil {
return err
}
//modify ini file here

err = gIni.ReflectFrom(&s.Game)
if err != nil {
return err
}

err = gIni.SaveTo(filepath.Join(s.ServerPath, "ShooterGame\\Saved\\Config\\WindowsServer\\Game.ini"))
if err != nil {
return err
}

runtime.EventsEmit(s.ctx, "reloadServers")

return nil
}
5 changes: 0 additions & 5 deletions server/gus.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,6 @@ func (s *Server) SaveGameUserSettingsIni() error {
return err
}

/*err := gusIni.SaveTo(filepath.Join(s.ServerPath, "ShooterGame\\Saved\\Config\\WindowsServer\\GameUserSettings.ini"))
if err != nil {
return err
}*/

}

s.GameUserSettings.ServerSettings.RCONEnabled = true
Expand Down
17 changes: 5 additions & 12 deletions server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import (
"strconv"
)

// region Local Helpers
var iniOpts = ini.LoadOptions{
AllowShadows: true,
AllowDuplicateShadowValues: true,
}

// findHighestKey returns the highest key in a map with int as key
func findHighestKey(m map[int]*Server) int {
var highestKey int = -1
Expand Down Expand Up @@ -190,10 +194,6 @@ func CopyAndMakeOld(path string) error {
return nil
}

//endregion

//region Global and Frontend Helpers

func (c *ServerController) GetNetworkInterfacesIp() map[string]string {

i, err := helpers.GetNetworkInterfaces()
Expand All @@ -216,13 +216,6 @@ func (c *ServerController) GetServerDir() string {
return c.serverDir
}

//endregion

var iniOpts = ini.LoadOptions{
AllowShadows: true,
AllowDuplicateShadowValues: true,
}

func ensureFilePath(filePath string) error {
// Check if the file already exists
if _, err := os.Stat(filePath); os.IsNotExist(err) {
Expand Down
19 changes: 3 additions & 16 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ type Server struct {
//Server Name and Passwords
ServerName string `json:"serverName"`

ServerPassword string `json:"serverPassword"` //TODO: Implement in startup/config
ServerPassword string `json:"serverPassword"`
AdminPassword string `json:"adminPassword"`
SpectatorPassword string `json:"spectatorPassword"` //TODO: Implement in startup/config
SpectatorPassword string `json:"spectatorPassword"`

//Server Networking
IpAddress string `json:"ipAddress"`
ServerPort int `json:"serverPort"`
PeerPort int `json:"peerPort"` //TODO: Implement in startup/config
PeerPort int `json:"peerPort"` //TODO: find out if used
QueryPort int `json:"queryPort"`
RCONPort int `json:"rconPort"`

Expand Down Expand Up @@ -129,19 +129,6 @@ func (s *Server) Start() error {
runtime.LogError(s.ctx, "Error sending message to discord: "+err.Error())
}
}

/*//restart server on crash
if err != nil && s.RestartOnServerQuit {
code := s.Command.ProcessState.ExitCode()
time.Sleep(2 * time.Second)
if code != 0 {
err := s.Start()
if err != nil {
runtime.EventsEmit(s.ctx, "onRestartServerFailed", err)
}
}
}*/

}()
}

Expand Down
Loading
Loading