Server-run play, part 1: game prerequisites and shared contracts
Groundwork for running multiplayer games on the session server; nothing
of it is switched on yet, and the plain build is unchanged.
- A new network in two halves (beginState/beginShow), the coach split into
tutAdvance/coachDom, toastPop split out of toast, bootNotes() for the
once-per-load toasts, the five text actions take their text as an
argument, and srvOn() with its two checks in the loop.
- Live state is what a reload makes of it (migrate() is a no-op on it):
new POPs, ports, PNIs, customers, attacks, dark fiber and the intern's
notes are written in their saved shape; a 365-day test proves it.
- pniAll and bstdApply check the quote the sheet showed (bstdApply by its
plan, within 1% for the daily hardware drift; utilityKit too).
- assemble({mp}) leaves src/game/98-server-play/ and its CSS out of every
page but a multiplayer build's, which also gets a SIM_ID build id.
- Contracts for the server, protocol and browser parts: the action tables
and envelope check (scripts/lib/mp-sim-acts.js), event fixtures, a shape
checker, a fake engine, and load({mp:true}) in the test harness.
- route-fuzz judges both pages with one migrate(), so reload repairs of
the base no longer count as divergences.
This commit is contained in:
parent
e25f843526
commit
d1e127da67
60 changed files with 2200 additions and 105 deletions
|
|
@ -100,7 +100,8 @@
|
|||
if (k === 'fail') { S.nextFail = S.day + 1; return ''; }
|
||||
if (k === 'event') { S.nextEvent = S.day + 1; return ''; }
|
||||
if (k === 'cash') { S.cash += a; after(); return ''; }
|
||||
if (k === 'lvl') { S.lvl = Math.min(LEVELS.length, (S.lvl || 0) + 1); after(); return ''; }
|
||||
// One level up from the level the game reads (lvl(): S.lvl, or 1 when a page never wrote it down).
|
||||
if (k === 'lvl') { S.lvl = Math.min(LEVELS.length, (S.lvl || 1) + 1); after(); return ''; }
|
||||
// Events that move routes, as the game's own events set them.
|
||||
if (k === 'ev') {
|
||||
const n = NETS[a % NETS.length].id;
|
||||
|
|
@ -148,28 +149,49 @@
|
|||
|
||||
// ---------- digests ----------
|
||||
// Everything routing produced: R in full (with every link's R.ef), the flows (R.fl), and what the PNI lists read.
|
||||
// An attack's record names its attack by id (as rwPack does): the attack itself is game state, compared with S.
|
||||
const rj = (v) => JSON.stringify(v, (k, x) => (k === 'attack' && x && typeof x === 'object' ? x.id : x));
|
||||
const routing = () => {
|
||||
if (!R) return 'noR';
|
||||
const r = JSON.stringify(R), fl = R.fl ? JSON.stringify(R.fl) : '';
|
||||
const r = rj(R), fl = R.fl ? JSON.stringify(R.fl) : '';
|
||||
let pf = '';
|
||||
if (typeof pniFlows === 'function' && S && !pzOn()) for (const c of Object.keys(S.pops).slice(0, 4)) try { pf += c + JSON.stringify(pniFlows(c)); } catch (e) { pf += c + 'E' + e.message; }
|
||||
return r + '\n' + fl + '\n' + pf;
|
||||
};
|
||||
const parts = () => { const o = {}; if (!R) return o; for (const k of Object.keys(R)) o[k] = JSON.stringify(R[k]); o.fl = R.fl ? JSON.stringify(R.fl) : ''; return o; };
|
||||
const parts = () => { const o = {}; if (!R) return o; for (const k of Object.keys(R)) o[k] = rj(R[k]); o.fl = R.fl ? JSON.stringify(R.fl) : ''; return o; };
|
||||
// A field only this checkout's game has (a new feature's state, on S or on its customers and offers) cannot match main
|
||||
// yet: the driver passes those (drop) and they are left out; every field both games have must still match.
|
||||
// The intern's state two levels deep (ops.on.sales, ops.wk.rev): a standing order one game has and the other retired.
|
||||
const opsPaths = () => { const O = S.ops, out = []; if (!O || typeof O !== 'object') return out;
|
||||
// Compared as a reload makes it (migrate(), keys in order): the same game, whichever way each version writes the
|
||||
// fields it fills in anyway (main may create a record without the defaults a reload gives it, in another order).
|
||||
// One reload judges both: the driver passes the base page's live state (sLive) through this checkout's migrate()
|
||||
// (sDigest(drop, json)), so a repair only one version's reload makes (main's re-aimed an attack whose customer left
|
||||
// during the day) is no divergence. That reload runs with this page's own S in scope (sanitize reads S.rules through
|
||||
// rule()): pages in lockstep have the same, and a difference in the rules shows up in the fields they decide. A POP without a router model plays the basic one (RG[p.rgen||0]): that is written
|
||||
// down first, so the reload does not guess one from its ports (a free upgrade a page from before canonical state got).
|
||||
// Puzzles are never saved: as they are. The rules stay as they are too: both pages may have set them alike (noIp4),
|
||||
// and a base that does not know a rule would drop it on the way.
|
||||
const sortK = (v) => (Array.isArray(v) ? v.map(sortK) : v && typeof v === 'object' ? Object.keys(v).sort().reduce((o, k) => ((o[k] = sortK(v[k])), o), {}) : v);
|
||||
const sLive = () => JSON.stringify(S === undefined ? null : S);
|
||||
const sOf = (json) => { const live = JSON.parse(json); if (!live || !S || pzOn() || live.mode === 'puzzle') return live; const u0 = uidN, r0 = S.rng;
|
||||
try {
|
||||
for (const c of Object.keys(live.pops || {})) if (live.pops[c] && live.pops[c].rgen === undefined) live.pops[c].rgen = 0;
|
||||
const rules = live.rules === undefined ? undefined : JSON.parse(JSON.stringify(live.rules));
|
||||
const s = migrate(live); s.rules = rules; return sortK(s);
|
||||
} finally { uidN = u0; S.rng = r0; } };
|
||||
const sNow = () => sOf(sLive());
|
||||
const opsPaths = (s = sNow()) => { const O = s.ops, out = []; if (!O || typeof O !== 'object') return out;
|
||||
for (const k of Object.keys(O)) { out.push(k); const v = O[k]; if (v && typeof v === 'object' && !Array.isArray(v)) for (const j of Object.keys(v)) out.push(k + '.' + j); } return out; };
|
||||
const sKeys = () => ({ top: Object.keys(S), items: [...new Set([...(S.biz || []), ...(S.offers || [])].flatMap((x) => Object.keys(x)))], ops: opsPaths(), orders: typeof OPSK === 'object' ? Object.keys(OPSK) : [] });
|
||||
const opsDrop = (ops) => { const o = {}; for (const k of Object.keys(S.ops)) { if (ops.includes(k)) continue; const v = S.ops[k];
|
||||
const sKeys = () => { const s = sNow(); return { top: Object.keys(s), items: [...new Set([...(s.biz || []), ...(s.offers || [])].flatMap((x) => Object.keys(x)))], ops: opsPaths(s), orders: typeof OPSK === 'object' ? Object.keys(OPSK) : [] }; };
|
||||
const opsDrop = (s, ops) => { const o = {}; for (const k of Object.keys(s.ops)) { if (ops.includes(k)) continue; const v = s.ops[k];
|
||||
if (v && typeof v === 'object' && !Array.isArray(v)) { const w = {}; for (const j of Object.keys(v)) if (!ops.includes(k + '.' + j)) w[j] = v[j]; o[k] = w; } else o[k] = v; } return o; };
|
||||
const sDrop = (drop) => { if (!drop || (!drop.top.length && !drop.items.length && !(drop.ops || []).length)) return S; const o = {};
|
||||
for (const k of Object.keys(S)) if (!drop.top.includes(k)) o[k] = k === 'ops' && S.ops && (drop.ops || []).length ? opsDrop(drop.ops) : S[k];
|
||||
// json: a live state to judge (the other page's, from sLive); without it, this page's own.
|
||||
const sDrop = (drop, json) => { const s = json === undefined ? sNow() : sOf(json); if (!s || typeof s !== 'object' || !drop || (!drop.top.length && !drop.items.length && !(drop.ops || []).length)) return s; const o = {};
|
||||
for (const k of Object.keys(s)) if (!drop.top.includes(k)) o[k] = k === 'ops' && s.ops && (drop.ops || []).length ? opsDrop(s, drop.ops) : s[k];
|
||||
for (const k of ['biz', 'offers']) if (Array.isArray(o[k])) o[k] = o[k].map((x) => { const y = {}; for (const f of Object.keys(x)) if (!drop.items.includes(f)) y[f] = x[f]; return y; });
|
||||
return o; };
|
||||
const sDigest = (drop) => JSON.stringify(sDrop(drop));
|
||||
const sParts = (drop) => { const s = sDrop(drop), o = {}; for (const k of Object.keys(s)) o[k] = JSON.stringify(s[k]); return o; };
|
||||
const sDigest = (drop, json) => JSON.stringify(sDrop(drop, json));
|
||||
const sParts = (drop, json) => { const s = sDrop(drop, json), o = {}; if (s && typeof s === 'object') for (const k of Object.keys(s)) o[k] = JSON.stringify(s[k]); return o; };
|
||||
/* After a move: what the move routed (a), routing again from the same state (b: on this checkout's page the kept
|
||||
tables are used), and routing from that state with the cache off (c: RC.on=false where there is an RC). b and c
|
||||
route from the same previous R; c's R is kept, as a plain compute would. */
|
||||
|
|
@ -188,5 +210,5 @@
|
|||
// Scarce IPv4 off (#150, rule ip4), the same rules object with its keys in the same order on both pages: the driver calls
|
||||
// it only while the base has no such rule, so the pages play the same game until it lands.
|
||||
const noIp4 = () => { if (S && S.rules) { const { ip4, mods, ...r } = S.rules; S.rules = { ...r, ip4: false, mods }; } };
|
||||
window.__fz = { acts, direct, lists, start, state, screen, press, close, poke, day, routing, parts, sKeys, sDigest, sParts, check, errs, modalOpen, noIp4 };
|
||||
window.__fz = { acts, direct, lists, start, state, screen, press, close, poke, day, routing, parts, sKeys, sLive, sDigest, sParts, check, errs, modalOpen, noIp4 };
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue