Renaming to vssm and adding a readme
This commit is contained in:
@@ -21,38 +21,39 @@ type VsServerConfigOptions struct {
|
||||
PreApprovedRole string `json:"PreApprovedRole"`
|
||||
}
|
||||
|
||||
func PrepareInstanceConfig(templateVersion string, instanceConfigPath string, config VsServerConfigOptions, cfg *AppConfig) error {
|
||||
func PrepareInstanceConfig(templateVersion string, instanceConfigPath string, options VsServerConfigOptions, cfg *AppConfig) error {
|
||||
return SyncInstanceConfig(templateVersion, instanceConfigPath, options, cfg)
|
||||
}
|
||||
|
||||
func SyncInstanceConfig(templateVersion string, instanceConfigPath string, options VsServerConfigOptions, cfg *AppConfig) error {
|
||||
templatePath := filepath.Join(cfg.Storage.ConfigTemplatesDir, templateVersion, "serverconfig.json")
|
||||
|
||||
if _, err := os.Stat(instanceConfigPath); err == nil {
|
||||
return nil
|
||||
}
|
||||
if _, err := os.Stat(instanceConfigPath); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(filepath.Dir(instanceConfigPath), 0755); err != nil {
|
||||
return fmt.Errorf("failed creating instance directory tree: %w", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(instanceConfigPath), 0755); err != nil {
|
||||
return fmt.Errorf("failed creating instance directory tree: %w", err)
|
||||
}
|
||||
source, err := os.Open(templatePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed opening baseline template file: %w", err)
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
source, err := os.Open(templatePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed opening baseline template file: %w", err)
|
||||
}
|
||||
defer source.Close()
|
||||
destination, err := os.Create(instanceConfigPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed creating target instance configuration: %w", err)
|
||||
}
|
||||
|
||||
destination, err := os.Create(instanceConfigPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed creating target instance configuration: %w", err)
|
||||
_, err = io.Copy(destination, source)
|
||||
destination.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed cloning configuration template payload: %w", err)
|
||||
}
|
||||
}
|
||||
defer destination.Close()
|
||||
|
||||
if _, err := io.Copy(destination, source); err != nil {
|
||||
return fmt.Errorf("failed cloning configuration template payload: %w", err)
|
||||
}
|
||||
|
||||
destination.Close()
|
||||
|
||||
data, err := os.ReadFile(instanceConfigPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed reading cloned configuration data: %w", err)
|
||||
return fmt.Errorf("failed reading configuration data: %w", err)
|
||||
}
|
||||
|
||||
var rawConfig map[string]interface{}
|
||||
@@ -60,18 +61,17 @@ func PrepareInstanceConfig(templateVersion string, instanceConfigPath string, co
|
||||
return fmt.Errorf("failed parsing configuration JSON payload: %w", err)
|
||||
}
|
||||
|
||||
rawConfig["ServerName"] = config.ServerName
|
||||
rawConfig["Port"] = config.Port
|
||||
rawConfig["MaxClients"] = config.MaxClients
|
||||
rawConfig["ServerName"] = options.ServerName
|
||||
rawConfig["Port"] = options.Port
|
||||
rawConfig["MaxClients"] = options.MaxClients
|
||||
|
||||
if config.Password != "" {
|
||||
rawConfig["Password"] = config.Password
|
||||
if options.Password != "" {
|
||||
rawConfig["Password"] = options.Password
|
||||
} else {
|
||||
rawConfig["Password"] = nil
|
||||
}
|
||||
|
||||
instanceDir := filepath.Dir(instanceConfigPath)
|
||||
|
||||
if worldConfig, ok := rawConfig["WorldConfig"].(map[string]interface{}); ok {
|
||||
worldConfig["SaveFileLocation"] = filepath.Join(instanceDir, "Saves", "default.vcdbs")
|
||||
}
|
||||
@@ -89,9 +89,5 @@ func PrepareInstanceConfig(templateVersion string, instanceConfigPath string, co
|
||||
return fmt.Errorf("failed marshaling updated configuration adjustments: %w", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(instanceConfigPath, updatedData, 0644); err != nil {
|
||||
return fmt.Errorf("failed committing updated configuration to disk: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
return os.WriteFile(instanceConfigPath, updatedData, 0644)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user