Skip to content

fix: fake client targeting and harden client state resets#34

Open
Rushaway wants to merge 1 commit into
masterfrom
Rushaway-patch-1
Open

fix: fake client targeting and harden client state resets#34
Rushaway wants to merge 1 commit into
masterfrom
Rushaway-patch-1

Conversation

@Rushaway

Copy link
Copy Markdown
Member

Description

This PR fixes a runtime exception in ThirdPerson when a fake client is processed during spawn/death flow and eventually reaches camera/convar code paths.

Context

A server error was reported:

  • Client X is fake and cannot be targeted
  • Exception on SendConVarValue from MirrorOff
  • Call path triggered from player_spawn -> ResetClient -> MirrorOff
L 03/27/2026 - 07:11:49: [SM] Exception reported: Client 6 is fake and cannot be targeted
L 03/27/2026 - 07:11:49: [SM] Blaming: custom/ThirdPerson.smx
L 03/27/2026 - 07:11:49: [SM] Call stack trace:
L 03/27/2026 - 07:11:49: [SM]   [0] SendConVarValue
L 03/27/2026 - 07:11:49: [SM]   [1] Line 304, ThirdPerson/addons/sourcemod/scripting/ThirdPerson.sp::MirrorOff
L 03/27/2026 - 07:11:49: [SM]   [2] Line 250, ThirdPerson/addons/sourcemod/scripting/ThirdPerson.sp::ResetClient
L 03/27/2026 - 07:11:49: [SM]   [3] Line 202, ThirdPerson/addons/sourcemod/scripting/ThirdPerson.sp::Event_PlayerSpawn
L 03/27/2026 - 07:11:49: [SM]   [5] CreateFakeClient
L 03/27/2026 - 07:11:49: [SM]   [6] Line 115, FakeClients/addons/sourcemod/scripting/FakeClients.sp::Timer_CreateFakeClient

Root cause

Two logic issues made fake clients reachable in reset paths:

  1. Spawn validation was too permissive for bots in the current helper semantics.
  2. Death condition precedence allowed state-reset logic to run in edge cases where the client validity guard was not applied as intended.

What changed

  • Tightened the death condition with explicit parentheses so client validity always gates mirror/thirdperson checks.
  • Updated spawn validation to exclude fake clients before calling reset logic.
  • Added disconnect cleanup to always clear thirdperson/mirror flags when a slot is released.

Behavior impact

  • Fake clients are no longer sent client-targeted convar updates.
  • Human players keep the same expected behavior.
  • State is cleaner across disconnect/reconnect cycles.

Test plan

  1. Load ThirdPerson and FakeClients plugins.
  2. Spawn fake clients repeatedly.
  3. Trigger player_spawn and player_death events for fake and real clients.
  4. Verify no SourceMod exception about fake client targeting appears.
  5. Confirm real clients can still toggle mirror/thirdperson normally.

Risk

Low. Changes are scoped to validation/guard logic and state reset paths.

Copilot AI review requested due to automatic review settings June 29, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens ThirdPerson’s client validation and state-reset paths to prevent runtime exceptions when fake clients hit spawn/death flows that ultimately call client-targeted ConVar updates.

Changes:

  • Bumped plugin version to 1.3.6.
  • Fixed operator-precedence in Event_PlayerDeath so client validity properly gates mirror/thirdperson reset logic.
  • Tightened spawn validation and added disconnect cleanup to clear per-client thirdperson/mirror state when slots are released.

Comment on lines 176 to +177
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client, true, false) && g_bThirdPerson[client] || g_bMirror[client])
if (IsValidClient(client, true, false) && (g_bThirdPerson[client] || g_bMirror[client]))
Comment on lines 206 to 208
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client))
if (IsValidClient(client, true))
{
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