switched to build-in steam server list
This commit is contained in:
@@ -17,7 +17,6 @@ steam:
|
||||
rate_per_sec: 1
|
||||
sentry: ".sentry"
|
||||
login_key: ".login_key"
|
||||
server_list: ".server.json"
|
||||
|
||||
redis:
|
||||
address: "localhost:6379"
|
||||
|
@@ -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"
|
||||
)
|
||||
@@ -31,7 +29,6 @@ type DemoMatchLoaderConfig struct {
|
||||
AuthCode string
|
||||
Sentry string
|
||||
LoginKey string
|
||||
ServerList string
|
||||
Db *ent.Client
|
||||
Worker int
|
||||
ApiKey string
|
||||
@@ -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,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 {
|
||||
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
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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() {
|
||||
if !d.connecting {
|
||||
d.connecting = true
|
||||
for d.connectToSteam() != nil {
|
||||
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:
|
||||
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)
|
||||
|
1
main.go
1
main.go
@@ -827,7 +827,6 @@ func main() {
|
||||
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,
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user