English 中文(简体)
Plugin permissions in an IRC Bot
原标题:

My friend and I are writing an C# IRC Bot that will allow users to extend it s capabilities via plugins. We need it so that each command will be able to have its own permissions. So that only a user on a specific level or above could execute the command. We had a hard time deciding how to do this.

The permissions system would be 1-10. 1 being the least privileged and 10 being the most. Each user would be assigned a 1-10 permission. Each command would also assign itself a required permission level. My question essentially is: How could I make a per-command permission system with plugins being able to have multiple commands within them.

I was hoping the good people of Stack Overflow could help me. Please bear with me as this is the first question I ve asked here. Any help will be greatly appreciated! Thanks!

最佳回答

that would definitely work, another way is the concept of capabilities . each user has a list of capabilities such as update-user , delete-user , download-file , etc. the list is unlimited. you can grant users capabilities and each function can check against the required list it needs

if (!checkCaps( shell-cmd , google , open-url )) sendError( sorry, no perms )

roles can be defined which aggregate a set of permissions, like guest , user , manager , admin etc.

问题回答

I would create your own implementation of IPrincipal which would return the values of 1-10 for the roles which represent the authorization level the user has. You then assign this as the principal permission when you authenticate your user.

Then, it s a matter of applying the PrincipalPermission attribute on all the methods (meaning your plugin methods, and others) to allow people in the appropriate role to execute the code only.

For example, if I have level five, then I am assigned roles 1, 2, 3, 4, 5.

You can have one method has a PrincpalPermission attribute where the Role property is set to 6, which I would not have access to and another method which has a PrincipalPermission attribute with the Role property set to 3, which I would.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签