SAwww / server-optimizer.js
SAyyeedd's picture
Upload 30 files
309ec79 verified
Raw
History Blame Contribute Delete
35.6 kB
'use strict';
/**
* โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
* Server Optimizer โ€” v1.0 | ุชุญุณูŠู† ุงู„ุณูŠุฑูุฑ ููŠ ุงู„ุฃูˆู‚ุงุช ุงู„ุญุฑุฌุฉ ูˆุงู„ู…ุชูˆุณุทุฉ โ•‘
* โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ
* โœ… ู…ุฑุงู‚ุจุฉ ู…ุณุชู…ุฑุฉ: TPS + RAM + Entities + Chunks + Players โ•‘
* โœ… 3 ุฃูˆุถุงุน: CRITICAL / MODERATE / NORMAL โ•‘
* โœ… ุชุญุณูŠู† ุชู„ู‚ุงุฆูŠ: ุชู‚ู„ูŠู„ ุงู„ุจูˆุชุงุช + ุชุนุทูŠู„ Pathfinding + ุชู‚ู„ูŠู„ ุงู„ุฑุณุงุฆู„ โ•‘
* โœ… ุชุญู„ูŠู„ ุฐูƒูŠ: ุฃู†ู…ุงุท ุงู„ุฃุฏุงุก + ุชูˆุตูŠุงุช + ุชู†ุจุค ุจุงู„ู…ุดุงูƒู„ โ•‘
* โœ… ุชู†ุณูŠู‚ ู…ุน ุงู„ุจูˆุชุงุช: ุฅุฑุณุงู„ ุฃูˆุงู…ุฑ ุชุนุทูŠู„/ุชูุนูŠู„ ุญุณุจ ุงู„ุญุงู„ุฉ โ•‘
* โœ… ุชู‚ุงุฑูŠุฑ ุฏูˆุฑูŠุฉ: ู…ู„ุฎุต ุฃุฏุงุก ูƒู„ 5 ุฏู‚ุงุฆู‚ โ•‘
* โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
*/
const { EventEmitter } = require('events');
const tsNow = () => new Date().toISOString().replace('T', ' ').slice(0, 19);
const sleep = ms => new Promise(r => setTimeout(r, Math.max(0, ms)));
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุงู„ุญุฏูˆุฏ ูˆุงู„ุนุชุจุงุช (Thresholds)
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
const THRESHOLDS = {
// โ”€โ”€โ”€ CRITICAL (ุฃู‚ู„ ู…ู† ูƒุฏู‡ ุงู„ุณูŠุฑูุฑ ุจูŠู…ูˆุช) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
critical: {
tps: 10, // TPS ุฃู‚ู„ ู…ู† 10
ram: 92, // RAM ุฃุนู„ู‰ ู…ู† 92%
entities: 200, // Entities ุฃุนู„ู‰ ู…ู† 200
chunkRate: 50, // Chunks per second ุฃู‚ู„ ู…ู† 50
playerPing: 500, // Ping ุฃุนู„ู‰ ู…ู† 500ms
},
// โ”€โ”€โ”€ MODERATE (ููŠู‡ ุถุบุท ุจุณ ู„ุณู‡ ุดุบุงู„) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
moderate: {
tps: 16, // TPS ุฃู‚ู„ ู…ู† 16
ram: 80, // RAM ุฃุนู„ู‰ ู…ู† 80%
entities: 120, // Entities ุฃุนู„ู‰ ู…ู† 120
chunkRate: 100, // Chunks per second ุฃู‚ู„ ู…ู† 100
playerPing: 300, // Ping ุฃุนู„ู‰ ู…ู† 300ms
},
// โ”€โ”€โ”€ NORMAL (ูƒู„ ุญุงุฌุฉ ุชู…ุงู…) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
normal: {
tps: 19,
ram: 65,
entities: 60,
chunkRate: 200,
playerPing: 150,
}
};
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุฅุนุฏุงุฏุงุช ูƒู„ ูˆุถุน
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
const MODE_CONFIGS = {
// โ”€โ”€โ”€ CRITICAL: ุฃู‚ู„ ู†ุดุงุท ู…ู…ูƒู† โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
critical: {
label: '๐Ÿ”ด ุญุฑุฌ',
botActivity: 'minimal', // ุฃู‚ู„ ู†ุดุงุท
pathfinding: false, // ุชุนุทูŠู„ Pathfinding ุชู…ุงู…ุงู‹
chatFrequency: 0, // ุชุนุทูŠู„ ุงู„ุฑุณุงุฆู„
taskInterval: 60000, // ุงู„ู…ู‡ุงู… ูƒู„ ุฏู‚ูŠู‚ุฉ
maxActiveBots: 2, // ุฃู‚ู„ ุนุฏุฏ ุจูˆุชุงุช ุดุบุงู„ุฉ
autoEat: true, // ุงู„ุฃูƒู„ ุดุบุงู„ ุฏุงูŠู…ุงู‹
autoSleep: true, // ุงู„ู†ูˆู… ุดุบุงู„
combatResponse: 'flee', // ุงู„ู‡ุฑูˆุจ ุจุณ
miningEnabled: false, // ุชุนุทูŠู„ ุงู„ุชุนุฏูŠู†
buildingEnabled: false, // ุชุนุทูŠู„ ุงู„ุจู†ุงุก
farmingEnabled: false, // ุชุนุทูŠู„ ุงู„ุฒุฑุงุนุฉ
explorationEnabled: false, // ุชุนุทูŠู„ ุงู„ุงุณุชูƒุดุงู
tradingEnabled: false, // ุชุนุทูŠู„ ุงู„ุชุฌุงุฑุฉ
socialEnabled: false, // ุชุนุทูŠู„ ุงู„ุชูุงุนู„
dailyRoutine: false, // ุชุนุทูŠู„ ุงู„ุฑูˆุชูŠู† ุงู„ูŠูˆู…ูŠ
antiAfk: 'sleep', // ุจุณ ู†ูˆู…
viewDistance: 'tiny', // ุฃู‚ู„ ู…ุณุงูุฉ ุฑุคูŠุฉ
},
// โ”€โ”€โ”€ MODERATE: ู†ุดุงุท ู…ุชูˆุณุท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
moderate: {
label: '๐ŸŸก ู…ุชูˆุณุท',
botActivity: 'reduced', // ู†ุดุงุท ู…ุฎูู
pathfinding: true, // Pathfinding ุดุบุงู„ ุจุณ ุจุทูŠุก
chatFrequency: 0.3, // 30% ู…ู† ุงู„ุฑุณุงุฆู„ ุงู„ุนุงุฏูŠุฉ
taskInterval: 30000, // ุงู„ู…ู‡ุงู… ูƒู„ 30 ุซุงู†ูŠุฉ
maxActiveBots: 4, // 4 ุจูˆุชุงุช ูƒุญุฏ ุฃู‚ุตู‰
autoEat: true,
autoSleep: true,
combatResponse: 'fight', // ู‚ุชุงู„ ุนุงุฏูŠ
miningEnabled: true,
buildingEnabled: true,
farmingEnabled: true,
explorationEnabled: false, // ุงู„ุงุณุชูƒุดุงู ู…ุชูˆู‚ู
tradingEnabled: false, // ุงู„ุชุฌุงุฑุฉ ู…ุชูˆู‚ูุฉ
socialEnabled: true,
dailyRoutine: true,
antiAfk: 'moderate', // ุญุฑูƒุฉ ู…ุชูˆุณุทุฉ
viewDistance: 'short', // ู…ุณุงูุฉ ุฑุคูŠุฉ ู‚ุตูŠุฑุฉ
},
// โ”€โ”€โ”€ NORMAL: ูƒู„ ุญุงุฌุฉ ุดุบุงู„ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
normal: {
label: '๐ŸŸข ุทุจูŠุนูŠ',
botActivity: 'full', // ู†ุดุงุท ูƒุงู…ู„
pathfinding: true,
chatFrequency: 1.0, // ูƒู„ ุงู„ุฑุณุงุฆู„
taskInterval: 15000, // ุงู„ู…ู‡ุงู… ูƒู„ 15 ุซุงู†ูŠุฉ
maxActiveBots: 10, // ูƒู„ ุงู„ุจูˆุชุงุช
autoEat: true,
autoSleep: true,
combatResponse: 'fight',
miningEnabled: true,
buildingEnabled: true,
farmingEnabled: true,
explorationEnabled: true,
tradingEnabled: true,
socialEnabled: true,
dailyRoutine: true,
antiAfk: 'full', // ุญุฑูƒุฉ ูƒุงู…ู„ุฉ
viewDistance: 'normal', // ู…ุณุงูุฉ ุฑุคูŠุฉ ุนุงุฏูŠุฉ
}
};
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ServerOptimizer Class
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
class ServerOptimizer extends EventEmitter {
constructor(config = {}) {
super();
this.config = {
checkInterval: config.checkInterval || 10000, // ูุญุต ูƒู„ 10 ุซูˆุงู†ูŠ
reportInterval: config.reportInterval || 300000, // ุชู‚ุฑูŠุฑ ูƒู„ 5 ุฏู‚ุงุฆู‚
historySize: config.historySize || 300, // 50 ุฏู‚ูŠู‚ุฉ ู…ู† ุงู„ุจูŠุงู†ุงุช
recoveryDelay: config.recoveryDelay || 60000, // ุฏู‚ูŠู‚ุฉ ู‚ุจู„ ุงู„ุฑุฌูˆุน ู…ู† CRITICAL
autoModeSwitch: config.autoModeSwitch !== false, // ุชุบูŠูŠุฑ ุชู„ู‚ุงุฆูŠ ู„ู„ูˆุถุน
...config
};
// โ”€โ”€โ”€ ุงู„ุญุงู„ุฉ ุงู„ุญุงู„ูŠุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this.currentMode = 'normal'; // ุงู„ูˆุถุน ุงู„ุญุงู„ูŠ
this.previousMode = 'normal'; // ุงู„ูˆุถุน ุงู„ุณุงุจู‚
this.modeStartTime = Date.now(); // ูˆู‚ุช ุจุฏุก ุงู„ูˆุถุน ุงู„ุญุงู„ูŠ
this.modeTransitionPending = null; // ุชุบูŠูŠุฑ ูˆุดูŠูƒ
this.modeTransitionTimer = null; // ู…ุคู‚ุช ุงู„ุชุบูŠูŠุฑ
// โ”€โ”€โ”€ ุงู„ุจูŠุงู†ุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this.metrics = {
tps: 20,
ram: 50,
entities: 0,
chunks: 0,
players: 0,
ping: 0,
worldTime: 0,
uptime: 0,
botCount: 0,
activeBots: 0,
};
this.history = [];
this.alerts = [];
this.optimizations = [];
this.stats = {
modeChanges: 0,
optimizationsApplied: 0,
criticalEvents: 0,
moderateEvents: 0,
normalEvents: 0,
totalChecks: 0,
avgTps: 20,
avgRam: 50,
worstTps: 20,
worstRam: 50,
};
// โ”€โ”€โ”€ ุงู„ุจูˆุชุงุช ุงู„ู…ุชุตู„ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this.connectedBots = new Map(); // botId โ†’ { bot, mode, lastAction }
this._running = false;
this._checkTimer = null;
this._reportTimer = null;
this._log('OPTIMIZER', 'ุชู… ุฅู†ุดุงุก Server Optimizer v1.0');
}
_log(tag, msg) {
console.log(`[${tsNow()}] [OPTIMIZER] ${tag} ${msg}`);
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุจุฏุก/ุฅูŠู‚ุงู ุงู„ุชุญุณูŠู†
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
start() {
if (this._running) return;
this._running = true;
this._log('๐ŸŸข', 'ุจุฏุก ู…ุฑุงู‚ุจุฉ ูˆุชุญุณูŠู† ุงู„ุณูŠุฑูุฑ...');
this._checkTimer = setInterval(() => this._check(), this.config.checkInterval);
this._reportTimer = setInterval(() => this._report(), this.config.reportInterval);
this._optimCycleTimer = setInterval(() => this._runOptimizationCycle(), 30000);
this._check();
this._report();
}
stop() {
this._running = false;
if (this._checkTimer) { clearInterval(this._checkTimer); this._checkTimer = null; }
if (this._reportTimer) { clearInterval(this._reportTimer); this._reportTimer = null; }
if (this.modeTransitionTimer) { clearTimeout(this.modeTransitionTimer); this.modeTransitionTimer = null; }
if (this._optimCycleTimer) { clearInterval(this._optimCycleTimer); this._optimCycleTimer = null; }
this._log('๐Ÿ”ด', 'ุฅูŠู‚ุงู Server Optimizer');
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุงู„ุชุญู‚ู‚ ุงู„ุฑุฆูŠุณูŠ (ูƒู„ 10 ุซูˆุงู†ูŠ)
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
async _check() {
if (!this._running) return;
this.stats.totalChecks++;
try {
// โ”€โ”€โ”€ ุชุญู„ูŠู„ ุงู„ุญุงู„ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const analysis = this._analyzeMetrics();
const newMode = analysis.recommendedMode;
// โ”€โ”€โ”€ ุชุญุฏูŠุซ ุงู„ุฅุญุตุงุฆูŠุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this._updateStats();
// โ”€โ”€โ”€ ุญูุธ ููŠ ุงู„ุชุงุฑูŠุฎ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this.history.push({
time: Date.now(),
mode: this.currentMode,
tps: this.metrics.tps,
ram: this.metrics.ram,
entities: this.metrics.entities,
players: this.metrics.players,
analysis: analysis.reasons
});
if (this.history.length > this.config.historySize) this.history.shift();
// โ”€โ”€โ”€ ุชุบูŠูŠุฑ ุงู„ูˆุถุน ุฅุฐุง ู„ุฒู… โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (this.config.autoModeSwitch && newMode !== this.currentMode) {
this._requestModeChange(newMode, analysis.reasons);
}
// โ”€โ”€โ”€ ุชุทุจูŠู‚ ุงู„ุชุญุณูŠู†ุงุช ุนู„ู‰ ุงู„ุจูˆุชุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this._applyOptimizations();
// โ”€โ”€โ”€ ุฅุฑุณุงู„ ุงู„ุฃุญุฏุงุซ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this.emit('check', { mode: this.currentMode, metrics: { ...this.metrics }, analysis });
} catch (err) {
this._log('โŒ', `ุฎุทุฃ ููŠ ุงู„ูุญุต: ${err.message}`);
}
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุชุญู„ูŠู„ ุงู„ู…ู‚ุงูŠูŠุณ ูˆุชุญุฏูŠุฏ ุงู„ูˆุถุน
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
_analyzeMetrics() {
const m = this.metrics;
const reasons = [];
let score = 0; // 0-100 (0=ุญุฑุฌ, 100=ู…ู…ุชุงุฒ)
// โ”€โ”€โ”€ ุชุญู„ูŠู„ TPS โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (m.tps <= THRESHOLDS.critical.tps) {
score -= 40;
reasons.push(`TPS ุญุฑุฌ: ${m.tps}`);
} else if (m.tps <= THRESHOLDS.moderate.tps) {
score -= 20;
reasons.push(`TPS ู…ู†ุฎูุถ: ${m.tps}`);
} else {
score += 20;
}
// โ”€โ”€โ”€ ุชุญู„ูŠู„ RAM โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (m.ram >= THRESHOLDS.critical.ram) {
score -= 30;
reasons.push(`RAM ุญุฑุฌ: ${m.ram}%`);
} else if (m.ram >= THRESHOLDS.moderate.ram) {
score -= 15;
reasons.push(`RAM ู…ุฑุชูุน: ${m.ram}%`);
} else {
score += 15;
}
// โ”€โ”€โ”€ ุชุญู„ูŠู„ Entities โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (m.entities >= THRESHOLDS.critical.entities) {
score -= 15;
reasons.push(`Entities ูƒุชูŠุฑ: ${m.entities}`);
} else if (m.entities >= THRESHOLDS.moderate.entities) {
score -= 8;
reasons.push(`Entities ู…ุชูˆุณุท: ${m.entities}`);
} else {
score += 10;
}
// โ”€โ”€โ”€ ุชุญู„ูŠู„ ุงู„ู„ุงุนุจูŠู† โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (m.players > 10) {
score -= 10;
reasons.push(`ู„ุงุนุจูŠู† ูƒุชูŠุฑ: ${m.players}`);
} else if (m.players > 5) {
score -= 5;
} else {
score += 5;
}
// โ”€โ”€โ”€ ุชุญู„ูŠู„ ุงู„ุจูˆุชุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const activeBots = this.connectedBots.size;
if (activeBots > 6) {
score -= 10;
reasons.push(`ุจูˆุชุงุช ูƒุชูŠุฑ ุดุบุงู„ุฉ: ${activeBots}`);
} else if (activeBots > 3) {
score -= 5;
} else {
score += 5;
}
// โ”€โ”€โ”€ ุชุญุฏูŠุฏ ุงู„ูˆุถุน โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
let recommendedMode;
if (score <= 20) {
recommendedMode = 'critical';
} else if (score <= 35) {
recommendedMode = 'moderate';
} else {
recommendedMode = 'normal';
}
// โ”€โ”€โ”€ ุชุญู„ูŠู„ ุงู„ุงุชุฌุงู‡ (ู‡ู„ Situation ุจุชุชุญุณู† ุฃูˆ ุจุช tแป‡ุŸ) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const trend = this._analyzeTrend();
return {
score: Math.max(0, Math.min(100, score)),
recommendedMode,
reasons,
trend,
details: {
tpsStatus: m.tps >= 19 ? '๐ŸŸข' : m.tps >= 16 ? '๐ŸŸก' : '๐Ÿ”ด',
ramStatus: m.ram <= 65 ? '๐ŸŸข' : m.ram <= 80 ? '๐ŸŸก' : '๐Ÿ”ด',
entityStatus: m.entities <= 60 ? '๐ŸŸข' : m.entities <= 120 ? '๐ŸŸก' : '๐Ÿ”ด',
}
};
}
_analyzeTrend() {
if (this.history.length < 10) return 'stable';
const recent = this.history.slice(-10);
const older = this.history.slice(-20, -10);
if (older.length === 0) return 'stable';
const recentAvgTps = recent.reduce((s, h) => s + h.tps, 0) / recent.length;
const olderAvgTps = older.reduce((s, h) => s + h.tps, 0) / older.length;
if (recentAvgTps > olderAvgTps + 2) return 'improving';
if (recentAvgTps < olderAvgTps - 2) return 'worsening';
return 'stable';
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุชุบูŠูŠุฑ ุงู„ูˆุถุน
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
_requestModeChange(newMode, reasons) {
// โ”€โ”€โ”€ CRITICAL: ุชุบูŠูŠุฑ ููˆุฑูŠ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (newMode === 'critical') {
this._switchMode(newMode, reasons);
return;
}
// โ”€โ”€โ”€ MODERATE โ†’ NORMAL: ุงู†ุชุธุงุฑ 30 ุซุงู†ูŠุฉ ู„ู„ุชุฃูƒุฏ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (this.currentMode === 'critical' && newMode === 'moderate') {
if (this.modeTransitionPending === 'moderate') {
// ุงู†ุชุธุฑ ุฃูƒุซุฑ
return;
}
this.modeTransitionPending = 'moderate';
this._log('โณ', 'ุงู†ุชุธุงุฑ 30 ุซุงู†ูŠุฉ ู„ู„ุฑุฌูˆุน ู…ู† CRITICAL...');
this.modeTransitionTimer = setTimeout(() => {
this._switchMode('moderate', reasons);
this.modeTransitionPending = null;
}, 30000);
return;
}
// โ”€โ”€โ”€ MODERATE โ†’ NORMAL: ุงู†ุชุธุงุฑ ุฏู‚ูŠู‚ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (this.currentMode === 'moderate' && newMode === 'normal') {
if (this.modeTransitionPending === 'normal') return;
this.modeTransitionPending = 'normal';
this._log('โณ', 'ุงู†ุชุธุงุฑ 60 ุซุงู†ูŠุฉ ู„ู„ุฑุฌูˆุน ู…ู† MODERATE...');
this.modeTransitionTimer = setTimeout(() => {
this._switchMode('normal', reasons);
this.modeTransitionPending = null;
}, 60000);
return;
}
// โ”€โ”€โ”€ ุฃูŠ ุชุบูŠูŠุฑ ุชุงู†ูŠ: ููˆุฑูŠ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this._switchMode(newMode, reasons);
}
_switchMode(newMode, reasons) {
if (this.modeTransitionTimer) {
clearTimeout(this.modeTransitionTimer);
this.modeTransitionTimer = null;
}
this.modeTransitionPending = null;
const oldMode = this.currentMode;
this.previousMode = oldMode;
this.currentMode = newMode;
this.modeStartTime = Date.now();
this.stats.modeChanges++;
if (newMode === 'critical') this.stats.criticalEvents++;
else if (newMode === 'moderate') this.stats.moderateEvents++;
else this.stats.normalEvents++;
const config = MODE_CONFIGS[newMode];
this._log('๐Ÿ”„', `ุชุบูŠูŠุฑ ุงู„ูˆุถุน: ${MODE_CONFIGS[oldMode].label} โ†’ ${config.label}`);
this._log('๐Ÿ“‹', `ุงู„ุฃุณุจุงุจ: ${reasons.join(', ')}`);
// โ”€โ”€โ”€ ุฅุฑุณุงู„ ุฃุญุฏุงุซ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this.emit('modeChange', {
from: oldMode,
to: newMode,
config,
reasons,
timestamp: Date.now()
});
// โ”€โ”€โ”€ ุฅุดุนุงุฑ ุงู„ุจูˆุชุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
this._notifyBotsModeChange(newMode, config);
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุฅุฏุงุฑุฉ ุงู„ุจูˆุชุงุช ุงู„ู…ุชุตู„ุฉ
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
registerBot(botId, bot) {
this.connectedBots.set(botId, {
bot,
mode: this.currentMode,
lastAction: Date.now(),
disabled: false,
pathfindingEnabled: true,
chatEnabled: true,
});
this._log('๐Ÿค–', `ุจูˆุช ู…ุณุฌู„: ${botId} (${this.connectedBots.size} ุจูˆุช)`);
this._applyBotMode(botId);
}
unregisterBot(botId) {
this.connectedBots.delete(botId);
this._log('๐Ÿ‘‹', `ุจูˆุช ุงู†ูุตู„: ${botId} (${this.connectedBots.size} ุจูˆุช)`);
}
_notifyBotsModeChange(newMode, config) {
this.connectedBots.forEach((data, botId) => {
data.mode = newMode;
this._applyBotMode(botId);
});
}
_applyBotMode(botId) {
const data = this.connectedBots.get(botId);
if (!data || !data.bot) return;
const config = MODE_CONFIGS[this.currentMode];
try {
// โ”€โ”€โ”€ ุชุนุทูŠู„/ุชูุนูŠู„ Pathfinding โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
data.pathfindingEnabled = config.pathfinding;
// โ”€โ”€โ”€ ุชุนุทูŠู„/ุชูุนูŠู„ ุงู„ุฑุณุงุฆู„ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
data.chatEnabled = config.chatFrequency > 0;
// โ”€โ”€โ”€ ุชู‚ู„ูŠู„ ู†ุดุงุท ุงู„ุจูˆุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (config.botActivity === 'minimal') {
data.bot._optimizerMode = 'minimal';
} else if (config.botActivity === 'reduced') {
data.bot._optimizerMode = 'reduced';
} else {
data.bot._optimizerMode = 'full';
}
this._log('โš™๏ธ', ` Bot ${botId}: ูˆุถุน ${config.label}`);
} catch (err) {
this._log('โŒ', `ุฎุทุฃ ููŠ ุชุทุจูŠู‚ ุงู„ูˆุถุน ุนู„ู‰ ${botId}: ${err.message}`);
}
}
_runOptimizationCycle() {
const bots = [...this.connectedBots.values()].filter(d => d.bot && !d.disabled);
if (bots.length === 0) return;
const b = bots[0].bot;
if (!b) return;
try { b.chat('/tps'); } catch(_) {}
setTimeout(() => {
if (!b) return;
try { b.chat('/lagg clear'); } catch(_) {}
if (this.currentMode === 'critical') {
setTimeout(() => {
if (!b) return;
try { b.chat('/lagg clear'); } catch(_) {}
setTimeout(() => {
if (!b) return;
try { b.chat('/minecraft:kill @e[type=item]'); } catch(_) {}
}, 500);
}, 500);
}
}, 500);
}
_applyOptimizations() {
const config = MODE_CONFIGS[this.currentMode];
this.connectedBots.forEach((data, botId) => {
if (!data.bot) return;
try {
// โ”€โ”€โ”€ ููŠ ุงู„ูˆุถุน ุงู„ุญุฑุฌ: ุชู‚ู„ูŠู„ ูƒู„ ุญุงุฌุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (this.currentMode === 'critical') {
// โ”€โ”€โ”€ ุฅูŠู‚ุงู ุฃูŠ ุญุฑูƒุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (data.bot.pathfinder && data.pathfindingEnabled) {
data.pathfindingEnabled = false;
}
// โ”€โ”€โ”€ ุฅูŠู‚ุงู ุงู„ุชุนุฏูŠู† โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (data.bot._mining && config.miningEnabled === false) {
data.bot._mining = false;
}
// โ”€โ”€โ”€ ุฅูŠู‚ุงู ุงู„ุจู†ุงุก โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (data.bot._building && config.buildingEnabled === false) {
data.bot._building = false;
}
}
// โ”€โ”€โ”€ ููŠ ุงู„ูˆุถุน ุงู„ู…ุชูˆุณุท: ุชู‚ู„ูŠู„ ุงู„ู†ุดุงุท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (this.currentMode === 'moderate') {
// โ”€โ”€โ”€ ุชู‚ู„ูŠู„ ุณุฑุนุฉ Pathfinding โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (data.bot.pathfinder && data.pathfindingEnabled) {
data.bot.pathfinder.setTicksPerTick(2); // ุจุทูŠุก
}
}
// โ”€โ”€โ”€ ููŠ ุงู„ูˆุถุน ุงู„ุทุจูŠุนูŠ: ูƒู„ ุญุงุฌุฉ ุดุบุงู„ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if (this.currentMode === 'normal') {
if (data.bot.pathfinder && !data.pathfindingEnabled) {
data.pathfindingEnabled = true;
}
if (data.bot.pathfinder) {
data.bot.pathfinder.setTicksPerTick(1); // ุนุงุฏูŠ
}
}
} catch (err) {
// ุชุฌุงู‡ู„ ุงู„ุฃุฎุทุงุก
}
});
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุชุญุฏูŠุซ ุงู„ู…ู‚ุงูŠูŠุณ (ูŠุชู… ุงุณุชุฏุนุงุคู‡ ู…ู† ะฒะฝะตัˆะฝะธะต ุฃู†ุธู…ุฉ)
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
updateMetrics(newMetrics) {
Object.assign(this.metrics, newMetrics);
}
updateTps(tps) {
this.metrics.tps = tps;
}
updateRam(ramPercent) {
this.metrics.ram = ramPercent;
}
updateEntities(count) {
this.metrics.entities = count;
}
updatePlayers(count) {
this.metrics.players = count;
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุชุญุฏูŠุซ ุงู„ุฅุญุตุงุฆูŠุงุช
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
_updateStats() {
const m = this.metrics;
const n = this.stats.totalChecks;
this.stats.avgTps = ((this.stats.avgTps * (n - 1)) + m.tps) / n;
this.stats.avgRam = ((this.stats.avgRam * (n - 1)) + m.ram) / n;
this.stats.worstTps = Math.min(this.stats.worstTps, m.tps);
this.stats.worstRam = Math.max(this.stats.worstRam, m.ram);
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุงู„ุชู‚ุงุฑูŠุฑ ุงู„ุฏูˆุฑูŠุฉ
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
_report() {
if (!this._running) return;
const m = this.metrics;
const config = MODE_CONFIGS[this.currentMode];
const uptime = Date.now() - this.modeStartTime;
const uptimeMin = Math.floor(uptime / 60000);
this._log('๐Ÿ“Š', 'โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
this._log('๐Ÿ“Š', `ุงู„ูˆุถุน ุงู„ุญุงู„ูŠ: ${config.label}`);
this._log('๐Ÿ“Š', `TPS: ${m.tps} | RAM: ${m.ram}% | Entities: ${m.entities} | Players: ${m.players}`);
this._log('๐Ÿ“Š', `ุจูˆุชุงุช ู…ุชุตู„ุฉ: ${this.connectedBots.size}`);
this._log('๐Ÿ“Š', `ู…ุฏุฉ ุงู„ูˆุถุน ุงู„ุญุงู„ูŠ: ${uptimeMin} ุฏู‚ูŠู‚ุฉ`);
this._log('๐Ÿ“Š', `ุชุบูŠูŠุฑุงุช ุงู„ูˆุถุน: ${this.stats.modeChanges} | ุฃุญุฏุงุซ ุญุฑุฌุฉ: ${this.stats.criticalEvents}`);
this._log('๐Ÿ“Š', `TPS ุงู„ู…ุชูˆุณุท: ${this.stats.avgTps.toFixed(1)} | Worst: ${this.stats.worstTps}`);
this._log('๐Ÿ“Š', `RAM ุงู„ู…ุชูˆุณุท: ${this.stats.avgRam.toFixed(1)}% | Worst: ${this.stats.worstRam}%`);
this._log('๐Ÿ“Š', 'โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
this.emit('report', this.getStatus());
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุงู„ุญุตูˆู„ ุนู„ู‰ ุงู„ุญุงู„ุฉ ุงู„ูƒุงู…ู„ุฉ
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
getStatus() {
const config = MODE_CONFIGS[this.currentMode];
const uptime = Date.now() - this.modeStartTime;
return {
running: this._running,
currentMode: this.currentMode,
modeLabel: config.label,
previousMode: this.previousMode,
modeUptime: uptime,
modeUptimeMin: Math.floor(uptime / 60000),
metrics: { ...this.metrics },
config: { ...config },
stats: { ...this.stats },
connectedBots: this.connectedBots.size,
historySize: this.history.length,
analysis: this._analyzeMetrics(),
recommendations: this._getRecommendations(),
};
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุงู„ุชูˆุตูŠุงุช ุงู„ุฐูƒูŠุฉ
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
_getRecommendations() {
const recs = [];
const m = this.metrics;
if (m.tps < 14) {
recs.push({
priority: 'high',
type: 'tps',
message: 'TPS ู…ู†ุฎูุถ ุฌุฏุงู‹ โ€” ู‚ู„ู„ ุนุฏุฏ ุงู„ุจูˆุชุงุช ุฃูˆ ุนุทู‘ู„ ุจุนุถ ุงู„ู…ูŠุฒุงุช',
action: 'reduce_bots'
});
}
if (m.ram > 85) {
recs.push({
priority: 'high',
type: 'ram',
message: 'RAM ุนุงู„ูŠ ุฌุฏุงู‹ โ€” ุดุบู‘ู„ GC ูŠุฏูˆูŠุงู‹ ุฃูˆ ู‚ู„ู„ ุงู„ูƒุงุด',
action: 'force_gc'
});
}
if (m.entities > 150) {
recs.push({
priority: 'medium',
type: 'entities',
message: 'ุนุฏุฏ Entities ูƒุจูŠุฑ โ€” ู‚ู„ู„ ู…ุณุงูุฉ ุงู„ุฑุคูŠุฉ ุฃูˆ ุนุทู‘ู„ ุจุนุถ ุงู„ู…ูŠุฒุงุช',
action: 'reduce_view'
});
}
if (this.connectedBots.size > 5) {
recs.push({
priority: 'medium',
type: 'bots',
message: `ุนุฏุฏ ุงู„ุจูˆุชุงุช ูƒุจูŠุฑ (${this.connectedBots.size}) โ€” ู‚ู„ู„ ุงู„ุนุฏุฏ`,
action: 'reduce_bots'
});
}
if (this.stats.worstTps < 8) {
recs.push({
priority: 'low',
type: 'history',
message: `ูˆุตู„ TPS ู„ู€ ${this.stats.worstTps} ู‚ุจู„ ูƒุฏู‡ โ€” ุฑุงู‚ุจ ุงู„ุฃุณุจุงุจ`,
action: 'monitor'
});
}
return recs;
}
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ุงู„ุชุญูƒู… ุงู„ูŠุฏูˆูŠ
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
setMode(mode) {
if (!MODE_CONFIGS[mode]) {
this._log('โŒ', `ูˆุถุน ุบูŠุฑ ุตุญูŠุญ: ${mode}`);
return false;
}
this._switchMode(mode, ['manual_override']);
this._log(' manual', `ุชู… ุชุบูŠูŠุฑ ุงู„ูˆุถุน ูŠุฏูˆูŠุงู‹ ุฅู„ู‰: ${MODE_CONFIGS[mode].label}`);
return true;
}
forceOptimization() {
this._log('๐Ÿ”ง', 'ุชุญุณูŠู† ุฅุฌุจุงุฑูŠ...');
this._applyOptimizations();
this.stats.optimizationsApplied++;
return true;
}
getModeConfig(mode) {
return MODE_CONFIGS[mode] ? { ...MODE_CONFIGS[mode] } : null;
}
getHistory(minutes = 30) {
const cutoff = Date.now() - (minutes * 60000);
return this.history.filter(h => h.time >= cutoff);
}
destroy() {
this.stop();
this.connectedBots.clear();
this.history = [];
this.alerts = [];
this.optimizations = [];
this.removeAllListeners();
}
}
module.exports = { ServerOptimizer, THRESHOLDS, MODE_CONFIGS };