aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go1
-rw-r--r--doc/config.md7
-rw-r--r--plugin.go63
3 files changed, 66 insertions, 5 deletions
diff --git a/config.go b/config.go
index 6db6dda..9928d27 100644
--- a/config.go
+++ b/config.go
@@ -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
diff --git a/plugin.go b/plugin.go
index 15674f5..1c453c2 100644
--- a/plugin.go
+++ b/plugin.go
@@ -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()
+}