Spaces:
Paused
Paused
Update bot.js
Browse files
bot.js
CHANGED
|
@@ -6,6 +6,7 @@ const { GoalBlock, GoalXZ } = require("mineflayer-pathfinder").goals;
|
|
| 6 |
const util = require("util");
|
| 7 |
const { SocksClient } = require('socks');
|
| 8 |
const { Client } = require('ssh2');
|
|
|
|
| 9 |
|
| 10 |
const config = require("./settings.json");
|
| 11 |
const loggers = require("./logging.js");
|
|
@@ -46,13 +47,41 @@ let botUptimeStart = null;
|
|
| 46 |
let lastFullFeedTimeStr = "Henüz besleme yapılmadı";
|
| 47 |
let lastCheckTimeStr = "Henüz kontrol yapılmadı";
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
https.get('https://api.ipify.org?format=json', (res) => {
|
| 50 |
let data = '';
|
| 51 |
res.on('data', chunk => { data += chunk; });
|
| 52 |
res.on('end', () => {
|
| 53 |
try {
|
| 54 |
const ipInfo = JSON.parse(data);
|
| 55 |
-
|
|
|
|
| 56 |
} catch (err) {}
|
| 57 |
});
|
| 58 |
}).on('error', () => {});
|
|
@@ -93,6 +122,8 @@ async function createBot() {
|
|
| 93 |
baglantiTuru = "Yok";
|
| 94 |
botIsReady = false;
|
| 95 |
botUptimeStart = null;
|
|
|
|
|
|
|
| 96 |
|
| 97 |
stopPeriodicHomeChecks();
|
| 98 |
safeDestroyAllConnections();
|
|
@@ -102,7 +133,7 @@ async function createBot() {
|
|
| 102 |
}
|
| 103 |
};
|
| 104 |
|
| 105 |
-
const connectDirectly = (reason) => {
|
| 106 |
if (fallbackTriggered) return;
|
| 107 |
fallbackTriggered = true;
|
| 108 |
|
|
@@ -116,6 +147,9 @@ async function createBot() {
|
|
| 116 |
} catch (e) {}
|
| 117 |
}
|
| 118 |
|
|
|
|
|
|
|
|
|
|
| 119 |
const socket = net.connect({
|
| 120 |
host: targetServerIp,
|
| 121 |
port: parseInt(targetServerPort) || 25565
|
|
@@ -222,10 +256,18 @@ async function createBot() {
|
|
| 222 |
connectDirectly("SSH Bağlantı Zaman Aşımı (10 saniye yanıt alınamadı)");
|
| 223 |
}, 10000);
|
| 224 |
|
| 225 |
-
sshClient.on('ready', () => {
|
| 226 |
clearTimeout(connectionTimeout);
|
| 227 |
logger.info('[SSH Tünel] SSH bağlantısı başarılı. Minecraft sunucusuna tünel açılıyor...');
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
sshClient.forwardOut(
|
| 230 |
'127.0.0.1',
|
| 231 |
12345,
|
|
@@ -609,6 +651,8 @@ async function createBot() {
|
|
| 609 |
baglantiTuru = "Yok";
|
| 610 |
botUptimeStart = null;
|
| 611 |
isListeningChat = false;
|
|
|
|
|
|
|
| 612 |
|
| 613 |
safeDestroyAllConnections();
|
| 614 |
|
|
@@ -721,6 +765,8 @@ app.get("/status", (req, res) => {
|
|
| 721 |
ready: botIsReady,
|
| 722 |
username: bot ? bot.username : null,
|
| 723 |
connection_type: baglantiTuru,
|
|
|
|
|
|
|
| 724 |
bot_uptime: uptimeString,
|
| 725 |
last_minyon_check: lastCheckTimeStr,
|
| 726 |
last_minyon_feed: lastFullFeedTimeStr
|
|
|
|
| 6 |
const util = require("util");
|
| 7 |
const { SocksClient } = require('socks');
|
| 8 |
const { Client } = require('ssh2');
|
| 9 |
+
const dns = require('dns').promises;
|
| 10 |
|
| 11 |
const config = require("./settings.json");
|
| 12 |
const loggers = require("./logging.js");
|
|
|
|
| 47 |
let lastFullFeedTimeStr = "Henüz besleme yapılmadı";
|
| 48 |
let lastCheckTimeStr = "Henüz kontrol yapılmadı";
|
| 49 |
|
| 50 |
+
// --- DİNAMİK IP VE KONUM BİLGİLERİ ---
|
| 51 |
+
let activeConnectionIp = "Bilinmiyor";
|
| 52 |
+
let activeConnectionLocation = "Bilinmiyor";
|
| 53 |
+
let localExternalIp = "Bilinmiyor";
|
| 54 |
+
|
| 55 |
+
function getIpLocation(ip) {
|
| 56 |
+
return new Promise((resolve) => {
|
| 57 |
+
if (!ip || ip === "Bilinmiyor" || ip.startsWith("127.")) {
|
| 58 |
+
return resolve("Bilinmiyor");
|
| 59 |
+
}
|
| 60 |
+
https.get(`https://ip-api.com/json/${ip}?fields=status,country,city`, (res) => {
|
| 61 |
+
let data = '';
|
| 62 |
+
res.on('data', chunk => data += chunk);
|
| 63 |
+
res.on('end', () => {
|
| 64 |
+
try {
|
| 65 |
+
const geo = JSON.parse(body || data);
|
| 66 |
+
if (geo && geo.status === 'success') {
|
| 67 |
+
resolve(`${geo.country} / ${geo.city}`);
|
| 68 |
+
} else {
|
| 69 |
+
resolve("Konum Alınamadı");
|
| 70 |
+
}
|
| 71 |
+
} catch (e) { resolve("Konum Ayrıştırma Hatası"); }
|
| 72 |
+
});
|
| 73 |
+
}).on('error', () => resolve("Konum Servisi Hatası"));
|
| 74 |
+
});
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
https.get('https://api.ipify.org?format=json', (res) => {
|
| 78 |
let data = '';
|
| 79 |
res.on('data', chunk => { data += chunk; });
|
| 80 |
res.on('end', () => {
|
| 81 |
try {
|
| 82 |
const ipInfo = JSON.parse(data);
|
| 83 |
+
localExternalIp = ipInfo.ip;
|
| 84 |
+
console.log(`Dış IP adresin: ${localExternalIp}`);
|
| 85 |
} catch (err) {}
|
| 86 |
});
|
| 87 |
}).on('error', () => {});
|
|
|
|
| 122 |
baglantiTuru = "Yok";
|
| 123 |
botIsReady = false;
|
| 124 |
botUptimeStart = null;
|
| 125 |
+
activeConnectionIp = "Bilinmiyor";
|
| 126 |
+
activeConnectionLocation = "Bilinmiyor";
|
| 127 |
|
| 128 |
stopPeriodicHomeChecks();
|
| 129 |
safeDestroyAllConnections();
|
|
|
|
| 133 |
}
|
| 134 |
};
|
| 135 |
|
| 136 |
+
const connectDirectly = async (reason) => {
|
| 137 |
if (fallbackTriggered) return;
|
| 138 |
fallbackTriggered = true;
|
| 139 |
|
|
|
|
| 147 |
} catch (e) {}
|
| 148 |
}
|
| 149 |
|
| 150 |
+
activeConnectionIp = localExternalIp !== "Bilinmiyor" ? localExternalIp : "Kendi Dış IP'niz";
|
| 151 |
+
activeConnectionLocation = await getIpLocation(localExternalIp);
|
| 152 |
+
|
| 153 |
const socket = net.connect({
|
| 154 |
host: targetServerIp,
|
| 155 |
port: parseInt(targetServerPort) || 25565
|
|
|
|
| 256 |
connectDirectly("SSH Bağlantı Zaman Aşımı (10 saniye yanıt alınamadı)");
|
| 257 |
}, 10000);
|
| 258 |
|
| 259 |
+
sshClient.on('ready', async () => {
|
| 260 |
clearTimeout(connectionTimeout);
|
| 261 |
logger.info('[SSH Tünel] SSH bağlantısı başarılı. Minecraft sunucusuna tünel açılıyor...');
|
| 262 |
|
| 263 |
+
try {
|
| 264 |
+
const lookup = await dns.lookup(sshConfig.host);
|
| 265 |
+
activeConnectionIp = lookup.address;
|
| 266 |
+
} catch (e) {
|
| 267 |
+
activeConnectionIp = sshConfig.host;
|
| 268 |
+
}
|
| 269 |
+
activeConnectionLocation = await getIpLocation(activeConnectionIp);
|
| 270 |
+
|
| 271 |
sshClient.forwardOut(
|
| 272 |
'127.0.0.1',
|
| 273 |
12345,
|
|
|
|
| 651 |
baglantiTuru = "Yok";
|
| 652 |
botUptimeStart = null;
|
| 653 |
isListeningChat = false;
|
| 654 |
+
activeConnectionIp = "Bilinmiyor";
|
| 655 |
+
activeConnectionLocation = "Bilinmiyor";
|
| 656 |
|
| 657 |
safeDestroyAllConnections();
|
| 658 |
|
|
|
|
| 765 |
ready: botIsReady,
|
| 766 |
username: bot ? bot.username : null,
|
| 767 |
connection_type: baglantiTuru,
|
| 768 |
+
connection_ip: activeConnectionIp,
|
| 769 |
+
connection_geo: activeConnectionLocation,
|
| 770 |
bot_uptime: uptimeString,
|
| 771 |
last_minyon_check: lastCheckTimeStr,
|
| 772 |
last_minyon_feed: lastFullFeedTimeStr
|