Skip to content

Commit b0a579b

Browse files
authored
fix: parse player name in connect/disconnect events (#108)
* fix: parse player name in connect/disconnect events Connect and disconnect events have the format [frameNum, "type", "playerName"] where the third element is a string. The parser was incorrectly treating this as a numeric SourceID, causing the player name to be lost when converting to protobuf/flatbuffers format. This fix adds special handling for connected/disconnected event types to store the player name in the Message field, which the frontend correctly reads. * test: add edge case for connect event without player name
1 parent 4a0c378 commit b0a579b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

internal/storage/parser_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,54 @@ func TestParserV1_parseEvent_EdgeCases(t *testing.T) {
544544
t.Errorf("Type = %q, want %q", evt.Type, "test")
545545
}
546546
})
547+
548+
t.Run("connected event", func(t *testing.T) {
549+
evt := p.parseEvent([]interface{}{2.0, "connected", "Cal"})
550+
if evt == nil {
551+
t.Fatal("expected non-nil event")
552+
}
553+
if evt.FrameNum != 2 {
554+
t.Errorf("FrameNum = %d, want %d", evt.FrameNum, 2)
555+
}
556+
if evt.Type != "connected" {
557+
t.Errorf("Type = %q, want %q", evt.Type, "connected")
558+
}
559+
if evt.Message != "Cal" {
560+
t.Errorf("Message = %q, want %q", evt.Message, "Cal")
561+
}
562+
if evt.SourceID != 0 {
563+
t.Errorf("SourceID = %d, want %d (should not be set)", evt.SourceID, 0)
564+
}
565+
})
566+
567+
t.Run("disconnected event", func(t *testing.T) {
568+
evt := p.parseEvent([]interface{}{3.0, "disconnected", "Wraith"})
569+
if evt == nil {
570+
t.Fatal("expected non-nil event")
571+
}
572+
if evt.FrameNum != 3 {
573+
t.Errorf("FrameNum = %d, want %d", evt.FrameNum, 3)
574+
}
575+
if evt.Type != "disconnected" {
576+
t.Errorf("Type = %q, want %q", evt.Type, "disconnected")
577+
}
578+
if evt.Message != "Wraith" {
579+
t.Errorf("Message = %q, want %q", evt.Message, "Wraith")
580+
}
581+
})
582+
583+
t.Run("connected event without player name", func(t *testing.T) {
584+
evt := p.parseEvent([]interface{}{5.0, "connected"})
585+
if evt == nil {
586+
t.Fatal("expected non-nil event")
587+
}
588+
if evt.Type != "connected" {
589+
t.Errorf("Type = %q, want %q", evt.Type, "connected")
590+
}
591+
if evt.Message != "" {
592+
t.Errorf("Message = %q, want empty string", evt.Message)
593+
}
594+
})
547595
}
548596

549597
func TestParserV1_parseMarker_EdgeCases(t *testing.T) {

internal/storage/parser_v1.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ func (p *ParserV1) parseEvent(evtArr []interface{}) *Event {
130130
Type: toString(evtArr[1]),
131131
}
132132

133+
// Connect/disconnect events: [frameNum, "type", "playerName"]
134+
if event.Type == "connected" || event.Type == "disconnected" {
135+
if len(evtArr) > 2 {
136+
event.Message = toString(evtArr[2])
137+
}
138+
return event
139+
}
140+
133141
// Parse additional fields based on event type
134142
// Common format: [frameNum, "type", sourceId, targetId, ...]
135143
if len(evtArr) > 2 {

0 commit comments

Comments
 (0)