From 44d1351a5c5de77a66bcc0800df778c6ed1da35e Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Wed, 30 Nov 2022 03:32:52 +0100 Subject: [PATCH] feat: admin perms --- config_client.lua | 5 +++++ server/functions.lua | 12 ++++++++---- server/main.lua | 6 ++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config_client.lua b/config_client.lua index fc5e156..fc1e607 100644 --- a/config_client.lua +++ b/config_client.lua @@ -17,6 +17,11 @@ config = { "872921520719142932" }, + -- These are admins roles that will give a user permission to admin commands and more. + adminRoles = { + "872921520719142932" + }, + -- Discord Rich presence enableRichPresence = true, updateIntervall = 60, -- how many seconds of delay until it updates status. diff --git a/server/functions.lua b/server/functions.lua index f0b2236..65e2f5d 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -364,10 +364,14 @@ function NDCore.Functions.SetPlayerData(player, key, value) TriggerClientEvent("ND:updateCharacter", player, NDCore.Players[player]) end --- Saves player inventory to the database. -function NDCore.Functions.SaveInventory(player) - local inventory = NDCore.Players[player].inventory - MySQL.query("UPDATE `characters` SET inventory = ? WHERE character_id = ?", {json.encode(inventory), NDCore.Players[player].id}) +function NDCore.Functions.IsPlayerAdmin(src) + local discordInfo = NDCore.PlayersDiscordInfo[src] + if not discordInfo or not discordInfo.roles then return end + for _, adminRole in pairs(config.adminRoles) do + for _, role in pairs(discordInfo.roles) do + if role == adminRole then return true end + end + end end function NDCore.Functions.VersionChecker(expectedResourceName, resourceName, downloadLink, rawGithubLink) diff --git a/server/main.lua b/server/main.lua index b198380..3110bb9 100644 --- a/server/main.lua +++ b/server/main.lua @@ -3,6 +3,8 @@ NDCore = {} NDCore.Players = {} NDCore.Functions = {} +NDCore.Commands = {} +NDCore.PlayersDiscordInfo = {} NDCore.Config = config function GetCoreObject() @@ -30,4 +32,8 @@ AddEventHandler("onResourceStart", function(resourceName) end) if GetResourceState("ox_inventory") == "started" then SetConvarReplicated("inventory:framework", "nd") +end + +for _, roleid in pairs(config.adminRoles) do + ExecuteCommand("add_principal identifier.discord:" .. roleid .. " group.admin") end \ No newline at end of file