SlnDmry commited on
Commit
84cee1b
·
verified ·
1 Parent(s): b5a2697

Update bot.js

Browse files
Files changed (1) hide show
  1. bot.js +60 -12
bot.js CHANGED
@@ -16,7 +16,7 @@ const https = require('https');
16
  // --- AYARLAR ---
17
  const HOME_ARRIVAL_DELAY_MS = 2000;
18
  const POST_ACTION_DELAY_MS = 4000;
19
- const WINDOW_OPEN_TIMEOUT_MS = 6000; // Mutlak üst sınır (6 Saniye)
20
  const PERIODIC_CHECK_INTERVAL_MS = 10 * 60 * 1000;
21
  const FULL_FEED_COOLDOWN_MS = 50 * 60 * 1000;
22
  const GO_HOME_COMMAND = "/home";
@@ -38,14 +38,13 @@ let reconnectTimeout = null;
38
  let currentSshClient = null;
39
  let currentStream = null;
40
  let currentSocket = null;
41
- let windowOpenResolvers = []; // Havuzun global erişilebilirliği garanti altına alındı
42
 
43
  // --- PANEL METRİKLERİ ---
44
  let botUptimeStart = null;
45
  let lastFullFeedTimeStr = "Henüz besleme yapılmadı";
46
  let lastCheckTimeStr = "Henüz kontrol yapılmadı";
47
 
