Merge dev into master #1
@@ -34,18 +34,19 @@ Alongside this project, I am developing a seperate web-based dashboard that can
|
||||
- [x] Daemon instance remembers config path (*so you don't have to pass `--config` everytime you run an ipc command*)
|
||||
- [ ] Daemon listen port (kind of implemented, could be cleaner)
|
||||
- [x] Declarative Server configuration (Create servers in config)
|
||||
- [ ] More configuration options
|
||||
- [x] All configuration options
|
||||
|
||||
- [ ] Server management
|
||||
- [x] Create servers
|
||||
- [x] Automatic server binary downloading by version
|
||||
- [x] Delete servers
|
||||
- [x] Start/Stop servers
|
||||
- [ ] Server configuration
|
||||
- [x] Server configuration
|
||||
- [x] Download correct configuration template for version (see availible templates [here](https://git.bellsworne.tech/chrisbell/vssm_config_templates))
|
||||
- [x] Version
|
||||
- [x] Server Name
|
||||
- [x] Port
|
||||
- [x] Full declarative configuration support in main app config
|
||||
- [x] Multiple servers support
|
||||
- [x] List servers and their status
|
||||
- [x] Send commands to servers
|
||||
|
||||
@@ -20,7 +20,7 @@ type AppConfig struct {
|
||||
ListenAddress string `json:"listen_address"`
|
||||
} `json:"daemon"`
|
||||
|
||||
Instances map[string]VsServerConfigOptions `json:"instances"`
|
||||
Instances map[string]InstanceMetadata `json:"instances"`
|
||||
}
|
||||
|
||||
func CreateConfigWithDefaults(configPath string) *AppConfig {
|
||||
@@ -36,7 +36,7 @@ func CreateConfigWithDefaults(configPath string) *AppConfig {
|
||||
|
||||
cfg.Daemon.ListenAddress = "127.0.0.1:12345"
|
||||
|
||||
cfg.Instances = make(map[string]VsServerConfigOptions)
|
||||
cfg.Instances = make(map[string]InstanceMetadata)
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
@@ -193,11 +193,10 @@ func (ds *DaemonServer) handleCreate(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
options := VsServerConfigOptions{
|
||||
metadata := InstanceMetadata{
|
||||
Version: version,
|
||||
ServerName: name,
|
||||
Port: converted_port,
|
||||
MaxClients: 10,
|
||||
}
|
||||
|
||||
err = DownloadAndExtractServer(version, ds.cfg.Storage.InstallDir)
|
||||
@@ -206,13 +205,13 @@ func (ds *DaemonServer) handleCreate(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = CreateNewInstance(name, version, options, ds.cfg)
|
||||
err = CreateNewInstance(name, version, metadata, ds.cfg)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("Instance provisioning failed: %v", err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
ds.cfg.Instances[name] = options
|
||||
ds.cfg.Instances[name] = metadata
|
||||
|
||||
data, err := json.MarshalIndent(ds.cfg, "", " ")
|
||||
if err != nil {
|
||||
|
||||
@@ -13,7 +13,7 @@ const (
|
||||
StateRunning InstanceState = "RUNNING"
|
||||
)
|
||||
|
||||
func CreateNewInstance(name string, version string, options VsServerConfigOptions, cfg *AppConfig) error {
|
||||
func CreateNewInstance(name string, version string, meta InstanceMetadata, cfg *AppConfig) error {
|
||||
instanceDir := filepath.Join(cfg.Storage.InstancesDir, name)
|
||||
|
||||
dirs := []string{
|
||||
@@ -29,7 +29,7 @@ func CreateNewInstance(name string, version string, options VsServerConfigOption
|
||||
}
|
||||
|
||||
instanceConfigPath := filepath.Join(instanceDir, "serverconfig.json")
|
||||
if err := PrepareInstanceConfig(version, instanceConfigPath, options, cfg); err != nil {
|
||||
if err := PrepareInstanceConfig(version, instanceConfigPath, meta, cfg); err != nil {
|
||||
return fmt.Errorf("Failed provisioning server baseline configuration: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,23 +10,18 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type VsServerConfigOptions struct {
|
||||
Version string `json:"Version"`
|
||||
ServerName string `json:"ServerName"`
|
||||
Port int `json:"Port"`
|
||||
IpAddress string `json:"IpAddress"`
|
||||
MaxClients int `json:"MaxClients"`
|
||||
Password string `json:"Password"`
|
||||
DefaultRole string `json:"DefaultRole"`
|
||||
GuestRole string `json:"GuestRole"`
|
||||
PreApprovedRole string `json:"PreApprovedRole"`
|
||||
type InstanceMetadata struct {
|
||||
Version string `json:"Version"`
|
||||
ServerName string `json:"ServerName"`
|
||||
Port int `json:"Port"`
|
||||
Config map[string]interface{} `json:"config"`
|
||||
}
|
||||
|
||||
func PrepareInstanceConfig(templateVersion string, instanceConfigPath string, options VsServerConfigOptions, cfg *AppConfig) error {
|
||||
return SyncInstanceConfig(templateVersion, instanceConfigPath, options, cfg)
|
||||
func PrepareInstanceConfig(templateVersion string, instanceConfigPath string, meta InstanceMetadata, cfg *AppConfig) error {
|
||||
return SyncInstanceConfig(templateVersion, instanceConfigPath, meta, cfg)
|
||||
}
|
||||
|
||||
func SyncInstanceConfig(templateVersion string, instanceConfigPath string, options VsServerConfigOptions, cfg *AppConfig) error {
|
||||
func SyncInstanceConfig(templateVersion string, instanceConfigPath string, meta InstanceMetadata, cfg *AppConfig) error {
|
||||
templatePath := filepath.Join(cfg.Storage.ConfigTemplatesDir, templateVersion, "serverconfig.json")
|
||||
|
||||
if err := ensureTemplateExists(templateVersion, templatePath, cfg); err != nil {
|
||||
@@ -66,16 +61,13 @@ func SyncInstanceConfig(templateVersion string, instanceConfigPath string, optio
|
||||
return fmt.Errorf("failed parsing configuration JSON payload: %w", err)
|
||||
}
|
||||
|
||||
rawConfig["ServerName"] = options.ServerName
|
||||
rawConfig["Port"] = options.Port
|
||||
rawConfig["MaxClients"] = options.MaxClients
|
||||
|
||||
if options.Password != "" {
|
||||
rawConfig["Password"] = options.Password
|
||||
} else {
|
||||
rawConfig["Password"] = nil
|
||||
for key, value := range meta.Config {
|
||||
rawConfig[key] = value
|
||||
}
|
||||
|
||||
rawConfig["ServerName"] = meta.ServerName
|
||||
rawConfig["Port"] = meta.Port
|
||||
|
||||
instanceDir := filepath.Dir(instanceConfigPath)
|
||||
if worldConfig, ok := rawConfig["WorldConfig"].(map[string]interface{}); ok {
|
||||
worldConfig["SaveFileLocation"] = filepath.Join(instanceDir, "Saves", "default.vcdbs")
|
||||
|
||||
@@ -32,7 +32,7 @@ func NewProcessManager() *ProcessManager {
|
||||
}
|
||||
}
|
||||
|
||||
func (pm *ProcessManager) StartInstance(name string, version string, options VsServerConfigOptions, config *AppConfig) error {
|
||||
func (pm *ProcessManager) StartInstance(name string, version string, meta InstanceMetadata, config *AppConfig) error {
|
||||
pm.Lock()
|
||||
defer pm.Unlock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user