diff options
-rw-r--r-- | config.go | 1 | ||||
-rw-r--r-- | doc/config.md | 7 | ||||
-rw-r--r-- | plugin.go | 63 |
3 files changed, 66 insertions, 5 deletions
@@ -35,6 +35,7 @@ type Server struct { // that affects the way the proxy works. type Config struct { NoPlugins bool + NoAutoPlugins bool CmdPrefix string RequirePasswd bool SendInterval float32 diff --git a/doc/config.md b/doc/config.md index af194fa..cfdf939 100644 --- a/doc/config.md +++ b/doc/config.md @@ -31,6 +31,13 @@ Default: false Description: Plugins are not loaded if this is true. ``` +> `NoAutoPlugins` +``` +Type: bool +Default: false +Description: Plugin subdirectories are not built automatically if this is true. +``` + > `CmdPrefix` ``` Type: string @@ -3,6 +3,7 @@ package proxy import ( "log" "os" + "os/exec" "plugin" "sync" ) @@ -14,6 +15,13 @@ func loadPlugins() { } func openPlugins() { + version, ok := Version() + if !ok { + log.Fatal("unable to retrieve proxy version") + } + + pathVer := "github.com/HimbeerserverDE/mt-multiserver-proxy@" + version + path := Path("plugins") os.Mkdir(path, 0777) @@ -22,13 +30,58 @@ func openPlugins() { log.Fatal(err) } - for _, file := range dir { - _, err := plugin.Open(path + "/" + file.Name()) - if err != nil { - log.Print(err) - continue + for _, pl := range dir { + if pl.IsDir() { + plPath := path + "/" + pl.Name() + + wd, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + + if err := os.Chdir(plPath); err != nil { + log.Fatal(err) + } + + if err := goCmd("get", "-u", pathVer); err != nil { + log.Fatal(err) + } + + if err := goCmd("mod", "tidy"); err != nil { + log.Fatal(err) + } + + if err := goCmd("build", "-buildmode=plugin"); err != nil { + log.Fatal(err) + } + + if err := os.Chdir(wd); err != nil { + log.Fatal(err) + } + + _, err = plugin.Open(path + "/" + pl.Name() + ".so") + if err != nil { + log.Print(err) + continue + } + } else { + _, err := plugin.Open(path + "/" + pl.Name()) + if err != nil { + log.Print(err) + continue + } } } log.Print("load plugins") } + +func goCmd(args ...string) error { + cmd := exec.Command("go", args...) + + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + return cmd.Run() +} |