// One network of a server session, run by the game's own code in a vm realm (the server-sim design, section 4.1). // The realm is a vm context made with DONT_CONTEXTIFY, so it has its own intrinsics (a prototype polluted in one realm // stays there) and runs at full speed. Into it go, in order: the prelude below (DOM stand-ins that record what the // game writes and reads back, no-op timers that count, the network's language), the network's dictionary // (site/i18n/.js, not English), the game script, and the epilogue (the srv… functions: what the server asks of a // network, and the rebinds that turn toasts, sounds, windows and the like into effects, "fx", for the page). // // The worker (mp-sim-worker.js) calls into a realm only through call()/raw(): the input goes in as one JSON string // (globalThis.__in), the answer comes back as one string, and no object crosses between host and realm. An answer is // a JSON header, optionally followed by more parts, each on its own line (JSON text never holds a raw newline): // srvPull answers `{"v":3,"parts":["upd","snap"]}\n\n`, ready to write to a stream. // A call that throws inside the realm answers {"srvErr": stack}; a call that runs over its time limit throws // ERR_SCRIPT_EXECUTION_TIMEOUT here, and the realm must not be used for play again (a timeout skips finally blocks). // // gameSource({root, page}) the game script (the largest inline