Fix MULTISESSION_MODE = 1

This commit is contained in:
Jonathan Piacenti 2015-02-26 17:46:28 -06:00 committed by Griatch
parent eda6cae1ef
commit 9733468098
3 changed files with 32 additions and 17 deletions

View file

@ -203,8 +203,8 @@ class DefaultPlayer(PlayerDB):
txt1 = "{c%s{n{R is now acted from another of your sessions.{n"
txt2 = "Taking over {c%s{n from another of your sessions."
self.unpuppet_object(obj.sessid.get())
self.msg(txt1 % obj.name, sessid=obj.sessid.get())
self.msg(txt2 % obj.name, sessid=sessid)
self.msg(txt1 % obj.name, sessid=obj.sessid.get(), _forced_nomulti=True)
self.msg(txt2 % obj.name, sessid=sessid, _forced_nomulti=True)
elif obj.player.is_connected:
# controlled by another player
raise RuntimeError("{R{c%s{R is already puppeted by another Player.")
@ -244,22 +244,24 @@ class DefaultPlayer(PlayerDB):
"""
if _MULTISESSION_MODE == 1:
sessions = self.get_all_sessions()
ignore_empty = True
else:
sessions = self.get_session(sessid)
ignore_empty = False
if not sessions:
raise RuntimeError("No session was found.")
for session in make_iter(sessions):
#print "unpuppet, session:", session, session.puppet
obj = hasattr(session, "puppet") and session.puppet or None
#print "unpuppet, obj:", obj
if not obj:
if not obj and not ignore_empty:
raise RuntimeError("No puppet was found to disconnect from.")
# do the disconnect, but only if we are the last session to puppet
obj.at_pre_unpuppet()
obj.sessid.remove(sessid)
if not obj.sessid.count():
del obj.player
obj.at_post_unpuppet(self, sessid=sessid)
elif obj:
# do the disconnect, but only if we are the last session to puppet
obj.at_pre_unpuppet()
obj.sessid.remove(session.sessid)
if not obj.sessid.count():
del obj.player
obj.at_post_unpuppet(self, sessid=sessid)
# Just to be sure we're always clear.
session.puppet = None
session.puid = None

View file

@ -10,7 +10,6 @@ are stored on the Portal side)
import time
from datetime import datetime
from django.conf import settings
#from evennia.scripts.models import ScriptDB
from evennia.comms.models import ChannelDB
from evennia.utils import logger
from evennia.utils.inlinefunc import parse_inlinefunc

View file

@ -446,15 +446,29 @@ class ServerSessionHandler(SessionHandler):
session will receive the rest of the data,
regardless of MULTISESSION_MODE. This is an
internal variable that will not be passed on.
This is ignored for MULTISESSION_MODE = 1,
since all messages are mirrored everywhere for
that.
_forced_nomulti (bool, optional): Like _nomulti,
but works even when MULTISESSION_MODE = 1.
Useful for connection handling messages.
"""
text = text and to_str(to_unicode(text), encoding=session.encoding)
multi = not kwargs.pop("_nomulti", None)
forced_nomulti = kwargs.pop("_forced_nomulti", None)
sessions = [session]
# Mode 1 mirrors to all.
if _MULTISESSION_MODE == 1:
if session.player:
sessions = self.sessions_from_player(session.player)
elif multi:
multi = True
# ...Unless we're absolutely sure.
if forced_nomulti:
multi = False
if multi:
if _MULTISESSION_MODE == 1:
if session.player:
sessions = self.sessions_from_player(session.player)
if _MULTISESSION_MODE == 2:
if session.player:
sessions = self.sessions_from_player(session.player)
@ -467,8 +481,8 @@ class ServerSessionHandler(SessionHandler):
# send to all found sessions
for session in sessions:
self.server.amp_protocol.call_remote_MsgServer2Portal(sessid=session.sessid,
msg=text,
data=kwargs)
msg=text,
data=kwargs)
def data_in(self, sessid, text="", **kwargs):
"""