Skip to content

fix: g_dm_auto_join / g_dm_force_join never fire for human players#234

Open
KarmicP wants to merge 1 commit into
DarkMatter-Productions:mainfrom
KarmicP:fix/dm-auto-join-humans
Open

fix: g_dm_auto_join / g_dm_force_join never fire for human players#234
KarmicP wants to merge 1 commit into
DarkMatter-Productions:mainfrom
KarmicP:fix/dm-auto-join-humans

Conversation

@KarmicP

@KarmicP KarmicP commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Bug

g_dm_auto_join and g_dm_force_join are dead cvars for human players.

ClientConnect pre-sets every fresh deathmatch client to TEAM_SPECTATOR before first spawn (its InitPlayerTeam(ent) call there is commented out):

https://github.com/DarkMatter-Productions/MuffMode/blob/45e4c9a/src/sgame/client/lifecycle.cpp#L1511-L1516

so by the time InitPlayerTeam runs at first spawn, the "already initialised" early-return (sess.team != TEAM_NONE) fires for every human and the g_dm_force_join / g_dm_auto_join block right below it is unreachable. Bots aren't affected because the bot manager assigns their team directly — which masks the bug in testing.

Fix

Treat an uninitialised spectator as a brand-new client and let them fall through to the auto-join gate. sess.initialised only becomes true at the end of a successful SetTeam (including a deliberate spectator pick), so:

  • fresh client (pre-set spectator, initialised == false) → falls through → auto-join applies as documented
  • deliberate spectator (initialised == true) → early-returns as before, never force-joined
  • g_dm_auto_join 0 / g_dm_force_join 0 (defaults) → behavior unchanged

Recursion via SetTeam → ClientSpawn is safe: sess.team and sess.initialised are both set before the nested spawn, so the inner InitPlayerTeam early-returns.

Testing

  • Release x64 build on top of 45e4c9a: 0 warnings / 0 errors
  • Verified in-game on a 16-slot FFA listen server (Q2 rerelease, Steam): with g_dm_auto_join 1, humans spawn straight into the match on connect and after map changes; with it unset, the join menu appears exactly as before; team spectator still works and spectators are not force-joined

ClientConnect pre-sets fresh deathmatch clients to TEAM_SPECTATOR before first
spawn (its InitPlayerTeam call is commented out upstream), so InitPlayerTeam's
'already initialised' early-return (team != TEAM_NONE) fired for every human
before the g_dm_force_join / g_dm_auto_join block could run - the cvars were
dead for humans (upstream bug; bots join via the bot manager instead).

An uninitialised spectator (sess.initialised only becomes true at the end of a
successful SetTeam, including deliberate spectator picks) is really a brand-new
client awaiting first join, so let them fall through to the auto-join gate.
Recursion via SetTeam -> ClientSpawn is safe: team + initialised are set before
the nested spawn, so the inner InitPlayerTeam early-returns.

With g_dm_auto_join 0 (default) behavior is unchanged. Motivation: hard map
rotation (g_hard_map_rotation) wipes sessions each rotation, dumping players
at the join menu every map change; g_dm_auto_join 1 now actually rejoins them.
@KarmicP KarmicP force-pushed the fix/dm-auto-join-humans branch from 10f1820 to 494c155 Compare July 3, 2026 05:04
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.

1 participant