-- Compiled with roblox-ts v1.2.7 local TS = _G[script] local Players = TS.import(script, TS.getModule(script, "@rbxts", "services")).Players local toArray = TS.import(script, script.Parent.Parent, "Shared", "Collections").toArray local ZirconUserGroup = TS.import(script, script.Parent.Parent, "Server", "Class", "ZirconGroup").default local ZrPlayerScriptContext = TS.import(script, TS.getModule(script, "@rbxts", "zirconium").out.Runtime.PlayerScriptContext).default local ZirconFunction = TS.import(script, script.Parent.Parent, "Class", "ZirconFunction").ZirconFunction local ZirconNamespace = TS.import(script, script.Parent.Parent, "Class", "ZirconNamespace").ZirconNamespace local ZirconEnum = TS.import(script, script.Parent.Parent, "Class", "ZirconEnum").ZirconEnum local ZirconConfigurationBuilder = TS.import(script, script.Parent.Parent, "Class", "ZirconConfigurationBuilder").ZirconConfigurationBuilder local Remotes = TS.import(script, script.Parent.Parent, "Shared", "Remotes").default local ZirconRegistryService = {} do local _container = ZirconRegistryService local contexts = {} local groups = {} local playerGroupMap = {} local unregisteredTypes = {} local initalized = false local function playerFunctionIterator(player) return TS.generator(function() local groups = playerGroupMap[player] if not groups then return false end for _, group in ipairs(groups) do for _k, _v in pairs(group:_getFunctions()) do local value = { _k, _v } coroutine.yield(value) end for _k, _v in pairs(group:_getNamespaces()) do local value = { _k, _v } coroutine.yield(value) end for _k, _v in pairs(group:_getEnums()) do local value = { _k, _v } coroutine.yield(value) end end return true end) end -- * @internal local function GetScriptContextsForPlayer(player) local contextArray if not (contexts[player] ~= nil) then contextArray = {} local context = ZrPlayerScriptContext.new(player) for _result in playerFunctionIterator(player).next do if _result.done then break end local _binding = _result.value local name = _binding[1] local fun = _binding[2] context:registerGlobal(name, fun) end -- ▼ Array.push ▼ contextArray[#contextArray + 1] = context -- ▲ Array.push ▲ local _contextArray = contextArray -- ▼ Map.set ▼ contexts[player] = _contextArray -- ▲ Map.set ▲ else contextArray = contexts[player] end return contextArray end _container.GetScriptContextsForPlayer = GetScriptContextsForPlayer --[[ * * Registers a function in the global namespace to the specified group(s) * @param func The function to register * @param groups The groups * @deprecated Use `ZirconFunctionBuilder` + the ZirconConfigurationBuilder API ]] local GetGroups local function RegisterFunction(func, groupIds) if not initalized then local _arg0 = { func, groupIds } -- ▼ Array.push ▼ unregisteredTypes[#unregisteredTypes + 1] = _arg0 -- ▲ Array.push ▲ else for _, group in ipairs(GetGroups(groupIds)) do group:RegisterFunction(func) end end end _container.RegisterFunction = RegisterFunction --[[ * * Registers a namespace to the specified group(s) * @param namespace The namespace * @param groups The groups to register it to * @deprecated Use `ZirconNamespaceBuilder` + the ZirconConfigurationBuilder API ]] local function RegisterNamespace(namespace, groupIds) if not initalized then local _arg0 = { namespace, groupIds } -- ▼ Array.push ▼ unregisteredTypes[#unregisteredTypes + 1] = _arg0 -- ▲ Array.push ▲ else for _, group in ipairs(GetGroups(groupIds)) do group:RegisterNamespace(namespace) end end end _container.RegisterNamespace = RegisterNamespace function GetGroups(groupIds) local _arg0 = function(groupId) local _arg0_1 = string.lower(groupId) return groups[_arg0_1] end -- ▼ ReadonlyArray.mapFiltered ▼ local _newValue = {} local _length = 0 for _k, _v in ipairs(groupIds) do local _result = _arg0(_v, _k - 1, groupIds) if _result ~= nil then _length += 1 _newValue[_length] = _result end end -- ▲ ReadonlyArray.mapFiltered ▲ return _newValue end _container.GetGroups = GetGroups --[[ * * Registers an enumerable type to the specified group(s) * @param enumType The enumerable type * @param groups The groups to register the enum to * @returns The enum * @deprecated Use `ZirconEnumBuilder` + the ZirconConfigurationBuilder API ]] local function RegisterEnum(enumType, groupIds) if not initalized then local _arg0 = { enumType, groupIds } -- ▼ Array.push ▼ unregisteredTypes[#unregisteredTypes + 1] = _arg0 -- ▲ Array.push ▲ else for _, group in ipairs(GetGroups(groupIds)) do group:RegisterEnum(enumType) end end end _container.RegisterEnum = RegisterEnum --[[ * * Gets the highest player group for this player ]] local function GetHighestPlayerGroup(player) local _result = playerGroupMap[player] if _result ~= nil then local _arg0 = function(acc, curr) return curr:GetRank() > acc:GetRank() and curr or acc end -- ▼ ReadonlyArray.reduce ▼ if #_result == 0 then error("Attempted to call `ReadonlyArray.reduce()` on an empty array without an initialValue.") end local _result_1 = _result[1] local _callback = _arg0 for _i = 2, #_result do _result_1 = _callback(_result_1, _result[_i], _i - 1, _result) end -- ▲ ReadonlyArray.reduce ▲ _result = _result_1 end return _result end _container.GetHighestPlayerGroup = GetHighestPlayerGroup --[[ * * Adds the specified player to the targeted groups. * * All players are added to `user`, and group owners/game owners are added to `creator` by default. * @param player The player to add to the groups * @param targetGroups The groups to add the player to ]] local function AddPlayerToGroups(player, targetGroups) local _condition = playerGroupMap[player] if _condition == nil then _condition = {} end local playerGroups = _condition for _, groupOrId in ipairs(targetGroups) do local _result if type(groupOrId) == "string" then _result = groups[groupOrId] else _result = groupOrId end local group = _result if group then group:AddMember(player) -- ▼ Array.push ▼ playerGroups[#playerGroups + 1] = group -- ▲ Array.push ▲ else warn("[Zircon] Failed to add player '" .. (tostring(player) .. ("' to group '" .. (tostring(groupOrId) .. "'")))) end end -- ▼ Map.set ▼ playerGroupMap[player] = playerGroups -- ▲ Map.set ▲ end -- * @internal local function GetGroupsWithPermission(permission) local matching = {} for _, group in pairs(groups) do if group:GetPermission(permission) then -- ▼ Array.push ▼ matching[#matching + 1] = group -- ▲ Array.push ▲ end end return matching end _container.GetGroupsWithPermission = GetGroupsWithPermission --[[ * * The cache of players that are allowed this permission ]] local permissionGroupCache = {} --[[ * * Gets the players with the specified permission * @internal ]] local function InternalGetPlayersWithPermission(permission) if permissionGroupCache[permission] ~= nil then return permissionGroupCache[permission] end local groups = GetGroupsWithPermission(permission) local playerSet = {} for _, group in ipairs(groups) do for member in pairs(group:GetMembers()) do -- ▼ Set.add ▼ playerSet[member] = true -- ▲ Set.add ▲ end end local arr = toArray(playerSet) -- ▼ Map.set ▼ permissionGroupCache[permission] = arr -- ▲ Map.set ▲ return arr end _container.InternalGetPlayersWithPermission = InternalGetPlayersWithPermission -- * @internal local function InternalGetPlayerHasPermission(player, permission) local players = InternalGetPlayersWithPermission(permission) local _arg0 = function(p) return p == player end -- ▼ ReadonlyArray.find ▼ local _result = nil for _i, _v in ipairs(players) do if _arg0(_v, _i - 1, players) == true then _result = _v break end end -- ▲ ReadonlyArray.find ▲ return _result ~= nil end _container.InternalGetPlayerHasPermission = InternalGetPlayerHasPermission local function GetGroupOrThrow(name) local _arg0 = string.lower(name) local group = groups[_arg0] local _arg1 = "Group '" .. name .. "' does not exist!" assert(group, _arg1) return group end _container.GetGroupOrThrow = GetGroupOrThrow local function RegisterZirconGlobal(_param) local typeId = _param[1] local typeGroups = _param[2] if TS.instanceof(typeId, ZirconFunction) then for _, group in ipairs(GetGroups(typeGroups)) do group:RegisterFunction(typeId) end elseif TS.instanceof(typeId, ZirconEnum) then for _, group in ipairs(GetGroups(typeGroups)) do group:RegisterEnum(typeId) end elseif TS.instanceof(typeId, ZirconNamespace) then for _, group in ipairs(GetGroups(typeGroups)) do group:RegisterNamespace(typeId) end end end --[[ * * Initializes Zircon as a logging console *only*. * * This is equivalent to * ```ts * ZirconServer.Registry.Init(ZirconConfigurationBuilder.logging()) * ``` ]] local Init local function InitLogging() return Init(ZirconConfigurationBuilder:logging()) end _container.InitLogging = InitLogging --[[ * * Initializes Zircon on the server with a given configuration if specified. * * If no configuration is passed, it will behave as a logging console _only_. * @param configuration The configuration ]] function Init(configuration) if initalized then return nil end local configurationGroups = configuration.Groups for _, group in ipairs(configurationGroups) do local userGroup = ZirconUserGroup.new(group.Rank, group.Id, group) local _arg0 = string.lower(group.Id) -- ▼ Map.set ▼ groups[_arg0] = userGroup -- ▲ Map.set ▲ end -- Handle builder API types for _, typeId in ipairs(configuration.Registry) do RegisterZirconGlobal(typeId) end -- Handle any types registered with the deprecated api for _, typeId in ipairs(unregisteredTypes) do RegisterZirconGlobal(typeId) end Players.PlayerAdded:Connect(function(player) -- ▼ Map.clear ▼ table.clear(permissionGroupCache) -- ▲ Map.clear ▲ local groupsToJoin = {} for _, group in pairs(groups) do if group:CanJoinGroup(player) then -- ▼ Array.push ▼ groupsToJoin[#groupsToJoin + 1] = group -- ▲ Array.push ▲ end end AddPlayerToGroups(player, groupsToJoin) Remotes.Server:Get("ZrSOi4/ZirconInit"):SendToPlayer(player) end) Players.PlayerRemoving:Connect(function(player) -- ▼ Map.clear ▼ table.clear(permissionGroupCache) -- ▲ Map.clear ▲ -- ▼ Map.delete ▼ contexts[player] = nil -- ▲ Map.delete ▲ -- ▼ Map.delete ▼ playerGroupMap[player] = nil -- ▲ Map.delete ▲ end) for _, player in ipairs(Players:GetPlayers()) do local groupsToJoin = {} for _, group in pairs(groups) do if group:CanJoinGroup(player) then -- ▼ Array.push ▼ groupsToJoin[#groupsToJoin + 1] = group -- ▲ Array.push ▲ end end AddPlayerToGroups(player, groupsToJoin) end initalized = true Remotes.Server:Get("ZrSOi4/ZirconInit"):SendToAllPlayers() end _container.Init = Init Remotes.Server:OnFunction("ZrSOi4/GetZirconInit", function() return initalized end) end return { ZirconRegistryService = ZirconRegistryService, }