Skip to content

Commit

Permalink
Add new function: aclObjectGetGroups (PR b#3180)
Browse files Browse the repository at this point in the history
  • Loading branch information
TracerDS authored Oct 18, 2023
1 parent 5b44a09 commit cf46bd8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void CLuaACLDefs::LoadFunctions()

{"isObjectInACLGroup", isObjectInACLGroup},
{"hasObjectPermissionTo", hasObjectPermissionTo},
{"aclObjectGetGroups", ArgumentParser<aclObjectGetGroups>},
};

// Add functions
Expand All @@ -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");
Expand Down Expand Up @@ -1049,3 +1051,33 @@ int CLuaACLDefs::OOP_isObjectInACLGroup(lua_State* luaVM)
lua_pushboolean(luaVM, false);
return 1;
}

std::vector<CAccessControlListGroup*> 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<CAccessControlListGroup*> 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;
}
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ class CLuaACLDefs : public CLuaDefs
LUA_DECLARE(aclGroupRemoveObject);
LUA_DECLARE_OOP(isObjectInACLGroup);
LUA_DECLARE(hasObjectPermissionTo);

static std::vector<CAccessControlListGroup*> aclObjectGetGroups(std::string strObject);
};

0 comments on commit cf46bd8

Please sign in to comment.