From fd5a065de24c850838fb692b71bb6aa40f4d8842 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Wed, 23 Feb 2022 07:08:00 +0100 Subject: [PATCH] added more login failed handling to steam connection manager --- csgo/demo_loader.go | 55 ++++++++++++++++++++++++++++----------------- utils/utils.go | 1 - 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/csgo/demo_loader.go b/csgo/demo_loader.go index 51b98f2..f76b0ec 100644 --- a/csgo/demo_loader.go +++ b/csgo/demo_loader.go @@ -41,20 +41,21 @@ type DemoMatchLoaderConfig struct { } type DemoMatchLoader struct { - client *steam.Client - GCReady bool - steamLogin *steam.LogOnDetails - matchRecv chan *protobuf.CMsgGCCStrike15V2_MatchList - cmList []*netutil.PortAddr - sentryFile string - loginKey string - db *ent.Client - dp *DemoParser - parseDemo chan *Demo - parseMap map[string]bool - parseMapL *sync.RWMutex - cache *cache.Cache - connecting bool + client *steam.Client + GCReady bool + steamLogin *steam.LogOnDetails + matchRecv chan *protobuf.CMsgGCCStrike15V2_MatchList + cmList []*netutil.PortAddr + sentryFile string + loginKey string + db *ent.Client + dp *DemoParser + parseDemo chan *Demo + parseMap map[string]bool + parseMapL *sync.RWMutex + cache *cache.Cache + connecting *sync.Mutex + connectionWait uint64 } func AccountId2SteamId(accId uint32) uint64 { @@ -184,6 +185,7 @@ func (dml *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error { dml.parseMap = map[string]bool{} dml.parseMapL = new(sync.RWMutex) dml.cache = config.Cache + dml.connecting = new(sync.Mutex) err := dml.dp.Setup(config.Db, config.Worker, config.SprayTimeout) if err != nil { return err @@ -240,11 +242,20 @@ func (dml DemoMatchLoader) LoadDemo(demo *Demo) error { } func (dml DemoMatchLoader) connectLoop() { - if !dml.connecting { - dml.connecting = true + dml.connecting.Lock() + defer dml.connecting.Unlock() + if !dml.client.Connected() { for dml.connectToSteam() != nil { log.Infof("[DL] Retrying connecting to steam...") - time.Sleep(time.Minute * 10) + if dml.connectionWait == 0 { + dml.connectionWait = 1 + } + time.Sleep(time.Minute * time.Duration(dml.connectionWait)) + dml.connectionWait *= 2 + } + if dml.client.Connected() { + log.Infof("[DL] Steam login successfully restored after %d minutes", dml.connectionWait) + dml.connectionWait = 1 } } } @@ -262,21 +273,23 @@ func (dml *DemoMatchLoader) steamEventHandler() { log.Errorf("[DL] Unable write sentry file: %v", err) } case *steam.LoggedOnEvent: - log.Debug("[DL] Login successfully!") + log.Debug("[DL] Steam login success!") dml.client.Social.SetPersonaState(steamlang.EPersonaState_Online) go dml.setPlaying() case *steam.LogOnFailedEvent: - log.Warningf("[DL] Steam login denied: %+v", e) + log.Debugf("[DL] Steam login denied: %+v", e) switch e.Result { case steamlang.EResult_AccountLogonDenied: log.Fatalf("[DL] Please provide AuthCode in config") case steamlang.EResult_InvalidPassword: _ = os.Remove(dml.sentryFile) _ = os.Remove(dml.loginKey) - log.Warningf("[DL] Steam login wrong") + log.Warningf("[DL] Steam login failed: InvalidPassword") go dml.connectLoop() case steamlang.EResult_InvalidLoginAuthCode: log.Fatalf("[DL] Steam auth code wrong") + default: + log.Warningf("[DL] Unhandled login fasiled event %+v", e) } case *steam.DisconnectedEvent: log.Warningf("Steam disconnected, trying to reconnect...") @@ -287,7 +300,7 @@ func (dml *DemoMatchLoader) steamEventHandler() { if err != nil { log.Errorf("[DL] Unable write login_key: %v", err) } - case steam.FatalErrorEvent: + case *steam.FatalErrorEvent: log.Debugf("[DL] Got FatalError %+v", e) case error: log.Fatalf("[DL] Got error %+v", e) diff --git a/utils/utils.go b/utils/utils.go index 029f5a0..70d7224 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -178,7 +178,6 @@ type ChatResponse struct { Message string `json:"message"` AllChat bool `json:"all_chat"` Tick int `json:"tick"` - Translated bool `json:"translated,omitempty"` TranslatedFrom string `json:"translated_from,omitempty"` TranslatedTo string `json:"translated_to,omitempty"` }