p4
This commit is contained in:
@@ -338,12 +338,185 @@ const statusCmd = command(
|
||||
const worlds = app.listWorlds()
|
||||
console.log('worlds:', worlds.length)
|
||||
for (const w of worlds) console.log(' -', w.id, w.version)
|
||||
const meshes = app.listMeshes()
|
||||
console.log('meshes:', meshes.length)
|
||||
for (const m of meshes) console.log(' -', m.meshId, m.key)
|
||||
} finally {
|
||||
await app.close()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const meshCreateCmd = command(
|
||||
'mesh-create',
|
||||
summary('Create a new mesh and print fj1. mesh invite'),
|
||||
flag('--name [name]', 'mesh display name'),
|
||||
async (cmd) => {
|
||||
const storage = resolveStorage(root.flags.storage)
|
||||
const app = makeApp(storage, false)
|
||||
await app.ready()
|
||||
try {
|
||||
const r = await app.createMesh({ name: cmd.flags.name })
|
||||
console.log('Mesh created')
|
||||
console.log(' meshId:', r.meshId)
|
||||
console.log(' key: ', r.key)
|
||||
console.log(' writer:', r.localWriterKey)
|
||||
console.log('')
|
||||
console.log('Mesh invite (share to join registry):')
|
||||
console.log(r.invite)
|
||||
console.log('')
|
||||
console.log('Keep process alive to seed registry, or re-open later with mesh-open.')
|
||||
console.log('Enroll a world: flying-jib mesh-enroll <world> --min-x 0 --max-x 9999 ...')
|
||||
// Keep mesh swarm alive until Ctrl+C
|
||||
attachShutdown(app)
|
||||
await new Promise(() => {})
|
||||
} catch (err) {
|
||||
console.error('[mesh-create failed]', err)
|
||||
await app.close()
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const meshOpenCmd = command(
|
||||
'mesh-open',
|
||||
summary('Open mesh by key or fj1. mesh invite'),
|
||||
flag('--key [key]', 'mesh public key (z32)'),
|
||||
flag('--invite [invite]', 'fj1. mesh invite'),
|
||||
flag('--name [name]', 'local display name for mesh folder'),
|
||||
async (cmd) => {
|
||||
const storage = resolveStorage(root.flags.storage)
|
||||
const app = makeApp(storage, false)
|
||||
await app.ready()
|
||||
try {
|
||||
const r = await app.openMesh({
|
||||
key: cmd.flags.key,
|
||||
invite: cmd.flags.invite,
|
||||
name: cmd.flags.name
|
||||
})
|
||||
console.log('Mesh open')
|
||||
console.log(' meshId: ', r.meshId)
|
||||
console.log(' key: ', r.key)
|
||||
console.log(' writable:', r.writable)
|
||||
console.log(' writer: ', r.localWriterKey)
|
||||
if (!r.writable) {
|
||||
console.log('')
|
||||
console.log('Not yet a writer. Ask a mesh writer to run:')
|
||||
console.log(` flying-jib mesh-admit ${r.localWriterKey}`)
|
||||
}
|
||||
attachShutdown(app)
|
||||
await new Promise(() => {})
|
||||
} catch (err) {
|
||||
console.error('[mesh-open failed]', err)
|
||||
await app.close()
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const meshAdmitCmd = command(
|
||||
'mesh-admit',
|
||||
summary('Admit a peer writer key (requires open writable mesh in this process)'),
|
||||
arg('<writerKey>', 'peer local writer key (z32 or hex)'),
|
||||
flag('--invite [invite]', 'open mesh from invite first'),
|
||||
flag('--key [key]', 'open mesh from key first'),
|
||||
async (cmd) => {
|
||||
const storage = resolveStorage(root.flags.storage)
|
||||
const app = makeApp(storage, false)
|
||||
await app.ready()
|
||||
try {
|
||||
if (cmd.flags.invite || cmd.flags.key) {
|
||||
await app.openMesh({ key: cmd.flags.key, invite: cmd.flags.invite })
|
||||
}
|
||||
if (!app.mesh) throw new Error('No mesh open; pass --invite or --key')
|
||||
await app.meshAddWriter(cmd.args.writerKey)
|
||||
console.log('Writer admitted:', cmd.args.writerKey)
|
||||
await app.stopMesh()
|
||||
await app.close()
|
||||
} catch (err) {
|
||||
console.error('[mesh-admit failed]', err)
|
||||
await app.close()
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const meshEnrollCmd = command(
|
||||
'mesh-enroll',
|
||||
summary('Enroll a local world region into the open mesh'),
|
||||
arg('<world>', 'world id to enroll'),
|
||||
flag('--invite [invite]', 'mesh invite to open'),
|
||||
flag('--key [key]', 'mesh key to open'),
|
||||
flag('--min-x [n]', 'bounds minX (default 0)'),
|
||||
flag('--max-x [n]', 'bounds maxX (default 9999)'),
|
||||
flag('--min-z [n]', 'bounds minZ (default 0)'),
|
||||
flag('--max-z [n]', 'bounds maxZ (default 9999)'),
|
||||
flag('--offset-x [n]', 'region offset x'),
|
||||
flag('--offset-z [n]', 'region offset z'),
|
||||
async (cmd) => {
|
||||
const storage = resolveStorage(root.flags.storage)
|
||||
const app = makeApp(storage, false)
|
||||
await app.ready()
|
||||
try {
|
||||
if (cmd.flags.invite || cmd.flags.key) {
|
||||
await app.openMesh({ key: cmd.flags.key, invite: cmd.flags.invite })
|
||||
}
|
||||
if (!app.mesh) throw new Error('No mesh open; pass --invite or --key')
|
||||
const region = await app.enrollWorld({
|
||||
world: cmd.args.world,
|
||||
minX: cmd.flags.minX,
|
||||
maxX: cmd.flags.maxX,
|
||||
minZ: cmd.flags.minZ,
|
||||
maxZ: cmd.flags.maxZ,
|
||||
offsetX: cmd.flags.offsetX,
|
||||
offsetZ: cmd.flags.offsetZ
|
||||
})
|
||||
console.log('Enrolled region:')
|
||||
console.log(JSON.stringify(region, null, 2))
|
||||
await app.stopMesh()
|
||||
await app.close()
|
||||
} catch (err) {
|
||||
console.error('[mesh-enroll failed]', err)
|
||||
await app.close()
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const meshListCmd = command(
|
||||
'mesh-list',
|
||||
summary('List regions in a mesh'),
|
||||
flag('--invite [invite]', 'mesh invite'),
|
||||
flag('--key [key]', 'mesh key'),
|
||||
async (cmd) => {
|
||||
const storage = resolveStorage(root.flags.storage)
|
||||
const app = makeApp(storage, false)
|
||||
await app.ready()
|
||||
try {
|
||||
if (cmd.flags.invite || cmd.flags.key) {
|
||||
await app.openMesh({ key: cmd.flags.key, invite: cmd.flags.invite })
|
||||
}
|
||||
if (!app.mesh) throw new Error('No mesh open; pass --invite or --key')
|
||||
const regions = await app.listMeshRegions()
|
||||
if (!regions.length) {
|
||||
console.log('(no regions enrolled yet)')
|
||||
} else {
|
||||
for (const r of regions) {
|
||||
console.log(
|
||||
`- ${r.regionId} ${r.name || ''} bounds=${JSON.stringify(r.bounds)} worldKey=${r.worldKey.slice(0, 12)}…`
|
||||
)
|
||||
}
|
||||
}
|
||||
await app.stopMesh()
|
||||
await app.close()
|
||||
} catch (err) {
|
||||
console.error('[mesh-list failed]', err)
|
||||
await app.close()
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const root = command(
|
||||
appName,
|
||||
header(`${appName} — decentralized P2P Minecraft (Bare/Pear)`),
|
||||
@@ -356,7 +529,12 @@ const root = command(
|
||||
startCmd,
|
||||
hostCmd,
|
||||
joinCmd,
|
||||
statusCmd
|
||||
statusCmd,
|
||||
meshCreateCmd,
|
||||
meshOpenCmd,
|
||||
meshAdmitCmd,
|
||||
meshEnrollCmd,
|
||||
meshListCmd
|
||||
)
|
||||
|
||||
root.parse(rawArgv)
|
||||
|
||||
Reference in New Issue
Block a user