Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- lua/autorun/server/admin_requests_sv.lua
- util.AddNetworkString("AdminRequest")
- util.AddNetworkString("AdminRequestAction")
- util.AddNetworkString("AdminRequestClaim")
- util.AddNetworkString("AdminRequestClaimData")
- util.AddNetworkString("RequestUpdatedAdminRequests")
- util.AddNetworkString("UpdatedAdminRequests")
- util.AddNetworkString("AdminRequestClose")
- adminClaimData = {}
- local adminClaimData = loadClaimData()
- local adminRequests = {}
- local function GetAdmins()
- local adminGroups = {
- "trialmod", "moderator", "seniormod", "admin", "headadmin", "senioradmin", "council", "superadmin", "manager"
- }
- local admins = {}
- for _, ply in ipairs(player.GetAll()) do
- for _, group in ipairs(adminGroups) do
- if ply:IsUserGroup(group) then
- table.insert(admins, ply)
- break
- end
- end
- end
- return admins
- end
- local function IsAdminGroup(ply)
- local adminGroups = {
- "trialmod", "moderator", "seniormod", "admin", "headadmin", "senioradmin", "council", "superadmin", "manager"
- }
- for _, group in ipairs(adminGroups) do
- if ply:IsUserGroup(group) then
- return true
- end
- end
- return false
- end
- hook.Add("PlayerSay", "AdminRequestSystem", function(ply, text, teamChat)
- if string.sub(text, 1, 1) == "@" then
- local requestData = {
- steamID64 = ply:SteamID64(),
- name = ply:Nick(),
- message = string.sub(text, 2),
- requestTime = CurTime()
- }
- table.insert(adminRequests, requestData) -- Save the request data to the adminRequests table
- net.Start("AdminRequest")
- net.WriteTable(requestData)
- net.Send(GetAdmins()) -- GetAdmins will now check for the specified user groups
- return "" -- Hide the message from the chat
- end
- end)
- local function getUpdatedAdminRequests()
- -- Return the contents of the adminRequests table
- return adminRequests
- end
- -- Handle admin actions
- local playerPreviousPositions = {}
- net.Receive("AdminRequestAction", function(len, ply)
- local action = net.ReadString()
- local target = net.ReadEntity()
- if not IsValid(target) then return end
- if action == "goto" then
- playerPreviousPositions[ply:SteamID64()] = ply:GetPos()
- ply:SetPos(target:GetPos() + Vector(0, 0, 50))
- elseif action == "bring" then
- playerPreviousPositions[target:SteamID64()] = target:GetPos()
- target:SetPos(ply:GetPos() + ply:GetForward() * 100 + Vector(0, 0, 50))
- elseif action == "return" then
- local prevPos = playerPreviousPositions[target:SteamID64()]
- if prevPos then
- target:SetPos(prevPos)
- playerPreviousPositions[target:SteamID64()] = nil
- end
- end
- end)
- -- Initialize admin claim data table
- local adminClaimData = {}
- net.Receive("AdminRequestClaim", function(len, ply)
- if not IsAdminGroup(ply) then return end
- local requestData = net.ReadTable()
- local adminID = ply:SteamID64()
- local currentDate = os.date("*t")
- local currentWeek = os.date("%U")
- if not adminClaimData[adminID] then
- adminClaimData[adminID] = {
- name = ply:Nick(),
- totalCount = 0,
- weeklyCount = 0,
- week = currentWeek
- }
- end
- local data = adminClaimData[adminID]
- if data.week ~= currentWeek then
- data.weeklyCount = 0
- data.week = currentWeek
- end
- data.totalCount = data.totalCount + 1
- data.weeklyCount = data.weeklyCount + 1
- saveClaimData(adminClaimData)
- end)
- -- Handle claimed cases
- local function markCaseAsClaimed(caseIndex, adminID)
- adminRequests[caseIndex].claimedBy = adminID
- end
- net.Receive("RequestUpdatedAdminRequests", function(len, ply)
- -- Get updated admin requests here
- local updatedRequests = getUpdatedAdminRequests()
- net.Start("UpdatedAdminRequests")
- net.WriteTable(updatedRequests)
- net.Send(ply)
- end)
- net.Receive("AdminRequestClose", function(len, ply)
- if not IsAdminGroup(ply) then return end
- local requestData = net.ReadTable()
- local index = -1
- for i, request in ipairs(adminRequests) do
- if request.steamID64 == requestData.steamID64 and request.requestTime == requestData.requestTime then
- index = i
- break
- end
- end
- if index > 0 then
- table.remove(adminRequests, index)
- end
- saveClaimData(adminClaimData)
- end)
- local function saveClaimData(claimData)
- local dataJSON = util.TableToJSON(claimData)
- sql.Query("CREATE TABLE IF NOT EXISTS claim_data (data TEXT)")
- sql.Query("DELETE FROM claim_data")
- sql.Query("INSERT INTO claim_data (data) VALUES ('" .. sql.SQLStr(dataJSON, true) .. "')")
- end
- local function loadClaimData()
- sql.Query("CREATE TABLE IF NOT EXISTS claim_data (data TEXT)")
- local result = sql.Query("SELECT data FROM claim_data LIMIT 1")
- if result then
- return util.JSONToTable(result[1].data)
- end
- return {}
- end
- concommand.Add("show_claim_data", function(ply, cmd, args)
- if not IsAdminGroup(ply) then return end
- net.Start("AdminRequestClaimData")
- net.WriteTable(adminClaimData)
- net.Send(ply)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement