コード例 #1
0
def getVariable(module, variable):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable in module.variables:
            return module.variables[variable]
    return False
コード例 #2
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def deleteVariable(module, variable):
    """
        Delete a variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar to delete
        
        return:         (bool) true (false if variable/module does not exist)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Get the variable name
        variable = getVariableName(module, variable)
        
        # Did we get a valid variable name and does the variable exist?
        if variable and getVariable(module, variable):
            # Reset the variable
            es.set(variable, '', '')
            
            # Remove the variable from our module
            del module.variables[variable]
            
            return True
    return False
コード例 #3
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def getVariable(module, variable):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable in module.variables:
            return module.variables[variable]
    return False
コード例 #4
0
def deleteVariable(module, variable):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable and getVariable(module, variable):
            es.set(variable, '', '')
            del module.variables[variable]
コード例 #5
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def deleteVariable(module, variable):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable and getVariable(module, variable):
            es.set(variable, '', '')
            del module.variables[variable]
コード例 #6
0
def createVariable(module, variable, defaultvalue=0, description=''):
    """
        Create a server variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar
        defaultvalue:   default value
        description:    text description of the cvar
        
        return:         (bool) true (false if module does not exist)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Get the variable name
        variable = getVariableName(module, variable)

        # Did we get a valid variable name?
        if variable:
            # Setup the variable
            module.variables[variable] = es.ServerVar(variable, defaultvalue,
                                                      description)
            module.variables[variable]._def = defaultvalue
            module.variables[variable]._descr = description

            # Return our new variable instance
            return module.variables[variable]

    # Fallback, variable creation failed
    return False
コード例 #7
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def createVariable(module, variable, defaultvalue=0, description=''):
    """
        Create a server variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar
        defaultvalue:   default value
        description:    text description of the cvar
        
        return:         (bool) true (false if module does not exist)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Get the variable name
        variable = getVariableName(module, variable)
        
        # Did we get a valid variable name?
        if variable:
            # Setup the variable
            module.variables[variable] = es.ServerVar(variable, defaultvalue, description)
            module.variables[variable]._def = defaultvalue
            module.variables[variable]._descr = description
            
            # Return our new variable instance
            return module.variables[variable]
    
    # Fallback, variable creation failed
    return False
コード例 #8
0
def deleteVariable(module, variable):
    """
        Delete a variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar to delete
        
        return:         (bool) true (false if variable/module does not exist)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Get the variable name
        variable = getVariableName(module, variable)

        # Did we get a valid variable name and does the variable exist?
        if variable and getVariable(module, variable):
            # Reset the variable
            es.set(variable, '', '')

            # Remove the variable from our module
            del module.variables[variable]

            return True
    return False
コード例 #9
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def createVariable(module, variable, defaultvalue=0, description=""):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable:
            module.variables[variable] = es.ServerVar(variable, defaultvalue, description)
            module.variables[variable]._def = defaultvalue
            module.variables[variable]._descr = description
            return module.variables[variable]
    return False
コード例 #10
0
def createVariable(module, variable, defaultvalue=0, description=""):
    if xa.exists(module):
        module = xa.find(module)
        variable = getVariableName(module, variable)
        if variable:
            module.variables[variable] = es.ServerVar(variable, defaultvalue,
                                                      description)
            module.variables[variable]._def = defaultvalue
            module.variables[variable]._descr = description
            return module.variables[variable]
    return False
コード例 #11
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def getVariables(module = None, submodule = None):
    varlist = []
    if submodule:
        module = submodule
    if xa.exists(module):
        module = xa.find(module)
        for variable in sorted(module.variables):
            varlist.append(module.variables[variable])
    else:
        for module in sorted(xa.modules()):
            module = xa.find(module)
            for variable in sorted(module.variables):
                varlist.append(module.variables[variable])
    return varlist
コード例 #12
0
def getVariables(module=None, submodule=None):
    varlist = []
    if submodule:
        module = submodule
    if xa.exists(module):
        module = xa.find(module)
        for variable in sorted(module.variables):
            varlist.append(module.variables[variable])
    else:
        for module in sorted(xa.modules()):
            module = xa.find(module)
            for variable in sorted(module.variables):
                varlist.append(module.variables[variable])
    return varlist
