One calendar for a server session (the user's answer to Q1): a network that joins begins on the session's date, and one that joins after day 180, when the shared market starts to move, gets a head start (answered 2026-11-11). Dormant until the host (T3) passes a start day: in the plain build and in single-device play S.day0 is 0 and the game is as before. - S.day0, the calendar day a network began: 0 in newGame(), repaired in sanitize() (at most S.day), so old saves load. netAge() is the network's age; the first-days rules count it: the charter window (and specSanitize), the tutorial's five days, the DDoS grace and early size cap, route leaks, RPKI, the world's bad news, shortages and control-plane events, sold-out routes, the scrubbing customers, loan offers, the broker's first calls, the Speedrun and Blitz badges and the day counts in the win, lose and Glass Baron windows. The market, the calendar and world events stay on the session's date. - beginState() takes o.day for a session network in Normal mode (lateStart()): the day, the first outage and event, the home POP and the first IPv4 block are stamped with it, so the block cannot be sold on day one at the session's price. - The head start (60-features/81-late-joiners.js): starting cash topped up by the rise in hardware prices (START_CASH x (hwTrend - 1), to $1,000, at most $60k, with the market rule only) and the first 365 days of home broadband matched (R.rev.late: what homes pay after the Australian wholesale cut or levy; outside investors' share, inside revMo). A second welcome with a button to the bank, a Goals card, a bank section, a line in a city's broadband pitch and a toast when the year is over; every label in all six dictionaries. - The "since you started" lines (supply chain, bandwidth market, wave prices) measure from the network's own start. - Server-run engine: srvBegin takes begin.day (an integer from 0, else the begin fails), the fake engine begins there and keeps day0 in its saves, CLOCK.off leaves the shape checker and the contract test, and the fixtures' network begins on day 473 (written again with tests/lib/mp-sim-fixtures.js; a second run changes nothing). - Gameplay rule F11, the agent's day0 doc and status age, ARCHITECTURE and the plans (Q1's game side built, open question 1 answered). - tests/late-joiners.test.js; F11 in tests/gameplay-rules.test.js; a late begin in tests/mp-sim-engine.test.js; one calendar in tests/mp-sim-contract.test.js. Merged onto Starblink and Island Wi-Fi: revMo counts both the islands (V.wisp) and the match (V.late), the revenue share base keeps V.wisp and leaves V.late out; F11 sits before F12 in the gameplay rules and their test; the mp-sim fixtures were written again with tests/lib/mp-sim-fixtures.js (a second run changes nothing).
89 lines
6.5 KiB
JavaScript
89 lines
6.5 KiB
JavaScript
// The canned stream of a server-run network (tests/fixtures/mp-sim/*.json): what the session server sends a page, made
|
|
// here from a real seeded game the way the server's realm will make it (section 5 of the server-sim design): live S,
|
|
// a top-level key diff per update, slim R, the effects a day and two actions leave. The client tests (and the fake
|
|
// engine) use these until the integration step records real streams in their place; every one passes
|
|
// tests/lib/mp-sim-shape.js. Run `node tests/lib/mp-sim-fixtures.js` to write them again.
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { load } = require('../harness');
|
|
|
|
const DIR = path.join(__dirname, '..', 'fixtures', 'mp-sim');
|
|
const CODE = 'K7Q2XD', PID = 'abcd1234', PID2 = 'efgh5678', EPOCH = 'k3f9', DEV = '9f8e7d6c', NOW = 1731000000000;
|
|
const MP = { code: CODE, pid: PID, asn: 201234, seed: 424242, preset: 'oncall', color: '#3a86ff', title: 'Friday' };
|
|
|
|
// In the page: the effects the realm would capture (its epilogue rebinds these the same way), and slim R (5.5).
|
|
const RIG = `window.__fx=[];
|
|
toast=(h,k='',a=[],o=null)=>{if(S)logNote(h,k,a,o);__fx.push(['toast',{h,k,a,o,tick:!!UI.tick}]);};
|
|
sfx=n=>{__fx.push(['sfx',n]);};haptic=n=>{__fx.push(['haptic',n]);};
|
|
floater=(x,y,t,c)=>{if(__fx.filter(f=>f[0]==='floater').length<40)__fx.push(['floater',[x,y,t,c]]);};
|
|
window.__slimR=()=>{const {o}=rwPack(R);for(const k of ['ef','fl','efp','flc','efg','egDesc','l2route','bbF','peered','cityBlocked'])delete o[k];
|
|
const tn={};for(const id in o.tNet)tn[id]=Object.fromEntries(Object.entries(o.tNet[id]).sort((a,b)=>b[1]-a[1]).slice(0,4));o.tNet=tn;
|
|
o.tTop8=transitTop(S.transit.map(t=>t.id),8);
|
|
const r6=v=>typeof v==='number'?(Number.isInteger(v)||!isFinite(v)?v:+v.toPrecision(6)):Array.isArray(v)?v.map(r6):v&&typeof v==='object'?Object.fromEntries(Object.entries(v).map(([k,x])=>[k,r6(x)])):v;
|
|
return r6(JSON.parse(JSON.stringify(o)));};
|
|
window.__keys=()=>Object.fromEntries(Object.keys(S).map(k=>[k,JSON.stringify(S[k])]));`;
|
|
|
|
function make() {
|
|
const { ev, errors, dom } = load({ seed: 4242 });
|
|
ev(`Date.now=()=>${NOW};`);
|
|
// A network of a server session, built the way the server builds one (beginState, then the server's own marks), with
|
|
// the intern on every order and a fiber cut it rushes: the snapshot carries a shift's log and the week's tally.
|
|
// It joined the session late (day 473): the session's date, one calendar for every network (S.day0).
|
|
ev(`UI.pitched=true;beginState('Packet Pals','fra',{mode:'normal',preset:'oncall',mp:${JSON.stringify(MP)},day:473});S.mp.sim=1;S.tut=null;compute();beginHello();
|
|
S.nextFail=S.nextEvent=1e9;UI.speed=0;UI.started=true;ACT.charter({k:'global'});
|
|
ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});ACT.buildPop({city:'ams'});ACT.launchBB({city:'ams'});
|
|
UI.pending={a:'fra',b:'ams'};ACT.buildLink({tier:0});closeModal();
|
|
S.lvl=Math.max(S.lvl,2);ACT.opsHire({id:'kevin'});for(const k in S.ops.on)S.ops.on[k]=true;S.ops.floor=0;closeModal();
|
|
for(let i=0;i<45;i++){if(i===20)dayGo(failureRun('cut'));dayTick();}`);
|
|
ev(RIG);
|
|
const snapS = JSON.parse(ev('JSON.stringify(S)'));
|
|
const r0 = JSON.parse(ev('JSON.stringify(__slimR())'));
|
|
const diff = (before) => { const now = JSON.parse(ev('JSON.stringify(__keys())')), s = {}, del = [];
|
|
for (const k of Object.keys(now)) if (now[k] !== before[k]) s[k] = JSON.parse(now[k]);
|
|
for (const k of Object.keys(before)) if (!(k in now)) del.push(k);
|
|
return { s, del, keys: now }; };
|
|
const fx = () => JSON.parse(ev('JSON.stringify(__fx.splice(0))'));
|
|
const clock = { t: 'clock', speed: 1, eff: 1, run: true, why: null, votes: { [PID2]: 4 }, tally: { 4: 1 }, need: 2, active: [PID, PID2], hold: [], idle: [],
|
|
day: snapS.day, last: 1, max: 8 };
|
|
const card = JSON.parse(ev('JSON.stringify(mpCard())'));
|
|
const roster = { t: 'roster', code: CODE, title: 'Friday', preset: 'oncall', seed: MP.seed, created: NOW - 864e5,
|
|
players: [{ pid: PID, name: 'Packet Pals', asn: MP.asn, color: MP.color, card, seen: NOW, joined: NOW - 864e5 },
|
|
{ pid: PID2, name: 'Tubular Bells', asn: 207777, color: '#ff4f9a', card: null, seen: NOW - 6e4, joined: NOW - 36e5 }],
|
|
feed: [{ k: 'join', pid: PID, name: 'Packet Pals', at: NOW - 864e5 }, { k: 'join', pid: PID2, name: 'Tubular Bells', at: NOW - 36e5 }, { k: 'chat', pid: PID2, name: 'Tubular Bells', at: NOW - 6e4, text: 'peer with me?' }],
|
|
on: [PID, PID2] };
|
|
const snap = { t: 'snap', epoch: EPOCH, v: 412, now: NOW, S: snapS, r: r0, clock, roster, since: { days: 37, again: 0 }, keep: [['badge', { id: 'firstpop', v: 'oncall' }]] };
|
|
|
|
// A day: the keys it changed, a new R, what it said.
|
|
let base = JSON.parse(ev('JSON.stringify(__keys())'));
|
|
ev('UI.tick=false;dayTick();');
|
|
const d1 = diff(base), dayFx = fx();
|
|
if (!dayFx.length) dayFx.push(['sfx', 'coin']);
|
|
const updDay = { t: 'upd', from: 412, v: 413, now: NOW + 2500, day: JSON.parse(ev('S.day')), s: d1.s, del: d1.del, r: JSON.parse(ev('JSON.stringify(__slimR())')), fx: dayFx };
|
|
|
|
// Two quick taps in one update: a new POP (the panel moves to it) and a transit port there.
|
|
base = d1.keys;
|
|
ev("ACT.buildPop({city:'par'});");
|
|
const ui1 = { sel: { type: 'city', id: 'par' }, tab: 'cust' };
|
|
ev("ACT.buyTransit({city:'par',net:'cog',tier:1});");
|
|
const d2 = diff(base), actFx = fx();
|
|
const updAct = { t: 'upd', from: 413, v: 414, now: NOW + 3100, day: updDay.day, s: d2.s, del: d2.del, r: JSON.parse(ev('JSON.stringify(__slimR())')), fx: actFx,
|
|
acts: [{ rid: 'a1b2c3d4e5', dev: DEV, ui: ui1 }, { rid: 'a1b2c3d4e6', dev: DEV, ui: {} }] };
|
|
|
|
// A stream's flow records: the link it shows and its traffic's ways in, and a city's Peering tab.
|
|
const sub = JSON.parse(ev(`(()=>{const l=S.links[0],k=edgeKey(l),rec=R.ef[k],egd={};if(rec)for(const e in rec.eg||{})if(R.egDesc[e])egd[e]=R.egDesc[e];
|
|
return JSON.stringify({t:'sub',v:414,ef:rec?{[k]:rec}:{},egd,pf:{fra:pniFlows('fra')}});})()`));
|
|
|
|
if (errors.length) throw new Error('the game failed while making fixtures: ' + errors.join('; '));
|
|
dom.window.close();
|
|
return { snap, 'upd-day': updDay, 'upd-act': updAct, sub, clock, roster };
|
|
}
|
|
function write() {
|
|
fs.mkdirSync(DIR, { recursive: true });
|
|
const out = make();
|
|
for (const [k, v] of Object.entries(out)) fs.writeFileSync(path.join(DIR, k + '.json'), JSON.stringify(v) + '\n');
|
|
return Object.keys(out);
|
|
}
|
|
|
|
module.exports = { make, write, DIR, CODE, PID, PID2, EPOCH, DEV, NOW };
|
|
|
|
if (require.main === module) console.log('wrote', write().map((k) => `tests/fixtures/mp-sim/${k}.json`).join(', '));
|