Skip to content

Commit 935fd38

Browse files
authored
Merge pull request #489 from markus-wa/fix-connected
fix: Participants().Playing() may returned disconnected players
2 parents 7b0c35e + 121ebdb commit 935fd38

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

pkg/demoinfocs/common/player.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ type Player struct {
3737
}
3838

3939
func (p *Player) PlayerPawnEntity() st.Entity {
40+
pawn, exists := p.Entity.PropertyValue("m_hPawn")
41+
if !exists {
42+
return nil
43+
}
44+
45+
if pawn.Handle() == constants.InvalidEntityHandleSource2 {
46+
return nil
47+
}
48+
4049
playerPawn, exists := p.Entity.PropertyValue("m_hPlayerPawn")
4150
if !exists {
4251
return nil

pkg/demoinfocs/common/player_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ func TestPlayer_Velocity(t *testing.T) {
454454
func createPlayerForVelocityTest() *Player {
455455
controllerEntity := entityWithProperties([]fakeProp{
456456
{propName: "m_hPlayerPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
457+
{propName: "m_hPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
457458
})
458459
pawnEntity := new(stfake.Entity)
459460
position := r3.Vector{X: 20, Y: 300, Z: 100}

pkg/demoinfocs/datatables.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,12 @@ func (p *parser) getOrCreatePlayerFromControllerEntity(controllerEntity st.Entit
514514
func (p *parser) bindNewPlayerControllerS2(controllerEntity st.Entity) {
515515
pl := p.getOrCreatePlayerFromControllerEntity(controllerEntity)
516516

517+
controllerEntity.Property("m_hPawn").OnUpdate(func(val st.PropertyValue) {
518+
if val.Handle() == constants.InvalidEntityHandleSource2 {
519+
pl.IsConnected = false
520+
}
521+
})
522+
517523
controllerEntity.Property("m_iTeamNum").OnUpdate(func(val st.PropertyValue) {
518524
pl.Team = common.Team(val.S2UInt64())
519525
pl.TeamState = p.gameState.Team(pl.Team)

0 commit comments

Comments
 (0)