update add modules
This commit is contained in:
@@ -49,9 +49,85 @@ def index():
|
||||
return render_template('index.html', players=players)
|
||||
|
||||
@dashboard.route('/player/<player_id>')
|
||||
def player_hub(player_id):
|
||||
return render_template('hub.html', player_id=player_id)
|
||||
|
||||
@dashboard.route('/player/<player_id>/admin')
|
||||
def player_dashboard(player_id):
|
||||
return render_template('dashboard.html', player_id=player_id)
|
||||
|
||||
@dashboard.route('/player/<player_id>/farm')
|
||||
def player_farm(player_id):
|
||||
return render_template('farm.html', player_id=player_id)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /dashboard/farm-settings — returns current farm config
|
||||
# POST /dashboard/farm-settings — updates farm config
|
||||
# ------------------------------------------------------------------
|
||||
@dashboard.route('/dashboard/farm-settings', methods=['GET'])
|
||||
def get_farm_settings():
|
||||
player_id = request.args.get('player_id')
|
||||
conn = get_db()
|
||||
row = conn.execute(
|
||||
'SELECT enabled, loot_option FROM farm_settings WHERE player_id = ?', (player_id,)
|
||||
).fetchone()
|
||||
conn.close()
|
||||
if row:
|
||||
return jsonify({'enabled': bool(row['enabled']), 'loot_option': row['loot_option']})
|
||||
return jsonify({'enabled': False, 'loot_option': 1})
|
||||
|
||||
@dashboard.route('/dashboard/farm-settings', methods=['POST'])
|
||||
def set_farm_settings():
|
||||
data = request.get_json(silent=True)
|
||||
if not data or 'player_id' not in data:
|
||||
return jsonify({'error': 'missing player_id'}), 400
|
||||
player_id = data['player_id']
|
||||
enabled = 1 if data.get('enabled') else 0
|
||||
loot_option = int(data.get('loot_option', 1))
|
||||
conn = get_db()
|
||||
conn.execute('''
|
||||
INSERT INTO farm_settings (player_id, enabled, loot_option, updated_at)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(player_id) DO UPDATE SET
|
||||
enabled = excluded.enabled,
|
||||
loot_option = excluded.loot_option,
|
||||
updated_at = excluded.updated_at
|
||||
''', (player_id, enabled, loot_option, datetime.utcnow().isoformat()))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'ok': True})
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /dashboard/farm-data
|
||||
# Returns ready-to-loot farm towns for a player across all towns
|
||||
# ------------------------------------------------------------------
|
||||
@dashboard.route('/dashboard/farm-data', methods=['GET'])
|
||||
def get_farm_data():
|
||||
player_id = request.args.get('player_id')
|
||||
conn = get_db()
|
||||
rows = conn.execute(
|
||||
'SELECT town_id, town_name, data FROM town_state WHERE player_id = ?', (player_id,)
|
||||
).fetchall()
|
||||
conn.close()
|
||||
|
||||
now_ts = int(datetime.utcnow().timestamp())
|
||||
farms_summary = []
|
||||
for row in rows:
|
||||
d = json.loads(row['data'])
|
||||
farm_data = d.get('farms', [])
|
||||
ready = [f for f in farm_data if f.get('lootable_at', 0) <= now_ts]
|
||||
if farm_data:
|
||||
farms_summary.append({
|
||||
'town_id': row['town_id'],
|
||||
'town_name': row['town_name'],
|
||||
'total_farms': len(farm_data),
|
||||
'ready_farms': len(ready),
|
||||
'next_ready_at': min((f['lootable_at'] for f in farm_data if f.get('lootable_at', 0) > now_ts), default=None)
|
||||
})
|
||||
return jsonify(farms_summary)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /dashboard/towns
|
||||
@@ -190,8 +266,8 @@ def create_command():
|
||||
return jsonify({'error': f'missing field: {field}'}), 400
|
||||
|
||||
cmd_type = data['type']
|
||||
if cmd_type not in ('build', 'recruit', 'market_offer'):
|
||||
return jsonify({'error': 'type must be build, recruit, or market_offer'}), 400
|
||||
if cmd_type not in ('build', 'recruit', 'market_offer', 'farm_loot'):
|
||||
return jsonify({'error': 'type must be build, recruit, market_offer, or farm_loot'}), 400
|
||||
|
||||
# Reject if the Tampermonkey client is offline (no state push in last 150 s)
|
||||
conn = get_db()
|
||||
|
||||
Reference in New Issue
Block a user