Skip to content

Commit

Permalink
Merge pull request #682 from cj123/plugin-spaces
Browse files Browse the repository at this point in the history
deprecate run_on_start, add plugins to server options, with more specific separation of executable and arguments
  • Loading branch information
cj123 authored Dec 17, 2019
2 parents f2e467d + 23e215f commit 791667c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
v1.6.1
------

**Please note, this release deprecates use of "run_on_start" in config.yml. Please read the new config.yml "plugins" section if you were using run_on_start!**

Added:

* Added send chat to driver option to the admin panel on the Live Timings page.
* The UDP message receiver now detects if it has fallen behind while handling messages. If it has, it reduces the refresh rate that the Assetto Corsa Server sends messages at, so it can catch up. If you see a lot of "can't keep up!" messages in the Server Logs, you probably need to increase your 'refresh_interval_ms' in the config.yml.
* Added configurable Open Graph images to both the manager as a whole and championships, with these you can link to images that will be shown whenever you share a link of the manager/championship pages on social media (premium).
* Optimised the handling of UDP messages to improve performance.
* When using "Any Available Car", one of each car is added to the EntryList (so long as there are enough entrants!) and then after that Entrant cars are randomised.
* Added a new 'plugins' section to config.yml. Please use this instead of 'run_on_start'. This has been added to fix issues with spaces in plugin path names.

Fixes:

Expand Down
11 changes: 6 additions & 5 deletions cmd/server-manager/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ server:
# each executable specified is run from the directory it is inside, for example,
# the command:
#
# ./my/cool/plugin/path/run.sh --some-opt config.json
# /my/cool/plugin/path/run.sh --some-opt config.json
# now actually performs the following two commands:
#
# 1. cd ./my/cool/plugin/path
# 1. cd /my/cool/plugin/path
# 2. ./run.sh --some-opt config.json
run_on_start:
# e.g. uncomment the line below to run a 'start.sh' for kissmyrank
# - ./assetto/kissmyrank/start.sh
plugins:
# uncomment the two lines below to run the command '/my/cool/plugin/path/run.sh --some-opt config.json'
# - executable: /my/cool/plugin/path/run.sh
# arguments: ["--some-opt", "config.json"]

################################################################################
#
Expand Down
56 changes: 54 additions & 2 deletions server_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"errors"
"fmt"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -164,7 +163,13 @@ func (as *AssettoServerProcess) Start(cfg ServerConfig, entryList EntryList, for
return err
}

err = as.startChildProcess(wd, fmt.Sprintf("%s --stracker_ini %s", StrackerExecutablePath(), filepath.Join(StrackerFolderPath(), strackerConfigIniFilename)))
err = as.startPlugin(wd, &CommandPlugin{
Executable: StrackerExecutablePath(),
Arguments: []string{
"--stracker_ini",
filepath.Join(StrackerFolderPath(), strackerConfigIniFilename),
},
})

if err != nil {
return err
Expand All @@ -176,6 +181,18 @@ func (as *AssettoServerProcess) Start(cfg ServerConfig, entryList EntryList, for
}
}

for _, plugin := range config.Server.Plugins {
err = as.startPlugin(wd, plugin)

if err != nil {
logrus.WithError(err).Errorf("Could not run extra command: %s", plugin.String())
}
}

if len(config.Server.RunOnStart) > 0 {
logrus.Warnf("Use of run_on_start in config.yml is deprecated. Please use 'plugins' instead")
}

for _, command := range config.Server.RunOnStart {
err = as.startChildProcess(wd, command)

Expand All @@ -193,7 +210,42 @@ func (as *AssettoServerProcess) Start(cfg ServerConfig, entryList EntryList, for
return nil
}

func (as *AssettoServerProcess) startPlugin(wd string, plugin *CommandPlugin) error {
commandFullPath, err := filepath.Abs(plugin.Executable)

if err != nil {
as.cmd = nil
return err
}

cmd := buildCommand(as.ctx, commandFullPath, plugin.Arguments...)

pluginDir, err := filepath.Abs(filepath.Dir(commandFullPath))

if err != nil {
logrus.WithError(err).Warnf("Could not determine plugin directory. Setting working dir to: %s", wd)
pluginDir = wd
}

cmd.Stdout = pluginsOutput
cmd.Stderr = pluginsOutput

cmd.Dir = pluginDir

err = cmd.Start()

if err != nil {
return err
}

as.extraProcesses = append(as.extraProcesses, cmd)

return nil
}

// Deprecated: use startPlugin instead
func (as *AssettoServerProcess) startChildProcess(wd string, command string) error {
// BUG(cj): splitting commands on spaces breaks child processes that have a space in their path name
parts := strings.Split(command, " ")

if len(parts) == 0 {
Expand Down
26 changes: 21 additions & 5 deletions servermanager_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"strings"

"github.com/cj123/sessions"
"github.com/etcd-io/bbolt"
Expand Down Expand Up @@ -141,11 +142,26 @@ func (s *StoreConfig) BuildStore() (Store, error) {
}

type ServerExtraConfig struct {
RunOnStart []string `yaml:"run_on_start"`
AuditLogging bool `yaml:"audit_logging"`
PerformanceMode bool `yaml:"performance_mode"`
DisableWindowsBrowserOpen bool `yaml:"dont_open_browser"`
ScanContentFolderForChanges bool `yaml:"scan_content_folder_for_changes"`
Plugins []*CommandPlugin `yaml:"plugins"`
AuditLogging bool `yaml:"audit_logging"`
PerformanceMode bool `yaml:"performance_mode"`
DisableWindowsBrowserOpen bool `yaml:"dont_open_browser"`
ScanContentFolderForChanges bool `yaml:"scan_content_folder_for_changes"`

// Deprecated; use Plugins instead
RunOnStart []string `yaml:"run_on_start"`
}

type CommandPlugin struct {
Executable string `yaml:"executable"`
Arguments []string `yaml:"arguments"`
}

func (c *CommandPlugin) String() string {
out := c.Executable
out += strings.Join(c.Arguments, " ")

return out
}

const acsrURL = "https://acsr.assettocorsaservers.com"
Expand Down

0 comments on commit 791667c

Please sign in to comment.