switched to go-retry for steam login; moved match reparsing higher in housekeeping
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/an0nfunc/go-steam/v3/protocol/gamecoordinator"
|
||||
"github.com/an0nfunc/go-steam/v3/protocol/steamlang"
|
||||
"github.com/go-redis/cache/v8"
|
||||
"github.com/sethvargo/go-retry"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -56,10 +57,9 @@ type DemoMatchLoader struct {
|
||||
parseMap map[string]bool
|
||||
parseMapL *sync.RWMutex
|
||||
cache *cache.Cache
|
||||
connectionWait uint64
|
||||
connectionWait retry.Backoff
|
||||
connectFeedback chan int
|
||||
LoggedIn bool
|
||||
retryTimeout int
|
||||
}
|
||||
|
||||
func AccountId2SteamId(accId uint32) uint64 {
|
||||
@@ -189,8 +189,9 @@ 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)
|
||||
dml.connectionWait = retry.NewExponential(time.Second)
|
||||
dml.connectionWait = retry.WithCappedDuration(time.Minute*time.Duration(config.RetryTimeout), dml.connectionWait)
|
||||
err := dml.dp.Setup(config.Db, config.Worker, config.SprayTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -261,7 +262,9 @@ func (dml *DemoMatchLoader) connectLoop() {
|
||||
case res := <-dml.connectFeedback:
|
||||
switch res {
|
||||
case LoginFailed:
|
||||
time.Sleep(time.Minute * time.Duration(dml.connectionWait))
|
||||
if sleep, ok := dml.connectionWait.Next(); ok {
|
||||
time.Sleep(sleep)
|
||||
}
|
||||
if !dml.LoggedIn {
|
||||
log.Infof("[DL] Connecting to steam...")
|
||||
|
||||
@@ -269,18 +272,10 @@ func (dml *DemoMatchLoader) connectLoop() {
|
||||
if err != nil {
|
||||
log.Warningf("[DL] Error connecting to steam: %v", err)
|
||||
}
|
||||
|
||||
if dml.connectionWait == 0 {
|
||||
dml.connectionWait = 1
|
||||
} else if dml.connectionWait > uint64(dml.retryTimeout) {
|
||||
dml.connectionWait = uint64(dml.retryTimeout)
|
||||
} else {
|
||||
dml.connectionWait *= 2
|
||||
}
|
||||
}
|
||||
case LoginSuccess:
|
||||
log.Infof("[DL] Steam login successfully restored after %d minutes", dml.connectionWait)
|
||||
dml.connectionWait = 0
|
||||
dml.connectionWait = retry.NewExponential(time.Minute)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user