234 lines
12 KiB
JavaScript
234 lines
12 KiB
JavaScript
app.use("/getPlayerMetadata.lvorex", express.json())
|
|
app.post("/getPlayerMetadata.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", 8)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
const playerHealth = GetEntityHealth(GetPlayerPed(Number(postBody.playerId)))
|
|
|
|
if (config.Framework.includes("qb")) {
|
|
const qPlayer = FrameworkObject.Functions.GetPlayer(Number(postBody.playerId))
|
|
if (!qPlayer) return res.json({ code: 404, message: "Player offline." })
|
|
|
|
const metadata = qPlayer.PlayerData.metadata
|
|
|
|
res.json({
|
|
health: parseInt(String(Number(playerHealth) / 2)),
|
|
hunger: parseInt(metadata.hunger),
|
|
thirst: parseInt(metadata.thirst),
|
|
stress: parseInt(metadata.stress),
|
|
armor: parseInt(metadata.armor)
|
|
})
|
|
} else if (config.Framework.includes("esx")) {
|
|
const xPlayer = FrameworkObject.GetPlayerFromId(Number(postBody.playerId))
|
|
if (!xPlayer) return res.json({ code: 404, message: "Player offline." })
|
|
const hunger = xPlayer.variables.status.find(s => s.name === "hunger")
|
|
const thirst = xPlayer.variables.status.find(s => s.name === "thirst")
|
|
const stress = xPlayer.variables.status.find(s => s.name === "drunk")
|
|
|
|
res.json({
|
|
health: parseInt(String(Number(playerHealth) / 2)),
|
|
hunger: parseInt(hunger ? hunger.percent : 0),
|
|
thirst: parseInt(thirst ? thirst.percent : 0),
|
|
stress: parseInt(stress ? stress.percent : 0),
|
|
armor: parseInt(GetPedArmour(GetPlayerPed(Number(postBody.playerId))))
|
|
})
|
|
}
|
|
})
|
|
|
|
async function changeCharacterName(newName, uid, res) {
|
|
if (config.Framework.includes("qb")) {
|
|
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]
|
|
|
|
let newCharInfo = JSON.parse(result.charinfo)
|
|
newCharInfo.firstname = newName.split(" ")[0]
|
|
newCharInfo.lastname = newName.split(" ")[1]
|
|
|
|
result = await query(`UPDATE \`players\` SET \`charinfo\` = '${JSON.stringify(newCharInfo)}' WHERE \`citizenid\` = '${uid}'`)
|
|
} else if (config.Framework.includes("esx")) {
|
|
let result = await query(`UPDATE \`users\` SET \`firstname\` = '${newName.split(" ")[0]}', \`lastname\` = '${newName.split(" ")[1]}' WHERE \`identifier\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
}
|
|
|
|
res.json({ code: 200, message: "Updated." })
|
|
}
|
|
|
|
async function changeCharacterGender(newGender, uid, res) {
|
|
if (config.Framework.includes("qb")) {
|
|
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]
|
|
|
|
let newCharInfo = JSON.parse(result.charinfo)
|
|
newCharInfo.gender = newGender === "Male" ? 0 : 1
|
|
|
|
result = await query(`UPDATE \`players\` SET \`charinfo\` = '${JSON.stringify(newCharInfo)}' WHERE \`citizenid\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
} else if (config.Framework.includes("esx")) {
|
|
let result = await query(`UPDATE \`users\` SET \`sex\` = '${newGender === "Male" ? "m" : "f"}' WHERE \`identifier\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
}
|
|
|
|
res.json({ code: 200, message: "Updated." })
|
|
}
|
|
|
|
async function changeCharacterBirthday(newDate, uid, res) {
|
|
if (newDate.length !== 10) return res.json({ code: 404, message: "Please use right syntax." })
|
|
if (config.Framework.includes("qb")) {
|
|
const toInsertDate = `${newDate.split(".")[2]}-${newDate.split(".")[1]}-${newDate.split(".")[0]}`
|
|
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]
|
|
|
|
let newCharInfo = JSON.parse(result.charinfo)
|
|
newCharInfo.birthdate = toInsertDate
|
|
|
|
result = await query(`UPDATE \`players\` SET \`charinfo\` = '${JSON.stringify(newCharInfo)}' WHERE \`citizenid\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
} else if (config.Framework.includes("esx")) {
|
|
const toInsertDate = newDate.replace(".", "/").replace(".", "/")
|
|
let result = await query(`UPDATE \`users\` SET \`dateofbirth\` = '${toInsertDate}' WHERE \`identifier\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
}
|
|
|
|
res.json({ code: 200, message: "Updated." })
|
|
}
|
|
|
|
async function changeCharacterNation(newNation, uid, res) {
|
|
if (!config.Framework.includes("qb")) return res.json({ code: 404, message: "Nationality not supported in ESX." })
|
|
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]
|
|
|
|
let newCharInfo = JSON.parse(result.charinfo)
|
|
newCharInfo.nationality = newNation
|
|
|
|
result = await query(`UPDATE \`players\` SET \`charinfo\` = '${JSON.stringify(newCharInfo)}' WHERE \`citizenid\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
res.json({ code: 200, message: "Updated." })
|
|
}
|
|
|
|
async function changeCharacterPhone(newPhone, uid, res) {
|
|
if (isNaN(newPhone)) return res.json({ code: 404, message: "Please use right syntax." })
|
|
|
|
if (config.Framework.includes("qb")) {
|
|
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]
|
|
|
|
let newCharInfo = JSON.parse(result.charinfo)
|
|
newCharInfo.phone = newPhone
|
|
result = await query(`UPDATE \`players\` SET \`charinfo\` = '${JSON.stringify(newCharInfo)}' WHERE \`citizenid\` = '${uid}'`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
} else if (config.Framework.includes("esx")) {
|
|
let result = await LV.ChangePlayersPhoneNumber(uid, newPhone)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
}
|
|
|
|
res.json({ code: 200, message: "Updated." })
|
|
}
|
|
|
|
app.use("/changeCharacterCredentials.lvorex", express.json())
|
|
app.post("/changeCharacterCredentials.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", 6)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
if (postBody.playerId !== null) return res.json({ code: 404, message: "Player need to be offline." })
|
|
|
|
if (postBody.type === "characterName") {
|
|
changeCharacterName(postBody.newValue, postBody.uid, res)
|
|
} else if (postBody.type === "genderInput") {
|
|
changeCharacterGender(postBody.newValue, postBody.uid, res)
|
|
} else if (postBody.type === "birthdayInput") {
|
|
changeCharacterBirthday(postBody.newValue, postBody.uid, res)
|
|
} else if (postBody.type === "nationalityInput") {
|
|
changeCharacterNation(postBody.newValue, postBody.uid, res)
|
|
} else if (postBody.type === "phoneInput") {
|
|
changeCharacterPhone(postBody.newValue, postBody.uid, res)
|
|
} else return res.json({ code: 404, message: "An error appeared." })
|
|
})
|
|
|
|
async function setPlayerHealth(type, playerId, res) {
|
|
if (type === "fill") {
|
|
emit("mAdmin:server:revivePlayer", playerId)
|
|
res.json({ code: 200, message: "Filled." })
|
|
} else if (type === "drain") {
|
|
emitNet("mAdmin:killPlayer", playerId)
|
|
res.json({ code: 200, message: "Drained." })
|
|
}
|
|
}
|
|
|
|
async function setPlayerMetadata(type, action, playerId, res) {
|
|
let meta = null
|
|
|
|
if (type === "hungerInput") meta = "hunger"
|
|
if (type === "armorInput") meta = "armor"
|
|
if (type === "thirstInput") meta = "thirst"
|
|
if (type === "stressInput") meta = "stress"
|
|
|
|
if (config.Framework.includes("qb")) {
|
|
const qPlayer = FrameworkObject.Functions.GetPlayer(playerId)
|
|
if (!qPlayer) return res.json({ code: 404, message: "Player not found." })
|
|
|
|
qPlayer.Functions.SetMetaData(meta, action === "fill" ? 100 : 0)
|
|
|
|
if (meta === "hunger") {
|
|
emit("madmin:server:updateNeeds", playerId, action === "fill" ? 100 : 0, qPlayer.PlayerData.metadata.thirst)
|
|
} else if (meta === "thirst") {
|
|
emit("madmin:server:updateNeeds", playerId, qPlayer.PlayerData.metadata.hunger, action === "fill" ? 100 : 0)
|
|
} else if (meta === "stress") {
|
|
emitNet("mAdmin:SetStress", playerId, action === "fill" ? 100 : 0, action === "fill" ? true : false)
|
|
} else if (meta === "armor") {
|
|
const ped = GetPlayerPed(playerId)
|
|
SetPedArmour(ped, action === "fill" ? 100 : 0)
|
|
}
|
|
} else {
|
|
const xPlayer = FrameworkObject.GetPlayerFromId(playerId)
|
|
if (!xPlayer) return res.json({ code: 404, message: "Player not found." })
|
|
|
|
const CurrentHunger = xPlayer.variables.status.find(s => s.name === "hunger").percent
|
|
const CurrentThirst = xPlayer.variables.status.find(s => s.name === "thirst").percent
|
|
|
|
if (meta === "hunger") {
|
|
emit("madmin:server:updateNeeds", playerId, action === "fill" ? 1000000 : 0, CurrentThirst, "hunger")
|
|
} else if (meta === "thirst") {
|
|
emit("madmin:server:updateNeeds", playerId, CurrentHunger, action === "fill" ? 1000000 : 0, "thirst")
|
|
} else if (meta === "stress") {
|
|
emitNet("mAdmin:SetStress", playerId, action === "fill" ? 100 : 0, action === "fill" ? true : false)
|
|
} else if (meta === "armor") {
|
|
const ped = GetPlayerPed(playerId)
|
|
SetPedArmour(ped, action === "fill" ? 100 : 0)
|
|
}
|
|
}
|
|
|
|
res.json({ code: 200, message: "Updated." })
|
|
}
|
|
|
|
app.use("/setPlayerMetadata.lvorex", express.json())
|
|
app.post("/setPlayerMetadata.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", 9)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
let result = await query(`INSERT INTO \`madmin_logs\` (\`type\`, \`author\`, \`message\`, \`date\`, \`player_uid\`) VALUES ('status', '${userKey.userName}', '${postBody.action.replaceAll("'", "\\'")}ed the ${postBody.type.split("Input")[0]}.', '${moment(Date.now()).format("DD.MM.YYYY HH:mm")}', '${postBody.uid}')`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
|
|
if (postBody.type === "healthInput") {
|
|
setPlayerHealth(postBody.action, Number(postBody.playerId), res)
|
|
return
|
|
} else {
|
|
setPlayerMetadata(postBody.type, postBody.action, Number(postBody.playerId), res)
|
|
return
|
|
}
|
|
}) |