Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing player in TeamState.Members() #492

Closed
CapekM opened this issue Jan 4, 2024 · 6 comments
Closed

Missing player in TeamState.Members() #492

CapekM opened this issue Jan 4, 2024 · 6 comments

Comments

@CapekM
Copy link

CapekM commented Jan 4, 2024

Describe the bug
I was parsing demofiles from HLTV and noticed that parser.GameState().TeamTerrorists().Members() does not return all players, but all players are in the parser.GameState().Participants().All().
When I looked into the func (ptcp participants) TeamMembers(team common.Team) there were only 9 participants, but the parser.GameState().Participants().All() is returning 13 players and all right ones are there.
When I looked into the p.parser.GameState().Participants().Connected/Playing() there are the 9 players. I'm not sure if it's a problem with data or the parser, since I'm not much proficient with this library.
Thanks for any reply.

To Reproduce
For example:

Library version
v4.0.0

@kartol
Copy link

kartol commented Jan 8, 2024

There seems to be an issue with disconnecting and reconnecting.
When "mir" disconnects and later reconnects he is still marked as disconnected

Round finished: winnerSide=T  ; team_len=5:5
Round finished: winnerSide=T  ; team_len=5:5
Round finished: winnerSide=T  ; team_len=5:5
player mir disconnected
player mir connected
Round finished: winnerSide=T  ; team_len=5:4
Round finished: winnerSide=T  ; team_len=5:4

Probably there should be some additional handling for this situation in the playerConnect method
analogically to the disconnecting

if pl != nil {
// Dispatch this event early since we delete the player on the next line
geh.dispatch(events.PlayerDisconnected{
Player: pl,
})
geh.playerByUserID(uid).IsConnected = false
}

inside the playerDisconnect method?

@micvbang
Copy link
Contributor

This is related to #494; I believe the problem is that we should switch to track players using the CCSTeam.m_aPlayers.00xx prop. From here, we can correctly keep track of players moving in and out of teams like so:

The most basic version of this is:

teamPlayers := make([]*common.Player, 64)

for i := 0; i < 64; i++ {
	i := i
	slot := fmt.Sprintf("m_aPlayers.%04d", i)
	entity.Property(slot).OnUpdate(func(pv st.PropertyValue) {
		var player *common.Player
		if pv.Any != nil {
			player = p.gameState.playersByEntityID[entityIDFromHandle(pv.S2UInt64(), true)]
		}
		teamPlayers[i] = player

		fmt.Printf("%v switched to %s\n", player, team)
	})
}

I have something like the above hacky version of this working locally, but I think we might need to consult @markus-wa or @akiver to decide how to do this properly. Right now I can't see a way to do this without a medium-sized overhaul of the team-related code.

@markus-wa
Copy link
Owner

Sorry I'm currently a bit slow at getting back on issues - this definitely seems like an important thing to fix.
I'm not sure about m_aPlayers - what about using m_iTeamNum on the player pawns?

I don't know how quickly I'll be able to get to this so MRs are very welcome.
Happy to go with the m_aPlayers path if that seems to be the most reliable

@micvbang
Copy link
Contributor

micvbang commented Feb 2, 2024

Sorry I'm currently a bit slow at getting back on issues - this definitely seems like an important thing to fix. I'm not sure about m_aPlayers - what about using m_iTeamNum on the player pawns?

I don't know how quickly I'll be able to get to this so MRs are very welcome. Happy to go with the m_aPlayers path if that seems to be the most reliable

This looks relevant: https://github.com/akiver/cs-demo-analyzer/blob/6c642144c19a40277e3690a3d6fc42e313f8752e/pkg/api/ebot.go#L71

akiver added a commit that referenced this issue Feb 2, 2024
@akiver
Copy link
Collaborator

akiver commented Feb 2, 2024

could you try with this branch please? #499

akiver added a commit that referenced this issue Feb 7, 2024
- Players were seen as disconnected and so not returned by some participants functions
- Rely on m_iConnected to detect players connection/disconnection
- Disable player_connect and player_disconnect game events for CS2 demos
- Dispatch events from prop updates

ref #494 #492
akiver added a commit that referenced this issue Feb 7, 2024
- Players were seen as disconnected and so not returned by some participants functions
- Rely on m_iConnected to detect players connection/disconnection
- Disable player_connect and player_disconnect game events for CS2 demos
- Dispatch events from prop updates

ref #494 #492
@markus-wa
Copy link
Owner

I will be closing this for now, feel free to reopen if the issue persists with v4.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants