Spaces:
Paused
Paused
Update bot.js
Browse files
bot.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
| 1 |
-
//npm install prismarine-viewer http-proxy-middleware yapılacak
|
| 2 |
const mineflayer = require("mineflayer");
|
| 3 |
const mineflayerViewer = require('prismarine-viewer').mineflayer;
|
| 4 |
-
const { createProxyMiddleware } = require('http-proxy-middleware');
|
| 5 |
const Movements = require("mineflayer-pathfinder").Movements;
|
| 6 |
const pathfinder = require("mineflayer-pathfinder").pathfinder;
|
| 7 |
const { GoalBlock, GoalXZ } = require("mineflayer-pathfinder").goals;
|
| 8 |
const util = require("util");
|
| 9 |
-
const { SocksProxyAgent } = require("socks-proxy-agent");
|
| 10 |
-
const proxyChain = require("proxy-chain");
|
| 11 |
const { SocksClient } = require('socks');
|
| 12 |
const { Client } = require('ssh2');
|
| 13 |
|
|
@@ -50,16 +46,16 @@ let viewerInstance = null;
|
|
| 50 |
let viewerTimeout = null;
|
| 51 |
let bot = null;
|
| 52 |
let botIsReady = false;
|
|
|
|
| 53 |
|
| 54 |
async function createBot() {
|
| 55 |
const sshClient = new Client();
|
| 56 |
|
| 57 |
const sshConfig = {
|
| 58 |
host: 'tr1.vpnjantit.com',
|
| 59 |
-
port: 22,
|
| 60 |
username: 'suvaa-vpnjantit.com',
|
| 61 |
password: 'suvaa'
|
| 62 |
-
// Eğer key kullanıyorsan: privateKey: require('fs').readFileSync('key.pem')
|
| 63 |
};
|
| 64 |
|
| 65 |
bot = await mineflayer.createBot({
|
|
@@ -72,34 +68,54 @@ async function createBot() {
|
|
| 72 |
connect: (client) => {
|
| 73 |
logger.info(`[SSH Tünel] ${sshConfig.host} sunucusuna bağlanılıyor...`);
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
sshClient.on('ready', () => {
|
| 76 |
logger.info('[SSH Tünel] SSH bağlantısı başarılı. Minecraft sunucusuna tünel açılıyor...');
|
| 77 |
|
| 78 |
-
// SSH üzerinden hedef Minecraft sunucusuna bir TCP soketi açmasını istiyoruz
|
| 79 |
sshClient.forwardOut(
|
| 80 |
-
'127.0.0.1',
|
| 81 |
-
12345,
|
| 82 |
-
config.server.ip,
|
| 83 |
-
parseInt(config.server.port) || 25565,
|
| 84 |
(err, stream) => {
|
| 85 |
if (err) {
|
| 86 |
-
|
| 87 |
-
sshClient.end();
|
| 88 |
-
if (bot) bot.emit('end');
|
| 89 |
return;
|
| 90 |
}
|
| 91 |
|
| 92 |
logger.info("[SSH Tünel] Tünel başarıyla kuruldu! Mineflayer sokete bağlanıyor.");
|
| 93 |
|
| 94 |
-
|
|
|
|
| 95 |
client.setSocket(stream);
|
| 96 |
client.emit('connect');
|
| 97 |
}
|
| 98 |
);
|
| 99 |
-
})
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
}
|
| 104 |
});
|
| 105 |
|
|
@@ -372,6 +388,7 @@ connect: (client) => {
|
|
| 372 |
logger.warn("Bağlantı koptu. Tüm zamanlayıcılar sıfırlanıyor...");
|
| 373 |
stopPeriodicHomeChecks();
|
| 374 |
botIsReady = false;
|
|
|
|
| 375 |
bot = null;
|
| 376 |
if (config.utils && config.utils["auto-reconnect"]) {
|
| 377 |
setTimeout(() => createBot(), config.utils["auto-reconnect-delay"]);
|
|
@@ -388,7 +405,11 @@ const express = require("express");
|
|
| 388 |
const app = express();
|
| 389 |
const http = require('http');
|
| 390 |
app.get("/status", (req, res) => {
|
| 391 |
-
res.send({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
});
|
| 393 |
|
| 394 |
app.get("/", (req, res) => res.send("Bot Aktif"));
|
|
|
|
|
|
|
| 1 |
const mineflayer = require("mineflayer");
|
| 2 |
const mineflayerViewer = require('prismarine-viewer').mineflayer;
|
|
|
|
| 3 |
const Movements = require("mineflayer-pathfinder").Movements;
|
| 4 |
const pathfinder = require("mineflayer-pathfinder").pathfinder;
|
| 5 |
const { GoalBlock, GoalXZ } = require("mineflayer-pathfinder").goals;
|
| 6 |
const util = require("util");
|
|
|
|
|
|
|
| 7 |
const { SocksClient } = require('socks');
|
| 8 |
const { Client } = require('ssh2');
|
| 9 |
|
|
|
|
| 46 |
let viewerTimeout = null;
|
| 47 |
let bot = null;
|
| 48 |
let botIsReady = false;
|
| 49 |
+
let baglantiTuru = "Yok";
|
| 50 |
|
| 51 |
async function createBot() {
|
| 52 |
const sshClient = new Client();
|
| 53 |
|
| 54 |
const sshConfig = {
|
| 55 |
host: 'tr1.vpnjantit.com',
|
| 56 |
+
port: 22,
|
| 57 |
username: 'suvaa-vpnjantit.com',
|
| 58 |
password: 'suvaa'
|
|
|
|
| 59 |
};
|
| 60 |
|
| 61 |
bot = await mineflayer.createBot({
|
|
|
|
| 68 |
connect: (client) => {
|
| 69 |
logger.info(`[SSH Tünel] ${sshConfig.host} sunucusuna bağlanılıyor...`);
|
| 70 |
|
| 71 |
+
let fallbackTriggered = false;
|
| 72 |
+
|
| 73 |
+
// Doğrudan (Normal IP ile) bağlantı kuran yardımcı fonksiyon
|
| 74 |
+
const connectDirectly = (reason) => {
|
| 75 |
+
if (fallbackTriggered) return;
|
| 76 |
+
fallbackTriggered = true;
|
| 77 |
+
|
| 78 |
+
logger.warn(`[Bağlantı Yedekleme] SSH Tüneli başarısız oldu (${reason}). Normal IP üzerinden doğrudan bağlantı deneniyor...`);
|
| 79 |
+
|
| 80 |
+
baglantiTuru = "Normal"; // SSH patladı, normal bağlantıya geçtik!
|
| 81 |
+
|
| 82 |
+
try { sshClient.end(); } catch(e) {}
|
| 83 |
+
client.emit('connect');
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
sshClient.on('ready', () => {
|
| 87 |
logger.info('[SSH Tünel] SSH bağlantısı başarılı. Minecraft sunucusuna tünel açılıyor...');
|
| 88 |
|
|
|
|
| 89 |
sshClient.forwardOut(
|
| 90 |
+
'127.0.0.1',
|
| 91 |
+
12345,
|
| 92 |
+
config.server.ip,
|
| 93 |
+
parseInt(config.server.port) || 25565,
|
| 94 |
(err, stream) => {
|
| 95 |
if (err) {
|
| 96 |
+
connectDirectly(`Tünel yönlendirme hatası: ${err.message}`);
|
|
|
|
|
|
|
| 97 |
return;
|
| 98 |
}
|
| 99 |
|
| 100 |
logger.info("[SSH Tünel] Tünel başarıyla kuruldu! Mineflayer sokete bağlanıyor.");
|
| 101 |
|
| 102 |
+
baglantiTuru = "SSH"; // Tünel başarıyla kuruldu, durum artık SSH!
|
| 103 |
+
|
| 104 |
client.setSocket(stream);
|
| 105 |
client.emit('connect');
|
| 106 |
}
|
| 107 |
);
|
| 108 |
+
});
|
| 109 |
+
|
| 110 |
+
sshClient.on('error', (err) => {
|
| 111 |
+
connectDirectly(`SSH Sunucu Hatası: ${err.message}`);
|
| 112 |
+
});
|
| 113 |
+
|
| 114 |
+
try {
|
| 115 |
+
sshClient.connect(sshConfig);
|
| 116 |
+
} catch (err) {
|
| 117 |
+
connectDirectly(`Sistem Hatası: ${err.message}`);
|
| 118 |
+
}
|
| 119 |
}
|
| 120 |
});
|
| 121 |
|
|
|
|
| 388 |
logger.warn("Bağlantı koptu. Tüm zamanlayıcılar sıfırlanıyor...");
|
| 389 |
stopPeriodicHomeChecks();
|
| 390 |
botIsReady = false;
|
| 391 |
+
baglantiTuru = "Yok";
|
| 392 |
bot = null;
|
| 393 |
if (config.utils && config.utils["auto-reconnect"]) {
|
| 394 |
setTimeout(() => createBot(), config.utils["auto-reconnect-delay"]);
|
|
|
|
| 405 |
const app = express();
|
| 406 |
const http = require('http');
|
| 407 |
app.get("/status", (req, res) => {
|
| 408 |
+
res.send({
|
| 409 |
+
ready: botIsReady,
|
| 410 |
+
username: bot ? bot.username : null,
|
| 411 |
+
connection_type: baglantiTuru // Panel artık SSH mı yoksa Normal mi görebilecek
|
| 412 |
+
});
|
| 413 |
});
|
| 414 |
|
| 415 |
app.get("/", (req, res) => res.send("Bot Aktif"));
|