[Targeting] Fix bug when using /tar on invalid target #3407
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.
Using /tar on an invalid target should not negate a current target. (Tested on live)
My previous attempt to fix this was invalid, as Handle_OP_Target was getting called for multiple packets, so my fix could not reside there alone.
In my digging I found that hitting escape (to remove target), mobs dying, clicking with the mouse, all issued direct OP_TargetMouse commands which should bahave as we have always done them. However, our code also called the same code for OP_Target, which actually only seems to be meant to server as a validation of a /tar command. If we accept the target, the client immediately sends the corresponding OP_TargetMouse. If we reject it, the client sends nothing further.
This fix seems to solve the original issue while not breaking the rest, which is much better than the last shitty PR I submitted.
The diff is hard to read because of indentation changes caused by code removal. Handle_TargetMouse is exactly whaty Handle_Target used to be, except it mo longer handes accept/reject. HandleTarget has been refactored for clarity, and only handles accept/reject.