Mervvebulx commited on
Commit
f0cc361
·
verified ·
1 Parent(s): a093f8f

Update bot.js

Browse files
Files changed (1) hide show
  1. bot.js +46 -30
bot.js CHANGED
@@ -4,32 +4,13 @@ const pathfinder = require("mineflayer-pathfinder").pathfinder;
4
  const { GoalBlock, GoalXZ } = require("mineflayer-pathfinder").goals;
5
  const util = require("util");
6
 
 
 
 
7
  const config = require("./settings.json");
8
  const loggers = require("./logging.js");
9
  const logger = loggers.logger;
10
 
11
- const https = require('https');
12
-
13
- https.get('https://api.ipify.org?format=json', (res) => {
14
- let data = '';
15
-
16
- res.on('data', chunk => {
17
- data += chunk;
18
- });
19
-
20
- res.on('end', () => {
21
- try {
22
- const ipInfo = JSON.parse(data);
23
- console.log(`Dış IP adresin: ${ipInfo.ip}`);
24
- } catch (err) {
25
- console.error('JSON parse hatası:', err);
26
- }
27
- });
28
- }).on('error', (err) => {
29
- console.error('İstek hatası:', err);
30
- });
31
-
32
-
33
  // --- AYARLAR ---
34
  const HOME_ARRIVAL_DELAY_MS = 2000;
35
  const POST_ACTION_DELAY_MS = 4000;
@@ -40,14 +21,49 @@ const GO_HOME_COMMAND = "/home";
40
  const RETURN_ISLAND_COMMAND = "/is home";
41
  const BESLEYICI_NAMES = (config.utils && config.utils["besleyici-names"]) || ["Besleyici", "ʙᴇsʟᴇʏiᴄi"];
42
 
43
- function createBot() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  const bot = mineflayer.createBot({
45
  username: config["bot-account"]["username"],
46
  auth: config["bot-account"]["type"],
47
  host: config.server.ip,
48
  port: config.server.port,
49
  version: config.server.version,
50
- brand: 'vanilla',
 
51
  });
52
 
53
  bot.loadPlugin(pathfinder);
@@ -191,7 +207,7 @@ function createBot() {
191
  } catch (err) { return null; }
192
  }
193
 
194
- async function goHome() {
195
  logger.info(`[${config["bot-account"]["username"]}] ${GO_HOME_COMMAND} komutu gönderiliyor.`);
196
  bot.chat(GO_HOME_COMMAND);
197
  }
@@ -228,7 +244,6 @@ function createBot() {
228
  }
229
 
230
  const dist = bot.entity.position.distanceTo(best.entity.position);
231
- // SENİN LOGUN: 'Armor Stand' bulundu id:...
232
  logger.info(`[${config["bot-account"]["username"]}] '${best.entity.name || 'Armor Stand'}' bulundu id:${best.entity.id} path:${best.path} dist:${dist.toFixed(2)} — aktive ediliyor.`);
233
 
