moved spray timeout to config
This commit is contained in:
@@ -41,3 +41,5 @@ csgowtfd:
|
|||||||
sharecode_update: "30m"
|
sharecode_update: "30m"
|
||||||
# days in which demos expire
|
# days in which demos expire
|
||||||
demos_expire: 30
|
demos_expire: 30
|
||||||
|
# ms between shots to count as spray
|
||||||
|
spray_timeout: 500
|
@@ -35,6 +35,7 @@ type DemoMatchLoaderConfig struct {
|
|||||||
ApiKey string
|
ApiKey string
|
||||||
RateLimit ratelimit.Limiter
|
RateLimit ratelimit.Limiter
|
||||||
Cache *cache.Cache
|
Cache *cache.Cache
|
||||||
|
SprayTimeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
type DemoMatchLoader struct {
|
type DemoMatchLoader struct {
|
||||||
@@ -160,7 +161,7 @@ func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error {
|
|||||||
d.parseMap = map[string]bool{}
|
d.parseMap = map[string]bool{}
|
||||||
d.parseMapL = new(sync.Mutex)
|
d.parseMapL = new(sync.Mutex)
|
||||||
d.cache = config.Cache
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ type DemoParser struct {
|
|||||||
demoQueue chan *Demo
|
demoQueue chan *Demo
|
||||||
tempDir string
|
tempDir string
|
||||||
db *ent.Client
|
db *ent.Client
|
||||||
|
sprayTimeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Encounter struct {
|
type Encounter struct {
|
||||||
@@ -56,19 +57,17 @@ type DemoNotFoundError struct {
|
|||||||
error
|
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
|
sprayFound := false
|
||||||
for _, sp := range s.Sprays {
|
for _, sp := range s.Sprays {
|
||||||
if currentTime.Milliseconds()-sp.Time.Milliseconds() <= int64(timeout) {
|
if currentTime.Milliseconds()-sp.Time.Milliseconds() <= int64(timeout) {
|
||||||
sprayFound = true
|
sprayFound = true
|
||||||
if len(sp.Spray) < maxLength+1 {
|
|
||||||
sp.Spray = append(sp.Spray, []float32{
|
sp.Spray = append(sp.Spray, []float32{
|
||||||
sprayPoint[0] - sp.Spray[0][0],
|
sprayPoint[0] - sp.Spray[0][0],
|
||||||
sprayPoint[1] - sp.Spray[0][1],
|
sprayPoint[1] - sp.Spray[0][1],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if !sprayFound {
|
if !sprayFound {
|
||||||
s.Sprays = append(s.Sprays, &Spray{
|
s.Sprays = append(s.Sprays, &Spray{
|
||||||
Time: currentTime,
|
Time: currentTime,
|
||||||
@@ -105,9 +104,10 @@ func (s *Sprays) Avg() (avg [][]float32) {
|
|||||||
return
|
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.demoQueue = make(chan *Demo, 1000)
|
||||||
p.db = db
|
p.db = db
|
||||||
|
p.sprayTimeout = sprayTimeout
|
||||||
for i := 0; i < worker; i++ {
|
for i := 0; i < worker; i++ {
|
||||||
go p.parseWorker()
|
go p.parseWorker()
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ func (p *DemoParser) parseWorker() {
|
|||||||
for _, spray := range spays {
|
for _, spray := range spays {
|
||||||
if e.Shooter.SteamID64 == spray.Sprayer && int(e.Weapon.Type) == spray.Weapon {
|
if e.Shooter.SteamID64 == spray.Sprayer && int(e.Weapon.Type) == spray.Weapon {
|
||||||
playerWeaponFound = true
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
main.go
6
main.go
@@ -34,6 +34,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//goland:noinspection ALL
|
||||||
var (
|
var (
|
||||||
conf = utils.Conf{}
|
conf = utils.Conf{}
|
||||||
demoLoader = &csgo.DemoMatchLoader{}
|
demoLoader = &csgo.DemoMatchLoader{}
|
||||||
@@ -42,7 +43,7 @@ var (
|
|||||||
rdb *redis.Client
|
rdb *redis.Client
|
||||||
rdc *cache.Cache
|
rdc *cache.Cache
|
||||||
rL ratelimit.Limiter
|
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")
|
journalLogFlag = flag.Bool("journal", false, "Log to systemd journal instead of stdout")
|
||||||
sqlDebugFlag = flag.Bool("sqldebug", false, "Debug SQL queries")
|
sqlDebugFlag = flag.Bool("sqldebug", false, "Debug SQL queries")
|
||||||
)
|
)
|
||||||
@@ -695,7 +696,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
|
|||||||
Stats: []*utils.StatsResponse{},
|
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
|
mResponse.ReplayURL = tMatch.ReplayURL
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -860,6 +861,7 @@ func main() {
|
|||||||
ApiKey: conf.Steam.APIKey,
|
ApiKey: conf.Steam.APIKey,
|
||||||
RateLimit: rL,
|
RateLimit: rL,
|
||||||
Cache: rdc,
|
Cache: rdc,
|
||||||
|
SprayTimeout: conf.Csgowtfd.SprayTimeout,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unbale to setup DemoLoader: %v", err)
|
log.Fatalf("Unbale to setup DemoLoader: %v", err)
|
||||||
|
@@ -61,6 +61,7 @@ type Conf struct {
|
|||||||
ProfileUpdate string `yaml:"profile_update"`
|
ProfileUpdate string `yaml:"profile_update"`
|
||||||
SharecodeUpdate string `yaml:"sharecode_update"`
|
SharecodeUpdate string `yaml:"sharecode_update"`
|
||||||
DemosExpire int `yaml:"demos_expire"`
|
DemosExpire int `yaml:"demos_expire"`
|
||||||
|
SprayTimeout int `yaml:"spray_timeout"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user