web/website/node/world-status.mjs
unimatrixgit 9dcd9b084a Integrate shared planetary inventories and account sales with the current site
Merge the supplied inventory/exchange package into the latest DuneRealms source.
Keep community-reward receipts, verified UUID linking, native menus and current
website artwork, Dutch naming and account controls. Wire the inventory/sales
adapters into the real CP session and verified-link schema, with isolated reads
and honest unconfigured states. Preserve lobby/ender separation and Core-owned
atomic exchange checkpoints.

Validation: website build and 56 tests; 12 inventory/market adapter tests;
Core/Essentials and NPC/Terrain/Lobby builds and tests; local browser inspection
of the themed inventory, mannequin and History of sales with fictional fixtures.
Paper 1.21.8 source only: live 1.21.4 binaries and databases are unchanged.
2026-10-27 19:44:22 +01:00

19 lines
1.5 KiB
JavaScript

const names=[['spacing-guild','Vaerkring'],['arrakis','Arrakduin'],['caladan','Kaladam'],['giedi-prime','Giedermark'],['kaitain','Kaiterhof'],['sigma-draconis-iv','Sigmadraken IV'],['velocity','Velocity']];
export function createWorldStatus(settings,fetcher=fetch){
let cached,inflight,expires=0;
async function check(){
if(!settings.WORLD_STATUS_URL)return {checkedAt:null,available:false,servers:names.map(([id,name])=>({id,name,state:'unknown'}))};
try{
const response=await fetcher(settings.WORLD_STATUS_URL,{signal:AbortSignal.timeout(4500)});
if(!response.ok)throw Error('unavailable');
const data=await response.json();
if(!Number.isSafeInteger(data.checkedAt)||Math.abs(Date.now()-data.checkedAt)>60000||!data.servers)throw Error('stale');
const servers=names.map(([id,name])=>{const row=data.servers[id];if(typeof row?.online!=='boolean'||typeof row?.configured!=='boolean')throw Error('invalid');return {id,name,state:row.online?'online':'offline',configured:row.configured,...(row.online&&Number.isSafeInteger(row.players)&&row.players>=0?{players:row.players}:{})};});
return {checkedAt:data.checkedAt,available:true,servers};
}catch{return {checkedAt:null,available:false,servers:names.map(([id,name])=>({id,name,state:'unknown'}))};}
}
return async()=>{
if(!cached||Date.now()>=expires){inflight||=(async()=>{try{cached=await check();expires=Date.now()+15000;}finally{inflight=null;}})();await inflight;}
return Response.json(cached,{headers:{'Cache-Control':'no-store'}});
};
}