Skip to content

Commit 4df89e0

Browse files
committed
events: add field RankUpdate.Player
this is only set if the player has not already disconnected
1 parent 44a1654 commit 4df89e0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pkg/demoinfocs/events/events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ type RankUpdate struct {
420420
RankOld int
421421
RankNew int
422422
WinCount int
423+
Player *common.Player // may be nil if the player has already disconnected
423424
}
424425

425426
// SteamID64 converts SteamID32 to the 64-bit SteamID variant and returns the result.

pkg/demoinfocs/user_messages.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package demoinfocs
33
import (
44
"fmt"
55

6-
"github.com/markus-wa/go-unassert"
6+
unassert "github.com/markus-wa/go-unassert"
77

8+
common "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
89
events "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
910
msg "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/msg"
1011
)
@@ -123,12 +124,21 @@ func (umh userMessageHandler) rankUpdate(um *msg.CSVCMsg_UserMessage) {
123124
}
124125

125126
for _, v := range st.RankUpdate {
127+
// find player (if he hasn't disconnected already)
128+
var player *common.Player
129+
for _, pl := range umh.parser.gameState.playersByUserID { //nolint:wsl
130+
if pl.SteamID32() == uint32(v.AccountId) {
131+
player = pl
132+
}
133+
}
134+
126135
umh.dispatch(events.RankUpdate{
127136
SteamID32: v.AccountId,
128137
RankOld: int(v.RankOld),
129138
RankNew: int(v.RankNew),
130139
WinCount: int(v.NumWins),
131140
RankChange: v.RankChange,
141+
Player: player,
132142
})
133143
}
134144
}

0 commit comments

Comments
 (0)