Update bot.js
Browse files
bot.js
CHANGED
|
@@ -44,31 +44,63 @@ const CIFTCI_SELL_ALL_SLOT = 45;
|
|
| 44 |
const CIFTCI_COMMAND = "/çiftçi menü";
|
| 45 |
const CIFTCI_WINDOW_TIMEOUT_MS = 6000;
|
| 46 |
const CIFTCI_LORE_FALLBACK_KEYWORDS = ["hepsini sat"];
|
| 47 |
-
// Menü açıldıktan sonra sunucunun içeriği (lore/slot) tam yerleştirmesi için
|
| 48 |
-
// beklenecek süre, tıklamadan önce. Ardından art arda birkaç kez tıklanır.
|
| 49 |
const CIFTCI_CLICK_DELAY_AFTER_OPEN_MS = 1000;
|
| 50 |
const CIFTCI_CLICK_REPEAT_COUNT = 3;
|
| 51 |
const CIFTCI_CLICK_REPEAT_GAP_MS = 350;
|
| 52 |
|
| 53 |
-
|
| 54 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
const CIFTCI_CYCLE_INTERVAL_MS = 60 * 1000; // 1 dakika
|
| 58 |
|
| 59 |
-
|
| 60 |
-
const
|
| 61 |
-
const
|
| 62 |
-
const FAILOVER_HOME_ARRIVAL_DELAY_MS = 4000; // yedek hesapta /is go sonrası varış beklemesi
|
| 63 |
const FAILOVER_LOGIN_DELAY_MS = 2500;
|
| 64 |
const FAILOVER_SKYBLOCK_DELAY_MS = 7500;
|
| 65 |
const FAILOVER_ISGO_DELAY_MS = 12500;
|
| 66 |
-
const FAILOVER_RECHECK_INTERVAL_MS = 20 * 1000;
|
| 67 |
-
const FAILOVER_MAX_WAIT_MS = 60 * 60 * 1000;
|
| 68 |
-
const FAILOVER_SPAWN_TIMEOUT_MS = 30 * 1000;
|
| 69 |
|
| 70 |
-
// İzlenen (KAZICI_NAMES ile eşleşmeyen, başka hesaptan konan) kazıcı minyonların
|
| 71 |
-
// skin texture hash'i. Bu skin + elde iron_pickaxe olan armor stand'ler izlenir.
|
| 72 |
const WATCHED_KAZICI_SKIN_HASHES = new Set([
|
| 73 |
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDQ4ODcwY2E3N2FhNjk5ZDAxNzA5M2I4Mjc3OWQwYTU5OGRjNGYzZjQ5ZDM1MTUzMmFlNGQ5NjMzZGNjMmE1YSJ9fX0=",
|
| 74 |
]);
|
|
@@ -83,7 +115,6 @@ let messagesTimeout = null;
|
|
| 83 |
let isListeningChat = false;
|
| 84 |
const ansiToHtmlConvert = new (require('ansi-to-html'))({ newline: true });
|
| 85 |
|
| 86 |
-
// --- GÜVENLİ BAĞLANTI DEĞİŞKENLERİ ---
|
| 87 |
let isConnecting = false;
|
| 88 |
let isDestroying = false;
|
| 89 |
let reconnectTimeout = null;
|
|
@@ -92,42 +123,37 @@ let currentStream = null;
|
|
| 92 |
let currentSocket = null;
|
| 93 |
let windowOpenResolvers = [];
|
| 94 |
|
| 95 |
-
// --- PANEL METRİKLERİ ---
|
| 96 |
let botUptimeStart = null;
|
| 97 |
let lastFullFeedTimeStr = "Henüz besleme yapılmadı";
|
| 98 |
let lastCheckTimeStr = "Henüz kontrol yapılmadı";
|
| 99 |
let nextScheduledCheckTimeStr = "Botun spawn olması bekleniyor...";
|
| 100 |
|
| 101 |
-
// --- KAZICI PANEL METRİKLERİ (bağımsız) ---
|
| 102 |
let lastKaziciCheckTimeStr = "Henüz kazıcı kontrolü yapılmadı";
|
| 103 |
let nextKaziciTimeStr = "Botun spawn olması bekleniyor...";
|
| 104 |
let nextKaziciAtMs = null;
|
| 105 |
|
| 106 |
-
// --- ÇİFTÇİ PANEL METRİKLERİ (bağımsız) ---
|
| 107 |
let lastCiftciSellTimeStr = "Henüz çiftçi satışı yapılmadı";
|
| 108 |
let nextCiftciTimeStr = "Botun spawn olması bekleniyor...";
|
| 109 |
let nextCiftciAtMs = null;
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
let
|
| 114 |
-
let
|
| 115 |
-
let
|
| 116 |
-
let
|
|
|
|
| 117 |
|
| 118 |
-
|
| 119 |
-
let poseTracker = new Map(); // entityId -> { poseKey, lastChangeAt, uuid }
|
| 120 |
let stallCheckIntervalHandle = null;
|
| 121 |
-
let failoverModeActive = false;
|
| 122 |
-
let failoverBot = null;
|
| 123 |
-
let failoverInProgress = false;
|
| 124 |
|
| 125 |
-
// --- DİNAMİK IP VE KONUM BİLGİLERİ ---
|
| 126 |
let activeConnectionIp = "Bilinmiyor";
|
| 127 |
let activeConnectionLocation = "Bilinmiyor";
|
| 128 |
let localExternalIp = "Bilinmiyor";
|
| 129 |
|
| 130 |
-
// --- DİNAMİK ZAMANLAYICI KONTROLÜ ---
|
| 131 |
let periodicTimeoutHandle = null;
|
| 132 |
let activeTimeouts = [];
|
| 133 |
|
|
@@ -137,7 +163,6 @@ function setSafeTimeout(fn, delay) {
|
|
| 137 |
return t;
|
| 138 |
}
|
| 139 |
|
| 140 |
-
// --- ÖNCELİKLİ GUI KİLİDİ (MUTEX) ---
|
| 141 |
class PriorityGuiMutex {
|
| 142 |
constructor() {
|
| 143 |
this._locked = false;
|
|
@@ -176,7 +201,9 @@ let botActions = {
|
|
| 176 |
goToIslandManual: null,
|
| 177 |
sendSkyblockManual: null,
|
| 178 |
antiBotMove: null,
|
| 179 |
-
sendMoneyToNick: null
|
|
|
|
|
|
|
| 180 |
};
|
| 181 |
|
| 182 |
function formatDurationMs(ms) {
|
|
@@ -217,6 +244,11 @@ function stopPeriodicHomeChecks() {
|
|
| 217 |
ciftciIntervalHandle = null;
|
| 218 |
logger.info("[Çiftçi Periyodik] Döngü zamanlayıcısı durduruldu.");
|
| 219 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
nextScheduledCheckAtMs = null;
|
| 222 |
nextKaziciAtMs = null;
|
|
@@ -225,7 +257,6 @@ function stopPeriodicHomeChecks() {
|
|
| 225 |
nextCiftciTimeStr = "Zamanlama durduruldu.";
|
| 226 |
}
|
| 227 |
|
| 228 |
-
// --- MANUEL DURDURMA/BAŞLATMA KONTROLÜ ---
|
| 229 |
let manualStopRequested = false;
|
| 230 |
|
| 231 |
async function getIpLocation(ip) {
|
|
@@ -274,14 +305,6 @@ https.get('https://api.ipify.org?format=json', (res) => {
|
|
| 274 |
});
|
| 275 |
}).on('error', () => {});
|
| 276 |
|
| 277 |
-
// =====================================================================
|
| 278 |
-
// KAZICI FAILOVER (YEDEK HESAP) YARDIMCI FONKSİYONLARI
|
| 279 |
-
// Bunlar module-level (createBot() dışında) çünkü bot bağlantısı kesilip
|
| 280 |
-
// yeniden kurulduğunda bile (createBot() tekrar çağrıldığında) hayatta
|
| 281 |
-
// kalmaları gerekiyor.
|
| 282 |
-
// =====================================================================
|
| 283 |
-
|
| 284 |
-
// Entity'nin skin texture değerini (player_head equipment'inden) çıkarır.
|
| 285 |
function getEntitySkinHash(entity) {
|
| 286 |
try {
|
| 287 |
const equipment = entity.equipment || [];
|
|
@@ -301,7 +324,6 @@ function getEntitySkinHash(entity) {
|
|
| 301 |
return null;
|
| 302 |
}
|
| 303 |
|
| 304 |
-
// Entity'nin elinde (equipment[0] = main hand) iron_pickaxe olup olmadığını kontrol eder.
|
| 305 |
function hasIronPickaxeEquipped(entity) {
|
| 306 |
try {
|
| 307 |
const equipment = entity.equipment || [];
|
|
@@ -312,7 +334,6 @@ function hasIronPickaxeEquipped(entity) {
|
|
| 312 |
}
|
| 313 |
}
|
| 314 |
|
| 315 |
-
// Skin + iron_pickaxe ikisi birden tutuyorsa bu entity izlenen kazıcı minyondur.
|
| 316 |
function isWatchedKaziciEntity(entity) {
|
| 317 |
if (!entity || entity.name !== "armor_stand") return false;
|
| 318 |
const skinHash = getEntitySkinHash(entity);
|
|
@@ -320,7 +341,6 @@ function isWatchedKaziciEntity(entity) {
|
|
| 320 |
return hasIronPickaxeEquipped(entity);
|
| 321 |
}
|
| 322 |
|
| 323 |
-
// metadata içindeki pose (kol/kafa açıları) + pozisyonu birleştirip bir imza çıkarır.
|
| 324 |
function getPoseKey(entity) {
|
| 325 |
try {
|
| 326 |
const md = entity.metadata || [];
|
|
@@ -339,8 +359,6 @@ function getPoseKey(entity) {
|
|
| 339 |
}
|
| 340 |
}
|
| 341 |
|
| 342 |
-
// bot.on('entityMoved', ...) ve bot.on('entitySpawn', ...) içinden çağrılır.
|
| 343 |
-
// İzlenen kazıcı minyonun pose'unu takip eder.
|
| 344 |
function trackKaziciPoseIfWatched(entity) {
|
| 345 |
if (!entity) return;
|
| 346 |
if (!isWatchedKaziciEntity(entity)) return;
|
|
@@ -358,10 +376,8 @@ function trackKaziciPoseIfWatched(entity) {
|
|
| 358 |
prev.poseKey = poseKey;
|
| 359 |
prev.lastChangeAt = Date.now();
|
| 360 |
}
|
| 361 |
-
// poseKey aynıysa lastChangeAt GÜNCELLENMEZ -> hareketsizlik süresi büyümeye devam eder.
|
| 362 |
}
|
| 363 |
|
| 364 |
-
// Artık dünyada olmayan entity kayıtlarını temizler.
|
| 365 |
function pruneStaleTrackedEntities() {
|
| 366 |
if (!bot || !bot.entities) return;
|
| 367 |
for (const id of poseTracker.keys()) {
|
|
@@ -402,9 +418,6 @@ function stopStallWatcher() {
|
|
| 402 |
poseTracker.clear();
|
| 403 |
}
|
| 404 |
|
| 405 |
-
// Ana hesabı geçici düşürüp yedek hesabı (kullaniciadi1) devreye alan, izlenen
|
| 406 |
-
// kazıcı minyonlar tekrar hareket edene kadar bekleyen, sonra ana hesabı
|
| 407 |
-
// yeniden bağlayan tam akış.
|
| 408 |
async function triggerFailoverSequence() {
|
| 409 |
if (failoverInProgress) return;
|
| 410 |
failoverInProgress = true;
|
|
@@ -415,7 +428,7 @@ async function triggerFailoverSequence() {
|
|
| 415 |
|
| 416 |
logger.warn(`[Failover] İzlenen kazıcı(lar) durdu. Ana hesap (${mainUsername}) geçici olarak düşürülüp yedek hesap (${backupUsername}) devreye alınıyor.`);
|
| 417 |
|
| 418 |
-
manualStopRequested = true;
|
| 419 |
stopPeriodicHomeChecks();
|
| 420 |
safeDestroyAllConnections();
|
| 421 |
|
|
@@ -434,9 +447,6 @@ async function triggerFailoverSequence() {
|
|
| 434 |
failoverInProgress = false;
|
| 435 |
}
|
| 436 |
|
| 437 |
-
// Yedek hesapla ayrı bir mineflayer bot'u başlatır: /login, /skyblock, /is go
|
| 438 |
-
// atar (ana hesaptaki ile AYNI gecikme süreleriyle), sonra izlenen minyonların
|
| 439 |
-
// hareketine bakar. Hareket geri gelince bağlantıyı kapatıp resolve eder.
|
| 440 |
function runBackupAccountAndWaitForRecovery(backupUsername) {
|
| 441 |
return new Promise((resolve) => {
|
| 442 |
const backupPoseTracker = new Map();
|
|
@@ -499,7 +509,6 @@ function runBackupAccountAndWaitForRecovery(backupUsername) {
|
|
| 499 |
logger.info(`[Failover - Yedek Hesap] ${GO_ISLAND_COMMAND} gönderildi, izlenen minyonların tekrar hareket etmesi bekleniyor...`);
|
| 500 |
}, FAILOVER_ISGO_DELAY_MS);
|
| 501 |
|
| 502 |
-
// Adaya varış + izleme başlatma
|
| 503 |
setTimeout(() => {
|
| 504 |
recheckHandle = setInterval(() => {
|
| 505 |
try {
|
|
@@ -516,7 +525,7 @@ function runBackupAccountAndWaitForRecovery(backupUsername) {
|
|
| 516 |
|
| 517 |
if (!prev) {
|
| 518 |
backupPoseTracker.set(e.id, { poseKey, lastChangeAt: Date.now() });
|
| 519 |
-
allRecovered = false;
|
| 520 |
continue;
|
| 521 |
}
|
| 522 |
|
|
@@ -524,7 +533,7 @@ function runBackupAccountAndWaitForRecovery(backupUsername) {
|
|
| 524 |
prev.poseKey = poseKey;
|
| 525 |
prev.lastChangeAt = Date.now();
|
| 526 |
} else if (Date.now() - prev.lastChangeAt < STALL_TIMEOUT_MS) {
|
| 527 |
-
//
|
| 528 |
} else {
|
| 529 |
allRecovered = false;
|
| 530 |
}
|
|
@@ -555,7 +564,6 @@ function runBackupAccountAndWaitForRecovery(backupUsername) {
|
|
| 555 |
}
|
| 556 |
});
|
| 557 |
|
| 558 |
-
// Güvenlik: sonsuza kadar beklemesin
|
| 559 |
safetyTimeoutHandle = setTimeout(() => {
|
| 560 |
logger.warn(`[Failover - Yedek Hesap] Azami bekleme süresi (${formatDurationMs(FAILOVER_MAX_WAIT_MS)}) doldu, ana hesaba geri dönülüyor.`);
|
| 561 |
finish();
|
|
@@ -915,8 +923,71 @@ async function createBot() {
|
|
| 915 |
}
|
| 916 |
return cur;
|
| 917 |
} catch (e) { return undefined; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 918 |
}
|
| 919 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 920 |
function deepSearchForString(root, targetVariantsList) {
|
| 921 |
const results = [];
|
| 922 |
const visited = new WeakSet();
|
|
@@ -990,6 +1061,20 @@ async function createBot() {
|
|
| 990 |
try {
|
| 991 |
if (!slot) return texts;
|
| 992 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 993 |
function extractPlain(raw) {
|
| 994 |
if (!raw || typeof raw !== "string") return null;
|
| 995 |
try {
|
|
@@ -1024,7 +1109,7 @@ async function createBot() {
|
|
| 1024 |
}
|
| 1025 |
} catch (err) {}
|
| 1026 |
return texts;
|
| 1027 |
-
}
|
| 1028 |
|
| 1029 |
function windowMatchesLoreKeyword(window, keywords) {
|
| 1030 |
try {
|
|
@@ -1061,12 +1146,10 @@ async function createBot() {
|
|
| 1061 |
}
|
| 1062 |
}
|
| 1063 |
|
| 1064 |
-
// --- SENDMONEY: /money oku, bakiyeden 1000 eksiğini ilgili nick'e /pay ile gönder ---
|
| 1065 |
const MONEY_BALANCE_REGEX = /bakiyen:\s*([\d.,]+)\s*TL/i;
|
| 1066 |
const MONEY_RESPONSE_TIMEOUT_MS = 8000;
|
| 1067 |
|
| 1068 |
function parseBalanceToAdjustedAmount(rawBalanceStr) {
|
| 1069 |
-
// "444,626.89" -> virgülleri kaldır -> "444626.89" -> noktadan öncesini al -> "444626"
|
| 1070 |
const noCommas = rawBalanceStr.replace(/,/g, "");
|
| 1071 |
const beforeDot = noCommas.split(".")[0];
|
| 1072 |
const intValue = parseInt(beforeDot, 10);
|
|
@@ -1148,22 +1231,21 @@ async function createBot() {
|
|
| 1148 |
if (!bot || !botIsReady) return;
|
| 1149 |
try {
|
| 1150 |
const moves = ['forward', 'left', 'right', 'jump'];
|
| 1151 |
-
|
| 1152 |
-
const moveCount = Math.floor(Math.random() * 4) + 2;
|
| 1153 |
-
|
| 1154 |
for (let i = 0; i < moveCount; i++) {
|
| 1155 |
const move = moves[Math.floor(Math.random() * moves.length)];
|
| 1156 |
const duration = 150 + Math.floor(Math.random() * 500);
|
| 1157 |
-
|
| 1158 |
bot.setControlState(move, true);
|
| 1159 |
await new Promise(r => setTimeout(r, duration));
|
| 1160 |
bot.setControlState(move, false);
|
| 1161 |
-
|
| 1162 |
await new Promise(r => setTimeout(r, 100 + Math.random() * 300));
|
| 1163 |
-
|
| 1164 |
}
|
| 1165 |
-
|
| 1166 |
-
// Rastgele kafa hareketi
|
| 1167 |
await bot.look(
|
| 1168 |
bot.entity.yaw + ((Math.random() - 0.5) * 1.5),
|
| 1169 |
bot.entity.pitch + ((Math.random() - 0.5) * 0.3),
|
|
@@ -1543,6 +1625,8 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1543 |
return;
|
| 1544 |
}
|
| 1545 |
|
|
|
|
|
|
|
| 1546 |
logger.info(`[${currentBotUsername}] Çiftçi (Hepsini Sat) menüsü açılıyor (${CIFTCI_COMMAND})...`);
|
| 1547 |
|
| 1548 |
if (bot.currentWindow != null) {
|
|
@@ -1617,6 +1701,627 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1617 |
}
|
| 1618 |
}
|
| 1619 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1620 |
function startKaziciPeriodic() {
|
| 1621 |
if (kaziciIntervalHandle) return;
|
| 1622 |
|
|
@@ -1697,9 +2402,12 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1697 |
botActions.sendSkyblockManual = sendSkyblockCommand;
|
| 1698 |
botActions.antiBotMove = antiBotMove;
|
| 1699 |
botActions.sendMoneyToNick = sendMoneyToNick;
|
|
|
|
|
|
|
| 1700 |
|
| 1701 |
startKaziciPeriodic();
|
| 1702 |
startCiftciPeriodic();
|
|
|
|
| 1703 |
startStallWatcher();
|
| 1704 |
|
| 1705 |
if (config.utils && config.utils["auto-auth"] && config.utils["auto-auth"].enabled) {
|
|
@@ -1766,12 +2474,14 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1766 |
(matchesAnyName(titleRaw, TARGET_CIFTCI_NORMS) || windowMatchesLoreKeyword(window, CIFTCI_LORE_FALLBACK_KEYWORDS));
|
| 1767 |
|
| 1768 |
if (!isBesleyiciWindow && !isKaziciWindow && !isCiftciWindow) {
|
| 1769 |
-
|
| 1770 |
-
|
| 1771 |
-
|
| 1772 |
-
|
| 1773 |
-
|
| 1774 |
-
|
|
|
|
|
|
|
| 1775 |
try {
|
| 1776 |
logger.info(`[${currentBotUsername}] Kazıcı minyon paneli açıldı. Depo aktarım slotuna (oyun içi 18. slot / mineflayer idx ${KAZICI_STORAGE_TRANSFER_SLOT}) tıklanıyor...`);
|
| 1777 |
await bot.clickWindow(KAZICI_STORAGE_TRANSFER_SLOT, 0, 0);
|
|
@@ -1784,30 +2494,35 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1784 |
try { bot.closeWindow(window); } catch(e){}
|
| 1785 |
|
| 1786 |
} else if (isCiftciWindow) {
|
| 1787 |
-
|
| 1788 |
-
|
| 1789 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1790 |
|
| 1791 |
-
|
| 1792 |
-
|
| 1793 |
-
|
| 1794 |
-
|
| 1795 |
-
|
| 1796 |
-
|
| 1797 |
-
|
| 1798 |
-
|
| 1799 |
-
|
| 1800 |
-
|
|
|
|
| 1801 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1802 |
}
|
| 1803 |
|
| 1804 |
-
|
| 1805 |
-
} catch (e) {
|
| 1806 |
-
logger.error(`[Çiftçi Arayüz Hatası] Hepsini-sat tıklama turu sırasında beklenmeyen hata: ${e && e.message ? e.message : e}`);
|
| 1807 |
}
|
| 1808 |
|
| 1809 |
-
try { bot.closeWindow(window); } catch(e){}
|
| 1810 |
-
|
| 1811 |
} else {
|
| 1812 |
const beefSlot = window.slots.find(s => s?.name === "cooked_beef");
|
| 1813 |
const can = extractMinyonCanFromSlot(beefSlot);
|
|
@@ -1864,6 +2579,7 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1864 |
}
|
| 1865 |
});
|
| 1866 |
|
|
|
|
| 1867 |
bot.on("end", () => {
|
| 1868 |
try {
|
| 1869 |
logger.warn(manualStopRequested ? "Bağlantı koptu. Manuel durdurma istendiği için yeniden bağlanılmayacak." : "Bağlantı koptu. Tüm zamanlayıcılar sıfırlanıyor ve YENİDEN BAĞLANMA SÜRECİ BAŞLIYOR...");
|
|
@@ -1887,6 +2603,8 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1887 |
botActions.sendSkyblockManual = null;
|
| 1888 |
botActions.antiBotMove = null;
|
| 1889 |
botActions.sendMoneyToNick = null;
|
|
|
|
|
|
|
| 1890 |
|
| 1891 |
safeDestroyAllConnections();
|
| 1892 |
|
|
@@ -1968,7 +2686,6 @@ function triggerSafeReconnect() {
|
|
| 1968 |
}, delay);
|
| 1969 |
}
|
| 1970 |
|
| 1971 |
-
// --- MANUEL BOT KONTROLÜ (stop/start/restart) ---
|
| 1972 |
let pendingHardRestartTimeout = null;
|
| 1973 |
|
| 1974 |
function stopBotHard(reason) {
|
|
@@ -2155,6 +2872,7 @@ app.get("/status", (req, res) => {
|
|
| 2155 |
next_kazici_check: nextKaziciTimeStr,
|
| 2156 |
last_ciftci_sell: lastCiftciSellTimeStr,
|
| 2157 |
next_ciftci_sell: nextCiftciTimeStr,
|
|
|
|
| 2158 |
gui_lock_busy: guiMutex.isLocked(),
|
| 2159 |
manually_stopped: manualStopRequested,
|
| 2160 |
is_connecting: isConnecting,
|
|
@@ -2162,7 +2880,15 @@ app.get("/status", (req, res) => {
|
|
| 2162 |
});
|
| 2163 |
});
|
| 2164 |
|
| 2165 |
-
/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2166 |
app.get("/bot/stop", (req, res) => {
|
| 2167 |
stopBotHard("Web paneli üzerinden /bot/stop isteği");
|
| 2168 |
res.send({ success: true, message: "Bot durduruldu. Tekrar başlatmak için /bot/start kullan." });
|
|
@@ -2197,6 +2923,14 @@ app.get("/bot/ciftci-satis", (req, res) => {
|
|
| 2197 |
botActions.openCiftciAndSellAllManual().catch(e => logger.error(`[/bot/ciftci-satis Hatası] ${e && e.stack ? e.stack : e}`));
|
| 2198 |
});
|
| 2199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2200 |
app.get("/bot/besleyici-kontrol", (req, res) => {
|
| 2201 |
if (!bot || !botIsReady || !botActions.scanAndFeedManual) {
|
| 2202 |
return res.status(503).send({ success: false, message: "Bot hazır değil." });
|
|
@@ -2279,6 +3013,26 @@ app.get("/bot/sendmoney", (req, res) => {
|
|
| 2279 |
});
|
| 2280 |
});
|
| 2281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2282 |
app.get("/", (req, res) => res.send("Bot Aktif"));
|
| 2283 |
|
| 2284 |
app.get("/messages", (req, res) => {
|
|
|
|
| 44 |
const CIFTCI_COMMAND = "/çiftçi menü";
|
| 45 |
const CIFTCI_WINDOW_TIMEOUT_MS = 6000;
|
| 46 |
const CIFTCI_LORE_FALLBACK_KEYWORDS = ["hepsini sat"];
|
|
|
|
|
|
|
| 47 |
const CIFTCI_CLICK_DELAY_AFTER_OPEN_MS = 1000;
|
| 48 |
const CIFTCI_CLICK_REPEAT_COUNT = 3;
|
| 49 |
const CIFTCI_CLICK_REPEAT_GAP_MS = 350;
|
| 50 |
|
| 51 |
+
const KAZICI_CYCLE_INTERVAL_MS = 5 * 60 * 1000;
|
| 52 |
+
const CIFTCI_CYCLE_INTERVAL_MS = 60 * 1000;
|
| 53 |
+
|
| 54 |
+
const CIFTCI_FILTER_MODES = [
|
| 55 |
+
"Standart",
|
| 56 |
+
"Favoriler",
|
| 57 |
+
"Depo dolumuna göre",
|
| 58 |
+
"Jeneratör materyalleri",
|
| 59 |
+
"Satışı açık olanlar",
|
| 60 |
+
"Toplaması açık olanlar"
|
| 61 |
+
];
|
| 62 |
+
const CIFTCI_TARGET_FILTER_INDEX = 3;
|
| 63 |
+
const CIFTCI_ACTIVE_FILTER_COLOR = "#FCF988";
|
| 64 |
+
const CIFTCI_FILTER_ITEM_NAME_KEYWORD = "Filtre";
|
| 65 |
+
const CIFTCI_FILTER_STEP_WAIT_MS = 1000;
|
| 66 |
+
const CIFTCI_FILTER_RETRY_WAIT_MS = 1000;
|
| 67 |
+
const CIFTCI_FILTER_MAX_RETRIES = 10;
|
| 68 |
+
const STORAGE_SCAN_INTERVAL_MS = 15 * 60 * 1000;
|
| 69 |
+
const STORAGE_TRACKED_ITEMS = ["diamond", "emerald", "iron_block"];
|
| 70 |
+
|
| 71 |
+
// --- SİPARİŞ (ORDER) SİSTEMİ AYARLARI ---
|
| 72 |
+
const ORDER_COMMAND_PREFIX = "/order";
|
| 73 |
+
const ORDER_WINDOW_TIMEOUT_MS = 8000;
|
| 74 |
+
const ORDER_WINDOW_SETTLE_DELAY_MS = 500;
|
| 75 |
+
const ORDER_AFTER_SELECT_DELAY_MS = 500;
|
| 76 |
+
const ORDER_IS_GO_SECOND_DELAY_MS = 5000;
|
| 77 |
+
const ORDER_ALLOWED_ITEMS = ["diamond", "emerald"];
|
| 78 |
+
const ORDER_LIST_TITLE_KEYWORD = "ѕiᴘᴀʀişʟᴇʀ";
|
| 79 |
+
const ORDER_DELIVERY_TITLE_KEYWORD = "ᴛᴇѕʟiᴍ ᴇᴛᴍᴇ";
|
| 80 |
+
// Nick seçildikten sonra Teslim Etme penceresinin gerçekten açılmasını beklemek için
|
| 81 |
+
// kullanılan zaman aşımı (sabit sleep yerine).
|
| 82 |
+
const ORDER_DELIVERY_WINDOW_WAIT_MS = 8000;
|
| 83 |
+
|
| 84 |
+
let storageInfoCache = {
|
| 85 |
+
diamond: null,
|
| 86 |
+
emerald: null,
|
| 87 |
+
iron_block: null,
|
| 88 |
+
lastUpdated: null
|
| 89 |
+
};
|
| 90 |
+
let storageScanIntervalHandle = null;
|
| 91 |
|
| 92 |
+
let ciftciWindowPurpose = "sell";
|
|
|
|
| 93 |
|
| 94 |
+
const STALL_CHECK_INTERVAL_MS = 15 * 1000;
|
| 95 |
+
const STALL_TIMEOUT_MS = 60 * 1000;
|
| 96 |
+
const FAILOVER_HOME_ARRIVAL_DELAY_MS = 4000;
|
|
|
|
| 97 |
const FAILOVER_LOGIN_DELAY_MS = 2500;
|
| 98 |
const FAILOVER_SKYBLOCK_DELAY_MS = 7500;
|
| 99 |
const FAILOVER_ISGO_DELAY_MS = 12500;
|
| 100 |
+
const FAILOVER_RECHECK_INTERVAL_MS = 20 * 1000;
|
| 101 |
+
const FAILOVER_MAX_WAIT_MS = 60 * 60 * 1000;
|
| 102 |
+
const FAILOVER_SPAWN_TIMEOUT_MS = 30 * 1000;
|
| 103 |
|
|
|
|
|
|
|
| 104 |
const WATCHED_KAZICI_SKIN_HASHES = new Set([
|
| 105 |
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDQ4ODcwY2E3N2FhNjk5ZDAxNzA5M2I4Mjc3OWQwYTU5OGRjNGYzZjQ5ZDM1MTUzMmFlNGQ5NjMzZGNjMmE1YSJ9fX0=",
|
| 106 |
]);
|
|
|
|
| 115 |
let isListeningChat = false;
|
| 116 |
const ansiToHtmlConvert = new (require('ansi-to-html'))({ newline: true });
|
| 117 |
|
|
|
|
| 118 |
let isConnecting = false;
|
| 119 |
let isDestroying = false;
|
| 120 |
let reconnectTimeout = null;
|
|
|
|
| 123 |
let currentSocket = null;
|
| 124 |
let windowOpenResolvers = [];
|
| 125 |
|
|
|
|
| 126 |
let botUptimeStart = null;
|
| 127 |
let lastFullFeedTimeStr = "Henüz besleme yapılmadı";
|
| 128 |
let lastCheckTimeStr = "Henüz kontrol yapılmadı";
|
| 129 |
let nextScheduledCheckTimeStr = "Botun spawn olması bekleniyor...";
|
| 130 |
|
|
|
|
| 131 |
let lastKaziciCheckTimeStr = "Henüz kazıcı kontrolü yapılmadı";
|
| 132 |
let nextKaziciTimeStr = "Botun spawn olması bekleniyor...";
|
| 133 |
let nextKaziciAtMs = null;
|
| 134 |
|
|
|
|
| 135 |
let lastCiftciSellTimeStr = "Henüz çiftçi satışı yapılmadı";
|
| 136 |
let nextCiftciTimeStr = "Botun spawn olması bekleniyor...";
|
| 137 |
let nextCiftciAtMs = null;
|
| 138 |
|
| 139 |
+
let lastOrderTimeStr = "Henüz sipariş işlemi yapılmadı";
|
| 140 |
+
|
| 141 |
+
let lastCheckAtMs = null;
|
| 142 |
+
let nextScheduledCheckAtMs = null;
|
| 143 |
+
let kaziciIntervalHandle = null;
|
| 144 |
+
let ciftciIntervalHandle = null;
|
| 145 |
+
let isMainCycleRunning = false;
|
| 146 |
|
| 147 |
+
let poseTracker = new Map();
|
|
|
|
| 148 |
let stallCheckIntervalHandle = null;
|
| 149 |
+
let failoverModeActive = false;
|
| 150 |
+
let failoverBot = null;
|
| 151 |
+
let failoverInProgress = false;
|
| 152 |
|
|
|
|
| 153 |
let activeConnectionIp = "Bilinmiyor";
|
| 154 |
let activeConnectionLocation = "Bilinmiyor";
|
| 155 |
let localExternalIp = "Bilinmiyor";
|
| 156 |
|
|
|
|
| 157 |
let periodicTimeoutHandle = null;
|
| 158 |
let activeTimeouts = [];
|
| 159 |
|
|
|
|
| 163 |
return t;
|
| 164 |
}
|
| 165 |
|
|
|
|
| 166 |
class PriorityGuiMutex {
|
| 167 |
constructor() {
|
| 168 |
this._locked = false;
|
|
|
|
| 201 |
goToIslandManual: null,
|
| 202 |
sendSkyblockManual: null,
|
| 203 |
antiBotMove: null,
|
| 204 |
+
sendMoneyToNick: null,
|
| 205 |
+
scanStorageInfoManual: null,
|
| 206 |
+
processOrderManual: null
|
| 207 |
};
|
| 208 |
|
| 209 |
function formatDurationMs(ms) {
|
|
|
|
| 244 |
ciftciIntervalHandle = null;
|
| 245 |
logger.info("[Çiftçi Periyodik] Döngü zamanlayıcısı durduruldu.");
|
| 246 |
}
|
| 247 |
+
if (storageScanIntervalHandle) {
|
| 248 |
+
clearInterval(storageScanIntervalHandle);
|
| 249 |
+
storageScanIntervalHandle = null;
|
| 250 |
+
logger.info("[Storage Tarama] Döngü zamanlayıcısı durduruldu.");
|
| 251 |
+
}
|
| 252 |
|
| 253 |
nextScheduledCheckAtMs = null;
|
| 254 |
nextKaziciAtMs = null;
|
|
|
|
| 257 |
nextCiftciTimeStr = "Zamanlama durduruldu.";
|
| 258 |
}
|
| 259 |
|
|
|
|
| 260 |
let manualStopRequested = false;
|
| 261 |
|
| 262 |
async function getIpLocation(ip) {
|
|
|
|
| 305 |
});
|
| 306 |
}).on('error', () => {});
|
| 307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
function getEntitySkinHash(entity) {
|
| 309 |
try {
|
| 310 |
const equipment = entity.equipment || [];
|
|
|
|
| 324 |
return null;
|
| 325 |
}
|
| 326 |
|
|
|
|
| 327 |
function hasIronPickaxeEquipped(entity) {
|
| 328 |
try {
|
| 329 |
const equipment = entity.equipment || [];
|
|
|
|
| 334 |
}
|
| 335 |
}
|
| 336 |
|
|
|
|
| 337 |
function isWatchedKaziciEntity(entity) {
|
| 338 |
if (!entity || entity.name !== "armor_stand") return false;
|
| 339 |
const skinHash = getEntitySkinHash(entity);
|
|
|
|
| 341 |
return hasIronPickaxeEquipped(entity);
|
| 342 |
}
|
| 343 |
|
|
|
|
| 344 |
function getPoseKey(entity) {
|
| 345 |
try {
|
| 346 |
const md = entity.metadata || [];
|
|
|
|
| 359 |
}
|
| 360 |
}
|
| 361 |
|
|
|
|
|
|
|
| 362 |
function trackKaziciPoseIfWatched(entity) {
|
| 363 |
if (!entity) return;
|
| 364 |
if (!isWatchedKaziciEntity(entity)) return;
|
|
|
|
| 376 |
prev.poseKey = poseKey;
|
| 377 |
prev.lastChangeAt = Date.now();
|
| 378 |
}
|
|
|
|
| 379 |
}
|
| 380 |
|
|
|
|
| 381 |
function pruneStaleTrackedEntities() {
|
| 382 |
if (!bot || !bot.entities) return;
|
| 383 |
for (const id of poseTracker.keys()) {
|
|
|
|
| 418 |
poseTracker.clear();
|
| 419 |
}
|
| 420 |
|
|
|
|
|
|
|
|
|
|
| 421 |
async function triggerFailoverSequence() {
|
| 422 |
if (failoverInProgress) return;
|
| 423 |
failoverInProgress = true;
|
|
|
|
| 428 |
|
| 429 |
logger.warn(`[Failover] İzlenen kazıcı(lar) durdu. Ana hesap (${mainUsername}) geçici olarak düşürülüp yedek hesap (${backupUsername}) devreye alınıyor.`);
|
| 430 |
|
| 431 |
+
manualStopRequested = true;
|
| 432 |
stopPeriodicHomeChecks();
|
| 433 |
safeDestroyAllConnections();
|
| 434 |
|
|
|
|
| 447 |
failoverInProgress = false;
|
| 448 |
}
|
| 449 |
|
|
|
|
|
|
|
|
|
|
| 450 |
function runBackupAccountAndWaitForRecovery(backupUsername) {
|
| 451 |
return new Promise((resolve) => {
|
| 452 |
const backupPoseTracker = new Map();
|
|
|
|
| 509 |
logger.info(`[Failover - Yedek Hesap] ${GO_ISLAND_COMMAND} gönderildi, izlenen minyonların tekrar hareket etmesi bekleniyor...`);
|
| 510 |
}, FAILOVER_ISGO_DELAY_MS);
|
| 511 |
|
|
|
|
| 512 |
setTimeout(() => {
|
| 513 |
recheckHandle = setInterval(() => {
|
| 514 |
try {
|
|
|
|
| 525 |
|
| 526 |
if (!prev) {
|
| 527 |
backupPoseTracker.set(e.id, { poseKey, lastChangeAt: Date.now() });
|
| 528 |
+
allRecovered = false;
|
| 529 |
continue;
|
| 530 |
}
|
| 531 |
|
|
|
|
| 533 |
prev.poseKey = poseKey;
|
| 534 |
prev.lastChangeAt = Date.now();
|
| 535 |
} else if (Date.now() - prev.lastChangeAt < STALL_TIMEOUT_MS) {
|
| 536 |
+
// ok
|
| 537 |
} else {
|
| 538 |
allRecovered = false;
|
| 539 |
}
|
|
|
|
| 564 |
}
|
| 565 |
});
|
| 566 |
|
|
|
|
| 567 |
safetyTimeoutHandle = setTimeout(() => {
|
| 568 |
logger.warn(`[Failover - Yedek Hesap] Azami bekleme süresi (${formatDurationMs(FAILOVER_MAX_WAIT_MS)}) doldu, ana hesaba geri dönülüyor.`);
|
| 569 |
finish();
|
|
|
|
| 923 |
}
|
| 924 |
return cur;
|
| 925 |
} catch (e) { return undefined; }
|
| 926 |
+
};
|
| 927 |
+
|
| 928 |
+
function getComponentData(slot, type) {
|
| 929 |
+
try {
|
| 930 |
+
if (!slot || !Array.isArray(slot.components)) return undefined;
|
| 931 |
+
const comp = slot.components.find(c => c && c.type === type);
|
| 932 |
+
return comp ? comp.data : undefined;
|
| 933 |
+
} catch (e) { return undefined; }
|
| 934 |
}
|
| 935 |
|
| 936 |
+
function nbtUnwrap(node) {
|
| 937 |
+
if (node && typeof node === "object" && "type" in node && "value" in node) {
|
| 938 |
+
return node.value;
|
| 939 |
+
}
|
| 940 |
+
return node;
|
| 941 |
+
};
|
| 942 |
+
|
| 943 |
+
function flattenTextComponent(node) {
|
| 944 |
+
if (node == null) return "";
|
| 945 |
+
if (typeof node === "string") return node;
|
| 946 |
+
if (Array.isArray(node)) return node.map(flattenTextComponent).join("");
|
| 947 |
+
|
| 948 |
+
if (typeof node === "object") {
|
| 949 |
+
if ("type" in node && "value" in node) {
|
| 950 |
+
const t = node.type, v = node.value;
|
| 951 |
+
if (t === "string") return typeof v === "string" ? v : "";
|
| 952 |
+
if (t === "list" || t === "compound") return flattenTextComponent(v);
|
| 953 |
+
return "";
|
| 954 |
+
}
|
| 955 |
+
let out = "";
|
| 956 |
+
if ("text" in node) out += flattenTextComponent(node.text);
|
| 957 |
+
if ("extra" in node) out += flattenTextComponent(node.extra);
|
| 958 |
+
return out;
|
| 959 |
+
}
|
| 960 |
+
return "";
|
| 961 |
+
};
|
| 962 |
+
|
| 963 |
+
function parseComponentLoreLine(lineNode) {
|
| 964 |
+
let text = "";
|
| 965 |
+
let color = null;
|
| 966 |
+
|
| 967 |
+
function walk(node) {
|
| 968 |
+
if (node == null) return;
|
| 969 |
+
if (typeof node === "string") { text += node; return; }
|
| 970 |
+
if (Array.isArray(node)) { node.forEach(walk); return; }
|
| 971 |
+
if (typeof node === "object") {
|
| 972 |
+
if ("type" in node && "value" in node) {
|
| 973 |
+
const t = node.type, v = node.value;
|
| 974 |
+
if (t === "string") { text += (typeof v === "string" ? v : ""); return; }
|
| 975 |
+
if (t === "list" || t === "compound") { walk(v); return; }
|
| 976 |
+
return;
|
| 977 |
+
}
|
| 978 |
+
if ("color" in node) {
|
| 979 |
+
const colVal = nbtUnwrap(node.color);
|
| 980 |
+
if (color == null && typeof colVal === "string") color = colVal;
|
| 981 |
+
}
|
| 982 |
+
if ("text" in node) walk(node.text);
|
| 983 |
+
if ("extra" in node) walk(node.extra);
|
| 984 |
+
}
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
walk(lineNode);
|
| 988 |
+
return { text: text.trim(), color };
|
| 989 |
+
};
|
| 990 |
+
|
| 991 |
function deepSearchForString(root, targetVariantsList) {
|
| 992 |
const results = [];
|
| 993 |
const visited = new WeakSet();
|
|
|
|
| 1061 |
try {
|
| 1062 |
if (!slot) return texts;
|
| 1063 |
|
| 1064 |
+
const customNameData = getComponentData(slot, "custom_name");
|
| 1065 |
+
if (customNameData !== undefined) {
|
| 1066 |
+
const nameTxt = flattenTextComponent(customNameData);
|
| 1067 |
+
if (nameTxt) texts.push(nameTxt);
|
| 1068 |
+
}
|
| 1069 |
+
const loreData = getComponentData(slot, "lore");
|
| 1070 |
+
if (Array.isArray(loreData)) {
|
| 1071 |
+
for (const line of loreData) {
|
| 1072 |
+
const { text } = parseComponentLoreLine(line);
|
| 1073 |
+
if (text) texts.push(text);
|
| 1074 |
+
}
|
| 1075 |
+
}
|
| 1076 |
+
if (texts.length > 0) return texts;
|
| 1077 |
+
|
| 1078 |
function extractPlain(raw) {
|
| 1079 |
if (!raw || typeof raw !== "string") return null;
|
| 1080 |
try {
|
|
|
|
| 1109 |
}
|
| 1110 |
} catch (err) {}
|
| 1111 |
return texts;
|
| 1112 |
+
};
|
| 1113 |
|
| 1114 |
function windowMatchesLoreKeyword(window, keywords) {
|
| 1115 |
try {
|
|
|
|
| 1146 |
}
|
| 1147 |
}
|
| 1148 |
|
|
|
|
| 1149 |
const MONEY_BALANCE_REGEX = /bakiyen:\s*([\d.,]+)\s*TL/i;
|
| 1150 |
const MONEY_RESPONSE_TIMEOUT_MS = 8000;
|
| 1151 |
|
| 1152 |
function parseBalanceToAdjustedAmount(rawBalanceStr) {
|
|
|
|
| 1153 |
const noCommas = rawBalanceStr.replace(/,/g, "");
|
| 1154 |
const beforeDot = noCommas.split(".")[0];
|
| 1155 |
const intValue = parseInt(beforeDot, 10);
|
|
|
|
| 1231 |
if (!bot || !botIsReady) return;
|
| 1232 |
try {
|
| 1233 |
const moves = ['forward', 'left', 'right', 'jump'];
|
| 1234 |
+
|
| 1235 |
+
const moveCount = Math.floor(Math.random() * 4) + 2;
|
| 1236 |
+
|
| 1237 |
for (let i = 0; i < moveCount; i++) {
|
| 1238 |
const move = moves[Math.floor(Math.random() * moves.length)];
|
| 1239 |
const duration = 150 + Math.floor(Math.random() * 500);
|
| 1240 |
+
|
| 1241 |
bot.setControlState(move, true);
|
| 1242 |
await new Promise(r => setTimeout(r, duration));
|
| 1243 |
bot.setControlState(move, false);
|
| 1244 |
+
|
| 1245 |
await new Promise(r => setTimeout(r, 100 + Math.random() * 300));
|
| 1246 |
+
|
| 1247 |
}
|
| 1248 |
+
|
|
|
|
| 1249 |
await bot.look(
|
| 1250 |
bot.entity.yaw + ((Math.random() - 0.5) * 1.5),
|
| 1251 |
bot.entity.pitch + ((Math.random() - 0.5) * 0.3),
|
|
|
|
| 1625 |
return;
|
| 1626 |
}
|
| 1627 |
|
| 1628 |
+
ciftciWindowPurpose = "sell";
|
| 1629 |
+
|
| 1630 |
logger.info(`[${currentBotUsername}] Çiftçi (Hepsini Sat) menüsü açılıyor (${CIFTCI_COMMAND})...`);
|
| 1631 |
|
| 1632 |
if (bot.currentWindow != null) {
|
|
|
|
| 1701 |
}
|
| 1702 |
}
|
| 1703 |
|
| 1704 |
+
function stripColorAndGetLoreLines(window) {
|
| 1705 |
+
if (!window || !Array.isArray(window.slots)) return null;
|
| 1706 |
+
for (const slot of window.slots) {
|
| 1707 |
+
if (!slot) continue;
|
| 1708 |
+
|
| 1709 |
+
let nameTxt = "";
|
| 1710 |
+
|
| 1711 |
+
const customNameData = getComponentData(slot, "custom_name");
|
| 1712 |
+
if (customNameData !== undefined) {
|
| 1713 |
+
nameTxt = flattenTextComponent(customNameData);
|
| 1714 |
+
}
|
| 1715 |
+
|
| 1716 |
+
if (!nameTxt && slot.nbt) {
|
| 1717 |
+
const nameRaw = safeGet(slot.nbt, ["value", "display", "value", "Name", "value"]);
|
| 1718 |
+
try {
|
| 1719 |
+
const maybe = JSON.parse(nameRaw);
|
| 1720 |
+
if (maybe && maybe.extra) nameTxt = maybe.extra.map(x => x.text || "").join("");
|
| 1721 |
+
else if (maybe && maybe.text) nameTxt = maybe.text;
|
| 1722 |
+
} catch (e) { nameTxt = nameRaw || ""; }
|
| 1723 |
+
}
|
| 1724 |
+
|
| 1725 |
+
if (nameTxt.includes(CIFTCI_FILTER_ITEM_NAME_KEYWORD)) {
|
| 1726 |
+
return { slot, index: window.slots.indexOf(slot) };
|
| 1727 |
+
}
|
| 1728 |
+
}
|
| 1729 |
+
return null;
|
| 1730 |
+
};
|
| 1731 |
+
|
| 1732 |
+
function getFilterItemLoreEntries(filterSlot) {
|
| 1733 |
+
const entries = [];
|
| 1734 |
+
|
| 1735 |
+
const loreData = getComponentData(filterSlot, "lore");
|
| 1736 |
+
if (Array.isArray(loreData)) {
|
| 1737 |
+
for (const line of loreData) {
|
| 1738 |
+
entries.push(parseComponentLoreLine(line));
|
| 1739 |
+
}
|
| 1740 |
+
if (entries.length > 0) return entries;
|
| 1741 |
+
}
|
| 1742 |
+
|
| 1743 |
+
try {
|
| 1744 |
+
const lore = safeGet(filterSlot.nbt, ["value", "display", "value", "Lore", "value"]);
|
| 1745 |
+
if (!Array.isArray(lore)) return entries;
|
| 1746 |
+
for (const line of lore) {
|
| 1747 |
+
const raw = line.value || line;
|
| 1748 |
+
let plain = "";
|
| 1749 |
+
let color = null;
|
| 1750 |
+
try {
|
| 1751 |
+
const maybe = JSON.parse(raw);
|
| 1752 |
+
if (maybe && Array.isArray(maybe.extra)) {
|
| 1753 |
+
for (const part of maybe.extra) {
|
| 1754 |
+
if (part.text) plain += part.text;
|
| 1755 |
+
if (part.color && !color) color = part.color;
|
| 1756 |
+
}
|
| 1757 |
+
} else if (maybe && maybe.text) {
|
| 1758 |
+
plain = maybe.text;
|
| 1759 |
+
}
|
| 1760 |
+
} catch (e) {
|
| 1761 |
+
plain = raw;
|
| 1762 |
+
}
|
| 1763 |
+
entries.push({ text: plain.trim(), color });
|
| 1764 |
+
}
|
| 1765 |
+
} catch (e) {}
|
| 1766 |
+
return entries;
|
| 1767 |
+
};
|
| 1768 |
+
|
| 1769 |
+
function findCurrentFilterIndex(loreEntries) {
|
| 1770 |
+
for (let i = 0; i < CIFTCI_FILTER_MODES.length; i++) {
|
| 1771 |
+
const modeName = CIFTCI_FILTER_MODES[i];
|
| 1772 |
+
const match = loreEntries.find(e =>
|
| 1773 |
+
e.text.includes(modeName) &&
|
| 1774 |
+
(e.text.includes("»") || e.color === CIFTCI_ACTIVE_FILTER_COLOR)
|
| 1775 |
+
);
|
| 1776 |
+
if (match) return i;
|
| 1777 |
+
}
|
| 1778 |
+
const colorMatch = loreEntries.find(e => e.color === CIFTCI_ACTIVE_FILTER_COLOR);
|
| 1779 |
+
if (colorMatch) {
|
| 1780 |
+
for (let i = 0; i < CIFTCI_FILTER_MODES.length; i++) {
|
| 1781 |
+
if (colorMatch.text.includes(CIFTCI_FILTER_MODES[i])) return i;
|
| 1782 |
+
}
|
| 1783 |
+
}
|
| 1784 |
+
return -1;
|
| 1785 |
+
}
|
| 1786 |
+
|
| 1787 |
+
async function waitForFilterItem(maxRetries) {
|
| 1788 |
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
| 1789 |
+
await new Promise(r => setTimeout(r, attempt === 0 ? CIFTCI_FILTER_STEP_WAIT_MS : CIFTCI_FILTER_RETRY_WAIT_MS));
|
| 1790 |
+
if (!bot || !bot.currentWindow) return null;
|
| 1791 |
+
const found = stripColorAndGetLoreLines(bot.currentWindow);
|
| 1792 |
+
if (found) return found;
|
| 1793 |
+
}
|
| 1794 |
+
return null;
|
| 1795 |
+
}
|
| 1796 |
+
|
| 1797 |
+
function extractStorageItemInfo(window, internalName) {
|
| 1798 |
+
if (!window || !Array.isArray(window.slots)) return null;
|
| 1799 |
+
const slot = window.slots.find(s => s && s.name === internalName);
|
| 1800 |
+
if (!slot) return null;
|
| 1801 |
+
|
| 1802 |
+
const texts = getItemDisplayTexts(slot);
|
| 1803 |
+
const joined = texts.join(" | ");
|
| 1804 |
+
|
| 1805 |
+
function grab(label) {
|
| 1806 |
+
const re = new RegExp(label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\s*:?\\s*([\\d.,%~]+)", "i");
|
| 1807 |
+
const m = joined.match(re);
|
| 1808 |
+
return m ? m[1] : null;
|
| 1809 |
+
}
|
| 1810 |
+
|
| 1811 |
+
return {
|
| 1812 |
+
depo: grab("Depo"),
|
| 1813 |
+
limit: grab("Limit"),
|
| 1814 |
+
dolulukOrani: grab("Doluluk Oranı"),
|
| 1815 |
+
birimFiyati: grab("Birim Fiyatı"),
|
| 1816 |
+
anlikNetKazanc: grab("Anlık Net Kazanç"),
|
| 1817 |
+
dakikalikUretim: grab("Dakikalık üretim"),
|
| 1818 |
+
saatlikUretim: grab("Saatlik üretim"),
|
| 1819 |
+
gunlukUretim: grab("Günlük üretim")
|
| 1820 |
+
};
|
| 1821 |
+
}
|
| 1822 |
+
|
| 1823 |
+
function findSlotByInternalName(window, internalName) {
|
| 1824 |
+
if (!window || !Array.isArray(window.slots)) return -1;
|
| 1825 |
+
for (let i = 0; i < window.slots.length; i++) {
|
| 1826 |
+
const s = window.slots[i];
|
| 1827 |
+
if (s && s.name === internalName) return i;
|
| 1828 |
+
}
|
| 1829 |
+
return -1;
|
| 1830 |
+
}
|
| 1831 |
+
|
| 1832 |
+
async function navigateCiftciFilterToGenerator() {
|
| 1833 |
+
if (!bot || !bot.currentWindow) return false;
|
| 1834 |
+
|
| 1835 |
+
let attempts = 0;
|
| 1836 |
+
while (attempts < CIFTCI_FILTER_MAX_RETRIES) {
|
| 1837 |
+
attempts++;
|
| 1838 |
+
|
| 1839 |
+
const foundItem = await waitForFilterItem(CIFTCI_FILTER_MAX_RETRIES);
|
| 1840 |
+
if (!foundItem) {
|
| 1841 |
+
logger.warn("[Çiftçi Filtre] Filtre item'ı bulunamadı, deneme durduruldu.");
|
| 1842 |
+
return false;
|
| 1843 |
+
}
|
| 1844 |
+
|
| 1845 |
+
const loreEntries = getFilterItemLoreEntries(foundItem.slot);
|
| 1846 |
+
const currentIndex = findCurrentFilterIndex(loreEntries);
|
| 1847 |
+
|
| 1848 |
+
if (currentIndex === -1) {
|
| 1849 |
+
logger.warn("[Çiftçi Filtre] Mevcut filtre modu tespit edilemedi.");
|
| 1850 |
+
return false;
|
| 1851 |
+
}
|
| 1852 |
+
|
| 1853 |
+
if (currentIndex === CIFTCI_TARGET_FILTER_INDEX) {
|
| 1854 |
+
logger.info("[Çiftçi Filtre] Jeneratör materyalleri moduna ulaşıldı.");
|
| 1855 |
+
return true;
|
| 1856 |
+
}
|
| 1857 |
+
|
| 1858 |
+
const total = CIFTCI_FILTER_MODES.length;
|
| 1859 |
+
const forwardDist = (CIFTCI_TARGET_FILTER_INDEX - currentIndex + total) % total;
|
| 1860 |
+
const backwardDist = (currentIndex - CIFTCI_TARGET_FILTER_INDEX + total) % total;
|
| 1861 |
+
|
| 1862 |
+
const useLeftClick = forwardDist <= backwardDist;
|
| 1863 |
+
const mouseButton = useLeftClick ? 0 : 1;
|
| 1864 |
+
|
| 1865 |
+
logger.info(`[Çiftçi Filtre] Mevcut: "${CIFTCI_FILTER_MODES[currentIndex]}" -> Hedef: "${CIFTCI_FILTER_MODES[CIFTCI_TARGET_FILTER_INDEX]}". ${useLeftClick ? "Sol tık (aşağı)" : "Sağ tık (yukarı)"} kullanılacak.`);
|
| 1866 |
+
|
| 1867 |
+
try {
|
| 1868 |
+
await bot.clickWindow(foundItem.index, mouseButton, 0);
|
| 1869 |
+
} catch (e) {
|
| 1870 |
+
logger.error(`[Çiftçi Filtre] Tıklama hatası: ${e && e.message ? e.message : e}`);
|
| 1871 |
+
return false;
|
| 1872 |
+
}
|
| 1873 |
+
}
|
| 1874 |
+
|
| 1875 |
+
logger.warn("[Çiftçi Filtre] Azami deneme sayısına ulaşıldı, Jeneratör materyallerine geçilemedi.");
|
| 1876 |
+
return false;
|
| 1877 |
+
}
|
| 1878 |
+
|
| 1879 |
+
async function scanStorageInfoCore() {
|
| 1880 |
+
if (!bot || !botIsReady) return;
|
| 1881 |
+
if (!guiMutex.isLocked()) {
|
| 1882 |
+
logger.error("[GÜVENLİK İHLALİ] scanStorageInfoCore kilitsiz çağrıldı! İşlem iptal ediliyor.");
|
| 1883 |
+
return;
|
| 1884 |
+
}
|
| 1885 |
+
|
| 1886 |
+
ciftciWindowPurpose = "scan";
|
| 1887 |
+
logger.info(`[${currentBotUsername}] Storage bilgisi taraması başlıyor: çiftçi menüsü (${CIFTCI_COMMAND}) açılıyor...`);
|
| 1888 |
+
|
| 1889 |
+
if (bot.currentWindow != null) {
|
| 1890 |
+
try { bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 1891 |
+
await new Promise(r => setTimeout(r, 300));
|
| 1892 |
+
}
|
| 1893 |
+
|
| 1894 |
+
let windowOpened = false;
|
| 1895 |
+
|
| 1896 |
+
await new Promise((resolve) => {
|
| 1897 |
+
let timeoutHandle = null;
|
| 1898 |
+
const cleanFinish = () => {
|
| 1899 |
+
clearTimeout(timeoutHandle);
|
| 1900 |
+
windowOpenResolvers = [];
|
| 1901 |
+
resolve();
|
| 1902 |
+
};
|
| 1903 |
+
|
| 1904 |
+
windowOpenResolvers.push(() => {
|
| 1905 |
+
windowOpened = true;
|
| 1906 |
+
cleanFinish();
|
| 1907 |
+
});
|
| 1908 |
+
|
| 1909 |
+
timeoutHandle = setTimeout(() => {
|
| 1910 |
+
logger.warn("[Storage Tarama] Menü açılamadı (zaman aşımı).");
|
| 1911 |
+
cleanFinish();
|
| 1912 |
+
}, CIFTCI_WINDOW_TIMEOUT_MS);
|
| 1913 |
+
|
| 1914 |
+
try { bot.chat(CIFTCI_COMMAND); } catch (e) {}
|
| 1915 |
+
});
|
| 1916 |
+
|
| 1917 |
+
if (!windowOpened || !bot.currentWindow) {
|
| 1918 |
+
logger.warn("[Storage Tarama] Menü açılmadığı için tarama atlandı.");
|
| 1919 |
+
ciftciWindowPurpose = "sell";
|
| 1920 |
+
return;
|
| 1921 |
+
}
|
| 1922 |
+
|
| 1923 |
+
const reached = await navigateCiftciFilterToGenerator();
|
| 1924 |
+
|
| 1925 |
+
if (reached && bot.currentWindow) {
|
| 1926 |
+
const newCache = {
|
| 1927 |
+
diamond: extractStorageItemInfo(bot.currentWindow, "diamond"),
|
| 1928 |
+
emerald: extractStorageItemInfo(bot.currentWindow, "emerald"),
|
| 1929 |
+
iron_block: extractStorageItemInfo(bot.currentWindow, "iron_block"),
|
| 1930 |
+
lastUpdated: getExtendedDateTimeString()
|
| 1931 |
+
};
|
| 1932 |
+
storageInfoCache = newCache;
|
| 1933 |
+
logger.info(`[Storage Tarama] Bilgiler güncellendi: ${JSON.stringify(newCache)}`);
|
| 1934 |
+
} else {
|
| 1935 |
+
logger.warn("[Storage Tarama] Jeneratör materyallerine ulaşılamadığı için veri güncellenmedi.");
|
| 1936 |
+
}
|
| 1937 |
+
|
| 1938 |
+
try { if (bot.currentWindow) bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 1939 |
+
ciftciWindowPurpose = "sell";
|
| 1940 |
+
}
|
| 1941 |
+
|
| 1942 |
+
async function scanStorageInfo() {
|
| 1943 |
+
if (!guiMutex.tryAcquire()) {
|
| 1944 |
+
logger.info("[Storage Tarama] Başka bir GUI işlemi sürüyor, bu tur atlanıyor.");
|
| 1945 |
+
return;
|
| 1946 |
+
}
|
| 1947 |
+
try {
|
| 1948 |
+
await scanStorageInfoCore();
|
| 1949 |
+
} catch (err) {
|
| 1950 |
+
logger.error(`[scanStorageInfo Hatası] ${err && err.stack ? err.stack : err}`);
|
| 1951 |
+
ciftciWindowPurpose = "sell";
|
| 1952 |
+
} finally {
|
| 1953 |
+
guiMutex.release();
|
| 1954 |
+
}
|
| 1955 |
+
};
|
| 1956 |
+
|
| 1957 |
+
async function scanStorageInfoManual() {
|
| 1958 |
+
logger.info("[Storage Tarama - Manuel] Panelden istek geldi, sırasını bekliyor (öncelikli)...");
|
| 1959 |
+
await guiMutex.acquire();
|
| 1960 |
+
try {
|
| 1961 |
+
logger.info("[Storage Tarama - Manuel] Kilit alındı, tarama başlıyor.");
|
| 1962 |
+
await scanStorageInfoCore();
|
| 1963 |
+
} catch (err) {
|
| 1964 |
+
logger.error(`[scanStorageInfoManual Hatası] ${err && err.stack ? err.stack : err}`);
|
| 1965 |
+
ciftciWindowPurpose = "sell";
|
| 1966 |
+
} finally {
|
| 1967 |
+
guiMutex.release();
|
| 1968 |
+
}
|
| 1969 |
+
};
|
| 1970 |
+
|
| 1971 |
+
// =====================================================================
|
| 1972 |
+
// SİPARİŞ (ORDER) SİSTEMİ
|
| 1973 |
+
// =====================================================================
|
| 1974 |
+
|
| 1975 |
+
async function waitForNextWindowOpen(timeoutMs) {
|
| 1976 |
+
return new Promise((resolve) => {
|
| 1977 |
+
let timeoutHandle = null;
|
| 1978 |
+
const cleanFinish = (opened) => {
|
| 1979 |
+
clearTimeout(timeoutHandle);
|
| 1980 |
+
windowOpenResolvers = [];
|
| 1981 |
+
resolve(opened);
|
| 1982 |
+
};
|
| 1983 |
+
|
| 1984 |
+
windowOpenResolvers.push(() => cleanFinish(true));
|
| 1985 |
+
|
| 1986 |
+
timeoutHandle = setTimeout(() => {
|
| 1987 |
+
cleanFinish(false);
|
| 1988 |
+
}, timeoutMs);
|
| 1989 |
+
});
|
| 1990 |
+
}
|
| 1991 |
+
|
| 1992 |
+
function findSlotContainingNick(window, nickNorm, itemInternalName) {
|
| 1993 |
+
if (!window || !Array.isArray(window.slots)) return -1;
|
| 1994 |
+
for (let i = 0; i < window.slots.length; i++) {
|
| 1995 |
+
const slot = window.slots[i];
|
| 1996 |
+
if (!slot) continue;
|
| 1997 |
+
|
| 1998 |
+
// ÖNEMLİ: hem item tipi hem de nick eşleşmeli.
|
| 1999 |
+
// itemInternalName verilmişse (örn. "diamond"), slotun gerçek
|
| 2000 |
+
// Minecraft item id'si ile karşılaştırıyoruz (dilden bağımsız, kesin).
|
| 2001 |
+
if (itemInternalName && slot.name !== itemInternalName) continue;
|
| 2002 |
+
|
| 2003 |
+
const texts = getItemDisplayTexts(slot);
|
| 2004 |
+
for (const t of texts) {
|
| 2005 |
+
if (matchesAnyName(t, [nickNorm])) return i;
|
| 2006 |
+
}
|
| 2007 |
+
}
|
| 2008 |
+
return -1;
|
| 2009 |
+
}
|
| 2010 |
+
|
| 2011 |
+
async function processOrderCore(itemInternalName, nick) {
|
| 2012 |
+
if (!bot || !botIsReady) return { success: false, message: "Bot hazır değil." };
|
| 2013 |
+
if (!guiMutex.isLocked()) {
|
| 2014 |
+
logger.error("[GÜVENLİK İHLALİ] processOrderCore kilitsiz çağrıldı! İşlem iptal ediliyor.");
|
| 2015 |
+
return { success: false, message: "Kilitsiz çağrı engellendi." };
|
| 2016 |
+
}
|
| 2017 |
+
if (!ORDER_ALLOWED_ITEMS.includes(itemInternalName)) {
|
| 2018 |
+
return { success: false, message: `Geçersiz item: ${itemInternalName}. İzin verilenler: ${ORDER_ALLOWED_ITEMS.join(", ")}` };
|
| 2019 |
+
}
|
| 2020 |
+
if (!nick || typeof nick !== "string" || nick.trim().length === 0) {
|
| 2021 |
+
return { success: false, message: "nick parametresi zorunlu." };
|
| 2022 |
+
}
|
| 2023 |
+
|
| 2024 |
+
// --- 1) Çiftçi menüsünü aç, jeneratör materyalleri filtresine geç ---
|
| 2025 |
+
ciftciWindowPurpose = "order";
|
| 2026 |
+
logger.info(`[Sipariş] Çiftçi menüsü açılıyor (${CIFTCI_COMMAND})...`);
|
| 2027 |
+
|
| 2028 |
+
if (bot.currentWindow != null) {
|
| 2029 |
+
try { bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 2030 |
+
await new Promise(r => setTimeout(r, 300));
|
| 2031 |
+
}
|
| 2032 |
+
|
| 2033 |
+
let windowOpened = false;
|
| 2034 |
+
await new Promise((resolve) => {
|
| 2035 |
+
let timeoutHandle = null;
|
| 2036 |
+
const cleanFinish = () => { clearTimeout(timeoutHandle); windowOpenResolvers = []; resolve(); };
|
| 2037 |
+
windowOpenResolvers.push(() => { windowOpened = true; cleanFinish(); });
|
| 2038 |
+
timeoutHandle = setTimeout(() => {
|
| 2039 |
+
logger.warn("[Sipariş] Çiftçi menüsü açılamadı (zaman aşımı).");
|
| 2040 |
+
cleanFinish();
|
| 2041 |
+
}, CIFTCI_WINDOW_TIMEOUT_MS);
|
| 2042 |
+
try { bot.chat(CIFTCI_COMMAND); } catch (e) {}
|
| 2043 |
+
});
|
| 2044 |
+
|
| 2045 |
+
if (!windowOpened || !bot.currentWindow) {
|
| 2046 |
+
ciftciWindowPurpose = "sell";
|
| 2047 |
+
return { success: false, message: "Çiftçi menüsü açılamadı." };
|
| 2048 |
+
}
|
| 2049 |
+
|
| 2050 |
+
const reached = await navigateCiftciFilterToGenerator();
|
| 2051 |
+
if (!reached || !bot.currentWindow) {
|
| 2052 |
+
try { if (bot.currentWindow) bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 2053 |
+
ciftciWindowPurpose = "sell";
|
| 2054 |
+
return { success: false, message: "Jeneratör materyalleri filtresine ulaşılamadı." };
|
| 2055 |
+
}
|
| 2056 |
+
|
| 2057 |
+
// --- 2) İstenen item'ın slotuna shift+sağ tık (envanter dolana kadar verir) ---
|
| 2058 |
+
const itemSlotIndex = findSlotByInternalName(bot.currentWindow, itemInternalName);
|
| 2059 |
+
if (itemSlotIndex === -1) {
|
| 2060 |
+
try { bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 2061 |
+
ciftciWindowPurpose = "sell";
|
| 2062 |
+
return { success: false, message: `'${itemInternalName}' slotu jeneratör materyalleri filtresinde bulunamadı.` };
|
| 2063 |
+
}
|
| 2064 |
+
|
| 2065 |
+
try {
|
| 2066 |
+
logger.info(`[Sipariş] '${itemInternalName}' slotuna (idx:${itemSlotIndex}) shift+sağ tık gönderiliyor...`);
|
| 2067 |
+
await bot.clickWindow(itemSlotIndex, 1, 1); // mouseButton=1 (sağ), mode=1 (shift)
|
| 2068 |
+
await new Promise(r => setTimeout(r, KAZICI_ACTION_SETTLE_DELAY_MS));
|
| 2069 |
+
} catch (e) {
|
| 2070 |
+
logger.error(`[Sipariş] Shift+sağ tık hatası: ${e && e.message ? e.message : e}`);
|
| 2071 |
+
}
|
| 2072 |
+
|
| 2073 |
+
// --- YENİ: Çiftçiden gerçekten item alınmış mı doğrula ---
|
| 2074 |
+
// clickWindow hata fırlatmasa bile sunucu isteği görmezden gelmiş olabilir.
|
| 2075 |
+
// Envanterde ilgili item yoksa devam etmenin anlamı yok (Teslim Etme'ye zaten
|
| 2076 |
+
// aktarılacak bir şey olmaz), bu yüzden burada erkenden kontrol edip
|
| 2077 |
+
// anlamlı bir hata dönüyoruz.
|
| 2078 |
+
const itemsAfterWithdraw = bot.inventory.items().filter(it => it && it.name === itemInternalName);
|
| 2079 |
+
const withdrawnCount = itemsAfterWithdraw.reduce((sum, it) => sum + (it.count || 0), 0);
|
| 2080 |
+
logger.info(`[Sipariş] Çiftçiden çekildikten sonra envanterde '${itemInternalName}': ${withdrawnCount} adet.`);
|
| 2081 |
+
|
| 2082 |
+
if (withdrawnCount === 0) {
|
| 2083 |
+
logger.warn(`[Sipariş] Çiftçi menüsünden '${itemInternalName}' envantere aktarılamadı (0 adet). İşlem iptal ediliyor.`);
|
| 2084 |
+
try { if (bot.currentWindow) bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 2085 |
+
ciftciWindowPurpose = "sell";
|
| 2086 |
+
return { success: false, message: `Çiftçiden '${itemInternalName}' alınamadı (envanterde 0 adet). Depoda yeterli stok olmayabilir ya da tıklama sunucu tarafından işlenmedi.` };
|
| 2087 |
+
}
|
| 2088 |
+
|
| 2089 |
+
// --- 3) Menüyü kapat ---
|
| 2090 |
+
try { if (bot.currentWindow) bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 2091 |
+
// ÖNEMLİ: purpose burada "sell"e ÇEVRİLMEZ! /order akışı (Siparişler +
|
| 2092 |
+
// Teslim Etme pencereleri) henüz açılmadı. purpose "order" kaldığı sürece
|
| 2093 |
+
// windowOpen handler bu pencereleri otomatik kapatmayacak.
|
| 2094 |
+
await new Promise(r => setTimeout(r, 300));
|
| 2095 |
+
|
| 2096 |
+
// --- 4) antiBotMove -> /is go -> 5sn -> /is go ---
|
| 2097 |
+
try { await antiBotMove(); } catch (e) {}
|
| 2098 |
+
try { bot.chat(GO_ISLAND_COMMAND); } catch (e) {}
|
| 2099 |
+
await new Promise(r => setTimeout(r, ORDER_IS_GO_SECOND_DELAY_MS));
|
| 2100 |
+
try { bot.chat(GO_ISLAND_COMMAND); } catch (e) {}
|
| 2101 |
+
await new Promise(r => setTimeout(r, HOME_ARRIVAL_DELAY_MS));
|
| 2102 |
+
|
| 2103 |
+
// --- 5) /order <nick> gönder ---
|
| 2104 |
+
logger.info(`[Sipariş] ${ORDER_COMMAND_PREFIX} ${nick} komutu gönderiliyor...`);
|
| 2105 |
+
|
| 2106 |
+
let orderWindowOpened = false;
|
| 2107 |
+
await new Promise((resolve) => {
|
| 2108 |
+
let timeoutHandle = null;
|
| 2109 |
+
const cleanFinish = () => { clearTimeout(timeoutHandle); windowOpenResolvers = []; resolve(); };
|
| 2110 |
+
windowOpenResolvers.push(() => { orderWindowOpened = true; cleanFinish(); });
|
| 2111 |
+
timeoutHandle = setTimeout(() => {
|
| 2112 |
+
logger.warn("[Sipariş] /order penceresi açılamadı (zaman aşımı).");
|
| 2113 |
+
cleanFinish();
|
| 2114 |
+
}, ORDER_WINDOW_TIMEOUT_MS);
|
| 2115 |
+
try { bot.chat(`${ORDER_COMMAND_PREFIX} ${nick}`); } catch (e) {}
|
| 2116 |
+
});
|
| 2117 |
+
|
| 2118 |
+
if (!orderWindowOpened || !bot.currentWindow) {
|
| 2119 |
+
ciftciWindowPurpose = "sell";
|
| 2120 |
+
return { success: false, message: "/order penceresi açılmadı." };
|
| 2121 |
+
}
|
| 2122 |
+
|
| 2123 |
+
// --- 6) +500ms bekle, güncel pencereyi oku (windowOpen anındaki değil) ---
|
| 2124 |
+
await new Promise(r => setTimeout(r, ORDER_WINDOW_SETTLE_DELAY_MS));
|
| 2125 |
+
if (!bot.currentWindow) {
|
| 2126 |
+
ciftciWindowPurpose = "sell";
|
| 2127 |
+
return { success: false, message: "Pencere beklenmedik şekilde kapandı." };
|
| 2128 |
+
}
|
| 2129 |
+
|
| 2130 |
+
// --- 7) Lore'da nick geçen slotu bul, sol tık ile seç ---
|
| 2131 |
+
const nickVariants = normalizeVariants(nick);
|
| 2132 |
+
let targetSlotIndex = -1;
|
| 2133 |
+
|
| 2134 |
+
// 1. ÖNCELİK: hem item tipi hem nick birlikte eşleşsin
|
| 2135 |
+
for (const nv of nickVariants) {
|
| 2136 |
+
targetSlotIndex = findSlotContainingNick(bot.currentWindow, nv, itemInternalName);
|
| 2137 |
+
if (targetSlotIndex !== -1) break;
|
| 2138 |
+
}
|
| 2139 |
+
|
| 2140 |
+
if (targetSlotIndex === -1) {
|
| 2141 |
+
logger.warn(`[Sipariş] '${nick}' + '${itemInternalName}' eşleşen item bulunamadı, pencere kapatılıyor.`);
|
| 2142 |
+
try { bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 2143 |
+
ciftciWindowPurpose = "sell";
|
| 2144 |
+
return { success: false, message: `'${nick}' kullanıcısının '${itemInternalName}' siparişi bulunamadı (belki farklı item için sipariş vermiş, ya da hiç sipariş yok).` };
|
| 2145 |
+
}
|
| 2146 |
+
|
| 2147 |
+
logger.info(`[Sipariş] '${nick}' içeren item bulundu (idx:${targetSlotIndex}), sol tık gönderiliyor...`);
|
| 2148 |
+
|
| 2149 |
+
// --- YENİ: nick'e tıkladıktan sonra sabit 500ms yerine GERÇEK yeni
|
| 2150 |
+
// pencere açılışını (Teslim Etme) bekliyoruz. Bu, mevcut buğun ana
|
| 2151 |
+
// sebebiydi: sunucu 500ms'den geç yanıt verirse eski (Siparişler)
|
| 2152 |
+
// penceresine göre hesaplanmış slotlara tıklanıyor ve hiçbir şey
|
| 2153 |
+
// taşınmıyordu (sunucu paketi reddetmediği için hata da görünmüyordu).
|
| 2154 |
+
const windowBeforeSelect = bot.currentWindow;
|
| 2155 |
+
try {
|
| 2156 |
+
await bot.clickWindow(targetSlotIndex, 0, 0);
|
| 2157 |
+
} catch (e) {
|
| 2158 |
+
logger.error(`[Sipariş] Slot seçim tıklaması hatası: ${e && e.message ? e.message : e}`);
|
| 2159 |
+
}
|
| 2160 |
+
|
| 2161 |
+
// --- 8) Teslim Etme penceresinin gerçekten açılmasını bekle ---
|
| 2162 |
+
const deliveryOpened = await waitForNextWindowOpen(ORDER_DELIVERY_WINDOW_WAIT_MS);
|
| 2163 |
+
|
| 2164 |
+
if (!deliveryOpened || !bot.currentWindow) {
|
| 2165 |
+
logger.warn("[Sipariş] Teslim Etme penceresi zaman aşımına uğradı ya da açılmadı, işlem yarım kalmış olabilir.");
|
| 2166 |
+
ciftciWindowPurpose = "sell";
|
| 2167 |
+
return { success: false, message: "Teslim Etme penceresi açılmadı (zaman aşımı)." };
|
| 2168 |
+
}
|
| 2169 |
+
|
| 2170 |
+
// Pencere objesinin gerçekten DEĞİŞTİĞİNİ doğrula (bazı sunucular aynı id'yi
|
| 2171 |
+
// update edip windowOpen yerine sadece slot update gönderebilir; bu durumda
|
| 2172 |
+
// en azından title kontrolüyle devam ediyoruz).
|
| 2173 |
+
if (bot.currentWindow === windowBeforeSelect) {
|
| 2174 |
+
logger.warn("[Sipariş] windowOpen tetiklendi ama pencere referansı değişmedi, dikkatli devam ediliyor.");
|
| 2175 |
+
}
|
| 2176 |
+
|
| 2177 |
+
const currentTitle = parseWindowTitleToString(bot.currentWindow.title);
|
| 2178 |
+
const looksLikeDelivery = matchesAnyName(currentTitle, normalizeVariants(ORDER_DELIVERY_TITLE_KEYWORD));
|
| 2179 |
+
logger.info(`[Sipariş] Yeni pencere açıldı: "${currentTitle}" (Teslim Etme eşleşmesi: ${looksLikeDelivery}). Envanterdeki '${itemInternalName}' item'ları aktarılıyor...`);
|
| 2180 |
+
|
| 2181 |
+
if (!looksLikeDelivery) {
|
| 2182 |
+
logger.warn(`[Sipariş] Açılan pencere Teslim Etme'ye benzemiyor, yine de mevcut pencereye aktarım denenecek: "${currentTitle}"`);
|
| 2183 |
+
}
|
| 2184 |
+
|
| 2185 |
+
// Ek güvenlik: envanterde gerçekten aktarılacak item var mı, tekrar kontrol et
|
| 2186 |
+
// (nick seçme / /is go arasında item'lar herhangi bir sebeple kaybolmuş olabilir).
|
| 2187 |
+
const invStartCheck = bot.currentWindow.inventoryStart;
|
| 2188 |
+
const invCheckBeforeTransfer = bot.currentWindow.slots
|
| 2189 |
+
.slice(invStartCheck)
|
| 2190 |
+
.filter(it => it && it.name === itemInternalName);
|
| 2191 |
+
if (invCheckBeforeTransfer.length === 0) {
|
| 2192 |
+
logger.warn(`[Sipariş] Aktarım öncesi envanterde '${itemInternalName}' bulunamadı, aktarım atlanıyor.`);
|
| 2193 |
+
try { if (bot.currentWindow) bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 2194 |
+
ciftciWindowPurpose = "sell";
|
| 2195 |
+
return { success: false, message: `Envanterde '${itemInternalName}' kalmamış, Teslim Etme'ye aktarılacak item yok.` };
|
| 2196 |
+
}
|
| 2197 |
+
|
| 2198 |
+
const windowAtTransferStart = bot.currentWindow;
|
| 2199 |
+
let transferredCount = 0;
|
| 2200 |
+
let keepGoing = true;
|
| 2201 |
+
let safetyCounter = 0;
|
| 2202 |
+
let stuckSlot = null;
|
| 2203 |
+
let stuckSlotRepeatCount = 0;
|
| 2204 |
+
|
| 2205 |
+
while (keepGoing && safetyCounter < 40) {
|
| 2206 |
+
safetyCounter++;
|
| 2207 |
+
|
| 2208 |
+
// Pencere döngü sırasında değişti/kapandıysa (ör. sunucu Teslim Etme'yi
|
| 2209 |
+
// kapattıysa) devam etmenin bir anlamı yok, güvenle çık.
|
| 2210 |
+
if (!bot.currentWindow || bot.currentWindow !== windowAtTransferStart) {
|
| 2211 |
+
logger.warn("[Sipariş] Aktarım sırasında pencere değişti/kapandı, döngü durduruluyor.");
|
| 2212 |
+
break;
|
| 2213 |
+
}
|
| 2214 |
+
|
| 2215 |
+
// ÖNEMLİ FIX: bot.inventory.items() custom pencere açıkken YANLIŞ slot
|
| 2216 |
+
// numarası döndürebiliyor (inventoryStart offsetini hesaba katmıyor).
|
| 2217 |
+
// Bunun yerine doğrudan currentWindow.slots üzerinden, gerçek (offsetli)
|
| 2218 |
+
// slot index'ini buluyoruz.
|
| 2219 |
+
const invStart = bot.currentWindow.inventoryStart;
|
| 2220 |
+
const winSlots = bot.currentWindow.slots;
|
| 2221 |
+
let realSlotIndex = -1;
|
| 2222 |
+
|
| 2223 |
+
for (let i = invStart; i < winSlots.length; i++) {
|
| 2224 |
+
if (winSlots[i] && winSlots[i].name === itemInternalName) {
|
| 2225 |
+
realSlotIndex = i;
|
| 2226 |
+
break;
|
| 2227 |
+
}
|
| 2228 |
+
}
|
| 2229 |
+
|
| 2230 |
+
if (realSlotIndex === -1) { keepGoing = false; break; }
|
| 2231 |
+
|
| 2232 |
+
if (stuckSlot === realSlotIndex) {
|
| 2233 |
+
stuckSlotRepeatCount++;
|
| 2234 |
+
if (stuckSlotRepeatCount >= 3) {
|
| 2235 |
+
logger.warn(`[Sipariş] Slot ${realSlotIndex} 3 kez üst üste taşınamadı (Teslim Etme dolu/limitli olabilir), aktarım durduruluyor.`);
|
| 2236 |
+
keepGoing = false;
|
| 2237 |
+
break;
|
| 2238 |
+
}
|
| 2239 |
+
} else {
|
| 2240 |
+
stuckSlot = realSlotIndex;
|
| 2241 |
+
stuckSlotRepeatCount = 0;
|
| 2242 |
+
}
|
| 2243 |
+
|
| 2244 |
+
try {
|
| 2245 |
+
await bot.clickWindow(realSlotIndex, 0, 1); // mouseButton=0 (sol), mode=1 (shift)
|
| 2246 |
+
await new Promise(r => setTimeout(r, 1000 + Math.floor(Math.random() * 200)));
|
| 2247 |
+
|
| 2248 |
+
const stillThere = bot.currentWindow.slots[realSlotIndex];
|
| 2249 |
+
if (!stillThere || stillThere.name !== itemInternalName) {
|
| 2250 |
+
transferredCount++;
|
| 2251 |
+
} else {
|
| 2252 |
+
logger.warn(`[Sipariş] Slot ${realSlotIndex} tıklandı ama item hâlâ envanterde, taşınmamış olabilir.`);
|
| 2253 |
+
}
|
| 2254 |
+
} catch (e) {
|
| 2255 |
+
logger.error(`[Sipariş] Envanterden aktarım tıklaması hatası: ${e && e.message ? e.message : e}`);
|
| 2256 |
+
keepGoing = false;
|
| 2257 |
+
}
|
| 2258 |
+
}
|
| 2259 |
+
|
| 2260 |
+
if (safetyCounter >= 40) {
|
| 2261 |
+
logger.warn(`[Sipariş] Güvenlik limitine (40 deneme) ulaşıldı. Teslim Etme kutusu dolu/limitli olabilir, transfer yarım kalmış olabilir.`);
|
| 2262 |
+
}
|
| 2263 |
+
|
| 2264 |
+
// --- 9) Pencereyi önce kapat, sonra sayım yap (pencere açıkken bot.inventory.items()
|
| 2265 |
+
// yanlış slot offseti hesaplayabildiği için, güvenilir sayım için kapanmasını bekliyoruz) ---
|
| 2266 |
+
try { if (bot.currentWindow) bot.closeWindow(bot.currentWindow); } catch (e) {}
|
| 2267 |
+
ciftciWindowPurpose = "sell"; // akış tamamen bitti, artık normal davranışa dön
|
| 2268 |
+
|
| 2269 |
+
await new Promise(r => setTimeout(r, 300)); // pencere kapanışının client tarafında senkronize olmasını bekle
|
| 2270 |
+
|
| 2271 |
+
const remainingAfterTransfer = bot.inventory.items()
|
| 2272 |
+
.filter(it => it && it.name === itemInternalName)
|
| 2273 |
+
.reduce((sum, it) => sum + (it.count || 0), 0);
|
| 2274 |
+
|
| 2275 |
+
const stoppedReason = safetyCounter >= 40
|
| 2276 |
+
? "güvenlik limiti (40 deneme)"
|
| 2277 |
+
: (remainingAfterTransfer > 0 ? "Teslim Etme dolu/limitli olabilir" : "envanter boşaldı");
|
| 2278 |
+
|
| 2279 |
+
logger.info(
|
| 2280 |
+
`[Sipariş] Envanterden Teslim Etme'ye aktarım tamamlandı: ` +
|
| 2281 |
+
`${transferredCount} yığın (stack) gönderildi, ` +
|
| 2282 |
+
`envanterde '${itemInternalName}' kaldı: ${remainingAfterTransfer} adet ` +
|
| 2283 |
+
`(durma sebebi: ${stoppedReason}).`
|
| 2284 |
+
);
|
| 2285 |
+
|
| 2286 |
+
|
| 2287 |
+
return {
|
| 2288 |
+
success: transferredCount > 0,
|
| 2289 |
+
message: transferredCount > 0 ? "Sipariş işlemi tamamlandı." : "Hiçbir yığın Teslim Etme'ye aktarılamadı.",
|
| 2290 |
+
item: itemInternalName,
|
| 2291 |
+
nick,
|
| 2292 |
+
withdrawn_from_ciftci: withdrawnCount,
|
| 2293 |
+
inventory_transferred_batches: transferredCount,
|
| 2294 |
+
remaining_in_inventory: remainingAfterTransfer
|
| 2295 |
+
};
|
| 2296 |
+
}
|
| 2297 |
+
|
| 2298 |
+
async function processOrderManual(itemInternalName, nick) {
|
| 2299 |
+
logger.info(`[Sipariş - Manuel] Panelden istek geldi (item:${itemInternalName}, nick:${nick}), sırasını bekliyor (öncelikli)...`);
|
| 2300 |
+
await guiMutex.acquire();
|
| 2301 |
+
try {
|
| 2302 |
+
logger.info("[Sipariş - Manuel] Kilit alındı, işlem başlıyor.");
|
| 2303 |
+
const result = await processOrderCore(itemInternalName, nick);
|
| 2304 |
+
lastOrderTimeStr = `${getExtendedDateTimeString()} (item:${itemInternalName}, nick:${nick}, sonuç:${result.success ? "başarılı" : "başarısız"})`;
|
| 2305 |
+
return result;
|
| 2306 |
+
} catch (err) {
|
| 2307 |
+
logger.error(`[processOrderManual Hatası] ${err && err.stack ? err.stack : err}`);
|
| 2308 |
+
return { success: false, message: "Beklenmeyen bir hata oluştu." };
|
| 2309 |
+
} finally {
|
| 2310 |
+
guiMutex.release();
|
| 2311 |
+
}
|
| 2312 |
+
}
|
| 2313 |
+
|
| 2314 |
+
function startStorageScanPeriodic() {
|
| 2315 |
+
if (storageScanIntervalHandle) return;
|
| 2316 |
+
storageScanIntervalHandle = setInterval(() => {
|
| 2317 |
+
if (!bot || !botIsReady) return;
|
| 2318 |
+
if (manualStopRequested || isDestroying) return;
|
| 2319 |
+
scanStorageInfo();
|
| 2320 |
+
}, STORAGE_SCAN_INTERVAL_MS);
|
| 2321 |
+
logger.info(`[Storage Tarama] Bağımsız döngü başlatıldı (her ${formatDurationMs(STORAGE_SCAN_INTERVAL_MS)}).`);
|
| 2322 |
+
setSafeTimeout(() => { scanStorageInfo(); }, 30 * 1000);
|
| 2323 |
+
}
|
| 2324 |
+
|
| 2325 |
function startKaziciPeriodic() {
|
| 2326 |
if (kaziciIntervalHandle) return;
|
| 2327 |
|
|
|
|
| 2402 |
botActions.sendSkyblockManual = sendSkyblockCommand;
|
| 2403 |
botActions.antiBotMove = antiBotMove;
|
| 2404 |
botActions.sendMoneyToNick = sendMoneyToNick;
|
| 2405 |
+
botActions.scanStorageInfoManual = scanStorageInfoManual;
|
| 2406 |
+
botActions.processOrderManual = processOrderManual;
|
| 2407 |
|
| 2408 |
startKaziciPeriodic();
|
| 2409 |
startCiftciPeriodic();
|
| 2410 |
+
startStorageScanPeriodic();
|
| 2411 |
startStallWatcher();
|
| 2412 |
|
| 2413 |
if (config.utils && config.utils["auto-auth"] && config.utils["auto-auth"].enabled) {
|
|
|
|
| 2474 |
(matchesAnyName(titleRaw, TARGET_CIFTCI_NORMS) || windowMatchesLoreKeyword(window, CIFTCI_LORE_FALLBACK_KEYWORDS));
|
| 2475 |
|
| 2476 |
if (!isBesleyiciWindow && !isKaziciWindow && !isCiftciWindow) {
|
| 2477 |
+
if (ciftciWindowPurpose === "order") {
|
| 2478 |
+
logger.info(`[${currentBotUsername}] Sipariş (/order) penceresi açıldı: ${titleRaw}`);
|
| 2479 |
+
} else {
|
| 2480 |
+
logger.info(`[${currentBotUsername}] Bi chest açıldı ama window title ı uyuşmadığı için kapatıldı. ${titleRaw}`);
|
| 2481 |
+
try { bot.closeWindow(window); } catch(e){}
|
| 2482 |
+
return;
|
| 2483 |
+
}
|
| 2484 |
+
} else if (isKaziciWindow) {
|
| 2485 |
try {
|
| 2486 |
logger.info(`[${currentBotUsername}] Kazıcı minyon paneli açıldı. Depo aktarım slotuna (oyun içi 18. slot / mineflayer idx ${KAZICI_STORAGE_TRANSFER_SLOT}) tıklanıyor...`);
|
| 2487 |
await bot.clickWindow(KAZICI_STORAGE_TRANSFER_SLOT, 0, 0);
|
|
|
|
| 2494 |
try { bot.closeWindow(window); } catch(e){}
|
| 2495 |
|
| 2496 |
} else if (isCiftciWindow) {
|
| 2497 |
+
if (ciftciWindowPurpose === "scan" || ciftciWindowPurpose === "order") {
|
| 2498 |
+
// Storage tarama / sipariş modu: burada otomatik tıklama/kapatma yapma,
|
| 2499 |
+
// ilgili core fonksiyon kendi akışını yönetiyor. Sadece resolver'ı tetikle.
|
| 2500 |
+
} else {
|
| 2501 |
+
try {
|
| 2502 |
+
logger.info(`[${currentBotUsername}] Çiftçi (Hepsini Sat) menüsü açıldı. ${formatDurationMs(CIFTCI_CLICK_DELAY_AFTER_OPEN_MS)} bekleniyor, sonra slot ${CIFTCI_SELL_ALL_SLOT}'e ${CIFTCI_CLICK_REPEAT_COUNT} kez tıklanacak...`);
|
| 2503 |
+
await new Promise(r => setTimeout(r, CIFTCI_CLICK_DELAY_AFTER_OPEN_MS));
|
| 2504 |
|
| 2505 |
+
for (let i = 0; i < CIFTCI_CLICK_REPEAT_COUNT; i++) {
|
| 2506 |
+
if (!bot || !botIsReady) break;
|
| 2507 |
+
try {
|
| 2508 |
+
await bot.clickWindow(CIFTCI_SELL_ALL_SLOT, 0, 0);
|
| 2509 |
+
logger.info(`[${currentBotUsername}] Çiftçi hepsini-sat tıklaması gönderildi (${i + 1}/${CIFTCI_CLICK_REPEAT_COUNT}).`);
|
| 2510 |
+
} catch (clickErr) {
|
| 2511 |
+
logger.error(`[Çiftçi Arayüz Hatası] Tıklama #${i + 1} sunucu tarafından onaylanmadı: ${clickErr && clickErr.message ? clickErr.message : clickErr}`);
|
| 2512 |
+
}
|
| 2513 |
+
if (i < CIFTCI_CLICK_REPEAT_COUNT - 1) {
|
| 2514 |
+
await new Promise(r => setTimeout(r, CIFTCI_CLICK_REPEAT_GAP_MS));
|
| 2515 |
+
}
|
| 2516 |
}
|
| 2517 |
+
|
| 2518 |
+
await new Promise(r => setTimeout(r, KAZICI_ACTION_SETTLE_DELAY_MS));
|
| 2519 |
+
} catch (e) {
|
| 2520 |
+
logger.error(`[Çiftçi Arayüz Hatası] Hepsini-sat tıklama turu sırasında beklenmeyen hata: ${e && e.message ? e.message : e}`);
|
| 2521 |
}
|
| 2522 |
|
| 2523 |
+
try { bot.closeWindow(window); } catch(e){}
|
|
|
|
|
|
|
| 2524 |
}
|
| 2525 |
|
|
|
|
|
|
|
| 2526 |
} else {
|
| 2527 |
const beefSlot = window.slots.find(s => s?.name === "cooked_beef");
|
| 2528 |
const can = extractMinyonCanFromSlot(beefSlot);
|
|
|
|
| 2579 |
}
|
| 2580 |
});
|
| 2581 |
|
| 2582 |
+
|
| 2583 |
bot.on("end", () => {
|
| 2584 |
try {
|
| 2585 |
logger.warn(manualStopRequested ? "Bağlantı koptu. Manuel durdurma istendiği için yeniden bağlanılmayacak." : "Bağlantı koptu. Tüm zamanlayıcılar sıfırlanıyor ve YENİDEN BAĞLANMA SÜRECİ BAŞLIYOR...");
|
|
|
|
| 2603 |
botActions.sendSkyblockManual = null;
|
| 2604 |
botActions.antiBotMove = null;
|
| 2605 |
botActions.sendMoneyToNick = null;
|
| 2606 |
+
botActions.scanStorageInfoManual = null;
|
| 2607 |
+
botActions.processOrderManual = null;
|
| 2608 |
|
| 2609 |
safeDestroyAllConnections();
|
| 2610 |
|
|
|
|
| 2686 |
}, delay);
|
| 2687 |
}
|
| 2688 |
|
|
|
|
| 2689 |
let pendingHardRestartTimeout = null;
|
| 2690 |
|
| 2691 |
function stopBotHard(reason) {
|
|
|
|
| 2872 |
next_kazici_check: nextKaziciTimeStr,
|
| 2873 |
last_ciftci_sell: lastCiftciSellTimeStr,
|
| 2874 |
next_ciftci_sell: nextCiftciTimeStr,
|
| 2875 |
+
last_order: lastOrderTimeStr,
|
| 2876 |
gui_lock_busy: guiMutex.isLocked(),
|
| 2877 |
manually_stopped: manualStopRequested,
|
| 2878 |
is_connecting: isConnecting,
|
|
|
|
| 2880 |
});
|
| 2881 |
});
|
| 2882 |
|
| 2883 |
+
app.get("/storageInfo", (req, res) => {
|
| 2884 |
+
res.send({
|
| 2885 |
+
diamond: storageInfoCache.diamond,
|
| 2886 |
+
emerald: storageInfoCache.emerald,
|
| 2887 |
+
iron_block: storageInfoCache.iron_block,
|
| 2888 |
+
lastUpdated: storageInfoCache.lastUpdated
|
| 2889 |
+
});
|
| 2890 |
+
});
|
| 2891 |
+
|
| 2892 |
app.get("/bot/stop", (req, res) => {
|
| 2893 |
stopBotHard("Web paneli üzerinden /bot/stop isteği");
|
| 2894 |
res.send({ success: true, message: "Bot durduruldu. Tekrar başlatmak için /bot/start kullan." });
|
|
|
|
| 2923 |
botActions.openCiftciAndSellAllManual().catch(e => logger.error(`[/bot/ciftci-satis Hatası] ${e && e.stack ? e.stack : e}`));
|
| 2924 |
});
|
| 2925 |
|
| 2926 |
+
app.get("/bot/checkFarmer", (req, res) => {
|
| 2927 |
+
if (!bot || !botIsReady || !botActions.scanStorageInfoManual) {
|
| 2928 |
+
return res.status(503).send({ success: false, message: "Bot hazır değil." });
|
| 2929 |
+
}
|
| 2930 |
+
res.send({ success: true, message: "Çiftçi depo/storage kontrolü öncelikli olarak kuyruğa alındı, işleniyor." });
|
| 2931 |
+
botActions.scanStorageInfoManual().catch(e => logger.error(`[/bot/checkFarmer Hatası] ${e && e.stack ? e.stack : e}`));
|
| 2932 |
+
});
|
| 2933 |
+
|
| 2934 |
app.get("/bot/besleyici-kontrol", (req, res) => {
|
| 2935 |
if (!bot || !botIsReady || !botActions.scanAndFeedManual) {
|
| 2936 |
return res.status(503).send({ success: false, message: "Bot hazır değil." });
|
|
|
|
| 3013 |
});
|
| 3014 |
});
|
| 3015 |
|
| 3016 |
+
app.get("/bot/order", (req, res) => {
|
| 3017 |
+
if (!bot || !botIsReady || !botActions.processOrderManual) {
|
| 3018 |
+
return res.status(503).send({ success: false, message: "Bot hazır değil." });
|
| 3019 |
+
}
|
| 3020 |
+
|
| 3021 |
+
const item = req.query.item;
|
| 3022 |
+
const nick = req.query.nick;
|
| 3023 |
+
|
| 3024 |
+
if (!item || typeof item !== "string" || !ORDER_ALLOWED_ITEMS.includes(item)) {
|
| 3025 |
+
return res.status(400).send({ success: false, message: `item query parametresi zorunlu ve şunlardan biri olmalı: ${ORDER_ALLOWED_ITEMS.join(", ")}` });
|
| 3026 |
+
}
|
| 3027 |
+
if (!nick || typeof nick !== "string" || nick.trim().length === 0) {
|
| 3028 |
+
return res.status(400).send({ success: false, message: "nick query parametresi zorunlu." });
|
| 3029 |
+
}
|
| 3030 |
+
|
| 3031 |
+
res.send({ success: true, message: "Sipariş işlemi öncelikli olarak kuyruğa alındı, işleniyor." });
|
| 3032 |
+
botActions.processOrderManual(item, nick)
|
| 3033 |
+
.catch(e => logger.error(`[/bot/order Hatası] ${e && e.stack ? e.stack : e}`));
|
| 3034 |
+
});
|
| 3035 |
+
|
| 3036 |
app.get("/", (req, res) => res.send("Bot Aktif"));
|
| 3037 |
|
| 3038 |
app.get("/messages", (req, res) => {
|