From c78afcdc2408213d8db2ff4652958dbd5e6315c2 Mon Sep 17 00:00:00 2001 From: Hendrik Schlehlein Date: Sun, 3 Feb 2019 20:08:48 +0100 Subject: [PATCH] added mutable nickname --- config.json | 3 ++- config/config.go | 24 ++++++++++++++++++------ service/service.go | 4 ++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/config.json b/config.json index 9bc4b96..591ff36 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,8 @@ { "user": { + "nickname": "serveradmin", "name": "serveradmin", - "password": "" + "password": "HNxkefVx" }, "serverTS": { "ip": "127.0.0.1", diff --git a/config/config.go b/config/config.go index 9bbf542..f36765b 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,7 @@ type Config struct { } type User struct { + Nickname string `json:"nickname"` Name string `json:"name"` Password string `json:"password"` } @@ -67,6 +68,7 @@ func (config Config) createFile() error { func defaults() Config { return Config{ User: User{ + Nickname: "serveradmin", Name: "serveradmin", Password: "", }, @@ -82,6 +84,7 @@ func defaults() Config { } func (config *Config) overrideWithEnv() { + nickname := os.Getenv("TS3_NICKNAME") username := os.Getenv("TS3_NAME") password := os.Getenv("TS3_PW") tsIP := os.Getenv("TS3_IP") @@ -89,6 +92,10 @@ func (config *Config) overrideWithEnv() { tsQuery, _ := strconv.Atoi(os.Getenv("TS3_QUERY")) webPort, _ := strconv.Atoi(os.Getenv("WEB_PORT")) + if nickname != "" { + config.User.Nickname = nickname + } + if username != "" { config.User.Name = username } @@ -101,20 +108,21 @@ func (config *Config) overrideWithEnv() { config.ServerTS.IP = tsIP } - if tsPort <= 65535 { + if tsPort <= 65535 && tsPort != 0 { config.ServerTS.PortServer = uint16(tsPort) } - if tsQuery <= 65535 { + if tsQuery <= 65535 && tsQuery != 0 { config.ServerTS.PortQuery = uint16(tsQuery) } - if webPort <= 65535 { + if webPort <= 65535 && webPort != 0 { config.ServerWeb.Port = uint16(webPort) } } func (config *Config) overrideWithFlags() { + nickname := flag.String("ts3_nickname", "", "TS3Query nickname") username := flag.String("ts3_name", "", "TS3Query username") password := flag.String("ts3_pw", "", "TS3Query user password") tsIP := flag.String("ts3_ip", "", "TS3 IP address") @@ -123,6 +131,10 @@ func (config *Config) overrideWithFlags() { webPort := flag.Uint64("web_port", 65536, "Webserver port") flag.Parse() + if *nickname != "" { + config.User.Nickname = *nickname + } + if *username != "" { config.User.Name = *username } @@ -135,15 +147,15 @@ func (config *Config) overrideWithFlags() { config.ServerTS.IP = *tsIP } - if *tsPort <= 65535 { + if *tsPort <= 65535 && *tsPort != 0 { config.ServerTS.PortServer = uint16(*tsPort) } - if *tsQuery <= 65535 { + if *tsQuery <= 65535 && *tsQuery != 0 { config.ServerTS.PortQuery = uint16(*tsQuery) } - if *webPort <= 65535 { + if *webPort <= 65535 && *webPort != 0 { config.ServerWeb.Port = uint16(*webPort) } } diff --git a/service/service.go b/service/service.go index 1a11c76..f70fb0d 100644 --- a/service/service.go +++ b/service/service.go @@ -27,6 +27,10 @@ func New(config config.Config) (*Service, error) { return nil, err } + if err := client.SetNick(config.User.Nickname); err != nil { + return nil, err + } + go func() { for true { time.Sleep(time.Second * 150)