Esempio n. 1
0
def increment(variable, silent=False):
	"""
	Increases the reference count of a variable by one.
	"""
	name = variable.getName()
	count = 1
	if name in _variables:
		_variables[name]["count"] += 1
		count = _variables[name]["count"]
	else:
		_variables[name]["count"] = 1
		_variables[name]["oldValue"] = str(variable)

	if silent:
		es.forcevalue(name, 1)
	else:
		variable.set(1)

	es.dbgmsg(1, 'refcount: Variable "%s" has a reference count of "%d".' % (name, count))
Esempio n. 2
0
def decrement(variable, silent=False):
	"""
	Decreases the reference count of a variable by one.
	"""
	name = variable.getName()
	if name not in _variables:
		raise ReferenceError(name + " has a reference count of 0.")

	# Decrease the reference count for the variable.
	_variables[name]["count"] -= 1
	count = _variables[name]["count"]
	if 0 == count:
		if silent:
			es.forcevalue(name, _variables[name]["oldValue"])
		else:
			variable.set(_variables[name]["oldValue"])
		del _variables[name]

	es.dbgmsg(1, 'refcount: Variable "%s" has a reference count of "%d".' % (name, count))
Esempio n. 3
0
    def _reload_addons(self):
        '''Reloads addons on GunGame load'''

        # Allow server_cvar to be called
        self._files_have_been_executed = True

        # Loop through all valid addons
        for cvar in ValidAddons.all:

            # Get the current value
            value = str(es.ServerVar(cvar))

            # Does the cvar need reloaded?
            if value != '0':

                # Force the value back to 0 without calling server_cvar
                es.forcevalue(cvar, 0)

                # Set the value back to the current setting
                es.set(cvar, value)
Esempio n. 4
0
def forcevalue(argv):
  var, val = argv[:2]
  es.forcevalue(var, val)
  sv[var] = val
Esempio n. 5
0
def forcevalue(argv):
    var, val = argv[:2]
    es.forcevalue(var, val)
    sv[var] = val
Esempio n. 6
0
    def _server_cvar(self, event_var):
        '''Method used to check to see if addons need loaded/unloaded'''

        # Is this being called when the cvars are being created?
        if not ConfigManager._files_have_been_executed:

            # If so, return
            # The cvar should be called again once the .cfg files are executed
            return

        # Get the cvar and value
        cvarname = event_var['cvarname']
        cvarvalue = event_var['cvarvalue']

        # Is the cvar the cvar for an addon?
        if not cvarname in ValidAddons.all:

            # If not, simply return
            return

        # Is the value not equal to 0 (including floats) or ''?
        if self._is_enable_value(cvarvalue):

            # Is the addon already loaded?
            if cvarname in LoadedAddons:

                # Is the addon a dependent addon?
                if cvarname in DependentAddons:

                    # Was the addon recently set to be loaded by a depender?
                    if not cvarname in DependentAddons.recently_added:

                        # If not, set the addon to remain loaded
                        # when no other addons depend upon it
                        DependentAddons[cvarname].remain_loaded = True

                # The addon is already loaded, so return
                return

            # Load the addon
            AddonQueue.add_to_queue('load', cvarname)

        # Unload addons with the value of 0 (including floats) or ''
        else:

            # Is the addon loaded?
            if not cvarname in LoadedAddons:

                # If not, simply return
                return

            # Is the addon depended upon by other addons?
            if cvarname in DependentAddons:

                # Mark the addon as needing to be
                # unloaded when no addons depend upon it
                DependentAddons[cvarname].remain_loaded = False

                # Force the value back to 1
                es.forcevalue(cvarname, 1)

                # Return, since we do not want to unload the dependent addon
                return

            # Unload the addon
            AddonQueue.add_to_queue('unload', cvarname)
Esempio n. 7
0
    def _load_addons(self):
        '''Attempts to load all addons in the load queue'''

        # Create an empty dictionary to store addon instances
        self._current_instances = {}

        # Loop through all addons in the load queue
        for addon in self.load:

            # Add the addons instance to the dictionary
            self._add_addon_instance(addon)

        # Added using a try/except to reset all cvars back to 0
        try:

            # Loop through all addon instances
            for addon in self._current_instances:

                # Is the addon listed as a conflict?
                if addon in AddonConflicts:

                    # If so, raise an error about the conflict
                    raise ConflictError(
                        'Sub-addon "%s" can not be loaded.' % addon +
                        '  It is listed as a conflict with Sub-addon(s) ' +
                        '"%s"' % '", "'.join(list(AddonConflicts[addon])))

                # Loop through all conflicts for the current addon
                for conflict in self._current_instances[addon].info.conflicts:

                    # Is the conflict already loaded?
                    if conflict in LoadedAddons:

                        # If so, raise an error
                        raise ConflictError(
                            'Sub-addon "%s" can not be loaded.' % addon +
                            '  Sub-addon "%s" ' % conflict +
                            'is loaded and is listed as a conflict.')

                    # Is the conflict going to be loaded?
                    if conflict in self._current_instances:

                        # If so, raise an error
                        raise ConflictError(
                            'Sub-addon "%s" can not be loaded.' % addon +
                            '  Sub-addon "%s" is set ' % conflict +
                            'to be loaded as well and is listed as a conflict')

        # Did an exception occur?
        except:

            # Loop through all addons in the queue
            for addon in self.load:

                # Force the cvar back to 0
                es.forcevalue(addon, 0)

            # Clear the dictionary
            self._finish()

            # Finish by raising the error
            raise

        # Everything went well if getting to this point
        # Loop through all addons in the load queue
        for addon in self.load:

            # Has the addon been loaded as a dependency?
            if addon in DependentAddons:

                # Make sure the addon is set to remain
                # loaded when no more dependers exist
                DependentAddons[addon].remain_loaded = True

                # Do not re-attempt to load the addon
                continue

            # Load the addon
            AddonManager()._load_addon(addon)