Fixed so reloading the server reconnects the proper sessions to the characters again.

This commit is contained in:
Griatch 2013-02-17 13:59:36 +01:00
parent eb1044d7a1
commit 707a21c7d7
5 changed files with 28 additions and 36 deletions

View file

@ -432,6 +432,8 @@ class PlayerDB(TypedObject):
from src.server.sessionhandler import SESSIONS as _SESSIONS
_SESSIONS.disconnect(sessid=sessid)
def connect_session_to_character(self, sessid, character, force=False):
"""
Connect the given session to a character through this player.
@ -488,6 +490,22 @@ class PlayerDB(TypedObject):
set_prop_cache(self, "_characters", cache)
return char
def reconnect_session_to_character(self, sessid):
"""
Auto-re-connect a session to a character. This is called by the sessionhandler
during a server reload. It goes through the characters stored in this player's
db_objs many2many fields and checks if any of those has the given sessid
stored on themselves - if so they connect them. This should ONLY be called
automatically by sessionhandler after a reload - after a portal shutdown
the portal sessids will be out of sync with whatever is stored on character
objects which could lead to a session being linked to the wrong character.
"""
char = _GA(self, "get_character")(sessid=sessid, return_dbobj=True)
if not char:
print "No reconnecting character found"
return
self.connect_session_to_character(sessid, char, force=True)
def get_session(self, sessid):
"""
Return session with given sessid connected to this player.

View file

@ -27,16 +27,6 @@ from twisted.internet import protocol
from twisted.internet.defer import Deferred
from src.utils.utils import to_str, variable_from_module
# these are only needed on the server side, so we delay loading of them
# so as to not have to load them on the portal too. Note: It's doubtful
# if this really matters, considering many of the
# protocols require import of django components (at least settings).
#_ServerConfig = None
#_ScriptDB = None
#_PlayerDB = None
#_ServerSession = None
#_ = None #i18n hook
# communication bits
PCONN = chr(1) # portal session connect
@ -61,8 +51,8 @@ def get_restart_mode(restart_file):
class AmpServerFactory(protocol.ServerFactory):
"""
This factory creates new AMPProtocol protocol instances to use for accepting
connections from TCPServer.
This factory creates the Server as a new AMPProtocol instance for accepting
connections from the Portal.
"""
def __init__(self, server):
"""
@ -83,10 +73,7 @@ class AmpServerFactory(protocol.ServerFactory):
class AmpClientFactory(protocol.ReconnectingClientFactory):
"""
This factory creates new AMPProtocol protocol instances to use to connect
to the MUD server. It also maintains the portal attribute
on the ProxyService instance, which is used for piping input
from Telnet to the MUD server.
This factory creates an instance of the Portal, an AMPProtocol instances to use to connect
"""
# Initial reconnect delay in seconds.
initialDelay = 1

View file

@ -190,9 +190,6 @@ class Evennia(object):
from src.objects.models import ObjectDB
#from src.players.models import PlayerDB
# clear eventual lingering session storages
ObjectDB.objects.clear_all_sessids()
#update eventual changed defaults
self.update_defaults()
@ -209,6 +206,8 @@ class Evennia(object):
SERVER_STARTSTOP_MODULE.at_server_reload_start()
elif mode in ('reset', 'shutdown'):
SERVER_STARTSTOP_MODULE.at_server_cold_start()
# clear eventual lingering session storages
ObjectDB.objects.clear_all_sessids()
# always call this regardless of start type
SERVER_STARTSTOP_MODULE.at_server_start()
@ -231,20 +230,6 @@ class Evennia(object):
f.write(str(mode))
return mode
#if mode == None:
# f = open(SERVER_RESTART, 'r')
# if os.path.exists(SERVER_RESTART) and 'True' == f.read():
# mode = 'reload'
# else:
# mode = 'shutdown'
# f.close()
#else:
# restart = mode in ('reload', 'reset')
# f = open(SERVER_RESTART, 'w')
# f.write(str(restart))
# f.close()
#return mode
@defer.inlineCallbacks
def shutdown(self, mode=None, _reactor_stopping=False):
"""

View file

@ -56,6 +56,8 @@ class ServerSession(Session):
self.cmdset_storage = [settings.CMDSET_UNLOGGEDIN]
self.cmdset.update(init_mode=True)
return
else:
self.player.reconnect_session_to_character(self.sessid)
def session_login(self, player):
"""

View file

@ -181,7 +181,7 @@ class ServerSessionHandler(SessionHandler):
_ScriptDB.objects.validate(init_mode=init_mode)
_ServerConfig.objects.conf("server_restart_mode", delete=True)
# announce the reconnection
self.announce_all(_(" ... server restarted."))
self.announce_all(_(" ... Server restarted."))
def portal_shutdown(self):
"""
@ -431,8 +431,8 @@ class PortalSessionHandler(SessionHandler):
serversessions - dictionary {sessid:{property:value},...} describing the properties
to sync on all sessions
"""
to_save = [sessid for sessid, syncdata in serversessions if sessid in self.sessions]
to_delete = [sessid for sessid, syncdata in serversessions if sessid not in to_save]
to_save = [sessid for sessid in serversessions if sessid in self.sessions]
to_delete = [sessid for sessid in serversessions if sessid not in to_save]
# save protocols
for sessid in to_save:
self.sessions[sessid].load_sync_data(serversessions[sessid])