Skip to content

Commit

Permalink
Merge pull request #489 from markus-wa/fix-connected
Browse files Browse the repository at this point in the history
fix: Participants().Playing() may returned disconnected players
  • Loading branch information
markus-wa authored Jan 8, 2024
2 parents 7b0c35e + 121ebdb commit 935fd38
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/demoinfocs/common/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ type Player struct {
}

func (p *Player) PlayerPawnEntity() st.Entity {
pawn, exists := p.Entity.PropertyValue("m_hPawn")
if !exists {
return nil
}

if pawn.Handle() == constants.InvalidEntityHandleSource2 {
return nil
}

playerPawn, exists := p.Entity.PropertyValue("m_hPlayerPawn")
if !exists {
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/demoinfocs/common/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ func TestPlayer_Velocity(t *testing.T) {
func createPlayerForVelocityTest() *Player {
controllerEntity := entityWithProperties([]fakeProp{
{propName: "m_hPlayerPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
{propName: "m_hPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
})
pawnEntity := new(stfake.Entity)
position := r3.Vector{X: 20, Y: 300, Z: 100}
Expand Down
6 changes: 6 additions & 0 deletions pkg/demoinfocs/datatables.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,12 @@ func (p *parser) getOrCreatePlayerFromControllerEntity(controllerEntity st.Entit
func (p *parser) bindNewPlayerControllerS2(controllerEntity st.Entity) {
pl := p.getOrCreatePlayerFromControllerEntity(controllerEntity)

controllerEntity.Property("m_hPawn").OnUpdate(func(val st.PropertyValue) {
if val.Handle() == constants.InvalidEntityHandleSource2 {
pl.IsConnected = false
}
})

controllerEntity.Property("m_iTeamNum").OnUpdate(func(val st.PropertyValue) {
pl.Team = common.Team(val.S2UInt64())
pl.TeamState = p.gameState.Team(pl.Team)
Expand Down

0 comments on commit 935fd38

Please sign in to comment.