Ejemplo n.º 1
0
    def add(self, scriptclass, key=None, autostart=True):
        """
        Add an script to this object.

        scriptclass - either a class object
             inheriting from Script, an instantiated script object
             or a python path to such a class object.
        key - optional identifier for the script (often set in script
              definition)
        autostart - start the script upon adding it
        """
        if self.obj.dbobj.__class__.__name__ == "PlayerDB":
            # we add to a Player, not an Object
            script = create.create_script(scriptclass,
                                          key=key,
                                          player=self.obj,
                                          autostart=autostart)
        else:
            # the normal - adding to an Object
            script = create.create_script(scriptclass,
                                          key=key,
                                          obj=self.obj,
                                          autostart=autostart)
        if not script:
            logger.log_errmsg(
                "Script %s could not be created and/or started." % scriptclass)
            return False
        return True
Ejemplo n.º 2
0
    def setUp(self):
        "sets up testing environment"
        settings.DEFAULT_HOME = "#2"
        #print "creating player %i: %s" % (self.CID, self.__class__.__name__)
        self.player = create.create_player("TestPlayer%i" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass)
        self.player2 = create.create_player("TestPlayer%ib" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass)
        self.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID, nohome=True)
        self.room1.db.desc = "room_desc"
        self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID)
        self.obj1 = create.create_object(TestObjectClass, key="Obj%i" % self.CID, location=self.room1, home=self.room1)
        self.obj2 = create.create_object(TestObjectClass, key="Obj%ib" % self.CID, location=self.room1, home=self.room1)
        self.char1 = create.create_object(TestCharacterClass, key="Char%i" % self.CID, location=self.room1, home=self.room1)
        self.char1.permissions.add("Immortals")
        self.char2 = create.create_object(TestCharacterClass, key="Char%ib" % self.CID, location=self.room1, home=self.room1)
        self.char1.player = self.player
        self.char2.player = self.player2
        self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID)
        self.player.permissions.add("Immortals")

        # set up a fake session

        global SESSIONS
        session = ServerSession()
        session.init_session("telnet", ("localhost", "testmode"), SESSIONS)
        session.sessid = self.CID
        SESSIONS.portal_connect(session.get_sync_data())
        SESSIONS.login(SESSIONS.session_from_sessid(self.CID), self.player, testmode=True)
Ejemplo n.º 3
0
def init_gametime():
    """
    This is called once, when the server starts for the very first time.
    """
    # create the GameTime script and start it
    game_time = create_script(GameTime)
    game_time.start()
Ejemplo n.º 4
0
    def setUp(self):
        "sets up testing environment"
        settings.DEFAULT_HOME = "#2"
        # print "creating player %i: %s" % (self.CID, self.__class__.__name__)
        self.player = create.create_player(
            "TestPlayer%i" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass
        )
        self.player2 = create.create_player(
            "TestPlayer%ib" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass
        )
        self.room1 = create.create_object("src.objects.objects.Room", key="Room%i" % self.CID, nohome=True)
        self.room1.db.desc = "room_desc"
        self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID)
        self.obj1 = create.create_object(TestObjectClass, key="Obj%i" % self.CID, location=self.room1, home=self.room1)
        self.obj2 = create.create_object(TestObjectClass, key="Obj%ib" % self.CID, location=self.room1, home=self.room1)
        self.char1 = create.create_object(
            TestCharacterClass, key="Char%i" % self.CID, location=self.room1, home=self.room1
        )
        self.char1.permissions.add("Immortals")
        self.char2 = create.create_object(
            TestCharacterClass, key="Char%ib" % self.CID, location=self.room1, home=self.room1
        )
        self.char1.player = self.player
        self.char2.player = self.player2
        self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID)
        self.player.permissions.add("Immortals")

        # set up a fake session

        global SESSIONS
        session = ServerSession()
        session.init_session("telnet", ("localhost", "testmode"), SESSIONS)
        session.sessid = self.CID
        SESSIONS.portal_connect(session.get_sync_data())
        SESSIONS.login(SESSIONS.session_from_sessid(self.CID), self.player, testmode=True)
Ejemplo n.º 5
0
def init_gametime():
    """
    This is called once, when the server starts for the very first time.
    """
    # create the GameTime script and start it
    game_time = create_script(GameTime)
    game_time.start()
