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

Commit

Permalink
Bug multiple bugfixes (#109)
Browse files Browse the repository at this point in the history
* fixed delete duplicate problem

* removed mapname check

* Revert "removed mapname check"

This reverts commit 0838720.

* Revert "Revert "removed mapname check""

This reverts commit 863e2a7.
  • Loading branch information
JensvandeWiel authored Nov 12, 2023
1 parent c2ad30b commit c9f62de
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 109 deletions.
14 changes: 2 additions & 12 deletions server/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package server
import (
"github.com/go-ini/ini"
"github.com/wailsapp/wails/v2/pkg/runtime"
"os"
"path/filepath"
)

Expand Down Expand Up @@ -263,17 +262,8 @@ func (s *Server) SaveGameIni() error {

filePath := filepath.Join(s.ServerPath, "ShooterGame", "Saved", "Config", "WindowsServer", "Game.ini")

if _, err := os.Stat(filePath); os.IsNotExist(err) {

file, err := os.Create(filePath)
if err != nil {

return err
}
defer file.Close()

} else if err != nil {

err := ensureFilePath(filePath)
if err != nil {
return err
}

Expand Down
115 changes: 20 additions & 95 deletions server/gus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package server
import (
"github.com/go-ini/ini"
"github.com/wailsapp/wails/v2/pkg/runtime"
"os"
"path/filepath"
)

Expand Down Expand Up @@ -414,17 +413,8 @@ func (s *Server) SaveGameUserSettingsIni() error {

filePath := filepath.Join(s.ServerPath, "ShooterGame", "Saved", "Config", "WindowsServer", "GameUserSettings.ini")

if _, err := os.Stat(filePath); os.IsNotExist(err) {

file, err := os.Create(filePath)
if err != nil {

return err
}
defer file.Close()

} else if err != nil {

err := ensureFilePath(filePath)
if err != nil {
return err
}

Expand All @@ -439,94 +429,27 @@ func (s *Server) SaveGameUserSettingsIni() error {
return err
}

{
s.GameUserSettings.ServerSettings.RCONEnabled = true

if s.GameUserSettings.ServerSettings.RCONPort == 0 {
/*s.RCONPort = 28015
s.GameUserSettings.ServerSettings.RCONPort = 28015*/
s.GameUserSettings.ServerSettings.RCONPort = s.RCONPort
} else {
s.RCONPort = s.GameUserSettings.ServerSettings.RCONPort
}

if s.GameUserSettings.ServerSettings.ServerAdminPassword == "" {
/*ps, err := password.Generate(18, 9, 0, false, false)
if err != nil {
return err
}
s.AdminPassword = ps
s.GameUserSettings.ServerSettings.ServerAdminPassword = ps*/
s.GameUserSettings.ServerSettings.ServerAdminPassword = s.AdminPassword
} else {
s.AdminPassword = s.GameUserSettings.ServerSettings.ServerAdminPassword
}

if s.GameUserSettings.SessionSettings.MultiHome == "" {
/*s.IpAddress = "0.0.0.0"
s.GameUserSettings.SessionSettings.MultiHome = "0.0.0.0"*/
s.GameUserSettings.SessionSettings.MultiHome = s.IpAddress
} else {
s.IpAddress = s.GameUserSettings.SessionSettings.MultiHome
}

if s.GameUserSettings.SessionSettings.Port == 0 {
/*s.ServerPort = 7777
s.GameUserSettings.SessionSettings.Port = 7777*/
s.GameUserSettings.SessionSettings.Port = s.ServerPort
} else {
s.ServerPort = s.GameUserSettings.SessionSettings.Port
}

if s.GameUserSettings.SessionSettings.QueryPort == 0 {
/*s.QueryPort = 27015
s.GameUserSettings.SessionSettings.QueryPort = 27015*/
s.GameUserSettings.SessionSettings.QueryPort = s.QueryPort
} else {
s.QueryPort = s.GameUserSettings.SessionSettings.QueryPort
}

if s.GameUserSettings.SessionSettings.SessionName == "" {
/*s.ServerName = "A server managed by ArkAscendedServerManager"
s.GameUserSettings.SessionSettings.SessionName = "A server managed by ArkAscendedServerManager"*/
s.GameUserSettings.SessionSettings.SessionName = s.ServerName
} else {
s.ServerName = s.GameUserSettings.SessionSettings.SessionName
}

s.GameUserSettings.MultiHome.MultiHome = true

if s.GameUserSettings.ScriptEngineGameSession.MaxPlayers == 0 {
/*s.MaxPlayers = 70
s.GameUserSettings.ScriptEngineGameSession.MaxPlayers = 70*/
s.GameUserSettings.ScriptEngineGameSession.MaxPlayers = s.MaxPlayers
} else {
s.MaxPlayers = s.GameUserSettings.ScriptEngineGameSession.MaxPlayers
}
}

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

runtime.EventsEmit(s.ctx, "reloadServers")
} else {
}

err = gusIni.ReflectFrom(&s.GameUserSettings)
s.GameUserSettings.ServerSettings.RCONEnabled = true
s.GameUserSettings.ServerSettings.RCONPort = s.RCONPort
s.GameUserSettings.ServerSettings.ServerAdminPassword = s.AdminPassword
s.GameUserSettings.ServerSettings.RCONEnabled = true
s.GameUserSettings.ServerSettings.RCONPort = s.RCONPort
s.GameUserSettings.ServerSettings.ServerAdminPassword = s.AdminPassword

s.GameUserSettings.SessionSettings.MultiHome = s.IpAddress
s.GameUserSettings.SessionSettings.Port = s.ServerPort
s.GameUserSettings.SessionSettings.QueryPort = s.QueryPort
s.GameUserSettings.SessionSettings.SessionName = s.ServerName
s.GameUserSettings.MultiHome.MultiHome = true
s.GameUserSettings.ScriptEngineGameSession.MaxPlayers = s.MaxPlayers
if err != nil {
return err
}
s.GameUserSettings.SessionSettings.MultiHome = s.IpAddress
s.GameUserSettings.SessionSettings.Port = s.ServerPort
s.GameUserSettings.SessionSettings.QueryPort = s.QueryPort
s.GameUserSettings.SessionSettings.SessionName = s.ServerName
s.GameUserSettings.MultiHome.MultiHome = true
s.GameUserSettings.ScriptEngineGameSession.MaxPlayers = s.MaxPlayers

err = gusIni.ReflectFrom(&s.GameUserSettings)
if err != nil {
return err
}

if s.ServerPassword != "" {
Expand All @@ -543,5 +466,7 @@ func (s *Server) SaveGameUserSettingsIni() error {
return err
}

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

return nil
}
33 changes: 31 additions & 2 deletions server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net"
"os"
"path/filepath"
"strconv"
)

Expand Down Expand Up @@ -129,8 +130,6 @@ func CheckIfServerCorrect(server Server) error {

if server.ServerMap == "" {
return fmt.Errorf("server.serverMap is empty")
} else if server.ServerMap != "TheIsland_WP" {
return fmt.Errorf("server.serverMap has invalid value: %v", server.ServerMap)
}

return nil
Expand Down Expand Up @@ -223,3 +222,33 @@ 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) {
// File does not exist, create it along with required directories

// Create any required directories
err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
if err != nil {
return err
}

// Create the file
file, err := os.Create(filePath)
if err != nil {
return err
}
defer file.Close()

// File created successfully
return nil

} else if err != nil {
// There was an error checking the file's existence
return err
}

// File already exists
return nil
}

0 comments on commit c9f62de

Please sign in to comment.