367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
215 lines
14 KiB
Python
215 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""Fixed, explicitly reviewed LOCAL rank4 admin summon of live Praxis4520.
|
|
|
|
Existing LegacySession authentication/chat only. No privileges or direct DB writes.
|
|
The server computes the target close point; native entry is a separate observation.
|
|
The archived Praxiscopy4518 recovery operation remains unchanged.
|
|
"""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import hashlib
|
|
|
|
from local_tortoise import db, private
|
|
from native_engine_character_test import ROOT, local_listeners
|
|
from native_test_guard import require_local_turtle_ports
|
|
|
|
LAUNCH = '74fd855789904092ba5c29e41fae4d79'
|
|
QUERY = ("SELECT c.guid,c.name,c.account,c.online,c.map,c.position_x,c.position_y,"
|
|
"c.position_z,c.orientation,a.`rank`,a.active FROM tw_char.characters c "
|
|
"JOIN tw_logon.account a ON a.id=c.account WHERE c.guid IN(4509,4520) ORDER BY c.guid;")
|
|
ALLOWED = {'ADMIN_WORLD_CONFIRMED', 'ADMIN_SOURCE35_WORLD_CONFIRMED',
|
|
'SUMMON4520_REQUESTED_ONCE', 'SERVER_SUMMON_COMMAND_REPLY_NOT_NATIVE_ACCEPTANCE',
|
|
'ADMIN_ORIGIN_XYZ_MAP_RESTORED_ORIENTATION_UNCHANGED', 'ADMIN_LOGOUT_CONFIRMED'}
|
|
|
|
|
|
def _send_native_control(child, control, report):
|
|
attempt={'control':control,'delivery':'UNCONFIRMED'}
|
|
report.setdefault('native_control_attempts',[]).append(attempt)
|
|
try:
|
|
child.stdin.write(control+'\n');child.stdin.flush()
|
|
except BrokenPipeError:
|
|
attempt['delivery']='PIPE_CLOSED_UNCONFIRMED_NO_REPLAY'
|
|
return False
|
|
attempt['delivery']='FLUSHED_NOT_CHILD_ACKNOWLEDGED'
|
|
return True
|
|
|
|
|
|
def _finish_fixture_child(child, report, error_path):
|
|
try:
|
|
child.stdin.close()
|
|
except BrokenPipeError:
|
|
report['control_pipe_close']='BROKEN_PIPE_CHILD_RESULT_STILL_COLLECTED'
|
|
code=child.wait(timeout=90)
|
|
report['returncode']=code
|
|
report['child_exit_observed']=True
|
|
report['helper_stderr']=str(error_path)
|
|
text=error_path.read_text()
|
|
stopped=next((line for line in reversed(text.splitlines()) if line.startswith('FIXTURE_STOPPED ')),None)
|
|
restored=('ADMIN_ORIGIN_XYZ_MAP_RESTORED_ORIENTATION_UNCHANGED' in report.get('events',[])
|
|
or (stopped is not None and 'admin_origin_restored=1' in stopped))
|
|
report['admin_cleanup']={'live_origin_restore_recorded':restored,
|
|
'logout_completion':'CONFIRMED' if 'ADMIN_LOGOUT_CONFIRMED' in report.get('events',[]) else 'UNRECORDED',
|
|
'stopped_child_marker':stopped,'DB_saved_row_equality_is_not_live_restore_proof':True}
|
|
return code
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--execute-reviewed-local-summon', action='store_true')
|
|
parser.add_argument('--execute-reviewed-local-map-batch', action='store_true')
|
|
parser.add_argument('--execute-reviewed-local-map1-site-batch', action='store_true')
|
|
parser.add_argument('--reviewed-map-batch', type=Path)
|
|
parser.add_argument('--executable', type=Path, required=True)
|
|
parser.add_argument('--accepted-world-policy-receipt', type=Path, required=True)
|
|
parser.add_argument('--evidence', type=Path, required=True)
|
|
args = parser.parse_args()
|
|
sites = args.execute_reviewed_local_map1_site_batch
|
|
batch = args.execute_reviewed_local_map_batch or sites
|
|
if sum((args.execute_reviewed_local_summon,args.execute_reviewed_local_map_batch,sites)) != 1 or (batch and not args.reviewed_map_batch):
|
|
parser.error('Prepared operation only; require explicit reviewed fixed4520 execution opt-in')
|
|
os.umask(0o077)
|
|
exe, out = args.executable.resolve(), args.evidence.resolve()
|
|
prep = ROOT / ('runtime/vm-build-share/local-map1-admin-transport-20261028' if sites else 'runtime/rea-system-jobs-20261022/existing-WMO-integration-20261026/admin-transport' if batch else 'runtime/continuation-20261026/local-admin-Runic-teleport-preparation')
|
|
if exe != prep / 'local-fixture-praxis-teleport' or not exe.is_file():
|
|
parser.error('Require the prepared fixed operation executable')
|
|
if not out.is_relative_to(ROOT/'runtime') or out.exists():
|
|
parser.error('Require a NEW private runtime result; no automatic repeat')
|
|
# Consume Root's same-session authoritative World/policy proof. No extra
|
|
# OCR, security-rank gate on the live user, or duplicate native query.
|
|
proof_raw=args.accepted_world_policy_receipt.read_bytes()
|
|
proof = json.loads(proof_raw)
|
|
if batch:
|
|
spec=json.loads(args.reviewed_map_batch.read_text())
|
|
if sites:
|
|
policy=proof.get('gameplay_policy',{})
|
|
ref=spec.get('accepted_world_proof',{})
|
|
if (proof.get('status')!='PASS' or proof.get('pid')!=spec.get('native_pid')
|
|
or proof.get('ui')!='world' or proof.get('world_and_gameplay_native_accepted') is not True
|
|
or proof.get('assets')!=32349 or proof.get('metadata_records')!=84611
|
|
or not policy.get('enabled') or not policy.get('owner_matches') or policy.get('error')!=0
|
|
or Path(ref.get('path','')).resolve()!=args.accepted_world_policy_receipt.resolve()
|
|
or hashlib.sha256(proof_raw).hexdigest()!=ref.get('sha256')):
|
|
raise RuntimeError('Current reviewed Map1 World/policy proof differs; nothing sent')
|
|
else:
|
|
policy=proof.get('policy',{}).get('policy',{})
|
|
if (proof.get('status')!='PASS_SAME_SESSION_WORLD_AND_GAMEPLAY_POLICY_READY'
|
|
or proof.get('pid')!=spec.get('native_pid') or not proof.get('same_session')
|
|
or not policy.get('enabled') or not policy.get('owner_matches') or policy.get('error')!=0):
|
|
raise RuntimeError('Current reviewed batch World/policy proof differs; nothing sent')
|
|
transport=spec['admin_transport'];coordinates=Path(transport['coordinates']).resolve()
|
|
if (not coordinates.is_relative_to(prep) or hashlib.sha256(coordinates.read_bytes()).hexdigest()!=transport['coordinates_sha256']):
|
|
raise RuntimeError('Reviewed coordinate pin differs; nothing sent')
|
|
if sites:
|
|
if spec.get('kind')!='reviewed-local-map1-site-batch-v1' or spec.get('target_guid')!=4520 or spec.get('admin_guid')!=4509:
|
|
raise RuntimeError('Reviewed Map1 site contract differs; nothing sent')
|
|
parsed=[]
|
|
for line in coordinates.read_text().splitlines():
|
|
fields=line.split()
|
|
if len(fields)!=7:raise RuntimeError('Reviewed site row differs; nothing sent')
|
|
parsed.append(fields)
|
|
expected=[['origin',spec['return_leg']['site_id'],str(spec['return_leg']['map_id'])]]+[['site',j['site_id'],str(j['map_id'])] for j in spec['jobs']]
|
|
if [r[:3] for r in parsed]!=expected or len({r[1] for r in parsed})!=len(parsed):
|
|
raise RuntimeError('Reviewed unique site namespace differs; nothing sent')
|
|
if spec['return_leg']['map_id']!=0 or not spec['jobs'] or len(spec['jobs'])>32 or any(j['map_id']!=1 for j in spec['jobs']):
|
|
raise RuntimeError('Only reviewed Map0 returns and Map1 sites supported')
|
|
site_tokens=[]
|
|
for index,job in enumerate(spec['jobs']):
|
|
if index:site_tokens.append('return-before-'+job['site_id'])
|
|
site_tokens.append(job['site_id'])
|
|
|
|
else:
|
|
policy = proof.get('native_policy', {})
|
|
if (proof.get('status') != 'ACCEPTED_SAME_SESSION_SOURCE_NATIVE_WORLD_AND_GAMEPLAY_POLICY'
|
|
or proof.get('pid') != 1898665 or proof.get('launch_id') != LAUNCH
|
|
or policy.get('enabled') != 1 or not policy.get('owner_matches') or policy.get('error') != 0):
|
|
raise RuntimeError('The reviewed current4520 World/policy lifetime proof differs; nothing sent')
|
|
require_local_turtle_ports(local_listeners())
|
|
before = db(QUERY)
|
|
rows = [line.split('\t') for line in before.splitlines()]
|
|
if len(rows) != 2 or any(len(row) != 11 for row in rows):
|
|
raise RuntimeError('Exact two-actor fixture identity unavailable; nothing sent')
|
|
admin, target = rows
|
|
if (admin[0:2] != ['4509','Gatewaytest'] or target[0:2] != ['4520','Praxis']
|
|
or admin[2] == target[2] or admin[3] != '0' or target[3] != '1'
|
|
or admin[9:] != ['4','1'] or target[9] != '0'):
|
|
raise RuntimeError('Existing admin offline/rank4 and live ordinary target contract differs; nothing sent')
|
|
# Avoid logging into an account with another active character.
|
|
if db(f'SELECT COUNT(*) FROM tw_char.characters WHERE account={int(admin[2])} AND online<>0;') != '0':
|
|
raise RuntimeError('Admin account already in use; nothing sent')
|
|
matches = []
|
|
for path in (ROOT/'secrets').glob('*/account.json'):
|
|
account = json.loads(path.read_text())
|
|
if account.get('account_id') == int(admin[2]):
|
|
matches.append((path.parent.resolve(), account))
|
|
if len(matches) != 1 or not matches[0][0].is_relative_to(ROOT/'secrets'):
|
|
raise RuntimeError('Ambiguous approved private admin fixture inputs; nothing sent')
|
|
directory, account = matches[0]
|
|
report = dict(kind='reviewed-fixed-local-admin-summon4520', phase='PREPARED_BEFORE_AUTH',
|
|
target=4520, admin_actor=4509, target_rank=0, admin_rank=4,
|
|
accepted_world_policy_receipt=str(args.accepted_world_policy_receipt.resolve()),
|
|
before_saved=before, completed=False, target_native_entry_verified=False,
|
|
target_coordinate_contract='server GetClosePoint near saved Source35 entry, not literal XYZ',
|
|
offline_target_race='Source summon has an offline save branch; current target online is required at boundary')
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
private(out, (json.dumps(report, indent=2)+'\n').encode())
|
|
try:
|
|
report['phase'] = 'SINGLE_ADMIN_SESSION_IN_PROGRESS'
|
|
out.write_text(json.dumps(report, indent=2)+'\n')
|
|
if batch:
|
|
report['kind']='reviewed-local-admin-map1-site-batch4520' if sites else 'reviewed-local-admin-original-global7-batch4520'
|
|
report['target_coordinate_contract']='server GetClosePoint near each reviewed Source portal destination, not literal target XYZ'
|
|
report['batch_maps']=[j['map_id'] for j in spec['jobs']]
|
|
if sites:report['batch_site_ids']=site_tokens;report['return_legs']=len(spec['jobs'])-1
|
|
report['native_acceptance_authority']='Per-map parent observer control; helper server reply is not native proof'
|
|
report['events']=[]
|
|
error_path=out.with_name(out.stem+'-helper-stderr-private.log')
|
|
report['helper_stderr']=str(error_path)
|
|
with error_path.open('w') as errors:
|
|
child=subprocess.Popen([str(exe),str(directory),'--allow-reviewed-local-map1-site-batch' if sites else '--allow-reviewed-original-global7-batch',str(coordinates)],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=errors,text=True,bufsize=1)
|
|
child.stdin.write(account['username']+'\n');child.stdin.flush()
|
|
try:
|
|
for raw in child.stdout:
|
|
event=raw.rstrip('\n')
|
|
parts=event.split()
|
|
base=parts[0] if parts else ''
|
|
if sites and base in {'ADMIN_SITE_READY','SUMMON4520_SITE_REQUESTED_ONCE','AWAIT_NATIVE_SITE_ACCEPTANCE'}:
|
|
if len(parts)!=2 or parts[1] not in report['batch_site_ids']:raise RuntimeError('Unreviewed helper site event')
|
|
elif base in {'ADMIN_BATCH_MAP_READY','SUMMON4520_REQUESTED_ONCE','AWAIT_NATIVE_ACCEPTANCE'}:
|
|
if len(parts)!=2 or int(parts[1]) not in report['batch_maps']:raise RuntimeError('Unreviewed helper event')
|
|
elif event not in ALLOWED:raise RuntimeError('Unexpected fixture event withheld')
|
|
report['events'].append(event);out.write_text(json.dumps(report,indent=2)+'\n')
|
|
print(event,flush=True)
|
|
if base in {'AWAIT_NATIVE_ACCEPTANCE','AWAIT_NATIVE_SITE_ACCEPTANCE'}:
|
|
control=sys.stdin.readline().rstrip('\n')
|
|
if control not in {'ACCEPT '+parts[1],'STOP '+parts[1]}:control='STOP '+parts[1]
|
|
if not _send_native_control(child,control,report):break
|
|
finally:
|
|
code=_finish_fixture_child(child,report,error_path)
|
|
report.update(returncode=code,completed=code==0,phase='ADMIN_BATCH_COMPLETE_NATIVE_OBSERVATIONS_SEPARATE' if code==0 else 'PARTIAL_OPERATION_PRESERVED_NO_RETRY',helper_stderr=str(error_path))
|
|
else:
|
|
child = subprocess.run([str(exe), str(directory), '--allow-current-praxis-4520-summon-fixture'],
|
|
input=account['username']+'\n', capture_output=True, text=True, timeout=180)
|
|
events = child.stdout.splitlines()
|
|
if not all(event in ALLOWED for event in events):
|
|
raise RuntimeError('Unexpected fixture output withheld; preserve before any new action')
|
|
report.update(returncode=child.returncode, events=events,
|
|
completed=child.returncode == 0,
|
|
phase='ADMIN_OPERATION_COMPLETE_NATIVE_ACCEPTANCE_PENDING' if child.returncode == 0 else 'PARTIAL_OPERATION_PRESERVED_NO_RETRY',
|
|
stage_metadata=child.stderr[-1200:])
|
|
except subprocess.TimeoutExpired:
|
|
report.update(phase='OPERATION_DEADLINE_PRESERVED_NO_RETRY', completed=False)
|
|
raise RuntimeError('Admin operation deadline; inspect saved state before any new action') from None
|
|
finally:
|
|
report['after_saved'] = db(QUERY)
|
|
out.write_text(json.dumps(report, indent=2)+'\n')
|
|
print(json.dumps({key:report[key] for key in ('phase','completed','target_native_entry_verified')}))
|
|
return 0 if report['completed'] else 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|