aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/test_item_proxies.mjs (6707B)


      1 import assert from 'node:assert/strict';
      2 import fs from 'node:fs/promises';
      3 import {createRequire} from 'node:module';
      4 import {GameTest} from './game_test.mjs';
      5 
      6 const {chromium} = createRequire(import.meta.url)('playwright');
      7 const [url, output] = process.argv.slice(2);
      8 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', headless: false,
      9   args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
     10     '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
     11 const games = [], evidence = {};
     12 try {
     13   // Keep the owner's unrelated native regeneration phase outside the short check.
     14   for (const index of [1, 0]) {
     15     const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     16     await context.addCookies([{name: 'ao_client', value: 'proxy-' + index, url}]);
     17     const page = await context.newPage();
     18     const game = await GameTest.attach(page);
     19     games[index] = game;
     20     await page.goto(url);
     21     await game.ready(); assert.equal((await game.page.request.post(url + '/test-defer-recovery')).status(), 204);
     22   }
     23   const [owner, observer] = games;
     24   const server = async () => (await owner.page.request.get(url + '/test-state')).json();
     25   const initial = await server();
     26   if (owner.local().inventory.length === 0) {
     27     assert.equal(initial.inventory.Credits, 5000);
     28     assert.equal(owner.local().stats[27], 50);
     29     await owner.key('KeyI');
     30     if (!owner.state.camera.firstPerson) await owner.key('F8');
     31     const [x, y] = await owner.pick(51035, 3221226655);
     32     await owner.click(x, y, 'right');
     33     await owner.wait('fixture catalog opens', state => state.regions.some(([left, top, right, bottom]) =>
     34       left === 832 && top === 0 && right === 1024 && bottom === 494));
     35     await owner.click(864, 85);
     36     await owner.click(924, 85);
     37     const navigation = owner.navigation;
     38     const purchase = owner.sequence;
     39     await owner.click(874, 475);
     40     await owner.wait('new anonymous ordinary proxies', state => owner.local(state).inventory.length === 2 &&
     41       owner.local(state).stats[61] === 4600);
     42     assert.deepEqual(owner.local().inventory, [
     43       {slot: 48, type: 0, id: 0, quality: 1, templates: [25812, 25812], count: 50},
     44       {slot: 49, type: 0, id: 0, quality: 1, templates: [85596, 85596], count: 1},
     45     ]);
     46     evidence.purchased = {native: owner.local().inventory, server: await server()};
     47     await owner.save(output + '/purchased');
     48 
     49     // Both operations must succeed before any replay can supply physical IDs.
     50     await owner.key('F1');
     51     await owner.key('KeyX');
     52     await owner.wait('native self sitting', state => owner.local(state).stats[430] === 2);
     53     const used = owner.sequence;
     54     await owner.click(681, 45, 'right');
     55     await owner.wait('anonymous laboratory restores HP and consumes one charge', state =>
     56       owner.local(state).stats[27] === 80 && owner.local(state).inventory.some(item => item.slot === 48 && item.count === 49));
     57     evidence.used = {native: owner.local().inventory, server: await server()};
     58     assert.equal(evidence.used.server.health, 80);
     59     assert.equal(evidence.used.server.inventory.Items[0].Count, 49);
     60     assert(Date.parse(evidence.used.server.lock) > Date.now());
     61     assert(owner.events.some(event => event.sequence > used && event.direction === 'framesent' && event.opcode === '52526858'));
     62     await owner.click(681, 45, 'right');
     63     assert.equal((await server()).inventory.Items[0].Count, 49);
     64     await owner.key('KeyX');
     65     await owner.wait('standing for wear', state => owner.local(state).stats[430] !== 2);
     66     const worn = observer.sequence;
     67     await owner.click(735, 45, 'right');
     68     await owner.wait('anonymous gloves worn', state => owner.local(state).inventory.some(item =>
     69       item.slot === 24 && item.templates[0] === 85596));
     70     await observer.wait('observer receives immediate wear', () => observer.events.some(event => {
     71       if (event.sequence <= worn || event.direction !== 'framereceived' || event.opcode !== '35505644') return false;
     72       const packet = Buffer.from(event.hex, 'hex');
     73       return packet.readUInt32BE(45) === 6 && packet.readUInt32BE(53) === 24;
     74     }));
     75     evidence.worn = {native: owner.local().inventory, server: await server()};
     76     assert.equal(evidence.worn.server.inventory.Items[1].ID, 2);
     77     assert.equal(evidence.worn.server.inventory.Items[1].Slot, 24);
     78     await owner.page.keyboard.press('Control+1');
     79     await owner.click(953, 53);
     80     await owner.save(output + '/anonymous-worn-cell');
     81     await owner.click(927, 206, 'right');
     82     await owner.wait('anonymous gloves removed to their ordinary cell', state => owner.local(state).inventory.some(item =>
     83       item.slot === 49 && item.templates[0] === 85596));
     84     await owner.wait('removal action finishes', state => !owner.local(state).actions.includes(3));
     85     await owner.click(735, 45, 'right');
     86     await owner.wait('same anonymous gloves re-worn', state => owner.local(state).inventory.some(item =>
     87       item.slot === 24 && item.templates[0] === 85596));
     88     evidence.reworn = {native: owner.local().inventory, server: await server()};
     89     assert.deepEqual(evidence.reworn.server.inventory, evidence.worn.server.inventory);
     90     assert.equal(owner.navigation, navigation);
     91     assert(!owner.events.some(event => event.sequence > purchase && event.direction === 'framereceived' &&
     92       ['29304349', '5f4b1a39', '445f2a0b'].includes(event.opcode)), 'Replay hid an immediate-use failure');
     93     await owner.save(output + '/used-and-worn');
     94     await owner.page.reload();
     95     await owner.ready(); assert.equal((await owner.page.request.post(url + '/test-defer-recovery')).status(), 204);
     96   }
     97 
     98   // FullCharacter supplies the physical identities for the same used instances.
     99   assert.deepEqual(owner.local().inventory, [
    100     {slot: 24, type: 51022, id: 2, quality: 1, templates: [85596, 85596], count: 1},
    101     {slot: 48, type: 51005, id: 1, quality: 1, templates: [25812, 25812], count: 49},
    102   ]);
    103   assert.equal(owner.local().stats[27], 80);
    104   assert.equal(owner.local().stats[61], 4600);
    105   assert.deepEqual(observer.local().inventory, []);
    106   evidence.replayed = {native: owner.local().inventory, server: await server()};
    107   assert(games.every(game => game.errors.length === 0));
    108   console.log('PASS: anonymous laboratory use and glove wear before replay; physical IDs/counts retained after page/cold recovery');
    109 } finally {
    110   await fs.mkdir(output, {recursive: true});
    111   await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2));
    112   try { await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); }
    113   finally { await browser.close(); }
    114 }