Ejemplo n.º 6
0
def debug_script(script_path, obj=None, auto_delete=True):
    """
    This function takes a script database object (ScriptDB) and tests
    all its hooks for syntax errors. Note that no run-time errors
    will be caught, only weird python syntax.

    script_path - the full path to the script typeclass module and class.

    """
    try:
        string = "Test-creating a new script of this type ... "
        scriptobj = create.create_script(script_path, autostart=False)
        scriptobj.obj = obj
        scriptobj.save()
        string += "{gOk{n."
    except Exception:
        string += trace()
        try: scriptobj.delete()
        except: pass
        return string 

    string += "\nRunning syntax check ..."
    try:
        string += "\nTesting syntax of at_script_creation(self) ... "
        ret = scriptobj.at_script_creation()
        string += "{gOk{n."
    except Exception:
        string += trace()
    try:
        string += "\nTesting syntax of is_valid(self) ... "
        ret = scriptobj.is_valid()
        string += "{gOk{n."
    except Exception:
        string += trace()        
    try:
        string += "\nTesting syntax of at_start(self) ... "
        ret = scriptobj.at_start()
        string += "{gOk{n."
    except Exception:
        string += trace()
    try:
        string += "\nTesting syntax of at_repeat(self) ... "
        ret = scriptobj.at_repeat()
        string += "{gOk{n."
    except Exception:
        string += trace()
    try:
        string += "\nTesting syntax of at_stop(self) ... "
        ret =  scriptobj.at_script_creation()
        string += "{gOk{n."
    except Exception:
        string += trace()

    if auto_delete:
        try: 
            scriptobj.delete()
        except: 
            string += trace()

    return string
Ejemplo n.º 7
0
 def test_deleted_script_fails_start(self):
     "Would it ever be necessary to start a deleted script?"
     self.scr.delete()
     with self.assertRaises(ObjectDoesNotExist):  # See issue #509
         self.scr.start()
     # Check the script is not recreated as a side-effect
     self.assertFalse(self.scr in ScriptDB.objects.get_all_scripts())
     self.scr = create_script(DoNothing)  # for tearDown()
Ejemplo n.º 8
0
def create_system_scripts():
    """
    Setup the system repeat scripts. They are automatically started
    by the create_script function.
    """
    from src.scripts import scripts

    print " Creating and starting global scripts ..."

    # check so that all sessions are alive.
    script1 = create.create_script(scripts.CheckSessions)
    # validate all scripts in script table.
    script2 = create.create_script(scripts.ValidateScripts)
    # update the channel handler to make sure it's in sync
    script3 = create.create_script(scripts.ValidateChannelHandler)
    if not script1 or not script2 or not script3:
        print " Error creating system scripts."
Ejemplo n.º 9
0
 def test_deleted_script_fails_start(self):
     "Would it ever be necessary to start a deleted script?"
     self.scr.delete()
     with self.assertRaises(ObjectDoesNotExist):  # See issue #509
         self.scr.start()
     # Check the script is not recreated as a side-effect
     self.assertFalse(self.scr in ScriptDB.objects.get_all_scripts())
     self.scr = create_script(DoNothing)  # for tearDown()
Ejemplo n.º 10
0
def create_system_scripts():
    """
    Setup the system repeat scripts. They are automatically started
    by the create_script function.
    """
    from src.scripts import scripts

    print " Creating and starting global scripts ..."

    # check so that all sessions are alive.
    script1 = create.create_script(scripts.CheckSessions)
    # validate all scripts in script table.
    script2 = create.create_script(scripts.ValidateScripts)
    # update the channel handler to make sure it's in sync
    script3 = create.create_script(scripts.ValidateChannelHandler)
    if not script1 or not script2 or not script3:
        print " Error creating system scripts."
Ejemplo n.º 11
0
 def add(self, store_key, sessid, func_key, interval, *args, **kwargs):
     """
     Add a new tracking
     """
     if interval not in self.scripts:
         # if no existing interval exists, create new script to fill the gap
         new_tracker = create_script(_RepeaterScript,
                        key="oob_repeater_%is" % interval, interval=interval)
         self.scripts[interval] = new_tracker
     self.scripts[interval].subscribe(store_key, sessid, func_key,
                                                   interval, *args, **kwargs)
Ejemplo n.º 12
0
    def copy_script(self, original_script, new_key=None, new_obj=None, new_locks=None):
        """
        Make an identical copy of the original_script
        """
        typeclass = original_script.typeclass_path
        new_key = new_key if new_key!=None else original_script.key
        new_obj = new_obj if new_obj!=None else original_script.obj
        new_locks = new_locks if new_locks!=None else original_script.db_lock_storage

        from src.utils import create
        new_script = create.create_script(typeclass, key=new_key, obj=new_obj, locks=new_locks, autostart=True)
        return new_script
