Fixed various Script issues. Resolves #2010. Might affect #2006.

This commit is contained in:
Griatch 2020-01-18 20:50:26 +01:00
parent a9b4d8e826
commit 7f7dd3bbf2
5 changed files with 19 additions and 12 deletions

View file

@ -308,7 +308,7 @@ class CmdPy(COMMAND_DEFAULT_CLASS):
clientraw - turn off all client-specific escaping. Note that this may clientraw - turn off all client-specific escaping. Note that this may
lead to different output depending on prototocol (such as angular brackets lead to different output depending on prototocol (such as angular brackets
being parsed as HTML in the webclient but not in telnet clients) being parsed as HTML in the webclient but not in telnet clients)
noecho - in Python console mode, turn off the input echo (e.g. if your client noecho - in Python console mode, turn off the input echo (e.g. if your client
does this for you already) does this for you already)
Without argument, open a Python console in-game. This is a full console, Without argument, open a Python console in-game. This is a full console,
@ -429,13 +429,14 @@ def format_script_list(scripts):
nextrep = script.time_until_next_repeat() nextrep = script.time_until_next_repeat()
if nextrep is None: if nextrep is None:
nextrep = "PAUS" if script.db._paused_time else "--" nextrep = "PAUSED" if script.db._paused_time else "--"
else: else:
nextrep = "%ss" % nextrep nextrep = "%ss" % nextrep
maxrepeat = script.repeats maxrepeat = script.repeats
remaining = script.remaining_repeats() or 0
if maxrepeat: if maxrepeat:
rept = "%i/%i" % (maxrepeat - script.remaining_repeats(), maxrepeat) rept = "%i/%i" % (maxrepeat - remaining, maxrepeat)
else: else:
rept = "-/-" rept = "-/-"

View file

@ -298,6 +298,9 @@ class GametimeScript(DefaultScript):
def at_repeat(self): def at_repeat(self):
"""Call the callback and reset interval.""" """Call the callback and reset interval."""
from evennia.utils.utils import calledby
callback = self.db.callback callback = self.db.callback
if callback: if callback:
callback() callback()

View file

@ -69,7 +69,7 @@ class ExtendedLoopingCall(LoopingCall):
steps if we want. steps if we want.
""" """
assert not self.running, "Tried to start an already running " "ExtendedLoopingCall." assert not self.running, "Tried to start an already running ExtendedLoopingCall."
if interval < 0: if interval < 0:
raise ValueError("interval must be >= 0") raise ValueError("interval must be >= 0")
self.running = True self.running = True
@ -107,7 +107,8 @@ class ExtendedLoopingCall(LoopingCall):
if self.start_delay: if self.start_delay:
self.start_delay = None self.start_delay = None
self.starttime = self.clock.seconds() self.starttime = self.clock.seconds()
LoopingCall.__call__(self) if self._deferred:
LoopingCall.__call__(self)
def force_repeat(self): def force_repeat(self):
""" """
@ -118,7 +119,7 @@ class ExtendedLoopingCall(LoopingCall):
running. running.
""" """
assert self.running, "Tried to fire an ExtendedLoopingCall " "that was not running." assert self.running, "Tried to fire an ExtendedLoopingCall that was not running."
self.call.cancel() self.call.cancel()
self.call = None self.call = None
self.starttime = self.clock.seconds() self.starttime = self.clock.seconds()
@ -173,7 +174,8 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
) )
del self.db._paused_time del self.db._paused_time
del self.db._paused_repeats del self.db._paused_repeats
else:
elif not self.ndb._task.running:
# starting script anew # starting script anew
self.ndb._task.start(self.db_interval, now=not self.db_start_delay) self.ndb._task.start(self.db_interval, now=not self.db_start_delay)
@ -185,6 +187,7 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
task = self.ndb._task task = self.ndb._task
if task and task.running: if task and task.running:
task.stop() task.stop()
self.ndb._task = None
def _step_errback(self, e): def _step_errback(self, e):
""" """
@ -266,13 +269,13 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
self.db_key = cdict["key"] self.db_key = cdict["key"]
updates.append("db_key") updates.append("db_key")
if cdict.get("interval") and self.interval != cdict["interval"]: if cdict.get("interval") and self.interval != cdict["interval"]:
self.db_interval = cdict["interval"] self.db_interval = max(0, cdict["interval"])
updates.append("db_interval") updates.append("db_interval")
if cdict.get("start_delay") and self.start_delay != cdict["start_delay"]: if cdict.get("start_delay") and self.start_delay != cdict["start_delay"]:
self.db_start_delay = cdict["start_delay"] self.db_start_delay = cdict["start_delay"]
updates.append("db_start_delay") updates.append("db_start_delay")
if cdict.get("repeats") and self.repeats != cdict["repeats"]: if cdict.get("repeats") and self.repeats != cdict["repeats"]:
self.db_repeats = cdict["repeats"] self.db_repeats = max(0, cdict["repeats"])
updates.append("db_repeats") updates.append("db_repeats")
if cdict.get("persistent") and self.persistent != cdict["persistent"]: if cdict.get("persistent") and self.persistent != cdict["persistent"]:
self.db_persistent = cdict["persistent"] self.db_persistent = cdict["persistent"]

View file

@ -416,7 +416,7 @@ class Evennia(object):
yield [ yield [
(s.pause(manual_pause=False), s.at_server_reload()) (s.pause(manual_pause=False), s.at_server_reload())
for s in ScriptDB.get_all_cached_instances() for s in ScriptDB.get_all_cached_instances()
if s.is_active or s.attributes.has("_manual_pause") if s.id and (s.is_active or s.attributes.has("_manual_pause"))
] ]
yield self.sessions.all_sessions_portal_sync() yield self.sessions.all_sessions_portal_sync()
self.at_server_reload_stop() self.at_server_reload_stop()

View file

@ -255,11 +255,11 @@ def create_script(
if obj: if obj:
kwarg["db_obj"] = dbid_to_obj(obj, _ObjectDB) kwarg["db_obj"] = dbid_to_obj(obj, _ObjectDB)
if interval: if interval:
kwarg["db_interval"] = interval kwarg["db_interval"] = max(0, interval)
if start_delay: if start_delay:
kwarg["db_start_delay"] = start_delay kwarg["db_start_delay"] = start_delay
if repeats: if repeats:
kwarg["db_repeats"] = repeats kwarg["db_repeats"] = max(0, repeats)
if persistent: if persistent:
kwarg["db_persistent"] = persistent kwarg["db_persistent"] = persistent
if desc: if desc: