EDIT: My approach to the command lib. I'll continue to update this occasionly - fine by me if it gets included into SP, otherwise I'll just ship this with my scripts :P
https://german-slaughterhouse.de/svn/k2tools/trunk/addons/source-python/_libs/k2tools/cmdlib.py
So here is what I think a command libary should or could do; stuff that has a common purpose:
SimpleCommandManger (possibly obsolete though c++ side of things):
- Only basic access for registering chat/console/server commands
- No fancy stuff = No overheard
- Should have one native python argument on the return method - a dictionary that contains the user, arguments and the command itself.
AdvancedCommandManager:
- Spam Protection
- Defaults to ON
- Should have configurable theresholds (for example, you can configure that people get kicked if they excute more then 5 commands within 1 second)
- Should have configurable punishment actions (possibly just a function that does whatever is needed - by default "kick")
- Reason: IMHO a must-have feature to prevent DoS exploits. Most scripters do not seem aware that their commands, if spammed, may cause the server to halt or crash - especailly if they are more expensive in nature
- Support for command aliases
- Probably you can just define a list/tuple of command aliases you wish to have
- When getting the command information, both, the 'real' command and the alias used could be returned to the KW dictionary
- Reason: Often you want multiple commands to do the same thing. Good example is adding a command for accessing the community website which may be !community !home !motd !<yourcommunityname> !website !homepage or anything similar
- Support for registration of multiple types at once
- You can choose whether your command should be registered as public say command, private say command, console command and/or server command
- Registration of the same callback for multiple ways is possible
- As for getting to know what type was used, another KW argument could be added ('type')
- Reason: Often different types of the same command should do the same
- Prefix support (for specific types)
- You can choosea list of prefixes for a specific command type
- When returing, it still returns the command normally without the prefix. Again, a special KW word argument could be used to return if there was a prefix (and which)
- Reason: Some plugins introduced 'command-type' prefixes, users are used to them and it allows for easy registration of 2 different things along side. A popular example would be sourcemod commands, usually you have a public command prefixed with ! (like !sm_admin) and a private one ( /sm_admin) and the console version without any prefixes (sm_admin). Another reason is that when you create your own game mode, you often want to prefix the commands (like rpg_admin).
- Command logging
- You can choose to log the command and parameters BEFORE and AFTER the command execution
- Reason: Generally useful for any kind of admin systems (so you know who did what) and also useful for debugging crashes [command executed -> server died. Without logging you may not know that the command was executed]
- Authentification support
- Depending on how the auth implemenation will be, you can choose to implement authenficiation for that command
- Assuming my system (or a similar one), you could choose to register/pass a permission which is checked when the command is accessed
- Reason: Well obviously you often want to authentificate your users for certain commands. Especially if it is of 'admin' nature.
- Internal 'help'
- Idea is to provide a translation file or section which provides help regarding the command
- Help can be shown though sp_help <command>
- Supports translations as opposed to the source engine built-in command description
- Reason: Unified interface makes this easier for everyone
- Pre-'Hook' function(s)
- List of methods that will be executed before the command
- Command will only be executed if all of them return true
- Arguments will be passed as if it was the real command
- Reason: Basically allows custom authentification and other purposes such as checking whether the database is accessable (instead of doing this on a per-command basis)
These would a lot of 'batteries-included' things, but I think they are generally quite useful and it's better to have them centerally defined instead of having multiple scripts each with their own implementation.
Input appreciated again :P