234
  if (dist > 7) {
@@ -316,16 +331,17 @@ function createBot() {
316
  bot.on("end", () => {
317
  logger.warn("Bağlantı koptu. Tüm zamanlayıcılar sıfırlanıyor...");
318
  stopPeriodicHomeChecks();
319
- if (config.utils && config.utils["auto-reconnect"]) {
320
- setTimeout(() => createBot(), config.utils["auto-reconnect-delay"]);
321
  }
 
322
  });
323
 
324
  bot.on("kicked", (reason) => logger.warn(`Bot sunucudan atıldı: ${util.inspect(reason)}`));
325
  bot.on("error", (err) => logger.error(`${err}`));
326
  }
327
-
328
- createBot();
329
 
330
  const express = require("express");
331
  const app = express();
 
4
  const { GoalBlock, GoalXZ } = require("mineflayer-pathfinder").goals;
5
  const util = require("util");
6
 
7
+ const { Client } = require("ssh2");
8
+ const { SocksProxyAgent } = require("socks-proxy-agent");
9
+
10
  const config = require("./settings.json");
11
  const loggers = require("./logging.js");
12
  const logger = loggers.logger;
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  // --- AYARLAR ---
15
  const HOME_ARRIVAL_DELAY_MS = 2000;
16
  const POST_ACTION_DELAY_MS = 4000;
 
21
  const RETURN_ISLAND_COMMAND = "/is home";
22
  const BESLEYICI_NAMES = (config.utils && config.utils["besleyici-names"]) || ["Besleyici", "ʙᴇsʟᴇʏiᴄi"];
23
 
24
+ // --- SSH Failover için eklenen kısım ---
25
+ const sshServers = [
26
+ { host: "tr1.vpnjantit.com", port: 22, username: "testestx-vpnjantit.com", password: "testestx" },
27
+ { host: "ssh2.example.com", port: 22, username: "user2", password: "pass2" }
28
+ ];
29
+ let currentIndex = 0;
30
+ let usingFallback = false;
31
+
32
+ function connectWithSSH() {
33
+ if (currentIndex >= sshServers.length) {
34
+ console.log("Tüm SSH bağlantıları başarısız. Normal IP ile bağlanılıyor...");
35
+ usingFallback = true;
36
+ createBot(); // fallback: normal bağlantı
37
+ return;
38
+ }
39
+
40
+ const server = sshServers[currentIndex];
41
+ const conn = new Client();
42
+
43
+ conn.on("ready", () => {
44
+ console.log(`SSH bağlantısı başarılı: ${server.host}`);
45
+ usingFallback = false;
46
+ const agent = new SocksProxyAgent("socks5://127.0.0.1:1080");
47
+ createBot(agent);
48
+ });
49
+
50
+ conn.on("error", (err) => {
51
+ console.log(`SSH bağlantısı başarısız: ${server.host} - ${err.message}`);
52
+ currentIndex++;
53
+ connectWithSSH(); // sıradaki sunucuyu dene
54
+ });
55
+
56
+ conn.connect(server);
57
+ }
58
+ function createBot(agent = null) {
59
  const bot = mineflayer.createBot({
60
  username: config["bot-account"]["username"],
61
  auth: config["bot-account"]["type"],
62
  host: config.server.ip,
63
  port: config.server.port,
64
  version: config.server.version,
65
+ brand: "vanilla",
66
+ agent: agent || undefined
67
  });
68
 
69
  bot.loadPlugin(pathfinder);
 
207
  } catch (err) { return null; }
208
  }
209
 
210
+ async function goHome() {
211
  logger.info(`[${config["bot-account"]["username"]}] ${GO_HOME_COMMAND} komutu gönderiliyor.`);
212
  bot.chat(GO_HOME_COMMAND);
213
  }
 
244
  }
245
 
246
  const dist = bot.entity.position.distanceTo(best.entity.position);
 
247
  logger.info(`[${config["bot-account"]["username"]}] '${best.entity.name || 'Armor Stand'}' bulundu id:${best.entity.id} path:${best.path} dist:${dist.toFixed(2)} — aktive ediliyor.`);
248
 
249
  if (dist > 7) {
 
331
  bot.on("end", () => {
332
  logger.warn("Bağlantı koptu. Tüm zamanlayıcılar sıfırlanıyor...");
333
  stopPeriodicHomeChecks();
334
+ if (usingFallback) {
335
+ currentIndex = 0; // normal IP’deyken koparsa index sıfırlanır
336
  }
337
+ connectWithSSH(); // tekrar SSH denemesi
338
  });
339
 
340
  bot.on("kicked", (reason) => logger.warn(`Bot sunucudan atıldı: ${util.inspect(reason)}`));
341
  bot.on("error", (err) => logger.error(`${err}`));
342
  }
343
+ // Başlatma
344
+ connectWithSSH();
345
 
346
  const express = require("express");
347
  const app = express();