コード例 #13
0
def log(module, text, userid=None, admin=False, loglvl=0):
    """
        XA logging
        
        module:         module name (usually automatically provided)
        test:           text string to log
        userid:         optionally provide a userid as reference
        admin:          set to true if this is an admin action
        loglvl:         an optional level - messages with lower xa_log values will not be recorded
        
        Appends a line to the module's log file (found in the xa/logs directory).
        
        Includes ability to reference a specific player and also flag as an admin action
    """
    # Is logging enabled and does our module exist?
    if int(es.ServerVar('xa_log')) and int(
            es.ServerVar('xa_log')) >= loglvl and xa.exists(module):
        # Was a valid source userid specified?
        if userid and es.exists('userid', int(userid)):
            # Is this userid an admin?
            if admin:
                # Adming log
                logtext = '%s: Admin %s [%s]: %s' % (
                    module, es.getplayername(userid),
                    es.getplayersteamid(userid), text)

            else:
                # User log
                logtext = '%s: User %s [%s]: %s' % (
                    module, es.getplayername(userid),
                    es.getplayersteamid(userid), text)

        else:
            # Default log
            logtext = '%s: %s' % (module, text)

        # Create our log folder if it does not exist
        if not os.path.isdir('%s/logs' % xa.coredir()):
            os.mkdir('%s/logs' % xa.coredir())

        # Write to our log file
        logname = '%s/logs/l%s' % (xa.coredir(), time.strftime('%m%d000.log'))
        logfile = open(logname, 'a+')
        logfile.write(
            time.strftime('L %m/%d/%Y - %H:%M:%S: ') + logtext + '\n')
        logfile.close()

        # Write to the SRCDS log file
        es.log(logtext)
コード例 #14
0
ファイル: logging.py プロジェクト: fizek/source_addons
def log(module, text, userid=0, admin=False):
    if bool(int(es.ServerVar("xa_log"))) and xa.exists(module):
        if (int(userid) > 0) and es.exists('userid', int(userid)):
            if admin:
                logtext = str(module) + ': Admin ' + es.getplayername(userid) + ' [' + es.getplayersteamid(userid) + ']: ' + str(text)
            else:
                logtext = str(module) + ': User ' + es.getplayername(userid) + ' [' + es.getplayersteamid(userid) + ']: ' + str(text)
        else:
            logtext = str(module) + ': ' + str(text)
        logname = '%s/logs/l%s' % (xa.coredir(), time.strftime('%m%d000.log'))
        logfile = open(logname, 'a+')
        logfile.write(time.strftime('L %m/%d/%Y - %H:%M:%S: ') + logtext + '\n')
        logfile.close()
        es.log(logtext)
        return True
    return False
コード例 #15
0
def getVariables(module, submodule=None):
    """
        Retrieve a list of the variables registered to a module
        
        module:         module name (usually automatically provided)
        submodule:      used to specify another module to retrieve variables from
        
        return:         list of ServerVar instances
        
        Because of how this is used you usually call:
          <xa instance>.settings.getVariables()
        to retrieve your own module's variables. And:
          <xa instance>.settings.getVariables("othermodule")
        to retrieve another modules variables.
    
    """
    # Return variable
    varlist = []

    # Do we want to get the list of another module?
    if submodule:
        module = submodule

    # Does our module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Fill our variable list
        for variable in sorted(module.variables):
            varlist.append(module.variables[variable])

    else:
        # No, we just return a variable list of all modules
        for module in sorted(xa.modules()):
            # Find the module instance
            module = xa.find(module)

            # Fill our variable list
            for variable in sorted(module.variables):
                varlist.append(module.variables[variable])

    # Return our variable list
    return varlist
コード例 #16
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def getVariables(module, submodule = None):
    """
        Retrieve a list of the variables registered to a module
        
        module:         module name (usually automatically provided)
        submodule:      used to specify another module to retrieve variables from
        
        return:         list of ServerVar instances
        
        Because of how this is used you usually call:
          <xa instance>.settings.getVariables()
        to retrieve your own module's variables. And:
          <xa instance>.settings.getVariables("othermodule")
        to retrieve another modules variables.
    
    """
    # Return variable
    varlist = []
    
    # Do we want to get the list of another module?
    if submodule:
        module = submodule
    
    # Does our module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Fill our variable list
        for variable in sorted(module.variables):
            varlist.append(module.variables[variable])
        
    else:
        # No, we just return a variable list of all modules
        for module in sorted(xa.modules()):
            # Find the module instance
            module = xa.find(module)
            
            # Fill our variable list
            for variable in sorted(module.variables):
                varlist.append(module.variables[variable])
    
    # Return our variable list
    return varlist
コード例 #17
0
ファイル: logging.py プロジェクト: StarsGame/source_addons
def log(module, text, userid=None, admin=False, loglvl=0):
    """
        XA logging
        
        module:         module name (usually automatically provided)
        test:           text string to log
        userid:         optionally provide a userid as reference
        admin:          set to true if this is an admin action
        loglvl:         an optional level - messages with lower xa_log values will not be recorded
        
        Appends a line to the module's log file (found in the xa/logs directory).
        
        Includes ability to reference a specific player and also flag as an admin action
    """
    # Is logging enabled and does our module exist?
    if int(es.ServerVar('xa_log')) and int(es.ServerVar('xa_log')) >= loglvl and xa.exists(module):
        # Was a valid source userid specified?
        if userid and es.exists('userid', int(userid)):
            # Is this userid an admin?
            if admin:
                # Adming log
                logtext = '%s: Admin %s [%s]: %s' % (module, es.getplayername(userid), es.getplayersteamid(userid), text)
            
            else:
                # User log
                logtext = '%s: User %s [%s]: %s' % (module, es.getplayername(userid), es.getplayersteamid(userid), text)
            
        else:
            # Default log
            logtext = '%s: %s' % (module, text)
        
        # Create our log folder if it does not exist
        if not os.path.isdir('%s/logs' % xa.coredir()):
            os.mkdir('%s/logs' % xa.coredir())
        
        # Write to our log file
        logname = '%s/logs/l%s' % (xa.coredir(), time.strftime('%m%d000.log'))
        logfile = open(logname, 'a+')
        logfile.write(time.strftime('L %m/%d/%Y - %H:%M:%S: ') + logtext + '\n')
        logfile.close()
        
        # Write to the SRCDS log file
        es.log(logtext)
コード例 #18
0
def createCommandSpace(module, command, usage='', description=''):
    """
        Create a server command section in the cfg
        
        module:         module name (usually automatically provided)
        command:        the command
        usage:          usually a longer section of text describing usage
        description:    text description of the command
        
        return:         (bool) true (false if module does not exist)
    """
    # ensure the module exists
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Store the command instance into the module's command attribute
        module.commands[command] = Command(command, description, usage)
        return True
    return False
コード例 #19
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def createCommandSpace(module, command, usage='', description=''):
    """
        Create a server command section in the cfg
        
        module:         module name (usually automatically provided)
        command:        the command
        usage:          usually a longer section of text describing usage
        description:    text description of the command
        
        return:         (bool) true (false if module does not exist)
    """
    # ensure the module exists
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Store the command instance into the module's command attribute 
        module.commands[command] = Command(command, description, usage)
        return True
    return False
コード例 #20
0
def getVariable(module, variable):
    """
        Retrieve a ServerVar reference to variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar to retrieve
        
        return:         ServerVar instance (False if no variable or module)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)

        # Get the variable name
        variable = getVariableName(module, variable)

        # Did we get a valid variable name and is the variable assigned to our module?
        if variable in module.variables:
            # Return our existing variable instance
            return module.variables[variable]

    # Fallback, couldn't find variable instance
    return False
コード例 #21
0
ファイル: setting.py プロジェクト: StarsGame/source_addons
def getVariable(module, variable):
    """
        Retrieve a ServerVar reference to variable
        
        module:         module name (usually automatically provided)
        variable:       the name of the cvar to retrieve
        
        return:         ServerVar instance (False if no variable or module)
    """
    # Does the module exist?
    if xa.exists(module):
        # Find the module instance
        module = xa.find(module)
        
        # Get the variable name
        variable = getVariableName(module, variable)
        
        # Did we get a valid variable name and is the variable assigned to our module?
        if variable in module.variables:
            # Return our existing variable instance
            return module.variables[variable]

    # Fallback, couldn't find variable instance
    return False