Fog of war (2026-10-16)
=======================

Why
---
Radar hacks, ESP and wallhacks read enemy positions the server sends in every
snapshot. Clearing the UAV state changes nothing for a modified client: it
already has the positions. The only fix is not sending them. scripts/mp/
ac_fog.gsc decides each server frame which alive enemies each alive player
could see and withholds the rest from that player's snapshots.

How the engine does it
----------------------
IW4 has no hideFromPlayer. Its script methods are:
  hide()              s.eFlags |= EF_NODRAW; s.clientMask[0] = 0xffffffff
  showToPlayer(p)     s.eFlags &= ~EF_NODRAW; clears p's bit in s.clientMask
  show()              visible to all again
(game binary: GScr_Hide 0x5f6da0, GScr_ShowToPlayer 0x5f6e20). The snapshot
writer (loop at 0x6294e1, mask tests at 0x6295fc and 0x629665) skips any
entity whose clientMask bit for the receiving client is set, before it writes
the entity. Masked entities therefore never reach that client: a server
withhold, not a client draw flag. MW2's own killstreak scripts hide players
the same way. The mask has 32 bits; MAX_CLIENTS is 18.

The script keeps, per player, whether hide() is in effect and which viewers
have been re-admitted. A viewer is allowed to receive an enemy when:
  * the viewer is a spectator, in the intermission, or a teammate (dead
    players waiting to respawn get nothing: no map knowledge every death)
  * the enemy fired in the last ac_fog_fire ms (1200): what a radar is
    supposed to show, and the shot is heard
  * a sight trace passes from the viewer's eye, or from the eye a tenth of a
    second ahead along their velocity, to the enemy's head, chest or feet
    (world geometry only, other players never block)
  * the enemy was seen within ac_fog_grace ms (100, two snapshots): clients
    draw everyone about 100 ms in the past anyway, so this leaks nothing and
    only stops blinking through railing gaps
ac_fog_near (0) would always send enemies within a distance; radar never
showed footsteps in any CoD, so it stays off. The sight test uses head, both
shoulders, chest and feet, from the eye and the predicted eye.
Removing one viewer means hide() again and re-admitting the others; steady
states cost no engine calls. Engine calls run in a child thread and a watchdog
restarts the decision loop if it stops, so a script error cannot leave a map
half-fogged. ac_fog 0 reveals everyone within a frame.

What a radar hack can still see
-------------------------------
Exactly what the honest player could know: enemies in view (plus the 100 ms
every client already lags behind), and anyone who fired in the last 1.2
seconds. Everything else is dark, including for dead players waiting to
respawn. Footsteps of an enemy behind a nearby wall are not heard; radar
never revealed those either.

Known effects
-------------
* An enemy stepping out from cover appears to the viewer when the server first
  has a line from the viewer's eye (or predicted eye) to any of three points on
  them, so up to one snapshot later than an honest full-data client would have
  had them. The grace window and the ahead-eye keep that small.
* EF_NODRAW is set while a player is masked from everyone who is fighting. A
  victim killed through a wall by FMJ while hidden from the killer is drawn in
  the killer's killcam only from the moment they were revealed.
* Kill feed, scores, chat and voice are unaffected (not entity data).
* Server demos record what each client was sent, so a demo shows what that
  player could legitimately know.

Rollout
-------
server.cfg sets ac_fog 0. zeal02-2 (Unranked) sets ac_fog 1 in instance.cfg
and runs it first; Ranked follows after a few days without pop-in complaints.
Settings: ac_fog, ac_fog_near, ac_fog_grace, ac_fog_fire, ac_fog_debug (console
hide/show lines and a per-player summary every 2 s), ac_fog_radar_test (QA
only: UAV for everyone).

Local QA (2026-10-16): compiles on the IW4x dedicated server; with five test
clients fighting on mp_rust the loop produced hide/show transitions as
expected; a real client's compass stayed empty while the server listed every
bot as hidden from it, and showed a target while spectating. Byte-rate
comparisons were uninformative because idle test clients produce almost no
entity traffic, which is why the engine path was verified in the binary.