Ejemplo n.º 13
0
    def add(self, scriptclass, key=None, autostart=True):
        """
        Add an script to this object.

        scriptclass - either a class object
             inheriting from Script, an instantiated script object
             or a python path to such a class object.
        key - optional identifier for the script (often set in script
              definition)
        autostart - start the script upon adding it
        """
        if self.obj.dbobj.__class__.__name__ == "PlayerDB":
            # we add to a Player, not an Object
            script = create.create_script(scriptclass, key=key, player=self.obj,
                                          autostart=autostart)
        else:
            # the normal - adding to an Object
            script = create.create_script(scriptclass, key=key, obj=self.obj,
                                      autostart=autostart)
        if not script:
            logger.log_errmsg("Script %s could not be created and/or started." % scriptclass)
            return False
        return True
Ejemplo n.º 14
0
    def add(self, scriptclass, key=None, autostart=True):
        """
        Add an script to this object.

        scriptclass - either a class object
             inheriting from Script, an instantiated script object
             or a python path to such a class object.
        key - optional identifier for the script (often set in script definition)
        autostart - start the script upon adding it
        """
        script = create.create_script(scriptclass, key=key, obj=self.obj, autostart=autostart)
        if not script:
            logger.log_errmsg("Script %s could not be created and/or started." % scriptclass)
            return False
        return True
Ejemplo n.º 15
0
def start_scripts(validate=False):
    """
    Start all the needed scripts
    """

    if validate:
        from src.scripts.models import ScriptDB
        ScriptDB.objects.validate()
        return
    if not search.scripts("IMC2_Send_IsAlive"):
        create.create_script(Send_IsAlive)
    if not search.scripts("IMC2_Send_Keepalive_Request"):
        create.create_script(Send_Keepalive_Request)
    if not search.scripts("IMC2_Prune_Inactive_Muds"):
        create.create_script(Prune_Inactive_Muds)
    if not search.scripts("IMC2_Sync_Server_Channel_List"):
        create.create_script(Sync_Server_Channel_List)
Ejemplo n.º 16
0
 def setUp(self):
     "sets up testing environment"
     self.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID)
     self.room1.db.desc = "room_desc"
     self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib"%self.CID)
     self.obj1 = create.create_object("src.objects.objects.Object", key="Obj%i"%self.CID, location=self.room1, home=self.room1)
     self.obj2 = create.create_object("src.objects.objects.Object", key="Obj%ib"%self.CID, location=self.room1, home=self.room1)
     self.player = create.create_player("TestPlayer%i"%self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayer, create_character=False)
     self.caller = create.create_player("Caller%i"%self.CID, "*****@*****.**", "testpassword", player_dbobj=self.player.dbobj,
                                        character_typeclass="src.objects.objects.Character",
                                        permissions=["Immortals"], character_home=self.room1, character_location=self.room1)
     self.caller.player = self.player
     self.char = create.create_player("Char%i"%self.CID, "*****@*****.**", "testpassword2", typeclass=TestPlayer,
                                      character_typeclass="src.objects.objects.Character",
                                      permissions=["Immortals"], character_home=self.room1, character_location=self.room1)
     self.char = create.create_script("src.scripts.scripts.Script", key="Script%i"%self.CID)
Ejemplo n.º 17
0
    def setUp(self):
        "sets up testing environment"
        self.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID)
        self.room1.db.desc = "room_desc"
        self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID)
        self.obj1 = create.create_object("src.objects.objects.Object", key="Obj%i" % self.CID, location=self.room1, home=self.room1)
        self.obj2 = create.create_object("src.objects.objects.Object", key="Obj%ib" % self.CID, location=self.room1, home=self.room1)
        self.char1 = create.create_object("src.objects.objects.Character", key="Char%i" % self.CID, location=self.room1, home=self.room1)
        self.char2 = create.create_object("src.objects.objects.Character", key="Char%ib" % self.CID, location=self.room1, home=self.room1)
        self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID)
        self.player = create.create_player("TestPlayer%i" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass)
        self.player2 = create.create_player("TestPlayer%ib" % self.CID, "*****@*****.**", "testpassword", typeclass=TestPlayerClass)

        self.player.permissions = "Immortals"
        self.char1.player = self.player
        self.char1.sessid = 1
