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