Files
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

106 lines
7.5 KiB
Python

#!/usr/bin/env python3
"""Stage/install Jerry's authorized local bank using existing Tortoise service.
No live endpoint, character edits, new privileges or replacement bank protocol.
Default is dry-run. A private journal retains exact rows and rollback SQL;
MyISAM tables mean this tool never promises transactional rollback.
"""
import argparse, hashlib, json, os, re
from pathlib import Path
from local_tortoise import ROOT, db, private
ENTRY, SPAWN, MENU = 62081, 6208100, 65081
TABLES = [('creature_template', 'entry=62081'), ('creature', 'guid=6208100'),
('gossip_menu', 'entry=65081'), ('gossip_menu_option', 'menu_id=65081')]
IDENT = re.compile(r'^[a-zA-Z_][a-zA-Z_0-9]*$')
def snapshot(table, where):
cols = [line.split('\t')[0] for line in db('SHOW COLUMNS FROM tw_world.'+table+';').splitlines()]
if not all(IDENT.fullmatch(c) for c in cols): raise ValueError('Unexpected local schema')
names = ','.join('`'+c+'`' for c in cols)
expressions = ','.join("IF(`"+c+"` IS NULL,'NULL',CONCAT('X',CHAR(39),HEX(`"+c+"`),CHAR(39)))" for c in cols)
rows = db('SELECT '+expressions+' FROM tw_world.'+table+' WHERE '+where+';').splitlines()
sql = 'DELETE FROM tw_world.'+table+' WHERE '+where+';\n'
for row in rows:
values = row.split('\t')
if len(values)!=len(cols): raise ValueError('Snapshot row shape differs')
sql += 'INSERT INTO tw_world.'+table+' ('+names+') VALUES ('+','.join(values)+');\n'
return sql
def observed():
return dict(template=db('SELECT entry,name,subname,display_id1,display_id2,display_id3,display_id4,faction,npc_flags,gossip_menu_id,script_name FROM tw_world.creature_template WHERE entry=62081;'),
spawn=db('SELECT guid,id,map,position_x,position_y,position_z,orientation FROM tw_world.creature WHERE guid=6208100;'),
menu=db('SELECT * FROM tw_world.gossip_menu WHERE entry=65081;'),
option=db('SELECT * FROM tw_world.gossip_menu_option WHERE menu_id=65081;'))
def verify_installed(after):
expected=dict(template='62081\tJerry Gallywix\tGuild Vault Administrator\t6882\t0\t0\t0\t120\t1\t65081',
spawn='6208100\t62081\t0\t-14415.2\t512.935\t4.98285\t2.07263',
menu='65081\t6320603\t0\t0',
option='65081\t0\t0\tI would like to access the guild bank.\t0\t18\t1\t0\t0\t0\t0\t0\tNULL\t0\t0')
if after!=expected: raise RuntimeError('Post-write verification differs; inspect private rollback, do not blindly reapply')
def main():
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('--journal', type=Path, required=True)
p.add_argument('--apply', action='store_true')
p.add_argument('--rollback', action='store_true')
a=p.parse_args(); os.umask(0o077)
folder=a.journal.resolve()
if not folder.is_relative_to(ROOT/'runtime') or a.apply and a.rollback: p.error('Owned runtime journal and one action required')
before=observed()
if a.rollback:
receipt=json.loads((folder/'receipt.json').read_text())
if before!=receipt['after']: raise RuntimeError('Local bank changed after install; preserve instead of overwriting')
if db('SELECT COUNT(*) FROM tw_char.characters WHERE online<>0;')!='0': raise RuntimeError('Local players online')
db((folder/'rollback.sql').read_text())
if observed()!=receipt['before']: raise RuntimeError('Rollback verification differs; preserve journal')
print('Exact local bank rows restored; world restart required');return
plan=dict(kind='local-Tortoise-bank-addition', entry=ENTRY, spawn=SPAWN, menu=MENU,
source_name='Jerry Gallywix', source_display=6882, source_title='Guild Vault Administrator',
source_cache_sha256='594e2cbe7ec838cc37d5d0c0c06f32585109bc1eb26e5b2946bccc490ed748f8',
placement=dict(map=0,x=-14415.2,y=512.935,z=4.98285,orientation=2.07263),
placement_basis='local placement adjacent to supplied Praxis Booty Bay export; exact live spawn unverified',
behavior='existing server bank handler, gossip option18, neutral Booty Bay faction120',
other_fields='existing unused local template retained; not claimed identical to live Octo',
all_capitals='existing local banker spawns retained; Orgrimmar is local addition, not Octo parity')
if before['template'].startswith('62081\tJerry Gallywix\t'):
if a.apply and not (folder/'receipt.json').exists() and all((folder/n).is_file() for n in ('before.json','plan.json','install.sql','rollback.sql')):
verify_installed(before)
private(folder/'receipt.json',json.dumps(dict(plan=json.loads((folder/'plan.json').read_text()),
before=json.loads((folder/'before.json').read_text()),after=before,
install_sha256=hashlib.sha256((folder/'install.sql').read_bytes()).hexdigest(),
world_reload_required=True),indent=2).encode())
print('Verified completed installation from retained journal; no writes repeated');return
if not (folder/'receipt.json').exists() or before!=json.loads((folder/'receipt.json').read_text())['after']:
raise RuntimeError('Existing Jerry differs from owned receipt; preserve')
print('Already installed exactly; no duplicate spawn or IDs changed');return
if not before['template'].startswith('62081\tEdrian\t\t18211\t') or any(before[k] for k in ('spawn','menu','option')):
raise RuntimeError('Local baseline differs; no changes')
for table in ('creature','creature_questrelation','creature_involvedrelation'):
if db('SELECT COUNT(*) FROM tw_world.'+table+' WHERE id=62081;')!='0': raise RuntimeError('Existing NPC has references; preserve')
if db('SELECT COUNT(*) FROM tw_world.gossip_menu WHERE entry=65000 AND text_id=6320603;')!='1': raise RuntimeError('Bank gossip text dependency differs')
print(json.dumps(plan,sort_keys=True))
if not a.apply: print('Dry-run only; no writes');return
if db('SELECT COUNT(*) FROM tw_char.characters WHERE online<>0;')!='0': raise RuntimeError('Local players online; no writes')
if folder.exists(): raise RuntimeError('Journal exists; inspect instead of reapplying')
folder.mkdir(parents=True,mode=0o700)
rollback=''.join(snapshot(t,w) for t,w in reversed(TABLES))
private(folder/'rollback.sql',rollback.encode())
private(folder/'plan.json',json.dumps(plan,indent=2).encode())
sql="""UPDATE tw_world.creature_template SET name='Jerry Gallywix',subname='Guild Vault Administrator',display_id1=6882,display_id2=0,display_id3=0,display_id4=0,faction=120,npc_flags=1,gossip_menu_id=65081,script_name='' WHERE entry=62081 AND name='Edrian' AND display_id1=18211;
INSERT INTO tw_world.gossip_menu(entry,text_id,script_id,condition_id) VALUES(65081,6320603,0,0);
INSERT INTO tw_world.gossip_menu_option(menu_id,id,option_icon,option_text,option_id,npc_option_npcflag) VALUES(65081,0,0,'I would like to access the guild bank.',18,1);
INSERT INTO tw_world.creature(guid,id,map,position_x,position_y,position_z,orientation,wander_distance,movement_type) VALUES(6208100,62081,0,-14415.2,512.935,4.98285,2.07263,0,0);
"""
private(folder/'install.sql',sql.encode())
private(folder/'before.json',json.dumps(before,indent=2).encode())
db(sql)
after=observed()
verify_installed(after)
private(folder/'receipt.json',json.dumps(dict(plan=plan,before=before,after=after,
install_sha256=hashlib.sha256(sql.encode()).hexdigest(),world_reload_required=True),indent=2).encode())
print('Local Jerry bank installed with exact row rollback; world restart required')
if __name__=='__main__': main()