farm fix between worlds

This commit is contained in:
2026-05-02 01:28:20 +03:00
parent 502b330ac5
commit 4272edf432
2 changed files with 16 additions and 7 deletions

View File

@@ -122,14 +122,22 @@ def set_farm_settings():
@dashboard.route('/dashboard/farm-data', methods=['GET'])
def get_farm_data():
player_id = request.args.get('player_id')
world_id = request.args.get('world_id')
conn = get_db()
if world_id:
rows = conn.execute(
'SELECT town_id, town_name, data FROM town_state WHERE player_id = ? AND world_id = ?',
(player_id, world_id)
).fetchall()
else:
rows = conn.execute(
'SELECT town_id, town_name, data FROM town_state WHERE player_id = ?', (player_id,)
).fetchall()
# Also fetch when the bot last farmed
# Also fetch when the bot last farmed (per world)
lf_key = f'last_farmed_{player_id}_{world_id}' if world_id else f'last_farmed_{player_id}'
lf_row = conn.execute(
"SELECT value FROM kv_store WHERE key = ?", (f'last_farmed_{player_id}',)
"SELECT value FROM kv_store WHERE key = ?", (lf_key,)
).fetchone()
last_farmed_at = lf_row['value'] if lf_row else None
conn.close()

View File

@@ -233,7 +233,7 @@
<body>
<div class="topbar">
<a href="/player/{{ player_id }}">← Πίσω</a>
<a href="/player/{{ player_id }}/{{ world_id }}">← Πίσω</a>
<h1>🌾 Farm Manager</h1>
<span class="online-dot" id="online-dot" title="Κατάσταση Script"></span>
<button class="sync-btn" onclick="requestSync()">Live Sync</button>
@@ -411,6 +411,7 @@
<script>
const PLAYER_ID = '{{ player_id }}';
const WORLD_ID = '{{ world_id }}';
let selectedOption = 1;
// -- Loot option buttons --
@@ -480,7 +481,7 @@
}
function loadFarmData() {
fetch(`/dashboard/farm-data?player_id=${PLAYER_ID}`)
fetch(`/dashboard/farm-data?player_id=${PLAYER_ID}&world_id=${WORLD_ID}`)
.then(r => r.json())
.then(resp => {
const data = resp.towns || [];