Split the game page into partials under src/, assembled into one index.html at build
site/index.html (900 KB of HTML, CSS and JS in one file) becomes src/: a shell (src/index.html), styles/ and game/, concatenated in path order by scripts/lib/page.js. The assembled page is byte-identical to the old file, so load time and in-game performance are unchanged. - scripts/build.js replaces build.sh (same env vars, same output) - npm run dev: a zero-dependency dev server that assembles on every request - tests assemble the page in memory; npm test runs every tests/*.test.js - perf-bench takes --base-ref to build a git ref's page - scripts/legacy/split-index-html.js is the splitter, kept for older branches
This commit is contained in:
parent
295e68cc46
commit
67a40942b4
113 changed files with 5584 additions and 5195 deletions
27
src/game/93-ui/10-dom.js
Normal file
27
src/game/93-ui/10-dom.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ================= DOM RENDER ================= */
|
||||
const $=id=>document.getElementById(id);
|
||||
const btn=(label,act,args={},cls='',dis=false,title='')=>`<button class="b ${cls}" data-act="${act}" data-args="${esc(JSON.stringify(args))}"${dis?' disabled':''}${title?` title="${esc(title)}"`:''}>${label}</button>`;
|
||||
const logo=n=>`<span class="logo" style="--c:${n.col}">${initials(n)}</span>`;
|
||||
const barCls=u=>u>=0.9?'bad':u>=0.65?'warn':'';
|
||||
/* Panels are rebuilt from state every tick. Replacing a thousand rows makes the browser style and lay out every one
|
||||
of them again, so patch what changed instead: same HTML, far less work. A button that now does something else, and
|
||||
any form field that changed, is swapped out whole, so a tap that started on the old one still cannot fire it (#44). */
|
||||
const SWAP={INPUT:1,SELECT:1,TEXTAREA:1,OPTION:1};
|
||||
function morph(el,html){const t=document.createElement(el.tagName);t.innerHTML=html;morphKids(el,t);}
|
||||
function sameNode(x,y){if(x.nodeType!==y.nodeType||x.nodeName!==y.nodeName)return false;if(x.nodeType!==1)return true;
|
||||
if(SWAP[x.nodeName])return x.outerHTML===y.outerHTML;
|
||||
return x.getAttribute('data-act')===y.getAttribute('data-act')&&x.getAttribute('data-args')===y.getAttribute('data-args');}
|
||||
function morphKids(a,b){let x=a.firstChild,y=b.firstChild;
|
||||
while(y){const ny=y.nextSibling;
|
||||
if(!x)a.appendChild(y);
|
||||
else if(!sameNode(x,y)){a.replaceChild(y,x);x=y;}
|
||||
else if(x.nodeType===1){if(!SWAP[x.nodeName]){const ya=y.attributes,xa=x.attributes;
|
||||
for(let i=0;i<ya.length;i++){const {name,value}=ya[i];if(x.getAttribute(name)!==value)x.setAttribute(name,value);}
|
||||
for(let i=xa.length-1;i>=0;i--)if(!y.hasAttribute(xa[i].name))x.removeAttribute(xa[i].name);
|
||||
morphKids(x,y);}}
|
||||
else if(x.nodeValue!==y.nodeValue)x.nodeValue=y.nodeValue;
|
||||
x=x&&x.nextSibling;y=ny;}
|
||||
while(x){const nx=x.nextSibling;a.removeChild(x);x=nx;}}
|
||||
function renderAll(){if(isTablet()&&!UI.sel)UI.leftOpen=false;renderHUD();renderLeft();renderPanel();renderHint();renderMega();renderCoach();}
|
||||
function renderMega(){const el=$('mega');if(!el)return;const on=!!(S&&S.ev&&S.ev.php>S.day);if(el.hidden===!on)return;el.hidden=!on;}
|
||||
|
||||
23
src/game/93-ui/20-phone.js
Normal file
23
src/game/93-ui/20-phone.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ================= PHONE ================= */
|
||||
const isPhone=()=>innerWidth<=760||(innerHeight<=500&&matchMedia('(pointer:coarse)').matches);
|
||||
const SPEEDS=[0.5,1,2,4,8];
|
||||
function renderTabbar(){const tb=$('tabbar');if(!tb||(pressing&&UI.ticking))return;if(!isPhone()||!S||!UI.started){tb.hidden=true;document.body.classList.remove('sheet-open');return;}tb.hidden=false;
|
||||
const open=UI.leftOpen&&!UI.sel,cur=UI.left||'goals',ndone=GOALS.filter(g=>S.done[g.id]!==undefined).length;
|
||||
const tab=(k,ic,l,cnt,red)=>`<button class="${open&&cur===k?'on':''}" data-act="phoneTab" data-args='{"t":"${k}"}' aria-label="${esc(l)}"><span class="ic" aria-hidden="true">${ic}</span>${esc(l)}${cnt?`<span class="cnt${red?' red':''}">${cnt}</span>`:''}</button>`;
|
||||
const h=`<button class="play${UI.speed?'':' paused'}" data-act="phonePlay" aria-label="${UI.speed?tr('Pause'):tr('Play')}"><span class="ic" aria-hidden="true">${UI.speed?'❚❚':'▶'}</span>${UI.speed?tr('Pause'):tr('Play')}</button>`+
|
||||
`<button data-act="phoneSpeed" aria-label="${tr('Game speed')}"><span class="ic" aria-hidden="true">${UI.speed===0.5?'½':(UI.lastSpeed||UI.speed||1)}×</span>${tr('Speed')}</button>`+
|
||||
(()=>{const P=scnProg();return tab('goals','🎯',tr('Goals'),P&&!S.scn.done&&!S.scn.failed?`${Math.round(P.f*100)}%`:`${ndone}/${GOALS.length}`);})()+(()=>{const u=custStats().unhappy;return u?tab('deals','💼',tr('Deals'),u,true):tab('deals','💼',tr('Deals'),S.offers.length||'');})()+tab('noc','🚨','NOC',S.inc.length||(UI.left==='noc'&&UI.leftOpen?'':logUnread())||'',S.inc.length>0)+tab('nets','🌐',tr('Networks'),ibxOpen()||'',ibxUrgent()>0);
|
||||
if(h!==UI._tb){UI._tb=h;tb.innerHTML=h;}
|
||||
document.body.classList.toggle('sheet-open',!!(UI.sel||UI.leftOpen));}
|
||||
function haptic(ms){if(UI.muted)return;try{navigator.vibrate&&navigator.vibrate(ms||12);}catch(e){}}
|
||||
// Bottom sheets: drag the handle up to expand, down to shrink or close; tap it to toggle.
|
||||
(function(){let g=null;
|
||||
document.addEventListener('pointerdown',e=>{const h=e.target.closest('[data-grab]');if(!h||!isPhone())return;const el=h.parentElement;g={el,y:e.clientY,dy:0,id:e.pointerId,full:el.classList.contains('full')};try{h.setPointerCapture(e.pointerId);}catch(_){}el.style.transition='none';});
|
||||
document.addEventListener('pointermove',e=>{if(!g||e.pointerId!==g.id)return;g.dy=e.clientY-g.y;if(g.dy>0)g.el.style.transform=`translateY(${g.dy}px)`;});
|
||||
const end=e=>{if(!g||e.pointerId!==g.id)return;const {el,dy,full}=g;g=null;el.style.transition='';el.style.transform='';
|
||||
if(Math.abs(dy)<6){el.classList.toggle('full');return;}
|
||||
if(dy<-40){el.classList.add('full');return;}
|
||||
if(dy>40){if(full){el.classList.remove('full');return;}if(el.id==='panel')ACT.closePanel();else{UI.leftOpen=false;renderLeft();}}};
|
||||
document.addEventListener('pointerup',end);document.addEventListener('pointercancel',end);})();
|
||||
// Toasts can be tapped away on touch screens.
|
||||
document.addEventListener('click',e=>{const t=e.target.closest('.toast');if(t&&!e.target.closest('[data-act]')&&isPhone())t.remove();});
|
||||
23
src/game/93-ui/30-install.js
Normal file
23
src/game/93-ui/30-install.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ================= INSTALL (PWA) ================= */
|
||||
let installEvt=null;
|
||||
addEventListener('beforeinstallprompt',e=>{e.preventDefault();installEvt=e;});
|
||||
addEventListener('appinstalled',()=>{installEvt=null;track('pwa_installed',true);if(UI.pendGame){const p=UI.pendGame;UI.pendGame=null;UI.pitched=true;beginGame(...p);}toast(tr('<b>Installed!</b><br>Open Series of Tubes from your home screen. Your saves come along.'),'good');});
|
||||
const isStandalone=()=>{try{return navigator.standalone===true||!!(window.matchMedia&&matchMedia('(display-mode: standalone)').matches);}catch(e){return false;}};
|
||||
const isIOS=()=>/iPad|iPhone|iPod/.test(navigator.userAgent)||(navigator.platform==='MacIntel'&&navigator.maxTouchPoints>1);
|
||||
function installRow(){if(isStandalone())return '';
|
||||
return `<div class="row icard"><div class="grow"><div class="nm">📲 ${tr('Best played as an app')}</div><div class="meta">${tr('Full screen, works offline, one tap from your home screen.')}${isIOS()?' '+tr('Install it before you start: a game begun in Safari stays in Safari.'):''}</div></div>${btn(tr('Install'),'install',{},'pink sm')}</div>`;}
|
||||
/* Phones get a real pitch before a new game: an installed app is full screen, works offline, and on iPhone
|
||||
keeps its save away from Safari's clean-ups. Storage is separate on iOS, so installing first matters. */
|
||||
const SHARE_SVG='<svg width="16" height="18" viewBox="0 0 16 18" aria-hidden="true"><path d="M8 1v10M4.5 4.5 8 1l3.5 3.5M5 7H2.5v9.5h11V7H11" fill="none" stroke="#1E2640" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
||||
const needPitch=()=>isPhone()&&!isStandalone();
|
||||
function installSteps(){
|
||||
if(isIOS())return `<ol class="isteps"><li>${tr('Tap <b>Share</b> {icon} in the browser toolbar.',{icon:SHARE_SVG})}</li><li>${tr('Tap <b>Add to Home Screen</b>. You may need to scroll down, or tap <b>More</b> first.')}</li><li>${tr('Open <b>Series of Tubes</b> from your home screen and start your network there.')}</li></ol>`;
|
||||
if(installEvt)return '';
|
||||
return `<ol class="isteps"><li>${tr('Open your browser menu (⋮).')}</li><li>${tr('Tap <b>Install app</b> or <b>Add to Home screen</b>.')}</li><li>${tr('Open <b>Series of Tubes</b> from your home screen.')}</li></ol>`;}
|
||||
function pitchHtml(starting){const ios=isIOS();
|
||||
return `<div style="display:flex;align-items:center"><div>${starting?`<div class="eyebrow">${tr('Before you start')}</div>`:''}<h2 style="font-size:26px">📲 ${tr('Play it as an app')}</h2></div><button class="x" data-act="${starting?'pitchSkip':'closeModal'}" aria-label="${tr('Close')}">×</button></div>
|
||||
<p class="lead" style="margin-top:6px">${tr('Series of Tubes is made for your home screen. It takes ten seconds, costs nothing, and it is a much better game there:')}</p>
|
||||
<ul class="pitch"><li>🗺️ <b>${tr('Full screen.')}</b> ${tr('No browser bars, a lot more map.')}</li><li>📶 <b>${tr('Works offline.')}</b> ${tr('Build your backbone on the train or on a plane.')}</li>${ios?`<li>💾 <b>${tr('Your save stays safe.')}</b> ${tr('Safari can clear the data of websites you have not opened for a week. A home-screen app keeps its own.')}</li><li class="warn">⚠️ <b>${tr('Install first.')}</b> ${tr('On iPhone, a game started in Safari does not carry over to the home-screen app.')}</li>`:`<li>⚡ <b>${tr('One tap away.')}</b> ${tr('It opens straight into your network, like any other app.')}</li>`}</ul>
|
||||
${installSteps()}
|
||||
<div class="btns cta" style="margin-top:12px">${installEvt?btn(tr('Install the app'),'install',{},'pink big'):''}${starting?btn(tr('Play in the browser anyway'),'pitchSkip',{},installEvt?'ghost':'ghost big'):btn(tr('Got it'),'closeModal',{},installEvt?'ghost':'pink')}</div>`;}
|
||||
if('serviceWorker' in navigator&&location.protocol==='https:'&&!IS_DEV)addEventListener('load',()=>{navigator.serviceWorker.register('/sw.js').catch(()=>{});});
|
||||
91
src/game/93-ui/40-hud-and-panels.js
Normal file
91
src/game/93-ui/40-hud-and-panels.js
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
function fitHud(){const h=$('hud');if(!h)return;h.classList.remove('fit1','fit2','fit3');if(innerWidth<=760)return;
|
||||
const row=()=>{let m=0;for(const c of h.children)if(c.offsetParent)m=Math.max(m,c.offsetHeight);return m;};
|
||||
for(const c of ['fit1','fit2','fit3']){if(h.offsetHeight<=row()*1.5)break;h.classList.add(c);}}
|
||||
function renderHUD(){
|
||||
for(const v of [0,0.5,1,2,4,8]){const b=$('sp'+v);if(b)b.classList.toggle('on',UI.speed===v);}
|
||||
$('muteBtn').style.opacity=UI.muted?.4:1;
|
||||
if(!S)return;
|
||||
$('hName').textContent=S.name;$('hAsn').textContent='AS'+S.asn+(S.mode==='sandbox'?' · '+tr('Sandbox'):S.scn?' · '+(scnName())+(S.scn.done||S.scn.failed?'':` · ${tr('{n}d left',{n:Math.max(0,S.scn.days-S.day)})}`):'');
|
||||
$('hCash').textContent=fmt$(S.cash);$('hCash').style.color=S.cash<0?'var(--bad)':'';
|
||||
const net=R.revMo-R.costMo;$('hRate').innerHTML=`<span class="${net>=0?'up':'down'}">${net>=0?'▲':'▼'} ${tr('{price}/mo',{price:fmt$(Math.abs(net))})}</span>`;
|
||||
$('hTraffic').textContent=`${fmtG(R.served)}`;
|
||||
$('hTrafBar').style.width=(R.demand?R.served/R.demand*100:0)+'%';
|
||||
$('hTrafBar').style.background=R.demand&&R.served/R.demand<0.9?'var(--bad)':'var(--ok)';
|
||||
$('hReach').textContent=reachPct(R.reach);$('hReach').style.color=R.reach<0.99?'var(--bad)':'var(--eye)';
|
||||
$('hTier').textContent=tierLabel()+' · '+tr('Lv {n}',{n:S.lvl||1});
|
||||
{const P=scnProg(),hs=$('hScn');hs.hidden=!P;if(P){const sc=S.scn;$('hScnVal').textContent=sc.done?tr('Done!'):sc.failed?tr("Time's up"):`${Math.round(P.f*100)}% · ${tr('{n}d left',{n:Math.max(0,sc.days-S.day)})}`;}}
|
||||
$('hDate').textContent=dateStr(S.day);
|
||||
{const bo=(S.loanOffers||[]).length,hb=$('hBank');hb.hidden=!bo;hb.textContent=bo;}
|
||||
{const st=custStats(),hc=$('hCust');hc.hidden=!st.n;if(st.n){$('hCustVal').innerHTML=`${st.avg>=80?'😀':st.avg>=60?'🙂':st.avg>=30?'😟':'😡'} ${Math.round(st.avg)}%${st.unhappy?` <span class="cnt red">${st.unhappy}</span>`:''}`;hc.classList.toggle('hot',st.furious>0);}}
|
||||
const n=S.inc.length;$('hNoc').classList.toggle('hot',n>0);{const u=UI.left==='noc'&&UI.leftOpen?0:logUnread(),b=$('hNocNew');if(b){b.hidden=!u;b.textContent=u>99?'99+':String(u);b.title=trn('{n} new notification','{n} new notifications',u);}}$('hNocVal').textContent=n?trn('{n} incident','{n} incidents',n):tr('All quiet');
|
||||
if(!window.__TUBES_TEST__)fitHud();
|
||||
renderTabbar();
|
||||
}
|
||||
function renderLeft(){checkLayer();
|
||||
// Tablets in landscape: both side panels don't fit next to the map, so the left one tucks away
|
||||
// while a city or link is open and comes back with the toggle button.
|
||||
const tab=isTablet(),L=$('left');L.classList.toggle('closed',tab?(!!UI.sel&&!UI.leftOpen):!UI.leftOpen);const tg=$('leftToggle');if(tg&&innerWidth>760)tg.hidden=!(tab&&L.classList.contains('closed'));
|
||||
renderTabbar();
|
||||
if(!S){L.hidden=true;return;}L.hidden=false;
|
||||
const ndone=GOALS.filter(g=>S.done[g.id]!==undefined).length;
|
||||
const tabs=[['goals',`${tr('Goals')}<span class="cnt">${ndone}/${GOALS.length}</span>`],['deals',`${tr('Deals')}${S.offers.length?`<span class="cnt">${S.offers.length}</span>`:''}`],['noc',`NOC${S.inc.length?`<span class="cnt red">${S.inc.length}</span>`:''}`],['nets',`${tr('Networks')}${ibxOpen()?`<span class="cnt${ibxUrgent()?' red':''}">${ibxOpen()}</span>`:''}`]];
|
||||
$('leftTabs').innerHTML=tabs.map(([k,l])=>`<button class="${UI.left===k?'on':''}" data-act="leftTab" data-args='{"t":"${k}"}'>${l}</button>`).join('')+(innerWidth<760?`<button data-act="toggleLeft" style="margin-left:auto" aria-label="${tr('Close')}">×</button>`:'');
|
||||
let h='';
|
||||
if(UI.left==='goals'){
|
||||
h+=scnCard()+lvlCard()+t1Card();
|
||||
const cur=GOALS.find(g=>S.done[g.id]===undefined);
|
||||
h+=GOALS.map(g=>{const d=S.done[g.id]!==undefined,c=g===cur;return `<div class="goal ${d?'done':''} ${c?'cur':''}"><div class="ck">${d?'✓':''}</div><div><div class="gt">${esc(g.t)}</div>${c||!d?`<div class="gd">${esc(g.d)}</div>`:''}${!d&&g.r?`<div class="gr">${tr('Reward {cash}',{cash:fmt$(g.r)})}</div>`:''}</div></div>`;}).join('');
|
||||
h+=badgeGrid();
|
||||
}else if(UI.left==='deals'){
|
||||
{const st=custStats();if(st.n)h+=`<div class="row" style="margin-bottom:8px"><div class="grow"><div class="nm">${tr('Your customers')} <span class="meta">${st.n} · ${tr('happiness {p}%',{p:Math.round(st.avg)})}</span></div><div class="bar ${moodCls(st.avg)}"><i style="width:${st.avg}%"></i></div>${st.unhappy?`<div class="why">${trn('{n} unhappy customer, {price}/mo at risk','{n} unhappy customers, {price}/mo at risk',st.unhappy,{price:fmt$(st.risk)})}</div>`:''}</div>${btn(st.unhappy?tr('See who'):tr('All customers'),'custOpen',{sad:st.unhappy?1:0},st.unhappy?'pink sm':'ghost sm')}</div>`;}
|
||||
h+=confSection();
|
||||
{const lv=S.lvl||1,nx=LEVELS[lv];h+=`<div class="inc" style="background:#FFF6CF"><div class="nm">${tr('Customer level {lv}: {name}',{lv,name:LEVELS[lv-1].n})}</div><div class="meta">${nx?tr('Next: {req} unlocks {what}',{req:nx.req,what:lc1(nx.unlock)}):tr('Every customer type is unlocked. Go get those terabits.')}</div></div>`;}
|
||||
if(!S.offers.length)h+=`<p class="empty">${tr('No open offers right now. Businesses look for networks with POPs in their city. New ones pop up every few weeks.')}</p>`;
|
||||
for(const o of S.offers.slice().sort((a,b)=>a.exp-b.exp)){const has=bHas(o);
|
||||
h+=`<div class="row"><div class="grow"><div class="nm">${esc(o.name)}</div><div class="meta">${esc(BIZ_T[o.type].l)} · ${CITY[o.city].name}${o.city2?' ⇄ '+CITY[o.city2].name:''} · <b>${bTerms(o)}</b> · ${tr('{n}d left',{n:o.exp-S.day})}${(o.reqs||[]).length?` · ${trn('{n} special requirement','{n} special requirements',o.reqs.length)}`:''}</div>${reqList(o)}
|
||||
<div class="btns">${has?btn(tr('Accept'),'accept',{id:o.id},'green sm'):btn(tr('Go there'),'focusCity',{city:bCities(o).find(c=>!S.pops[c])},'ghost sm')}${btn(tr('Decline'),'decline',{id:o.id},'ghost sm')}</div>${has?'':`<div class="why">${tr('Needs a POP in {cities}',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}</div>`}</div></div>`;}
|
||||
}else if(UI.left==='noc'){
|
||||
h+=`<div class="btns" style="margin-bottom:8px">${btn(tr('Open NOC dashboard'),'dash',{},'pink')}${btn(tr('Connections'),'connOpen',{},'')}${btn(tr('Traceroute'),'trace',{},'')}</div>`;
|
||||
h+=`<p class="lead">${tr('Your Network Operations Center. Every notification also lands here. Things fail all the time on the internet. Redundant links and multiple upstreams let traffic reroute by itself.')}</p>`;
|
||||
// Incidents come first, the ones you can fix with one click at the top (#63): no scrolling past hot ports to replace an optic.
|
||||
for(const i of S.inc.filter(i=>i.type!=='ddos').sort((a,b)=>(b.cost?1:0)-(a.cost?1:0)||(b.impact||0)-(a.impact||0))){h+=`<div class="inc"><div class="nm">${incTitle(i.type)}</div><div class="meta">${esc(i.msg)}</div><div class="meta">${trn('Auto-fix in {n} day','Auto-fix in {n} days',i.until-S.day)}${i.impact?` · ${tr('{g} lost',{g:fmtG(i.impact)})}`:''}</div>${i.cost?`<div class="btns">${btn(`${esc(i.fix||tr('Rush repair'))} ${fmt$(i.cost)}`,'fixInc',{id:i.id},'red sm',S.cash<i.cost)}</div>`:''}</div>`;}
|
||||
h+=logSection();UI.logSeen=Date.now();
|
||||
h+=`<div class="kv"><span>${tr('DDoS scrubbing')}</span><b>${hasScrub()?tr('On · {city}',{city:S.scrubs.map(x=>CITY[x.city].name).join(', ')}):tr('None (build one from a POP\'s Infra tab)')}</b></div>`;
|
||||
{const pops=Object.keys(S.pops),nfs=pops.filter(c=>fsAt(c)).length;
|
||||
h+=`<div class="kv"><span>${tr('Flowspec-capable POPs')}</span><b>${nfs}/${pops.length}</b></div>`;
|
||||
if(nfs<pops.length)h+=`<p class="meta" style="margin:2px 0 6px">${tr('Flowspec drop rules live in router TCAM, so only capable routers filter known UDP floods (DNS, NTP, CLDAP, SYN) at the edge. The used Rusty has none, merchant-silicon and whitebox models do a little, the big chassis do it in full. Upgrade a POP’s router from its Infra tab.')}</p>`;}
|
||||
if(S.grace&&S.grace.until>S.day&&R.graceNets)h+=`<div class="kv"><span>${tr('Courtesy route')}</span><b>${tr('{n} networks · {d} days left',{n:R.graceNets,d:S.grace.until-S.day})}</b></div><p class="meta" style="margin:0 0 6px">${tr('Reaches networks from the last update that you have no other path to, for free. Connect to them before it ends.')}</p>`;
|
||||
h+=ddosPanel();
|
||||
h+=S.te?`<div class="kv"><span>Auto-TE</span><b>${S.te.on?tr('On · moving {g} onto alternate paths',{g:fmtG(R.teMoved||0)}):tr('Off')}</b></div><div class="btns">${btn(S.te.on?tr('Turn Auto-TE off'):tr('Turn Auto-TE on'),'teToggle',{},'ghost sm')}${btn(S.te.script?tr('Edit RouteScript'):tr('Write a RouteScript'),'teEdit',{},'pink sm')}</div>${S.te.script?`<p class="meta" style="margin:2px 0 6px">RouteScript: ${teRules()?tr('{n} rules live',{n:teRules().n}):S.te.on?tr('has errors, not running'):tr('controller off')}${R.teBlack?` · ${tr('blackholing {g}',{g:fmtG(R.teBlack)})}`:''}</p>`:''}`
|
||||
:`<div class="kv"><span>Auto-TE</span><b>${lvl()<3?tr('Unlocks at customer level 3'):tr('Not installed')}</b></div><p class="meta" style="margin:2px 0 6px">${tr('Traffic takes the shortest path, even when it is full. A traffic-engineering controller spills the overflow onto the next-best paths with room.')}</p><div class="btns">${btn(tr('Install Auto-TE <small>{cost} + {mo}/mo</small>',{cost:fmt$(TE_COST),mo:fmt$(TE_MO)}),'buyTE',{},'pink sm',lvl()<3||S.cash<TE_COST)}</div>`;
|
||||
const hot=S.links.filter(l=>!linkDown(l)&&capOf(l)>0&&(R.load[l.id]||0)/capOf(l)>=0.85).sort((a,b)=>(R.load[b.id]/capOf(b))-(R.load[a.id]/capOf(a)));
|
||||
if(hot.length){h+=`<h3 style="font-size:15px;margin:4px 0">${tr('Congested links')}</h3>${S.te&&S.te.on?'':'<p class="meta" style="margin:0 0 4px">'+tr('Raise a full link’s metric so traffic prefers another path, upgrade it, or install Auto-TE.')+'</p>'}`+hot.map(l=>`<div class="row"><div class="grow"><div class="nm">${CITY[l.a].name} ⇄ ${CITY[l.b].name}</div><div class="meta">${capName(l)} · ${tr('{p} full',{p:pct((R.load[l.id]||0)/capOf(l))})}</div></div>${btn(tr('Inspect'),'selLink',{id:l.id},'pink sm')}</div>`).join('');}
|
||||
h+=hwCard();
|
||||
const slow=Object.keys(S.pops).filter(latSlow).sort((a,b)=>R.latF[a]-R.latF[b]);
|
||||
if(slow.length)h+=`<h3 style="font-size:15px;margin:4px 0">🐢 ${tr('Slow cities')}</h3><p class="meta" style="margin:0 0 4px">${tr('Their users go out through transit far away. Past 50 ms round trip, broadband and internet services count as bad service.')}</p>`+slow.map(c=>{const f=R.latFar[c];return `<div class="row"><div class="grow"><div class="nm">${CITY[c].name} → ${CITY[f.to].name}</div><div class="meta">${tr('{p} of its traffic · {ms} ms round trip · service {sf}',{p:pct(Math.min(1,f.share)),ms:Math.round(f.ms),sf:pct(R.latF[c])})}</div></div>${btn(tr('Inspect'),'focusCity',{city:c},'ghost sm')}</div>`;}).join('');
|
||||
const hotR=hotPorts();
|
||||
if(hotR.length)h+=`<h3 style="font-size:15px;margin:4px 0">${tr('Ports, caches and routers running hot')}</h3>`+hotR.map(x=>`<div class="row"><span class="hotk hk-${x.k}">${HOTL[x.k]}</span><div class="grow"><div class="nm">${CITY[x.city].name} · ${esc(x.lab)}</div><div class="meta">${tr('{p} full',{p:pct(Math.min(1,x.u))})}${x.u>=0.995?' · '+tr('dropping or overflowing'):''} · ${esc(x.tip)}</div></div>${btn(tr('Inspect'),'focusCity',{city:x.city},'pink sm')}</div>`).join('');
|
||||
if(!S.inc.length&&!hot.length&&!hotR.length&&!slow.length)h+=`<p class="empty">${tr('All systems green. Enjoy it while it lasts.')}</p>`;
|
||||
h+=`<div class="kv" style="margin-top:8px"><span>${tr('Incidents so far')}</span><b>${S.stats.incidents}</b></div><div class="kv"><span>${tr('Survived with no impact')}</span><b>${S.stats.survived}</b></div>`;
|
||||
}else{
|
||||
if(Object.keys(S.ixp).length||ibxOpen()||(S.inbox&&S.inbox.bot)){const n=ibxOpen(),u=ibxUrgent();h+=`<div class="ibx ibxcard"><div class="nm">📬 ${tr('Peering inbox')} ${n?`<span class="cnt${u?' red':''}">${n}</span>`:''}</div><div class="meta">${S.inbox&&S.inbox.bot?tr('Large Peering Model is on it.'):u?trn('{n} session is down on its max-prefix limit.','{n} sessions are down on their max-prefix limit.',u):n?trn('{n} message waiting for an answer.','{n} messages waiting for an answer.',n):tr('Inbox zero.')}</div><div class="btns">${btn(tr('Open inbox'),'inbox',{},'sm')}</div></div>`;}
|
||||
h+=`<p class="lead">${tr("Every network on the map. Traffic share is how much of your users' traffic goes to them. Tap a connection to jump to its POP.")}</p>`;
|
||||
{const nc=conns().length;if(nc)h+=`<div class="btns" style="margin-bottom:8px">${btn(tr('All connections <small>{n}</small>',{n:nc}),'connOpen',{},'pink sm')}</div>`;}
|
||||
const where=netWhereIdx(),tl=NETS.filter(n=>n.tail),tlOn=tl.filter(n=>where(n.id).some(x=>x[2]==='ix')).length;
|
||||
const foc=UI.netFocus&&NET[UI.netFocus]?NET[UI.netFocus]:null,out=!foc&&UI.nf==='out',lostN=ntLost().length;
|
||||
h+=`<div class="btns" style="margin-bottom:8px">${btn(tr('All networks'),'netFilter',{f:'all'},!foc&&!out?'sm':'ghost sm')}${btn(tr('Out of reach without transit <small>{n}</small>',{n:lostN}),'netFilter',{f:'out'},out?'sm':'ghost sm')}</div>`;
|
||||
if(out&&!lostN)h+=`<p class="empty">${tr('Nothing: every network is reachable without transit.')}</p>`;
|
||||
for(const n of foc?[foc]:out?ntLost():NETS){if(n.tail&&!UI.tailOpen&&!foc&&!out)continue;
|
||||
h+=`<div class="row">${logo(n)}<div class="grow"><div class="nm">${esc(n.name)} <span class="meta">AS${n.asn}</span></div><div class="meta"><span class="tag ${n.type}">${TYPE_L[n.type]}</span> <span class="tag ${n.pol}">${n.pol}</span> · ${tr('{p}% of traffic',{p:(NSH[n.id]*100).toFixed(1)})}${n.price?` · ${tr('transit ${price}/Gbps',{price:(n.price*S.priceMul).toFixed(2)})}`:''}</div><div class="meta">${esc(n.blurb)}</div>${netWhere(n,where)}${(foc||out)&&!R.nt[n.id]?`<p class="why">${esc(offTransitHint(n.id))}</p>`:''}${foc||out&&!R.nt[n.id]?meetLine(n,foc?24:4):''}</div></div>`;}
|
||||
if(!foc&&!out)h+=`<div class="row"><div class="grow"><div class="nm">${tr('The long tail')} <span class="meta">${tr('{n} small networks',{n:tl.length})}</span></div><div class="meta">${tr('{p}% of traffic between them, scattered across exchanges. You peer with {n}.',{p:(tl.reduce((a,n)=>a+NSH[n.id],0)*100).toFixed(1),n:tlOn})}</div></div>${btn(UI.tailOpen?tr('Hide'):tr('Show'),'tailTog',{},'ghost sm')}</div>`;
|
||||
}
|
||||
if(h!==UI._lh){UI._lh=h;morph($('leftBody'),h);}
|
||||
}
|
||||
function renderPanel(){checkLayer();
|
||||
const P=$('panel');
|
||||
if(!S||!UI.sel){P.hidden=true;return;}
|
||||
P.hidden=false;
|
||||
const scrollEl=$('panelBody').querySelector('.scroll');const st=scrollEl?scrollEl.scrollTop:0;
|
||||
const html=UI.sel.type==='city'?cityPanel(UI.sel.id):linkPanel(UI.sel.id);if(html===UI._ph&&!P.hidden&&$('panelBody').firstChild)return;UI._ph=html;morph($('panelBody'),html);
|
||||
const ns=$('panelBody').querySelector('.scroll');if(ns)ns.scrollTop=st;
|
||||
}
|
||||
112
src/game/93-ui/50-city-panel.js
Normal file
112
src/game/93-ui/50-city-panel.js
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
function cityPanel(c){
|
||||
const C=CITY[c],p=S.pops[c],ix=ixName(c),down=p&&p.down>S.day;
|
||||
let h=`<div class="ph"><div style="min-width:0"><div class="eyebrow">${REG[C.reg]} · ${esc(siteName(c,'a'))}</div><h2>${C.name}</h2>
|
||||
<div class="facts"><span class="fact">${tr('{g} of eyeballs',{g:fmtG(eyeP(c))})}</span>${latSlow(c)?`<span class="fact bad">🐢 ${tr('{ms} ms to transit',{ms:Math.round(R.latFar[c].ms)})}</span>`:''}${regionMult(c)>1?`<span class="fact">${tr('Transit {x}× pricier',{x:regionMult(c)})}</span>`:''}${C.reg==='AS'&&!C.cn?'<span class="fact ixf">'+tr('Underserved: users grow 60% faster')+'</span>':''}${ix?`<span class="fact ixf">${tr('IX: <b>{ix}</b>',{ix:esc(ix)})}</span>`:''}${p?`<span class="fact mine">${tr('Your POP')}</span><button class="fact trb" data-act="trace" data-args='{"city":"${c}"}'>🔍 ${tr('Traceroute')}</button>`:''}${down?`<span class="fact down">DOWN</span>`:''}</div></div>
|
||||
<button class="x" data-act="closePanel" aria-label="${tr('Close')}">×</button></div>`;
|
||||
if(!p){
|
||||
h+=`<div class="scroll">${C.note?`<p class="note" style="margin-top:0">${esc(C.note)}</p>`:''}
|
||||
${C.cn?chinaSection(c):''}${C.cn&&!cnOk()?'':`<section><h3>${tr('Open a POP here')}</h3><p class="lead">${tr('A POP (point of presence) is your router in a rack here. Then connect it: lay fiber from one of your POPs, or buy transit right here.')}</p>
|
||||
${C.ru?`<p class="why">${tr('Includes the mandatory government box in your rack: {cost} + {mo}/mo. It comes with its own listener.',{cost:fmt$(RU_BOX),mo:fmt$(RU_BOX_MO)})}</p>`:''}${btn(tr('Build POP <small>{cost} + {mo}/mo</small>',{cost:fmt$(popCost(c)),mo:fmt$(POP_MO)}),'buildPop',{city:c},'pink big',S.cash<popCost(c))}
|
||||
<p class="note">${tr('Or drag from one of your routers to this city to lay fiber and build the POP in one go.')}</p></section>`}`;
|
||||
h+=offersHere(c);
|
||||
const trs=NETS.filter(n=>sellsAt(n,c));
|
||||
const fh=FABS.filter(f=>f.cities.includes(c));
|
||||
if(ix&&fh.length){if(remoteCities().includes(c))h+=ixSection(c).replace('<h3>'+tr('Internet Exchange')+'</h3>','<h3>'+tr('Remote peering at the IX')+'</h3>');
|
||||
else h+=`<section><h3>${tr('Remote peering')}</h3><p class="lead">${tr('Peer at {ix} without building a POP. Order a virtual circuit here from one of your POPs over {fabs}.',{ix:esc(ix),fabs:fh.map(f=>esc(f.name)).join(tr(' or '))})}</p>${REMOTE_WARN}${btn(tr('Order circuit anyway'),'openVxc',{to:c},'ghost sm')}</section>`;}
|
||||
h+=`<section><h3>${tr("Who's here")}</h3><div class="meta" style="font-size:12.5px;line-height:1.6">${MEGA.filter(m=>m.c===c).length?`${tr('AI and cloud campuses nearby: {list}',{list:MEGA.filter(m=>m.c===c).map(m=>`<b>${esc(m.n)}</b>`).join(', ')})}<br>`:''}${tr('Transit sellers: {list}',{list:trs.map(n=>`<b>${esc(n.name)}</b>`).join(', ')||tr('none')})}<br>${tr('Fabrics: {list}',{list:fh.map(f=>`<b>${esc(f.name)}</b>`).join(', ')||tr('none')})}<br>${ix?ixIdsIn(c).map(x=>tr('IX members on {ix}: {n}',{ix:esc(ixName(x)),n:ixMembers(x).length})).join('<br>'):tr('No IX here yet. You could found one later.')}</div></section></div>`;
|
||||
return h;
|
||||
}
|
||||
const tabs=[['cust',tr('Customers')],['up',tr('Transit')],['peer',tr('Peering')],['links',tr('Infra')]];
|
||||
h+=`<nav class="tabs">${tabs.map(([k,l])=>`<button class="${UI.tab===k?'on':''}" data-act="tab" data-args='{"t":"${k}"}'>${l}</button>`).join('')}</nav><div class="scroll">`;
|
||||
if(C.cn&&UI.tab==='cust')h+=chinaSection(c);
|
||||
const sf=sfOf(R,c),dem=R.cityDem[c]||0;
|
||||
if(down){const i=S.inc.filter(x=>x.ref===c&&POPDOWN.includes(x.type)).sort((a,b)=>b.until-a.until)[0];h+=`<section><h3 style="color:var(--bad)">${tr('This POP is down')}</h3><p class="lead">${i?esc(i.msg):''} ${tr("Customers here get nothing until it's back.")}</p>${i&&i.cost?btn(`${i.fix} ${fmt$(i.cost)}`,'fixInc',{id:i.id},'red'):''}</section>`;}
|
||||
if(UI.tab==='cust'){
|
||||
{const nl=R.nodeLoad[c]||0,nc=R.nodeCap[c]||1;if(nl>=nc*0.95)h+=`<section><h3 style="color:var(--bad)">${tr('Router maxed out')}</h3><p class="lead">${tr('Your routers here are forwarding {load} of {cap}. Traffic is being dropped. Upgrade or add a router in the Infra tab.',{load:fmtG(nl),cap:fmtG(nc)})}</p>${btn(tr('Open Infra'),'tab',{t:'links'},'pink sm')}</section>`;}
|
||||
h+=`<section><h3>${tr('Home broadband')}</h3>`;
|
||||
if(!p.bb){const s=bbStart(c);h+=`<p class="lead">${tr('Sell internet to homes here. Starts around {start} and grows toward {max} while service is good. Pays {rate} per Gbps served, every month.',{start:fmtG(s),max:fmtG(eyeP(c)),rate:fmt$(EYE_RATE*(C.arpu||1))})}${C.au?` ${scnRule('levy')?tr('It runs on your own fibre, so the Nearly Broadband Network gets nothing. The government still takes a {pct} levy.',{pct:pct(AU_LEVY)}):tr('The Nearly Broadband Network keeps {pct} of it for the last mile.',{pct:pct(AU_WHOLESALE)})}`:''}</p>${btn(tr('Launch broadband <small>{cost}</small>',{cost:fmt$(bbCost(c))}),'launchBB',{city:c},'pink big',S.cash<bbCost(c))}`;}
|
||||
else{const eye=R.cityEye[c]||0;
|
||||
h+=`<div class="kv"><span>${tr('Eyeball demand')}</span><b>${tr('{a} of {b}',{a:fmtG(eye),b:fmtG(eyeP(c))})}</b></div><div class="bar me"><i style="width:${Math.min(100,eye/eyeP(c)*100)}%"></i></div>
|
||||
<div class="kv"><span>${tr('Served in {city}',{city:C.name})}</span><b style="color:${sf<0.9?'var(--bad)':'var(--eye)'}">${pct(sf)}</b></div><div class="bar ${sf<0.9?'bad':''}"><i style="width:${sf*100}%"></i></div>
|
||||
<div class="kv"><span>${tr('Revenue')}</span><b>${tr('{price}/mo',{price:fmt$(eye*sf*EYE_RATE*(C.arpu||1))})}</b></div>
|
||||
<div class="kv"><span>${tr('Network-wide peering ratio')}</span><b>${pct(R.peerShare||0)}</b></div><p class="note">${tr('More traffic over peering, PNIs and caches means lower latency, and happier users grow faster.')}</p>
|
||||
${sf<0.9?`<p class="why">${tr('Customers are unhappy and leaving. Add upstream capacity, peering, or a bigger link.')}</p>`:''}
|
||||
<div class="btns">${p.boost>S.day?`<span class="tag st on">${tr('Ad campaign: {n}d left',{n:p.boost-S.day})}</span>`:btn(tr('Run ad campaign <small>$8k · 2× growth 30d</small>'),'ad',{city:c},'',S.cash<8000)}</div>`;}
|
||||
h+=`</section><section><h3>${tr('Business customers')}</h3>`;
|
||||
const bz=S.biz.filter(b=>bCities(b).includes(c));
|
||||
if(!bz.length)h+=`<p class="empty">${tr('No businesses yet. Offers pop up as $ bubbles on the map.')}</p>`;
|
||||
for(const b of bz)h+=`<div class="row"><div class="grow"><div class="nm">${esc(b.name)}</div><div class="meta">${esc(BIZ_T[b.type].l)}${b.city2?` ${CITY[b.city].name} ⇄ ${CITY[b.city2].name}`:''} · ${bTerms(b)}${BIZ_T[b.type].l2?` · ${b.sites?tr('carrying {g} per site',{g:fmtG(R.l2[b.id]||0)}):tr('carrying {g}',{g:fmtG(R.l2[b.id]||0)})}`:''}${BIZ_T[b.type].fiber&&!fiberOk(b)?' · <b style="color:var(--bad)">'+tr('fiber is down')+'</b>':''}${BIZ_T[b.type].event&&eventLive(b)?` · <b>${tr('serving {v}',{v:pct(sfOf(R,b.city))})}</b>`:''}${b.type==='scrub'&&!hasScrub()?' · <b style="color:var(--bad)">'+tr('needs a scrubbing center')+'</b>':''}${S.day-(b.since||0)<15?` · <b>${tr('provisioning, {n}d grace',{n:15-(S.day-(b.since||0))})}</b>`:''}</div>${reqList(b)}${BIZ_T[b.type].l2?routeCtl(b):''}<div class="bar ${b.mood<30?'bad':b.mood<65?'warn':''}"><i style="width:${b.mood}%"></i></div><div class="meta">${tr('Happiness {p}%',{p:Math.round(b.mood)})}</div></div>${btn(UI.confirm===b.id?tr('Really drop?'):tr('Drop'),'dropBiz',{id:b.id},'ghost sm')}</div>`;
|
||||
h+=`</section>`+offersHere(c);
|
||||
}else if(UI.tab==='up'){
|
||||
h+=portNote(c)+latNote(c);
|
||||
h+=`<section><h3>${tr('IP transit')}</h3><p class="lead">${tr('Pay a bigger network per Gbps and it carries your traffic to the whole internet. Billed on the 95th percentile of the last 30 days, with a 20% commit and a port fee. Spikes like DDoS raise your bill.')}</p>`;
|
||||
const prov=NETS.filter(n=>sellsAt(n,c)).sort((a,b)=>a.price-b.price);
|
||||
if(!prov.length)h+=`<p class="empty">${tr('Nobody sells transit here. Haul your traffic over fiber to a city that has it.')}</p>`;
|
||||
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+=`<div class="row">${logo(n)}<div class="grow"><div class="nm">${esc(n.name)} <span class="tag ${n.type}">${TYPE_L[n.type]}</span></div><div class="meta">${tr('${price} per Gbps / month · billed on 95th percentile',{price:pr.toFixed(2)})}</div>`;
|
||||
if(t){const u=R.useT[t.id]||0,cap=lagCap(PORT[t.tier].g,t.n),tdown=t.down>S.day;
|
||||
h+=`<div class="kv"><span>${lagName(t.tier,t.n)}${tdown?' · <b style="color:var(--bad)">'+tr('OUTAGE')+'</b>':''}</span><b>${fmtG(u)}</b></div><div class="bar ${barCls(u/cap)}"><i style="width:${u/cap*100}%"></i></div>${prefCtl('t',t.id,t.pref)}${siteCtl('t',t.id,c,t.site)}${n.premium&&c==='hkg'?`<div class="btns">${btn(t.premium?tr('CN-Too premium on ✓'):tr('Switch to CN-Too premium <small>{x}× price · ~3% loss into China</small>',{x:n.premium}),'togglePrem',{id:t.id},t.premium?'green sm':'sm')}</div>`:''}${(()=>{const top=transitTop([t.id],4);return top.length?`<div class="ttop"><div class="meta"><b>${tr('Top destinations on this port')}</b></div>${top.map(([id,v])=>`<div class="meta">${esc(NET[id].name)} · ${fmtG(v)} · <i>${esc(offTransitHint(id,c))}</i></div>`).join('')}</div>`:'';})()}<div class="meta">${tr('95th pct {p95} · commit {commit} · bill {bill}/mo',{p95: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))})}</div>
|
||||
<div class="btns">${PORT.map((P2,i)=>i>t.tier&&portShown(i)?btn((t.n||1)>1?tr('Upgrade all to {port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(P2.setup*(t.n||1)),mo:fmt$(P2.tmo*(t.n||1))}):tr('Upgrade {port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(P2.setup*(t.n||1)),mo:fmt$(P2.tmo*(t.n||1))}),'buyTransit',{city:c,net:n.id,tier:i},'sm',S.cash<P2.setup*(t.n||1)||!portOk(c,i)):'').join('')}${(t.n||1)<LAG_MAX?btn(tr('+ LAG member <small>{cost} + {mo}/mo</small>',{cost:fmt$(PORT[t.tier].setup),mo:fmt$(PORT[t.tier].tmo)}),'lagT',{id:t.id,d:1},'sm',S.cash<PORT[t.tier].setup||!portOk(c,t.tier)):''}${(t.n||1)>1?btn(tr('− member'),'lagT',{id:t.id,d:-1},'ghost sm'):''}${btn(t.clean?tr('Clean-pipe on ✓'):tr('+ Clean-pipe <small>{mo}/mo · scrubs DDoS upstream</small>',{mo:fmt$(cleanMo(t))}),'cleanPipe',{id:t.id},t.clean?'green sm':'sm')}${btn(UI.confirm===t.id?tr('Really cancel?'):tr('Cancel'),'cancelTransit',{id:t.id},'ghost sm')}</div>`;}
|
||||
else h+=`<div class="btns">${PORT.map((P2,i)=>portShown(i)?btn(tr('{port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(P2.setup),mo:fmt$(P2.tmo)}),'buyTransit',{city:c,net:n.id,tier:i},'sm',S.cash<P2.setup||!portOk(c,i)):'').join('')}</div>`;
|
||||
h+=`</div></div>`;}
|
||||
h+=`</section>`;
|
||||
}else if(UI.tab==='peer'){
|
||||
h+=portNote(c);
|
||||
h+=ixSection(c);
|
||||
h+=`<section><h3>${tr('Private interconnects (PNI)')}</h3><p class="lead">${tr('A dedicated cross-connect to one network in {dc}. Needs more traffic than IX peering, but has its own capacity.',{dc:esc(siteName(c,'a'))})}</p>`;
|
||||
const here=NETS.filter(n=>n.pops.includes(c));
|
||||
for(const n of here){const pn=S.pni.find(x=>x.city===c&&x.net===n.id),chk=peerOk(n.id,'pni',c);
|
||||
h+=`<div class="row">${logo(n)}<div class="grow"><div class="nm">${esc(n.name)} <span class="tag ${n.pol}">${n.pol}</span></div>`;
|
||||
if(pn&&!pniOn(pn))h+=pniWait(pn,c);
|
||||
else if(pn){const u=R.usePni[pn.id]||0,cap=lagCap(pniG(pn),pn.n);h+=`<div class="kv"><span>${(pn.n||1)>1?`${pn.n}×${pniPN(pn)} LAG`:pniPN(pn)} PNI</span><b>${fmtG(u)}</b></div>${pn.up?`<div class="meta">${tr('Augment on order: {port}, about {n} days to go.',{port:(pn.up.n>1?pn.up.n+'×':'')+(pn.up.g1?'1G':PORT[pn.up.tier].n),n:Math.max(0,pn.up.ready-S.day)})} ${btn(tr('Chase it'),'pniChase',{id:pn.id},'ghost sm')}</div>`:''}<div class="bar ${barCls(u/cap)}"><i style="width:${u/cap*100}%"></i></div>${prefCtl('p',pn.id,pn.pref)}${siteCtl('p',pn.id,c,pn.site)}<div class="btns">${PORT.map((P2,i)=>!pn.up&&!msfNope(n.id,c)&&(i>pn.tier||(pn.g1&&i===0))?btn((a=>(pn.n||1)>1?tr('Upgrade all to {port} <small>{cost} + {mo}/mo</small>',a):tr('Upgrade {port} <small>{cost} + {mo}/mo</small>',a))({port:P2.n,cost:fmt$((1500+P2.setup/2)*(pn.n||1)),mo:fmt$(P2.pni*(pn.n||1))}),'pni',{city:c,net:n.id,tier:i},'sm',!portOk(c,i)||S.cash<(1500+P2.setup/2)*(pn.n||1)):'').join('')}${(pn.n||1)<LAG_MAX&&!pn.up&&!msfNope(n.id,c)?btn(tr('+ LAG member <small>{cost} + {mo}/mo</small>',{cost:fmt$(1500+PORT[pn.tier].setup/2),mo:fmt$(PORT[pn.tier].pni)}),'lagP',{id:pn.id,d:1},'sm',S.cash<1500+PORT[pn.tier].setup/2):''}${(pn.n||1)>1?btn(tr('− member'),'lagP',{id:pn.id,d:-1},'ghost sm'):''}${NET[n.id].cn?btn(pn.sacrif?tr('Sacrificial choke ✓'):tr('Make sacrificial <small>contains floods · ½ capacity</small>'),'sacrif',{id:pn.id},pn.sacrif?'green sm':'sm'):''}${btn(UI.confirm===pn.id?tr('Really remove?'):tr('Remove'),'cancelPni',{id:pn.id},'ghost sm')}</div>`;}
|
||||
else{h+=chk.ok?`<div class="btns">${pniG1(n.id)?btn(tr('{port} <small>{cost} + {mo}/mo</small>',{port:'1G',cost:fmt$(PNI_G1_COST),mo:fmt$(Math.round(PORT[0].pni/2))}),'pni',{city:c,net:n.id,tier:-1},'sm',S.cash<PNI_G1_COST||!portOk(c,0)):''}${PORT.map((P2,i)=>portShown(i)&&i>=pniMin(n.id)?btn(tr('{port} <small>{cost} + {mo}/mo</small>',{port:P2.n,cost:fmt$(1500+P2.setup/2),mo:fmt$(P2.pni)}),'pni',{city:c,net:n.id,tier:i},'sm',S.cash<1500+P2.setup/2||!portOk(c,i)):'').join('')}</div><div class="meta">${pniEta(n.id)}${pniMin(n.id)?' · '+tr('no 10G: {net} starts at 100G',{net:esc(n.name)}):pniG1(n.id)?' · '+tr('sells PNIs down to 1G'):''}</div>${chk.fee?`<div class="meta">${tr('Paid peering: {price}/mo on top',{price:fmt$(chk.fee)})}</div>`:''}`:`<div class="why">${esc(chk.why)}</div>`;}
|
||||
h+=`</div></div>`;}
|
||||
h+=`</section><section><h3>${tr('Embedded caches')}</h3><p class="lead">${tr('CDNs put free cache servers inside your POP. Most of their traffic is then served right here, with no transit and no IX port.')}</p>`;
|
||||
for(const n of NETS.filter(n=>n.cache)){const have=S.caches.filter(x=>x.city===c&&x.net===n.id),dem=R.demTo[n.id]||0,ok=dem>=n.cache.min;
|
||||
h+=`<div class="row">${logo(n)}<div class="grow"><div class="nm">${esc(n.cache.name)}</div><div class="meta">${tr('from {net}',{net:esc(n.name)})} · ${have.length?`${trn('{n} box','{n} boxes',have.length)} · ${tr('serving {v}',{v:fmtG(have.reduce((a,x)=>a+(R.useCache[x.id]||0),0))})}`:tr('100G per box')}</div>${!ok?`<div class="why">${tr('Needs {min} Gbps of traffic to {net} (now {now})',{min:n.cache.min,net:esc(n.name),now:dem.toFixed(1)})}</div>`:''}</div>
|
||||
${have.length?btn(tr('Remove'),'rmCache',{id:(have.find(x=>x.site==='b')||have[0]).id},'ghost sm'):''}${btn(have.length?tr('+ box'):tr('Request'),'cache',{city:c,net:n.id},'sm',!ok)}</div>${S.pops[c].site2&&have.length?(()=>{const nb=have.filter(x=>x.site==='b').length,na=have.length-nb;return `<div class="seg site"><span class="meta">${tr('Boxes: {a} in A · {b} in B',{a:na,b:nb})}</span>${na?btn(tr('Move one to B'),'cacheSite',{city:c,net:n.id,s:'b'},'ghost sm'):''}${nb?btn(tr('Move one to A'),'cacheSite',{city:c,net:n.id,s:'a'},'ghost sm'):''}</div>`;})():''}`;}
|
||||
h+=`</section>`;
|
||||
}else{
|
||||
const ls=S.links.filter(l=>l.a===c||l.b===c);
|
||||
const rt=p.routers||1,g=p.rgen||0,G=RG[g],nl=R.nodeLoad[c]||0,nc=R.nodeCap[c]||nodeCap(c),Ni=g===mainRG(G.cls)?mainRG(G.cls+1):-1,N=Ni>=0?RG[Ni]:null,pu=portsUsed(c),pm=portsMax(c);
|
||||
h+=`<section><h3>${tr('Routers')}</h3><p class="lead">${tr('The model sets your fastest interface and how much this POP can forward. More routers add capacity and survive crashes.')}</p>
|
||||
<div class="row"><span class="logo" style="--c:${G.badge?'#2C7A7B':'#FF4F9A'}">${G.badge||'R'+(G.cls+1)}</span><div class="grow"><div class="nm">${rt} × ${esc(G.n)}</div><div class="meta">${tr('Up to {pn} interfaces · {ports} ports and {cap} per router',{pn:G.pn,ports:G.ports,cap:fmtG(G.cap)})} · ${esc(G.blurb)}</div></div></div>
|
||||
<div class="kv"><span>${tr('Router ports')}</span><b>${tr('{used} / {max} in use',{used:fmtPorts(pu),max:pm})}</b></div><div class="bar ${barCls(pu/pm)}"><i style="width:${Math.min(100,pu/pm*100)}%"></i></div>${pu>=pm?`<p class="why">${tr('Every port is taken. Add a router or swap to a model with more ports before you plug in anything new.')}</p>`:''}
|
||||
<div class="kv"><span>${tr('Forwarding chip')}</span><b>${esc(G.chip)}</b></div><div class="kv"><span>${tr('Boot time')}</span><b>${slowBoot(c)?`<span style="color:var(--bad)">${tr('~{n} min · a slow one',{n:bootMin(c)})}</span>`:tr('~{n} min',{n:bootMin(c)})}</b></div>${slowBoot(c)?`<p class="note">${tr('This chassis takes forever to boot: crashes last longer, and swapping the only router here takes 3 days. A second router hides it.')}</p>`:''}
|
||||
<div class="kv"><span>${tr('Forwarding load')}</span><b>${fmtG(nl)} / ${fmtG(nc)}</b></div><div class="bar ${barCls(nl/nc)}"><i style="width:${Math.min(100,nl/nc*100)}%"></i></div>
|
||||
${nl>=nc*0.95?`<p class="why">${tr('Maxed out. Traffic here is being dropped.')}</p>`:''}
|
||||
<div class="btns">${N?btn(N.lvl>lvl()?tr('{model} <small>level {lv}</small>',{model:esc(N.n),lv:N.lvl}):tr('Upgrade to {model} <small>{cost} + {mo}/mo</small>',{model:esc(N.n),cost:fmt$(swapCost(c,Ni)),mo:fmt$(N.mo*rt)}),'upRouter',{city:c,g:Ni},'pink',N.lvl>lvl()||S.cash<swapCost(c,Ni)||p.rupDay===S.day):''}${btn(UI.models?tr('Hide other models'):tr('Other models'),'models',{},'ghost sm')}${rt<RMAX?btn(tr('Add router <small>{cost} + {mo}/mo</small>',{cost:fmt$(routerCost(g)),mo:fmt$(ROUTER_MO+G.mo)}),'addRouter',{city:c},'',S.cash<routerCost(g)):''}${rt>1?btn(tr('Remove one'),'rmRouter',{city:c},'ghost sm'):''}</div>
|
||||
${UI.models?routerModels(c):''}
|
||||
${N||UI.models?`<p class="note">${(p.rgen||0)>0?tr('Prices include {p} back for the old routers on eBuy.',{p:fmt$(tradeIn(p.rgen||0,rt))})+' ':''}${p.rupDay===S.day?tr('New routers went in today. The next swap can wait until tomorrow.')+' ':''}${rt>1?tr('Rolling upgrade: one router at a time, no downtime.'):tr('With one router, the upgrade needs a maintenance window: this POP goes dark for a day.')}</p>`:''}
|
||||
<p class="note">${rt>=2?tr('A crash here only costs one router’s capacity for a few days.'):tr('One router is a single point of failure.')}</p></section>
|
||||
<section><h3>${tr('Metro diversity')}</h3>${p.site2?(()=>{const up=s=>[...S.transit.filter(t=>t.city===c&&onSite(t.site,s)).map(t=>tr('{net} transit',{net:NET[t.net].name})+(t.site==='ab'?' '+tr('(split)'):'')),...S.pni.filter(x=>x.city===c&&onSite(x.site,s)).map(x=>'PNI '+NET[x.net].name+(x.site==='ab'?' '+tr('(split)'):'')),...ixIdsIn(c).filter(x=>S.ixp[x]!==undefined&&onSite((S.ixSite||{})[x],s)).map(x=>(S.myIx[x]?tr('{ix} switch',{ix:ixName(x)}):tr('{port} port',{port:ixName(x)}))+((S.ixSite||{})[x]==='ab'?' '+tr('(split)'):'')),...S.caches.filter(x=>x.city===c&&(x.site==='b'?'b':'a')===s).map(x=>NET[x.net].cache.name)];
|
||||
const row=s=>{const dn=siteDown(c,s),u=up(s);return `<div class="row"><span class="logo" style="--c:${s==='a'?'#FF4F9A':'#7B61FF'}">${s.toUpperCase()}</span><div class="grow"><div class="nm">${esc(siteName(c,s))}${dn?' <span class="tag restrictive">DOWN</span>':''}</div><div class="meta">${u.length?esc(u.join(', ')):tr('Nothing plugged in here yet')}</div></div></div>`;};
|
||||
return `<p class="lead">${tr('Two buildings joined by your own metro ring. A power cut or cleaner in one leaves the other running at half capacity. Uplinks only work while their site is up, unless you split them: choose <b>Both</b> on a port to put LAG members in each building.')}</p>${row('a')}${row('b')}${up('b').length&&up('a').length?'':`<p class="why">${tr('Everything is in one building. Move some uplinks to the other site from the Transit and Peering tabs.')}</p>`}<div class="kv"><span>${tr('Second site and metro ring')}</span><b>${tr('{price}/mo',{price:fmt$(SITE2_MO)})}</b></div><div class="btns">${btn(UI.confirm==='site'+c?tr('Really close it?'):tr('Close site B'),'rmSite',{city:c},'ghost sm')}</div>`;})()
|
||||
:`<p class="lead">${tr('Right now {city} is one building. A power cut, an A/C failure or a cleaner with a vacuum takes the whole city dark, and a second router does not help with that. A second data center across town, joined by your own metro ring, keeps half the POP up.',{city:esc(CITY[c].name)})}</p><div class="btns">${btn(tr('Add a second site <small>{cost} + {mo}/mo</small>',{cost:fmt$(SITE2_COST),mo:fmt$(SITE2_MO)}),'addSite',{city:c},'pink',S.cash<SITE2_COST)}</div>`}</section>
|
||||
<section><h3>${tr('Power')}</h3><div class="kv"><span>${tr('Backup generator')}</span><b>${p.gen?tr('Installed'):tr('None')}</b></div>${p.gen?'<p class="note">'+tr('Power cuts are covered.')+'</p>':`<div class="btns">${btn(tr('Install generator <small>{cost} + {mo}/mo</small>',{cost:fmt$(GEN_COST),mo:fmt$(GEN_MO)}),'addGen',{city:c},'',S.cash<GEN_COST)}</div>`}</section>`;
|
||||
h+=`<section><h3>${tr('DDoS scrubbing center')}</h3>`;
|
||||
{const here=S.scrubs.find(x=>x.city===c),others=S.scrubs.filter(x=>x.city!==c);
|
||||
if(here){const T=SCRUB_TIERS[here.tier||0];
|
||||
h+=`<p class="lead">${tr('Cleans attacks for your whole network, up to its clean-bandwidth capacity, and unlocks DDoS protection contracts. Clean traffic returns over GRE, which can re-open the MSS black hole.')}</p>
|
||||
<div class="kv"><span>${tr('Capacity')}</span><b>${T.n} · ${fmtG(T.g)}</b></div>
|
||||
<div class="kv"><span>${tr('Mode')}</span><b>${S.scrubMode==='ondemand'?tr('On-demand (engages in {n}d)',{n:SCRUB_DELAY}):tr('Always-on')} · ${fmt$(scrubMo1(here))}/mo</b></div>
|
||||
<div class="btns">${btn(S.scrubMode==='ondemand'?tr('Switch to always-on'):tr('Switch to on-demand <small>cheaper</small>'),'scrubMode',{},'sm')}${SCRUB_TIERS.map((X,i)=>i>(here.tier||0)?btn(tr('Upgrade to {tier} <small>{cost}</small>',{tier:X.n,cost:fmt$(Math.round(X.cost*0.6))}),'scrubUp',{city:c,tier:i},'sm',(lvl()||1)<X.lvl||S.cash<X.cost*0.6):'').join('')}${btn(UI.confirm==='scrub:'+c?tr('Really shut it down?'):tr('Shut down'),'rmScrub',{city:c},'ghost sm')}</div>`;}
|
||||
else{h+=`<p class="lead">${others.length?tr('Attacks go to your nearest scrubbing center. From here that is {city}, {km} km away: the flood rides your backbone there and back, which adds latency, and whatever your links cannot carry is not scrubbed. A center here cleans attacks on the spot.',{city:CITY[others.slice().sort((a,b)=>kmBetween(c,a.city)-kmBetween(c,b.city))[0].city].name,km:Math.round(kmBetween(c,others.slice().sort((a,b)=>kmBetween(c,a.city)-kmBetween(c,b.city))[0].city)).toLocaleString()}):tr('Cleans DDoS attacks for your whole network, up to its clean-bandwidth capacity, and unlocks DDoS protection contracts for businesses.')}</p><div class="btns">${SCRUB_TIERS.map((X,i)=>btn(tr('Build {tier} <small>{cost} + {mo}/mo</small>',{tier:X.n,cost:fmt$(X.cost),mo:fmt$(X.mo)}),'buildScrub',{city:c,tier:i},i===0?'':'sm',(lvl()||1)<X.lvl||S.cash<X.cost)).join('')}</div>`;}}
|
||||
h+=`</section>`;
|
||||
const fabs=FABS.filter(f=>f.cities.includes(c));
|
||||
if(fabs.length){h+=`<section><h3>${tr('Interconnection fabrics (NNI)')}</h3><p class="lead">${tr('Buy a port on a fabric, then order virtual circuits to your other POPs or to a remote IX. Fast and flexible, but you share their fabric.')}</p>`;
|
||||
for(const f of fabs){const pt=nniPort(c,f.id),used=nniUsed(c,f.id);
|
||||
h+=`<div class="row"><span class="logo" style="--c:${f.col}">${initials(f)}</span><div class="grow"><div class="nm">${esc(f.name)}</div><div class="meta">${esc(f.blurb)}</div>`;
|
||||
if(pt){const cap=NNI[pt.tier].g;h+=`<div class="kv"><span>${tr('{port} port · {price}/mo',{port:NNI[pt.tier].n,price:fmt$(NNI[pt.tier].mo)})}</span><b>${tr('{g} of circuits',{g:fmtG(used)})}</b></div><div class="bar ${barCls(used/cap)}"><i style="width:${used/cap*100}%"></i></div><div class="btns">${btn(tr('New circuit'),'openVxc',{from:c,prov:f.id},'pink sm')}${pt.tier<1?btn(tr('Upgrade {port} <small>{price}/mo</small>',{port:NNI[1].n,price:fmt$(NNI[1].mo)}),'buyNni',{city:c,prov:f.id,tier:1},'sm'):''}${btn(tr('Remove port'),'rmNni',{city:c,prov:f.id},'ghost sm')}</div>`;}
|
||||
else h+=`<div class="btns">${NNI.map((N,i)=>btn(tr('{port} port <small>{price}/mo</small>',{port:N.n,price:fmt$(N.mo)}),'buyNni',{city:c,prov:f.id,tier:i},'sm',S.cash<N.mo)).join('')}</div>`;
|
||||
h+=`</div></div>`;}
|
||||
h+=`</section>`;}
|
||||
h+=`<section><h3>${tr('Fiber from {city}',{city:C.name})}</h3><p class="lead">${tr("Drag from this router to any city on the map to lay a new link. Two paths to every POP means a backhoe can't take you offline.")}</p>`;
|
||||
if(!ls.length)h+=`<p class="empty">${tr('No links yet.')}</p>`;
|
||||
for(const l of ls){const o=l.a===c?l.b:l.a,u=capOf(l)?(R.load[l.id]||0)/capOf(l):0,cut=linkDown(l);
|
||||
h+=`<div class="row"><div class="grow"><div class="nm">→ ${CITY[o].name}${l.mult>1?' · '+tr('diverse'):''} ${cut?'<span class="tag restrictive">'+tr('CUT')+'</span>':''}</div><div class="meta">${capName(l)} · ${l.km.toLocaleString()} km ${l.kind==='vxc'?tr('virtual circuit via {fab}',{fab:esc(FAB[l.prov].name)}):l.kind==='df'?(l.own?(l.sub&&l.cname?tr('your own subsea cable {name}',{name:l.cname}):tr('own dark fiber')):tr('dark fiber IRU'))+(l.ready>S.day?` · ${tr('ready in {n}d',{n:l.ready-S.day})}`:''):l.sub?tr('subsea'):tr('terrestrial')} · ${tr('{price}/mo',{price:fmt$(l.mo)})}</div><div class="bar ${barCls(u)}"><i style="width:${u*100}%"></i></div></div>${btn(tr('Open'),'selLink',{id:l.id},'ghost sm')}</div>`;}
|
||||
h+=`</section>`;
|
||||
if(Object.keys(S.pops).length>1)h+=`<section><h3>${tr('Decommission')}</h3><p class="lead">${tr('Shut this POP down: its links, ports and caches go with it, and every customer that depends on it is let go, with an early-termination penalty.')}</p><div class="btns">${btn(tr('Decommission {city}…',{city:C.name}),'decomOpen',{city:c},'ghost sm')}${btn(tr('Decommission several POPs…'),'decomOpen',{},'ghost sm')}</div></section>`;
|
||||
}
|
||||
return h+`</div>`;
|
||||
}
|
||||
22
src/game/93-ui/60-decommission.js
Normal file
22
src/game/93-ui/60-decommission.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* Decommissioning POPs. Customers that touch a decommissioned city, or ride a removed link, are let go
|
||||
with an early-termination penalty of three months of their contract. */
|
||||
const DECOM_MONTHS=3;
|
||||
function decomImpact(cities){const set=new Set(cities),links=S.links.filter(l=>set.has(l.a)||set.has(l.b)),lids=new Set(links.map(l=>l.id));
|
||||
const biz=S.biz.filter(b=>bCities(b).some(c=>set.has(c))||(b.link&&lids.has(b.link)));
|
||||
const pen=b=>Math.max(2000,Math.round(b.fee?b.fee*0.5:b.bw*b.rate*DECOM_MONTHS));
|
||||
return {links,biz,pen,fee:biz.reduce((a,b)=>a+pen(b),0),eye:cities.reduce((a,c)=>a+(R.cityEye[c]||0),0)};}
|
||||
function decomModal(){const sel=[...(UI.decom||[])],im=decomImpact(sel),all=Object.keys(S.pops),left=all.length-sel.length;
|
||||
const rows=all.map(c=>`<label class="row" style="cursor:pointer"><input type="checkbox" data-act="decomToggle" data-args='${esc(JSON.stringify({city:c}))}' ${sel.includes(c)?'checked':''}><div class="grow"><div class="nm">${esc(CITY[c].name)}${c===S.home?` <span class="tag st">${tr('home')}</span>`:''}</div><div class="meta">${trn('{n} link','{n} links',S.links.filter(l=>l.a===c||l.b===c).length)} · ${trn('{n} customer','{n} customers',S.biz.filter(b=>bCities(b).includes(c)).length)}</div></div></label>`).join('');
|
||||
openModal(`<div style="display:flex;align-items:center"><h2 style="font-size:24px">${tr('Decommission POPs')}</h2><button class="x" data-act="closeModal" aria-label="${tr('Close')}">×</button></div>
|
||||
<p class="lead" style="margin-top:6px">${tr('Pick the POPs to shut down. Everything in them goes: routers, ports, caches, exchange ports and every link that touches them.')}</p>${rows}
|
||||
${sel.length?`<div class="kv"><span>${tr('Links removed')}</span><b>${im.links.length}</b></div><div class="kv"><span>${tr('Eyeballs you stop serving')}</span><b>${fmtG(im.eye)}</b></div><div class="kv"><span>${trn('{n} customer let go','{n} customers let go',im.biz.length)}</span><b style="color:var(--bad)">${fmt$(im.fee)}</b></div>${im.biz.length?`<p class="meta">${im.biz.map(b=>esc(b.name)+' '+fmt$(im.pen(b))).join(' · ')}</p>`:''}`:''}
|
||||
${left<1?`<p class="why">${tr('Keep at least one POP.')}</p>`:''}
|
||||
<div class="btns" style="margin-top:10px">${btn(sel.length?trn('Decommission {n} POP · pay {fee}','Decommission {n} POPs · pay {fee}',sel.length,{fee:fmt$(im.fee)}):tr('Pick a POP'),'decomGo',{},'red',!sel.length||left<1)}${btn(tr('Keep them'),'closeModal',{},'ghost')}</div>`);}
|
||||
function decommission(cities){const set=new Set(cities),im=decomImpact(cities),lids=new Set(im.links.map(l=>l.id)),bids=new Set(im.biz.map(b=>b.id));
|
||||
S.links=S.links.filter(l=>!lids.has(l.id));S.biz=S.biz.filter(b=>!bids.has(b.id));S.offers=S.offers.filter(o=>!bCities(o).some(c=>set.has(c)));
|
||||
S.transit=S.transit.filter(t=>!set.has(t.city));S.pni=S.pni.filter(x=>!set.has(x.city));S.caches=S.caches.filter(x=>!set.has(x.city));S.nni=(S.nni||[]).filter(x=>!set.has(x.city));
|
||||
for(const c of cities){for(const x of ixIdsIn(c)){delete S.ixp[x];delete S.rs[x];if(S.ixn)delete S.ixn[x];if(S.ixSite)delete S.ixSite[x];for(const k in S.peers)if(k.endsWith('@'+x))delete S.peers[k];}delete S.myIx[c];S.scrubs=S.scrubs.filter(x=>x.city!==c);delete S.pops[c];}
|
||||
const rem=remoteCities();for(const x in S.ixp){const c=ixCity(x);if(!S.pops[c]&&!rem.includes(c)){delete S.ixp[x];delete S.rs[x];for(const k in S.peers)if(k.endsWith('@'+x))delete S.peers[k];}}
|
||||
if(set.has(S.home))S.home=Object.keys(S.pops)[0];
|
||||
purgeInc();S.cash-=im.fee;S.stats.decom=(S.stats.decom||0)+cities.length;
|
||||
toast(trn('<b>{n} POP decommissioned.</b><br>{fee} in early-termination penalties to {m} customers.','<b>{n} POPs decommissioned.</b><br>{fee} in early-termination penalties to {m} customers.',cities.length,{fee:fmt$(im.fee),m:im.biz.length}),'bad');}
|
||||
139
src/game/93-ui/70-link-panels.js
Normal file
139
src/game/93-ui/70-link-panels.js
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
const portMo=v=>v?tr('{price}/mo',{price:fmt$(v)}):tr('free');
|
||||
function ixSection(c){const ids=ixIdsIn(c);if(ids.length<2)return ixBlock(c,false);
|
||||
let h=`<section><h3>${tr('Internet Exchanges')}</h3><p class="lead">${tr('{n} exchanges compete in {city}. Members overlap, but not completely, and the challengers undercut the incumbent. Small networks often sit on just one of them.',{n:ids.length,city:esc(CITY[c].name)})}</p></section>`;
|
||||
for(const x of ids)h+=ixBlock(x,true);return h;}
|
||||
function ixBlock(c,multi){const city=ixCity(c),C=CITY[city],ix=ixName(c),X=XIXM[c];let h='';
|
||||
h+=`<section><h3>${multi?esc(ix)+(X?' <span class="tag st">'+tr('challenger')+'</span>':' <span class="tag st">'+tr('incumbent')+'</span>'):tr('Internet Exchange')}</h3>`;
|
||||
if(!ix&&C.cn){h+=`<p class="lead">${tr('Running an exchange in mainland China takes a different license entirely. Peer with Chinese networks over PNIs, or meet them in Hong Kong.')}</p>`;}
|
||||
else if(!ix){h+=`<p class="lead">${tr("There's no IX in {city} yet. Found one: networks join over time, pay you for ports, and peer with you for free.",{city:C.name})}</p>${S.pops[city]?btn(tr('Found your own IX <small>{cost} + {mo}/mo</small>',{cost:fmt$(MYIX_COST),mo:fmt$(MYIX_MO)}),'foundIx',{city:c},'pink',S.cash<MYIX_COST):'<p class="note">'+tr('Build a POP here first.')+'</p>'}`;}
|
||||
else if(S.ixp[c]===undefined){h+=`<p class="lead">${tr('{ix} is a shared switch. One port lets you peer with every member for free. Members: {list}.',{ix:esc(ix),list:(()=>{const m=ixMembers(c),big=m.filter(id=>!NET[id].tail),t=m.length-big.length;return (big.map(id=>esc(NET[id].name)).join(', ')||tr('nobody yet'))+(t?trn(', plus {n} small network',', plus {n} small networks',t):'');})()})}</p>${S.pops[city]?'':REMOTE_WARN}${X?`<p class="note">${esc(X.blurb)} ${X.freeTo!==undefined?tr('Ports up to {port} are free.',{port:PORT[X.freeTo].n}):tr('Ports at {p}% of the usual price.',{p:Math.round(ixMul(c)*100)})}</p>`:''}${CITY[city].ixCheap?`<p class="note">${tr('<b>Run by a nonprofit.</b> Public prices at a fraction of what other exchanges charge, and almost everyone is here.')}</p>`:''}${isDk(c)?`<p class="note">${tr('<b>Run by DE-KICKS Group.</b> No public price list. Ask sales for a personalised quote and bring your haggling face.')}</p>`:''}<div class="btns">${PORT.map((P2,i)=>btn(isDk(c)?tr('{port} port <small>Price on request ☎</small>',{port:P2.n}):tr('{port} port <small>{price}</small>',{port:P2.n,price:portMo(ixPortMo(c,i))}),'buyIx',{city:c,tier:i},'',(!isDk(c)&&S.cash<ixPortMo(c,i))||(!!S.pops[city]&&!portOk(city,i))||(!S.pops[city]&&i>1))).join('')}</div>`;}
|
||||
else{const mine=!!S.myIx[c],u=R.useIx[c]||0,cap=ixCap(c),set=ixSessions(c),xdown=S.ev.ixdown&&S.ev.ixdown[c]>S.day;
|
||||
h+=`<div class="kv"><span>${mine?tr('Your own fabric · {name}',{name:myFab(c).n}):lagName(S.ixp[c],(S.ixn||{})[c])}${xdown?' · <b style="color:var(--bad)">FABRIC DOWN</b>':''}</span><b>${fmtG(u)}</b></div><div class="bar ${barCls(u/cap)}"><i style="width:${u/cap*100}%"></i></div>${prefCtl('ix',c,S.ixPref&&S.ixPref[c])}${S.pops[city]?siteCtl('ix',c,city,(S.ixSite||{})[c]):''}`;
|
||||
if(isDk(c)&&S.dk){const ad=S.dk.add[c]||[],rt=S.dk.ret[c];h+=`<p class="note">${rt&&rt>S.day?tr('DE-KICKS personalised pricing: {p}% of what a normal IX would charge (promo, {n} days left).',{p:Math.round(dkMult(c)*100),n:rt-S.day}):tr('DE-KICKS personalised pricing: {p}% of what a normal IX would charge.',{p:Math.round(dkMult(c)*100)})}</p>`;
|
||||
for(const x of ad)h+=`<div class="row"><div class="grow"><div class="nm">${esc(x.n)} <span class="tag paid">${tr('auto-enrolled')}</span></div><div class="meta">${esc(x.blurb)} · ${tr('{price}/mo',{price:fmt$(x.mo)})}</div></div>${btn(UI.confirm==='dk'+c+x.n?tr('Lose exclusive benefits?'):tr('Opt out'),'dkOptOut',{city:c,n:x.n},'ghost sm')}</div>`;}
|
||||
if(isRemote(c))h+=`<p class="note">${trn('Remote port via a reseller: 1.5× price, 80% usable, and {n} member here refuse remote peers.','Remote port via a reseller: 1.5× price, 80% usable, and {n} members here refuse remote peers.',ixMembers(c).filter(noRemote).length)}</p>`;
|
||||
if(mine){const f=S.myIx[c].fab|0,N=MYIX_FAB[f+1];h+=`<div class="kv"><span>${tr('Members paying you')}</span><b>${tr('{n} of up to {max} · {price}/mo',{n:S.myIx[c].members.length,max:myFab(c).max,price:fmt$(S.myIx[c].members.length*MYIX_FEE)})}</b></div>${N?`<div class="btns">${btn(N.lvl>lvl()?tr('{name} fabric <small>level {lv}</small>',{name:N.n,lv:N.lvl}):tr('Upgrade fabric to {name} <small>{cost} + {mo}/mo</small>',{name:N.n,cost:fmt$(N.cost),mo:fmt$(N.mo)}),'myIxUp',{city:c},'pink sm',N.lvl>lvl()||S.cash<N.cost)}</div><p class="note">${tr('A bigger fabric carries more traffic and has room for more members. Your router here still has to keep up.')}</p>`:'<p class="note">'+tr('Biggest fabric money can buy.')+'</p>'}`;}
|
||||
else h+=`<div class="btns">${PORT.map((P2,i)=>i>S.ixp[c]&&portShown(i)?btn(tr('Upgrade {port} <small>{price}</small>',{port:P2.n,price:portMo(ixPortMo(c,i)*((S.ixn||{})[c]||1))}),'buyIx',{city:c,tier:i},'sm',(!!S.pops[city]&&!portOk(city,i))||(!S.pops[city]&&i>1)):'').join('')}${S.pops[city]&&((S.ixn||{})[c]||1)<LAG_MAX?btn(tr('+ LAG member <small>{price}</small>',{price:portMo(ixPortMo(c,S.ixp[c]))}),'lagIx',{city:c,d:1},'sm',S.cash<ixPortMo(c,S.ixp[c])):''}${((S.ixn||{})[c]||1)>1?btn(tr('− member'),'lagIx',{city:c,d:-1},'ghost sm'):''}${btn(S.rs[c]?tr('Leave route server'):tr('Join route server'),'rs',{city:c},S.rs[c]?'ghost sm':'pink sm')}${btn(UI.confirm==='ix'+c?tr('Really leave?'):tr('Leave IX'),'cancelIx',{city:c},'ghost sm')}</div>`;
|
||||
h+=`<div style="margin-top:8px">`;
|
||||
{const elig=mine?[]:ixMembers(c).filter(id=>!set.has(id)&&peerOk(id,'ix',c).ok);if(elig.length>1)h+=`<div class="btns">${btn(tr('Request all {n} willing peers',{n:elig.length}),'peerAll',{city:c},'pink sm')}</div>`;}
|
||||
for(const id of ixMembers(c).sort((a,b)=>NSH[b]-NSH[a])){const n=NET[id],on=set.has(id),viaRs=on&&!S.peers[id+'@'+c]&&!mine,chk=peerOk(id,'ix',c);
|
||||
h+=`<div class="row">${logo(n)}<div class="grow"><div class="nm">${esc(n.name)}</div><div class="meta"><span class="tag ${n.type}">${TYPE_L[n.type]}</span> <span class="tag ${n.pol}">${n.pol}</span> · ${(NSH[id]*100).toFixed(NSH[id]<0.01?1:0)}%${n.tail?' <span class="tag st">'+tr('tiny')+'</span>':''}</div>${!on&&!chk.ok?`<div class="why">${esc(chk.why)}</div>`:''}</div>
|
||||
${on?(viaRs||mine?`<span class="tag st on">${mine?tr('Member'):tr('via RS')}</span>`:btn(tr('Peered ✓'),'unpeer',{city:c,net:id},'green sm',false,tr('Click to tear down'))):btn(tr('Request'),'peer',{city:c,net:id},'sm',!chk.ok)}</div>`;}
|
||||
h+=`</div>`;}
|
||||
h+=`</section>`;return h;
|
||||
}
|
||||
function vxcPanel(l){
|
||||
const load=R.load[l.id]||0,cap=VXC[l.vt].g,u=load/cap,down=linkDown(l),f=FAB[l.prov];
|
||||
let h=`<div class="ph"><div><div class="eyebrow">${tr('Virtual circuit · {name} · {km} km',{name:esc(f.name),km:l.km.toLocaleString()})}</div><h2>${CITY[l.a].name} ⇄ ${CITY[l.b].name}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('Close')}">×</button></div><div class="scroll">`;
|
||||
if(down)h+=`<section><h3 style="color:var(--bad)">${tr('Fabric outage')}</h3><p class="lead">${tr('{name} is down. Nothing you can do but wait, or have another path.',{name:esc(f.name)})}</p></section>`;
|
||||
h+=`<section><h3>${tr('Capacity')}</h3><div class="kv"><span>${tr('{name} circuit',{name:VXC[l.vt].n})}</span><b>${fmtG(load)} / ${fmtG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>
|
||||
<div class="kv"><span>${tr('Monthly')}</span><b>${tr('{price}/mo',{price:fmt$(l.mo)})}</b></div>${!S.pops[l.b]?`<p class="note">${tr('Remote peering leg into {ix}.',{ix:esc(CITY[l.b].ix)})}</p>`:''}
|
||||
<div class="btns">${VXC.map((V,t)=>t>l.vt?btn(`${V.n} <small>${tr('{price}/mo',{price:fmt$(vxcMo(l.km,l.sub,t))})}</small>`,'upVxc',{id:l.id,t},'sm'):'').join('')}</div></section>
|
||||
${trafficSection(l)}${metricSection(l)}
|
||||
<section>${btn(UI.confirm===l.id?tr('Really cancel?'):tr('Cancel circuit'),'cancelVxc',{id:l.id},'ghost sm')}</section></div>`;
|
||||
return h;
|
||||
}
|
||||
function prefCtl(kind,id,cur){cur=cur||'normal';return `<div class="btns"><span class="meta" style="align-self:center">${tr('Egress:')}</span>${Object.keys(PREF).map(v=>btn(PREF[v],'setPref',{kind,id,v},cur===v?'pink sm':'ghost sm')).join('')}</div>`;}
|
||||
function trafficSection(l){
|
||||
const rec=R.ef[edgeKey(l)],n=pairLinks(l.a,l.b).length;
|
||||
let h=`<section><h3>${tr("What's on this link")}</h3>`;
|
||||
if(!rec){return h+`<p class="empty">${tr('No traffic right now.')}</p></section>`;}
|
||||
const tot=Object.values(rec.net).reduce((a,b)=>a+b,0)||1;
|
||||
const nets=Object.entries(rec.net).sort((a,b)=>b[1]-a[1]);
|
||||
const col=id=>id==='junk'?'#FF4D5E':id==='l2vpn'?'#7B61FF':NET[id].col,nm=id=>id==='junk'?tr('DDoS junk'):id==='l2vpn'?tr('L2VPN customers'):NET[id].name;
|
||||
h+=`${n>1?`<p class="note" style="margin-top:0">${tr('Totals for all {n} links between these cities.',{n})}</p>`:''}<div class="stack">${nets.map(([id,v])=>`<i style="width:${v/tot*100}%;background:${col(id)}" title="${esc(nm(id))}"></i>`).join('')}</div>`;
|
||||
h+=`<h4 class="sub4">${tr('Content from')}</h4>`+nets.slice(0,6).map(([id,v])=>`<div class="kv"><span><span class="dot" style="background:${col(id)}"></span>${esc(nm(id))}</span><b>${fmtG(v)} · ${pct(v/tot)}</b></div>`).join('');
|
||||
const egs=Object.entries(rec.eg).sort((a,b)=>b[1]-a[1]);
|
||||
h+=`<h4 class="sub4">${tr('Enters your network at')}</h4>`+egs.slice(0,6).map(([k,v])=>{const d=R.egDesc[k];return `<div class="row"><div class="grow"><div class="nm">${esc(d.lab)}</div><div class="meta">${CITY[d.city].name} · ${fmtG(v)} · ${pct(v/tot)}</div></div>${btn(tr('Open'),'goEgress',{city:d.city,k:d.k},'ghost sm')}</div>`;}).join('');
|
||||
const dst=Object.entries(rec.dst).sort((a,b)=>b[1]-a[1]);
|
||||
h+=`<h4 class="sub4">${tr('Going to customers in')}</h4>`+dst.slice(0,6).map(([c,v])=>`<div class="kv"><span>${CITY[c].name}</span><b>${fmtG(v)} · ${pct(v/tot)}</b></div>`).join('');
|
||||
const u=tot/pairLinks(l.a,l.b).filter(x=>!linkDown(x)).reduce((a,x)=>a+capOf(x),0);
|
||||
if(u>=0.8&&egs.length){const d=R.egDesc[egs[0][0]];h+=`<p class="why">${tr("Biggest feeder: {egress} in {city}. Set it to “Backup only”, give the customers a closer egress (peering, a cache, local transit), or raise this link's metric.",{egress:esc(d.lab),city:CITY[d.city].name})}</p>`;}
|
||||
return h+`</section>`;
|
||||
}
|
||||
function metricSection(l){const cur=l.metric||'normal';
|
||||
return `<section><h3>${tr('Routing metric')}</h3><p class="lead">${tr('Your routers pick the lowest-cost path. Raise the metric to push traffic onto other paths. “Backup only” keeps it idle unless nothing else works. Applies to every link between these two cities.')}</p><div class="btns">${Object.keys(MET).map(k=>btn(MET[k].l,'setMetric',{id:l.id,v:k},cur===k?'pink sm':'ghost sm')).join('')}</div></section>`;}
|
||||
function chinaSection(c){const st=S.cnLic?S.cnLic.state:'none',loss=S.ev.gfw>S.day?0.35:0.2;
|
||||
let h=`<section><h3>${tr('Behind the Great Firewall')}</h3><p class="lead">${tr('Mainland China plays by its own rules. {list} and other foreign services are blocked here, so users mostly reach Chinese networks. Traffic crossing the border loses about {pct} to filtering and congestion, unless it rides a premium route: CN-Too transit or a premium cross-border circuit (both sold only in Hong Kong), or a PNI with a Chinese network. Revenue per user is lower here.',{list:CN_BLOCKED.slice(0,4).map(esc).join(', '),pct:pct(loss)})}</p>`;
|
||||
if(st==='none')h+=`<p class="lead">${tr('Foreign networks need a local joint venture and an operating license to build infrastructure here.')}</p>${btn(tr('Apply for a license <small>{price} + {mo}/mo · ~45 days</small>',{price:fmt$(CN_LIC),mo:fmt$(CN_JV_MO)}),'applyCn',{},'pink',S.cash<CN_LIC)}`;
|
||||
else if(st==='pending')h+=`<p class="note">${tr('License paperwork in progress: {n} days left.',{n:Math.max(0,S.cnLic.ready-S.day)})}</p>`;
|
||||
else h+=`<p class="note">${tr('Your joint venture holds an operating license.')}</p>`;
|
||||
if(R.gfwCross>0.5)h+=`<div class="kv"><span>${tr('Your traffic crossing the border')}</span><b>${fmtG(R.gfwCross)}</b></div><div class="kv"><span>${tr('Lost on the way')}</span><b style="color:var(--bad)">${fmtG(R.gfwLost)}</b></div>`;
|
||||
return h+`</section>`;}
|
||||
function subUpgradePanel(l){return `<h4 class="sub4">${tr('Submarine transmission')}</h4><p class="note">${tr('Better terminals and optical tuning extend long-haul reach. Repeaters are already included; these upgrades do not change latency.')}</p>`+Object.entries(SUB_UPGRADES).map(([k,U])=>{
|
||||
const at=l['sub'+k],done=subUpgradeReady(l,k),cost=subUpgradeCost(l,k),preview={...l,['sub'+k]:S.day};
|
||||
const status=done?tr('Installed'):at!==undefined?tr('Ready in {n} days',{n:Math.max(0,at-S.day)}):tr('{price} · {n} days',{price:fmt$(cost),n:U.days});
|
||||
return `<div class="row"><div class="grow"><div class="nm">${tr(U.n)}</div><div class="meta">${status}</div><div class="meta">${tr('Up to {g} per channel',{g:fmtG(submarineRate(preview))})}</div></div>${at===undefined?btn(tr('Install'),'subUpgrade',{id:l.id,k},'sm',lvl()<4||S.cash<cost):''}</div>`;}).join('');}
|
||||
function dfPanel(l){
|
||||
const load=R.load[l.id]||0,cap=dfCap(l),u=cap?load/cap:0,bld=l.ready>S.day,A=CITY[l.a].name,B=CITY[l.b].name,inc=S.inc.find(i=>i.ref===l.id||i.ref===(l.trench||l.id)),amps=ampCount(l.km),sysD=DF_SYS[l.sys];
|
||||
let h=`<div class="ph"><div><div class="eyebrow">${tr('Dark fiber · {kind} · {km} km',{kind:l.own?tr('your own build'):tr('leased IRU'),km:l.km.toLocaleString()})}</div><h2>${A} ⇄ ${B}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('Close')}">×</button></div><div class="scroll">`;
|
||||
if(bld){const tot=Math.max(1,l.ready-l.day),done=clamp((S.day-l.day)/tot,0,1);
|
||||
h+=`<section><h3>${l.own?tr('Under construction'):tr('Being spliced')}</h3><div class="kv"><span>${l.own?tr('Permits, trenching, splicing'):tr('IRU handover')}</span><b>${tr('{n} days left',{n:l.ready-S.day})}</b></div><div class="bar me"><i style="width:${done*100}%"></i></div>${l.own?`<div class="btns">${btn(tr('Hire extra crews <small>{price} · −30 days</small>',{price:fmt$(crewCost(l))}),'crews',{id:l.id},'sm',l.ready<=S.day+1||S.cash<crewCost(l))}${btn(tr('Finish in 1 day <small>{price}</small>',{price:fmt$(crewSteps(l)*crewCost(l))}),'crews',{id:l.id,all:1},'sm',!crewSteps(l)||S.cash<crewSteps(l)*crewCost(l))}</div>`:''}<p class="note">${tr("You can pre-install optics now so it lights up the day it's ready.")}</p></section>`;}
|
||||
else if(inc&&linkDown(l))h+=`<section><h3 style="color:var(--bad)">${tr('Dark!')}</h3><p class="lead">${esc(inc.msg)}</p>${inc.cost?btn(`${esc(inc.fix||tr('Rush repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash<inc.cost):''}</section>`;
|
||||
h+=`<section><h3>${tr('Capacity')}</h3><div class="kv"><span>${tr('{n} of {max} channels lit',{n:(l.ch||[]).length,max:chMax(l)})}${soldSlots(l)?` · ${tr('{n} sold as alien waves',{n:soldSlots(l)})}`:''}</span><b>${fmtG(load)} / ${fmtG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>
|
||||
${l.own&&l.sub?`<div class="kv"><span>${tr('Cable design')}</span><b>${tr((SEA_DESIGNS[l.seaDesign]||SEA_DESIGNS.standard).n)}</b></div>`:''}
|
||||
<div class="kv"><span>${tr('Latency')}</span><b>${tr('{ms} ms one-way',{ms:linkLat(l).toFixed(1)})}</b></div><div class="kv"><span>${l.own?tr('Right-of-way upkeep'):tr('IRU lease')}</span><b>${tr('{price}/mo',{price:fmt$(l.mo)})}</b></div><div class="kv"><span>${tr('{n} amp huts',{n:amps})}</span><b>${tr('{price}/mo',{price:fmt$(amps*AMP_MO)})}</b></div>${!bld&&!(l.ch||[]).length?`<p class="why">${tr('This fiber is dark. Add optics below to carry traffic.')}</p>`:''}</section>`;
|
||||
if(!bld){const sold=S.biz.filter(b=>b.link===l.id&&(b.type==='wwave'||b.type==='dfpair'||b.type==='pairs')),off=S.offers.find(o=>o.link===l.id),fc=freeCh(l);
|
||||
h+=`<section><h3>${tr('Selling spare capacity')}</h3><p class="lead">${tr('Other carriers rent what you do not use: alien waves on free channels of your line system, or on your own build a spare fiber pair in the trench.')}</p>
|
||||
<div class="kv"><span>${tr('Free channels')}</span><b>${fc} / ${chMax(l)}</b></div>${sold.map(b=>`<div class="row"><div class="grow"><div class="nm">${esc(b.name)}</div><div class="meta">${esc(b.what||BIZ_T[b.type].l)} · ${tr('{price}/mo',{price:fmt$(b.rate)})}</div></div></div>`).join('')}
|
||||
${off?`<div class="row"><div class="grow"><div class="nm">${esc(off.name)}</div><div class="meta">${esc(off.what)} · ${tr('{price}/mo',{price:fmt$(off.rate)})} · ${tr('{n}d left',{n:off.exp-S.day})}${off.broker?' · '+tr('via a capacity broker'):''}</div></div>${btn(tr('Accept'),'accept',{id:off.id},'pink sm')}</div>`:fc>=1||pairFree(l)?`<div class="btns">${btn(tr('List it with a capacity broker <small>they keep 10%</small>'),'advertise',{id:l.id},'sm')}</div>`:`<p class="note">${tr('Nothing spare to sell on this fiber right now.')}</p>`}</section>`;}
|
||||
h+=`<section><h3>${tr('Optics')}</h3><p class="lead">${tr('Each channel is a pair of optics, one per end. ZR+ optics plug straight into your routers. Transponders sit on a shelf.')}</p>`;
|
||||
if(l.own&&l.sub)h+=subUpgradePanel(l);
|
||||
for(const k of Object.keys(OPT)){const O=OPT[k],n=(l.ch||[]).filter(x=>x===k).length,why=chWhy(l,k);
|
||||
const md=optMode(k,l),cc=chCost(l,k),sp=spareN(k);
|
||||
h+=`<div class="row"><div class="grow"><div class="nm">${O.n} <span class="meta">${optModes(k,l).map(([g,r])=>tr('{g} to {km} km',{g:fmtG(g),km:r.toLocaleString()})).join(' · ')}</span></div><div class="meta">${esc(O.blurb)}${n?` · <b>${tr('{n} lit',{n})}</b>`:''}${sp?` · ${trn('{n} spare on the shelf','{n} spares on the shelf',sp)}`:''}</div>${md&&!md.full?`<div class="meta">⚠️ ${tr('Runs at <b>{g}</b> per channel on this route (long-haul mode).',{g:fmtG(md.g)})} ${!l.sub&®enNeed(k,l)>(l.regen|0)?trn('{n} regen site would bring it back to {g}.','{n} regen sites would bring it back to {g}.',regenNeed(k,l),{g:fmtG(O.g)}):''}</div>`:''}${why?`<div class="why">${esc(why)}</div>`:''}</div>${n?btn('−','rmCh',{id:l.id,o:k},'ghost sm'):''}${btn(sp?`+ <small>${cc?tr('spare + {price}',{price:fmt$(cc)}):tr('spare')}</small>`:`+ <small>${fmt$(cc)}</small>`,'addCh',{id:l.id,o:k},'sm',!!why||S.cash<cc)}</div>`;}
|
||||
{const st=Object.keys(OPT).filter(k=>spareN(k)>0);h+=`<p class="note">${tr('Unplugged optics go on the spares shelf and are used first next time.')}</p>`;
|
||||
{const used=[...new Set(l.ch||[])].filter(k=>OPT[k]&&OPT[k].lvl<=lvl());if(used.length)h+=`<div class="btns">${used.map(k=>btn(tr('Stock a spare {optic} <small>{price}</small>',{optic:OPT[k].n,price:fmt$(optCost(k))}),'buySpare',{o:k},'ghost sm',S.cash<optCost(k)||spareN(k)>=64)).join('')}</div><p class="meta">${tr('Spares bought now are already paid for when the next shortage hits.')}</p>`;}if(st.length)h+=`<h4 class="sub4">${tr('Spares shelf')}</h4>`+st.map(k=>`<div class="row"><div class="grow"><div class="nm">${spareN(k)} × ${OPT[k].n}</div></div>${btn(tr('Sell one <small>{price}</small>',{price:fmt$(spareValue(k))}),'sellSpare',{o:k},'ghost sm')}</div>`).join('');}
|
||||
const rg=l.regen|0,rgAdd=REGEN_COST+Math.round((l.ch||[]).reduce((a,c)=>a+optCost(c),0)*REGEN_CH);
|
||||
h+=`</section><section><h3>${tr('Line system')}</h3><div class="kv"><span>${esc(sysD.n)}</span><b>${tr('{n} amplifiers',{n:amps})}</b></div>
|
||||
<div class="kv"><span>${tr('Regen sites')}</span><b>${rg?tr('{n} · optical spans of {km} km',{n:rg,km:spanKm(l).toLocaleString()}):tr('none')}</b></div><p class="note">${tr('A regen site turns the light back into bits halfway and sends it on fresh, so optics only have to reach the next site. Each needs a regen card for every lit channel. {price}/mo per site for the hut.',{price:fmt$(REGEN_MO)})}</p>${l.sub&&l.own?`<p class="note">${tr('No regen sites in the middle of the ocean: long cables run their optics in long-haul mode.')}</p>`:`<div class="btns">${rg<REGEN_MAX?btn(tr('+ Regen site <small>{price}</small>',{price:fmt$(rgAdd)}),'regen',{id:l.id,d:1},'sm',S.cash<rgAdd):''}${rg?btn(tr('− Regen site'),'regen',{id:l.id,d:-1},'ghost sm'):''}</div>`}<p class="note">${esc(sysD.blurb)}</p><div class="btns">${(()=>{const t=sysNext(l);if(!t)return '';const T=DF_SYS[t],c=sysUpCost(l);return T.lvl>lvl()?btn(tr('{sys} <small>level {n}</small>',{sys:T.n,n:T.lvl}),'upSys',{id:l.id},'sm',true):btn(tr('Upgrade to {sys} <small>{price}</small>',{sys:T.n,price:fmt$(c)}),'upSys',{id:l.id},'sm',S.cash<c);})()}${pairBtn(l)}${btn(l.spares?tr('Spares kit on ✓'):tr('Keep a spares kit <small>{price}/mo</small>',{price:fmt$(Math.round(150+(l.ch||[]).length*80))}),'spares',{id:l.id},l.spares?'green sm':'sm')}</div><p class="note">${tr('Spare optics and amplifier cards on the shelf turn multi-day hardware failures into one-day swaps.')}</p></section>`;
|
||||
{const sib=pairLinks(l.a,l.b).filter(x=>x!==l&&x.kind!=='vxc');h+=`<section><h3>${tr('Redundancy')}</h3><p class="lead">${sib.length?tr('Other links between these cities:'):tr('This is the only link between these cities. Add a parallel one, or a path through another city.')}</p>${sib.map(x=>`<div class="row"><div class="grow"><div class="nm">${esc(capName(x))} ${linkDown(x)?'<span class="tag restrictive">'+tr('CUT')+'</span>':''}</div><div class="meta">${(x.trench||x.id)===(l.trench||l.id)?tr('same trench'):tr('diverse route')}</div></div>${btn(tr('Open'),'selLink',{id:x.id},'ghost sm')}</div>`).join('')}<div class="btns">${btn(tr('Add parallel link'),'addParallel',{id:l.id},'pink sm')}</div></section>`;}
|
||||
h+=`${trafficSection(l)}${metricSection(l)}<section>${btn(UI.confirm===l.id?tr('Really give it up?'):(l.own?tr('Abandon the fiber'):tr('Cancel the IRU')),'rmLink',{id:l.id},'ghost sm')}${cabBack(l)>0?`<p class="note">${tr('Giving it up now returns {price}.',{price:fmt$(cabBack(l))})}</p>`:''}</section></div>`;
|
||||
return h;
|
||||
}
|
||||
function offersHere(c){
|
||||
const os=S.offers.filter(o=>bCities(o).includes(c));if(!os.length)return '';
|
||||
return `<section><h3>${tr('Offers here')}</h3>${os.map(o=>`<div class="row"><div class="grow"><div class="nm">${esc(o.name)}</div><div class="meta">${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('{n}d left',{n:o.exp-S.day})}</div>${R.reach<0.99&&!BIZ_T[o.type].l2?`<div class="why">${tr('They need the full internet. Your reach is {pct}.',{pct:pct(R.reach)})}</div>`:''}${o.type==='scrub'&&!hasScrub()?`<div class="why">${tr('Needs your own scrubbing center (Infra tab).')}</div>`:''}${reqList(o)}${bHas(o)?'':`<div class="why">${tr('Needs a POP in {cities} too.',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}</div>`}</div>${bHas(o)?btn(tr('Accept'),'accept',{id:o.id},'green sm'):''}${btn(tr('No'),'decline',{id:o.id},'ghost sm')}</div>`).join('')}</section>`;
|
||||
}
|
||||
function linkPanel(id){
|
||||
const l=S.links.find(x=>x.id===id);if(!l){UI.sel=null;return '';}
|
||||
if(l.kind==='vxc')return vxcPanel(l);
|
||||
if(l.kind==='df')return dfPanel(l);
|
||||
const load=R.load[l.id]||0,cap=LT[l.tier].g,u=load/cap,cut=l.cut>S.day,trk=l.trench||l.id,inc=S.inc.find(i=>(LINKCUT_TR.includes(i.type)&&i.ref===trk)||((i.type==='fatwave'||i.type==='label'||i.type==='mtu')&&i.ref===l.id)),sib=pairLinks(l.a,l.b).filter(x=>x!==l&&x.kind!=='vxc'),mates=sib.filter(x=>(x.trench||x.id)===trk);
|
||||
let h=`<div class="ph"><div><div class="eyebrow">${l.cable?esc(CAB[l.cable].name):l.sub?tr('Subsea cable'):tr('Terrestrial fiber')} · ${l.km.toLocaleString()} km</div><h2>${CITY[l.a].name} ⇄ ${CITY[l.b].name}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('Close')}">×</button></div><div class="scroll">`;
|
||||
if(cut)h+=`<section><h3 style="color:var(--bad)">${tr('Cut!')}</h3><p class="lead">${inc?esc(inc.msg):''} ${tr('Back in {n} days.',{n:l.cut-S.day})}</p>${inc&&inc.cost?btn(`${esc(inc.fix||tr('Rush repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash<inc.cost):''}</section>`;
|
||||
h+=`<section><h3>${tr('Capacity')}</h3><div class="kv"><span>${tr('{name} wave',{name:LT[l.tier].n})}</span><b>${fmtG(load)} / ${fmtG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>
|
||||
<div class="kv"><span>${tr('Latency')}</span><b>${tr('{ms} ms one-way',{ms:linkLat(l).toFixed(1)})}</b></div>${l.cable?`<div class="kv"><span>${tr('Cable system')}</span><b>${esc(CAB[l.cable].name)}</b></div>`:''}
|
||||
<div class="kv"><span>${tr('Wave lease')}</span><b>${tr('{price}/mo',{price:fmt$(l.mo)})}</b></div>${u>=0.9?`<p class="why">${tr('Congested. Upgrade it or add a parallel path.')}</p>`:''}
|
||||
<div class="btns">${LT.map((T,i)=>{const d=Math.round(waveMo(l.km,l.sub,i)*(l.mult||1)),sw=subWaveWhy(i,l.km,l.sub),ok=waveOk(l.a,l.b,i);return i>l.tier&&waveShown(i)?btn(`${T.n} <small>${sw?tr('too far for this cable'):ok?tr('{price}/mo',{price:fmt$(d)}):tr('needs {what}',{what:esc(waveNeed(i))})}</small>`,'upLink',{id:l.id,tier:i},'sm',S.cash<d||!ok||!!sw):'';}).join('')}${l.sub&&subMaxTier(l.km)<LT.length-1?`<p class="note">${tr('{km} km of cable carries at most {g} per carrier.',{km:Math.round(l.km).toLocaleString(),g:fmtCap(subCarrier(l.km))})}${l.tier>subMaxTier(l.km)?' '+tr('Your wave was sold before the cable owner re-engineered it, so it keeps running.'):''}</p>`:''}</div></section>
|
||||
<section><h3>${tr('Redundancy')}</h3><p class="lead">${mates.length?trn('Shares a trench with {n} other link. One cut takes them all down.','Shares a trench with {n} other links. One cut takes them all down.',mates.length):sib.length?tr('Runs on its own route. A cut here leaves the other links up.'):tr('This is the only link between these cities. Add a parallel one, or a path through another city.')}</p>
|
||||
${sib.map(x=>`<div class="row"><div class="grow"><div class="nm">${tr('{name} parallel link',{name:capName(x)})} ${x.cut>S.day?'<span class="tag restrictive">'+tr('CUT')+'</span>':''}</div><div class="meta">${(x.trench||x.id)===trk?tr('same trench'):tr('diverse route')}</div></div>${btn(tr('Open'),'selLink',{id:x.id},'ghost sm')}</div>`).join('')}
|
||||
<div class="btns">${btn(tr('Add parallel link'),'addParallel',{id:l.id},'pink sm')}</div></section>
|
||||
${trafficSection(l)}${metricSection(l)}
|
||||
<section>${btn(UI.confirm===l.id?tr('Really decommission?'):tr('Decommission link'),'rmLink',{id:l.id},'ghost sm')}</section></div>`;
|
||||
return h;
|
||||
}
|
||||
const EGC={c:[tr('Caches'),'#16A866'],p:[tr('PNIs'),'#7B61FF'],ix:[tr('IX peering'),'#FFD23F'],t:[tr('Transit'),'#FF8A3D'],l2:[tr('L2 circuits'),'#2F8CFF']};
|
||||
function svgChart(rows,stackKeys,lines,fmtY){
|
||||
const W=600,H=180,L=50,B=20,T=8,Rr=8;if(rows.length<2)return `<p class="empty">${tr('Collecting data. Check back in a few days.')}</p>`;
|
||||
let ymax=1;for(const r of rows){let s=0;for(const k of stackKeys)s+=r[k]||0;ymax=Math.max(ymax,s);for(const ln of lines)ymax=Math.max(ymax,r[ln.k]||0);}ymax*=1.1;
|
||||
const x=i=>L+(W-L-Rr)*i/(rows.length-1),y=v=>T+(H-T-B)*(1-v/ymax);let g='';
|
||||
for(let j=0;j<=3;j++){const v=ymax*j/3,yy=y(v);g+=`<line x1="${L}" x2="${W-Rr}" y1="${yy}" y2="${yy}" stroke="#D5DEEC" stroke-width="1"/><text x="${L-6}" y="${yy+3}" text-anchor="end" font-size="10" fill="#55608A" font-weight="700">${fmtY(v)}</text>`;}
|
||||
const base=rows.map(()=>0);
|
||||
for(const k of stackKeys){const top=rows.map((r,i)=>base[i]+(r[k]||0));let d=`M${x(0)},${y(top[0])}`;for(let i=1;i<rows.length;i++)d+=`L${x(i)},${y(top[i])}`;for(let i=rows.length-1;i>=0;i--)d+=`L${x(i)},${y(base[i])}`;g+=`<path d="${d}Z" fill="${EGC[k][1]}" fill-opacity=".85" stroke="#1E2640" stroke-width=".8"/>`;top.forEach((v,i)=>base[i]=v);}
|
||||
for(const ln of lines){let d='';rows.forEach((r,i)=>{d+=(i?'L':'M')+x(i)+','+y(r[ln.k]||0);});g+=`<path d="${d}" fill="none" stroke="${ln.col}" stroke-width="2.5" ${ln.dash?'stroke-dasharray="5 4"':''} stroke-linejoin="round"/>`;const last=rows[rows.length-1][ln.k]||0;g+=`<circle cx="${x(rows.length-1)}" cy="${y(last)}" r="3.5" fill="${ln.col}" stroke="#1E2640" stroke-width="1.5"/>`;}
|
||||
g+=`<text x="${L}" y="${H-5}" font-size="10" fill="#55608A" font-weight="700">${dateStr(rows[0].d)}</text><text x="${W-Rr}" y="${H-5}" text-anchor="end" font-size="10" fill="#55608A" font-weight="700">${dateStr(rows[rows.length-1].d)}</text>`;
|
||||
return `<svg class="chart" viewBox="0 0 ${W} ${H}" role="img">${g}</svg>`;}
|
||||
// For a network you currently reach over transit: the cheapest way to move it to peering.
|
||||
// Exchange members as sets, rebuilt once per routing pass: hints are asked for many networks at a time.
|
||||
let IXMR=null,IXMC={};const ixHas=(x,id)=>{if(IXMR!==R){IXMR=R;IXMC={};}return (IXMC[x]||(IXMC[x]=new Set(ixMembers(x)))).has(id);};
|
||||
function offTransitHint(id,city){const n=NET[id];if(n.type==='t1')return tr('Tier 1: only a PNI, and only once you are big enough for the Tier 1 club');
|
||||
const ixc=Object.keys(S.pops).flatMap(ixIdsIn).filter(x=>ixHas(x,id)),here=city&&ixIdsIn(city).find(x=>ixHas(x,id))||null,pick1=here||ixc.find(x=>S.ixp[x]!==undefined)||ixc[0];
|
||||
if(n.pol==='open'){if(pick1)return here||ixNamesCity(pick1)?tr('Open peer: join the route server at {ix}',{ix:ixName(pick1)}):tr('Open peer: join the route server at {ix} ({city})',{ix:ixName(pick1),city:CITY[ixCity(pick1)].name});const x=nearestSpot(id);return x?tr('Open peer, but not on any IX where you have a POP. Nearest: {city}',{city:CITY[x.c].name}):tr('Open peer, but not on any IX where you have a POP');}
|
||||
if(n.pol==='paid')return paidFree(n)?tr('Peers with you for free over a PNI. You got too big to charge.'):n.freeLv?tr('Paid peering only: a PNI costs {price}/mo. Free from customer level {n}.',{price:fmt$(n.paidFee),n:n.freeLv}):tr('Paid peering only: a PNI costs {price}/mo',{price:fmt$(n.paidFee)});
|
||||
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 tr('Ready for a PNI in {city}',{city:CITY[pniC.includes(city)?city:pniC[0]].name});
|
||||
if(ixOk&&ixOk.ok)return tr('Will peer at {ix}: request a session',{ix:ixName(pick1)});
|
||||
if(ixOk)return `${ixName(pick1)}: ${ixOk.why}`;
|
||||
if(pniC.length)return tr('PNI in {city}: {why}',{city:CITY[pniC[0]].name,why:pOk.why});{const x=nearestSpot(id);return x?tr('Not in your cities yet. Nearest: {city}',{city:CITY[x.c].name}):tr('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);}
|
||||
Loading…
Add table
Add a link
Reference in a new issue