Skip to content

refactor: clarify team-selection logic in OnJoinTeamCommand - #39

Open
Rushaway wants to merge 1 commit into
masterfrom
refactor/jointeam-team-selection
Open

Rushaway wants to merge 1 commit into
masterfrom
refactor/jointeam-team-selection

Conversation

@Rushaway

@Rushaway Rushaway commented Sep 9, 2026

Copy link
Copy Markdown
Member

Audit finding — OnJoinTeamCommand() readability / dead code

1. Operator-precedence footgun

if(!g_bZombieSpawned && NewTeam == CS_TEAM_T || NewTeam == CS_TEAM_NONE)

&& binds tighter than ||, so this already meant
(!g_bZombieSpawned && NewTeam == CS_TEAM_T) || NewTeam == CS_TEAM_NONE.
Added the explicit parentheses + a comment. No behaviour change — this
just makes the intent obvious and silences the compiler warning.

2. Always-true condition

if(!g_cvAliveTeamChange.BoolValue && IsPlayerAlive(client) && NewTeam >= 0 && (...))

NewTeam is validated to be within [CS_TEAM_NONE, CS_TEAM_CT] (i.e.
>= 0) earlier in the function, so NewTeam >= 0 is dead. Removed.

Noted, not changed here

The strcmp(command, "joingame") branch (lines ~274-281) is unreachable:
only "jointeam" is registered with AddCommandListener. Activating it
(registering "joingame" so the forced team-selection panel works) is a
behaviour change that deserves its own tested PR.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 9, 2026 16:01

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.

🟡 Changes recommended

One newly added comment misstates the behavior of the alive-team-change guard and should be corrected to avoid misleading future maintenance.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Refactors OnJoinTeamCommand() in TeamManager.sp to make team-selection intent clearer (explicit operator precedence in a ZR-specific condition) and remove a dead/always-true sub-condition, aligning with the stated readability audit findings.

Changes:

  • Added explicit parentheses (and explanatory comment) to avoid operator-precedence ambiguity in the ZombieReloaded team-selection branch.
  • Removed the redundant NewTeam >= 0 check after NewTeam is already range-validated earlier in the function.
  • Updated nearby comments to describe the logic (one comment needs a small wording correction to match behavior).
File summaries
File Description
addons/sourcemod/scripting/TeamManager.sp Clarifies ZR team-selection condition precedence and removes a dead team-range check in OnJoinTeamCommand().
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +326 to +327
// Prevent alive players from switching between CT and T when disallowed.
// NewTeam is already validated to be within [CS_TEAM_NONE, CS_TEAM_CT] above.
- Add explicit parentheses to the ZombieReloaded team remap. `&&` binds
  tighter than `||`, so the condition already meant
  `(!g_bZombieSpawned && NewTeam == CS_TEAM_T) || NewTeam == CS_TEAM_NONE`;
  this only makes the intent readable and silences the compiler warning.
- Drop the always-true `NewTeam >= 0` check from the alive-team-change
  guard. NewTeam is validated to be within [CS_TEAM_NONE, CS_TEAM_CT]
  earlier in the function.

Note for reviewers: the `strcmp(command, "joingame")` branch is currently
dead code because only "jointeam" is registered with AddCommandListener.
Left as-is here; activating it (registering "joingame") should be a
separate, tested change.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Rushaway
Rushaway force-pushed the refactor/jointeam-team-selection branch from 0db270f to 66743a5 Compare September 11, 2026 20:47
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