-
Notifications
You must be signed in to change notification settings - Fork 6
/
proxy.go
65 lines (53 loc) · 1.2 KB
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
Package proxy is a minetest reverse proxy for multiple servers.
It also provides an API for plugins.
*/
package proxy
import (
"errors"
"log"
"os"
"path/filepath"
"regexp"
"runtime/debug"
"strings"
"sync"
)
const (
serializeVer = 29
protoVer = 44
versionString = "5.9.0"
maxPlayerNameLen = 20
bytesPerMediaBunch = 5000
)
var ErrNoBuildInfo = errors.New("unable to retrieve proxy version: no build info")
var playerNameChars = regexp.MustCompile("^[a-zA-Z0-9-_]+$")
var proxyDir string
var proxyDirOnce sync.Once
// Path prepends the directory the executable is in to the given path.
// It follows symlinks to the executable.
func Path(path ...string) string {
proxyDirOnce.Do(func() {
executable, err := os.Executable()
if err != nil {
log.Fatal(err)
}
proxyDir = filepath.Dir(executable)
})
return proxyDir + "/" + strings.Join(path, "")
}
// Version returns the version string of the running instance.
func Version() (string, error) {
info, ok := debug.ReadBuildInfo()
if !ok {
return "", ErrNoBuildInfo
}
return info.Main.Version, nil
}
func init() {
version, err := Version()
if err != nil {
log.Fatal(err)
}
log.Println("version:", version)
}