aorecomp

Anarchy Online classic in the browser

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


tools/client/test_weapon_wear_admission.mjs (5519B)


      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 = {attempts: [], supported: []};
     12 try {
     13   for (let index = 0; index < 2; ++index) {
     14     const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     15     await context.addCookies([{name: 'ao_client', value: 'wear-audit-' + index, url}]);
     16     const page = await context.newPage(), game = await GameTest.attach(page);
     17     games.push(game);
     18     await page.goto(url);
     19     await game.ready();
     20   }
     21   const [owner, observer] = games;
     22   const state = async () => (await owner.page.request.get(url + '/test-state')).json();
     23   evidence.initial = await state();
     24   if (evidence.initial.inventory.Items[1].Slot !== 6) {
     25     await owner.key('KeyI');
     26     await owner.page.keyboard.press('Control+1');
     27     for (let attempt = 0; attempt < 2; ++attempt) {
     28       await owner.wait('native equipment action finishes', snapshot =>
     29         !owner.local(snapshot).actions.includes(3) && !owner.local(snapshot).actions.includes(6));
     30       const sequence = owner.sequence, observerSequence = observer.sequence;
     31       await owner.click(681, 45);
     32       await owner.click(867, 206);
     33       await owner.wait('native request and equipment response', () =>
     34         owner.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24') &&
     35         (owner.events.filter(event => event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '47537a24').length >= 2 ||
     36           owner.events.some(event => event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '3b1d2268')));
     37       const current = await state();
     38       evidence.attempts.push({server: current, native: owner.local().inventory});
     39       await owner.save(output + '/refused-' + attempt);
     40       const request = owner.events.find(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24');
     41       const bytes = Buffer.from(request.hex, 'hex');
     42       assert.deepEqual([29, 33, 37, 41, 45].map(offset => bytes.readUInt32BE(offset)), [104, 48, 50000, 1, 6]);
     43       assert.deepEqual(current.inventory, evidence.initial.inventory);
     44       assert.equal(current.psychic, 0);
     45       assert.equal(current.nanoMaximum, evidence.initial.nanoMaximum);
     46       assert.equal(owner.local().inventory.find(item => item.id === 1).slot, 48);
     47       assert(!observer.events.some(event => event.sequence > observerSequence && event.direction === 'framereceived' &&
     48         event.opcode === '3b1d2268' && event.actor[1] === 1));
     49     }
     50 
     51     // Supported weapons and native HeadText still use their normal wear/removal path.
     52     for (const [id, remove] of [[2, true], [3, true], [2, false]]) {
     53       await owner.wait('native equipment action finishes', snapshot =>
     54         !owner.local(snapshot).actions.includes(3) && !owner.local(snapshot).actions.includes(6));
     55       const item = owner.local().inventory.find(item => item.id === id), cell = item.slot - 48;
     56       if (id === 3) {
     57         await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54);
     58         await owner.click(867, 206);
     59       } else {
     60         await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54, 'right');
     61       }
     62       await owner.wait('supported weapon worn', snapshot => owner.local(snapshot).inventory.some(item => item.id === id && item.slot === 6));
     63       evidence.supported.push({id, server: await state()});
     64       await owner.save(output + '/supported-' + id);
     65       if (remove) {
     66         await owner.wait('native equipment action finishes', snapshot =>
     67           !owner.local(snapshot).actions.includes(3) && !owner.local(snapshot).actions.includes(6));
     68         if (id === 3) {
     69           await owner.click(867, 206);
     70           await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54);
     71         } else {
     72           await owner.click(867, 206, 'right');
     73         }
     74         await owner.wait('supported weapon removed', snapshot => owner.local(snapshot).inventory.some(item => item.id === id && item.slot >= 48));
     75       }
     76     }
     77     for (const game of games) {
     78       await game.page.reload();
     79       await game.ready();
     80     }
     81   }
     82   assert.deepEqual(owner.local().inventory.map(item => [item.id, item.slot, item.quality]).sort((a, b) => a[0] - b[0]),
     83     [[1, 48, 41], [2, 6, 1], [3, 50, 1]]);
     84   assert.equal((await state()).psychic, 0);
     85   assert.deepEqual(observer.local().inventory, []);
     86   evidence.final = {server: await state(), native: owner.local().inventory};
     87   assert(games.every(game => game.errors.length === 0));
     88   console.log('PASS: repeated native unsupported wear restores its icon; supported weapons and HeadText retain three instances through page/cold recovery');
     89 } finally {
     90   try {
     91     await fs.mkdir(output, {recursive: true});
     92     await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2));
     93     await Promise.all(games.map((game, index) => game.save(output + '/final-' + index)));
     94   } finally { await browser.close(); }
     95 }