From e7f8b901ce880728e7e5f3beac4919f2fb23b938 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Fri, 25 May 2007 15:02:16 +0000 Subject: [PATCH] Connection recovery is now in. You can only have one session active per account. This is just the safest and cleanest way to do things. Also made some misc. other changes that will probably go unnoticed. --- commands_privileged.py | 2 +- functions_general.py | 11 +++-------- session.py | 1 + session_mgr.py | 23 +++++++++++++++++++++-- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/commands_privileged.py b/commands_privileged.py index 85bc7086d2..7a9ad70275 100644 --- a/commands_privileged.py +++ b/commands_privileged.py @@ -668,7 +668,7 @@ def cmd_wall(cdat): return message = "%s shouts \"%s\"" % (session.get_pobject().get_name(show_dbref=False), wallstring) - functions_general.announce_all(message) + functions_general.announce_all(message) def cmd_shutdown(cdat): """ diff --git a/functions_general.py b/functions_general.py index a79ef3ff94..fc42fc699e 100644 --- a/functions_general.py +++ b/functions_general.py @@ -119,7 +119,7 @@ def time_format(seconds, style=0): retval = '%s%s%s%s' % (days_str, hours_str, minutes_str, seconds_str,) return retval -def announce_all(message, with_ann_prefix=True, with_nl=True): +def announce_all(message, with_ann_prefix=True): """ Announces something to all connected players. """ @@ -127,14 +127,9 @@ def announce_all(message, with_ann_prefix=True, with_nl=True): prefix = 'Announcement:' else: prefix = '' - - if with_nl: - newline = '\r\n' - else: - newline = '' - + for session in session_mgr.get_session_list(): - session.msg('%s %s%s' % (prefix, message,newline,)) + session.msg('%s %s' % (prefix, message)) def word_wrap(text, width=78): """ diff --git a/session.py b/session.py index 614078f904..6d00cb7f88 100755 --- a/session.py +++ b/session.py @@ -139,6 +139,7 @@ class SessionProtocol(StatefulTelnetProtocol): pobject = self.get_pobject() pobject.set_flag("CONNECTED", True) + session_mgr.disconnect_duplicate_session(self) self.msg("You are now logged in as %s." % (self.name,)) pobject.get_location().emit_to_contents("%s has connected." % (pobject.get_name(),), exclude=pobject) cdat = {"session": self, "uinput":'look', "server": self.factory.server} diff --git a/session_mgr.py b/session_mgr.py index 44967a217e..d21d15ce46 100644 --- a/session_mgr.py +++ b/session_mgr.py @@ -31,6 +31,21 @@ def disconnect_all_sessions(): for sess in get_session_list(): sess.handle_close() +def disconnect_duplicate_session(session): + """ + Disconnects any existing session under the same object. This is used in + connection recovery to help with record-keeping. + """ + sess_list = get_session_list() + new_pobj = session.get_pobject() + for sess in sess_list: + if new_pobj == sess.get_pobject() and sess != session: + sess.msg("Your account has been logged in from elsewhere, disconnecting.") + sess.disconnectClient() + return True + return False + + def check_all_sessions(): """ Check all currently connected sessions and see if any are dead. @@ -52,8 +67,12 @@ def remove_session(session): """ Removes a session from the session list. """ - session_list.remove(session) - print 'Sessions active:', len(get_session_list()) + try: + session_list.remove(session) + functions_general.log_infomsg('Sessions active: %d' % (len(get_session_list()),)) + except: + functions_general.log_errmsg("Unable to remove session: %s" % (session,)) + def session_from_object(targobject): """