Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (64 loc) · 1.85 KB
/
Copy pathindex.js
File metadata and controls
77 lines (64 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { execSync } = require('child_process');
const http = require('http');
try { require.resolve('mineflayer'); }
catch {
console.log('📦 Installing mineflayer...');
execSync('npm install mineflayer', { stdio: 'inherit' });
}
const mineflayer = require('mineflayer');
// ✅ CONFIG
const IP = 'ubaid.mcsh.io'; // Minecraft server IP
const PORT = 25565; // Server port
const WEB_PORT = process.env.PORT || 3000; // Fake port for Render/web host
const PASSWORD = 'Mishra@123';
let logs = [];
let bot;
// 🧠 Log helper
function log(msg) {
const line = `[${new Date().toISOString()}] ${msg}`;
console.log(line);
logs.push(line);
if (logs.length > 100) logs.shift();
}
// 🎲 Generate new name
function randomUsername() {
return 'BOT_' + Math.floor(Math.random() * 100000);
}
// 🤖 Infinite bot reconnect loop
function startBotLoop() {
const username = randomUsername();
log(`🔁 Connecting as ${username}...`);
bot = mineflayer.createBot({
host: IP,
port: PORT,
username
});
bot.on('spawn', () => {
log(`✅ ${username} spawned`);
setTimeout(() => bot.chat(`/register ${PASSWORD} ${PASSWORD}`), 2000);
setTimeout(() => bot.chat(`/login ${PASSWORD}`), 4000);
});
bot.on('kicked', reason => {
log(`🚫 Kicked: ${reason}`);
});
bot.on('error', err => {
log(`⚠️ Error: ${err.message}`);
});
bot.on('end', () => {
log(`🔌 Bot disconnected. Rejoining in 5s...`);
setTimeout(startBotLoop, 5000);
});
}
startBotLoop();
// 🌐 Minimal Web Server
http.createServer((req, res) => {
if (req.url === '/logs') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(logs.join('\n'));
} else {
res.writeHead(200);
res.end('Bot is running.\nUse /logs to view output.');
}
}).listen(WEB_PORT, () => {
log(`🌍 Web server running on port ${WEB_PORT}`);
});