Merge pull request #25 from daniloctdev/fix/rival-ix-depeer-crash

Fix the game freezing when a peer drops you at a rival exchange
This commit is contained in:
Frederic Jung 2026-10-24 21:00:10 +02:00 • committed by GitHub
commit 16e1f95d1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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, []);
});