From 5464487c93c770056e544928b675a3b2cfa319ec Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 21 Feb 2011 12:56:44 +0000 Subject: [PATCH] Server module should be accessed through proxy, i.e. through the sessionhandler, at all times. Resolves issue 127. Script updates made @ps non-compatible, fixed the formatting. Resolves issue 128. --- src/commands/default/system.py | 33 ++++++++++++++++++--------------- src/commands/default/tests.py | 8 +++++++- src/server/server.py | 3 +++ src/server/sessionhandler.py | 3 +++ 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/commands/default/system.py b/src/commands/default/system.py index 046f08af72..7b4369f045 100644 --- a/src/commands/default/system.py +++ b/src/commands/default/system.py @@ -432,7 +432,7 @@ class CmdShutdown(MuxCommand): announcement += "%s\n" % self.args logger.log_infomsg('Server shutdown by %s.' % self.caller.name) SESSIONS.announce_all(announcement) - sessions.server.shutdown() + SESSIONS.server.shutdown() class CmdVersion(MuxCommand): """ @@ -626,26 +626,29 @@ class CmdPs(MuxCommand): def func(self): "run the function." - string = "Processes Scheduled:\n-- PID [time/interval] [repeats] description --" all_scripts = ScriptDB.objects.get_all_scripts() - repeat_scripts = [script for script in all_scripts if script.interval] - nrepeat_scripts = [script for script in all_scripts if script not in repeat_scripts] - - string = "\nNon-timed scripts:" - for script in nrepeat_scripts: - string += "\n %i %s %s" % (script.id, script.key, script.desc) + repeat_scripts = [script for script in all_scripts if script.interval > 0] + nrepeat_scripts = [script for script in all_scripts if script.interval <= 0] - string += "\n\nTimed scripts:" + string = "\n{wNon-timed scripts:{n -- PID name desc --" + if not nrepeat_scripts: + string += "\n " + for script in nrepeat_scripts: + string += "\n {w%i{n %s %s" % (script.id, script.key, script.desc) + + string += "\n{wTimed scripts:{n -- PID name [time/interval][repeats] desc --" + if not repeat_scripts: + string += "\n " for script in repeat_scripts: repeats = "[inf] " if script.repeats: repeats = "[%i] " % script.repeats - string += "\n %i %s [%d/%d] %s%s" % (script.id, script.key, - script.time_until_next_repeat(), - script.interval, - repeats, - script.desc) - string += "\nTotals: %d interval scripts" % len(all_scripts) + time_next = "[inf/inf]" + if script.time_until_next_repeat() != None: + time_next = "[%d/%d]" % (script.time_until_next_repeat(), script.interval) + string += "\n {w%i{n %s %s%s%s" % (script.id, script.key, + time_next, repeats, script.desc) + string += "\n{wTotal{n: %d scripts." % len(all_scripts) self.caller.msg(string) class CmdStats(MuxCommand): diff --git a/src/commands/default/tests.py b/src/commands/default/tests.py index b5298449a1..21814421ec 100644 --- a/src/commands/default/tests.py +++ b/src/commands/default/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ ** OBS - this is not a normal command module! ** - ** You cannot import anythin in this module as a command! ** + ** You cannot import anything in this module as a command! ** This is part of the Evennia unittest framework, for testing the stability and integrity of the codebase during updates. This module @@ -43,6 +43,8 @@ class FakeSession(session.Session): def lineReceived(self, raw_string): pass def msg(self, message, data=None): + if message.startswith("Traceback (most recent call last):"): + raise AssertionError(message) if VERBOSE: print message @@ -121,3 +123,7 @@ class TestNick(CommandTest): def test_call(self): self.execute_cmd("nickname testalias = testaliasedstring") self.assertEquals("testaliasedstring", self.char1.nicks.get("testalias", None)) +# system.py tests +class TestPs(CommandTest): + def test_call(self): + self.execute_cmd("@ps") diff --git a/src/server/server.py b/src/server/server.py index 3d384419cc..6dfe71b8c6 100644 --- a/src/server/server.py +++ b/src/server/server.py @@ -78,6 +78,9 @@ class Evennia(object): # we have to null this here. SESSIONS.session_count(0) + # we link ourself to the sessionhandler so other modules don't have to + # re-import the server module itself (which would re-initialize it). + SESSIONS.server = self self.start_time = time.time() diff --git a/src/server/sessionhandler.py b/src/server/sessionhandler.py index ddf66b3e05..a99ab98d9e 100644 --- a/src/server/sessionhandler.py +++ b/src/server/sessionhandler.py @@ -47,6 +47,9 @@ class SessionHandler(object): self.unloggedin = [] self.loggedin = [] + # we keep a link to the server here, for the rest of the game to access. + self.server = None + def add_unloggedin_session(self, session): """ Call at first connect. This adds a not-yet authenticated session.