diff --git a/config_example.yaml b/config_example.yaml index 569595c..68b9226 100644 --- a/config_example.yaml +++ b/config_example.yaml @@ -17,7 +17,6 @@ steam: rate_per_sec: 1 sentry: ".sentry" login_key: ".login_key" - server_list: ".server.json" redis: address: "localhost:6379" diff --git a/csgo/demo_loader.go b/csgo/demo_loader.go index ba795d0..a2c77f0 100644 --- a/csgo/demo_loader.go +++ b/csgo/demo_loader.go @@ -4,7 +4,6 @@ import ( "context" "csgowtfd/ent" "csgowtfd/utils" - "encoding/json" "fmt" "github.com/an0nfunc/go-steam/v3" "github.com/an0nfunc/go-steam/v3/csgo/protocol/protobuf" @@ -16,7 +15,6 @@ import ( "go.uber.org/ratelimit" "google.golang.org/protobuf/proto" "io/ioutil" - "math/rand" "os" "time" ) @@ -26,17 +24,16 @@ const ( ) type DemoMatchLoaderConfig struct { - Username string - Password string - AuthCode string - Sentry string - LoginKey string - ServerList string - Db *ent.Client - Worker int - ApiKey string - RateLimit ratelimit.Limiter - Cache *cache.Cache + Username string + Password string + AuthCode string + Sentry string + LoginKey string + Db *ent.Client + Worker int + ApiKey string + RateLimit ratelimit.Limiter + Cache *cache.Cache } type DemoMatchLoader struct { @@ -47,12 +44,12 @@ type DemoMatchLoader struct { cmList []*netutil.PortAddr sentryFile string loginKey string - serverList string db *ent.Client dp *DemoParser parseDemo chan *Demo parseMap map[string]bool cache *cache.Cache + connecting bool } func AccountId2SteamId(accId uint32) uint64 { @@ -141,25 +138,14 @@ func (d *DemoMatchLoader) getMatchDetails(sharecode string) (*protobuf.CMsgGCCSt } } -func (d *DemoMatchLoader) getRandomCM() *netutil.PortAddr { - return d.cmList[rand.Intn(len(d.cmList))] -} - func (d *DemoMatchLoader) connectToSteam() error { if d.client.Connected() { return nil } - if d.cmList != nil { - err := d.client.ConnectTo(d.getRandomCM()) - if err != nil { - return err - } - } else { - _, err := d.client.Connect() - if err != nil { - return err - } + _, err := d.client.Connect() + if err != nil { + return err } return nil } @@ -167,7 +153,6 @@ func (d *DemoMatchLoader) connectToSteam() error { func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error { d.loginKey = config.LoginKey d.sentryFile = config.Sentry - d.serverList = config.ServerList d.db = config.Db d.dp = &DemoParser{} d.parseMap = map[string]bool{} @@ -199,18 +184,11 @@ func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error { d.steamLogin.LoginKey = string(hash) } - if _, err := os.Stat(d.serverList); err == nil { - rawJson, err := ioutil.ReadFile(d.serverList) - if err != nil { - return err - } - err = json.Unmarshal(rawJson, &d.cmList) - if err != nil { - return err - } - } - d.client = steam.NewClient() + err = steam.InitializeSteamDirectory() + if err != nil { + return err + } d.matchRecv = make(chan *protobuf.CMsgGCCStrike15V2_MatchList, 1000) d.parseDemo = make(chan *Demo, 1000) @@ -234,9 +212,12 @@ func (d DemoMatchLoader) LoadDemo(demo *Demo) error { } func (d DemoMatchLoader) connectLoop() { - for d.connectToSteam() != nil { - log.Infof("[DL] Retrying connecting to steam...") - time.Sleep(time.Second * 10) + if !d.connecting { + d.connecting = true + for d.connectToSteam() != nil { + log.Infof("[DL] Retrying connecting to steam...") + time.Sleep(time.Minute) + } } } @@ -246,17 +227,6 @@ func (d *DemoMatchLoader) steamEventHandler() { case *steam.ConnectedEvent: log.Debug("[DL] Connected!") d.client.Auth.LogOn(d.steamLogin) - case *steam.ClientCMListEvent: - log.Debug("[DL] CM list") - serverJson, err := json.Marshal(e.Addresses) - if err != nil { - log.Errorf("[DL] Unable to marshal JSON: %v", err) - } - - err = ioutil.WriteFile(d.serverList, serverJson, os.ModePerm) - if err != nil { - log.Errorf("[DL] Unable to write server list: %v", err) - } case *steam.MachineAuthUpdateEvent: log.Debug("[DL] Got sentry!") err := ioutil.WriteFile(d.sentryFile, e.Hash, os.ModePerm) diff --git a/main.go b/main.go index ad0fd59..2474609 100644 --- a/main.go +++ b/main.go @@ -822,17 +822,16 @@ func main() { // setup GC err = demoLoader.Setup(&csgo.DemoMatchLoaderConfig{ - Username: conf.Steam.Username, - Password: conf.Steam.Password, - AuthCode: conf.Steam.AuthCode, - Sentry: conf.Steam.Sentry, - LoginKey: conf.Steam.LoginKey, - ServerList: conf.Steam.ServerList, - Db: db, - Worker: conf.Parser.Worker, - ApiKey: conf.Steam.APIKey, - RateLimit: rL, - Cache: rdc, + Username: conf.Steam.Username, + Password: conf.Steam.Password, + AuthCode: conf.Steam.AuthCode, + Sentry: conf.Steam.Sentry, + LoginKey: conf.Steam.LoginKey, + Db: db, + Worker: conf.Parser.Worker, + ApiKey: conf.Steam.APIKey, + RateLimit: rL, + Cache: rdc, }) if err != nil { log.Fatalf("Unbale to setup DemoLoader: %v", err) diff --git a/utils/utils.go b/utils/utils.go index 234f736..9a0b955 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -44,7 +44,6 @@ type Conf struct { RatePerSecond int `yaml:"rate_per_sec"` Sentry string LoginKey string `yaml:"login_key"` - ServerList string `yaml:"server_list"` } Redis struct { Address string