Six actions look up their city among the network's own POPs only
launchBB, addSite, addRouter, upRouter, addGen and myIxUp read S.pops[city]
(S.myIx[city]) without checking the key, so a city named '__proto__' found
Object.prototype and wrote to it (launchBB left Object.prototype.bb behind,
and every for…in after it saw that), and 'constructor' spent cash on
statics of Object. Only an MCP agent or a request to a server-run network
can send such a city; the page's own buttons never do. Each now takes the
POP only when it is an own key (own(), as sanitize() does).
tests/act-args-builtins.test.js sends every action an agent may send with
'__proto__', 'constructor' and 'prototype' in each usual arg and checks
that the page's built-ins stay as they were; without this change it finds
exactly these six. No state, strings or saves change.
Performance on the big network against 61e31c5 (npm run perf, headless,
median of 15 runs, ms):
| What | Base | This | Change | p |
|---|--:|--:|--:|--:|
| Routing: compute() | 25.4 | 28.1 | +11% | 0.90 |
| One game day: dayTick() | 27.8 | 28.7 | +3% | 0.77 |
| An action: after() | 1.82 | 1.77 | -3% | 0.77 |
| Side panel and left list | 58.8 | 57.1 | -3% | 0.013 |
| NOC dashboard tabs | 95.9 | 95.9 | +0% | 1.00 |
| Map at three zoom levels | 3.49 | 3.30 | -6% | 0.53 |
| The NOC intern's shift: opsDay() | 3.45 | 3.52 | +2% | 0.80 |
Routing results are identical to the base; no slowdowns beyond noise.
This commit is contained in:
parent
9597d89079
commit
77f4035853
6 changed files with 43 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
Object.assign(ACT,{
|
Object.assign(ACT,{
|
||||||
buildPop:({city})=>{if(S.pops[city]||!CITY[city])return;if(!cityOn(city)){toast(popOffWhy(city),'bad');sfx('err');return;}const flipNote=CITY[city]&&CITY[city].au;if(cnCity(city)&&!cnOk()){toast(tr('pops_transit_ix.you_need_a_license_first_foreign'),'bad');sfx('err');return;}if(!spend(popCost(city)))return;S.pops[city]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};popStdApply(city);floater(CITY[city].x,CITY[city].y-30,tr('common.new_pop'),'#FF4F9A');if(flipNote)toast(pick([tr('pops_transit_ix.router_installed_in_city_upside_down',{city:CITY[city].name}),tr('pops_transit_ix.router_installed_in_city_the_vendor',{city:CITY[city].name})]),'good',[],{a:'city',v:city});UI.tab='cust';after();},
|
buildPop:({city})=>{if(S.pops[city]||!CITY[city])return;if(!cityOn(city)){toast(popOffWhy(city),'bad');sfx('err');return;}const flipNote=CITY[city]&&CITY[city].au;if(cnCity(city)&&!cnOk()){toast(tr('pops_transit_ix.you_need_a_license_first_foreign'),'bad');sfx('err');return;}if(!spend(popCost(city)))return;S.pops[city]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};popStdApply(city);floater(CITY[city].x,CITY[city].y-30,tr('common.new_pop'),'#FF4F9A');if(flipNote)toast(pick([tr('pops_transit_ix.router_installed_in_city_upside_down',{city:CITY[city].name}),tr('pops_transit_ix.router_installed_in_city_the_vendor',{city:CITY[city].name})]),'good',[],{a:'city',v:city});UI.tab='cust';after();},
|
||||||
launchBB:({city})=>{const p=S.pops[city];if(!p||p.bb)return;const C=CITY[city];if(!spend(bbCost(city)))return;p.bb={d:bbStart(city)};floater(C.x,C.y-30,tr('common.eyeballs_online'),'#16A866');after();},
|
launchBB:({city})=>{const p=own(S.pops,city)&&S.pops[city];if(!p||p.bb)return;const C=CITY[city];if(!spend(bbCost(city)))return;p.bb={d:bbStart(city)};floater(C.x,C.y-30,tr('common.eyeballs_online'),'#16A866');after();},
|
||||||
ad:({city})=>{const p=S.pops[city];if(!p||!p.bb)return;if(!spend(8000))return;p.boost=S.day+30;floater(CITY[city].x,CITY[city].y-30,tr('common.ad_campaign'),'#FF8A3D');after();},
|
ad:({city})=>{const p=S.pops[city];if(!p||!p.bb)return;if(!spend(8000))return;p.boost=S.day+30;floater(CITY[city].x,CITY[city].y-30,tr('common.ad_campaign'),'#FF8A3D');after();},
|
||||||
// A new port has every field sanitize() gives one, so live S is what a reload makes of it.
|
// A new port has every field sanitize() gives one, so live S is what a reload makes of it.
|
||||||
buyTransit:({city,net,tier})=>{tier=+tier;if(scnRule('noTransit')){toast(tr('pops_transit_ix.no_transit_in_this_scenario_peering'),'bad');sfx('err');return;}if(!S.pops[city]||!NET[net]||!sellsAt(NET[net],city)||!PORT[tier])return;if(!portOk(city,tier)){toast(tr('actions.your_router_can_t_take_a',{port:PORT[tier].n}),'bad');sfx('err');return;}const ex=S.transit.find(t=>t.city===city&&t.net===net);if(ex&&tier<=ex.tier)return;if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend(PORT[tier].setup*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else{const pr=premOnlyAt(NET[net],city);S.transit.push({id:uid(),city,net,tier,down:0,...(pr?{premium:true}:{}),lacp:null,site:'a',n:1,clean:false,...(pr?{}:{premium:false})});}toast(tr('pops_transit_ix.net_transit_is_live_in_city',{net:esc(NET[net].name),city:CITY[city].name}),'good');after();},
|
buyTransit:({city,net,tier})=>{tier=+tier;if(scnRule('noTransit')){toast(tr('pops_transit_ix.no_transit_in_this_scenario_peering'),'bad');sfx('err');return;}if(!S.pops[city]||!NET[net]||!sellsAt(NET[net],city)||!PORT[tier])return;if(!portOk(city,tier)){toast(tr('actions.your_router_can_t_take_a',{port:PORT[tier].n}),'bad');sfx('err');return;}const ex=S.transit.find(t=>t.city===city&&t.net===net);if(ex&&tier<=ex.tier)return;if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend(PORT[tier].setup*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else{const pr=premOnlyAt(NET[net],city);S.transit.push({id:uid(),city,net,tier,down:0,...(pr?{premium:true}:{}),lacp:null,site:'a',n:1,clean:false,...(pr?{}:{premium:false})});}toast(tr('pops_transit_ix.net_transit_is_live_in_city',{net:esc(NET[net].name),city:CITY[city].name}),'good');after();},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Object.assign(ACT,{
|
Object.assign(ACT,{
|
||||||
addSite:({city})=>{const p=S.pops[city];if(!p||p.site2)return;if(!spend(SITE2_COST))return;p.site2=true;p.site2Day=S.day;toast(tr('sites_peering_caches.second_site_live_in_city_b',{city:CITY[city].name,b:esc(siteName(city,'b')),a:esc(siteName(city,'a'))}),'good');sfx('build');after();},
|
addSite:({city})=>{const p=own(S.pops,city)&&S.pops[city];if(!p||p.site2)return;if(!spend(SITE2_COST))return;p.site2=true;p.site2Day=S.day;toast(tr('sites_peering_caches.second_site_live_in_city_b',{city:CITY[city].name,b:esc(siteName(city,'b')),a:esc(siteName(city,'a'))}),'good');sfx('build');after();},
|
||||||
rmSite:({city})=>{const p=S.pops[city];if(!p||!p.site2)return;if(UI.confirm!=='site'+city){UI.confirm='site'+city;renderPanel();return;}UI.confirm=null;p.site2=0;p.sdown=null;p.ringcut=0;for(const t of S.transit)if(t.city===city)t.site='a';for(const x of S.pni)if(x.city===city)x.site='a';for(const x of S.caches)if(x.city===city)x.site='a';if(S.ixSite)for(const x of ixIdsIn(city))delete S.ixSite[x];after();},
|
rmSite:({city})=>{const p=S.pops[city];if(!p||!p.site2)return;if(UI.confirm!=='site'+city){UI.confirm='site'+city;renderPanel();return;}UI.confirm=null;p.site2=0;p.sdown=null;p.ringcut=0;for(const t of S.transit)if(t.city===city)t.site='a';for(const x of S.pni)if(x.city===city)x.site='a';for(const x of S.caches)if(x.city===city)x.site='a';if(S.ixSite)for(const x of ixIdsIn(city))delete S.ixSite[x];after();},
|
||||||
siteSet:({k,id,s})=>{if(!['a','b','ab'].includes(s))return;
|
siteSet:({k,id,s})=>{if(!['a','b','ab'].includes(s))return;
|
||||||
const o=k==='t'?S.transit.find(x=>x.id===id):k==='p'?S.pni.find(x=>x.id===id):null;if(k!=='ix'&&!o)return;if(k==='ix'&&(!isIx(id)||S.ixp[id]===undefined||!S.pops[ixCity(id)]))return;
|
const o=k==='t'?S.transit.find(x=>x.id===id):k==='p'?S.pni.find(x=>x.id===id):null;if(k!=='ix'&&!o)return;if(k==='ix'&&(!isIx(id)||S.ixp[id]===undefined||!S.pops[ixCity(id)]))return;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Object.assign(ACT,{
|
||||||
// At sea, paying means a private charter: another ship sails, it does not appear (50-cable-ships.js).
|
// At sea, paying means a private charter: another ship sails, it does not appear (50-cable-ships.js).
|
||||||
if(shipSea(i)){if(shipRush(i)){const s=SHIP[i.ship];toast(tr('cable_ships.ship_chartered',{ship:esc(s.n),home:esc(CITY[s.home].name),n:Math.max(1,i.until-S.day)}),'good');sfx('coin');after();}return;}if(i.slow&&i.rushed)return;if(!spend(i.cost))return;
|
if(shipSea(i)){if(shipRush(i)){const s=SHIP[i.ship];toast(tr('cable_ships.ship_chartered',{ship:esc(s.n),home:esc(CITY[s.home].name),n:Math.max(1,i.until-S.day)}),'good');sfx('coin');after();}return;}if(i.slow&&i.rushed)return;if(!spend(i.cost))return;
|
||||||
if(i.slow&&i.until>S.day+1){i.rushed=true;i.cost=0;i.until=S.day+1;const p=S.pops[i.ref];if(p)p.down=Math.min(p.down,S.day+1);toast(tr('links.power_cycled_the_router_in_city',{city:esc(CITY[i.ref].name),chip:esc(RG[(p&&p.rgen)||0].chip)}),'good');after();return;}clearInc(i);toast(tr('links.fixed_what_resolved_early',{what:incTitle(i.type)}),'good');after();},
|
if(i.slow&&i.until>S.day+1){i.rushed=true;i.cost=0;i.until=S.day+1;const p=S.pops[i.ref];if(p)p.down=Math.min(p.down,S.day+1);toast(tr('links.power_cycled_the_router_in_city',{city:esc(CITY[i.ref].name),chip:esc(RG[(p&&p.rgen)||0].chip)}),'good');after();return;}clearInc(i);toast(tr('links.fixed_what_resolved_early',{what:incTitle(i.type)}),'good');after();},
|
||||||
myIxUp:({city})=>{const m=S.myIx[city];if(!m)return;const f=(m.fab|0)+1,N=MYIX_FAB[f];if(!N)return;if(N.lvl>lvl()){toast(tr('links.a_fab_fabric_unlocks_at_customer',{fab:N.n,lv:N.lvl}),'bad');sfx('err');return;}if(!spend(N.cost))return;m.fab=f;toast(tr('links.ix_now_runs_a_fab_fabric',{ix:esc(m.name),fab:N.n,max:N.max}),'good');m.next=Math.min(m.next,S.day+3);after();},
|
myIxUp:({city})=>{const m=own(S.myIx,city)&&S.myIx[city];if(!m)return;const f=(m.fab|0)+1,N=MYIX_FAB[f];if(!N)return;if(N.lvl>lvl()){toast(tr('links.a_fab_fabric_unlocks_at_customer',{fab:N.n,lv:N.lvl}),'bad');sfx('err');return;}if(!spend(N.cost))return;m.fab=f;toast(tr('links.ix_now_runs_a_fab_fabric',{ix:esc(m.name),fab:N.n,max:N.max}),'good');m.next=Math.min(m.next,S.day+3);after();},
|
||||||
foundIx:({city})=>{if(!isCity(city))return;const why=foundIxWhy(city);if(why){toast(why,'bad');sfx('err');return;}if(!spend(MYIX_COST))return;const nm=(S.name.split(' ')[0]||'My').replace(/[^A-Za-z0-9]/g,'').slice(0,10)+'-IX '+CITY[city].name;
|
foundIx:({city})=>{if(!isCity(city))return;const why=foundIxWhy(city);if(why){toast(why,'bad');sfx('err');return;}if(!spend(MYIX_COST))return;const nm=(S.name.split(' ')[0]||'My').replace(/[^A-Za-z0-9]/g,'').slice(0,10)+'-IX '+CITY[city].name;
|
||||||
S.myIx[city]={name:nm,members:[],next:S.day+4,fab:0};S.ixp[city]=2;toast(tr('links.you_founded_ix_networks_will_join',{ix:esc(nm)}),'goal');after();},
|
S.myIx[city]={name:nm,members:[],next:S.day+4,fab:0};S.ixp[city]=2;toast(tr('links.you_founded_ix_networks_will_join',{ix:esc(nm)}),'goal');after();},
|
||||||
buildLink:({tier})=>{tier=+tier;const p=UI.pending;if(!p||noTalk(p.a,p.b))return;const {a,b}=p;const km=kmBetween(a,b),sub=isSub(a,b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat'),jn=sib.length?routeJoin(a,b):null,same=!!jn,border=cnCity(a)!==cnCity(b),mult=(sib.length&&!(jn&&jn.k===(landTrenches(a,b)[0]||{}).k)?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1);
|
buildLink:({tier})=>{tier=+tier;const p=UI.pending;if(!p||noTalk(p.a,p.b))return;const {a,b}=p;const km=kmBetween(a,b),sub=isSub(a,b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'&&l.kind!=='xp'&&l.kind!=='sat'),jn=sib.length?routeJoin(a,b):null,same=!!jn,border=cnCity(a)!==cnCity(b),mult=(sib.length&&!(jn&&jn.k===(landTrenches(a,b)[0]||{}).k)?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1);
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,10 @@ Object.assign(ACT,{
|
||||||
popStdSet:({city})=>{const p=S.pops[city];if(!p||pzOn())return;S.popStd=bstdPut({...bstd(),g:p.rgen||0,rt:p.routers||1,site2:!!p.site2,gen:!!p.gen});
|
popStdSet:({city})=>{const p=S.pops[city];if(!p||pzOn())return;S.popStd=bstdPut({...bstd(),g:p.rgen||0,rt:p.routers||1,site2:!!p.site2,gen:!!p.gen});
|
||||||
toast(tr('pop_std.new_pops_now_start_with_list',{list:esc(bstdPopParts(bstd()).join(', '))}),'good');sfx('click');after();if(bstdShown())bstdModal();},
|
toast(tr('pop_std.new_pops_now_start_with_list',{list:esc(bstdPopParts(bstd()).join(', '))}),'good');sfx('click');after();if(bstdShown())bstdModal();},
|
||||||
popStdClear:()=>{S.popStd=null;sfx('click');after();if(bstdShown())bstdModal();},
|
popStdClear:()=>{S.popStd=null;sfx('click');after();if(bstdShown())bstdModal();},
|
||||||
addRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)>=RMAX)return;if(!spend(routerCost(p.rgen||0,p.routers||1)))return;p.routers=(p.routers||1)+1;floater(CITY[city].x,CITY[city].y-30,tr('common.router_added'),'#FF4F9A');after();},
|
addRouter:({city})=>{const p=own(S.pops,city)&&S.pops[city];if(!p||(p.routers||1)>=RMAX)return;if(!spend(routerCost(p.rgen||0,p.routers||1)))return;p.routers=(p.routers||1)+1;floater(CITY[city].x,CITY[city].y-30,tr('common.router_added'),'#FF4F9A');after();},
|
||||||
models:()=>{UI.models=!UI.models;renderPanel();},
|
models:()=>{UI.models=!UI.models;renderPanel();},
|
||||||
rmRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)<=1)return;if(portsUsed(city)>portsMax(city,undefined,p.routers-1)){toast(tr('routing_and_routers.unplug_something_first_used_ports',{used:fmtPorts(portsUsed(city)),max:portsMax(city,undefined,p.routers-1)}),'bad');sfx('err');return;}p.routers--;{const back=tradeIn(p.rgen||0,1);if(back>0){S.cash+=back;toast(tr('routing_and_routers.sold_a_model_on_ebuy_price',{model:esc(RG[p.rgen||0].n),price:fmt$(back)}),'good');}}after();},
|
rmRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)<=1)return;if(portsUsed(city)>portsMax(city,undefined,p.routers-1)){toast(tr('routing_and_routers.unplug_something_first_used_ports',{used:fmtPorts(portsUsed(city)),max:portsMax(city,undefined,p.routers-1)}),'bad');sfx('err');return;}p.routers--;{const back=tradeIn(p.rgen||0,1);if(back>0){S.cash+=back;toast(tr('routing_and_routers.sold_a_model_on_ebuy_price',{model:esc(RG[p.rgen||0].n),price:fmt$(back)}),'good');}}after();},
|
||||||
upRouter:({city,g})=>{const p=S.pops[city];if(!p)return;g=g===undefined?mainRG(RG[p.rgen||0].cls+1):+g;if(!RG[g]||g===(p.rgen||0))return;{const why=modelFits(city,g);if(why){toast(tr('routing_and_routers.the_model_won_t_fit_why',{model:esc(RG[g].n),why:esc(why)}),'bad');sfx('err');return;}}if(!techOk('rg',g,RG[g].lvl)){toast(tr('routing_and_routers.model_unlocks_at_customer_level_lv',{model:esc(RG[g].n),lv:RG[g].lvl}),'bad');sfx('err');return;}
|
upRouter:({city,g})=>{const p=own(S.pops,city)&&S.pops[city];if(!p)return;g=g===undefined?mainRG(RG[p.rgen||0].cls+1):+g;if(!RG[g]||g===(p.rgen||0))return;{const why=modelFits(city,g);if(why){toast(tr('routing_and_routers.the_model_won_t_fit_why',{model:esc(RG[g].n),why:esc(why)}),'bad');sfx('err');return;}}if(!techOk('rg',g,RG[g].lvl)){toast(tr('routing_and_routers.model_unlocks_at_customer_level_lv',{model:esc(RG[g].n),lv:RG[g].lvl}),'bad');sfx('err');return;}
|
||||||
const rt=p.routers||1,old=p.rgen||0;if(p.rupDay===S.day){toast(tr('routing_and_routers.the_new_routers_in_city_are',{city:CITY[city].name}),'bad');sfx('err');return;}const back=tradeIn(old,rt);if(!spend(swapCost(city,g)))return;p.rgen=g;p.rupDay=S.day;if(back>0)toast(tr('routing_and_routers.sold_the_old_model_on_ebuy',{model:esc(RG[old].n),price:fmt$(back)}),'good');
|
const rt=p.routers||1,old=p.rgen||0;if(p.rupDay===S.day){toast(tr('routing_and_routers.the_new_routers_in_city_are',{city:CITY[city].name}),'bad');sfx('err');return;}const back=tradeIn(old,rt);if(!spend(swapCost(city,g)))return;p.rgen=g;p.rupDay=S.day;if(back>0)toast(tr('routing_and_routers.sold_the_old_model_on_ebuy',{model:esc(RG[old].n),price:fmt$(back)}),'good');
|
||||||
if(rt===1&&popIdle(city))toast(tr('routing_and_routers.new_router_in_city_swapped_before',{city:CITY[city].name}),'good');
|
if(rt===1&&popIdle(city))toast(tr('routing_and_routers.new_router_in_city_swapped_before',{city:CITY[city].name}),'good');
|
||||||
else if(rt===1){const sl=slowBoot(city),dd=sl?3:1;p.down=Math.max(p.down||0,S.day+dd);addInc({type:'maint',ref:city,until:S.day+dd,msg:sl?tr('routing_and_routers.swapping_the_only_router_in_city',{city:CITY[city].name,model:RG[g].n,how:pick(SLOW_BOOT),n:dd}):tr('routing_and_routers.swapping_the_only_router_in_city_d5b5',{city:CITY[city].name,model:RG[g].n}),cost:0});toast(`<b>${tr('routing_and_routers.maintenance_window_in_city',{city:CITY[city].name})}</b><br>${sl?tr('routing_and_routers.one_router_and_this_one_takes',{n:dd}):tr('routing_and_routers.one_router_means_downtime_during_the')}`,'bad');}
|
else if(rt===1){const sl=slowBoot(city),dd=sl?3:1;p.down=Math.max(p.down||0,S.day+dd);addInc({type:'maint',ref:city,until:S.day+dd,msg:sl?tr('routing_and_routers.swapping_the_only_router_in_city',{city:CITY[city].name,model:RG[g].n,how:pick(SLOW_BOOT),n:dd}):tr('routing_and_routers.swapping_the_only_router_in_city_d5b5',{city:CITY[city].name,model:RG[g].n}),cost:0});toast(`<b>${tr('routing_and_routers.maintenance_window_in_city',{city:CITY[city].name})}</b><br>${sl?tr('routing_and_routers.one_router_and_this_one_takes',{n:dd}):tr('routing_and_routers.one_router_means_downtime_during_the')}`,'bad');}
|
||||||
|
|
|
||||||
|
|
@ -38,5 +38,5 @@ Object.assign(ACT,{
|
||||||
layShip:({id})=>{const l=S.links.find(x=>x.id===id);const q=l&&layQuote(l);if(!q||!spend(q.cost))return;l.ship2=1;setCableReady(l,l.ready-q.save);
|
layShip:({id})=>{const l=S.links.find(x=>x.id===id);const q=l&&layQuote(l);if(!q||!spend(q.cost))return;l.ship2=1;setCableReady(l,l.ready-q.save);
|
||||||
toast(trn('cable_ships.second_lay_ship_booked',q.save,{ship:esc(layName(l,1)),n:q.save}),'good');sfx('coin');after();},
|
toast(trn('cable_ships.second_lay_ship_booked',q.save,{ship:esc(layName(l,1)),n:q.save}),'good');sfx('coin');after();},
|
||||||
crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.sub||!crewSteps(l))return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(crewFloor(l),l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('fiber_and_hardware.more_crews_on_site_construction_is',saved,{n:saved}),'good');after();},
|
crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.sub||!crewSteps(l))return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(crewFloor(l),l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('fiber_and_hardware.more_crews_on_site_construction_is',saved,{n:saved}),'good');after();},
|
||||||
addGen:({city})=>{const p=S.pops[city];if(!p||p.gen)return;if(!spend(GEN_COST))return;p.gen=true;floater(CITY[city].x,CITY[city].y-30,tr('common.generator'),'#FF8A3D');after();},
|
addGen:({city})=>{const p=own(S.pops,city)&&S.pops[city];if(!p||p.gen)return;if(!spend(GEN_COST))return;p.gen=true;floater(CITY[city].x,CITY[city].y-30,tr('common.generator'),'#FF8A3D');after();},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
37
tests/act-args-builtins.test.js
Normal file
37
tests/act-args-builtins.test.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
// A click's args name things the game looks up by key: S.pops[city], S.myIx[city]. A city that is '__proto__' or
|
||||||
|
// 'constructor' (an MCP agent's, or a request to a server-run network) must find nothing there, never a prototype or a
|
||||||
|
// built-in's statics: every action that takes one, with each such name in each usual arg, leaves the page's built-ins
|
||||||
|
// as they were and spends nothing on them.
|
||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const { load } = require('./harness');
|
||||||
|
|
||||||
|
const BAD = ['__proto__', 'constructor', 'prototype'];
|
||||||
|
const ARGS = ['city', 'id', 'net', 'k', 'c', 'v', 'a', 'b', 'to', 'from', 'link', 's'];
|
||||||
|
|
||||||
|
test('no action reaches a built-in through an arg that names one', (t) => {
|
||||||
|
// The development page: API_CMD is every action an agent may send (the MCP facade), the sent ones of a server's page.
|
||||||
|
const { ev, errors, dom } = load({ agent: true });
|
||||||
|
t.after(() => dom.window.close());
|
||||||
|
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e12;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;");
|
||||||
|
for (const c of ['fra', 'ams', 'lon', 'par']) ev(`ACT.buildPop({city:'${c}'})`);
|
||||||
|
ev("ACT.launchBB({city:'fra'});closeModal();UI.confirm=null;compute();");
|
||||||
|
// What the built-ins hold now: anything an action adds to them is found by name.
|
||||||
|
ev(`window.__fp=()=>{const o={};for(const [n,x] of [['Object',Object],['Object.prototype',Object.prototype],['Array',Array],['Array.prototype',Array.prototype],['Function.prototype',Function.prototype],['String.prototype',String.prototype]])o[n]=Object.getOwnPropertyNames(x).sort().join(',');
|
||||||
|
const e=[];for(const k in {})e.push(k);for(const k in [])e.push('[]'+k);o.enum=e.join(',');return o;};window.__fp0=__fp();
|
||||||
|
window.__clean=()=>{for(const [n,x] of [['Object',Object],['Object.prototype',Object.prototype],['Array',Array],['Array.prototype',Array.prototype],['Function.prototype',Function.prototype],['String.prototype',String.prototype]]){const had=new Set(__fp0[n].split(','));for(const k of Object.getOwnPropertyNames(x))if(!had.has(k))delete x[k];}};`);
|
||||||
|
const acts = JSON.parse(ev('JSON.stringify(Object.keys(API_CMD).filter(k=>typeof ACT[k]==="function"&&!/^pz[A-Z]/.test(k)))'));
|
||||||
|
const hits = [];
|
||||||
|
for (const act of acts) {
|
||||||
|
for (const name of ARGS) {
|
||||||
|
for (const v of BAD) {
|
||||||
|
const r = JSON.parse(ev(`(()=>{const c0=S.cash;let err=null;try{ACT[${JSON.stringify(act)}]({[${JSON.stringify(name)}]:${JSON.stringify(v)}});}catch(e){err=String(e&&e.message||e);}
|
||||||
|
try{closeModal();}catch(e){}UI.confirm=null;const f=__fp(),d=Object.keys(f).filter(k=>f[k]!==__fp0[k]);if(d.length)__clean();return JSON.stringify({d,spent:c0-S.cash,err});})()`));
|
||||||
|
if (r.d.length) hits.push(`${act}({${name}:'${v}'}) changed ${r.d.join(', ')}${r.spent > 0 ? ` and spent ${r.spent}` : ''}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.diagnostic(`${acts.length} actions × ${ARGS.length} args × ${BAD.length} names`);
|
||||||
|
assert.deepEqual(hits, []);
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue