k2tools.cmdlib (version 1.00.000 $Rev: 13 $, $Date: 2013-06-28 21:41:02 +0200 (Fr, 28 Jun 2013) $)
index
y:\server\csgo\csgo\addons\source-python\_libs\k2tools\cmdlib.py

Path     addons/source-python/_libs/k2tools/cmdlib.py
Name     Command Libary
Version  1.00.000
Revision $Rev: 13 $
Author   (C) [#OMEGA] - K2
 
 
NOTES
 
Discussion Thread here:
http://www.sourcepython.com/forums/showthread.php?93
 
 
ON SPAM PROTECTION
 
I found it difficult to provide an optimal solution to command spamming. Some
commands may be rather light and can be executed a lot while others can impact
the game greatly.
 
I originally intended per-command spam-protection, but that leads to the issue
that if /multiple/ commands are spammed people can bypass the protection.
 
The downside of using a shared spam-protection is that that we can't define
it as correctly as before. So currently, we have a global setting for the
time between execution attempts and a shared value for any command execution
attemps.
So, commands with a high execution limit thereshold, can still be executed, 
however ones with a lot execution limit may be not.
 
 
COMMAND EXECUTION METHOD RESOLUTION ORDER
 
I put the methods for the command execution in a way I think it makes the most
sense. In order to be able to modify this in a simple manner, each 'aspect' is 
a method if it does a more complex task
 
 
TODO
 
Fix minor TODO-S
Eventually add much more detailed error-checking for command registry
Comments & doc-strings

 
Modules
       
command_c
cvar_c
logging
re

 
Classes
       
builtins.object
_AdvancedCommandManager

 
class _AdvancedCommandManager(builtins.object)
     Methods defined here:
__init__(self)
register(self, command, callback=(), description='No description given', spam_protect=True, spam_protect_attempts=5, spam_protect_action=(<function _kick>,), spam_protect_server=False, alias=(), public_say=False, public_say_prefix=(), private_say=False, private_say_prefix=(), private_say_return_on_success=command_c.CommandReturn.CONTINUE, private_say_return_on_failure=command_c.CommandReturn.CONTINUE, console=False, console_prefix=(), console_return_on_success=command_c.CommandReturn.CONTINUE, console_return_on_failure=command_c.CommandReturn.CONTINUE, server=False, server_prefix=(), server_flags=0, server_return_on_success=command_c.CommandReturn.CONTINUE, server_return_on_failure=command_c.CommandReturn.CONTINUE, log_pre_exec=False, log_post_exec=False, log_spam_protect=False, log_logger=<logging.Logger object>, auth=0, auth_params=(), auth_kwparams={}, auth_failure_callback=(<function _access_denied>,), help_enabled=False, pre_hook=())
Registers the specified command.
 
Notes:
Any param that requires an iterable and does not receive one will have the 
parameter automatically turned into a tuple. Be careful when using strings, as
they are iterable!
 
In order to maintain compability with future cmdlib versions I suggest you use
keyword arguments instead of positional arguments.
 
@command                       - Name of the command to register
@callback                      - Iterable of callbacks for this command
@description                   - Description for this command as registered in
                                 the engine
@spam_protect                  - Whether to enable spam protection
@spam_protect_attempts         - Maximum attempts per second before taking 
                               - action (Default: 5)
@spam_protect_action           - Iterable of callables when the user fails the
                                 spam protection checks
@spam_protect_server           - Whether to enable spam protection for server
@alias                         - Iterable of strings to use as command alias
@public_say                    - Whether to register as public say command
@public_say_prefix             - Iterable of strings to use as prefix for
                                 public say commands
@private_say                   - Whether to register as private say command
@private_say_prefix            - Iterable of strings to use as prefix for
                                 private say commands
@private_say_return_on_success - Internal return value of the command on
                                 successful execution (Default: Continue)
@private_say_return_on_failure - Internal return value of the command on
                                 failed execution (Default: Continue)
@console                       - Whether to register as console command
@console_prefix                - Iterable of strings to use as prefix for
                                 console commands
@console_return_on_success     - Internal return value of the command on
                                 sucesssful execution (Default: Continue)
@console_return_on_failure     - Internal return value of the command on
                                 failed execution (Default: Continue)
@server                        - Whether to register as server command
@server_prefix                 - Iterable of strings to use as prefix for 
                                 private commands
@server_flags                  - Flags to use when creating the command (Def:
                                 FCVAR_NONE)
@server_return_on_success      - Internal return value of the command on
                                 succecssful execution (Default: Continue)
@server_return_on_failure      - Internal return value of the command on
                                 failed execution (Default: Continue)
@log_pre_exec                  - Whether to log before the command executes
@log_post_exec                 - Whether to log after the command executes
@log_spam_protect              - Whether to log failed spam protection attempts
@log_logger                    - Logger to use (Default: cmdlib logger)
@auth                          - Auth type to use:
                                 0 = Disabled
                                 1 = Source Python authentification
@auth_params                   - Positional parameters passed to the 
                                 authentification function
@auth_kwparams                 - Keyword parameter passed to the 
                                 authentification function                                
@auth_failure_callback         - Iterable of callables that will be executed if
                                 authentification fails
@help_enabled                  - TODO
@pre_hook                      - Iterable of callables to execute before the
                                 command runs. Only if all return True the
                                 command is executed
 
Raises KeyError if the command exists
Raises TypeError if one of the callbacks supplied is not callable
set_spam_protect_delta(self, delta=1)
Sets the time to use for spam protection.
Your best bet is to leave it at the default.
 
@delta - Time in seconds (Default: 1)
unregister(self, command)
Unregisters the specified command.
 
@command - The name of the command to unregister
 
Raises KeyError if the command does not exist

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Data
        AdvancedCommandManager = <k2tools.cmdlib._AdvancedCommandManager object>
__all__ = ['AdvancedCommandManager', '_AdvancedCommandManager']

 
Author
        [#OMEGA] - K2