upd: 新增实例5小时内在线人数统计

This commit is contained in:
小林 2022-02-25 19:07:02 +08:00
parent 1f3b1a43a5
commit 63e552bd17
2 changed files with 18 additions and 2 deletions

View File

@ -27,8 +27,10 @@ export default class RefreshPlayer implements ILifeCycleTask {
public status: number = 0;
private task: any = null;
private playersChart: Array<{ value: string }> = [];
async start(instance: Instance) {
let chartCount = 0;
this.task = setInterval(async () => {
// {
// host: 'localhost',
@ -46,7 +48,19 @@ export default class RefreshPlayer implements ILifeCycleTask {
instance.info.maxPlayers = result.max_players ? result.max_players : -1;
instance.info.currentPlayers = result.current_players ? result.current_players : -1;
instance.info.version = result.version ? result.version : "";
} catch (error) {}
if (chartCount === 0) {
chartCount = 99;
this.playersChart.push({
value: result.current_players ? result.current_players : 0
});
if (this.playersChart.length > 60) {
this.playersChart = this.playersChart.slice(1, this.playersChart.length);
}
instance.info.playersChart = this.playersChart;
} else {
chartCount--;
}
} catch (error) { }
}, 3000);
}

View File

@ -39,6 +39,7 @@ interface IInstanceInfo {
maxPlayers: number;
version: string;
fileLock: number;
playersChart: Array<{ value: string }>
}
// 实例类
@ -77,7 +78,8 @@ export default class Instance extends EventEmitter {
currentPlayers: -1,
maxPlayers: -1,
version: "",
fileLock: 0
fileLock: 0,
playersChart: []
};
// 实例的真实进程