forked from mirror/MCSM-Daemon
优化 玩家数量图表数据
This commit is contained in:
parent
d2f6bd4552
commit
c48cd42151
@ -43,41 +43,42 @@ export default class RefreshPlayer implements ILifeCycleTask {
|
|||||||
// latency: 1
|
// latency: 1
|
||||||
// }
|
// }
|
||||||
try {
|
try {
|
||||||
|
// 获取玩家人数版本等信息
|
||||||
const result = await instance.execPreset("getPlayer");
|
const result = await instance.execPreset("getPlayer");
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
instance.info.maxPlayers = result.max_players ? result.max_players : -1;
|
instance.info.maxPlayers = result.max_players ? result.max_players : -1;
|
||||||
instance.info.currentPlayers = result.current_players ? result.current_players : -1;
|
instance.info.currentPlayers = result.current_players ? result.current_players : -1;
|
||||||
instance.info.version = result.version ? result.version : "";
|
instance.info.version = result.version ? result.version : "";
|
||||||
} catch (error) { }
|
|
||||||
|
// 当第一次正确获取用户人数时,初始化玩家人数图表
|
||||||
|
if (this.playersChart.length === 0) {
|
||||||
|
this.initPlayersChart(instance);
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
// 提前填充在线人数报表数据
|
// 开启查询在线人数报表数据定时器
|
||||||
|
this.playersChartTask = setInterval(() => {
|
||||||
|
this.getPlayersChartData(instance);
|
||||||
|
}, 600000);
|
||||||
|
}
|
||||||
|
|
||||||
|
initPlayersChart(instance: Instance) {
|
||||||
while (this.playersChart.length < 60) {
|
while (this.playersChart.length < 60) {
|
||||||
this.playersChart.push({ value: "0" });
|
this.playersChart.push({ value: "0" });
|
||||||
}
|
}
|
||||||
instance.info.playersChart = this.playersChart;
|
instance.info.playersChart = this.playersChart;
|
||||||
|
this.getPlayersChartData(instance);
|
||||||
// 启动的时候先执行一次
|
|
||||||
this.getPlayersChartData(instance).then(() => { });
|
|
||||||
|
|
||||||
// 开启查询在线人数报表数据定时器
|
|
||||||
this.playersChartTask = setInterval(() => {
|
|
||||||
this.getPlayersChartData(instance).then(() => { });
|
|
||||||
}, 600000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPlayersChartData(instance: Instance) {
|
getPlayersChartData(instance: Instance) {
|
||||||
try {
|
try {
|
||||||
const result = await instance.execPreset("getPlayer");
|
this.playersChart.shift();
|
||||||
if (!result) return;
|
|
||||||
this.playersChart.push({
|
this.playersChart.push({
|
||||||
value: result.current_players ? result.current_players : 0
|
value: String(instance.info.currentPlayers) ?? "0"
|
||||||
});
|
});
|
||||||
if (this.playersChart.length > 60) {
|
|
||||||
this.playersChart = this.playersChart.slice(1, this.playersChart.length);
|
|
||||||
}
|
|
||||||
instance.info.playersChart = this.playersChart;
|
instance.info.playersChart = this.playersChart;
|
||||||
} catch (error) { }
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async stop(instance: Instance) {
|
async stop(instance: Instance) {
|
||||||
@ -87,5 +88,7 @@ export default class RefreshPlayer implements ILifeCycleTask {
|
|||||||
instance.info.currentPlayers = -1;
|
instance.info.currentPlayers = -1;
|
||||||
instance.info.version = "";
|
instance.info.version = "";
|
||||||
instance.info.playersChart = [];
|
instance.info.playersChart = [];
|
||||||
|
this.playersChart = [];
|
||||||
|
this.playersChartTask = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user