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

Add 0.0.0.0 default interface back and fixed some bugs #53

Merged
merged 3 commits into from
Nov 2, 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
4 changes: 3 additions & 1 deletion frontend/src/components/PasswordInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ type Props = {
value: string | ReadonlyArray<string> | number | undefined;
children?: any
className?: string | undefined
disabled?: boolean
}

export function PasswordInput({onChange, value, children, className}: Props) {
export function PasswordInput({onChange, value, children, className, disabled}: Props) {
const [textVisible, setTextVisible] = useState(false)
return (
<Input type={textVisible? 'text' : 'password'}
endDecorator={<IconButton onClick={() => setTextVisible(!textVisible)}>{textVisible? <IconEye/> : <IconEyeClosed/>}</IconButton>}
value={value}
onChange={onChange}
className={className}
disabled={disabled}
>{children}</Input>
);
}
8 changes: 4 additions & 4 deletions frontend/src/pages/server/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export function General({serv, setServ}: Props) {
<div className={'space-x-4 w-full flex'}>
<div className={'inline-block'}>
<FormLabel>Server Password:</FormLabel>
<PasswordInput value={serv?.serverPassword} onChange={(e) => setServ((p) => ({ ...p, serverPassword: e.target.value }))} ></PasswordInput>
<PasswordInput value={serv?.serverPassword} disabled={true} onChange={(e) => setServ((p) => ({ ...p, serverPassword: e.target.value }))} ></PasswordInput>
</div>
<div className={'inline-block'}>
<FormLabel>Admin Password:</FormLabel>
<PasswordInput value={serv?.adminPassword} onChange={(e) => setServ((p) => ({ ...p, adminPassword: e.target.value }))} ></PasswordInput>
</div>
<div className={'inline-block'}>
<FormLabel>Spectator Password:</FormLabel>
<PasswordInput value={serv?.spectatorPassword} onChange={(e) => setServ((p) => ({ ...p, spectatorPassword: e.target.value }))} ></PasswordInput>
<PasswordInput value={serv?.spectatorPassword} disabled={true} onChange={(e) => setServ((p) => ({ ...p, spectatorPassword: e.target.value }))} ></PasswordInput>
</div>
</div>
</Card>
Expand All @@ -80,7 +80,7 @@ export function General({serv, setServ}: Props) {
<Divider className={'mx-2'}/>
<FormLabel>IP Address:</FormLabel>
<Select
value={serv.ipAddress}
value={serv.ipAddress?? "0.0.0.0"}
onChange={(e, value) => {
const newValue = value;
setServ(
Expand All @@ -93,7 +93,7 @@ export function General({serv, setServ}: Props) {
)
}}
>
{/*<Option value={"0.0.0.0"}>0.0.0.0 - All</Option>*/}
<Option value={"0.0.0.0"}>0.0.0.0 - All</Option>
{interfaceElements}
</Select>
<FormLabel>Ports: </FormLabel>
Expand Down
4 changes: 4 additions & 0 deletions helpers/rcon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
)

func (c *HelpersController) SendRconCommand(command string, ip string, port int, password string) (string, error) {
if ip == "0.0.0.0" {
ip = "127.0.0.1"
}

conn, err := rcon.Dial(ip+":"+strconv.Itoa(port), password)
if err != nil {
return "", fmt.Errorf("failed connectting to rcon server: %v", err)
Expand Down
47 changes: 24 additions & 23 deletions server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,42 @@ func CheckIfServerCorrect(server Server) error {
return fmt.Errorf("Checks failed: Server.ServerName is empty")
}

if server.ServerPassword != "" && len(server.ServerPassword) < 8 {
return fmt.Errorf("Checks failed: Server.ServerPassword is too short")
//serverpassword can be empty
if server.ServerPassword == "" {
//return fmt.Errorf("Checks failed: Server.ServerPassword is empty, this must be set")
}

// adminpassword must not be empty, because we need it for stopping the server and rcon
if server.AdminPassword == "" {
return fmt.Errorf("Checks failed: Server.AdminPassword is empty you should set an admin password")
}
if len(server.AdminPassword) < 8 {
return fmt.Errorf("Checks failed: Server.AdminPassword is too short.")
return fmt.Errorf("Checks failed: Server.AdminPassword is empty, you should set an admin password")
}

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

if err != nil {
return fmt.Errorf("Check failed: Failed to get Network Interfaces: %v", err)
}
if err != nil {
return fmt.Errorf("Check failed: Failed to get Network Interfaces: %v", err)
}

serverIp := net.ParseIP(server.IpAddress)
serverIp := net.ParseIP(server.IpAddress)

found := false
for _, iface := range interfaces {
if iface.IP.Equal(serverIp) {
found = true
break
found := false
for _, iface := range interfaces {
if iface.IP.Equal(serverIp) {
found = true
break
}
}
if !found {
return fmt.Errorf("Check failed: Ip address not found in system interfaces: %v", server.IpAddress)
}
}
if !found {
return fmt.Errorf("Check failed: Ip address not found in system interfaces: %v", server.IpAddress)
}

if err := CheckServerPorts(&server); err != nil {
return fmt.Errorf("Check failed: ports failed to parse: %v", err)
if err := CheckServerPorts(&server); err != nil {
return fmt.Errorf("Check failed: ports failed to parse: %v", err)
}
}
}

Expand Down
Loading