Beispiel #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
Beispiel #2
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
Beispiel #3
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
Beispiel #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]
Beispiel #5
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]
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
Beispiel #7
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
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
Beispiel #9
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
Beispiel #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
Beispiel #11
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
Beispiel #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
Beispiel #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)
Beispiel #14
0
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
Beispiel #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
Beispiel #16
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
Beispiel #17
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)
Beispiel #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
Beispiel #19
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
Beispiel #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
Beispiel #21
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