From 5bff9a287d079c2791d0c40f25bf8b223999dd74 Mon Sep 17 00:00:00 2001 From: haunter Date: Sun, 26 Apr 2026 13:55:25 +0300 Subject: [PATCH] MJ:Fix 2 --- GrepoRemoteLoader.user.js | 39 +++++++++++++++++++++++++-------------- bot_modules/02_state.js | 2 +- bot_modules/05_main.js | 18 ++++++++++++++---- routes/api.py | 4 ---- routes/dashboard.py | 4 ++-- 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/GrepoRemoteLoader.user.js b/GrepoRemoteLoader.user.js index d982662..d4e9442 100644 --- a/GrepoRemoteLoader.user.js +++ b/GrepoRemoteLoader.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Grepolis Remote Loader // @namespace http://tampermonkey.net/ -// @version 4.0.0 +// @version 4.0.1 // @description Dynamically loads the Grepolis Remote Control bot from the server // @author Dimitrios // @match https://*.grepolis.com/game/* @@ -15,37 +15,48 @@ (function() { 'use strict'; - // Set to your VPS domain - const BASE_URL = 'https://grepo.haunter-pets.top'; + const BASE_URL = 'https://grepo.haunter-pets.top'; + const MAX_TRIES = 3; + const RETRY_BASE = 3000; // 3 s, then 6 s + + function loadBot(attempt) { + attempt = attempt || 1; + console.log(`[Loader] Fetching bot code (attempt ${attempt}/${MAX_TRIES})...`); - function loadBot() { - console.log('[Loader] Fetching bot code from server...'); - GM_xmlhttpRequest({ method: 'GET', url: `${BASE_URL}/api/bot?t=${Date.now()}`, onload: function(response) { if (response.status === 200) { - console.log('[Loader] Bot code downloaded successfully! Executing...'); + console.log('[Loader] Bot code downloaded. Executing...'); try { eval(response.responseText); } catch (e) { - console.error('[Loader] Error executing bot code:', e); + console.error('[Loader] Execution error:', e); } + } else if (attempt < MAX_TRIES) { + const delay = RETRY_BASE * attempt; + console.warn(`[Loader] Server returned ${response.status}. Retrying in ${delay / 1000}s...`); + setTimeout(() => loadBot(attempt + 1), delay); } else { - console.error('[Loader] Failed to download bot. Server returned:', response.status); + console.error(`[Loader] Failed after ${MAX_TRIES} attempts (status ${response.status}). Give up.`); } }, - onerror: function(err) { - console.error('[Loader] Connection error while trying to reach the server.', err); + onerror: function() { + if (attempt < MAX_TRIES) { + const delay = RETRY_BASE * attempt; + console.warn(`[Loader] Connection error. Retrying in ${delay / 1000}s...`); + setTimeout(() => loadBot(attempt + 1), delay); + } else { + console.error(`[Loader] Failed after ${MAX_TRIES} attempts. Check your server.`); + } } }); } - // Wait for page to be ready before loading the heavy bot logic if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', loadBot); + document.addEventListener('DOMContentLoaded', () => loadBot(1)); } else { - loadBot(); + loadBot(1); } })(); diff --git a/bot_modules/02_state.js b/bot_modules/02_state.js index 4aadd5c..30e8015 100644 --- a/bot_modules/02_state.js +++ b/bot_modules/02_state.js @@ -12,7 +12,7 @@ function gatherState() { try { const pm = uw.MM.getModels().Player[player_id]; if (pm && pm.attributes) alliance_name = pm.attributes.alliance_name; - } catch (e) {} + } catch (e) { log(`Failed to extract alliance_name: ${e}`); } const total_points = uw.Game?.player_points ?? 0; const world = uw.Game?.world_id || ''; diff --git a/bot_modules/05_main.js b/bot_modules/05_main.js index d5af506..097ba1c 100644 --- a/bot_modules/05_main.js +++ b/bot_modules/05_main.js @@ -82,10 +82,20 @@ async function pollAndExecute() { const towns = Object.values(uw.ITowns?.towns || {}); for (const town of towns) { - const storage = town.resources?.()?.storage || town.get?.('storage') || 0; - const wood = town.resources?.()?.wood || town.get?.('wood') || 0; - const stone = town.resources?.()?.stone || town.get?.('stone') || 0; - const iron = town.resources?.()?.iron || town.get?.('iron') || 0; + // Use same multi-strategy lookup as gatherState() — res.storage is often 0 in Grepolis + const res = town.resources?.() || {}; + let storage = town.getStorageCapacity?.() || 0; + if (!storage) { + const buildings = town.buildings?.()?.attributes || {}; + const storageLevel = buildings.storage ?? 0; + const gd = uw.GameData?.buildingData?.storage; + storage = gd?.max_storage?.[storageLevel] || gd?.storage?.[storageLevel] || 0; + } + if (!storage) storage = res.capacity || res.storage_capacity || res.storage || 0; + + const wood = res.wood || 0; + const stone = res.stone || 0; + const iron = res.iron || 0; if (!storage) continue; const maxRes = Math.max(wood, stone, iron); diff --git a/routes/api.py b/routes/api.py index 1a95d2a..15666fe 100644 --- a/routes/api.py +++ b/routes/api.py @@ -103,8 +103,6 @@ def get_pending_command(): farm_cmd = _fetch_pending_of_type(c, 'farm_loot', player_id) farm_upgrade_cmd = _fetch_pending_of_type(c, 'farm_upgrade', player_id) research_cmd = _fetch_pending_of_type(c, 'research', player_id) - scan_market_cmd = _fetch_pending_of_type(c, 'scan_market', player_id) - accept_market_offer_cmd = _fetch_pending_of_type(c, 'accept_market_offer', player_id) sync_req = _check_and_reset_sync(c, player_id) # Also return current farm settings so TM knows loot_option @@ -123,8 +121,6 @@ def get_pending_command(): 'build': build_cmd, 'recruit': recruit_cmd, 'market': market_cmd, - 'scan_market': scan_market_cmd, - 'accept_market_offer': accept_market_offer_cmd, 'research': research_cmd, 'farm': farm_cmd, 'farm_upgrade': farm_upgrade_cmd, diff --git a/routes/dashboard.py b/routes/dashboard.py index 3fdb865..efd400e 100644 --- a/routes/dashboard.py +++ b/routes/dashboard.py @@ -284,8 +284,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', 'farm_loot', 'farm_upgrade', 'research', 'scan_market', 'accept_market_offer'): - return jsonify({'error': 'type must be build, recruit, market_offer, farm_loot, farm_upgrade, research, scan_market, or accept_market_offer'}), 400 + if cmd_type not in ('build', 'recruit', 'market_offer', 'farm_loot', 'farm_upgrade', 'research'): + return jsonify({'error': 'type must be build, recruit, market_offer, farm_loot, farm_upgrade, or research'}), 400 # Reject if the Tampermonkey client is offline (no state push in last 150 s) conn = get_db()