48
- // Dış IP tespiti
49
  https.get('https://api.ipify.org?format=json', (res) => {
50
  let data = '';
51
  res.on('data', chunk => { data += chunk; });
@@ -108,7 +107,6 @@ async function createBot() {
108
 
109
  logger.warn(`[Bağlantı Yedekleme] Doğrudan IP moduna geçiliyor (Sebep: ${reason}). Kendi (Yurt dışı) IP'miz üzerinden GERÇEK TCP bağlantısı kuruluyor...`);
110
 
111
- // KESİN ÇÖZÜM 4: Eski SSH nesnesinin tüm listener'larını söküyoruz ki arkadan zombi tetikleme yapmasın
112
  if (sshClient) {
113
  try {
114
  sshClient.removeAllListeners('ready');
@@ -484,7 +482,7 @@ async function createBot() {
484
  const cleanFinish = () => {
485
  isLoopActive = false;
486
  clearInterval(clickInterval);
487
- windowOpenResolvers = []; // KESİN ÇÖZÜM 1: Havuz her durumda sıfırlanır
488
  resolve();
489
  };
490
 
@@ -492,8 +490,8 @@ async function createBot() {
492
  cleanFinish();
493
  });
494
 
495
- const clickInterval = setInterval(() => {
496
- if (!isLoopActive) return;
497
 
498
  if (bot.currentWindow != null) {
499
  cleanFinish();
@@ -513,8 +511,10 @@ async function createBot() {
513
  if (typeof bot.activateEntityAt === "function") bot.activateEntityAt(best.entity, best.entity.position);
514
  else if (typeof bot.activateEntity === "function") bot.activateEntity(best.entity);
515
  } catch (err) {}
 
516
 
517
- }, 600);
 
518
  });
519
 
520
  } catch (err) {}
@@ -626,7 +626,6 @@ function safeDestroyAllConnections() {
626
  isDestroying = true;
627
  isConnecting = false;
628
 
629
- // KESİN ÇÖZÜM 2: Bağlantı koptuğu an resolvers dizisi kökten boşaltılır, bir sonraki girişe zombi taşımaz
630
  windowOpenResolvers = [];
631
 
632
  if (viewerInstance && typeof viewerInstance.close === 'function') {
@@ -640,7 +639,6 @@ function safeDestroyAllConnections() {
640
  viewerInstance = null;
641
  if (bot) { bot.viewer = null; }
642
 
643
- // KESİN ÇÖZÜM 1: Önce alt akış (stream) kapatılır, ardından hiyerarşik imha yapılır
644
  if (currentStream && typeof currentStream.destroy === 'function') {
645
  try { currentStream.destroy(); } catch(e){}
646
  }
@@ -659,7 +657,6 @@ function safeDestroyAllConnections() {
659
 
660
  if (bot) {
661
  try {
662
- // KESİN ÇÖZÜM 3: Event sızıntılarını önlemek için bot üstündeki tüm listenerlar zorla sökülür
663
  bot.removeAllListeners('message');
664
  bot.removeAllListeners('spawn');
665
  bot.removeAllListeners('windowOpen');
@@ -754,6 +751,57 @@ app.get("/messages", (req, res) => {
754
  }, 60000);
755
  });
756
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
757
  const checkAndStartViewer = (req, res, next) => {
758
  if (viewerTimeout) {
759
  clearTimeout(viewerTimeout);
@@ -888,7 +936,7 @@ server.on('upgrade', (req, socket, head) => {
888
  });
889
 
890
  proxyReq.on('error', (err) => {
891
- logger.error("[WS Tünel Hatası] Websocket aktarızedilemedi: " + err.message);
892
  });
893
 
894
  proxyReq.end();
 
16
  // --- AYARLAR ---
17
  const HOME_ARRIVAL_DELAY_MS = 2000;
18
  const POST_ACTION_DELAY_MS = 4000;
19
+ const WINDOW_OPEN_TIMEOUT_MS = 6000;
20
  const PERIODIC_CHECK_INTERVAL_MS = 10 * 60 * 1000;
21
  const FULL_FEED_COOLDOWN_MS = 50 * 60 * 1000;
22
  const GO_HOME_COMMAND = "/home";
 
38
  let currentSshClient = null;
39
  let currentStream = null;
40
  let currentSocket = null;
41
+ let windowOpenResolvers = [];
42
 
43
  // --- PANEL METRİKLERİ ---
44
  let botUptimeStart = null;
45
  let lastFullFeedTimeStr = "Henüz besleme yapılmadı";
46
  let lastCheckTimeStr = "Henüz kontrol yapılmadı";
47
 
 
48
  https.get('https://api.ipify.org?format=json', (res) => {
49
  let data = '';
50
  res.on('data', chunk => { data += chunk; });
 
107
 
108
  logger.warn(`[Bağlantı Yedekleme] Doğrudan IP moduna geçiliyor (Sebep: ${reason}). Kendi (Yurt dışı) IP'miz üzerinden GERÇEK TCP bağlantısı kuruluyor...`);
109
 
 
110
  if (sshClient) {
111
  try {
112
  sshClient.removeAllListeners('ready');
 
482
  const cleanFinish = () => {
483
  isLoopActive = false;
484
  clearInterval(clickInterval);
485
+ windowOpenResolvers = [];
486
  resolve();
487
  };
488
 
 
490
  cleanFinish();
491
  });
492
 
493
+ const sendClickPacket = () => {
494
+ if (!isLoopActive) return;
495
 
496
  if (bot.currentWindow != null) {
497
  cleanFinish();
 
511
  if (typeof bot.activateEntityAt === "function") bot.activateEntityAt(best.entity, best.entity.position);
512
  else if (typeof bot.activateEntity === "function") bot.activateEntity(best.entity);
513
  } catch (err) {}
514
+ };
515
 
516
+ sendClickPacket();
517
+ const clickInterval = setInterval(sendClickPacket, 600);
518
  });
519
 
520
  } catch (err) {}
 
626
  isDestroying = true;
627
  isConnecting = false;
628
 
 
629
  windowOpenResolvers = [];
630
 
631
  if (viewerInstance && typeof viewerInstance.close === 'function') {
 
639
  viewerInstance = null;
640
  if (bot) { bot.viewer = null; }
641
 
 
642
  if (currentStream && typeof currentStream.destroy === 'function') {
643
  try { currentStream.destroy(); } catch(e){}
644
  }
 
657
 
658
  if (bot) {
659
  try {
 
660
  bot.removeAllListeners('message');
661
  bot.removeAllListeners('spawn');
662
  bot.removeAllListeners('windowOpen');
 
751
  }, 60000);
752
  });
753
 
754
+ app.get("/chat", (req, res) => {
755
+ const html = `
756
+ <!DOCTYPE html>
757
+ <html>
758
+ <head>
759
+ <meta charset="UTF-8">
760
+ <title>Canlı Minecraft Sohbeti</title>
761
+ <style>
762
+ body { background-color: #111; color: #eee; font-family: 'Courier New', Courier, monospace; padding: 20px; margin: 0; }
763
+ .container { max-width: 900px; margin: 0 auto; background: #1a1a1a; padding: 15px; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
764
+ h2 { margin-top: 0; border-bottom: 1px solid #333; padding-bottom: 10px; color: #fff; }
765
+ #chat-box { height: 500px; overflow-y: auto; background: #000; border: 1px solid #333; padding: 10px; border-radius: 4px; display: flex; flex-direction: column; }
766
+ .msg-line { margin-bottom: 6px; line-height: 1.4; font-size: 14px; word-break: break-all; }
767
+ .time-tag { color: #555; margin-right: 8px; font-size: 12px; }
768
+ </style>
769
+ </head>
770
+ <body>
771
+ <div class="container">
772
+ <h2>Canlı Oyun Sohbeti</h2>
773
+ <div id="chat-box"></div>
774
+ </div>
775
+ <script>
776
+ async function updateChat() {
777
+ try {
778
+ const res = await fetch('/messages');
779
+ if (!res.ok) return;
780
+ const data = await res.json();
781
+ const chatBox = document.getElementById('chat-box');
782
+ chatBox.innerHTML = '';
783
+ if (data.logs && data.logs.length > 0) {
784
+ data.logs.forEach(msg => {
785
+ const div = document.createElement('div');
786
+ div.className = 'msg-line';
787
+ div.innerHTML = '<span class="time-tag">[' + msg.time + ']</span>' + msg.text;
788
+ chatBox.appendChild(div);
789
+ });
790
+ chatBox.scrollTop = chatBox.scrollHeight;
791
+ } else {
792
+ chatBox.innerHTML = '<div style="color:#555;">Henüz yeni mesaj yok veya havuz temizlendi...</div>';
793
+ }
794
+ } catch(e) {}
795
+ }
796
+ setInterval(updateChat, 2000);
797
+ updateChat();
798
+ </script>
799
+ </body>
800
+ </html>
801
+ `;
802
+ res.send(html);
803
+ });
804
+
805
  const checkAndStartViewer = (req, res, next) => {
806
  if (viewerTimeout) {
807
  clearTimeout(viewerTimeout);
 
936
  });
937
 
938
  proxyReq.on('error', (err) => {
939
+ logger.error("[WS Tünel Hatası] Websocket aktarılamadı: " + err.message);
940
  });
941
 
942
  proxyReq.end();