Skip to content

Commit 7de8cfb

Browse files
committed
feat: dispatch server rank update event
1 parent 89faff3 commit 7de8cfb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/demoinfocs/net_messages.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/binary"
66
"fmt"
77

8+
"github.com/markus-wa/go-unassert"
89
"github.com/markus-wa/ice-cipher-go/pkg/ice"
910
"google.golang.org/protobuf/proto"
1011

@@ -108,6 +109,28 @@ func (p *parser) handleServerInfoS2(srvInfo *msgs2.CSVCMsg_ServerInfo) {
108109
})
109110
}
110111

112+
func (p *parser) handleServerRankUpdate(msg *msgs2.CCSUsrMsg_ServerRankUpdate) {
113+
for _, v := range msg.RankUpdate {
114+
steamID32 := uint32(v.GetAccountId())
115+
player, ok := p.gameState.playersBySteamID32[steamID32]
116+
if !ok {
117+
errMsg := fmt.Sprintf("rank update for unknown player with SteamID32=%d", steamID32)
118+
119+
p.eventDispatcher.Dispatch(events.ParserWarn{Message: errMsg})
120+
unassert.Error(errMsg)
121+
}
122+
123+
p.eventDispatcher.Dispatch(events.RankUpdate{
124+
SteamID32: v.GetAccountId(),
125+
RankOld: int(v.GetRankOld()),
126+
RankNew: int(v.GetRankNew()),
127+
WinCount: int(v.GetNumWins()),
128+
RankChange: v.GetRankChange(),
129+
Player: player,
130+
})
131+
}
132+
}
133+
111134
func (p *parser) handleEncryptedData(msg *msg.CSVCMsg_EncryptedData) {
112135
if msg.GetKeyType() != 2 {
113136
return

pkg/demoinfocs/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ func NewParserWithConfig(demostream io.Reader, config ParserConfig) Parser {
411411
p.msgDispatcher.RegisterHandler(p.handleCreateStringTableS2)
412412
p.msgDispatcher.RegisterHandler(p.handleUpdateStringTableS2)
413413
p.msgDispatcher.RegisterHandler(p.handleSetConVarS2)
414+
p.msgDispatcher.RegisterHandler(p.handleServerRankUpdate)
414415

415416
if config.MsgQueueBufferSize >= 0 {
416417
p.initMsgQueue(config.MsgQueueBufferSize)

0 commit comments

Comments
 (0)