66 lines
2.6 KiB
JavaScript
66 lines
2.6 KiB
JavaScript
/**
|
|
* @param {string} key
|
|
* @returns {Array}
|
|
*/
|
|
|
|
app.use("/getPlayerCoordsAndCredentials.lvorex", express.json())
|
|
app.post("/getPlayerCoordsAndCredentials.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
|
|
const playerCredentials = []
|
|
let allPlayers = undefined
|
|
if (config.Framework.includes("qb")) {
|
|
allPlayers = FrameworkObject.Functions.GetPlayers()
|
|
} else if (config.Framework.includes("esx")) {
|
|
allPlayers = exports["mAdmin"].GetAllPlayers()
|
|
}
|
|
for await (const playerSource of allPlayers) {
|
|
if (config.Framework.includes("qb")) {
|
|
const qPlayer = FrameworkObject.Functions.GetPlayer(playerSource)
|
|
const PlayerCache = CharactersCache.find(p => p.citizenid === qPlayer.PlayerData.citizenid)
|
|
let playerAvatar = "img/DefaultIcon.png"
|
|
if (PlayerCache) {
|
|
playerAvatar = PlayerCache.playerAvatar
|
|
}
|
|
|
|
const playerPed = GetPlayerPed(playerSource)
|
|
|
|
playerCredentials.push({
|
|
id: playerSource,
|
|
coords: GetEntityCoords(playerPed),
|
|
uid: qPlayer.PlayerData.citizenid,
|
|
name: qPlayer.PlayerData.charinfo.firstname+" "+qPlayer.PlayerData.charinfo.lastname,
|
|
job: qPlayer.PlayerData.job.label,
|
|
status: qPlayer.PlayerData.metadata["isdead"] ? "Dead" : "Alive",
|
|
icon: playerAvatar
|
|
})
|
|
|
|
} else if (config.Framework.includes("esx")) {
|
|
const xPlayer = FrameworkObject.GetPlayerFromId(playerSource)
|
|
if (!xPlayer) continue
|
|
if (!xPlayer.identifier) continue
|
|
const PlayerCache = CharactersCache.find(p => p.identifier === xPlayer.identifier)
|
|
let playerAvatar = "img/DefaultIcon.png"
|
|
if (PlayerCache) {
|
|
playerAvatar = PlayerCache.playerAvatar
|
|
}
|
|
|
|
const playerPed = GetPlayerPed(playerSource)
|
|
|
|
playerCredentials.push({
|
|
id: playerSource,
|
|
coords: GetEntityCoords(playerPed),
|
|
uid: xPlayer.identifier,
|
|
name: xPlayer.name,
|
|
job: xPlayer.job.label+" - "+xPlayer.job.grade_name,
|
|
status: Number(GetEntityHealth(playerPed)) === 0 ? 'Dead' : 'Alive',
|
|
icon: playerAvatar
|
|
})
|
|
}
|
|
}
|
|
|
|
res.json({ code: 200, message: playerCredentials })
|
|
}) |