Fix stream key loading

Somehow I broke this without noticing.  Also, If a stream key is
provided as a command line flag, load it but do not save it to
settings.json.
This commit is contained in:
Zorchenhimer 2019-03-11 23:45:23 -04:00
parent 2e17d92cae
commit 1a217775ff
2 changed files with 24 additions and 7 deletions

13
main.go
View File

@ -74,12 +74,7 @@ func main() {
return
}
streamKey := settings.StreamKey
if sKey != nil && len(*sKey) != 0 {
streamKey = *sKey
}
if urlParts[1] != streamKey {
if urlParts[1] != settings.GetStreamKey() {
fmt.Println("Due to key not match, denied stream")
return //If key not match, deny stream
}
@ -161,7 +156,11 @@ func main() {
os.Exit(1)
}
fmt.Println("Stream key: ", streamKey)
if sKey != nil && len(*sKey) != 0 {
settings.SetTempKey(*sKey)
}
fmt.Println("Stream key: ", settings.GetStreamKey())
fmt.Println("Admin password: ", settings.AdminPassword)
go http.ListenAndServe(address, nil)

View File

@ -19,6 +19,7 @@ type Settings struct {
Bans []BanInfo
StreamKey string
ListenAddress string
cmdLineKey string // stream key from the command line
}
type BanInfo struct {
@ -128,3 +129,20 @@ func (s *Settings) IsBanned(host string) (bool, []string) {
}
return false, nil
}
func (s *Settings) SetTempKey(key string) {
defer settingsMtx.Unlock()
settingsMtx.Lock()
s.cmdLineKey = key
}
func (s *Settings) GetStreamKey() string {
defer settingsMtx.Unlock()
settingsMtx.Lock()
if len(s.cmdLineKey) > 0 {
return s.cmdLineKey
}
return s.StreamKey
}