Spaces:
Paused
Paused
Update bot.js
Browse files
bot.js
CHANGED
|
@@ -69,57 +69,80 @@ async function createBot() {
|
|
| 69 |
version: config.server.version,
|
| 70 |
|
| 71 |
connect: (client) => {
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
|
| 84 |
|
| 85 |
-
|
| 86 |
-
client.emit('connect');
|
| 87 |
-
};
|
| 88 |
-
|
| 89 |
-
sshClient.on('ready', () => {
|
| 90 |
-
logger.info('[SSH Tünel] SSH bağlantısı başarılı. Minecraft sunucusuna tünel açılıyor...');
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
config.server.ip,
|
| 96 |
-
parseInt(config.server.port) || 25565,
|
| 97 |
-
(err, stream) => {
|
| 98 |
-
if (err) {
|
| 99 |
-
connectDirectly(`Tünel yönlendirme hatası: ${err.message}`);
|
| 100 |
-
return;
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
logger.info("[SSH Tünel] Tünel başarıyla kuruldu! Mineflayer sokete bağlanıyor.");
|
| 104 |
-
|
| 105 |
-
baglantiTuru = "SSH"; // Tünel başarıyla kuruldu, durum artık SSH!
|
| 106 |
-
|
| 107 |
-
client.setSocket(stream);
|
| 108 |
-
client.emit('connect');
|
| 109 |
-
}
|
| 110 |
-
);
|
| 111 |
-
});
|
| 112 |
-
|
| 113 |
-
sshClient.on('error', (err) => {
|
| 114 |
-
connectDirectly(`SSH Sunucu Hatası: ${err.message}`);
|
| 115 |
-
});
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
} catch (err) {
|
| 120 |
-
connectDirectly(`Sistem Hatası: ${err.message}`);
|
| 121 |
}
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
});
|
| 124 |
|
| 125 |
|
|
|
|
| 69 |
version: config.server.version,
|
| 70 |
|
| 71 |
connect: (client) => {
|
| 72 |
+
logger.info(`[SSH Tünel] ${sshConfig.host} sunucusuna bağlanılıyor...`);
|
| 73 |
+
|
| 74 |
+
let isFinished = false;
|
| 75 |
|
| 76 |
+
// SSH veya Tünel başarısız olduğunda botu temiz bir şekilde bitiren fonksiyon
|
| 77 |
+
const handleTunnelFailure = (reason) => {
|
| 78 |
+
if (isFinished) return;
|
| 79 |
+
isFinished = true;
|
| 80 |
+
|
| 81 |
+
logger.error(`[SSH Tünel Hatası] Tünel kurulamadı veya koptu (${reason}). Kökten yeniden başlatılıyor...`);
|
| 82 |
+
|
| 83 |
+
baglantiTuru = "Yok";
|
| 84 |
+
botIsReady = false;
|
| 85 |
+
|
| 86 |
+
try { sshClient.end(); } catch(e) {}
|
| 87 |
+
|
| 88 |
+
// Bota bağlantının bittiğini haber veriyoruz.
|
| 89 |
+
// Bu sayede aşağıdaki bot.on('end') tetiklenecek ve auto-reconnect delay süresi sonra temizce createBot() çağrılacak.
|
| 90 |
+
if (bot) {
|
| 91 |
+
bot.end();
|
| 92 |
+
}
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
// SSH sunucusunun askıda kalmasını önlemek için 15 saniyelik bir bağlantı zaman aşımı
|
| 96 |
+
const connectionTimeout = setTimeout(() => {
|
| 97 |
+
handleTunnelFailure("SSH Bağlantı Zaman Aşımı (15 saniye yanıt alınamadı)");
|
| 98 |
+
}, 15000);
|
| 99 |
+
|
| 100 |
+
sshClient.on('ready', () => {
|
| 101 |
+
clearTimeout(connectionTimeout); // SSH bağlandı, zaman aşımını iptal et
|
| 102 |
+
logger.info('[SSH Tünel] SSH bağlantısı başarılı. Minecraft sunucusuna tünel açılıyor...');
|
| 103 |
+
|
| 104 |
+
sshClient.forwardOut(
|
| 105 |
+
'127.0.0.1',
|
| 106 |
+
12345,
|
| 107 |
+
config.server.ip,
|
| 108 |
+
parseInt(config.server.port) || 25565,
|
| 109 |
+
(err, stream) => {
|
| 110 |
+
if (err) {
|
| 111 |
+
handleTunnelFailure(`Tünel yönlendirme hatası: ${err.message}`);
|
| 112 |
+
return;
|
| 113 |
+
}
|
| 114 |
|
| 115 |
+
logger.info("[SSH Tünel] Tünel başarıyla kuruldu! Mineflayer sokete bağlanıyor.");
|
| 116 |
|
| 117 |
+
baglantiTuru = "SSH";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
// Soket koptuğunda da doğrudan hataya düşür
|
| 120 |
+
stream.on('close', () => handleTunnelFailure("Tünel stream kapandı"));
|
| 121 |
+
stream.on('error', (e) => handleTunnelFailure(`Tünel stream hatası: ${e.message}`));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
+
client.setSocket(stream);
|
| 124 |
+
client.emit('connect');
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
+
);
|
| 127 |
+
});
|
| 128 |
+
|
| 129 |
+
sshClient.on('error', (err) => {
|
| 130 |
+
clearTimeout(connectionTimeout);
|
| 131 |
+
handleTunnelFailure(`SSH Sunucu Hatası: ${err.message}`);
|
| 132 |
+
});
|
| 133 |
+
|
| 134 |
+
sshClient.on('close', () => {
|
| 135 |
+
clearTimeout(connectionTimeout);
|
| 136 |
+
handleTunnelFailure("SSH Bağlantısı kapandı");
|
| 137 |
+
});
|
| 138 |
+
|
| 139 |
+
try {
|
| 140 |
+
sshClient.connect(sshConfig);
|
| 141 |
+
} catch (err) {
|
| 142 |
+
clearTimeout(connectionTimeout);
|
| 143 |
+
handleTunnelFailure(`Sistem Hatası: ${err.message}`);
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
});
|
| 147 |
|
| 148 |
|