moved spray timeout to config
This commit is contained in:
@@ -40,4 +40,6 @@ csgowtfd:
|
||||
# default: 30m
|
||||
sharecode_update: "30m"
|
||||
# days in which demos expire
|
||||
demos_expire: 30
|
||||
demos_expire: 30
|
||||
# ms between shots to count as spray
|
||||
spray_timeout: 500
|
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
26
main.go
26
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)
|
||||
|
@@ -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"`
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user