Reconcile delayed hardcore deaths with native population registry
This commit is contained in:
@@ -44,6 +44,27 @@ try:
|
||||
state=json.load(urllib.request.urlopen(base+'/api/state',timeout=10));days=max(3,min(30,int(state.get('opsRetentionDays',7))))
|
||||
env=os.environ.copy();env['MYSQL_PWD']=cfg['DOCKER_DB_ROOT_PASSWORD']
|
||||
def sql(q):return subprocess.check_output(['docker','exec','-e','MYSQL_PWD','ac-database','mysql','-uroot','-N','-B','-e',q],env=env,text=True)
|
||||
# Reconcile delayed verified deaths by the full native identity. This never
|
||||
# revives an identity, changes a protected resident, or counts a human as a bot.
|
||||
if state.get('settings',{}).get('hardcore',{}).get('enabled'):
|
||||
retired=0
|
||||
registry={int(line.split('\t')[0]):line for line in sql("SELECT guid,name,account_id,state,died_at FROM acore_auth.azerothai_lifecycle WHERE state<>'dead' AND protected=0 AND LOWER(name)<>'zaku'").splitlines() if line}
|
||||
for bot in state.get('bots',[]):
|
||||
identity=bot.get('autonomy') or {};death=bot.get('death') or {}
|
||||
if bot.get('status')!='dead' or not death.get('verified') or death.get('source')!='azerothcore' or not identity.get('managed'):continue
|
||||
if not bot.get('mortal') or bot.get('plotArmorHpFloor',0)>0 or bot.get('name','').lower()=='zaku':continue
|
||||
guid=identity.get('characterGuid');account=identity.get('accountId')
|
||||
if type(guid) is not int or type(account) is not int or guid<=0 or account<=0:continue
|
||||
before=registry.get(guid,'');fields=before.split('\t')
|
||||
if len(fields)!=5 or fields[1]!=bot['name'] or int(fields[2])!=account:continue
|
||||
name=bot['name'].encode().hex()
|
||||
where=f"guid={guid} AND account_id={account} AND BINARY name=UNHEX('{name}') AND protected=0 AND LOWER(name)<>'zaku' AND state<>'dead'"
|
||||
# Keep an audit of the old registry row and supporting death before changing it.
|
||||
audit=lab/'lifecycle-reconciliation.jsonl'
|
||||
with audit.open('a') as f:f.write(json.dumps({'at':time.time(),'before':before.strip(),'death':death})+'\n')
|
||||
changed=sql("UPDATE acore_auth.azerothai_lifecycle SET state='dead',died_at=COALESCE(died_at,NOW()) WHERE "+where+'; SELECT ROW_COUNT()')
|
||||
retired+=int(changed.strip())
|
||||
maintenance.append(f'Hardcore registry checked; {retired} delayed deaths reconciled')
|
||||
for table,column in [('azerothai_event_outbox','delivered_at'),('azerothai_result_outbox','delivered_at')]:
|
||||
sql(f'DELETE FROM acore_auth.{table} WHERE {column} IS NOT NULL AND {column}<NOW()-INTERVAL 1 DAY LIMIT 2000')
|
||||
sql(f'DELETE FROM acore_auth.azerothai_snapshot_archive WHERE created_at<NOW()-INTERVAL {days} DAY LIMIT 2000')
|
||||
|
||||
Reference in New Issue
Block a user