captcha block fix ?
This commit is contained in:
@@ -485,6 +485,10 @@
|
|||||||
skipped++; continue;
|
skipped++; continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (paused) {
|
||||||
|
return { ok: false, msg: 'Aborted due to pause/captcha' };
|
||||||
|
}
|
||||||
|
|
||||||
log(`Farm ${action}: farm_id=${farm.attributes.id} level=${level} town=${town_id}`);
|
log(`Farm ${action}: farm_id=${farm.attributes.id} level=${level} town=${town_id}`);
|
||||||
try {
|
try {
|
||||||
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
||||||
@@ -496,8 +500,8 @@
|
|||||||
isLocked ? unlocked++ : upgraded++;
|
isLocked ? unlocked++ : upgraded++;
|
||||||
} catch (e) { errors++; }
|
} catch (e) { errors++; }
|
||||||
|
|
||||||
// Random delay between actions: 800ms – 2000ms
|
// Random delay between actions: 1200ms – 2500ms
|
||||||
await sleep(randInt(800, 2000));
|
await sleep(randInt(1200, 2500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -626,6 +630,10 @@
|
|||||||
log(`Farm: ${readyFarms.length} ready on island of town ${town_id}`);
|
log(`Farm: ${readyFarms.length} ready on island of town ${town_id}`);
|
||||||
|
|
||||||
for (const farm of readyFarms) {
|
for (const farm of readyFarms) {
|
||||||
|
if (paused) {
|
||||||
|
return { ok: false, msg: 'Aborted due to pause/captcha' };
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
||||||
model_url: `FarmTownPlayerRelation/${farm.relation_id}`,
|
model_url: `FarmTownPlayerRelation/${farm.relation_id}`,
|
||||||
@@ -636,8 +644,8 @@
|
|||||||
claimed++;
|
claimed++;
|
||||||
} catch (e) { errors++; }
|
} catch (e) { errors++; }
|
||||||
|
|
||||||
// Random per-claim delay: 500ms – 1500ms (never below 500ms)
|
// Random per-claim delay: 1000ms – 2200ms
|
||||||
await sleep(randInt(500, 1500));
|
await sleep(randInt(1000, 2200));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh map icons after claiming (same as original)
|
// Refresh map icons after claiming (same as original)
|
||||||
@@ -645,6 +653,7 @@
|
|||||||
|
|
||||||
// Random between-island delay: 30s – 90s (only if more islands remain)
|
// Random between-island delay: 30s – 90s (only if more islands remain)
|
||||||
if (i < islandList.length - 1) {
|
if (i < islandList.length - 1) {
|
||||||
|
if (paused) return { ok: false, msg: 'Aborted due to pause/captcha' };
|
||||||
const gap = randInt(30000, 90000);
|
const gap = randInt(30000, 90000);
|
||||||
log(`Farm: island done. Waiting ${(gap / 1000).toFixed(0)}s before next island...`);
|
log(`Farm: island done. Waiting ${(gap / 1000).toFixed(0)}s before next island...`);
|
||||||
await sleep(gap);
|
await sleep(gap);
|
||||||
@@ -698,6 +707,8 @@
|
|||||||
log(`Waiting ${reactionMs}ms before firing buildUp (reaction time)...`);
|
log(`Waiting ${reactionMs}ms before firing buildUp (reaction time)...`);
|
||||||
await sleep(reactionMs);
|
await sleep(reactionMs);
|
||||||
|
|
||||||
|
if (paused) return { ok: false, msg: 'Aborted due to pause/captcha' };
|
||||||
|
|
||||||
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
||||||
model_url: 'BuildingOrder',
|
model_url: 'BuildingOrder',
|
||||||
action_name: 'buildUp',
|
action_name: 'buildUp',
|
||||||
@@ -733,6 +744,8 @@
|
|||||||
log(`Waiting ${reactionMs}ms before firing recruit (reaction time)...`);
|
log(`Waiting ${reactionMs}ms before firing recruit (reaction time)...`);
|
||||||
await sleep(reactionMs);
|
await sleep(reactionMs);
|
||||||
|
|
||||||
|
if (paused) return { ok: false, msg: 'Aborted due to pause/captcha' };
|
||||||
|
|
||||||
uw.gpAjax.ajaxPost(endpoint, 'build', {
|
uw.gpAjax.ajaxPost(endpoint, 'build', {
|
||||||
unit_id,
|
unit_id,
|
||||||
amount: parseInt(amount) || 1,
|
amount: parseInt(amount) || 1,
|
||||||
@@ -759,6 +772,8 @@
|
|||||||
log(`Waiting ${reactionMs}ms before firing market offer (reaction time)...`);
|
log(`Waiting ${reactionMs}ms before firing market offer (reaction time)...`);
|
||||||
await sleep(reactionMs);
|
await sleep(reactionMs);
|
||||||
|
|
||||||
|
if (paused) return { ok: false, msg: 'Aborted due to pause/captcha' };
|
||||||
|
|
||||||
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
||||||
model_url: 'CreateOffers/' + town_id,
|
model_url: 'CreateOffers/' + town_id,
|
||||||
action_name: 'createOffer',
|
action_name: 'createOffer',
|
||||||
@@ -796,23 +811,7 @@
|
|||||||
const farmCmd = cmdData.farm;
|
const farmCmd = cmdData.farm;
|
||||||
const farmUpgradeCmd = cmdData.farm_upgrade;
|
const farmUpgradeCmd = cmdData.farm_upgrade;
|
||||||
|
|
||||||
// Auto-farm: if enabled, claim all ready farms (no explicit command needed)
|
|
||||||
const farmSettings = cmdData.farm_settings || {};
|
|
||||||
if (farmSettings.enabled && !farmCmd) {
|
|
||||||
const nowTs = Math.floor(Date.now() / 1000);
|
|
||||||
// Check if any town has ready farms before triggering
|
|
||||||
const hasFarms = Object.values(uw.ITowns?.towns || {}).some(t => {
|
|
||||||
try {
|
|
||||||
const coll = uw.MM.getOnlyCollectionByName('FarmTownPlayerRelation');
|
|
||||||
return coll?.models?.some(r => r.attributes.relation_status === 1 && (r.attributes.lootable_at || 0) <= nowTs);
|
|
||||||
} catch (e) { return false; }
|
|
||||||
});
|
|
||||||
if (hasFarms) {
|
|
||||||
log('⚡ Auto-farm: ready farms detected, triggering loot...');
|
|
||||||
await executeFarmLoot({ payload: { loot_option: farmSettings.loot_option } });
|
|
||||||
pushState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmdData.sync_requested) {
|
if (cmdData.sync_requested) {
|
||||||
log('Sync requested by server — pushing state immediately');
|
log('Sync requested by server — pushing state immediately');
|
||||||
@@ -838,10 +837,30 @@
|
|||||||
reportResult(cmd.id, finalStatus, result.msg);
|
reportResult(cmd.id, finalStatus, result.msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run concurrently — they do NOT block each other
|
// Run sequentially — humans cannot perform 3 actions simultaneously!
|
||||||
await Promise.all([execute(buildCmd), execute(recruitCmd), execute(marketCmd)]);
|
await execute(buildCmd);
|
||||||
if (farmCmd) await execute(farmCmd);
|
await execute(recruitCmd);
|
||||||
if (farmUpgradeCmd) await execute(farmUpgradeCmd);
|
await execute(marketCmd);
|
||||||
|
await execute(farmCmd);
|
||||||
|
await execute(farmUpgradeCmd);
|
||||||
|
|
||||||
|
// Auto-farm: if enabled, claim all ready farms (no explicit command needed)
|
||||||
|
const farmSettings = cmdData.farm_settings || {};
|
||||||
|
if (farmSettings.enabled && !farmCmd) {
|
||||||
|
const nowTs = Math.floor(Date.now() / 1000);
|
||||||
|
// Check if ANY farm relation is ready (no need to iterate per-town)
|
||||||
|
const hasFarms = (() => {
|
||||||
|
try {
|
||||||
|
const coll = uw.MM.getOnlyCollectionByName('FarmTownPlayerRelation');
|
||||||
|
return coll?.models?.some(r => r.attributes.relation_status === 1 && (r.attributes.lootable_at || 0) <= nowTs);
|
||||||
|
} catch (e) { return false; }
|
||||||
|
})();
|
||||||
|
if (hasFarms) {
|
||||||
|
log('⚡ Auto-farm: ready farms detected, triggering loot...');
|
||||||
|
await executeFarmLoot({ payload: { loot_option: farmSettings.loot_option } });
|
||||||
|
pushState();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
|
|||||||
@@ -275,8 +275,11 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div style="display: flex; gap: 1rem; align-items: center;">
|
||||||
<button class="save-btn" id="save-btn" onclick="saveSettings()">💾 Αποθήκευση</button>
|
<button class="save-btn" id="save-btn" onclick="saveSettings()">💾 Αποθήκευση</button>
|
||||||
<span class="save-status" id="save-status">✓ Αποθηκεύτηκε</span>
|
<button class="save-btn" id="manual-loot-btn" onclick="triggerManualLoot()" style="background: linear-gradient(135deg, #2a5a7a, #4a9ccc);">🌾 Λεηλασία Τώρα</button>
|
||||||
|
<span class="save-status" id="save-status">✓ Στάλθηκε</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Farm Upgrade Panel -->
|
<!-- Farm Upgrade Panel -->
|
||||||
@@ -475,6 +478,33 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- Trigger Manual Loot --
|
||||||
|
function triggerManualLoot() {
|
||||||
|
const btn = document.getElementById('manual-loot-btn');
|
||||||
|
const originalText = btn.innerText;
|
||||||
|
btn.innerText = '⏳ Αποστολή...';
|
||||||
|
btn.disabled = true;
|
||||||
|
|
||||||
|
fetch('/dashboard/commands', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
player_id: PLAYER_ID,
|
||||||
|
town_id: 0,
|
||||||
|
type: 'farm_loot',
|
||||||
|
payload: { loot_option: selectedOption }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(() => {
|
||||||
|
btn.innerText = '✓ Εστάλη!';
|
||||||
|
setTimeout(() => {
|
||||||
|
btn.innerText = originalText;
|
||||||
|
btn.disabled = false;
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// -- Boot --
|
// -- Boot --
|
||||||
loadSettings();
|
loadSettings();
|
||||||
loadFarmData();
|
loadFarmData();
|
||||||
|
|||||||
Reference in New Issue
Block a user