Ejemplo n.º 18
0
    def copy_script(self,
                    original_script,
                    new_key=None,
                    new_obj=None,
                    new_locks=None):
        """
        Make an identical copy of the original_script
        """
        typeclass = original_script.typeclass_path
        new_key = new_key if new_key is not None else original_script.key
        new_obj = new_obj if new_obj is not None else original_script.obj
        new_locks = new_locks if new_locks is not None else original_script.db_lock_storage

        from src.utils import create
        new_script = create.create_script(typeclass,
                                          key=new_key,
                                          obj=new_obj,
                                          locks=new_locks,
                                          autostart=True)
        return new_script
Ejemplo n.º 19
0
    def track_active(self, oobkey, func, interval=30, *args, **kwargs):
        """
        Create a tracking, re-use script with same interval if available,
        otherwise create a new one.

        args:
         oobkey - interval-unique identifier needed for removing tracking later
         func - function to call at interval seconds
            (all other args become argjs into func)
        keywords:
         interval (default 30s) - how often to update tracker
            (all other kwargs become kwargs into func)
        """
        if interval in self.track_active_subs:
            # tracker with given interval found. Add to its subs
            self.track_active_subs[interval].track(oobkey, func, *args, **kwargs)
        else:
            # create new tracker with given interval
            new_tracker = create.create_script(_OOBTracker, oobkey="oob_tracking_%i" % interval, interval=interval)
            new_tracker.track(oobkey, func, *args, **kwargs)
            self.track_active_subs[interval] = new_tracker
 def setUp(self):
     self.scr = create_script(DoNothing)
Ejemplo n.º 21
0
 def test_deleted_script_is_invalid(self):
     "Can deleted scripts be said to be valid?"
     self.scr.delete()
     self.assertFalse(self.scr.is_valid())  # assertRaises? See issue #509
     self.scr = create_script(DoNothing)  # for tearDown()
Ejemplo n.º 22
0
 def setUp(self):
     self.scr = create_script(DoNothing)
Ejemplo n.º 23
0
#HEADER
from src.utils.create import create_script

#CODE (Mobrunner Script)
create_script("game.gamesrc.scripts.world_scripts.global.MobRunner", obj=None)
#CODE (Irreglar Runner Script)
create_script("game.gamesrc.scripts.world_scripts.global.IrregularRunner", obj=None)
#CODE (Zone Runner Script)
create_script("game.gamesrc.scripts.world_scripts.global.ZoneRunner", obj=None)
#CODE (Npc Runner Script)
create_script("game.gamesrc.scripts.world_scripts.global.NpcRunner", obj=None)
#CODE (Lair Runner Script)
create_script("game.gamesrc.scripts.world_scripts.global.LairRunner", obj=None)

Ejemplo n.º 24
0
    def func(self):
        "implement method"

        caller = self.caller
        args = self.args

        string = ""
        if args:
            if "start" in self.switches:
                # global script-start mode
                new_script = create.create_script(args)
                if new_script:
                    caller.msg("Global script %s was started successfully." %
                               args)
                else:
                    caller.msg(
                        "Global script %s could not start correctly. See logs."
                        % args)
                return

            # test first if this is a script match
            scripts = ScriptDB.objects.get_all_scripts(key=args)
            if not scripts:
                # try to find an object instead.
                objects = ObjectDB.objects.object_search(args)
                if objects:
                    scripts = []
                    for obj in objects:
                        # get all scripts on the object(s)
                        scripts.extend(
                            ScriptDB.objects.get_all_scripts_on_obj(obj))
        else:
            # we want all scripts.
            scripts = ScriptDB.objects.get_all_scripts()
            if not scripts:
                caller.msg("No scripts are running.")
                return

        if not scripts:
            string = "No scripts found with a key '%s', or on an object named '%s'." % (
                args, args)
            caller.msg(string)
            return

        if self.switches and self.switches[0] in ('stop', 'del', 'delete',
                                                  'kill'):
            # we want to delete something
            if not scripts:
                string = "No scripts/objects matching '%s'. " % args
                string += "Be more specific."
            elif len(scripts) == 1:
                # we have a unique match!
                if 'kill' in self.switches:
                    string = "Killing script '%s'" % scripts[0].key
                    scripts[0].stop(kill=True)
                else:
                    string = "Stopping script '%s'." % scripts[0].key
                    scripts[0].stop()
                #import pdb
                #pdb.set_trace()
                ScriptDB.objects.validate()  #just to be sure all is synced
            else:
                # multiple matches.
                string = "Multiple script matches. Please refine your search:\n"
                string += format_script_list(scripts)
        elif self.switches and self.switches[0] in ("validate", "valid",
                                                    "val"):
            # run validation on all found scripts
            nr_started, nr_stopped = ScriptDB.objects.validate(scripts=scripts)
            string = "Validated %s scripts. " % ScriptDB.objects.all().count()
            string += "Started %s and stopped %s scripts." % (nr_started,
                                                              nr_stopped)
        else:
            # No stopping or validation. We just want to view things.
            string = format_script_list(scripts)
        caller.msg(string)
