[ALL] Player thinks break if executed before any player command is run #1179
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.
Description
If the server attempts to run frame-based think functions on a player before they have received a command, the think functions will break.
Why
Working backwards here:
gpGlobals->curtime
is 0 which results in the next execution never occurring. Ex. think function in tf_player.cppgpGlobals->curtime
is 0 here because player_command.cpp: CPlayerMove::RunCommand setsgpGlobals->curtime
based on the player'sm_nTicks
value, which was 0.m_nTicks
is set to 0 because it itself is only set in a few places. It normally appears to be set after a player joins the server by player.cpp: RunNullCommand. (SetTimeBase
setsm_nTicks
).RunNullCommand
is run based on the cvarsv_player_usercommand_timeout
which has a default value of 3. In some mods or if this value is set to be higher than 3,RunNullCommand
may not be run before the server attempts to run the player's think functions, ultimately causing them to stop.Replication
Note, this does not appear to be easily replicable in live TF2, but can be reproduced reliably in Frog Fortress 2 by increasing the
sv_player_usercommand_timeout
cvar and in Open Fortress without needing to do so (where the issue was discovered after updating to the latest SDK).Replication Steps
listenserver.cfg
:kill
in console.TFPlayerThink
no longer being run.Video examples
Normal (
sv_player_usercommand_timeout
= 3)https://youtu.be/POhGMmfN128
Replicated (
sv_player_usercommand_timeout
= 10)https://youtu.be/LBzJElDipgQ
The Fix
There are probably several different ways to fix this, but the simplest fix I came up with was to simply set
m_nTicks
withSetTimeBase
when the player is created.If there would be any other preferred method of doing so I'm happy to adapt.