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

fix: set player connected flag to false when controller is destroyed #497

Merged
merged 2 commits into from
Jan 21, 2024

Conversation

akiver
Copy link
Collaborator

@akiver akiver commented Jan 14, 2024

Bot controller entities can be destroyed:

d

96322 player_controller_destroy 12 Baroud 0
107866 player_controller_destroy 14 Bank 0

If we don't update the prop Connected, the bot will still be in the slice returned by Playing().
As a result, calling a player's function that relies on its pawn entity such as EquipmentValueCurrent() may result in a panic as the pawn entity doesn't exists anymore.

Noticed with this demo https://mega.nz/file/uBdF3TBT#aoGpmJ6PKaNIMqPdZsVxHyhiv7DbxO3M9jJNWAOIhb0 and the following code:

p.RegisterEventHandler(func(e events.RoundStart) {
  fmt.Println(p.GameState().TeamCounterTerrorists().CurrentEquipmentValue())
  fmt.Println(p.GameState().TeamTerrorists().CurrentEquipmentValue())
})

ref akiver/cs-demo-manager#727

Bot controller entities can be destroyed:

```
96322 player_controller_destroy 12 Baroud 0
107866 player_controller_destroy 14 Bank 0
```

If we don't update the prop `Connected`, the bot will still be in the slice returned by `Playing()`.
As a result, calling a player's function that relies on its pawn entity such as `EquipmentValueCurrent()` may result in a panic as the pawn doesn't exists anymore.

Noticed with this demo https://mega.nz/file/uBdF3TBT#aoGpmJ6PKaNIMqPdZsVxHyhiv7DbxO3M9jJNWAOIhb0 and the following code:

```go
p.RegisterEventHandler(func(e events.RoundStart) {
  fmt.Println(p.GameState().TeamCounterTerrorists().CurrentEquipmentValue())
  fmt.Println(p.GameState().TeamTerrorists().CurrentEquipmentValue())
})
```

ref akiver/cs-demo-manager#727
@akiver akiver requested a review from markus-wa January 14, 2024 15:15
Copy link

codecov bot commented Jan 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d7f0779) 80.67% compared to head (713ae71) 80.67%.
Report is 1 commits behind head on master.

❗ Current head 713ae71 differs from pull request most recent head 30541c4. Consider uploading reports for the commit 30541c4 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #497   +/-   ##
=======================================
  Coverage   80.67%   80.67%           
=======================================
  Files          47       47           
  Lines        6338     6339    +1     
=======================================
+ Hits         5113     5114    +1     
  Misses       1015     1015           
  Partials      210      210           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@markus-wa markus-wa enabled auto-merge January 21, 2024 15:23
@markus-wa markus-wa merged commit 88ff690 into master Jan 21, 2024
6 checks passed
@markus-wa markus-wa deleted the disconnect-bots branch January 21, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants