Skip to content

Commit 7b92d66

Browse files
committed
wip
1 parent b2480e0 commit 7b92d66

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

cmd/server/http.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func handleParse(w http.ResponseWriter, r *http.Request) {
7070
if logPrefix == "" {
7171
logPrefix = "<no-id>"
7272
}
73-
log.Printf("[%s] fetching demo", logPrefix)
73+
log.Printf("[%s] fetching demo %s", logPrefix, req.DemoURL)
74+
fetchStart := time.Now()
7475

7576
demoResp, err := http.Get(req.DemoURL)
7677
if err != nil {
@@ -85,12 +86,18 @@ func handleParse(w http.ResponseWriter, r *http.Request) {
8586
)
8687
return
8788
}
89+
log.Printf("[%s] fetched demo in %s (Content-Length=%s)",
90+
logPrefix,
91+
time.Since(fetchStart),
92+
demoResp.Header.Get("Content-Length"),
93+
)
8894

8995
body, err := sniffDemoStream(demoResp.Body, logPrefix)
9096
if err != nil {
9197
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
9298
return
9399
}
100+
log.Printf("[%s] parsing demo", logPrefix)
94101
parseAndRespond(w, body, logPrefix)
95102
}
96103

internal/parser/grenades.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,29 @@ func (s *state) onFireGrenadeStart(e events.FireGrenadeStart) {
181181
}
182182
s.emitDetonate(e.GrenadeEvent, "Molotov")
183183
}
184+
185+
// onPlayerFlashed fires once per blinded player per flash. We capture
186+
// the attacker (thrower), the victim, and the resulting blind duration
187+
// so player_flashes aggregates (enemies_flashed / team_flashed /
188+
// avg_blind_time) work for imported demos.
189+
func (s *state) onPlayerFlashed(e events.PlayerFlashed) {
190+
if !s.matchStarted {
191+
return
192+
}
193+
if e.Player == nil || e.Attacker == nil {
194+
return
195+
}
196+
attackerTeam := teamCode(e.Attacker.Team)
197+
victimTeam := teamCode(e.Player.Team)
198+
ev := EventFlash{
199+
Tick: s.parser.GameState().IngameTick(),
200+
Round: s.currentRound,
201+
AttackerSteamID: steamIDStr(e.Attacker),
202+
AttackerTeam: attackerTeam,
203+
VictimSteamID: steamIDStr(e.Player),
204+
VictimTeam: victimTeam,
205+
Duration: e.Player.FlashDurationTime().Seconds(),
206+
TeamFlash: attackerTeam != "" && attackerTeam == victimTeam,
207+
}
208+
s.res.Flashes = append(s.res.Flashes, ev)
209+
}

internal/parser/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func (s *state) registerHandlers() {
140140
s.parser.RegisterEventHandler(s.onFlashExplode)
141141
s.parser.RegisterEventHandler(s.onSmokeStart)
142142
s.parser.RegisterEventHandler(s.onFireGrenadeStart)
143+
s.parser.RegisterEventHandler(s.onPlayerFlashed)
143144
}
144145

145146
// finalize resolves header-equivalent fields from the live parser

internal/parser/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ type EventPosition struct {
118118
HasDefuser bool `json:"has_defuser,omitempty"`
119119
}
120120

121+
type EventFlash struct {
122+
Tick int `json:"tick"`
123+
Round int `json:"round,omitempty"`
124+
AttackerSteamID string `json:"attacker,omitempty"`
125+
AttackerTeam string `json:"attacker_team,omitempty"`
126+
VictimSteamID string `json:"victim,omitempty"`
127+
VictimTeam string `json:"victim_team,omitempty"`
128+
Duration float64 `json:"duration,omitempty"`
129+
TeamFlash bool `json:"team_flash,omitempty"`
130+
}
131+
121132
type EventRoundInventory struct {
122133
Round int `json:"round,omitempty"`
123134
AttackerSteamID string `json:"attacker,omitempty"`
@@ -205,6 +216,7 @@ type Result struct {
205216
Spotted []EventSpotted `json:"spotted,omitempty"`
206217
GrenadeThrows []EventGrenadeThrow `json:"grenade_throws,omitempty"`
207218
GrenadeDetonations []EventGrenadeDetonate `json:"grenade_detonations,omitempty"`
219+
Flashes []EventFlash `json:"flashes,omitempty"`
208220
RoundInventory []EventRoundInventory `json:"round_inventory,omitempty"`
209221
Positions []EventPosition `json:"positions,omitempty"`
210222
KitDrops []EventKitDrop `json:"kit_drops,omitempty"`

0 commit comments

Comments
 (0)