Ejemplo n.º 25
0
#HEADER
from src.utils.create import create_script
#CODE (Mobrunner)
create_script("game.gamesrc.scripts.world_scripts.global.MobRunner", obj=None)
#CODE (CharRunner)
create_script("game.gamesrc.scripts.world_scripts.global.CharacterRunner", obj=None)
#CODE (Zone Runner)
create_script("game.gamesrc.scripts.world_scripts.global.ZoneRunner", obj=None)
Ejemplo n.º 26
0
    def func(self):
        "implement method"

        caller = self.caller
        args = self.args

        string = ""
        if args:
            if "start" in self.switches:
                # global script-start mode
                new_script = create.create_script(args)
                if new_script:
                    caller.msg("Global script %s was started successfully." % args)
                else:
                    caller.msg("Global script %s could not start correctly. See logs." % args)
                return

            # test first if this is a script match
            scripts = ScriptDB.objects.get_all_scripts(key=args)
            if not scripts:
                # try to find an object instead.
                objects = ObjectDB.objects.object_search(args)
                if objects:
                    scripts = []
                    for obj in objects:
                        # get all scripts on the object(s)
                        scripts.extend(ScriptDB.objects.get_all_scripts_on_obj(obj))
        else:
            # we want all scripts.
            scripts = ScriptDB.objects.get_all_scripts()
            if not scripts:
                caller.msg("No scripts are running.")
                return

        if not scripts:
            string = "No scripts found with a key '%s', or on an object named '%s'." % (args, args)
            caller.msg(string)
            return

        if self.switches and self.switches[0] in ('stop', 'del', 'delete', 'kill'):
            # we want to delete something
            if not scripts:
                string = "No scripts/objects matching '%s'. " % args
                string += "Be more specific."
            elif len(scripts) == 1:
                # we have a unique match!
                if 'kill' in self.switches:
                    string = "Killing script '%s'" % scripts[0].key
                    scripts[0].stop(kill=True)
                else:
                    string = "Stopping script '%s'." % scripts[0].key
                    scripts[0].stop()
                #import pdb
                #pdb.set_trace()
                ScriptDB.objects.validate() #just to be sure all is synced
            else:
                # multiple matches.
                string = "Multiple script matches. Please refine your search:\n"
                string += format_script_list(scripts)
        elif self.switches and self.switches[0] in ("validate", "valid", "val"):
            # run validation on all found scripts
            nr_started, nr_stopped = ScriptDB.objects.validate(scripts=scripts)
            string = "Validated %s scripts. " % ScriptDB.objects.all().count()
            string += "Started %s and stopped %s scripts." % (nr_started, nr_stopped)
        else:
            # No stopping or validation. We just want to view things.
            string = format_script_list(scripts)
        caller.msg(string)
Ejemplo n.º 27
0
def at_server_start():
    pass
    create_script("src.utils.gametime.GameTime", obj=None)
Ejemplo n.º 28
0
#HEADER
from src.utils.create import create_script
#CODE (Mobrunner)
create_script("game.gamesrc.scripts.world_scripts.global.MobRunner", obj=None)
#CODE (CharRunner)
create_script("game.gamesrc.scripts.world_scripts.global.CharacterRunner",
              obj=None)
#CODE (Zone Runner)
create_script("game.gamesrc.scripts.world_scripts.global.ZoneRunner", obj=None)
Ejemplo n.º 29
0
 def test_deleted_script_is_invalid(self):
     "Can deleted scripts be said to be valid?"
     self.scr.delete()
     self.assertFalse(self.scr.is_valid())  # assertRaises? See issue #509
     self.scr = create_script(DoNothing)  # for tearDown()