import { utils } from '@start9labs/start-sdk' import { getJoinSecret } from '../actions/getJoinSecret' import { i18n } from '../i18n' import { sdk } from '../sdk' import { storeJson } from '../fileModels/store.json' /** * The server exits immediately if `JOIN_SECRET` is unset (`src/server/index.ts` in the game * repo), so a value has to exist before main.ts's daemon ever starts — seeded here rather than * left for the user to generate via the action first. */ export const seedJoinSecret = sdk.setupOnInit(async (effects, kind) => { if (kind === 'install') { await storeJson.merge(effects, { joinSecret: utils.getDefaultString({ charset: 'a-z,A-Z,0-9', len: 24 }), }) await sdk.action.createOwnTask(effects, getJoinSecret, 'critical', { reason: i18n('Get the join secret to share with players'), }) } else { // 'update' and 'restore' — repairs a corrupted store.json without touching an existing // joinSecret. A restored volume already carries one (it lives inside the backed-up volume, // see backups.ts), so there is nothing to seed. await storeJson.merge(effects, {}) } })