From 7930d332f1f552e969b0a09a43692c198e943671 Mon Sep 17 00:00:00 2001 From: jvanvik Date: Mon, 9 Nov 2026 22:52:06 +0100 Subject: [PATCH] IPv4 notices in the notifications open the address space (#150) The IPv4 toasts (CGNAT, out of IPv4, a renewal that could not grow, an IPv6-only city done) carry an Address space button, but openOf() did not know ip4Open, so their line in the NOC's notifications had no Open. It now maps to a log target of its own, 'ip4', like 'ops' for opsOpen: Open runs ip4Open, the bank scrolled to its Address space (just the bank if IPv4 is off since). sanitize() keeps the new target. ip4Open is also on the NOC window's list of actions it may run in the game, should a dashboard tab ever draw it. --- CHANGELOG.md | 1 + src/game/80-simulation/50-sanitize.js | 2 +- src/game/90-actions/10-interface.js | 2 +- src/game/94-dashboard/90-noc-window.js | 2 +- src/game/95-modals/20-notifications.js | 4 +-- tests/address-space.test.js | 34 ++++++++++++++++++++++++++ 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7481d9..672976a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- IPv4 notices in the NOC's notifications, like "Your IPv4 is full", now have an Open button that takes you to the bank's Address space, as the notice's own button does (#150). - In dark mode, red warning text is now a lighter red that reads well on the dark panels, and the capacity market's Hot and Cool tags take the night colours instead of staying bright pastel chips (#80). - The NOC dashboard's connections list no longer breaks when one of your fabric ports is already at 400G, the biggest a fabric port gets: it offers a LAG member instead of an upgrade. - Broadband cities can now go IPv6-only with 464XLAT, a second way to save IPv4 next to CGNAT. Start it from a city's Home broadband, which also says what it does to your monthly IPv4 bill: its home routers are swapped over a month or more, paid as each one goes in (new homes there get one too, at the same price), and the homes then need no IPv4 address of their own, only a share of a NAT64 pool at up to 256 homes per address, with fewer refunds than CGNAT at the same ratio. The bank's Address space section shows your homes as public, behind CGNAT and IPv6-only, with the NAT64 ratio next to the CGNAT one, and says which of the two to stretch when space runs out. diff --git a/src/game/80-simulation/50-sanitize.js b/src/game/80-simulation/50-sanitize.js index d90f002..b542bcd 100644 --- a/src/game/80-simulation/50-sanitize.js +++ b/src/game/80-simulation/50-sanitize.js @@ -82,7 +82,7 @@ function sanitize(s){ for(const l of s.links){const v=l.lay;if(v===undefined)continue;if(!(v&&typeof v==='object'&&!Array.isArray(v)&&l.kind==='df'&&l.own&&l.sub&&l.ready>s.day)){delete l.lay;continue;} const t=Math.round(clamp(num(v.t,s.day),0,l.ready));l.lay={s:Math.round(clamp(num(v.s,s.day),0,Math.min(s.day,t))),q:clamp(num(v.q,0),0,1),t};}} s.loans=s.loans.filter(l=>l&&own(BANKS,l.bank));for(const l of s.loans){if(l.model!==undefined&&!['balloon','storm','transit','astro'].includes(l.model))delete l.model;for(const k of ['apr0','cut','share'])if(l[k]!==undefined&&!isFinite(+l[k]))delete l[k];if(!Array.isArray(l.covs))l.covs=[];l.covs=l.covs.filter(c=>own(COVS,c));}s.loanOffers=s.loanOffers.filter(l=>l&&own(BANKS,l.bank)); - s.usedNames=[...new Set(s.usedNames.filter(x=>typeof x==='string'))];s.log=s.log.filter(e=>e&&typeof e.t==='string').slice(0,LOG_KEEP).map(e=>{const o=e.o&&typeof e.o==='object'&&e.o.a==='inbox'?{a:'tab',v:'nets'}:e&&e.o&&typeof e.o==='object'&&LOG_OPEN.includes(e.o.a)?(e.o.a==='bank'||e.o.a==='ops'?{a:e.o.a}:typeof e.o.v==='string'&&e.o.v.length<=64&&(e.o.a!=='city'||isCity(e.o.v))&&(e.o.a!=='tab'||LOG_TABS.includes(e.o.v))?{a:e.o.a,v:e.o.v}:null):null; + s.usedNames=[...new Set(s.usedNames.filter(x=>typeof x==='string'))];s.log=s.log.filter(e=>e&&typeof e.t==='string').slice(0,LOG_KEEP).map(e=>{const o=e.o&&typeof e.o==='object'&&e.o.a==='inbox'?{a:'tab',v:'nets'}:e&&e.o&&typeof e.o==='object'&&LOG_OPEN.includes(e.o.a)?(e.o.a==='bank'||e.o.a==='ip4'||e.o.a==='ops'?{a:e.o.a}:typeof e.o.v==='string'&&e.o.v.length<=64&&(e.o.a!=='city'||isCity(e.o.v))&&(e.o.a!=='tab'||LOG_TABS.includes(e.o.v))?{a:e.o.a,v:e.o.v}:null):null; return {id:typeof e.id==='string'&&e.id.length<=40?e.id:uid(),d:num(e.d,0),t:e.t.slice(0,600),h:typeof e.h==='string'?e.h.slice(0,200):'',k:LOG_KINDS.includes(e.k)?e.k:'',at:Number.isFinite(+e.at)?+e.at:0,o,n:int(e.n,1,9999,1)};}); // One scrubbing center became a list (#117): older saves carry theirs over. if(!Array.isArray(s.scrubs))s.scrubs=s.scrubAt&&isCity(s.scrubAt)?[{city:s.scrubAt,tier:s.scrubTier}]:[];delete s.scrubAt;delete s.scrubTier; diff --git a/src/game/90-actions/10-interface.js b/src/game/90-actions/10-interface.js index 3bd9588..2871fb0 100644 --- a/src/game/90-actions/10-interface.js +++ b/src/game/90-actions/10-interface.js @@ -46,7 +46,7 @@ const ACT={ if(o.a==='city'&&isCity(o.v)){ACT.focusCity({city:o.v});return;} if(o.a==='link'){if(S.links.some(l=>l.id===o.v)){ACT.selLink({id:o.v});return;}toast(tr('interface.that_link_is_gone_it_was'),'');return;} if(o.a==='cust'){if(S.biz.some(b=>b.id===o.v)){ACT.custGo({id:o.v});return;}toast(tr('interface.that_customer_is_gone_the_contract'),'');return;} - if(o.a==='bank'){ACT.bank({});return;}if(o.a==='ops'){ACT.opsOpen();return;}if(o.a==='tab'&&LOG_TABS.includes(o.v))ACT.leftTab({t:o.v});}, + if(o.a==='ip4'&&ip4On()){ACT.ip4Open();return;}if(o.a==='bank'||o.a==='ip4'){ACT.bank({});return;}if(o.a==='ops'){ACT.opsOpen();return;}if(o.a==='tab'&&LOG_TABS.includes(o.v))ACT.leftTab({t:o.v});}, logAll:()=>{UI.logAll=!UI.logAll;renderLeft();}, findOpen:()=>findOpen(), findGo:({city})=>{if(!isCity(city))return;closeModal();$('dash').hidden=true;ACT.focusCity({city});}, diff --git a/src/game/94-dashboard/90-noc-window.js b/src/game/94-dashboard/90-noc-window.js index 49ff64b..fbfb15c 100644 --- a/src/game/94-dashboard/90-noc-window.js +++ b/src/game/94-dashboard/90-noc-window.js @@ -6,7 +6,7 @@ const NOC_HB=3000,NOC_LOST=10000,NOC_GAP=1000; // What a click in the window does: changes only its own view, or runs in the game. Every button the dashboard draws is in one list. const NOC_LOCAL=['chartToggle','connCity','connF','connNet','connSort','custCity','custF','custSort','dashClose','dashSort','dashTab','listMore','popsReg','popsSort']; -const NOC_GO=['buyIx','buyNni','buyTransit','cache','connCancel','custGo','dashLink','goConn','lagIx','lagNni','lagP','lagT','leaseSwap','mktCfg','mktHold','mktRoute','netFocus','opsOpen','pni','pniAllOpen','popGo']; +const NOC_GO=['buyIx','buyNni','buyTransit','cache','connCancel','custGo','dashLink','goConn','ip4Open','lagIx','lagNni','lagP','lagT','leaseSwap','mktCfg','mktHold','mktRoute','netFocus','opsOpen','pni','pniAllOpen','popGo']; const NOC={win:false,id:null,ctl:null,st:null,stId:null,peer:false,until:0,dirty:false,sent:0,speed:1,hid:false,yoAt:0,gone:false}; {const id=RW_IN?null:new URLSearchParams(location.search).get('noc');if(slotOkId(id)){NOC.win=true;NOC.id=id;}} if(!RW_IN)try{if(typeof BroadcastChannel==='function'){NOC.ctl=new BroadcastChannel('sot-noc');NOC.ctl.onmessage=e=>{const m=e.data;if(!m||typeof m!=='object'||!slotOkId(m.id))return;if(NOC.win)nocWinMsg(m);else nocGameMsg(m);};}}catch(e){} diff --git a/src/game/95-modals/20-notifications.js b/src/game/95-modals/20-notifications.js index f49fe4e..1a2be8a 100644 --- a/src/game/95-modals/20-notifications.js +++ b/src/game/95-modals/20-notifications.js @@ -1,9 +1,9 @@ /* ---------- notifications: the NOC keeps the last ten minutes, readable and openable ---------- */ -const LOG_KEEP=60,LOG_MS=10*60*1000,LOG_KINDS=['','good','bad','goal'],LOG_OPEN=['city','link','cust','bank','tab','ops'],LOG_TABS=['goals','deals','noc','nets']; +const LOG_KEEP=60,LOG_MS=10*60*1000,LOG_KINDS=['','good','bad','goal'],LOG_OPEN=['city','link','cust','bank','ip4','tab','ops'],LOG_TABS=['goals','deals','noc','nets']; // What a notification is about, from the button it came with: the same place its own button would take you. function openOf(actions){for(const a of actions||[]){const g=a.args||{}; if(a.act==='focusCity'&&isCity(g.city))return {a:'city',v:g.city};if(a.act==='selLink'&&g.id)return {a:'link',v:String(g.id)}; - if(a.act==='custGo'&&g.id)return {a:'cust',v:String(g.id)};if(a.act==='bank')return {a:'bank'};if(a.act==='leftTab'&&LOG_TABS.includes(g.t))return {a:'tab',v:g.t};}return null;} + if(a.act==='custGo'&&g.id)return {a:'cust',v:String(g.id)};if(a.act==='bank')return {a:'bank'};if(a.act==='ip4Open')return {a:'ip4'};if(a.act==='leftTab'&&LOG_TABS.includes(g.t))return {a:'tab',v:g.t};}return null;} // Otherwise from the text: a link between two of your cities it names, or the first of your cities it names. function openFromText(t){const cs=Object.keys(S.pops).map(c=>[c,t.indexOf(CITY[c].name)]).filter(([,i])=>i>=0).sort((a,b)=>a[1]-b[1]).map(([c])=>c); if(cs.length>=2){const l=S.links.find(l=>(l.a===cs[0]&&l.b===cs[1])||(l.a===cs[1]&&l.b===cs[0]));if(l)return {a:'link',v:l.id};}return cs.length?{a:'city',v:cs[0]}:null;} diff --git a/tests/address-space.test.js b/tests/address-space.test.js index e3017db..544d11f 100644 --- a/tests/address-space.test.js +++ b/tests/address-space.test.js @@ -330,6 +330,40 @@ test('the day says it once when homes go behind CGNAT, and when even CGNAT canno assert.deepEqual(errors, []); }); +// The notices came with an Address space button, but their line in the NOC's notifications had no Open: the log did not +// know the button (openOf), so it fell back to the text, which names no POP. Open now goes where the button went. +test('an address-space notice in the notifications opens the bank at its Address space, and the NOC window may ask for it', (t) => { + const { ev, dom, errors } = game(t); + const doc = dom.window.document; + // Where the bank scrolls to: the Address space's own button scrolls it into view. + ev("S.log=[];window.__into=[];(()=>{const s=Element.prototype.scrollIntoView;Element.prototype.scrollIntoView=function(){__into.push(this.id);if(s)return s.apply(this,arguments);};})()"); + homes(ev, 250); + ev('ip4Day(S.day)'); + assert.match(ev('S.log[0].t'), /Your IPv4 is full/); + assert.deepEqual(J(ev, 'S.log[0].o'), { a: 'ip4' }); + ev("closeModal();ACT.leftTab({t:'noc'})"); + const b = doc.querySelector(`#leftBody [data-act=logOpen][data-args='${lit({ id: ev('S.log[0].id') })}']`); + assert.ok(b, 'the notice has an Open button'); + b.click(); + assert.equal(doc.getElementById('bankBox').hidden, false, 'the bank is open'); + assert.ok(doc.getElementById('bankIp4')); + assert.deepEqual(J(ev, '__into'), ['bankIp4'], 'at its Address space'); + // A renewal that could not grow carries the same button. + biz(ev, { id: 'h1', name: 'Hoster' }); + ev("ACT.bankClose();S.log=[];ip4News([[S.biz.find(b=>b.id==='h1'),20]])"); + assert.deepEqual(J(ev, 'S.log[0].o'), { a: 'ip4' }); + // Kept in the save; with IPv4 off (a save from a gentler preset) it still opens the bank. + ev("S=migrate(JSON.parse(JSON.stringify(S)));"); + assert.deepEqual(J(ev, 'S.log[0].o'), { a: 'ip4' }); + ev("ACT.bankClose();S.rules.ip4=false;__into.length=0;ACT.logOpen({id:S.log[0].id})"); + assert.equal(ev('ip4On()'), false); + assert.equal(doc.getElementById('bankBox').hidden, false); + assert.deepEqual(J(ev, '__into'), []); + // The NOC window's clicks run in the game only from its list; the address space is on it (#150). + assert.ok(ev("NOC_GO.includes('ip4Open')&&!NOC_LOCAL.includes('ip4Open')")); + assert.deepEqual(errors, []); +}); + test('rule off means no effect: gentler presets, sandbox, puzzles and scenarios unless they opt in', (t) => { const { ev, dom, errors } = game(t); assert.deepEqual(J(ev, "['soft','freeze','oncall','bgp','sandbox','puzzle'].map(p=>makeRules(p).ip4)"), [false, false, null, null, false, false], 'On-call and BGP keep the default (on), written nowhere');