Fix for random occurrence of player state none #1146
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This should finally fix the issue #1008 with pretty critical behavior difference, when omp server as a workaround sets the player state to
PLAYER_STATE_NONEwhen he leaves the spectating. As the comment says the reasons:open.mp/Server/Source/player_impl.hpp
Lines 635 to 638 in 59fd6e5
it is supposed to update the player state to pass further checks inside RequestClass or RequestSpawn events, one of which will be called by player when he exits spectating.
But what we see in those places are only such checks:
open.mp/Server/Components/Classes/classes_main.cpp
Lines 156 to 160 in 59fd6e5
^ in PlayerRequestClassHandler, and:
open.mp/Server/Source/player_pool.hpp
Lines 64 to 68 in 59fd6e5
^ in PlayerRequestSpawnRPCHandler
So, if player still has PLAYER_STATE_SPECTATING, it will pass both of those checks, since spectating state is not in the range of forbidden states which are blocked to call all the mentioned events.
Meanwhile having manually update player states to random ones leads to behavior differences, and in this case it's pretty critical one since it break many protections against state change spoofing and thus falsely triggers on fair players (#325 as example). Not to say that such actions are also undocumented and doesn't match SA-MP behavior for any other scripts which aren't designed to consider similar server behavior surprises.