Fix the game freezing when a peer drops you at a rival exchange

Peering sessions at a second or third exchange in a city are keyed like
"drz@mil~2". The de-peering toast looked the city up as CITY['mil~2'],
threw, and the exception stopped the animation loop for good: time and
the map froze until a reload.
This commit is contained in:
Danilo Carbonaro 2026-10-24 18:18:47 +02:00
parent 56e15d10dd
commit ba1c1e1a35
2 changed files with 12 additions and 1 deletions

View file

@ -1889,7 +1889,7 @@ function dayTick(){
if(R&&R.demand>0)S.stats.clean=R.served/R.demand>=0.995?(S.stats.clean||0)+1:0;
if(S.ev.php===d)toast('<b>The internet is back.</b><br>Half of it, anyway. Everything was patched in a hurry and nobody learned anything.','good');
for(const k in S.peers){const [id,c]=k.split('@'),sn=snub(id,c);if(!sn)continue;delete S.peers[k];S.stats.depeered=(S.stats.depeered||0)+1;
toast(`<b>${esc(NET[id].name)} de-peered you in ${esc(CITY[c].name)}.</b><br>${esc(sn.why)} Traffic falls back to your next best path.`,'bad');}
toast(`<b>${esc(NET[id].name)} de-peered you in ${esc(CITY[ixCity(c)].name)}.</b><br>${esc(sn.why)} Traffic falls back to your next best path.`,'bad');}
if(S.cnLic&&S.cnLic.state==='pending'&&d>=S.cnLic.ready){S.cnLic.state='ok';toast('<b>License granted!</b><br>Your joint venture can now build POPs in mainland China.','goal');sfx('coin');}
// resolve incidents
for(const i of S.inc.slice())if(i.until<=d){clearInc(i);toast(`<b>Resolved:</b> ${incTitle(i.type).toLowerCase()} is fixed.`,'good');}

View file

@ -113,3 +113,14 @@ test('DE-KICKS hides prices, haggles, harmonises upwards, auto-enrolls add-ons a
assert.equal(ev("ixPortMo('ams',1)"), ev("Math.round(PORT[1].ix*ixMul('ams'))"), 'other IXs keep open pricing');
assert.deepEqual(errors, []);
});
test('a peer at a rival exchange can de-peer you without stopping the game', () => {
const { ev, errors } = load();
ev('ACT.start({})');
const ix = ev('Object.keys(XIXM)[0]');
ev(`S.peers['ggl@${ix}']=true;window.snub=()=>({why:'Testing.'})`);
ev('dayTick()');
assert.equal(ev(`'ggl@${ix}' in S.peers`), false);
assert.match(ev("document.getElementById('toasts').textContent"), new RegExp(`de-peered you in ${ev(`CITY[ixCity('${ix}')].name`)}`));
assert.deepEqual(errors, []);
});