From cf46bd8487bdb2d0cafdab1f43936357f670fe10 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:33:27 +0200 Subject: [PATCH] Add new function: aclObjectGetGroups (PR b#3180) --- .../deathmatch/logic/luadefs/CLuaACLDefs.cpp | 32 +++++++++++++++++++ .../deathmatch/logic/luadefs/CLuaACLDefs.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.cpp index 51d3c01aa1..c37a1ebeac 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.cpp @@ -57,6 +57,7 @@ void CLuaACLDefs::LoadFunctions() {"isObjectInACLGroup", isObjectInACLGroup}, {"hasObjectPermissionTo", hasObjectPermissionTo}, + {"aclObjectGetGroups", ArgumentParser}, }; // Add functions @@ -74,6 +75,7 @@ void CLuaACLDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "reload", "aclReload"); lua_classfunction(luaVM, "list", "aclList"); lua_classfunction(luaVM, "hasObjectPermissionTo", "hasObjectPermissionTo"); + lua_classfunction(luaVM, "aclObjectGetGroups", "aclObjectGetGroups"); lua_classfunction(luaVM, "create", "aclCreate"); lua_classfunction(luaVM, "destroy", "aclDestroy"); @@ -1049,3 +1051,33 @@ int CLuaACLDefs::OOP_isObjectInACLGroup(lua_State* luaVM) lua_pushboolean(luaVM, false); return 1; } + +std::vector CLuaACLDefs::aclObjectGetGroups(std::string strObject) +{ + CAccessControlListGroupObject::EObjectType objectType; + const char* szObjectAfterDot = strObject.c_str(); + if (StringBeginsWith(szObjectAfterDot, "resource.")) + { + szObjectAfterDot += 9; + objectType = CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE; + } + else if (StringBeginsWith(szObjectAfterDot, "user.")) + { + szObjectAfterDot += 5; + objectType = CAccessControlListGroupObject::OBJECT_TYPE_USER; + } + else + throw std::invalid_argument("Object must be either a resource or an user."); + + std::vector groups; + + for (auto iter = m_pACLManager->Groups_Begin(); + iter != m_pACLManager->Groups_End(); ++iter) + { + if (!(*iter)->FindObjectMatch(szObjectAfterDot, objectType)) + continue; + + groups.push_back(*iter); + } + return groups; +} diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.h index 6b08b05289..8a3bb2cfbc 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.h @@ -48,4 +48,6 @@ class CLuaACLDefs : public CLuaDefs LUA_DECLARE(aclGroupRemoveObject); LUA_DECLARE_OOP(isObjectInACLGroup); LUA_DECLARE(hasObjectPermissionTo); + + static std::vector aclObjectGetGroups(std::string strObject); };