tools/client/verify_client_1491.py (3751B)
1 """Run stock 14.9.1 at the saved BB view for a bounded validation session.""" 2 3 import html 4 import json 5 import os 6 import pathlib 7 import re 8 import socket 9 import struct 10 import subprocess 11 import sys 12 import time 13 import urllib.parse 14 import urllib.request 15 16 root = pathlib.Path(__file__).resolve().parents[2] 17 sys.path.insert(0, str(root)) 18 import tools.client.server_fixture 19 admin = tools.client.server_fixture.admin_login("http://127.0.0.1:8081") 20 client = root / 'anarchy-vanilla-14.9.1' 21 output = root / 'local/client/fonts' 22 assert (client / 'version.id').read_text().strip() == '14.9.1' 23 (client / 'Screenshots').mkdir(exist_ok=True) 24 with socket.create_connection(('127.0.0.1', 7510), timeout=10) as connection: 25 connection.sendall(struct.pack('>HHHHIII', 1, 1, 1, 20, 0, 1, 0x25)) 26 with connection.makefile('rb') as reader: 27 header = reader.read(16) 28 length = struct.unpack_from('>H', header, 6)[0] 29 body = reader.read(((length + 3) & ~3) - 16) 30 character_id = struct.unpack_from('>I', body, 12)[0] 31 32 # View Bronto Burger and the building behind it from street level to the southwest. 33 url = f'http://127.0.0.1:8081/admin/players/{character_id}' 34 page = admin.open(url).read().decode() 35 data = html.unescape(re.search(r'<textarea[^>]*>(.*?)</textarea>', page, re.S)[1]) 36 assert 'return_door: null' in data 37 data = re.sub(r'(?m)^playfield:.*$', 'playfield: 705', data) 38 data = re.sub(r'(?m)^position:.*$', 'position: [960, 16.5, 510]', data) 39 data = re.sub(r'(?m)^rotation:.*$', 'rotation: [0, 0.9238795, 0, -0.3826834]', data) 40 request = urllib.parse.urlencode({'data': data}).encode() 41 admin.open(url, request).read() 42 admin.open('http://127.0.0.1:8081/admin/time', b'hour=13&minute=30').read() 43 44 # Suppress first-run tutorials so each fresh test character has an unobstructed view. 45 preferences = client / 'Prefs/localtest' 46 character_preferences = preferences / f'Char{character_id}' 47 character_preferences.mkdir(exist_ok=True) 48 (character_preferences / 'Char.cfg').write_text('IsFirstTime 0\nIsTipEnabled 0\n', encoding='ascii') 49 login_preferences = preferences / 'Login.cfg' 50 login_preferences.write_text(login_preferences.read_text().replace('ShowTipOfTheDay 1', 'ShowTipOfTheDay 0').replace('3rdPersonCamera 1', '3rdPersonCamera 0'), 51 encoding='ascii') 52 53 # Launch the stock client with a bounded lifetime and retain capture metadata. 54 environment = os.environ.copy() 55 environment.update(ANARCHY_CD='cd_image', ANARCHY_SETUP='Setupf') 56 process = subprocess.Popen([str(client / 'Clientr.exe'), 'localtest', 'localtest', 57 str(character_id), '2130706433', '7511', '0', '0'], 58 cwd=client, env=environment) 59 report = {'pid': process.pid, 'client': str(client), 'character_id': character_id, 60 'version': '14.9.1', 'playfield': 705, 'position': [960, 16.5, 510], 61 'rotation': [0, 0.9238795, 0, -0.3826834], 62 'started_at': time.time()} 63 (output / 'current.json').write_text(json.dumps(report, indent=2)) 64 print(json.dumps(report), flush=True) 65 try: 66 deadline = time.monotonic() + 600 67 while process.poll() is None and time.monotonic() < deadline: 68 time.sleep(0.2) 69 report['running_after_600_seconds'] = process.poll() is None 70 finally: 71 report['elapsed_seconds'] = time.time() - report['started_at'] 72 if process.poll() is None: 73 subprocess.run(['taskkill', '/PID', str(process.pid), '/T', '/F'], check=True) 74 process.wait(timeout=10) 75 report['client_exited'] = True 76 report['exit_code'] = process.returncode 77 (output / f'bronto-{process.pid}.json').write_text(json.dumps(report, indent=2)) 78 (output / 'current.json').write_text(json.dumps(report, indent=2)) 79 print(json.dumps(report), flush=True) 80