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"
) )
@@ -31,7 +29,6 @@ type DemoMatchLoaderConfig struct {
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
@@ -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,33 +138,21 @@ 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.ConnectTo(d.getRandomCM())
if err != nil {
return err
}
} else {
_, err := d.client.Connect() _, err := d.client.Connect()
if err != nil { if err != nil {
return err return err
} }
}
return nil return nil
} }
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() {
if !d.connecting {
d.connecting = true
for d.connectToSteam() != nil { for d.connectToSteam() != nil {
log.Infof("[DL] Retrying connecting to steam...") log.Infof("[DL] Retrying connecting to steam...")
time.Sleep(time.Second * 10) 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)

View File

@@ -827,7 +827,6 @@ func main() {
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,

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