File size: 9,169 Bytes
d4d39bb 8bb61b2 d4d39bb 89279ce d4d39bb 65c4436 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 3b2ae1c d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb 8bb61b2 d4d39bb |
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
// server.js
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const mineflayer = require('mineflayer');
const path = require('path');
const app = express();
const server = http.createServer(app);
const io = socketIo(server);
// Configuration
const SERVER_HOST = 'dm.progamer.me';
const SERVER_PORT = 40675;
const SERVER_VERSION = '1.21.8';
const BOT_NAMES = ['Alfha_lag', 'Bigboybloom', 'Kitcat'];
const ROTATION_DURATION = 3600; // 1 hour in seconds
// State
let currentBotIndex = 0;
let rotationStartTime = null;
let activeBot = null;
let serverStatus = { online: false, players: '0/0', latency: 0 };
const botStats = {};
// Initialize bot stats
BOT_NAMES.forEach(name => {
botStats[name] = {
name,
status: 'offline',
deaths: 0,
reconnects: 0,
uptime: 0,
position: { x: 0, y: 0, z: 0 },
health: 20,
food: 20,
isActive: false
};
});
// Bot creation with circular movement
function createBot(botName) {
console.log(`๐ Starting ${botName}...`);
const bot = mineflayer.createBot({
host: SERVER_HOST,
port: SERVER_PORT,
username: botName,
auth: 'offline',
version: SERVER_VERSION,
hideErrors: false,
checkTimeoutInterval: 30000,
keepAlive: true
});
let circleInterval = null;
let centerPos = null;
let angle = 0;
bot.once('spawn', () => {
console.log(`โ
${botName} connected`);
botStats[botName].status = 'online';
botStats[botName].uptime = Date.now();
// Start circular movement
setTimeout(() => {
if (!bot.entity) return;
centerPos = bot.entity.position.clone();
circleInterval = setInterval(() => {
if (!bot.entity) return;
try {
const radius = 4;
angle += 0.03;
const targetX = centerPos.x + Math.cos(angle) * radius;
const targetZ = centerPos.z + Math.sin(angle) * radius;
const dx = targetX - bot.entity.position.x;
const dz = targetZ - bot.entity.position.z;
const yaw = Math.atan2(-dx, -dz);
bot.look(yaw, 0, true);
bot.setControlState('forward', true);
// Update position
botStats[botName].position = {
x: Math.floor(bot.entity.position.x),
y: Math.floor(bot.entity.position.y),
z: Math.floor(bot.entity.position.z)
};
botStats[botName].health = bot.health || 20;
botStats[botName].food = bot.food || 20;
} catch (err) {
console.error(`Movement error for ${botName}:`, err.message);
}
}, 100);
}, 2000);
});
bot.on('death', () => {
console.log(`๐ ${botName} died`);
botStats[botName].deaths++;
if (circleInterval) clearInterval(circleInterval);
centerPos = null;
});
bot.on('respawn', () => {
console.log(`๐ ${botName} respawned`);
if (circleInterval) clearInterval(circleInterval);
centerPos = null;
angle = 0;
});
bot.on('kicked', (reason) => {
console.log(`โ ${botName} kicked: ${reason}`);
botStats[botName].status = 'offline';
if (circleInterval) clearInterval(circleInterval);
});
bot.on('error', (err) => {
console.error(`โ ${botName} error:`, err.message);
});
bot.on('end', () => {
console.log(`๐ ${botName} disconnected`);
botStats[botName].status = 'offline';
if (circleInterval) clearInterval(circleInterval);
// Auto reconnect after 5 seconds if still active
setTimeout(() => {
if (activeBot && activeBot.username === botName) {
console.log(`๐ Reconnecting ${botName}...`);
botStats[botName].reconnects++;
activeBot = createBot(botName);
}
}, 5000);
});
return bot;
}
// Stop bot
function stopBot(bot) {
if (!bot) return;
try {
bot.quit();
console.log(`โน๏ธ Stopped ${bot.username}`);
} catch (err) {
console.error('Error stopping bot:', err.message);
}
}
// Rotation manager
function rotationManager() {
setInterval(() => {
const currentBot = BOT_NAMES[currentBotIndex];
const now = Date.now();
if (!rotationStartTime || (now - rotationStartTime) >= (ROTATION_DURATION * 1000)) {
// Stop current bot
if (activeBot) {
stopBot(activeBot);
botStats[activeBot.username].isActive = false;
}
// Start new bot
setTimeout(() => {
activeBot = createBot(currentBot);
botStats[currentBot].isActive = true;
rotationStartTime = Date.now();
console.log(`๐ Rotation: ${currentBot} is now active`);
// Move to next bot
currentBotIndex = (currentBotIndex + 1) % BOT_NAMES.length;
}, 2000);
}
}, 5000);
}
// Check server status
async function checkServerStatus() {
try {
const net = require('net');
const client = new net.Socket();
const startTime = Date.now();
client.setTimeout(5000);
client.connect(SERVER_PORT, SERVER_HOST, () => {
const latency = Date.now() - startTime;
serverStatus = {
online: true,
latency,
players: '?/?'
};
client.destroy();
});
client.on('error', () => {
serverStatus = { online: false, latency: 0, players: '0/0' };
client.destroy();
});
client.on('timeout', () => {
serverStatus = { online: false, latency: 0, players: '0/0' };
client.destroy();
});
} catch (err) {
serverStatus = { online: false, latency: 0, players: '0/0' };
}
}
// Socket.IO
io.on('connection', (socket) => {
console.log('๐ฑ Client connected');
const sendUpdate = () => {
const currentBot = BOT_NAMES[(currentBotIndex - 1 + BOT_NAMES.length) % BOT_NAMES.length];
const nextBot = BOT_NAMES[currentBotIndex];
const elapsed = rotationStartTime ? Math.floor((Date.now() - rotationStartTime) / 1000) : 0;
const remaining = Math.max(0, ROTATION_DURATION - elapsed);
// Update uptimes
Object.keys(botStats).forEach(name => {
if (botStats[name].status === 'online' && botStats[name].uptime) {
botStats[name].uptimeSeconds = Math.floor((Date.now() - botStats[name].uptime) / 1000);
} else {
botStats[name].uptimeSeconds = 0;
}
});
socket.emit('update', {
server: {
host: SERVER_HOST,
port: SERVER_PORT,
version: SERVER_VERSION,
status: serverStatus
},
rotation: {
current: currentBot,
next: nextBot,
elapsed,
remaining,
queue: BOT_NAMES
},
bots: Object.values(botStats)
});
};
const interval = setInterval(sendUpdate, 1000);
sendUpdate();
socket.on('forceRotation', () => {
rotationStartTime = 0;
socket.emit('rotationForced', true);
});
socket.on('disconnect', () => {
clearInterval(interval);
console.log('๐ด Client disconnected');
});
});
// Serve static files
app.use(express.static(__dirname));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
// Start server
const PORT = process.env.PORT || 7860;
server.listen(PORT, () => {
console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
console.log('๐ฎ MINECRAFT BOT MANAGER');
console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
console.log(`๐ก Server: ${SERVER_HOST}:${SERVER_PORT}`);
console.log(`๐ค Bots: ${BOT_NAMES.join(', ')}`);
console.log(`โฑ๏ธ Rotation: ${ROTATION_DURATION / 60} minutes`);
console.log(`๐ Dashboard: http://localhost:${PORT}`);
console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
});
// Start systems
rotationManager();
setInterval(checkServerStatus, 1000);
checkServerStatus(); |