${esc(dateStr(r.s.day))} · ${tr('save.cash_in_the_bank',{cash:fmt$(r.s.cash)})} · ${trn('save.n_pop',Object.keys(r.s.pops).length)} · ${tr('save.saved_by_v_ver',{ver:esc(r.ver)})}
${tr('slots.it_joins_your_networks_on_this')}
${esc(dateStr(r.s.day))} · ${tr('save.cash_in_the_bank',{cash:fmt$(r.s.cash)})} · ${trn('save.n_pop',Object.keys(r.s.pops).length)} · ${tr('save.saved_by_v_ver',{ver:esc(r.ver)})}
${tr('slots.it_joins_your_networks_on_this')}${r.lean?' '+tr('transfer.its_charts_and_news_start_fresh'):''}
${homeWhat()}
-v${APP_VERSION} · ${tr('title.source_on_github')} · ${tr('title.chat_on_signal')} · ${tr('title.cookieless_stats_no_tracking')}
`); +v${APP_VERSION} · ${tr('title.source_on_github')} · ${tr('title.chat_on_signal')} · ${tr('title.cookieless_stats_no_tracking')}
`); $('nmIn').addEventListener('input',e=>{UI.nm=e.target.value;}); $('asnIn').addEventListener('input',e=>{UI.asnTxt=e.target.value.replace(/\D/g,'').slice(0,10);if(e.target.value!==UI.asnTxt)e.target.value=UI.asnTxt;e.target.classList.toggle('bad',!!UI.asnTxt&&!asnOk(+UI.asnTxt));}); } diff --git a/src/game/95-modals/45-slots.js b/src/game/95-modals/45-slots.js index 047c54d..c8dff9b 100644 --- a/src/game/95-modals/45-slots.js +++ b/src/game/95-modals/45-slots.js @@ -19,7 +19,7 @@ function slotRefresh(){const el=$('slotList');if(!el||UI.started)return;const h= function slotMenuHtml(id){const e=slotIdx().find(x=>x.id===id);if(!e)return '';const nm=esc(e.name||tr('common.unnamed_network')); return `${e.at?tr('slots.last_played_ago',{ago:slotAgo(e.at)}):''}${e.size?' · '+tr('slots.size_on_this_device',{size:slotSize(e.size)}):''}
- `;} + `;} const slotSize=n=>n>=1e6?(n/1e6).toFixed(1)+' MB':Math.max(1,Math.round(n/1e3))+' kB'; function slotBusyModal(id){const e=slotIdx().find(x=>x.id===id),nm=esc(e&&e.name||tr('common.unnamed_network')); openModal(`${n>1?tr('transfer.on_your_other_device_open_the_many'):tr('transfer.on_your_other_device_open_the')}
${qrSvg(q,tr('transfer.qr_code_i_of_n',{i:i+1,n}))} + ${n>1?`${tr('transfer.this_network_is_too_big_for')}
`} +${n?tr('transfer.the_codes_leave_out_your_charts')+' ':''}${tr('transfer.nothing_is_uploaded_anywhere_the_codes')}
`;} +function xferRecvHtml(){return `${tr('transfer.on_the_other_device_open_the')}
+ +${tr('transfer.scan_the_next_code_on_your')}
${tr('help.name_as_asn_is_transit_free',{name:esc(S.name),asn:S.asn,days:S.day,n:S.stats.incidents})}
${btn(tr('common.keep_building'),'keepPlaying',{},'pink big')}`);sfx('coin');} function showLose(){openModal(`${tr('help.the_bank_repossessed_your_routers',{name:esc(S.name),days:S.day,peak:fmtG(S.stats.peak)})}
${btn(tr('common.try_again'),'newgame',{},'pink big')}`);if(UI.slot){const id=UI.slot;slotDrop(id);slotFree(id);}} diff --git a/src/game/96-map/95-clicks.js b/src/game/96-map/95-clicks.js index c10b794..9919023 100644 --- a/src/game/96-map/95-clicks.js +++ b/src/game/96-map/95-clicks.js @@ -11,5 +11,5 @@ let PD={t:0,b:null}; document.addEventListener('pointerdown',e=>{PD={t:performance.now(),b:e.target.closest('[data-act]')};},true); function tapOk(e,b){if(!e.isTrusted||!PD.t||e.detail===0)return true;const now=performance.now();if(now-PD.t>4000)return true; if(PD.b!==b)return false;if((UI.layerAt||0)>PD.t)return false;const ts=b.closest('.toast');if(ts&&PD.t-(+ts.dataset.born||0)<500)return false;return true;} -document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;if(!$('modal').hidden&&!b.closest('#modal'))return;if(!tapOk(e,b))return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','keys','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','mapSet','soundSet','langSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','presetSet','chaosSet','puzzleDoor','puzzleMenu','pzStart','pzArStart','pzWeekly','scenarios','startScn','startWeekly','settings','settingsClose','prefSet','vpSet','install','pitchSkip','slotMenu','slotExport','slotDel','slotDelGo','slotBack','slotSwitch','slotTake','slotSpace','toTitle'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);}); +document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;if(!$('modal').hidden&&!b.closest('#modal'))return;if(!tapOk(e,b))return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','keys','randomName','pickStart','cont','help','helpClose','newgame','mute','animSet','mapSet','soundSet','langSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','presetSet','chaosSet','puzzleDoor','puzzleMenu','pzStart','pzArStart','pzWeekly','scenarios','startScn','startWeekly','settings','settingsClose','prefSet','vpSet','install','pitchSkip','slotMenu','slotExport','slotDel','slotDelGo','slotBack','slotSwitch','slotTake','slotSpace','toTitle','xfer','xferPage','xferLink','xferFile','xferRecv','xferPaste','xferReset'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);}); diff --git a/src/game/99-loop.js b/src/game/99-loop.js index 03f7aaa..bbb8114 100644 --- a/src/game/99-loop.js +++ b/src/game/99-loop.js @@ -68,7 +68,7 @@ function boot(data){ // A save that cannot be loaded stays where it is, marked damaged: it can still be exported, or deleted. else if(UI.slot&&(sv||UI.loadBad))slotBroke(UI.slot); else{showTitle();if(UI.bootBusy)slotBusyModal(UI.bootBusy);else whatsNew(false);if(UI.bootBroken)toast(tr('loop.your_saved_game_could_not_be'),'bad');}} - renderHUD();renderLeft(); + renderHUD();renderLeft();xferBoot(); window.claude?.hot?.snapshot?.(()=>({S:S&&JSON.parse(JSON.stringify(S)),cam:{...cam}})); if(!window.__TUBES_TEST__){requestAnimationFrame(frame);setTimeout(checkUpdate,4000);setInterval(checkUpdate,10*60*1000);} } diff --git a/src/i18n/en.js b/src/i18n/en.js index 8ace98f..d0a2a0e 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -4848,6 +4848,30 @@ "traceroute.this_one_is_set_to_mode":"; this one is set to {mode}", "traceroute.transit_is_the_last_resort":"transit is the last resort", "traceroute.your_traffic_follows_the_metrics_this":"Your internet traffic follows the metrics. This is the path a customer circuit on “{mode}” would take.", +"transfer.code_i_of_n":"Code {i} of {n}", +"transfer.copy_the_link":"Copy the link", +"transfer.could_not_copy_the_link_here":"Could not copy the link here. Export a save file instead.", +"transfer.from_another_device":"From another device", +"transfer.have_of_n_codes_are_here":"{have} of {n} codes are here", +"transfer.its_charts_and_news_start_fresh":"Its charts and news start fresh here.", +"transfer.link_copied_open_it_on_your":"Link copied. Open it on your other device.", +"transfer.moving_a_network_here":"Move a network here", +"transfer.next_code":"Next code", +"transfer.nothing_is_uploaded_anywhere_the_codes":"Nothing is uploaded anywhere: the codes and the link carry the network itself. Whoever opens them gets a copy, so keep them to yourself.", +"transfer.on_the_other_device_open_the":"On the device with your network, open the menu and pick Send to another device. Scan its code with this device's camera, or paste its link here.", +"transfer.on_your_other_device_open_the":"On your other device, point the camera at this code and open the link.", +"transfer.on_your_other_device_open_the_many":"On your other device, point the camera at this code and open the link, then come back here for the next one. They can arrive in any order.", +"transfer.paste_a_transfer_link":"Paste a transfer link", +"transfer.qr_code_i_of_n":"QR code {i} of {n}", +"transfer.scan_the_next_code_on_your":"Scan the next code on your other device and open its link. Your network loads as soon as the last one arrives.", +"transfer.send_the_link":"Send the link", +"transfer.send_to_another_device":"Send to another device", +"transfer.start_over":"Start over", +"transfer.that_is_not_a_transfer_link":"That is not a transfer link.", +"transfer.that_link_is_incomplete_or_damaged":"That link is incomplete or damaged. Copy it again, all of it.", +"transfer.the_codes_leave_out_your_charts":"To keep the codes few, they leave out your charts and news; the link carries everything.", +"transfer.this_browser_cannot_pack_networks_into":"This browser cannot pack networks into links. Use a save file instead.", +"transfer.this_network_is_too_big_for":"This network is too big for codes. Send the link instead, or export a save file.", "tutorial.businesses_pop_up_as_bubbles_on":"Businesses pop up as $ bubbles on the map. Open Deals and sign your first customer.", "tutorial.grow_drag_from_your_pink_router":"Grow: drag from your pink router onto a nearby city to lay fiber and open a second POP.", "tutorial.start_the_clock_with_1_and":"Start the clock with 1× and watch traffic and money flow. You can pause any time.", diff --git a/src/styles/40-modal.css b/src/styles/40-modal.css index 4c1884e..d431cd1 100644 --- a/src/styles/40-modal.css +++ b/src/styles/40-modal.css @@ -229,3 +229,8 @@ h2 .rn{font-size:18px;vertical-align:middle;padding:2px 4px} .cmroute{align-items:flex-start} .tag.cmhot{background:#FFE1D6;color:#B43A12} .tag.cmcool{background:#DDF1FB;color:#1E6A8C} +/* Moving a network to another device (#263). A code stays dark on white in dark mode too: cameras need the contrast. */ +svg.qr{display:block;width:100%;max-width:300px;height:auto;margin:10px auto 6px;border:3px solid var(--ink);border-radius:12px;background:#fff;box-sizing:border-box} +.xfer-nav{display:flex;align-items:center;justify-content:space-between;gap:8px;max-width:300px;margin:0 auto}.xfer-nav b{font:800 14px var(--display)} +textarea.xfer-in{width:100%;box-sizing:border-box;border:3px solid var(--ink);border-radius:12px;padding:8px 10px;font:13px/1.35 ui-monospace,monospace;background:var(--soft);color:var(--ink);resize:vertical;word-break:break-all} +.xfer-dots{display:flex;flex-wrap:wrap;gap:5px;margin:10px 0}.xfer-dots i{width:12px;height:12px;border-radius:50%;border:2px solid var(--ink);background:var(--soft)}.xfer-dots i.on{background:var(--ok)} diff --git a/tests/device-transfer.test.js b/tests/device-transfer.test.js new file mode 100644 index 0000000..e6d49fa --- /dev/null +++ b/tests/device-transfer.test.js @@ -0,0 +1,164 @@ +// Moving a network to another device with QR codes or a link (#263): no server, the network travels in the link. +const test = require('node:test'); +const assert = require('node:assert/strict'); +const crypto = require('node:crypto'); +const { load } = require('./harness'); +const { until } = require('./net'); + +const settle = async (ev, cond, what) => assert.ok(await until(() => ev(cond)), what || cond); +const hash = (rows) => crypto.createHash('sha256').update(rows).digest('hex').slice(0, 16); + +// Module matrices from Project Nayuki's reference encoder (qrcodegen), byte mode, one per mask. +const REF = [ + ['https://seriesoftub.es/#sot1.ab12c.0.3.HELLO-world_42', 'L', 3, ['30728883c56ec1b1', '18174c37d6786fa7', 'a981f41d89cceb7e', 'e28c29324d50ad09', 'd05a240976233180', 'd7ad281bfed61f9e', '083a4137b252f78f', 'a82468785d358d89']], + ['x'.repeat(200), 'M', 10, ['750d745db4aee09b', '9ff2474eb4806262', 'c8294f9a437b1546', '1bf4d13e40b47c5f', 'fdce0323024df963', '87c3d49925e75834', 'b719f9e8d1b0dd89', '342f8ed986243039']], + ['Series of Tubes '.repeat(40), 'L', 17, ['6d81d73a8426ecea', 'c36740777a080ce2', '79556df75d596a27', 'c4999ca1f4c7cdff', '23185df5abef3f74', '5b2fc9fa8d26aac0', '88b5814b383833f3', '298a1c7f2a08b6ae']], + ['AS64512 '.repeat(120), 'L', 22, ['f8229058824f8960', '0c473ae025a4c779', '58c3ab340313be0a', 'd4fa9891688a1ccc', 'eaac167548e8e5f3', '3f14beb40d1dc4cf', 'a29dee8e6e34fd04', 'b0c682d9933fe28a']], + ['peering '.repeat(360), 'L', 40, ['6efd1b3513f437d0', 'c18c188947dc52bc', 'cd93f7d4626a657f', 'a596a01654473a8d', '33fa5bbfe6b4915a', 'c547ade997387b9e', 'ed333919d660b05a', '44f32c8d979821a8']], +]; + +test('the QR encoder draws exactly the reference codes, for every mask, from version 3 to 40', () => { + const { ev, errors } = load(); + for (const [s, ecc, v, masks] of REF) { + masks.forEach((h, mask) => { + const q = JSON.parse(ev(`(()=>{const q=qrEncode(new TextEncoder().encode(${JSON.stringify(s)}),{ecc:'${ecc}',mask:${mask}});return JSON.stringify({v:q.v,size:q.size,m:q.m.map(r=>r.map(b=>b?1:0).join('')).join('')});})()`)); + assert.equal(q.v, v, `${s.slice(0, 12)}… version`); + assert.equal(q.size, v * 4 + 17); + assert.equal(hash(q.m), h, `${s.slice(0, 12)}… ${ecc} mask ${mask}`); + }); + // Left to choose, it picks one of the eight valid masks. + const auto = JSON.parse(ev(`(()=>{const q=qrEncode(new TextEncoder().encode(${JSON.stringify(s)}),{ecc:'${ecc}'});return JSON.stringify({v:q.v,m:q.m.map(r=>r.map(b=>b?1:0).join('')).join(''),mask:q.mask});})()`)); + assert.equal(auto.v, v); + assert.equal(hash(auto.m), masks[auto.mask]); + } + assert.equal(ev("qrEncode(new Uint8Array(2954))"), null, 'more than version 40 holds'); + assert.match(ev("qrSvg(qrEncode(new TextEncoder().encode('hi')),'x')"), /^