From 1d6396abfdd28bd5a580262d806f65793b0184ac Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Tue, 9 Nov 2021 18:59:00 +0100 Subject: [PATCH] moved spray timeout to config --- config_example.yaml | 4 +++- csgo/demo_loader.go | 23 ++++++++++++----------- csgo/demo_parser.go | 24 ++++++++++++------------ main.go | 26 ++++++++++++++------------ utils/utils.go | 1 + 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/config_example.yaml b/config_example.yaml index 724171d..e3f27f1 100644 --- a/config_example.yaml +++ b/config_example.yaml @@ -40,4 +40,6 @@ csgowtfd: # default: 30m sharecode_update: "30m" # days in which demos expire - demos_expire: 30 \ No newline at end of file + demos_expire: 30 + # ms between shots to count as spray + spray_timeout: 500 \ No newline at end of file diff --git a/csgo/demo_loader.go b/csgo/demo_loader.go index d61d7bd..a28886f 100644 --- a/csgo/demo_loader.go +++ b/csgo/demo_loader.go @@ -25,16 +25,17 @@ const ( ) type DemoMatchLoaderConfig struct { - Username string - Password string - AuthCode string - Sentry string - LoginKey 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 + SprayTimeout int } type DemoMatchLoader struct { @@ -160,7 +161,7 @@ func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error { d.parseMap = map[string]bool{} d.parseMapL = new(sync.Mutex) d.cache = config.Cache - err := d.dp.Setup(config.Db, config.Worker) + err := d.dp.Setup(config.Db, config.Worker, config.SprayTimeout) if err != nil { return err } diff --git a/csgo/demo_parser.go b/csgo/demo_parser.go index 5482852..dd9233c 100644 --- a/csgo/demo_parser.go +++ b/csgo/demo_parser.go @@ -27,9 +27,10 @@ type Demo struct { } type DemoParser struct { - demoQueue chan *Demo - tempDir string - db *ent.Client + demoQueue chan *Demo + tempDir string + db *ent.Client + sprayTimeout int } type Encounter struct { @@ -56,17 +57,15 @@ type DemoNotFoundError struct { error } -func (s *Sprays) Add(currentTime time.Duration, sprayPoint []float32, timeout int, maxLength int) { +func (s *Sprays) Add(currentTime time.Duration, sprayPoint []float32, timeout int) { sprayFound := false for _, sp := range s.Sprays { if currentTime.Milliseconds()-sp.Time.Milliseconds() <= int64(timeout) { sprayFound = true - if len(sp.Spray) < maxLength+1 { - sp.Spray = append(sp.Spray, []float32{ - sprayPoint[0] - sp.Spray[0][0], - sprayPoint[1] - sp.Spray[0][1], - }) - } + sp.Spray = append(sp.Spray, []float32{ + sprayPoint[0] - sp.Spray[0][0], + sprayPoint[1] - sp.Spray[0][1], + }) } } if !sprayFound { @@ -105,9 +104,10 @@ func (s *Sprays) Avg() (avg [][]float32) { return } -func (p *DemoParser) Setup(db *ent.Client, worker int) error { +func (p *DemoParser) Setup(db *ent.Client, worker int, sprayTimeout int) error { p.demoQueue = make(chan *Demo, 1000) p.db = db + p.sprayTimeout = sprayTimeout for i := 0; i < worker; i++ { go p.parseWorker() } @@ -267,7 +267,7 @@ func (p *DemoParser) parseWorker() { for _, spray := range spays { if e.Shooter.SteamID64 == spray.Sprayer && int(e.Weapon.Type) == spray.Weapon { playerWeaponFound = true - spray.Add(demoParser.CurrentTime(), []float32{e.Shooter.ViewDirectionX(), e.Shooter.ViewDirectionY()}, 500, 10) + spray.Add(demoParser.CurrentTime(), []float32{e.Shooter.ViewDirectionX(), e.Shooter.ViewDirectionY()}, p.sprayTimeout) } } diff --git a/main.go b/main.go index 1fdadb0..9a7c633 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ import ( "time" ) +//goland:noinspection ALL var ( conf = utils.Conf{} demoLoader = &csgo.DemoMatchLoader{} @@ -42,7 +43,7 @@ var ( rdb *redis.Client rdc *cache.Cache rL ratelimit.Limiter - configFlag = flag.String("config", "config.yaml", "Set config to use") + configFlag = flag.String("config", "config.yaml", "Set config file to use") journalLogFlag = flag.Bool("journal", false, "Log to systemd journal instead of stdout") sqlDebugFlag = flag.Bool("sqldebug", false, "Debug SQL queries") ) @@ -695,7 +696,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) { Stats: []*utils.StatsResponse{}, } - if tMatch.Date.After(time.Now().AddDate(0, 0, -30)) { + if tMatch.Date.After(time.Now().AddDate(0, 0, -1*conf.Csgowtfd.DemosExpire)) { mResponse.ReplayURL = tMatch.ReplayURL } @@ -850,16 +851,17 @@ 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, - 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, + SprayTimeout: conf.Csgowtfd.SprayTimeout, }) if err != nil { log.Fatalf("Unbale to setup DemoLoader: %v", err) diff --git a/utils/utils.go b/utils/utils.go index 77c5c57..7a86457 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -61,6 +61,7 @@ type Conf struct { ProfileUpdate string `yaml:"profile_update"` SharecodeUpdate string `yaml:"sharecode_update"` DemosExpire int `yaml:"demos_expire"` + SprayTimeout int `yaml:"spray_timeout"` } }