Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 69c627f

Browse files
committed
upd: 单独开定时器记录在线人数报表数据
1 parent 5ba458a commit 69c627f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/entity/commands/task/players.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default class RefreshPlayer implements ILifeCycleTask {
2727
public status: number = 0;
2828

2929
private task: any = null;
30+
private playersChartTask: any = null;
3031
private playersChart: Array<{ value: string }> = [];
3132

3233
async start(instance: Instance) {
@@ -62,13 +63,28 @@ export default class RefreshPlayer implements ILifeCycleTask {
6263
}
6364
} catch (error) { }
6465
}, 3000);
66+
67+
this.playersChartTask = setInterval(async () => {
68+
try {
69+
const result = await instance.execPreset("getPlayer");
70+
if (!result) return;
71+
this.playersChart.push({
72+
value: result.current_players ? result.current_players : 0
73+
});
74+
if (this.playersChart.length > 60) {
75+
this.playersChart = this.playersChart.slice(1, this.playersChart.length);
76+
}
77+
instance.info.playersChart = this.playersChart;
78+
} catch (error) { }
79+
}, 600000);
6580
}
6681

6782
async stop(instance: Instance) {
83+
clearInterval(this.task);
84+
clearInterval(this.playersChartTask);
6885
instance.info.maxPlayers = -1;
6986
instance.info.currentPlayers = -1;
7087
instance.info.version = "";
7188
instance.info.playersChart = [];
72-
clearInterval(this.task);
7389
}
7490
}

0 commit comments

Comments
 (0)