Skip to content

Commit 8959323

Browse files
committed
common.Player: rename field SteamID to SteamID64
also added Player.SteamID32() utility func
1 parent 4f818b0 commit 8959323

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

pkg/demoinfocs/common/player.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
type Player struct {
2222
demoInfoProvider demoInfoProvider // provider for demo info such as tick-rate or current tick
2323

24-
SteamID uint64 // int64 representation of the User's Steam ID
24+
SteamID64 uint64 // 64-bit representation of the user's Steam ID
2525
LastAlivePosition r3.Vector // The location where the player was last alive. Should be equal to Position if the player is still alive.
2626
UserID int // Mostly used in game-events to address this player
2727
Name string // Steam / in-game user name
@@ -51,6 +51,12 @@ func (p *Player) String() string {
5151
return p.Name
5252
}
5353

54+
// SteamID32 converts SteamID64 to the 32-bit SteamID variant and returns the result.
55+
// See https://developer.valvesoftware.com/wiki/SteamID
56+
func (p *Player) SteamID32() uint32 {
57+
return ConvertSteamID64To32(p.SteamID64)
58+
}
59+
5460
// IsAlive returns true if the Hp of the player are > 0.
5561
func (p *Player) IsAlive() bool {
5662
return p.Health() > 0

pkg/demoinfocs/common/player_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ func TestPlayer_ControlledBot(t *testing.T) {
250250
assert.Same(t, dave, pl.ControlledBot())
251251
}
252252

253+
func TestPlayer_SteamID32(t *testing.T) {
254+
pl := &Player{SteamID64: 76561198012952267}
255+
256+
assert.Equal(t, uint32(52686539), pl.SteamID32())
257+
}
258+
253259
func newPlayer(tick int) *Player {
254260
return NewPlayer(mockDemoInfoProvider(128, tick))
255261
}

pkg/demoinfocs/datatables.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (p *parser) getOrCreatePlayer(entityID int, rp *playerInfo) (isNew bool, pl
191191

192192
player = common.NewPlayer(p.demoInfoProvider)
193193
player.Name = rp.name
194-
player.SteamID = rp.xuid
194+
player.SteamID64 = rp.xuid
195195
player.IsBot = rp.isFakePlayer || rp.guid == "BOT"
196196
player.UserID = rp.userID
197197
}
@@ -284,7 +284,7 @@ func (p *parser) bindNewPlayer(playerEntity st.Entity) {
284284
playerEntity.Property("m_bSpottedByMask.001").OnUpdate(spottersChanged)
285285
}
286286

287-
if isNew && pl.SteamID != 0 {
287+
if isNew && pl.SteamID64 != 0 {
288288
p.eventDispatcher.Dispatch(events.PlayerConnect{Player: pl})
289289
}
290290
}

0 commit comments

Comments
 (0)