DDoS attacks are scored and SLA-charged at their victim only
ddosSf() took the worst service of every city with an ingress port, so on a big network every attack counted as lost and charged SLA payouts to protected customers anywhere. Held/lost, the SLA check and the far-scrubbing warning now look at the attacked city.
This commit is contained in:
parent
675c63d561
commit
25e3e6db33
3 changed files with 25 additions and 3 deletions
|
|
@ -37,7 +37,8 @@ function ddosSlices(a){if(!a.entries?.length)return [a];const groups={};
|
|||
return Object.entries(groups).map(([city,entries])=>({...a,parent:a,city,entries,gbps:a.gbps*entries.reduce((n,en)=>n+en.share,0)}));}
|
||||
const ddosCities=a=>[...new Set([a.city,...(a.entries||[]).map(en=>en.city)])].filter(c=>S.pops[c]);
|
||||
const ddosHasIx=a=>ddosCities(a).some(hasIxAt);
|
||||
const ddosSf=a=>Math.min(1,...ddosCities(a).map(c=>sfOf(R,c)));
|
||||
// An attack is held or lost at its victim: the junk lands there, and other POPs' bad days are not the attacker's doing.
|
||||
const ddosSf=a=>sfOf(R,a.city);
|
||||
function ddosReport(a){const ms=(R.ddos||[]).filter(m=>m.attack===a||m.attack.parent===a);if(!ms.length)return ddosMitigation(a);
|
||||
const parts={};for(const m of ms)for(const x of m.sp?.parts||[]){const q=parts[x.city]||(parts[x.city]={city:x.city,tier:x.tier,a:0,cleaned:0});q.a+=x.a;q.cleaned+=x.cleaned;}
|
||||
return {attack:a,blackhole:ms.some(m=>m.blackhole),upstream:ms.some(m=>m.upstream),reaching:ms.reduce((n,m)=>n+m.reaching,0),flowspec:ms.reduce((n,m)=>n+m.flowspec,0),fsMissing:ms.some(m=>m.fsMissing),filtered:ms.reduce((n,m)=>n+m.filtered,0),sp:Object.keys(parts).length?{parts:Object.values(parts)}:null,near:ms.find(m=>m.near)?.near||null,leak:ms.reduce((n,m)=>n+m.leak,0)};}
|
||||
|
|
@ -53,7 +54,7 @@ const fsAt=c=>{const p=S.pops[c];return p?(RG[p.rgen||0].fs||0):0;};
|
|||
function scrubEngaged(atk){return hasScrub()&&(S.scrubMode==='always'||(S.day-(atk.start??S.day))>=SCRUB_DELAY);}
|
||||
// Several centers (#117): the flood goes to the nearest working one, and what it cannot take spills to the next.
|
||||
// A center in another city only helps if the backbone can carry the flood there; routing works that out.
|
||||
const scrubFar=c=>ddosAll().some(a=>ddosCities(a).includes(c))&&(R.haul||[]).find(q=>q.city===c&&q.ms!==null&&q.ms>=SCRUB_FAR_MS)||null;
|
||||
const scrubFar=c=>{for(const a of ddosAll())if(a.city===c){const q=(R.haul||[]).find(q=>q.attack===a.id&&q.city===c&&q.ms!==null&&q.ms>=SCRUB_FAR_MS);if(q)return q;}return null;};
|
||||
function scrubPlan(atk,g=atk.gbps||0,room={},take=null){if(!scrubEngaged(atk))return null;const c=atk.city;const parts=[];
|
||||
for(const x of S.scrubs.filter(x=>popUp(x.city)&&(x.city===c||pathExists(c,x.city))).sort((a,b)=>(a.city===c?0:kmBetween(c,a.city))-(b.city===c?0:kmBetween(c,b.city)))){if(g<=0)break;const cap=SCRUB_TIERS[x.tier||0].g,a=Math.min(g,room[x.city]??cap);if(a<=0)continue;const cleaned=take?take(x,a):a;room[x.city]=(room[x.city]??cap)-cleaned;parts.push({city:x.city,tier:x.tier||0,a,cleaned});g-=cleaned;}
|
||||
return parts.length?{parts,leak:g}:null;}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ function dayTick(){
|
|||
if(l.own&&l.ready>d&&Math.random()<0.012){const extra=10+Math.floor(Math.random()*40);setCableReady(l,l.ready+leadDays(extra));toast(tr('day_tick.construction_delay_n_days_why_a',{n:leadDays(extra),why:pick(l.sub?SEA_DELAYS.map(x=>tr(x)):[tr('day_tick.archaeologists_found_a_roman'),tr('day_tick.a_protected_hamster_species_lives'),tr('day_tick.the_railway_changed_its_mind_about'),tr('day_tick.the_drilling_crew_hit_a_granite'),tr('day_tick.a_town_council_wants_a_public'),tr('day_tick.somebody_else_s_gas_main_was'),tr('day_tick.the_permit_office_lost_your_permit')]),a:CITY[l.a].name,b:CITY[l.b].name}),'bad');}}
|
||||
// DDoS protection SLA: if a protected customer's own city is hit and still goes down, you pay out (once per attack).
|
||||
for(const a of ddosAll()){
|
||||
for(const b of S.biz)if(b.type==='scrub'&&ddosCities(a).includes(b.city)&&!(a.sla||[]).includes(b.id)&&(a.id||b.slaFor!==a.start)&&sfOf(R,b.city)<0.85){
|
||||
for(const b of S.biz)if(b.type==='scrub'&&b.city===a.city&&!(a.sla||[]).includes(b.id)&&(a.id||b.slaFor!==a.start)&&sfOf(R,b.city)<0.85){
|
||||
(a.sla||(a.sla=[])).push(b.id);b.slaFor=a.start;S.cash-=SLA_PEN;b.mood=Math.max(0,b.mood-18);S.stats.sla=(S.stats.sla||0)+1;
|
||||
toast(tr('day_tick.sla_breach_name_the_attack_on',{name:esc(b.name),city:CITY[a.city].name,pen:fmt$(SLA_PEN)}),'bad');sfx('err');}}
|
||||
// businesses mood
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue