367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
74 lines
4.6 KiB
Python
74 lines
4.6 KiB
Python
"""Owned batch fixture staging and cleanup, with explicit mutation policy.
|
|
|
|
The caller owns the client lock and provides the existing SQL/identity helpers.
|
|
This function performs no login, input or artifact/store rollback.
|
|
"""
|
|
|
|
|
|
def stage_owned_fixture(*, sql, ownership_where, record, guid, account,
|
|
username, rank, position=None, flight_node_ids=None):
|
|
"""Stage only the specifically requested pose or legacy flight fixture."""
|
|
mask_text = None
|
|
if flight_node_ids is not None:
|
|
if (rank != 4 or not isinstance(flight_node_ids, (list, tuple)) or not flight_node_ids
|
|
or any(type(node) is not int or not 1 <= node <= 256 for node in flight_node_ids)):
|
|
raise ValueError('Legacy flight staging requires an owned rank4 actor and bounded node IDs')
|
|
mask = [0] * 8
|
|
for node in flight_node_ids:
|
|
mask[(node - 1) // 32] |= 1 << ((node - 1) % 32)
|
|
mask_text = ' '.join(str(value) for value in mask) + ' '
|
|
record['fixture_position_staged'] = False
|
|
record['fixture_flight_staged'] = False
|
|
if position is not None:
|
|
columns = {'map': 'map', 'zone': 'zone', 'x': 'position_x', 'y': 'position_y', 'z': 'position_z', 'orientation': 'orientation'}
|
|
position_set = ','.join(columns[key] + '=' + str(value) for key, value in position.items())
|
|
sql(f'UPDATE tw_char.characters c JOIN tw_logon.account a ON a.id=c.account SET {position_set} WHERE ' + ownership_where(guid, account, username) + f' AND c.online=0 AND a.rank={rank}')
|
|
record['fixture_position_staged'] = True
|
|
if mask_text is not None:
|
|
sql("UPDATE tw_char.characters c JOIN tw_logon.account a ON a.id=c.account SET c.money=100000,c.taxi_path='',c.taximask=UNHEX('" + mask_text.encode().hex() + "') WHERE " + ownership_where(guid, account, username) + ' AND c.online=0 AND a.rank=4')
|
|
record['fixture_flight_staged'] = True
|
|
|
|
|
|
def cleanup_owned_fixtures(*, sql, ownership_where, sleep, record, locked,
|
|
first, second, flight_before, second_rank_changed,
|
|
restore_fixture):
|
|
if not locked:
|
|
record['characters_restored'] = False
|
|
record['fixture_cleanup'] = 'not-attempted-no-lock'
|
|
return
|
|
|
|
# A failed client/input action does not establish that character changes
|
|
# should be undone. Artifact rollback is handled separately by the caller.
|
|
restore = bool(restore_fixture)
|
|
reason = 'requested' if restore else 'preserved'
|
|
# Match the existing offline guard even when preserving the character.
|
|
for guid, before, account, username in (first, second):
|
|
if before:
|
|
for _ in range(35):
|
|
if sql(f'SELECT online FROM tw_char.characters WHERE guid={guid}') == '0':
|
|
break
|
|
sleep(1)
|
|
else:
|
|
raise RuntimeError('Owned character still online; cleanup pending ' + str(guid))
|
|
if restore:
|
|
v = before
|
|
sql(f'UPDATE tw_char.characters c JOIN tw_logon.account a ON a.id=c.account SET c.map={int(v[0])},c.zone={int(v[1])},c.position_x={float(v[2])},c.position_y={float(v[3])},c.position_z={float(v[4])},c.orientation={float(v[5])} WHERE ' + ownership_where(guid, account, username) + ' AND c.online=0')
|
|
if flight_before and restore:
|
|
v = flight_before
|
|
assert all(c in '0123456789ABCDEFabcdef' for x in (v[1], v[3]) for c in x)
|
|
guid, _, account, username = first
|
|
sql(f"UPDATE tw_char.characters c JOIN tw_logon.account a ON a.id=c.account SET c.money={int(v[0])},c.taximask=UNHEX('{v[1]}'),c.extra_flags={int(v[2])},c.taxi_path=UNHEX('{v[3]}'),c.playerFlags=(c.playerFlags & ~3072) | {int(v[4]) & 3072} WHERE " + ownership_where(guid, account, username) + ' AND c.online=0')
|
|
record['flight_fields_restored'] = True
|
|
elif flight_before:
|
|
record['flight_fields_restored'] = False
|
|
_, second_before, second_account, second_username = second
|
|
if second_before:
|
|
if second_rank_changed:
|
|
sql(f"UPDATE tw_logon.account SET rank={int(second_before[7])} WHERE id={second_account} AND username=UNHEX('{second_username.encode().hex()}') AND rank=0")
|
|
restored = sql(f"SELECT rank FROM tw_logon.account WHERE id={second_account} AND username=UNHEX('{second_username.encode().hex()}')")
|
|
if restored != second_before[7]:
|
|
raise RuntimeError('Second owned original rank cleanup mismatch')
|
|
record['second_rank_restored'] = True
|
|
record['characters_restored'] = bool(restore and (first[1] or second[1]))
|
|
record['fixture_cleanup'] = reason
|