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

Commit

Permalink
Duplicated INI entry fixes (#166)
Browse files Browse the repository at this point in the history
* Duplicated INI entry fixes

INI values no longer duplicate and are correctly represented on Server start when configs are updated.

For easier testing i also added the Update config trigger when the save buttons are pressed when adding addition settings through text in multipliers tab as well as when saving config in administration.

* INI Save Fixes to Allow for Dupe Key Values

Changes that now allow for adding OverridePlayerEngram settings and others that needed to have duplicated Key Value pairs.

Still-Issue:
Have to manually delete extra settings after removing them from the text boxes in the app.
  • Loading branch information
Grandalfy authored Dec 1, 2023
1 parent 5226cf4 commit dcfce7a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,5 @@ fabric.properties
!build/windows/installer/VC_redist.x64.exe
!build/windows/installer/VC_redist.x86.exe
steamcmd
KEY
KEY
.vscode
21 changes: 19 additions & 2 deletions server/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,35 @@ func (s *Server) SaveGameIni(filePathToLoadFrom string, overrideUseIniConfig boo

//modify ini file here

//Same as GUS change. changes from app should now reflect in actual INI file
// gIni.Append([]byte(s.AdditionalGameSections))

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

gIni.Append([]byte(s.AdditionalGameSections))

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

if s.AdditionalGameSections != "" {
addGIni, err := ini.LoadSources(ini.LoadOptions{
// This setting allowed duplicate values in the INI files. With the Changes values should now be replaced
AllowShadows: true,
AllowDuplicateShadowValues: true,
PreserveSurroundedQuote: true,
}, filePath, []byte(s.AdditionalGameSections))
if err != nil {
return err
}
err = addGIni.SaveTo(filePath)
if err != nil {
return err
}
}

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

return nil
Expand Down
42 changes: 27 additions & 15 deletions server/gus.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type ServerSettings struct {
//ExtinctionEventTimeInterval int `json:"extinctionEventTimeInterval" ini:"ExtinctionEventTimeInterval"` //TODO: Usage unknown in asa
FastDecayUnsnappedCoreStructures bool `json:"fastDecayUnsnappedCoreStructures" ini:"FastDecayUnsnappedCoreStructures"` //TODO: Usage unknown in asa
ForceAllStructureLocking bool `json:"forceAllStructureLocking" ini:"ForceAllStructureLocking"`
GlobalVoiceChat bool `json:"globalVoiceChat" ini:"globalVoiceChat"` //TODO if it actually starts with a non capital letter
GlobalVoiceChat bool `json:"globalVoiceChat" ini:"GlobalVoiceChat"` //TODO if it actually starts with a non capital letter
HarvestAmountMultiplier float32 `json:"harvestAmountMultiplier" ini:"HarvestAmountMultiplier"`
HarvestHealthMultiplier float32 `json:"harvestHealthMultiplier" ini:"HarvestHealthMultiplier"`
IgnoreLimitMaxStructuresInRangeTypeFlag bool `json:"ignoreLimitMaxStructuresInRangeTypeFlag" ini:"IgnoreLimitMaxStructuresInRangeTypeFlag"` //TODO: Usage unknown in asa
Expand Down Expand Up @@ -96,7 +96,7 @@ type ServerSettings struct {
PreventOfflinePvPInterval float32 `json:"preventOfflinePvPInterval" ini:"PreventOfflinePvPInterval"`
PreventSpawnAnimations bool `json:"preventSpawnAnimations" ini:"PreventSpawnAnimations"`
PreventTribeAlliances bool `json:"preventTribeAlliances" ini:"PreventTribeAlliances"`
ProximityChat bool `json:"proximityChat" ini:"proximityChat"`
ProximityChat bool `json:"proximityChat" ini:"ProximityChat"`
PvEAllowStructuresAtSupplyDrops bool `json:"pveAllowStructuresAtSupplyDrops" ini:"PvEAllowStructuresAtSupplyDrops"`
PvEDinoDecayPeriodMultiplier float32 `json:"pveDinoDecayPeriodMultiplier" ini:"PvEDinoDecayPeriodMultiplier"`
PvEStructureDecayPeriodMultiplier float32 `json:"pveStructureDecayPeriodMultiplier" ini:"PvEStructureDecayPeriodMultiplier"`
Expand All @@ -113,7 +113,7 @@ type ServerSettings struct {
ServerCrosshair bool `json:"serverCrosshair" ini:"ServerCrosshair"`
ServerForceNoHUD bool `json:"serverForceNoHUD" ini:"ServerForceNoHUD"`
ServerHardcore bool `json:"serverHardcore" ini:"ServerHardcore"`
ServerPVE bool `json:"serverPVE" ini:"serverPVE"`
ServerPVE bool `json:"serverPVE" ini:"ServerPVE"`
ShowFloatingDamageText bool `json:"showFloatingDamageText" ini:"ShowFloatingDamageText"`
ShowMapPlayerLocation bool `json:"showMapPlayerLocation" ini:"ShowMapPlayerLocation"`
StructureDamageMultiplier float32 `json:"structureDamageMultiplier" ini:"StructureDamageMultiplier"`
Expand All @@ -133,7 +133,7 @@ type ServerSettings struct {
//CrossARK Transfers
CrossARKAllowForeignDinoDownloads bool `json:"crossARKAllowForeignDinoDownloads" ini:"CrossARKAllowForeignDinoDownloads"` //TODO: Usage unknown in asa
MinimumDinoReuploadInterval float32 `json:"minimumDinoReuploadInterval" ini:"MinimumDinoReuploadInterval"` //TODO: Usage unknown in asa
NoTributeDownloads bool `json:"noTributeDownloads" ini:"noTributeDownloads"`
NoTributeDownloads bool `json:"noTributeDownloads" ini:"NoTributeDownloads"`
PreventDownloadDinos bool `json:"preventDownloadDinos" ini:"PreventDownloadDinos"`
PreventDownloadItems bool `json:"preventDownloadItems" ini:"PreventDownloadItems"`
PreventDownloadSurvivors bool `json:"preventDownloadSurvivors" ini:"PreventDownloadSurvivors"`
Expand Down Expand Up @@ -444,27 +444,39 @@ func (s *Server) SaveGameUserSettingsIni(filePathToLoadFrom string, overrideUseI

s.GameUserSettings.ServerSettings.ActiveMods = s.Mods

// Append Additional Settings before reflect because gusIni.Append() reloads the original file without the changes
// gusIni.Append([]byte(s.AdditionalGUSSections))

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

if s.ServerPassword != "" {
gusIni.Section("ServerSettings").Key("ServerPassword").SetValue(s.ServerPassword)
}
if s.SpectatorPassword != "" {
gusIni.Section("ServerSettings").Key("SpectatorPassword").SetValue(s.SpectatorPassword)
}

gusIni.Section("ServerSettings").Key("AdminPassword").SetValue(s.AdminPassword)
// INI values for these wouldn't change
gusIni.Section("ServerSettings").Key("ServerPassword").SetValue(s.ServerPassword)
gusIni.Section("ServerSettings").Key("SpectatorPassword").SetValue(s.SpectatorPassword)

gusIni.Append([]byte(s.AdditionalGUSSections))

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

if s.AdditionalGUSSections != "" {
addGUSIni, err := ini.LoadSources(ini.LoadOptions{
// This setting allowed duplicate values in the INI files. With the Changes values should now be replaced
AllowShadows: true,
AllowDuplicateShadowValues: true,
PreserveSurroundedQuote: true,
}, filePath, []byte(s.AdditionalGUSSections))
if err != nil {
return err
}
err = addGUSIni.SaveTo(filePath)
if err != nil {
return err
}
}

/*err = replaceForwardSlashInFile(filepath.Join(s.ServerPath, "ShooterGame\\Saved\\Config\\WindowsServer\\GameUserSettings.ini"))
if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"fmt"
"github.com/StackExchange/wmi"
"io"
"io/ioutil"
"net"
Expand All @@ -13,14 +12,18 @@ import (
"strconv"
"strings"

"github.com/StackExchange/wmi"

"github.com/JensvandeWiel/ArkAscendedServerManager/helpers"
"github.com/go-ini/ini"
"github.com/sethvargo/go-password/password"
"github.com/wailsapp/wails/v2/pkg/runtime"
)

var iniOpts = ini.LoadOptions{
AllowShadows: true,
// This setting allowed duplicate values in the INI files. With the Changes values should now be replaced
AllowShadows: false,
PreserveSurroundedQuote: true,
}

func replaceForwardSlashInFile(filePath string) error {
Expand Down
6 changes: 6 additions & 0 deletions server/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ func (c *ServerController) SaveServerConfigFile(content string, id int) error {
return err
}

// Lets the program save the INI files when pressing Save Config from administration as well as Addition Setting Section
err = serv.UpdateConfig()
if err != nil {
return fmt.Errorf("error starting server: failed updating server configuration: %v", err)
}

return nil

}
Expand Down

0 comments on commit dcfce7a

Please sign in to comment.