-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.mjs
61 lines (57 loc) · 2 KB
/
player.mjs
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
import * as alt from "alt-server";
import { acpManager } from "./index.mjs";
import { acpServerStats } from "./serverstats.mjs";
const acpPlayer = {
/**
* @description Initializes the dashboard module for the admin control panel
*/
init() {
acpPlayer.addListener();
},
/**
* @description Adds one or more listeners (get) requests to the acp manager.
*/
addListener() {
acpManager.addAcpListener("/acp/playerlist", (req, res) => {
const info = [];
alt.Player.all.forEach((p) => {
info.push({
id: p.id,
name: p.name,
socialId: p.socialId,
ip: p.ip,
ping: p.ping
});
});
res.status(200).send(JSON.stringify(info));
});
acpManager.addAcpListener("/acp/playerinfo", (req, res) => {
if (!req.query.id) {
res.sendStatus(400);
}
else {
let data = {};
alt.Player.all.forEach((p) => {
if (p.id === Number(req.query.id)) {
const connectionTime = acpServerStats.getConnectionDateForPlayerId(p.id);
data = {
id: p.id,
name: p.name,
socialId: p.socialId,
ip: p.ip,
ping: p.ping,
connected: (connectionTime) ? (new Date().getTime() - connectionTime.getTime()) / 1000 : 0,
health: p.health,
armour: p.armour,
dimension: p.dimension,
pos: p.pos,
rot: p.rot
}
}
});
res.status(200).send(JSON.stringify(data));
}
});
},
};
export { acpPlayer };