local ExtUtils = {} local cjson = require "cjson" function ExtUtils.slurpFile( name ) local f = assert( io.open( name, "rb" ) ) local content = f:read( "*all" ) f:close() return content end function getManifest() local fn = Helix.Core.Server.GetArchDirFileName( "manifest.json" ) return cjson.decode( ExtUtils.slurpFile( fn ) ) end function ExtUtils.trim( s ) return ( s:gsub( "^%s*(.-)%s*$", "%1" ) ) end function split(s, delimiter) if s == nil or s == '' then return nil end local result = {}; for match in (s..delimiter):gmatch("(.-)"..delimiter) do table.insert(result, match); end return result; end function getICfg() local cfg = {} for k, v in pairs( Helix.Core.Server.GetInstanceConfigData() ) do if k == "num_level" then cfg[ k ] = tonumber( ExtUtils.trim( v ) ) else cfg[ k ] = ExtUtils.trim( v ) end end -- Set a default to 0 (no restrictions) if no level set if cfg[ "num_level" ] == nil then cfg[ "num_level" ] = 0 end return cfg end function ExtUtils.getUsers() local userstr = ExtUtils.iCfgData[ "exempt_users" ] return split( userstr, " ") end function ExtUtils.getLevel() return ExtUtils.iCfgData[ "num_level" ] end function ExtUtils.UserNeedsRestrictions() local listusers = ExtUtils.getUsers() if listusers ~= nil then for k, u in pairs(listusers) do if Helix.Core.Server.GetVar( "user" ) == u then return false end end end return true end function ExtUtils.msgHeader() return ExtUtils.manifest[ "name" ] .. "/" .. ExtUtils.manifest[ "key" ] .. "/" .. ExtUtils.manifest[ "version_name" ] .. ": " end ExtUtils.manifest = {} ExtUtils.iCfgData = {} function ExtUtils.init() if ExtUtils.iCfgData[ "specName" ] == nil then ExtUtils.iCfgData = getICfg() end if ExtUtils.manifest[ "key" ] == nil then ExtUtils.manifest = getManifest() end end return ExtUtils
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 30808 | C. Thomas Tyler |
Promoted from 2019.1/... to main/... |
||
//guest/perforce_software/extensions/2019.1/narrow_workspace_mappings/ExtUtils.lua | |||||
#1 | 25601 | Jason Gibson |
Import example Extensions. p19.1@1797741 |