agoara update

This commit is contained in:
2026-05-06 23:41:52 +03:00
parent 7e98f1292e
commit b824144a6a
9 changed files with 1283 additions and 6 deletions

View File

@@ -120,11 +120,38 @@ def receive_state():
except Exception as e:
print("Error evaluating blueprints:", e)
# Upsert active celebrations (party / triumph cooldowns per town)
celebrations = data.get('celebrations', [])
if celebrations and player_id and world_id:
now_iso = datetime.utcnow().isoformat()
for cel in celebrations:
town_id_cel = str(cel.get('town_id', ''))
cel_type = cel.get('celebration_type', '')
finished_at = int(cel.get('finished_at', 0))
if not town_id_cel or not cel_type:
continue
# Resolve town_name from what we just upserted
t_name_row = c.execute(
'SELECT town_name FROM town_state WHERE town_id = ?', (town_id_cel,)
).fetchone()
t_name = t_name_row['town_name'] if t_name_row else ''
c.execute('''\
INSERT INTO celebrations
(player_id, world_id, town_id, town_name, celebration_type, finished_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(player_id, world_id, town_id, celebration_type) DO UPDATE SET
town_name = excluded.town_name,
finished_at = excluded.finished_at,
updated_at = excluded.updated_at
''', (str(player_id), world_id, town_id_cel, t_name, cel_type, finished_at, now_iso))
conn.commit()
conn.close()
return jsonify({'ok': True, 'towns_updated': len(towns)})
# ------------------------------------------------------------------
# GET /api/commands/pending
# Tampermonkey polls this to get the next command to execute.
@@ -266,11 +293,12 @@ def get_pending_command():
''', (two_minutes_ago, player_id))
build_cmds = _fetch_pending_builds_all_towns(c, player_id, world_id) # one per town
recruit_cmd = _fetch_pending_of_type(c, 'recruit', player_id, world_id)
recruit_cmd = _fetch_pending_of_type(c, 'recruit', player_id, world_id)
market_cmd = _fetch_pending_of_type(c, 'market_offer', player_id, world_id)
farm_cmd = _fetch_pending_of_type(c, 'farm_loot', player_id, world_id)
farm_cmd = _fetch_pending_of_type(c, 'farm_loot', player_id, world_id)
farm_upgrade_cmd = _fetch_pending_of_type(c, 'farm_upgrade', player_id, world_id)
research_cmd = _fetch_pending_of_type(c, 'research', player_id, world_id)
research_cmd = _fetch_pending_of_type(c, 'research', player_id, world_id)
culture_cmd = _fetch_pending_of_type(c, 'culture', player_id, world_id)
sync_req = _check_and_reset_sync(c, player_id)
# Determine player_key for world-specific settings if world_id is provided
@@ -324,6 +352,7 @@ def get_pending_command():
'research': research_cmd,
'farm': farm_cmd,
'farm_upgrade': farm_upgrade_cmd,
'culture': culture_cmd,
'farm_settings': farm_settings,
'bot_settings': bot_settings,
'enabled_features': enabled_features,
@@ -393,11 +422,26 @@ def command_result(cmd_id):
ON CONFLICT(key) DO UPDATE SET value=excluded.value, updated_at=excluded.updated_at
''', (lf_key, now, now))
# When a culture command finishes, update the matching culture_log row
if cmd and cmd['type'] == 'culture' and cmd['player_id']:
log_status = 'success' if status == 'done' else ('failed' if status == 'failed' else 'pending')
conn.execute('''\
UPDATE culture_log
SET status = ?, result_msg = ?, confirmed_at = ?
WHERE player_id = ? AND status = 'pending'
AND id = (
SELECT id FROM culture_log
WHERE player_id = ? AND status = 'pending'
ORDER BY id DESC LIMIT 1
)
''', (log_status, msg, now, str(cmd['player_id']), str(cmd['player_id'])))
conn.commit()
conn.close()
return jsonify({'ok': True})
# ------------------------------------------------------------------
# POST /api/captcha/alert
# Tampermonkey reports when #hcaptcha_window appears/disappears.