Merge #62: Add on-demand single-link redundancy checks (Flol0)

This commit is contained in:
Frederic Jung 2026-10-28 14:50:23 +01:00
commit 0fb3d3ab96
No known key found for this signature in database
12 changed files with 118 additions and 3 deletions

View file

@ -1,6 +1,7 @@
/* ================= ACTIONS ================= */
function spend(c){if(S.cash<c){toast(tr('interface.not_enough_cash_wait_for_revenue'),'bad');sfx('err');return false;}S.cash-=c;sfx('build');return true;}
const ACT={
linkCheck:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||linkDown(l))return;linkCheckModal(l);},
speed:({v})=>{v=+v;if(![0,0.5,1,2,4,8].includes(v))return;if(v)UI.lastSpeed=v;UI.speed=v;renderHUD();},
help:()=>showHelp(),
dash:()=>{if(!S)return;const d=$('dash');d.hidden=!d.hidden;if(!d.hidden)renderDash();},
@ -32,7 +33,7 @@ const ACT={
netFilter:({f})=>{UI.nf=f==='out'?'out':'all';UI.netFocus=null;$('dash').hidden=true;UI.left='nets';UI.leftOpen=true;UI.sel=null;renderPanel();renderLeft();const b=$('leftBody');if(b)b.scrollTop=0;},
meetGo:({city})=>{if(!isCity(city))return;$('dash').hidden=true;ACT.focusCity({city});if(S.pops[city]){UI.tab='peer';renderPanel();}},
toggleLeft:()=>{UI.leftOpen=!UI.leftOpen;renderLeft();},
phoneTab:({t})=>{if(!['goals','deals','noc','nets'].includes(t))return;haptic(8);if(UI.leftOpen&&UI.left===t&&!UI.sel){UI.leftOpen=false;}else{UI.left=t;UI.leftOpen=true;UI.sel=null;renderPanel();}$('left').classList.remove('full');renderLeft();},
phoneTab:({t})=>{if(!['goals','deals','noc','nets'].includes(t))return;if($('modal').classList.contains('link-check'))closeModal();haptic(8);if(UI.leftOpen&&UI.left===t&&!UI.sel){UI.leftOpen=false;}else{UI.left=t;UI.leftOpen=true;UI.sel=null;renderPanel();}$('left').classList.remove('full');renderLeft();},
phonePlay:()=>{haptic(10);if(UI.speed){UI.lastSpeed=UI.speed;UI.speed=0;}else UI.speed=UI.lastSpeed||1;renderHUD();},
phoneSpeed:()=>{haptic(8);const cur=UI.speed||UI.lastSpeed||1,i=SPEEDS.indexOf(cur),n=SPEEDS[(i+1)%SPEEDS.length];UI.speed=n;UI.lastSpeed=n;renderHUD();},
install:()=>{if(installEvt){installEvt.prompt();installEvt.userChoice.finally(()=>{installEvt=null;});return;}

View file

@ -34,9 +34,25 @@ function vxcPanel(l){
return h;
}
function prefCtl(kind,id,cur){cur=cur||'normal';return `<div class="btns"><span class="meta" style="align-self:center">${tr('common.egress')}</span>${Object.keys(PREF).map(v=>btn(PREF[v],'setPref',{kind,id,v},cur===v?'pink sm':'ghost sm')).join('')}</div>`;}
// Trial routing is isolated from the live save, counters and scenic-route memory.
function linkTrial(id){const save=S,live=R,hot=UI.hotMap,cache=TE_CACHE;
try{S=JSON.parse(JSON.stringify(save));const l=S.links.find(x=>x.id===id);if(!l||linkDown(l))return null;
compute();const before=R;l.cut=S.day+1;compute();
const allowed=new Set(Object.keys(S.pops).filter(popUp).concat(remoteCities())),adj={};
for(const x of S.links)if(!linkDown(x)&&allowed.has(x.a)&&allowed.has(x.b)){(adj[x.a]=adj[x.a]||[]).push(x.b);(adj[x.b]=adj[x.b]||[]).push(x.a);}
const seen=new Set([l.a]),q=[l.a];for(let i=0;i<q.length;i++)for(const c of adj[q[i]]||[])if(!seen.has(c)){seen.add(c);q.push(c);}
const losses=[];for(const c in S.pops){const g=Math.max(0,(before.citySrv[c]||0)-(R.citySrv[c]||0));if(g>.01)losses.push({name:CITY[c].name,g});}
for(const b of S.biz)if(BIZ_T[b.type].l2){const g=Math.max(0,(before.l2[b.id]||0)-(R.l2[b.id]||0));if(g>.01)losses.push({name:b.name,g});}
const busy=S.links.filter(x=>x.id!==id&&!linkDown(x)&&capOf(x)>0&&(R.load[x.id]||0)/capOf(x)>=.995).map(x=>({name:CITY[x.a].name+' ⇄ '+CITY[x.b].name,g:R.load[x.id]||0,cap:capOf(x)}));
return {split:!seen.has(l.b),loss:losses.reduce((a,x)=>a+x.g,0),losses,busy,day:S.day};
}finally{S=save;R=live;UI.hotMap=hot;TE_CACHE=cache;}}
function linkCheckModal(l){const t=linkTrial(l.id);if(!t)return;
const title=t.split?tr('link_panels.this_backhoe_wins'):t.loss>.01?tr('link_panels.connected_but_tight'):tr('link_panels.one_backhoe_is_not_enough');
openModal(`<div style="display:flex;align-items:center;justify-content:space-between;gap:10px"><h2>${tr('common.redundancy_check')}</h2><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div><p class="eyebrow">${esc(CITY[l.a].name)} ⇄ ${esc(CITY[l.b].name)} · ${dateStr(t.day)}</p><div class="inc" style="background:${t.split?'#FFE3E3':t.loss>.01?'#FFF6CF':'#EAF7EE'}"><div class="nm">${title}</div><p class="lead">${t.split?tr('link_panels.no_alternate_backbone_path_connects'):t.loss>.01?tr('link_panels.an_alternate_path_exists_but_current'):tr('link_panels.with_current_demand_and_routing_this')}</p><div class="kv"><span>${tr('link_panels.additional_traffic_lost')}</span><b>${fmtG(t.loss)}</b></div></div>${t.losses.length?`<h3>${tr('common.service_affected')}</h3>${t.losses.map(x=>`<div class="kv"><span>${esc(x.name)}</span><b>−${fmtG(x.g)}</b></div>`).join('')}`:''}${t.busy.length?`<h3>${tr('link_panels.full_links_during_the_test')}</h3>${t.busy.slice(0,6).map(x=>`<div class="kv"><span>${esc(x.name)}</span><b>${fmtG(x.g)} / ${fmtG(x.cap)}</b></div>`).join('')}`:''}<p class="note">${tr('link_panels.snapshot_only_one_selected_link')}</p><div class="btns">${btn(tr('common.close'),'closeModal',{},'ghost')}</div>`,'link-check');}
function linkCheckControl(l){return `<section><h3>${tr('common.redundancy_check')}</h3><p class="note">${tr('link_panels.what_happens_if_this_link_fails')}</p>${btn(tr('common.check_redundancy'),'linkCheck',{id:l.id},'ghost sm',linkDown(l))}</section>`;}
function trafficSection(l){
const rec=R.ef[edgeKey(l)],n=pairLinks(l.a,l.b).length;
let h=`<section><h3>${tr('link_panels.what_s_on_this_link')}</h3>`;
let h=linkCheckControl(l)+`<section><h3>${tr('link_panels.what_s_on_this_link')}</h3>`;
if(!rec){return h+`<p class="empty">${tr('link_panels.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]);

View file

@ -1,5 +1,6 @@
// Keyboard focus moves into the modal, so Enter or Space can't keep pressing a hidden button behind it.
function openModal(html){if($('modal').hidden)markLayer();$('modalCard').innerHTML=html;$('modal').hidden=false;const a=document.activeElement;if(a&&a!==document.body&&!a.closest('#modal')){a.blur();const m=$('modalCard');m.tabIndex=-1;m.focus({preventScroll:true});}}
// The link check on phones sits above the tab bar and is not modal, so the tabs stay usable.
function openModal(html,cls=''){$('modal').className=cls;$('modalCard').setAttribute('aria-modal',cls==='link-check'&&isPhone()?'false':'true');if($('modal').hidden)markLayer();$('modalCard').innerHTML=html;$('modal').hidden=false;const a=document.activeElement;if(a&&a!==document.body&&!a.closest('#modal')){a.blur();const m=$('modalCard');m.tabIndex=-1;m.focus({preventScroll:true});}}
function closeModal(){if(!$('modal').hidden)markLayer();$('modal').hidden=true;UI.pending=null;}
const NETWORK_NAMES=[
'Packet Pals','Shinternet','Post, Telegraph & Tubes','Peering Pressure','Best Effort Telecom',

View file

@ -844,6 +844,7 @@
"common.challenger":"challenger",
"common.change_freeze":"Change freeze",
"common.chase_it":"Chase it",
"common.check_redundancy":"Check redundancy",
"common.china":"China",
"common.city":"city",
"common.city_906b":"City",
@ -1165,6 +1166,7 @@
"common.really_leave":"Really leave?",
"common.really_remove":"Really remove?",
"common.redundancy":"Redundancy",
"common.redundancy_check":"Redundancy check",
"common.regen_site":"− Regen site",
"common.regen_sites":"Regen sites",
"common.regional_player":"Regional player",
@ -1222,6 +1224,7 @@
"common.sep":"Sep",
"common.serious_backbone":"Serious backbone",
"common.serve_as_much_traffic_as_you":"Serve as much traffic as you can in one year.",
"common.service_affected":"Service affected",
"common.settings":"Settings",
"common.share":"Share",
"common.share_2cd9":"Share…",
@ -2100,6 +2103,8 @@
"link_panels.a_regen_site_turns_the_light":"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.",
"link_panels.abandon_the_fiber":"Abandon the fiber",
"link_panels.add_parallel_link":"Add parallel link",
"link_panels.additional_traffic_lost":"Additional traffic lost",
"link_panels.an_alternate_path_exists_but_current":"An alternate path exists, but current routing and capacity deliver less traffic.",
"link_panels.apply_for_a_license_price_mo":"Apply for a license <small>{price} + {mo}/mo · ~45 days</small>",
"link_panels.back_in_n_days":"Back in {n} days.",
"link_panels.behind_the_great_firewall":"Behind the Great Firewall",
@ -2110,6 +2115,7 @@
"link_panels.click_to_tear_down":"Click to tear down",
"link_panels.collecting_data_check_back_in_a":"Collecting data. Check back in a few days.",
"link_panels.congested_upgrade_it_or_add_a":"Congested. Upgrade it or add a parallel path.",
"link_panels.connected_but_tight":"Connected, but tight.",
"link_panels.dark_fiber_kind_km_km":"Dark fiber · {kind} · {km} km",
"link_panels.de_kicks_personalised_pricing_p_of":"DE-KICKS personalised pricing: {p}% of what a normal IX would charge (promo, {n} days left).",
"link_panels.de_kicks_personalised_pricing_p_of_3d4f":"DE-KICKS personalised pricing: {p}% of what a normal IX would charge.",
@ -2118,6 +2124,7 @@
"link_panels.finish_in_1_day_price":"Finish in 1 day <small>{price}</small>",
"link_panels.foreign_networks_need_a_local_joint":"Foreign networks need a local joint venture and an operating license to build infrastructure here.",
"link_panels.found_your_own_ix_cost_mo":"Found your own IX <small>{cost} + {mo}/mo</small>",
"link_panels.full_links_during_the_test":"Full links during the test",
"link_panels.g_to_km_km":"{g} to {km} km",
"link_panels.giving_it_up_now_returns_price":"Giving it up now returns {price}.",
"link_panels.going_to_customers_in":"Going to customers in",
@ -2150,6 +2157,7 @@
"link_panels.needs_a_pop_in_cities_too":"Needs a POP in {cities} too.",
"link_panels.needs_what":"needs {what}",
"link_panels.needs_your_own_scrubbing_center":"Needs your own scrubbing center (Infra tab).",
"link_panels.no_alternate_backbone_path_connects":"No alternate backbone path connects these endpoints if this link fails.",
"link_panels.no_regen_sites_in_the_middle":"No regen sites in the middle of the ocean: long cables run their optics in long-haul mode.",
"link_panels.no_traffic_right_now":"No traffic right now.",
"link_panels.not_in_your_cities_yet_nearest":"Not in your cities yet. Nearest: {city}",
@ -2159,6 +2167,7 @@
"link_panels.on_standby_but_carrying_the_traffic":"On standby, but carrying the traffic: no active link between these cities is up.",
"link_panels.on_standby_idle_while_the_other":"On standby: idle while the other links between these cities have room.",
"link_panels.on_standby_taking_the_overflow":"On standby: taking the overflow, because the other links between these cities are full.",
"link_panels.one_backhoe_is_not_enough":"One backhoe is not enough.",
"link_panels.open_peer_but_not_on_any":"Open peer, but not on any IX where you have a POP. Nearest: {city}",
"link_panels.open_peer_but_not_on_any_bfbb":"Open peer, but not on any IX where you have a POP",
"link_panels.open_peer_join_the_route_server":"Open peer: join the route server at {ix}",
@ -2193,6 +2202,7 @@
"link_panels.sell_one_price":"Sell one <small>{price}</small>",
"link_panels.selling_spare_capacity":"Selling spare capacity",
"link_panels.shares_a_trench_with_n_other":{"one":"Shares a trench with {n} other link. One cut takes them all down.","other":"Shares a trench with {n} other links. One cut takes them all down."},
"link_panels.snapshot_only_one_selected_link":"Snapshot only: one selected link fails. Other links on the same cable, trench or fabric stay up. Existing outages and routing rules still apply. No time, money or game state is changed.",
"link_panels.spare_optics_and_amplifier_cards_on":"Spare optics and amplifier cards on the shelf turn multi-day hardware failures into one-day swaps.",
"link_panels.spare_price":"spare + {price}",
"link_panels.spares_bought_now_are_already_paid":"Spares bought now are already paid for when the next shortage hits.",
@ -2202,6 +2212,7 @@
"link_panels.take_it_off_standby":"Take it off standby",
"link_panels.there_s_no_ix_in_city":"There's no IX in {city} yet. Found one: networks join over time, pay you for ports, and peer with you for free.",
"link_panels.they_need_the_full_internet_your":"They need the full internet. Your reach is {pct}.",
"link_panels.this_backhoe_wins":"This backhoe wins.",
"link_panels.this_fiber_is_dark_add_optics":"This fiber is dark. Add optics below to carry traffic.",
"link_panels.this_is_the_only_link_between":"This is the only link between these cities. Add a parallel one, or a path through another city.",
"link_panels.tier_1_only_a_pni_and":"Tier 1: only a PNI, and only once you are big enough for the Tier 1 club",
@ -2211,8 +2222,10 @@
"link_panels.upgrade_to_sys_price":"Upgrade to {sys} <small>{price}</small>",
"link_panels.via_a_capacity_broker":"via a capacity broker",
"link_panels.virtual_circuit_name_km_km":"Virtual circuit · {name} · {km} km",
"link_panels.what_happens_if_this_link_fails":"What happens if this link fails right now?",
"link_panels.what_s_on_this_link":"What's on this link",
"link_panels.will_peer_at_ix_request_a":"Will peer at {ix}: request a session",
"link_panels.with_current_demand_and_routing_this":"With current demand and routing, this link can fail without additional traffic loss.",
"link_panels.you_can_pre_install_optics_now":"You can pre-install optics now so it lights up the day it's ready.",
"link_panels.your_joint_venture_holds_an":"Your joint venture holds an operating license.",
"link_panels.your_own_build":"your own build",

View file

@ -54,6 +54,7 @@ button,.chip,.b,a{touch-action:manipulation;-webkit-tap-highlight-color:transpar
#coach{top:auto !important;bottom:calc(var(--tabbar) + 8px);width:calc(100% - 16px);padding:7px 10px;font-size:13px}
body.sheet-open #coach{bottom:calc(var(--tabbar) + 8px + min(62vh,520px))}
#modal{align-items:end;padding:0}
#modal.link-check{bottom:var(--tabbar)}
#modal .cta{position:sticky;bottom:calc(-16px - env(safe-area-inset-bottom,0px));z-index:1;background:var(--paper);margin:12px -16px 0 !important;padding:10px 16px calc(10px + env(safe-area-inset-bottom,0px));border-top:2px solid var(--line)}
.title-art h1{font-size:34px}.title-art svg{width:54px;height:54px}
.tagline{font-size:13.5px;margin:8px 0 10px}