|
1 | 1 | import { app, BrowserWindow } from 'electron' |
2 | | -import { existsSync } from 'node:fs' |
| 2 | +import { existsSync, writeFileSync, mkdirSync, rmSync } from 'node:fs' |
3 | 3 | import { join } from 'node:path' |
| 4 | +import * as nbt from 'prismarine-nbt' |
4 | 5 | import { processManager } from './core/processManager' |
5 | 6 | import { getConfig, updateConfig } from './config' |
6 | 7 | import { startWebServer, stopWebServer } from './web/server' |
@@ -192,6 +193,50 @@ export async function runSmoke(): Promise<void> { |
192 | 193 | if (!steve || !steve.op) return fail('players: op merge failed') |
193 | 194 | console.log('SMOKE: rcon-enable + players merge OK') |
194 | 195 |
|
| 196 | + // --- 2d. inventory NBT parse (write a real playerdata .dat) --- |
| 197 | + const spath = getConfig().servers.find((s) => s.id === id)?.path ?? '' |
| 198 | + const invUuid = '22222222-2222-2222-2222-222222222222' |
| 199 | + const pdDir = join(spath, 'world', 'playerdata') |
| 200 | + mkdirSync(pdDir, { recursive: true }) |
| 201 | + const datBuf = nbt.writeUncompressed( |
| 202 | + { |
| 203 | + type: 'compound', |
| 204 | + name: '', |
| 205 | + value: { |
| 206 | + Health: { type: 'float', value: 20 }, |
| 207 | + Inventory: { |
| 208 | + type: 'list', |
| 209 | + value: { |
| 210 | + type: 'compound', |
| 211 | + value: [ |
| 212 | + { |
| 213 | + Slot: { type: 'byte', value: 0 }, |
| 214 | + id: { type: 'string', value: 'minecraft:diamond_sword' }, |
| 215 | + Count: { type: 'byte', value: 1 } |
| 216 | + } |
| 217 | + ] |
| 218 | + } |
| 219 | + } |
| 220 | + } |
| 221 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 222 | + } as any, |
| 223 | + 'big' |
| 224 | + ) |
| 225 | + writeFileSync(join(pdDir, invUuid + '.dat'), datBuf) |
| 226 | + sf.writeTextFile(id, 'usercache.json', JSON.stringify([{ name: 'InvTester', uuid: invUuid }])) |
| 227 | + const players2 = await playersMod.getPlayers(id) |
| 228 | + const invp = players2.find((p) => p.name === 'InvTester') |
| 229 | + sf.deleteEntry(id, 'usercache.json') |
| 230 | + try { |
| 231 | + rmSync(join(spath, 'world'), { recursive: true, force: true }) |
| 232 | + } catch { |
| 233 | + /* ignore */ |
| 234 | + } |
| 235 | + if (!invp?.inventory?.some((it) => it.id === 'diamond_sword')) { |
| 236 | + return fail('inventory NBT not parsed') |
| 237 | + } |
| 238 | + console.log('SMOKE: inventory NBT parse OK') |
| 239 | + |
195 | 240 | // --- 3. command over stdin --- |
196 | 241 | processManager.sendCommand(id, 'say hello-from-smoke') |
197 | 242 | await sleep(400) |
|
0 commit comments