switched to build-in steam server list

This commit is contained in:
2021-10-27 01:55:01 +02:00
parent 20f95589db
commit 9019a19369
4 changed files with 34 additions and 67 deletions

View File

@@ -17,7 +17,6 @@ steam:
rate_per_sec: 1 rate_per_sec: 1
sentry: ".sentry" sentry: ".sentry"
login_key: ".login_key" login_key: ".login_key"
server_list: ".server.json"
redis: redis:
address: "localhost:6379" address: "localhost:6379"

View File

@@ -4,7 +4,6 @@ import (
"context" "context"
"csgowtfd/ent" "csgowtfd/ent"
"csgowtfd/utils" "csgowtfd/utils"
"encoding/json"
"fmt" "fmt"
"github.com/an0nfunc/go-steam/v3" "github.com/an0nfunc/go-steam/v3"
"github.com/an0nfunc/go-steam/v3/csgo/protocol/protobuf" "github.com/an0nfunc/go-steam/v3/csgo/protocol/protobuf"
@@ -16,7 +15,6 @@ import (
"go.uber.org/ratelimit" "go.uber.org/ratelimit"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"io/ioutil" "io/ioutil"
"math/rand"
"os" "os"
"time" "time"
) )
@@ -26,17 +24,16 @@ const (
) )
type DemoMatchLoaderConfig struct { type DemoMatchLoaderConfig struct {
Username string Username string
Password string Password string
AuthCode string AuthCode string
Sentry string Sentry string
LoginKey string LoginKey string
ServerList string Db *ent.Client
Db *ent.Client Worker int
Worker int ApiKey string
ApiKey string RateLimit ratelimit.Limiter
RateLimit ratelimit.Limiter Cache *cache.Cache
Cache *cache.Cache
} }
type DemoMatchLoader struct { type DemoMatchLoader struct {
@@ -47,12 +44,12 @@ type DemoMatchLoader struct {
cmList []*netutil.PortAddr cmList []*netutil.PortAddr
sentryFile string sentryFile string
loginKey string loginKey string
serverList string
db *ent.Client db *ent.Client
dp *DemoParser dp *DemoParser
parseDemo chan *Demo parseDemo chan *Demo
parseMap map[string]bool parseMap map[string]bool
cache *cache.Cache cache *cache.Cache
connecting bool
} }
func AccountId2SteamId(accId uint32) uint64 { 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 { func (d *DemoMatchLoader) connectToSteam() error {
if d.client.Connected() { if d.client.Connected() {
return nil return nil
} }
if d.cmList != nil { _, err := d.client.Connect()
err := d.client.ConnectTo(d.getRandomCM()) if err != nil {
if err != nil { return err
return err
}
} else {
_, err := d.client.Connect()
if err != nil {
return err
}
} }
return nil return nil
} }
@@ -167,7 +153,6 @@ func (d *DemoMatchLoader) connectToSteam() error {
func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error { func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error {
d.loginKey = config.LoginKey d.loginKey = config.LoginKey
d.sentryFile = config.Sentry d.sentryFile = config.Sentry
d.serverList = config.ServerList
d.db = config.Db d.db = config.Db
d.dp = &DemoParser{} d.dp = &DemoParser{}
d.parseMap = map[string]bool{} d.parseMap = map[string]bool{}
@@ -199,18 +184,11 @@ func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error {
d.steamLogin.LoginKey = string(hash) 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() d.client = steam.NewClient()
err = steam.InitializeSteamDirectory()
if err != nil {
return err
}
d.matchRecv = make(chan *protobuf.CMsgGCCStrike15V2_MatchList, 1000) d.matchRecv = make(chan *protobuf.CMsgGCCStrike15V2_MatchList, 1000)
d.parseDemo = make(chan *Demo, 1000) d.parseDemo = make(chan *Demo, 1000)
@@ -234,9 +212,12 @@ func (d DemoMatchLoader) LoadDemo(demo *Demo) error {
} }
func (d DemoMatchLoader) connectLoop() { func (d DemoMatchLoader) connectLoop() {
for d.connectToSteam() != nil { if !d.connecting {
log.Infof("[DL] Retrying connecting to steam...") d.connecting = true
time.Sleep(time.Second * 10) 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: case *steam.ConnectedEvent:
log.Debug("[DL] Connected!") log.Debug("[DL] Connected!")
d.client.Auth.LogOn(d.steamLogin) 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: case *steam.MachineAuthUpdateEvent:
log.Debug("[DL] Got sentry!") log.Debug("[DL] Got sentry!")
err := ioutil.WriteFile(d.sentryFile, e.Hash, os.ModePerm) err := ioutil.WriteFile(d.sentryFile, e.Hash, os.ModePerm)

21
main.go
View File

@@ -822,17 +822,16 @@ func main() {
// setup GC // setup GC
err = demoLoader.Setup(&csgo.DemoMatchLoaderConfig{ err = demoLoader.Setup(&csgo.DemoMatchLoaderConfig{
Username: conf.Steam.Username, Username: conf.Steam.Username,
Password: conf.Steam.Password, Password: conf.Steam.Password,
AuthCode: conf.Steam.AuthCode, AuthCode: conf.Steam.AuthCode,
Sentry: conf.Steam.Sentry, Sentry: conf.Steam.Sentry,
LoginKey: conf.Steam.LoginKey, LoginKey: conf.Steam.LoginKey,
ServerList: conf.Steam.ServerList, Db: db,
Db: db, Worker: conf.Parser.Worker,
Worker: conf.Parser.Worker, ApiKey: conf.Steam.APIKey,
ApiKey: conf.Steam.APIKey, RateLimit: rL,
RateLimit: rL, Cache: rdc,
Cache: rdc,
}) })
if err != nil { if err != nil {
log.Fatalf("Unbale to setup DemoLoader: %v", err) log.Fatalf("Unbale to setup DemoLoader: %v", err)

View File

@@ -44,7 +44,6 @@ 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"`
ServerList string `yaml:"server_list"`
} }
Redis struct { Redis struct {
Address string Address string