def validate(self, scripts=None, obj=None, key=None, dbref=None,
                 init_mode=False):
        """
        This will step through the script database and make sure
        all objects run scripts that are still valid in the context
        they are in. This is called by the game engine at regular
        intervals but can also be initiated by player scripts.

        Only one of the arguments are supposed to be supplied
        at a time, since they are exclusive to each other.

        Args:
            scripts (list, optional): A list of script objects to
                validate.
            obj (Object, optional): Validate only scripts defined on
                this object.
            key (str): Validate only scripts with this key.
            dbref (int): Validate only the single script with this
                particular id.
            init_mode (str, optional): This is used during server
                upstart and can have three values:
                - `False` (no init mode). Called during run.
                - `"reset"` - server reboot. Kill non-persistent scripts
                - `"reload"` - server reload. Keep non-persistent scripts.
        Returns:
            nr_started, nr_stopped (tuple): Statistics on how many objects
                where started and stopped.

        Notes:
            This method also makes sure start any scripts it validates
            which should be harmless, since already-active scripts have
            the property 'is_running' set and will be skipped.

        """

        # we store a variable that tracks if we are calling a
        # validation from within another validation (avoids
        # loops).

        global VALIDATE_ITERATION
        if VALIDATE_ITERATION > 0:
            # we are in a nested validation. Exit.
            VALIDATE_ITERATION -= 1
            return None, None
        VALIDATE_ITERATION += 1

        # not in a validation - loop. Validate as normal.

        nr_started = 0
        nr_stopped = 0

        if init_mode:
            if init_mode == 'reset':
                # special mode when server starts or object logs in.
                # This deletes all non-persistent scripts from database
                nr_stopped += self.remove_non_persistent(obj=obj)
            # turn off the activity flag for all remaining scripts
            scripts = self.get_all_scripts()
            for script in scripts:
                script.is_active = False

        elif not scripts:
            # normal operation
            if dbref and self.dbref(dbref, reqhash=False):
                scripts = self.get_id(dbref)
            elif obj:
                scripts = self.get_all_scripts_on_obj(obj, key=key)
            else:
                scripts = self.get_all_scripts(key=key) #self.model.get_all_cached_instances()

        if not scripts:
            # no scripts available to validate
            VALIDATE_ITERATION -= 1
            return None, None

        for script in scripts:
            if script.is_valid():
                nr_started += script.start(force_restart=init_mode)
            else:
                script.stop()
                nr_stopped += 1
        VALIDATE_ITERATION -= 1
        return nr_started, nr_stopped
dataset/ETHPy150Open evennia/evennia/evennia/scripts/manager.py/ScriptDBManager.validate/original