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.

This commit is contained in:
Greg Taylor 2007-05-25 15:02:16 +00:00
parent f57ef16912
commit e7f8b901ce
4 changed files with 26 additions and 11 deletions

View file

@ -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):
"""

View file

@ -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):
"""

View file

@ -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}

View file

@ -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):
"""