This commit is contained in:
Raven Scott
2026-07-30 23:48:16 -04:00
parent 21066b35cb
commit a417a3a4f1
15 changed files with 665 additions and 55 deletions
+52 -7
View File
@@ -52,7 +52,7 @@ function exit(code) {
else process.exit(code)
}
function makeApp(storage, updates = false, displayName) {
function makeApp(storage, updates = false, displayName, mcUsername) {
return new App({
dir: storage,
appPath: isDev ? null : argv0,
@@ -60,7 +60,8 @@ function makeApp(storage, updates = false, displayName) {
version: pkg.version,
upgrade: pkg.upgrade,
name: appName,
displayName: displayName || 'player'
displayName: displayName || 'player',
mcUsername: mcUsername || displayName || null
})
}
@@ -81,6 +82,21 @@ function attachPeerUi(app) {
console.log(`[peers] online: ${list.map((p) => p.name).join(', ')}`)
}
})
app.on('border', (evt) => {
if (evt.type === 'warn') {
console.log(
`[mesh] border warn ${evt.player?.username}${evt.neighbor?.name || evt.neighbor?.regionId || 'edge'}`
)
}
})
app.on('migrate', (evt) => {
console.log(
`[mesh] migrate ${evt.player?.username || evt.username}${evt.neighbor?.name || evt.neighbor?.regionId}`
)
})
app.on('migrated', (evt) => {
console.log(`[mesh] tunnel now 127.0.0.1:${evt.localPort} region=${evt.neighbor?.regionId}`)
})
// Type lines to chat (host/join sessions)
if (process.stdin && process.stdin.isTTY && typeof process.stdin.on === 'function') {
@@ -242,9 +258,16 @@ const hostCmd = command(
flag('--port|-p [port]', 'local Minecraft port (default 25565)'),
flag('--version [ver]', 'override Minecraft version'),
flag('--name|-n [display]', 'chat display name'),
flag('--mc-name [user]', 'Minecraft username for mesh migrate filter'),
flag('--mesh', 'create a new mesh and enroll this world'),
flag('--mesh-invite [invite]', 'open mesh invite and enroll this world'),
flag('--min-x [n]', 'enroll bounds minX'),
flag('--max-x [n]', 'enroll bounds maxX'),
flag('--min-z [n]', 'enroll bounds minZ'),
flag('--max-z [n]', 'enroll bounds maxZ'),
async (cmd) => {
const storage = resolveStorage(root.flags.storage)
const app = makeApp(storage, false, cmd.flags.name)
const app = makeApp(storage, false, cmd.flags.name, cmd.flags.mcName)
app.on('message', (m) => console.log(m))
app.on('error', (err) => console.error('[error]', err))
attachShutdown(app)
@@ -252,11 +275,21 @@ const hostCmd = command(
await app.ready()
try {
const enroll = {
minX: cmd.flags.minX,
maxX: cmd.flags.maxX,
minZ: cmd.flags.minZ,
maxZ: cmd.flags.maxZ
}
const result = await app.hostWorld({
world: cmd.args.name,
port: cmd.flags.port ? Number(cmd.flags.port) : 25565,
version: cmd.flags.version,
displayName: cmd.flags.name
displayName: cmd.flags.name,
mcUsername: cmd.flags.mcName,
createMesh: !!cmd.flags.mesh,
meshInvite: cmd.flags.meshInvite,
enroll
})
console.log('')
console.log(`${appName} hosting private world (P2P)`)
@@ -264,12 +297,21 @@ const hostCmd = command(
console.log(` local: ${result.squid.host}:${result.squid.port}`)
console.log(` tunnel: HyperDHT host`)
console.log(` chat: type lines + Enter; /peers for list`)
if (result.region) {
console.log(` mesh: enrolled ${result.region.regionId}`)
console.log(` border: active (kick+migrate signal on leave)`)
}
console.log('')
console.log('Invite (treat as secret — fj1. capability):')
console.log(result.invite)
if (result.mesh && result.mesh.invite) {
console.log('')
console.log('Mesh invite:')
console.log(result.mesh.invite)
}
console.log('')
console.log('Friends run:')
console.log(` flying-jib join '<invite>'`)
console.log(` flying-jib join '<invite>' --mc-name <TheirMcName>`)
console.log('')
console.log('You connect Java Edition to:')
console.log(` ${result.squid.host}:${result.squid.port}`)
@@ -290,9 +332,10 @@ const joinCmd = command(
arg('<invite>', 'fj1. invite string'),
flag('--port|-p [port]', 'local bind port (default: ephemeral)'),
flag('--name|-n [display]', 'chat display name'),
flag('--mc-name [user]', 'Minecraft username (mesh migrate filter)'),
async (cmd) => {
const storage = resolveStorage(root.flags.storage)
const app = makeApp(storage, false, cmd.flags.name)
const app = makeApp(storage, false, cmd.flags.name, cmd.flags.mcName)
app.on('message', (m) => console.log(m))
app.on('error', (err) => console.error('[error]', err))
attachShutdown(app)
@@ -303,7 +346,8 @@ const joinCmd = command(
const result = await app.joinWorld({
invite: cmd.args.invite,
localPort: cmd.flags.port ? Number(cmd.flags.port) : 0,
displayName: cmd.flags.name
displayName: cmd.flags.name,
mcUsername: cmd.flags.mcName
})
const port = result.tunnel.localPort
console.log('')
@@ -312,6 +356,7 @@ const joinCmd = command(
console.log(` version: ${result.invite.mcVersion || 'unknown'}`)
console.log(` local: 127.0.0.1:${port}`)
console.log(` chat: type lines + Enter; /peers for list`)
console.log(` migrate: auto if host signals mesh border for --mc-name`)
console.log('')
console.log('Connect Java Edition to:')
console.log(` 127.0.0.1:${port}`)