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

@@ -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)