move login retry max to config
This commit is contained in:
@@ -17,6 +17,8 @@ steam:
|
|||||||
rate_per_sec: 1
|
rate_per_sec: 1
|
||||||
sentry: ".sentry"
|
sentry: ".sentry"
|
||||||
login_key: ".login_key"
|
login_key: ".login_key"
|
||||||
|
# maximum amount of time (in minutes) to wait before trying to reconnect to steam
|
||||||
|
max_retry_wait: 60
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
address: "localhost:6379"
|
address: "localhost:6379"
|
||||||
|
@@ -23,9 +23,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
APPID = 730
|
APPID = 730
|
||||||
LOGIN_FAILED = iota
|
LoginFailed = iota
|
||||||
LOGIN_SUCCESS
|
LoginSuccess
|
||||||
)
|
)
|
||||||
|
|
||||||
type DemoMatchLoaderConfig struct {
|
type DemoMatchLoaderConfig struct {
|
||||||
@@ -40,6 +40,7 @@ type DemoMatchLoaderConfig struct {
|
|||||||
RateLimit ratelimit.Limiter
|
RateLimit ratelimit.Limiter
|
||||||
Cache *cache.Cache
|
Cache *cache.Cache
|
||||||
SprayTimeout int
|
SprayTimeout int
|
||||||
|
RetryTimeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
type DemoMatchLoader struct {
|
type DemoMatchLoader struct {
|
||||||
@@ -59,6 +60,7 @@ type DemoMatchLoader struct {
|
|||||||
connectionWait uint64
|
connectionWait uint64
|
||||||
connectFeedback chan int
|
connectFeedback chan int
|
||||||
LoggedIn bool
|
LoggedIn bool
|
||||||
|
retryTimeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
func AccountId2SteamId(accId uint32) uint64 {
|
func AccountId2SteamId(accId uint32) uint64 {
|
||||||
@@ -188,6 +190,7 @@ func (dml *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error {
|
|||||||
dml.parseMap = map[string]bool{}
|
dml.parseMap = map[string]bool{}
|
||||||
dml.parseMapL = new(sync.RWMutex)
|
dml.parseMapL = new(sync.RWMutex)
|
||||||
dml.cache = config.Cache
|
dml.cache = config.Cache
|
||||||
|
dml.retryTimeout = config.RetryTimeout
|
||||||
dml.connectFeedback = make(chan int, 10)
|
dml.connectFeedback = make(chan int, 10)
|
||||||
err := dml.dp.Setup(config.Db, config.Worker, config.SprayTimeout)
|
err := dml.dp.Setup(config.Db, config.Worker, config.SprayTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -232,7 +235,7 @@ func (dml *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error {
|
|||||||
go dml.gcWorker(config.ApiKey, config.RateLimit)
|
go dml.gcWorker(config.ApiKey, config.RateLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
dml.connectFeedback <- LOGIN_FAILED
|
dml.connectFeedback <- LoginFailed
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -251,7 +254,7 @@ func (dml *DemoMatchLoader) connectLoop() {
|
|||||||
select {
|
select {
|
||||||
case res := <-dml.connectFeedback:
|
case res := <-dml.connectFeedback:
|
||||||
switch res {
|
switch res {
|
||||||
case LOGIN_FAILED:
|
case LoginFailed:
|
||||||
time.Sleep(time.Minute * time.Duration(dml.connectionWait))
|
time.Sleep(time.Minute * time.Duration(dml.connectionWait))
|
||||||
if !dml.LoggedIn {
|
if !dml.LoggedIn {
|
||||||
log.Infof("[DL] Connecting to steam...")
|
log.Infof("[DL] Connecting to steam...")
|
||||||
@@ -263,13 +266,13 @@ func (dml *DemoMatchLoader) connectLoop() {
|
|||||||
|
|
||||||
if dml.connectionWait == 0 {
|
if dml.connectionWait == 0 {
|
||||||
dml.connectionWait = 1
|
dml.connectionWait = 1
|
||||||
} else if dml.connectionWait > 20 {
|
} else if dml.connectionWait > uint64(dml.retryTimeout) {
|
||||||
dml.connectionWait = 20
|
dml.connectionWait = uint64(dml.retryTimeout)
|
||||||
} else {
|
} else {
|
||||||
dml.connectionWait *= 2
|
dml.connectionWait *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case LOGIN_SUCCESS:
|
case LoginSuccess:
|
||||||
log.Infof("[DL] Steam login successfully restored after %d minutes", dml.connectionWait)
|
log.Infof("[DL] Steam login successfully restored after %d minutes", dml.connectionWait)
|
||||||
dml.connectionWait = 0
|
dml.connectionWait = 0
|
||||||
}
|
}
|
||||||
@@ -292,7 +295,7 @@ func (dml *DemoMatchLoader) steamEventHandler() {
|
|||||||
case *steam.LoggedOnEvent:
|
case *steam.LoggedOnEvent:
|
||||||
log.Debug("[DL] Steam login success!")
|
log.Debug("[DL] Steam login success!")
|
||||||
dml.LoggedIn = true
|
dml.LoggedIn = true
|
||||||
dml.connectFeedback <- LOGIN_SUCCESS
|
dml.connectFeedback <- LoginSuccess
|
||||||
dml.client.Social.SetPersonaState(steamlang.EPersonaState_Online)
|
dml.client.Social.SetPersonaState(steamlang.EPersonaState_Online)
|
||||||
go dml.setPlaying()
|
go dml.setPlaying()
|
||||||
case *steam.LogOnFailedEvent:
|
case *steam.LogOnFailedEvent:
|
||||||
@@ -313,7 +316,7 @@ func (dml *DemoMatchLoader) steamEventHandler() {
|
|||||||
log.Warningf("[DL] Steam disconnected, trying to reconnect...")
|
log.Warningf("[DL] Steam disconnected, trying to reconnect...")
|
||||||
dml.GCReady = false
|
dml.GCReady = false
|
||||||
dml.LoggedIn = false
|
dml.LoggedIn = false
|
||||||
dml.connectFeedback <- LOGIN_FAILED
|
dml.connectFeedback <- LoginFailed
|
||||||
case *steam.LoginKeyEvent:
|
case *steam.LoginKeyEvent:
|
||||||
log.Debug("Got login_key!")
|
log.Debug("Got login_key!")
|
||||||
err := ioutil.WriteFile(dml.loginKey, []byte(e.LoginKey), os.ModePerm)
|
err := ioutil.WriteFile(dml.loginKey, []byte(e.LoginKey), os.ModePerm)
|
||||||
|
1
main.go
1
main.go
@@ -1165,6 +1165,7 @@ func main() {
|
|||||||
RateLimit: rL,
|
RateLimit: rL,
|
||||||
Cache: rdc,
|
Cache: rdc,
|
||||||
SprayTimeout: conf.Csgowtfd.SprayTimeout,
|
SprayTimeout: conf.Csgowtfd.SprayTimeout,
|
||||||
|
RetryTimeout: conf.Steam.MaxRetryWait,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error setting up DemoLoader: %v", err)
|
log.Fatalf("Error setting up DemoLoader: %v", err)
|
||||||
|
@@ -47,6 +47,7 @@ type Conf struct {
|
|||||||
RatePerSecond int `yaml:"rate_per_sec"`
|
RatePerSecond int `yaml:"rate_per_sec"`
|
||||||
Sentry string
|
Sentry string
|
||||||
LoginKey string `yaml:"login_key"`
|
LoginKey string `yaml:"login_key"`
|
||||||
|
MaxRetryWait int `yaml:"max_retry_wait"`
|
||||||
}
|
}
|
||||||
Redis struct {
|
Redis struct {
|
||||||
Address string
|
Address string
|
||||||
|
Reference in New Issue
Block a user