212 lines
8.6 KiB
JavaScript
212 lines
8.6 KiB
JavaScript
const addNewLog = async (staffName, itemName, playerName, amount, playerUid) => {
|
|
let result = await query(`
|
|
insert into \`madmin_logs\` (
|
|
\`type\`,
|
|
\`author\`,
|
|
\`message\`,
|
|
\`date\`,
|
|
\`player_uid\`
|
|
) values (
|
|
'item',
|
|
'${staffName}',
|
|
'added ${itemName} to ${playerName}. Amount: ${amount}',
|
|
'${moment(Date.now()).format("DD.MM.YYYY HH:mm:ss")}',
|
|
'${playerUid}'
|
|
)
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
}
|
|
|
|
const removeNewLog = async (staffName, itemName, playerName, amount, playerUid) => {
|
|
let result = await query(`
|
|
insert into \`madmin_logs\` (
|
|
\`type\`,
|
|
\`author\`,
|
|
\`message\`,
|
|
\`date\`,
|
|
\`player_uid\`
|
|
) values (
|
|
'item',
|
|
'${staffName}',
|
|
'removed ${itemName.replace(/\'/g)} from ${playerName.replace(/\'/g)}. Amount: ${amount}',
|
|
'${moment(Date.now()).format("DD.MM.YYYY HH:mm:ss")}',
|
|
'${playerUid}'
|
|
)
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
}
|
|
|
|
const clearNewLog = async (staffName, playerName, playerUid) => {
|
|
let result = await query(`
|
|
insert into \`madmin_logs\` (
|
|
\`type\`,
|
|
\`author\`,
|
|
\`message\`,
|
|
\`date\`,
|
|
\`player_uid\`
|
|
) values (
|
|
'item',
|
|
'${staffName}',
|
|
'cleared ${playerName.replace(/\'/g)} inventory.',
|
|
'${moment(Date.now()).format("DD.MM.YYYY HH:mm:ss")}',
|
|
'${playerUid}'
|
|
)
|
|
`)
|
|
if (result === false) return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
}
|
|
|
|
/**
|
|
* @param {string} key
|
|
* @param {string} uid
|
|
* @returns {Array}
|
|
*/
|
|
|
|
app.use("/getInventoryItems.lvorex", express.json())
|
|
app.post("/getInventoryItems.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 NeededPlayer = await checkPlayerIsOnline(postBody.uid, res, true)
|
|
let items = undefined
|
|
|
|
if (!NeededPlayer) {
|
|
const response = await LV.GetPlayerInventoryItems(false, postBody.uid)
|
|
if (response === "SQL") return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
items = response
|
|
} else {
|
|
const response = await LV.GetPlayerInventoryItems(true, NeededPlayer.playerId)
|
|
if (response === "SQL") return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
items = response
|
|
}
|
|
|
|
res.json({ code: 200, message: JSON.stringify(items) })
|
|
})
|
|
|
|
/**
|
|
* @param {string} key
|
|
* @param {string} uid
|
|
* @returns {string}
|
|
*/
|
|
|
|
app.use("/clearInventory.lvorex", express.json())
|
|
app.post("/clearInventory.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", 18)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const NeededPlayer = await checkPlayerIsOnline(postBody.uid, res, true)
|
|
let playerName = "Not Found."
|
|
if (!NeededPlayer) {
|
|
await LV.ClearInventory(false, postBody.uid)
|
|
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." })
|
|
result = result[0]
|
|
playerName = result.name
|
|
|
|
await clearNewLog(userKey.userName, playerName, postBody.uid)
|
|
res.json({ code: 200, message: "Cleared." })
|
|
return
|
|
} else {
|
|
await LV.ClearInventory(true, NeededPlayer.playerId)
|
|
await clearNewLog(userKey.userName, NeededPlayer["name"], postBody.uid)
|
|
res.json({ code: 200, message: "Cleared." })
|
|
}
|
|
})
|
|
|
|
/**
|
|
* @param {string} key
|
|
* @param {string} uid
|
|
* @param {string} slot
|
|
* @param {string} amount
|
|
* @param {string} itemName
|
|
* @returns {string}
|
|
*/
|
|
|
|
app.use("/removeItemFromInventory.lvorex", express.json())
|
|
app.post("/removeItemFromInventory.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", 17)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const NeededPlayer = await checkPlayerIsOnline(postBody.uid, res, true)
|
|
|
|
if (!NeededPlayer) {
|
|
const response = await LV.RemoveItem(false, postBody.uid, postBody.slot, Number(postBody.amount))
|
|
if (response === "SQL") return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
await removeNewLog(userKey.userName, postBody.itemName, response.playerName, response.realAmount, postBody.uid)
|
|
} else {
|
|
const response = await LV.RemoveItem(true, NeededPlayer.playerId, postBody.slot, Number(postBody.amount), postBody.itemName)
|
|
if (response === "SQL") return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
await removeNewLog(userKey.userName, postBody.itemName, response.playerName, response.newAmount, postBody.uid)
|
|
}
|
|
|
|
res.json({ code: 200, message: "Removed." })
|
|
})
|
|
|
|
app.use("/addItemToInventory.lvorex", express.json())
|
|
app.post("/addItemToInventory.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", 17)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const NeededPlayer = await checkPlayerIsOnline(postBody.uid, res, true)
|
|
let playerName = "Not Found."
|
|
|
|
if (!NeededPlayer) {
|
|
const response = await LV.AddItem(false, postBody.uid, postBody.item, postBody.addingCount, true, postBody.slot)
|
|
if (response === "SQL") return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
if (!response) return res.json({ code: 404, message: "An error appeared." })
|
|
playerName = response
|
|
} else {
|
|
const response = await LV.AddItem(true, NeededPlayer.playerId, postBody.item, postBody.addingCount, true, postBody.slot)
|
|
if (!response) return res.json({ code: 404, message: "An error appeared." })
|
|
playerName = response
|
|
}
|
|
|
|
await addNewLog(userKey.userName, postBody.item, playerName, postBody.addingCount, postBody.uid)
|
|
|
|
res.json({ code: 200, message: "Updated." })
|
|
})
|
|
|
|
app.use("/addNewItemToInventory.lvorex", express.json())
|
|
app.post("/addNewItemToInventory.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", 17)
|
|
if (!PermissionCheck) return res.json({ code: 401, message: "Your rank is not enough." })
|
|
|
|
const NeededPlayer = await checkPlayerIsOnline(postBody.uid, res, true)
|
|
let playerName = "Not Found."
|
|
|
|
if (!NeededPlayer) {
|
|
const response = await LV.AddItem(false, postBody.uid, postBody.item, Number(postBody.amount))
|
|
if (response === "SQL") return res.json({ code: 404, message: "SQL Error Appeared." })
|
|
playerName = response
|
|
} else {
|
|
const response = await LV.AddItem(true, NeededPlayer.playerId, postBody.item, Number(postBody.amount))
|
|
if (!response) return res.json({ code: 404, message: "An error appeared." })
|
|
playerName = response
|
|
}
|
|
|
|
await addNewLog(userKey.userName, postBody.item, playerName, postBody.amount, postBody.uid)
|
|
|
|
res.json({ code: 200, message: "Added." })
|
|
}) |