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

@@ -12,7 +12,14 @@ dashboard = Blueprint('dashboard', __name__)
# ------------------------------------------------------------------
@dashboard.route('/')
def index():
return render_template('dashboard.html')
conn = get_db()
players = conn.execute('SELECT DISTINCT player, player_id FROM town_state WHERE player IS NOT NULL ORDER BY player ASC').fetchall()
conn.close()
return render_template('index.html', players=players)
@dashboard.route('/player/<player_id>')
def player_dashboard(player_id):
return render_template('dashboard.html', player_id=player_id)
# ------------------------------------------------------------------
@@ -21,13 +28,15 @@ def index():
# ------------------------------------------------------------------
@dashboard.route('/dashboard/towns', methods=['GET'])
def get_towns():
player_id = request.args.get('player_id')
conn = get_db()
rows = conn.execute('''
SELECT town_id, town_name, player, player_id, alliance_id,
world_id, x, y, sea, data, updated_at
FROM town_state
WHERE player_id = ?
ORDER BY town_name ASC
''').fetchall()
''', (player_id, )).fetchall()
conn.close()
towns = []
@@ -74,10 +83,11 @@ def get_towns():
# ------------------------------------------------------------------
@dashboard.route('/dashboard/client-status', methods=['GET'])
def client_status():
player_id = request.args.get('player_id')
conn = get_db()
row = conn.execute('''
SELECT MAX(updated_at) AS last_seen FROM town_state
''').fetchone()
SELECT MAX(updated_at) AS last_seen FROM town_state WHERE player_id = ?
''', (player_id, )).fetchone()
conn.close()
last_seen = row['last_seen'] if row else None
@@ -100,9 +110,10 @@ def client_status():
# ------------------------------------------------------------------
@dashboard.route('/dashboard/captcha-status', methods=['GET'])
def captcha_status():
player_id = request.args.get('player_id')
conn = get_db()
row = conn.execute(
"SELECT value FROM kv_store WHERE key = 'captcha_active'"
"SELECT value FROM kv_store WHERE key = ?", (f'captcha_active_{player_id}', )
).fetchone()
conn.close()
active = bool(row and row['value'] == '1')
@@ -115,13 +126,15 @@ def captcha_status():
# ------------------------------------------------------------------
@dashboard.route('/dashboard/commands', methods=['GET'])
def get_commands():
player_id = request.args.get('player_id')
conn = get_db()
rows = conn.execute('''
SELECT id, town_id, town_name, type, payload, status, result_msg, created_at, updated_at
FROM commands
WHERE player_id = ?
ORDER BY id DESC
LIMIT 50
''').fetchall()
''', (player_id, )).fetchall()
conn.close()
return jsonify([dict(r) for r in rows])
@@ -138,7 +151,7 @@ def create_command():
if not data:
return jsonify({'error': 'no data'}), 400
required = ['town_id', 'type', 'payload']
required = ['town_id', 'type', 'payload', 'player_id']
for field in required:
if field not in data:
return jsonify({'error': f'missing field: {field}'}), 400
@@ -149,7 +162,7 @@ def create_command():
# Reject if the Tampermonkey client is offline (no state push in last 150 s)
conn = get_db()
row = conn.execute('SELECT MAX(updated_at) AS last_seen FROM town_state').fetchone()
row = conn.execute('SELECT MAX(updated_at) AS last_seen FROM town_state WHERE player_id = ?', (data['player_id'], )).fetchone()
last_seen = row['last_seen'] if row else None
client_online = False
if last_seen:
@@ -165,15 +178,16 @@ def create_command():
c = conn.cursor()
c.execute('''
INSERT INTO commands (town_id, town_name, type, payload, status, created_at, updated_at)
VALUES (?, ?, ?, ?, 'pending', ?, ?)
INSERT INTO commands (town_id, town_name, type, payload, status, created_at, updated_at, player_id)
VALUES (?, ?, ?, ?, 'pending', ?, ?, ?)
''', (
str(data['town_id']),
data.get('town_name', ''),
cmd_type,
json.dumps(data['payload']),
datetime.utcnow().isoformat(),
datetime.utcnow().isoformat()
datetime.utcnow().isoformat(),
str(data['player_id'])
))
cmd_id = c.lastrowid
conn.commit()
@@ -202,6 +216,7 @@ def cancel_command(cmd_id):
# ------------------------------------------------------------------
@dashboard.route('/dashboard/commands/fail-stale', methods=['POST'])
def fail_stale_commands():
player_id = request.args.get('player_id')
conn = get_db()
c = conn.cursor()
c.execute('''
@@ -209,8 +224,8 @@ def fail_stale_commands():
SET status = 'failed',
result_msg = 'Client went offline',
updated_at = ?
WHERE status IN ('pending', 'executing')
''', (datetime.utcnow().isoformat(),))
WHERE status IN ('pending', 'executing') AND player_id = ?
''', (datetime.utcnow().isoformat(), player_id))
affected = c.rowcount
conn.commit()
conn.close()