Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/thoda-dev/du-simple-access-control. a script to control access with doors of force fields. Work with user name or ID or Organisation name or id
Something went wrong. Try again.
du-simple-access-control config.json
7.0 kB · 1 line
JSON
at main
1{"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-3":{"name":"player","type":{"events":[],"methods":[]}},"-2":{"name":"construct","type":{"events":[],"methods":[]}},"-4":{"name":"system","type":{"events":[],"methods":[]}},"-5":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"--version 1.0.1\n\n--LUA PARAMETERS\nlocal AllowedUsersId = \"\" --export: the list of all IDs, comma separated\nlocal AllowedUsersName = \"jericho\" --export: the list of all names, comma separated (Case sensitive)\nlocal AllowedUserOrgsId = \"\" --export: the list of all organisation IDs, comma separated\nlocal AllowedUserOrgsName = \"Federatis\" --export: the list of all organisation Names, comma separated (Case sensitive)\n\n--Libraries\n--split is a function to split a string in a table with a delimiter written by Jericho\nfunction split(s,d)local t={}s:gsub(\"[^\"..d..\"]+\",function(w)table.insert(t,w)end)return t end\n\n--hide unit widget\nunit.hideWidget()\n\n--auto detecting the door, force fields and the screens\nDoors = {}\nFields = {}\nScreens = {}\nSwitches = {}\nfor slotName,slot in pairs(unit) do\n if\n type(slot) == \"table\"\n and type(slot.export) == \"table\"\n and slot.getClass\n then\n local ElementClass = slot.getClass():lower()\n if ElementClass:find(\"doorunit\") then\n table.insert(Doors, slot)\n elseif ElementClass:find(\"manualswitchunit\") then\n table.insert(Switches, slot)\n slot.deactivate()\n elseif ElementClass:find(\"forcefieldunit\") then\n table.insert(Fields, slot)\n slot.activate()\n elseif ElementClass:find(\"screenunit\") then\n table.insert(Screens, slot)\n slot.activate()\n else\n system.print(ElementClass)\n end\n end\nend\n\nfunction getRenderScript(access)\n local color = \"red\"\n local message = \"Access Denied\"\n if access then\n color = \"green\"\n message = \"Access Granted\"\n end\n return [[\n setBackgroundColor(15/255,24/255,29/255)\n local rx,ry = getResolution()\n local cx, cy = getCursor()\n if vmode then\n ry,rx = getResolution()\n cy, cx = getCursor()\n cx = rx - cx\n if vmode_side == \"right\" then\n cy = ry - cy\n cx = rx - cx\nend\nend\n\n local smallBold=loadFont('Play-Bold',40)\n local bigBold=loadFont('Play-Bold',64)\n\n local front=createLayer()\n local back=createLayer()\n setDefaultStrokeColor( back,Shape_Line,0,0,0,0.5)\n setDefaultShadow( back,Shape_Line,6,0,0,0,0.5)\n setDefaultFillColor( front,Shape_BoxRounded,249/255,212/255,123/255,1)\n setDefaultFillColor( front,Shape_Text,0,0,0,1)\n setDefaultFillColor( front,Shape_Box,0.075,0.125,0.156,1)\n setDefaultFillColor( front,Shape_Text,0.710,0.878,0.941,1)\n\n local red = {177/255,42/255,42/255}\n local green = {34/255,177/255,76/255}\n\n function renderHeader(title)\n local h = 55\n addLine(back,0,h+12,rx,h+12)\n addBox(front,0,12,rx,h)\n addText(front,smallBold,title,44,h-12)\nend\n\n setNextFillColor(front, ]] .. color .. [[[1], ]] .. color .. [[[2], ]] .. color .. [[[3], 1)\n setNextTextAlign(front,AlignH_Center,AlignV_Middle)\n addText(front,smallBold,\"]] .. message .. [[\", rx/2, ry/4)\n\n\n setNextFillColor(front, ]] .. color .. [[[1], ]] .. color .. [[[2], ]] .. color .. [[[3], 1)\n setNextTextAlign(front,AlignH_Center,AlignV_Middle)\n addText(front,bigBold,\"]] .. player.getName() .. [[\", rx/2, ry/2)\n\n renderHeader(\"Access Control System\")\n requestAnimationFrame(10)\n ]]\nend\n\nlocal AccessPermitted = false\n\nfunction setRenderScriptOnScreens(access)\n for _,screen in pairs(Screens) do\n screen.setRenderScript(getRenderScript(access))\n end\nend\n\nfunction grantAccess()\n AccessPermitted = true\n for _,Door in pairs(Doors) do\n Door.open() --open the door\n end\n for _,Field in pairs(Fields) do\n Field.deactivate() --open the field\n end\n for _,Switch in pairs(Switches) do\n Switch.activate() --activate the swicth\n end\n setRenderScriptOnScreens(true)\nend\n\nfunction closeAll()\n AccessPermitted = false\n for _,Door in pairs(Doors) do\n Door.close() --close the door\n end\n for _,Field in pairs(Fields) do\n Field.activate() --close the field\n end\n for _,Switch in pairs(Switches) do\n Switch.deactivate() --deactivate the switch\n end\nend\ncloseAll() --close all by default\n\nfunction rejectAccess()\n closeAll()\n setRenderScriptOnScreens(false)\n unit.exit()\nend\n\n--converting to tables\nlocal tPermittedUsersId = split(AllowedUsersId,',') or {}\nlocal tPermittedUsersName = split(AllowedUsersName,',') or {}\nlocal tPermittedOrgsId = split(AllowedUserOrgsId,',') or {}\nlocal tPermittedOrgsName = split(AllowedUserOrgsName,',') or {}\n\nlocal player_id = player.getId()\n\nfor _,id in pairs(tPermittedUsersId) do\n if id == player_id then\n grantAccess()\n AccessPermitted = true\n break\n end\nend\n\nif not AccessPermitted then\n local player_name = player.getName()\n for _,name in pairs(tPermittedUsersName) do\n if name == player_name then\n grantAccess()\n break\n end\n end\nend\n\nif not AccessPermitted then\n local player_orgs_id = player.getOrgIds()\n for _,oid in pairs(player_orgs_id) do\n for _,id in pairs(tPermittedOrgsId) do\n if tonumber(id) == oid then\n grantAccess()\n break\n end\n end\n --if access is granted, end the loop\n if AccessPermitted then break end\n --if not a valid ID, veifying the org name\n local o = system.getOrganization(oid)\n if o.name then\n for _,name in pairs(tPermittedOrgsName) do\n if name == o.name then\n grantAccess()\n break\n end\n end\n end\n --if access is granted, end the loop\n if AccessPermitted then break end\n end\nend\n\nif not AccessPermitted then\n rejectAccess()\nend","filter":{"args":[],"signature":"onStart()","slotKey":"-1"},"key":"0"},{"code":"closeAll()\n","filter":{"args":[],"signature":"onStop()","slotKey":"-1"},"key":"1"}],"methods":[],"events":[]}