803 lines
34 KiB
JavaScript
803 lines
34 KiB
JavaScript
function AssignJob(currentJob) {
|
|
if (currentJob === config.JobCodes.police) return "police"
|
|
if (currentJob === config.JobCodes.ems) return "ems"
|
|
if (config.JobCodes.mechanics.some(m => m === currentJob)) return "mechanic"
|
|
return "unemployed"
|
|
}
|
|
|
|
app.use("/getCharacters.lvorex", express.json())
|
|
app.post("/getCharacters.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
let PermissionCheck = undefined
|
|
if (postBody.page === "Players") {
|
|
PermissionCheck = await checkPermission(userKey.rank, "Players", 0)
|
|
} else if (postBody.page === "Admins") {
|
|
PermissionCheck = await checkPermission(userKey.rank, "Admins", 0)
|
|
}
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const uidType = config.Framework.includes("qb") ? "citizenid" : "identifier"
|
|
const onlinePlayers = await getOnlinePlayers()
|
|
const ForPlayersList = []
|
|
CharactersCache.map(c => {
|
|
let newC = c
|
|
const oPlayer = onlinePlayers.find(p => p[uidType] === c[uidType])
|
|
if (oPlayer) {
|
|
if (config.Framework.includes("qb")) {
|
|
const Permissions = FrameworkObject.Functions.GetPermission(oPlayer.playerId)
|
|
if (Permissions.length !== 0) {
|
|
const LastPerm = Object.entries(Permissions).map(w => { return w[0] }).join(", ")
|
|
newC.admin = LastPerm
|
|
}
|
|
newC.job = `{"name": "${oPlayer.job.name}", "label": "${oPlayer.job.label}", "grade": {"name": "${oPlayer.job.grade.name}"}}`
|
|
} else {
|
|
const xPlayer = FrameworkObject.GetPlayerFromId(oPlayer.playerId)
|
|
|
|
newC.job = xPlayer.job.name
|
|
newC.job_grade = xPlayer.job.grade
|
|
|
|
const group = xPlayer.getGroup()
|
|
if (config.Permissions.some(p => group === p)) {
|
|
if (group !== null && group) newC.admin = group
|
|
}
|
|
}
|
|
newC.playerId = oPlayer.playerId,
|
|
newC.playerStatus = "Online"
|
|
} else {
|
|
newC.playerId = "-"
|
|
newC.playerStatus = "Offline"
|
|
}
|
|
|
|
if (postBody.page === "Players") {
|
|
const listPlayer = {}
|
|
let JobJson = undefined
|
|
if (config.Framework.includes("qb")) {
|
|
JobJson = JSON.parse(newC.job)
|
|
}
|
|
listPlayer.id = newC.playerId
|
|
listPlayer.inGameName = config.Framework.includes("qb") ? `${JSON.parse(newC.charinfo).firstname} ${JSON.parse(newC.charinfo).lastname}` : `${newC.firstname} ${newC.lastname}`
|
|
listPlayer.name = config.Framework.includes("qb") ? newC.name : `${newC.firstname} ${newC.lastname}`
|
|
listPlayer.job = config.Framework.includes("qb") ? JobJson.name : newC.job
|
|
listPlayer.grade = config.Framework.includes("qb") ? JobJson.label + " - " + JobJson.grade.name : newC.job + " - " + newC.job_grade
|
|
listPlayer.date = config.Framework.includes("qb") ? moment(JSON.parse(newC.charinfo).birthdate, "YYYY-MM-DD").format("DD.MM.YYYY") : moment(newC.dateofbirth, "YYYY-MM-DD").format("DD.MM.YYYY")
|
|
listPlayer.time = newC.onlineTime ?? "Not Detected."
|
|
listPlayer.male = config.Framework.includes("qb") ? JSON.parse(newC.charinfo).gender === 0 ? "Male" : "Female" : newC.sex === "m" ? "Male" : "Female"
|
|
listPlayer.status = newC.playerStatus
|
|
listPlayer.icon = newC.playerAvatar ?? "img/DefaultIcon.png"
|
|
listPlayer.uid = newC[uidType]
|
|
ForPlayersList.push(listPlayer)
|
|
}
|
|
return newC
|
|
})
|
|
|
|
let result = CharactersCache
|
|
|
|
res.json({ code: 200, message: JSON.stringify({
|
|
identifier: config.Framework.includes("qb") ? "citizenid" : "identifier",
|
|
players: postBody.page === "Players" ? ForPlayersList : result
|
|
}) })
|
|
})
|
|
|
|
app.use("/getAllItems.lvorex", express.json())
|
|
app.post("/getAllItems.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Players", 16)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const items = LV.GetAllItems()
|
|
|
|
res.json({ code: 200, message: JSON.stringify(items) })
|
|
})
|
|
|
|
async function getPlayerBlackMoney(playerId, uid, res) {
|
|
if (config.BlackMoney.Type === "none") return 0
|
|
|
|
if (config.Framework.includes("qb")) {
|
|
const qPlayer = FrameworkObject.Functions.GetPlayer(Number(playerId))
|
|
|
|
if (config.BlackMoney.Type === "with-item") {
|
|
if (qPlayer) {
|
|
const blackMoneyItems = qPlayer.Functions.GetItemsByName(config.BlackMoney.Object)
|
|
let blackMoneyCount = 0
|
|
if (blackMoneyItems.length === 0) return 0
|
|
if (!blackMoneyItems) return 0
|
|
|
|
blackMoneyItems.forEach(item => {
|
|
blackMoneyCount = blackMoneyCount + Number(item.amount)
|
|
})
|
|
|
|
return blackMoneyCount
|
|
} else {
|
|
const playerInventory = await LV.GetPlayerInventoryItems(false, uid)
|
|
let blackMoneyCount = 0
|
|
playerInventory.forEach(item => {
|
|
if (item.name === config.BlackMoney.Object) {
|
|
blackMoneyCount = blackMoneyCount + Number(item.count)
|
|
}
|
|
})
|
|
|
|
return blackMoneyCount
|
|
}
|
|
} else if (config.BlackMoney.Type === "without-item") {
|
|
if (qPlayer) {
|
|
const blackMoneyCount = qPlayer.PlayerData.money[config.BlackMoney.Object] ?? 0
|
|
return blackMoneyCount
|
|
} else {
|
|
let result = await query(`SELECT * FROM \`players\` WHERE \`citizenid\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
result = result [0]
|
|
|
|
const playerMoneyJson = JSON.parse(result.money)
|
|
return playerMoneyJson.blackmoney ?? 0
|
|
}
|
|
}
|
|
} else if (config.Framework.includes("esx")) {
|
|
const xPlayer = FrameworkObject.GetPlayerFromId(Number(playerId))
|
|
|
|
if (config.BlackMoney.Type === "with-item") {
|
|
if (xPlayer) {
|
|
const blackMoneyItems = xPlayer.getInventoryItem(config.BlackMoney.Object)
|
|
let blackMoneyCount = blackMoneyItems ? blackMoneyItems.count : 0
|
|
return blackMoneyCount
|
|
} else {
|
|
let result = await query(`select * from \`users\` where \`identifier\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
result = result[0]
|
|
|
|
const playerInventory = JSON.parse(result.inventory)
|
|
let blackMoneyCount = 0
|
|
Object.entries(playerInventory).forEach(([k,v]) => {
|
|
if (k === config.BlackMoney.Object) {
|
|
blackMoneyCount = blackMoneyCount + Number(v)
|
|
}
|
|
})
|
|
|
|
return blackMoneyCount
|
|
}
|
|
} else {
|
|
if (xPlayer) {
|
|
const blackMoneyCount = xPlayer.accounts.find(a => a.name === config.BlackMoney.Object).money
|
|
return blackMoneyCount
|
|
} else {
|
|
let result = await query(`select * from \`users\` where \`identifier\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
result = result[0]
|
|
|
|
return JSON.parse(result.accounts)[config.BlackMoney.Object]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async function getSocietyMoney(job) {
|
|
if (config.Society.System === false) return 0
|
|
|
|
if (config.Framework.includes("esx")) {
|
|
let result = await query(`
|
|
select * from \`addon_account_data\`
|
|
where \`account_name\` = 'society_${job}'
|
|
`)
|
|
if (result.length === 0) return undefined
|
|
result = result[0]
|
|
|
|
return result.money
|
|
}
|
|
|
|
const societyAccount = LV.Society.GetAccountMoney(job)
|
|
return societyAccount
|
|
}
|
|
|
|
app.use("/getSpecificCharacter.lvorex", express.json())
|
|
app.post("/getSpecificCharacter.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
let PermissionCheck = await checkPermission(userKey.rank, "Players", 1)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
let result = await query(`SELECT * FROM \`${config.Framework.includes("qb") ? "players" : "users"}\` WHERE \`${config.Framework.includes("qb") ? "citizenid" : "identifier"}\` = '${postBody.uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
|
|
const onlinePlayers = await getOnlinePlayers()
|
|
|
|
const uidType = config.Framework.includes("qb") ? "citizenid" : "identifier"
|
|
const oPlayer = onlinePlayers.find(oPlayer => oPlayer[uidType] === result[0][uidType])
|
|
result[0].playerStatus = oPlayer ? "Online" : "Offline"
|
|
result[0].playerId = oPlayer ? oPlayer.playerId : "-"
|
|
result[0].fullName = config.Framework.includes("qb") ? JSON.parse(result[0].charinfo).firstname + " " + JSON.parse(result[0].charinfo).lastname : result[0].firstname + " " + result[0].lastname
|
|
let OtherPermCheck = await checkPermission(userKey.rank, "Players", 4)
|
|
|
|
if (oPlayer) {
|
|
const qPlayer = config.Framework.includes("qb") ? FrameworkObject.Functions.GetPlayer(oPlayer.playerId) : FrameworkObject.GetPlayerFromId(oPlayer.playerId)
|
|
if (qPlayer) {
|
|
const OtherPermCheck = await checkPermission(userKey.rank, "Players", 4)
|
|
if (OtherPermCheck) {
|
|
oPlayer.job = config.Framework.includes("qb") ? qPlayer.PlayerData.job : qPlayer.job
|
|
oPlayer.faction = config.Framework.includes("qb") ? qPlayer.PlayerData.gang : "Not Found."
|
|
oPlayer.societyMoney = await getSocietyMoney(config.Framework.includes("qb") ? qPlayer.PlayerData.job.name : qPlayer.job.name)
|
|
}
|
|
}
|
|
if (config.Framework.includes("esx")) {
|
|
oPlayer.sex = oPlayer.variables.sex
|
|
oPlayer.phone_number = await LV.GetPlayerPhoneNumber()
|
|
oPlayer.created_at = result[0].created_at
|
|
oPlayer.dateofbirth = oPlayer.variables.dateofbirth
|
|
oPlayer.firstname = oPlayer.name.split(" ")[0]
|
|
oPlayer.lastname = oPlayer.name.split(" ")[1]
|
|
}
|
|
oPlayer.playerStatus = "Online"
|
|
const OtherPermCheck = await checkPermission(userKey.rank, "Players", 10)
|
|
if (OtherPermCheck) {
|
|
const blackMoneyCount = await getPlayerBlackMoney(oPlayer.playerId, "", res)
|
|
oPlayer.blackMoneyCount = blackMoneyCount
|
|
}
|
|
|
|
result[0].discordId = getPlayerIdentifierByType(oPlayer.playerId, "discord")
|
|
if (OtherPermCheck) {
|
|
result[0].steamId = getPlayerIdentifierByType(oPlayer.playerId, "steam")
|
|
result[0].licenseId = getPlayerIdentifierByType(oPlayer.playerId, "license")
|
|
}
|
|
|
|
if (!OtherPermCheck) {
|
|
result[0].discordId = "undefined"
|
|
}
|
|
} else {
|
|
let OtherPermCheck = await checkPermission(userKey.rank, "Players", 10)
|
|
if (OtherPermCheck) {
|
|
result[0].blackMoneyCount = await getPlayerBlackMoney(undefined, result[0][uidType], res)
|
|
}
|
|
OtherPermCheck = await checkPermission(userKey.rank, "Players", 4)
|
|
if (OtherPermCheck) {
|
|
result[0].societyMoney = await getSocietyMoney(config.Framework.includes("qb") ? JSON.parse(result[0].job).name : result[0].job)
|
|
}
|
|
|
|
if (config.Framework.includes("esx")) {
|
|
let esxJobLabel = await query(`select * from \`jobs\` where \`name\` = '${result[0].job}'`)
|
|
if (esxJobLabel === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
esxJobLabel = esxJobLabel[0].label
|
|
|
|
let esxJobGradeLabel = await query(`
|
|
select * from \`job_grades\`
|
|
where \`job_name\` = '${result[0].job}'
|
|
and \`grade\` = ${result[0].job_grade}
|
|
`)
|
|
esxJobGradeLabel = esxJobGradeLabel[0].label
|
|
|
|
let newJson = {
|
|
label: esxJobLabel,
|
|
grade_label: esxJobGradeLabel,
|
|
name: result[0].job,
|
|
grade: result[0].job_grade
|
|
}
|
|
|
|
result[0].job = newJson
|
|
}
|
|
}
|
|
|
|
result[0].playerAvatar = "img/DefaultIcon.png"
|
|
if (oPlayer) {
|
|
oPlayer.playerAvatar = "img/DefaultIcon.png"
|
|
}
|
|
|
|
// let dcResult = await query(`SELECT * FROM \`madmin_characters\` WHERE \`identifier\` = '${result[0][uidType]}'`)
|
|
let dcResult = await query(`select * from \`madmin_characters\` where \`license\` like '%${result[0][config.Framework.includes("qb") ? "license" : "identifier"].split(":")[1]}'`)
|
|
if (dcResult === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (dcResult.length > 0) {
|
|
let cins = "ms"
|
|
let sure = Number(dcResult[0].online_time)
|
|
|
|
if (sure > 1000 && sure < 1000 * 60) {
|
|
cins = "s"
|
|
sure = sure / 1000
|
|
} else if (sure > 1000 * 60 && sure < 1000 * 60 * 60) {
|
|
cins = "mn"
|
|
sure = sure / (1000 * 60)
|
|
} else if (sure > 1000 * 60 * 60) {
|
|
cins = "hr"
|
|
sure = sure / (1000 * 60 * 60)
|
|
}
|
|
|
|
sure = parseInt(String(sure))
|
|
|
|
result[0].discordId = dcResult[0].discord
|
|
|
|
if (OtherPermCheck) {
|
|
result[0].steamId = dcResult[0].steam
|
|
result[0].licenseId = dcResult[0].license
|
|
result[0].onlineTime = `${sure}${cins}`
|
|
}
|
|
|
|
if (oPlayer && OtherPermCheck) {
|
|
oPlayer.discordId = dcResult[0].discord
|
|
oPlayer.steamId = dcResult[0].steam
|
|
oPlayer.licenseId = dcResult[0].license
|
|
oPlayer.onlineTime = `${sure}${cins}`
|
|
}
|
|
|
|
if (result[0].discordId !== "undefined") {
|
|
result[0].playerAvatar = dcResult[0].discord_avatar
|
|
if (oPlayer) {
|
|
oPlayer.playerAvatar = dcResult[0].discord_avatar
|
|
}
|
|
}
|
|
|
|
if (!OtherPermCheck) {
|
|
result[0].discordId = "undefined"
|
|
}
|
|
} else {
|
|
if (OtherPermCheck) {
|
|
result[0].licenseId = "license:"+result[0][config.Framework.includes("qb") ? "license" : "identifier"].split(":")[1]
|
|
}
|
|
|
|
if (oPlayer && OtherPermCheck) {
|
|
oPlayer.licenseId = "license:"+result[0][config.Framework.includes("qb") ? "license" : "identifier"].split(":")[1]
|
|
}
|
|
}
|
|
|
|
PermissionCheck = await checkPermission(userKey.rank, "Players", 4)
|
|
if (!PermissionCheck) {
|
|
if (oPlayer) { oPlayer.charinfo = undefined } else { result[0].charinfo = undefined }
|
|
}
|
|
|
|
res.json({ code: 200, message: JSON.stringify({
|
|
identifier: config.Framework.includes("qb") ? "citizenid" : "identifier",
|
|
player: oPlayer ?? result[0]
|
|
}) })
|
|
})
|
|
|
|
app.use("/getOnlinePlayers.lvorex", express.json())
|
|
app.post("/getOnlinePlayers.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 toSendPlayer = []
|
|
const onlinePlayers = await getOnlinePlayers()
|
|
let uidType = "citizenid"
|
|
if (config.Framework.includes("esx")) {
|
|
uidType = "identifier"
|
|
}
|
|
|
|
async function CheckAdminStatus(player) {
|
|
if (config.Framework.includes("qb")) {
|
|
const Permissions = FrameworkObject.Functions.GetPermission(player.playerId)
|
|
if (!Permissions.length) return true
|
|
} else {
|
|
const Permission = config.Permissions.some(p => p === player.group)
|
|
if (Permission) return true
|
|
}
|
|
|
|
let dcResult = await query(`SELECT * FROM \`madmin_characters\` WHERE \`identifier\` = '${player[uidType]}'`)
|
|
if (dcResult === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
let Result = false
|
|
if (dcResult.length > 0) {
|
|
if (
|
|
IsPrincipalAceAllowed(`identifier.${config.AceIdentifier}:${dcResult[0][config.AceIdentifier].split(":")[1]}`, `command`)
|
|
) {
|
|
Result = true
|
|
}
|
|
}
|
|
|
|
return Result
|
|
}
|
|
|
|
if (config.Framework.includes("qb")) {
|
|
for await (const player of onlinePlayers) {
|
|
const AdminState = await CheckAdminStatus(player)
|
|
toSendPlayer.push({
|
|
id: player.playerId,
|
|
name: player.charinfo.firstname+" "+player.charinfo.lastname,
|
|
job: player.job.name,
|
|
assignjob: AssignJob(player.job.name),
|
|
uid: player.citizenid,
|
|
admin: AdminState
|
|
})
|
|
}
|
|
} else if (config.Framework.includes("esx")) {
|
|
for await(const player of onlinePlayers) {
|
|
const AdminState = await CheckAdminStatus(player)
|
|
toSendPlayer.push({
|
|
id: player.playerId,
|
|
name: player.name,
|
|
job: player.job.name,
|
|
assignjob: AssignJob(player.job.name),
|
|
uid: player.identifier,
|
|
admin: AdminState
|
|
})
|
|
}
|
|
}
|
|
|
|
res.json({ code: 200, message: toSendPlayer, peakcount: PeakPlayerCount })
|
|
})
|
|
|
|
app.use("/getPlayerBanStatus.lvorex", express.json())
|
|
app.post("/getPlayerBanStatus.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 NeededPlayer = await checkPlayerIsOnline(postBody.uid, res, true)
|
|
if (NeededPlayer) return res.json({ code: 200, message: undefined })
|
|
|
|
let result = await query(`
|
|
SELECT * FROM \`madmin_bans\`
|
|
WHERE \`license\` LIKE '%${postBody.license}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (result.length === 0) return res.json({ code: 200, message: undefined })
|
|
result = result [0]
|
|
|
|
if (Number(result.endTime) !== 0) return res.json({ code: 200, message: undefined })
|
|
res.json({ code: 200, message: {
|
|
bannedAt: moment(Number(result.bannedAt)).format("DD/MM/YYYY"),
|
|
bannedBy: result.bannedBy
|
|
} })
|
|
})
|
|
|
|
app.use("/getPlayerActionLogs.lvorex", express.json())
|
|
app.post("/getPlayerActionLogs.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Players", 19)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
let result = await query(`
|
|
SELECT * FROM \`madmin_logs\`
|
|
WHERE \`type\` != 'status'
|
|
AND \`type\` != 'money'
|
|
AND \`player_uid\` = '${postBody.uid}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (result.length === 0) return res.json({ code: 200, message: [] })
|
|
|
|
let toResponse = {
|
|
warn: [],
|
|
kick: [],
|
|
adminjail: [],
|
|
ban: [],
|
|
item: [],
|
|
death: [],
|
|
kill: []
|
|
}
|
|
|
|
result.forEach(log => {
|
|
toResponse[log.type].push({
|
|
id: log.id,
|
|
desc: log.message,
|
|
staff: log.author,
|
|
date: log.date,
|
|
count: Number(log.count) !== 0 ? (Number(log.count) / 1000 / 60)+" minutes" : undefined,
|
|
active: Number(log.count) !== 0 ? log.cancelled === 0 ? Date.now() - (Number(moment(log.date, "DD.MM.YYYY HH:mm:ss").format("x")) + Number(log.count)) <= 0 ? true : false : undefined : undefined
|
|
})
|
|
})
|
|
|
|
Object.entries(toResponse).forEach(([key, index]) => {
|
|
toResponse[key].sort((a,b) => moment(b.date, 'DD.MM.YYYY') - moment(a.date, 'DD.MM.YYYY HH:mm:ss'))
|
|
})
|
|
|
|
res.json({ code: 200, message: toResponse })
|
|
})
|
|
|
|
app.use("/getDeletedCharacters.lvorex", express.json())
|
|
app.post("/getDeletedCharacters.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 uidType = config.Framework.includes("qb") ? "citizenid" : "identifier"
|
|
let result = await query(`SELECT * FROM \`madmin_deletedchars\``)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (result.length === 0) return res.json({ code: 200, message: [] })
|
|
|
|
for await (const player of result) {
|
|
player.playerId = "-"
|
|
player.playerStatus = "Offline"
|
|
|
|
let dcResult = await query(`SELECT * FROM \`madmin_characters\` WHERE \`identifier\` = '${player[uidType]}'`)
|
|
if (dcResult === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (dcResult.length > 0) {
|
|
let cins = "ms"
|
|
let sure = Number(dcResult[0].online_time)
|
|
|
|
if (sure > 1000 && sure < 1000 * 60) {
|
|
cins = "s"
|
|
sure = sure / 1000
|
|
} else if (sure > 1000 * 60 && sure < 1000 * 60 * 60) {
|
|
cins = "mn"
|
|
sure = sure / (1000 * 60)
|
|
} else if (sure > 1000 * 60 * 60) {
|
|
cins = "hr"
|
|
sure = sure / (1000 * 60 * 60)
|
|
}
|
|
|
|
sure = parseInt(String(sure))
|
|
|
|
player.onlineTime = `${sure}${cins}`
|
|
|
|
player.discordId = dcResult[0].discord
|
|
if (player.discordId !== "undefined") {
|
|
let avatarRequest = await fetch(`https://discord.com/api/v9/users/${player.discordId.split(":")[1]}`, {
|
|
headers: {
|
|
"authorization": `Bot ${config.token}`
|
|
}
|
|
})
|
|
avatarRequest = await avatarRequest.json()
|
|
player.playerAvatar = `https://cdn.discordapp.com/avatars/${player.discordId.split(":")[1]}/${avatarRequest.avatar}.png`
|
|
}
|
|
}
|
|
}
|
|
|
|
res.json({ code: 200, message: JSON.stringify({
|
|
identifier: config.Framework.includes("qb") ? "citizenid" : "identifier",
|
|
players: result
|
|
}) })
|
|
})
|
|
|
|
app.use("/getAccounts.lvorex", express.json())
|
|
app.post("/getAccounts.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Accounts", 0)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const accounts = []
|
|
for await (const character of CharactersCache) {
|
|
let characterLicense = character[config.Framework.includes("qb") ? "license" : "identifier"].split(":")[1]
|
|
|
|
if (accounts.length > 0) {
|
|
const findAccount = accounts.find(w => w.license.split(":")[1] === characterLicense)
|
|
if (findAccount) {
|
|
const qPlayer = await getPlayerByLicense(character[config.Framework.includes("qb") ? "license" : "identifier"])
|
|
if (qPlayer) {
|
|
findAccount.status = "Online"
|
|
findAccount.currentCharacter = config.Framework.includes("qb")
|
|
? qPlayer.charinfo.firstname + " " + qPlayer.charinfo.lastname
|
|
: qPlayer.name
|
|
}
|
|
|
|
findAccount.characterCount = findAccount.characterCount + 1
|
|
if (moment(findAccount.lastOnline).format("x") < moment(character.lastOnline).format("x")) {
|
|
findAccount.lastOnline = character[config.Framework.includes("qb") ? "last_updated" : "last_seen"]
|
|
}
|
|
continue
|
|
}
|
|
}
|
|
|
|
const newAccount = {
|
|
name: config.Framework.includes("qb") ? character.name : character.firstname+" "+character.lastname, // +
|
|
icon: "img/DefaultIcon.png", // +
|
|
license: "license:"+characterLicense, // +
|
|
characterCount: 1, // +
|
|
discordId: "Not found.", // +
|
|
playTime: "", // +
|
|
status: "", // +
|
|
currentCharacter: "", // +
|
|
lastOnline: config.Framework.includes("qb") ? character.last_updated : character.last_seen, // +
|
|
banned: false
|
|
}
|
|
|
|
result = await query(`
|
|
SELECT * FROM \`madmin_bans\`
|
|
WHERE \`license\` LIKE '%${characterLicense}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared" })
|
|
if (result.length !== 0) {
|
|
newAccount.banned = true
|
|
newAccount.endtime = result[0].endTime === 0 ? 'Perma Banned' : `End Time: ${moment(result[0].endTime).format("DD.MM.YYYY")}`
|
|
}
|
|
|
|
let dcResult = await query(`SELECT * FROM \`madmin_characters\` WHERE \`license\` LIKE '%${characterLicense}'`)
|
|
if (dcResult === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (dcResult.length !== 0) {
|
|
newAccount.name = character.playerName
|
|
if (character.discordId !== "undefined") {
|
|
newAccount.icon = character.playerAvatar
|
|
newAccount.discordId = character.discordId
|
|
newAccount.playTime = character.onlineTime
|
|
}
|
|
}
|
|
|
|
const qPlayer = await getPlayerByLicense(character[config.Framework.includes("qb") ? "license" : "identifier"])
|
|
newAccount.status = qPlayer ? "Online" : "Offline"
|
|
if (qPlayer) {
|
|
if (config.Framework.includes("qb")) {
|
|
// result = await query(`
|
|
// SELECT * FROM \`players\`
|
|
// WHERE \`citizenid\` = '${qPlayer.citizenid}'
|
|
// `)
|
|
// if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
// result = result [0]
|
|
// const charInfo = JSON.parse(result.charinfo)
|
|
newAccount.currentCharacter = qPlayer.charinfo.firstname + " " + qPlayer.charinfo.lastname
|
|
} else if (config.Framework.includes("esx")) {
|
|
// result = await query(`
|
|
// select * from \`users\`
|
|
// where \`identifier\` = '${qPlayer.identifier}'
|
|
// `)
|
|
// if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
// result = result [0]
|
|
newAccount.currentCharacter = qPlayer.name
|
|
}
|
|
}
|
|
|
|
accounts.push(newAccount)
|
|
}
|
|
|
|
res.json({ code: 200, message: accounts })
|
|
})
|
|
|
|
app.use("/getPlayerCharacters.lvorex", express.json())
|
|
app.post("/getPlayerCharacters.lvorex", async (req, res) => {
|
|
const postBody = req.body
|
|
const { keyFound, userKey } = await controlKey(req, postBody.key)
|
|
|
|
if (keyFound === false) return res.json({ code: 404, message: "Not authorized." })
|
|
const PermissionCheck = await checkPermission(userKey.rank, "Accounts", 1)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const characters = []
|
|
|
|
if (config.Framework.includes("qb")) {
|
|
let result = await query(`
|
|
SELECT * FROM \`players\`
|
|
WHERE \`license\` LIKE '%${postBody.license.split(":")[1]}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
for await (const character of result) {
|
|
const NeededPlayer = await checkPlayerIsOnline(character.citizenid, res, true)
|
|
const newCharacter = {
|
|
id: "-",
|
|
name: "",
|
|
job: "",
|
|
lastOnline: "",
|
|
playTime: "",
|
|
status: "Offline",
|
|
uid: character.citizenid
|
|
}
|
|
if (NeededPlayer) {
|
|
newCharacter.id = NeededPlayer.playerId
|
|
newCharacter.status = "Online"
|
|
newCharacter.name = NeededPlayer.charinfo.firstname + " " + NeededPlayer.charinfo.lastname
|
|
newCharacter.job = NeededPlayer.job.label + " - " + NeededPlayer.job.grade.name
|
|
newCharacter.lastOnline = Date.now()
|
|
} else {
|
|
const charInfo = JSON.parse(character.charinfo)
|
|
const jobCredits = JSON.parse(character.job)
|
|
|
|
newCharacter.name = charInfo.firstname + " " + charInfo.lastname
|
|
newCharacter.job = jobCredits.label + " - " + jobCredits.grade.name
|
|
newCharacter.lastOnline = character.last_updated
|
|
}
|
|
|
|
result = await query(`
|
|
SELECT * FROM \`madmin_characters\`
|
|
WHERE \`identifier\` = '${character.citizenid}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (result.length === 0) {
|
|
newCharacter.playTime = "0mn"
|
|
} else {
|
|
result = result [0]
|
|
let cins = "ms"
|
|
let sure = Number(result.online_time)
|
|
|
|
if (sure > 1000 && sure < 1000 * 60) {
|
|
cins = "s"
|
|
sure = sure / 1000
|
|
} else if (sure > 1000 * 60 && sure < 1000 * 60 * 60) {
|
|
cins = "mn"
|
|
sure = sure / (1000 * 60)
|
|
} else if (sure > 1000 * 60 * 60) {
|
|
cins = "hr"
|
|
sure = sure / (1000 * 60 * 60)
|
|
}
|
|
|
|
sure = parseInt(String(sure))
|
|
newCharacter.playTime = `${sure}${cins}`
|
|
}
|
|
|
|
characters.push(newCharacter)
|
|
}
|
|
} else if (config.Framework.includes("esx")) {
|
|
let result = await query(`
|
|
select * from \`users\`
|
|
where \`identifier\` like '%${postBody.license.split(":")[1]}%'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
for await (const character of result) {
|
|
const NeededPlayer = await checkPlayerIsOnline(character.identifier, res, true)
|
|
const newCharacter = {
|
|
id: "-",
|
|
name: "",
|
|
job: "",
|
|
lastOnline: "",
|
|
playTime: "",
|
|
status: "Offline",
|
|
uid: character.identifier
|
|
}
|
|
|
|
if (NeededPlayer) {
|
|
newCharacter.id = NeededPlayer.playerId
|
|
newCharacter.status = "Online"
|
|
newCharacter.name = NeededPlayer.name
|
|
newCharacter.job = NeededPlayer.job.label + " - " + NeededPlayer.job.grade.name
|
|
newCharacter.lastOnline = Date.now()
|
|
} else {
|
|
const AllJobs = FrameworkObject.GetJobs()
|
|
const CurrentJob = AllJobs[character.job]
|
|
|
|
newCharacter.name = character.firstname + " " + character.lastname
|
|
newCharacter.job = CurrentJob.label + " - " + CurrentJob.grades[character.job_grade].label
|
|
newCharacter.lastOnline = character.last_seen
|
|
}
|
|
|
|
result = await query(`
|
|
SELECT * FROM \`madmin_characters\`
|
|
WHERE \`identifier\` = '${character.identifier}'
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (result.length === 0) {
|
|
newCharacter.playTime = "0mn"
|
|
} else {
|
|
result = result [0]
|
|
let cins = "ms"
|
|
let sure = Number(result.online_time)
|
|
|
|
if (sure > 1000 && sure < 1000 * 60) {
|
|
cins = "s"
|
|
sure = sure / 1000
|
|
} else if (sure > 1000 * 60 && sure < 1000 * 60 * 60) {
|
|
cins = "mn"
|
|
sure = sure / (1000 * 60)
|
|
} else if (sure > 1000 * 60 * 60) {
|
|
cins = "hr"
|
|
sure = sure / (1000 * 60 * 60)
|
|
}
|
|
|
|
sure = parseInt(String(sure))
|
|
newCharacter.playTime = `${sure}${cins}`
|
|
}
|
|
|
|
characters.push(newCharacter)
|
|
}
|
|
}
|
|
|
|
res.json({ code: 200, message: characters })
|
|
})
|
|
|
|
app.use("/getBlacklistedAccounts.lvorex", express.json())
|
|
app.post("/getBlacklistedAccounts.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." })
|
|
|
|
let result = await query(`
|
|
SELECT * FROM \`madmin_blacklist\`
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
|
|
const blacklistedAccounts = []
|
|
result.forEach(account => {
|
|
blacklistedAccounts.push({
|
|
name: account.name,
|
|
license: account.license
|
|
})
|
|
})
|
|
|
|
res.json({ code: 200, message: blacklistedAccounts })
|
|
}) |