forked from Cliffbreak/tsviewer
added mutable nickname
This commit is contained in:
parent
5527744c43
commit
c78afcdc24
3 changed files with 24 additions and 7 deletions
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"user": {
|
||||
"nickname": "serveradmin",
|
||||
"name": "serveradmin",
|
||||
"password": ""
|
||||
"password": "HNxkefVx"
|
||||
},
|
||||
"serverTS": {
|
||||
"ip": "127.0.0.1",
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue