Skip to content

fix(coop): write the host's save at once when the PvP client plays the aliens - #237

Merged
NonPolynomialTim merged 2 commits into
mainfrom
fix/pvp-gm2-save-after-rejoin
Nov 6, 2026
Merged

NonPolynomialTim merged 2 commits into
mainfrom
fix/pvp-gm2-save-after-rejoin

Conversation

@NonPolynomialTim

@NonPolynomialTim NonPolynomialTim commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

In a PvP campaign where the host plays X-COM and the client plays the aliens (gamemode 2), a host save could hang on "Saving..." (the co-op save-wait dialog) with CANCEL showing, and no file was written. This happened to the quick save, the autosave and OPTIONS > SAVE GAME:

  • after the alien client crashed and rejoined the running campaign
  • after both players reloaded a host save (no crash needed)

A save in a freshly started campaign worked.

Root cause (captured with temporary logging, since removed)

SaveGameState defers a host geoscape save so it can ask the client for its world first, but only while the host's co-op session flag is set. The logging printed each part of that condition at every save:

fresh campaign: save terms: quitAfter=0 coopSession=0 serverOwner=1 ... type=2 shared=0 separate=0   -> written at once
rejoin:         coopSession=1 at COOP_READY_CLIENT
                save terms: quitAfter=0 coopSession=1 serverOwner=1 ... type=2 shared=0 separate=0
                [coop-session] armDeferredSave ('_quick_.asav')
                [coop-dialog] open code=54
alien client:   [coop-save] save request held: own base unnamed

A freshly started campaign never sets the flag, so its saves never ask. A rejoin or a resume runs the COOP_READY handshake, which sets it, so every later save asks the alien client. The alien client never places a base. Before and after the rejoin, geo_state shows its world holding one base named '' at 0,0, with noBases=True gamemode=2. coopOwnBaseUnnamed() is therefore always true, and the client holds its answer until that base is named, which never happens.

The alien client has no world of its own to send. The host's save already embeds a stand-in world for it (SavedGame::save), and, from reading the code, its receive path rejects a world with no real base (CoopState(994)). So making the client answer is not the fix.

Fix

SaveGameState skips the deferral in gamemode 2 and writes at once, as a freshly started campaign already did. Every other mode is unchanged.

Test

tools/coop_test/test_pvp_campaign_save_after_rejoin.py (8 s locally). It runs a gamemode 2 campaign and checks five saves: one in the fresh campaign, a quick save, autosave and menu save after the alien client crashes and rejoins, and a quick save after both players reload the menu save. It also checks that the client comes back on the alien side.

  • On main 8ccc045: fails 3 of 3. fresh passes. rejoin, autosave, menu and reload each fail with host save ... not written after 15 s: host top CoopState dialog code 54 title 'Saving...'; alien client said ['[coop-save] save request held: own base unnamed'].
  • With the fix: 20 of 20 passes (10 each on two harness slots, 7.9 to 8.5 s).
  • These pass once each on the fixed build: test_campaign_resume_gm2, test_campaign_battle_gm2, test_pvp_campaign_resume, test_pvp_campaign_reconnect, test_pvp_campaign_month, test_pvp_rehost_mode, test_client_zero_disk.

A PvP campaign whose client plays the aliens (gamemode 2): the host saves
in the fresh campaign, after the alien client crashes and rejoins (quick
save, autosave, OPTIONS > SAVE GAME), and after both players reload the
host's save. Each save must be written within 15 s.
…e aliens

In a PvP campaign whose client plays the aliens (gamemode 2), every host
save after the alien client rejoined, or after a resumed campaign, stayed
on "Saving..." forever.

The host defers a save to ask the client for its world only while its
co-op session flag is set. A freshly started campaign never sets it, so
those saves wrote at once. A rejoin or a resume runs the COOP_READY
handshake, which sets it, so the next quick save, autosave or menu save
asked the alien client. That client never places a base: its world holds
one unnamed base at 0,0, so it holds its answer until the base is named,
which never happens.

The alien client has no world of its own to send, and the host's save
already embeds a stand-in world for it. Skip the deferral in gamemode 2,
as a fresh campaign already did.
@NonPolynomialTim
NonPolynomialTim enabled auto-merge (squash) November 6, 2026 02:36
@NonPolynomialTim
NonPolynomialTim merged commit 0d10db0 into main Nov 6, 2026
11 checks passed
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