From f9d89ac815a6c60323f638199a81e0e588407872 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Fri, 23 Oct 2026 18:02:06 +0200 Subject: [PATCH] NOC legend, sortable network table and transit insights Closes #7 --- CHANGELOG.md | 23 +++++++++++++++++++++++ site/index.html | 28 ++++++++++++++++++++++------ tests/issues.test.js | 19 +++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d2355d..94996c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,29 @@ All notable changes to this project are documented here. The project follows - Zoom in twice as far as before, handy for crowded spots like the UAE, Singapore or Central Europe. - Half speed: a new ½× button, or press 0. +- NOC dashboard: a legend explains the colours in "How it arrives", the + network table sorts by any column (traffic, transit cost, loss, name), and a + new "Who your transit carries" list shows the networks you pay transit to + reach, with the cheapest way to move each one to peering (#7). +- The Transit tab shows the top destinations on each transit port, with the + same hint, so you can see who to peer with in that city (#7). +- A full code review, and about 40 fixes from it: + - Saves and imported files are checked and repaired before use, so a + damaged or hand-edited save can no longer break the game or inject + anything into the page. + - Loophole fixes: flipping crypto loans for profit, free repairs of + geopolitical cable cuts, re-rolling DE-KICKS quotes, walking out of a + failing event, and selling the same trench twice. + - The Red Sea scenario really cuts the Red Sea now, the weekly challenge + gives everyone the same world, and its "pricey" and "poor" twists work. + - China Telecomet and China Unicorn no longer act like Tier 1s. + - Metro ring cuts now alert you, overlapping site outages no longer cancel + each other, and alien waves work on unlit fiber. + - Routing is several times faster on big networks. + - The map fills wide screens at any zoom, pinch zoom goes as far as the + mouse wheel, and touch scrolling and cancelled touches behave. + - Starting a scenario from a running game asks first, and Space no longer + pauses when you meant to press a button. ## [1.8.1] — 2026-10-23 diff --git a/site/index.html b/site/index.html index 014a734..fc6841c 100644 --- a/site/index.html +++ b/site/index.html @@ -252,6 +252,8 @@ section h3{font-size:17px;margin-bottom:6px;display:flex;align-items:center;gap: :root.no-anim .coach-glow{outline:3px solid #FF4F9A} .setline{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:4px 0} .setline>span{font-weight:800} +.thb{font:inherit;font-weight:900;background:none;border:0;padding:0;cursor:pointer;color:inherit} +.ttop{margin:4px 0;padding:4px 8px;border-left:3px solid #FF8A3D;background:#FFF6EC;border-radius:6px} .menu-list{display:flex;flex-direction:column;gap:8px;margin-top:12px} .menu-list .b{justify-content:space-between;width:100%} #mega{position:fixed;left:0;right:0;bottom:0;z-index:17;background:#7A86B8;border-top:3px solid var(--ink);overflow:hidden;white-space:nowrap;pointer-events:none;animation:megaflash 1.2s steps(2) infinite} @@ -807,7 +809,7 @@ const GOALS=[ let S=null, R=emptyR(); const UI={sel:null,tab:'cust',left:'goals',speed:1,hover:null,drag:null,snap:null,pending:null,confirm:null,leftOpen:false,muted:false,startCity:'fra',hintOff:false}; let uidN=1; const uid=()=>'i'+(Date.now()%1e7).toString(36)+(uidN++); -function emptyR(){return {egT:{},netEg:{},l2lat:{},nodeLoad:{},nodeCap:{},div:{},l2:{},gfwLost:0,gfwCross:0,ef:{},egDesc:{},p95:{},peered:0,peerShare:0,load:{},useT:{},useIx:{},usePni:{},useCache:{},cityDem:{},citySrv:{},cityEye:{},demTo:{},served:0,demand:0,reach:0,sessions:0,revMo:0,costMo:0,cost:{},rev:{},reachable:{}};} +function emptyR(){return {tNet:{},egT:{},netEg:{},l2lat:{},nodeLoad:{},nodeCap:{},div:{},l2:{},gfwLost:0,gfwCross:0,ef:{},egDesc:{},p95:{},peered:0,peerShare:0,load:{},useT:{},useIx:{},usePni:{},useCache:{},cityDem:{},citySrv:{},cityEye:{},demTo:{},served:0,demand:0,reach:0,sessions:0,revMo:0,costMo:0,cost:{},rev:{},reachable:{}};} /* ================= BANKS & LOANS ================= Lenders make offers now and then (more often when you are broke). Each loan is a fixed monthly payment that shows up in your costs; conditions are checked @@ -1226,7 +1228,7 @@ function compute(){ if(!f.junk){let ok=amt;const fc=cnCity(f.c),ec=cnCity(e.city),nc=!!NET[f.n].cn; if(fc!==ec||(fc&&!nc)||(!fc&&nc&&e.k==='t')){const prem=(e.k==='t'&&e.prem)||(e.k==='p'&&e.pnc)||path.some(x=>x.links&&x.links.some(y=>y.premium));const loss=prem?0.03:(ev.gfw>day?0.35:0.2);R2.gfwLost+=amt*loss;R2.gfwCross+=amt;ok=amt*(1-loss);} if(f.n==='ggl'&&ruCity(f.c))ok*=0.5; - R2.citySrv[f.c]+=ok;R2.served+=ok;if(e.rank<=2)R2.peered+=ok;R2.egT[e.k]=(R2.egT[e.k]||0)+ok;const ne=R2.netEg[f.n]||(R2.netEg[f.n]={c:0,p:0,ix:0,t:0});ne[e.k]+=ok;} + R2.citySrv[f.c]+=ok;R2.served+=ok;if(e.rank<=2)R2.peered+=ok;if(e.k==='t'){const m=R2.tNet[e.id]||(R2.tNet[e.id]={});m[f.n]=(m[f.n]||0)+ok;}R2.egT[e.k]=(R2.egT[e.k]||0)+ok;const ne=R2.netEg[f.n]||(R2.netEg[f.n]={c:0,p:0,ix:0,t:0});ne[e.k]+=ok;} return amt; }; // Shortest path first. With Auto-TE, whatever does not fit spills onto up to two alternate paths @@ -1753,6 +1755,7 @@ const ACT={ help:()=>showHelp(), dash:()=>{if(!S)return;const d=$('dash');d.hidden=!d.hidden;if(!d.hidden)renderDash();}, dashClose:()=>{$('dash').hidden=true;}, + dashSort:({k})=>{if(!['name','asn','type','traffic','cost','lost'].includes(k))return;if(UI.dashSort===k)UI.dashDir=-(UI.dashDir||-1);else{UI.dashSort=k;UI.dashDir=k==='name'||k==='type'||k==='asn'?1:-1;}renderDash();}, bank:()=>{if(!S)return;UI.confirm=null;$('dash').hidden=true;const b=$('bankBox');b.hidden=false;UI._bh=null;renderBank();}, bankClose:()=>{UI.confirm=null;$('bankBox').hidden=true;}, takeLoan:({id})=>{const o=S.loanOffers.find(x=>x.id===id);if(!o)return;S.stats.loans=(S.stats.loans||0)+1;const B=BANKS[o.bank];let got=o.amount,note=''; @@ -2077,7 +2080,7 @@ function cityPanel(c){ for(const n of prov){const t=S.transit.find(x=>x.city===c&&x.net===n.id);const pr=n.price*S.priceMul*(t&&t.premium&&c==='hkg'?n.premium:1)*regionMult(c); h+=`
${logo(n)}
${esc(n.name)} ${TYPE_L[n.type]}
$${pr.toFixed(2)} per Gbps / month · billed on 95th percentile
`; if(t){const u=R.useT[t.id]||0,cap=lagCap(PORT[t.tier].g,t.n),tdown=t.down>S.day; - h+=`
${lagName(t.tier,t.n)}${tdown?' · OUTAGE':''}${fmtG(u)}
${prefCtl('t',t.id,t.pref)}${siteCtl('t',t.id,c,t.site)}${n.premium&&c==='hkg'?`
${btn(t.premium?'CN-Too premium on ✓':`Switch to CN-Too premium ${n.premium}× price · ~3% loss into China`,'togglePrem',{id:t.id},t.premium?'green sm':'sm')}
`:''}
95th pct ${fmtG(R.p95[t.id]||0)} · commit ${fmtG(cap*.2)} · bill ${fmt$(Math.max(R.p95[t.id]||0,PORT[t.tier].g*(t.n||1)*.2)*pr+PORT[t.tier].tmo*(t.n||1))}/mo
+ h+=`
${lagName(t.tier,t.n)}${tdown?' · OUTAGE':''}${fmtG(u)}
${prefCtl('t',t.id,t.pref)}${siteCtl('t',t.id,c,t.site)}${n.premium&&c==='hkg'?`
${btn(t.premium?'CN-Too premium on ✓':`Switch to CN-Too premium ${n.premium}× price · ~3% loss into China`,'togglePrem',{id:t.id},t.premium?'green sm':'sm')}
`:''}${(()=>{const top=transitTop([t.id],4);return top.length?`
Top destinations on this port
${top.map(([id,v])=>`
${esc(NET[id].name)} · ${fmtG(v)} · ${esc(offTransitHint(id,c))}
`).join('')}
`:'';})()}
95th pct ${fmtG(R.p95[t.id]||0)} · commit ${fmtG(cap*.2)} · bill ${fmt$(Math.max(R.p95[t.id]||0,PORT[t.tier].g*(t.n||1)*.2)*pr+PORT[t.tier].tmo*(t.n||1))}/mo
${PORT.map((P2,i)=>i>t.tier?btn(`Upgrade ${(t.n||1)>1?'all to ':''}${P2.n} ${fmt$(P2.setup*(t.n||1))} + ${fmt$(P2.tmo*(t.n||1))}/mo`,'buyTransit',{city:c,net:n.id,tier:i},'sm',S.cash${fmt$(PORT[t.tier].setup)} + ${fmt$(PORT[t.tier].tmo)}/mo`,'lagT',{id:t.id,d:1},'sm',S.cash1?btn('− member','lagT',{id:t.id,d:-1},'ghost sm'):''}${btn(UI.confirm===t.id?'Really cancel?':'Cancel','cancelTransit',{id:t.id},'ghost sm')}
`;} else h+=`
${PORT.map((P2,i)=>btn(`${P2.n} ${fmt$(P2.setup)} + ${fmt$(P2.tmo)}/mo`,'buyTransit',{city:c,net:n.id,tier:i},'sm',S.cash`; h+=`
`;} @@ -2235,6 +2238,17 @@ function svgChart(rows,stackKeys,lines,fmtY){ for(const ln of lines){let d='';rows.forEach((r,i)=>{d+=(i?'L':'M')+x(i)+','+y(r[ln.k]||0);});g+=``;const last=rows[rows.length-1][ln.k]||0;g+=``;} g+=`${dateStr(rows[0].d)}${dateStr(rows[rows.length-1].d)}`; return `${g}`;} +// For a network you currently reach over transit: the cheapest way to move it to peering. +function offTransitHint(id,city){const n=NET[id];if(n.type==='t1')return 'Tier 1: only a PNI, and only once you are big enough for the Tier 1 club'; + const ixc=Object.keys(S.pops).filter(c=>ixMembers(c).includes(id)),here=city&&ixMembers(city).includes(id)?city:null,pick1=here||ixc[0]; + if(n.pol==='open')return pick1?`Open peer: join the route server at ${ixName(pick1)}${here?'':' ('+CITY[pick1].name+')'}`:'Open peer, but not on any IX where you have a POP'; + if(n.pol==='paid')return `Paid peering only: a PNI costs ${fmt$(n.paidFee)}/mo`; + const pniC=Object.keys(S.pops).filter(c=>n.pops.includes(c));const ixOk=pick1?peerOk(id,'ix',pick1):null,pOk=pniC.length?peerOk(id,'pni',pniC.includes(city)?city:pniC[0]):null; + if(pOk&&pOk.ok)return `Ready for a PNI in ${CITY[pniC.includes(city)?city:pniC[0]].name}`; + if(ixOk&&ixOk.ok)return `Will peer at ${ixName(pick1)}: request a session`; + if(ixOk)return `${ixName(pick1)}: ${ixOk.why}`; + return pniC.length?`PNI in ${CITY[pniC[0]].name}: ${pOk.why}`:'Not present in any of your cities yet';} +function transitTop(ids,k=5){const m={};for(const id of ids)for(const [n,v] of Object.entries(R.tNet[id]||{}))m[n]=(m[n]||0)+v;return Object.entries(m).filter(([,v])=>v>0.01).sort((a,b)=>b[1]-a[1]).slice(0,k);} function renderDash(){ const H=S.hist||[],rows=H.slice(-90),last30=H.slice(-30); const up=last30.length?last30.reduce((a,r)=>a+(r.dem?Math.min(1,r.srv/r.dem):1),0)/last30.length:1; @@ -2245,10 +2259,12 @@ function renderDash(){

Traffic by way out

${svgChart(rows,['c','p','ix','t','l2'],[{k:'dem',col:'#1E2640',dash:true}],v=>fmtCap(Math.round(v)))}
${Object.keys(EGC).map(k=>`${EGC[k][0]} ${pct((R.egT[k]||0)/tot)}`).join('')}Demand

Money per month

${svgChart(rows,[],[{k:'rev',col:'#16A866'},{k:'cost',col:'#FF4D5E'}],v=>fmt$(v))}
RevenueCosts

Where the money goes

${Object.entries(R.cost).filter(([k,v])=>v>0).sort((a,b)=>b[1]-a[1]).map(([k,v])=>`
${{pops:'POPs and routers',links:'Waves and fiber',transit:'Transit',ix:'IX ports',pni:'PNIs',caches:'Cache power',nni:'Fabric ports',optical:'Amp huts and spares',loans:'Loan repayments',revshare:'Investor revenue share',extras:'Licenses and scrubbing'}[k]||k}${fmt$(v)}/mo
`).join('')}
`; - const nets=NETS.map(n=>{const e=R.netEg[n.id]||{c:0,p:0,ix:0,t:0};const t=e.c+e.p+e.ix+e.t;return {n,e,t};}).filter(x=>x.t>0.01||R.demTo[x.n.id]>0.01).sort((a,b)=>b.t-a.t); const tT=(R.egT.t||0)||1; - h+=`

Traffic by network (ASN)

Where your users' traffic comes from, and how it gets to you. Red in the mix is paid transit; everything else is free or cheap.

- ${nets.map(({n,e,t})=>{const want=R.demTo[n.id]||0;return ``;}).join('')}
NetworkASTypeTrafficHow it arrivesTransit costLost
${logo(n)}${esc(n.name)}${n.asn}${TYPE_L[n.type]}${fmtG(t)}
${['c','p','ix','t'].map(k=>``).join('')}
${e.t>0.01?fmt$((R.cost.transit||0)*e.t/tT)+'/mo':'—'}${want>0.01?pct(Math.max(0,1-t/want)):'—'}
`; + const nets=NETS.map(n=>{const e=R.netEg[n.id]||{c:0,p:0,ix:0,t:0};const t=e.c+e.p+e.ix+e.t,want=R.demTo[n.id]||0;return {n,e,t,cost:(R.cost.transit||0)*e.t/tT,lost:want>0.01?Math.max(0,1-t/want):0};}).filter(x=>x.t>0.01||R.demTo[x.n.id]>0.01); + {const k=UI.dashSort||'traffic',dir=UI.dashDir||-1,val=x=>k==='name'?x.n.name.toLowerCase():k==='asn'?x.n.asn:k==='type'?x.n.type:k==='cost'?x.cost:k==='lost'?x.lost:x.t;nets.sort((a,b)=>{const A=val(a),B=val(b);return (AB?1:0)*dir||b.t-a.t;});} + h+=`

Traffic by network (ASN)

Where your users' traffic comes from, and how it gets to you. Transit is the only part you pay per gigabit; caches, PNIs and IX peering are free or flat-rate. Tap a column to sort.

${['c','p','ix','t'].map(k=>`${EGC[k][0]}`).join('')}
${[['name','Network',''],['asn','AS',''],['type','Type',''],['traffic','Traffic','r'],['mix','How it arrives',''],['cost','Transit cost','r'],['lost','Lost','r']].map(([k,l,c])=>``).join('')} + ${nets.map(({n,e,t})=>{const want=R.demTo[n.id]||0;return ``;}).join('')}
${k==='mix'?l:``}
${logo(n)}${esc(n.name)}${n.asn}${TYPE_L[n.type]}${fmtG(t)}
${['c','p','ix','t'].map(k=>``).join('')}
${e.t>0.01?fmt$((R.cost.transit||0)*e.t/tT)+'/mo':'—'}${want>0.01?pct(Math.max(0,1-t/want)):'—'}
`; + {const top=transitTop(S.transit.map(t=>t.id),8);if(top.length)h+=`

Who your transit carries

The networks you pay transit to reach, biggest first, and the cheapest way to move each one to peering. This is your to-do list on the way to Tier 1.

${top.map(([id,v])=>`
${logo(NET[id])}
${esc(NET[id].name)} AS${NET[id].asn} · ${fmtG(v)} · about ${fmt$((R.cost.transit||0)*v/tT)}/mo
${esc(offTransitHint(id))}
`).join('')}
`;} const ls=S.links.filter(l=>capOf(l)>0).map(l=>({l,u:(R.load[l.id]||0)/capOf(l)})).sort((a,b)=>b.u-a.u).slice(0,8); const rs=Object.keys(S.pops).map(c=>({c,u:(R.nodeLoad[c]||0)/(R.nodeCap[c]||1)})).sort((a,b)=>b.u-a.u).slice(0,6); h+=`

Busiest links

${ls.length?ls.map(({l,u})=>`
${CITY[l.a].name} ⇄ ${CITY[l.b].name} ${capName(l)} · ${linkLat(l).toFixed(1)} ms
${pct(u)}${btn('Open','dashLink',{id:l.id},'ghost sm')}
`).join(''):'

No links yet.

'}
diff --git a/tests/issues.test.js b/tests/issues.test.js index 7dd0d0f..62c7c0c 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -160,3 +160,22 @@ test('rare badges hook into incidents and deals', () => { assert.equal(ev("BADGES.length>=46&&new Set(BADGES.map(b=>b.id)).size===BADGES.length"), true); assert.deepEqual(errors, []); }); + +test('#7 NOC legend, sortable network table and transit destinations', () => { + const { ev, errors } = load(); + base(ev); + ev("ACT.buyTransit({city:'fra',net:'cog',tier:1});compute();ACT.dash()"); + let t = ev("document.getElementById('dashCard').textContent"); + assert.match(t, /Who your transit carries/); + assert.match(t, /IX peering/, 'legend explains the colours'); + const top = JSON.parse(ev("JSON.stringify(transitTop(S.transit.map(t=>t.id),3))")); + assert.ok(top.length > 0 && top[0][1] > 0); + assert.equal(ev(`typeof offTransitHint('${top[0][0]}','fra')`), 'string'); + ev("ACT.dashSort({k:'cost'})"); + assert.equal(ev("UI.dashSort"), 'cost'); + ev("ACT.dashSort({k:'cost'})"); + assert.equal(ev("UI.dashDir"), 1, 'second tap flips the order'); + ev("selectCity('fra');ACT.tab({t:'up'})"); + assert.match(ev("document.getElementById('panelBody').textContent"), /Top destinations on this port/); + assert.deepEqual(errors, []); +});