Skip to content

Commit 489d6fb

Browse files
allenyminmarkus-wa
authored andcommitted
events: added RankUpdate event dispatching (#112)
1 parent 2327ef7 commit 489d6fb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

examples/print-events/print_events.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func main() {
5656
fmt.Printf("Chat - %s says: %s\n", formatPlayer(e.Sender), e.Text)
5757
})
5858

59+
p.RegisterEventHandler(func(e events.RankUpdate) {
60+
fmt.Printf("Rank Update: %d went from rank %d to rank %d, change: %f\n", e.SteamID, e.RankOld, e.RankNew, e.RankChange)
61+
})
62+
5963
// Parse to end
6064
err = p.ParseToEnd()
6165
checkError(err)

game_events.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,22 @@ func (p *Parser) handleUserMessage(um *msg.CSVCMsg_UserMessage) {
665665
default:
666666
p.eventDispatcher.Dispatch(events.ParserWarn{Message: fmt.Sprintf("Skipped sending ChatMessageEvent for SayText2 with unknown MsgName %q", st.MsgName)})
667667
}
668+
case msg.ECstrike15UserMessages_CS_UM_ServerRankUpdate:
669+
st := new(msg.CCSUsrMsg_ServerRankUpdate)
670+
err := st.Unmarshal(um.MsgData)
671+
if err != nil {
672+
p.eventDispatcher.Dispatch(events.ParserWarn{Message: fmt.Sprintf("Failed to decode ServerRankUpdate message: %s", err.Error())})
673+
}
668674

675+
for _, v := range st.RankUpdate {
676+
p.eventDispatcher.Dispatch(events.RankUpdate{
677+
SteamID: int64(v.AccountId),
678+
RankOld: int(v.RankOld),
679+
RankNew: int(v.RankNew),
680+
WinCount: int(v.NumWins),
681+
RankChange: v.RankChange,
682+
})
683+
}
669684
default:
670685
// TODO: handle more user messages (if they are interesting)
671686
// Maybe msg.ECstrike15UserMessages_CS_UM_RadioText

0 commit comments

Comments
 (0)