multi account large update

This commit is contained in:
2026-04-21 21:10:14 +03:00
parent c9da46a530
commit db78568340
7 changed files with 141 additions and 32 deletions

View File

@@ -65,13 +65,13 @@ def receive_state():
# Returns one 'build' AND one 'recruit' command independently,
# so both queues are served in parallel without blocking each other.
# ------------------------------------------------------------------
def _fetch_pending_of_type(c, cmd_type):
def _fetch_pending_of_type(c, cmd_type, player_id):
row = c.execute('''
SELECT * FROM commands
WHERE status = 'pending' AND type = ?
WHERE status = 'pending' AND type = ? AND player_id = ?
ORDER BY id ASC
LIMIT 1
''', (cmd_type,)).fetchone()
''', (cmd_type, player_id)).fetchone()
if not row:
return None
c.execute('''
@@ -88,12 +88,16 @@ def _fetch_pending_of_type(c, cmd_type):
@api.route('/api/commands/pending', methods=['GET'])
def get_pending_command():
player_id = request.args.get('player_id')
if not player_id:
return jsonify({'error': 'no player_id provided'}), 400
conn = get_db()
c = conn.cursor()
build_cmd = _fetch_pending_of_type(c, 'build')
recruit_cmd = _fetch_pending_of_type(c, 'recruit')
market_cmd = _fetch_pending_of_type(c, 'market_offer')
build_cmd = _fetch_pending_of_type(c, 'build', player_id)
recruit_cmd = _fetch_pending_of_type(c, 'recruit', player_id)
market_cmd = _fetch_pending_of_type(c, 'market_offer', player_id)
conn.commit()
conn.close()
@@ -133,16 +137,22 @@ def command_result(cmd_id):
# ------------------------------------------------------------------
@api.route('/api/captcha/alert', methods=['POST'])
def captcha_alert():
player_id = request.args.get('player_id')
if not player_id:
return jsonify({'error': 'no player_id provided'}), 400
data = request.get_json(silent=True) or {}
detected = bool(data.get('detected', False))
kv_key = f'captcha_active_{player_id}'
conn = get_db()
conn.execute('''
INSERT INTO kv_store (key, value, updated_at)
VALUES ('captcha_active', ?, ?)
VALUES (?, ?, ?)
ON CONFLICT(key) DO UPDATE SET
value = excluded.value,
updated_at = excluded.updated_at
''', ('1' if detected else '0', datetime.utcnow().isoformat()))
''', (kv_key, '1' if detected else '0', datetime.utcnow().isoformat()))
conn.commit()
conn.close()
return jsonify({'ok': True})