Tested all multisession modes against unittests. Seems to work.
This commit is contained in:
parent
1ffbc4b9f3
commit
55cbe615e9
4 changed files with 25 additions and 22 deletions
|
|
@ -248,21 +248,21 @@ class CmdIC(MuxPlayerCommand):
|
||||||
self.msg("That is not a valid character choice.")
|
self.msg("That is not a valid character choice.")
|
||||||
return
|
return
|
||||||
# permission checks
|
# permission checks
|
||||||
if player.get_puppjet(sessid) == new_character:
|
if player.get_puppet(sessid) == new_character:
|
||||||
self.msg("{RYou already act as {c%s{n." % new_character.name)
|
self.msg("{RYou already act as {c%s{n." % new_character.name)
|
||||||
return
|
return
|
||||||
if new_character.player:
|
if new_character.player:
|
||||||
# may not puppet an already puppeted character
|
# may not puppet an already puppeted character
|
||||||
if new_character.sessid.count() and new_character.player == player:
|
if new_character.sessid.count() and new_character.player == player:
|
||||||
# as a safeguard we allow "taking over" chars from your own sessions.
|
# as a safeguard we allow "taking over" chars from your own sessions.
|
||||||
if MULTISESSION_MODE == 3:
|
if MULTISESSION_MODE in (1, 3):
|
||||||
txt = "{c%s{n{G is now shared from another of your sessions.{n"
|
txt = "{c%s{n{G is now shared from another of your sessions.{n"
|
||||||
txt2 = "Sharing {c%s{n with another of your sessions."
|
txt2 = "Sharing {c%s{n with another of your sessions."
|
||||||
else:
|
else:
|
||||||
txt = "{c%s{n{R is now acted from another of your sessions.{n"
|
txt = "{c%s{n{R is now acted from another of your sessions.{n"
|
||||||
txt2 = "Taking over {c%s{n from another of your sessions."
|
txt2 = "Taking over {c%s{n from another of your sessions."
|
||||||
|
player.unpuppet_object(new_character.sessid.get())
|
||||||
player.msg(txt % (new_character.name), sessid=new_character.sessid.get())
|
player.msg(txt % (new_character.name), sessid=new_character.sessid.get())
|
||||||
player.unpuppet_object(new_character.sessid)
|
|
||||||
self.msg(txt2 % new_character.name)
|
self.msg(txt2 % new_character.name)
|
||||||
elif new_character.player != player and new_character.player.is_connected:
|
elif new_character.player != player and new_character.player.is_connected:
|
||||||
self.msg("{c%s{r is already acted by another player.{n" % new_character.name)
|
self.msg("{c%s{r is already acted by another player.{n" % new_character.name)
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ from src.utils import logger
|
||||||
from src.utils.utils import (make_iter, to_str, to_unicode, lazy_property,
|
from src.utils.utils import (make_iter, to_str, to_unicode, lazy_property,
|
||||||
variable_from_module, dbref)
|
variable_from_module, dbref)
|
||||||
|
|
||||||
|
MULTISESSION_MODE = settings.MULTISESSION_MODE
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
#__all__ = ("ObjectDB", )
|
#__all__ = ("ObjectDB", )
|
||||||
|
|
@ -42,7 +43,7 @@ _SA = object.__setattr__
|
||||||
_DA = object.__delattr__
|
_DA = object.__delattr__
|
||||||
|
|
||||||
# the sessid_max is based on the length of the db_sessid csv field (excluding commas)
|
# the sessid_max is based on the length of the db_sessid csv field (excluding commas)
|
||||||
_SESSID_MAX = 16 if settings.MULTISESSION_MODE > 2 else 1
|
_SESSID_MAX = 16 if MULTISESSION_MODE in (1, 3) else 1
|
||||||
|
|
||||||
class SessidHandler(object):
|
class SessidHandler(object):
|
||||||
"""
|
"""
|
||||||
|
|
@ -55,7 +56,7 @@ class SessidHandler(object):
|
||||||
self._recache()
|
self._recache()
|
||||||
|
|
||||||
def _recache(self):
|
def _recache(self):
|
||||||
self._cache = set(int(val) for val in (_GA(self.obj, "db_sessid") or "").split(",") if val)
|
self._cache = list(set(int(val) for val in (_GA(self.obj, "db_sessid") or "").split(",") if val))
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
"Returns a single integer or a list"
|
"Returns a single integer or a list"
|
||||||
|
|
@ -64,12 +65,12 @@ class SessidHandler(object):
|
||||||
def add(self, sessid):
|
def add(self, sessid):
|
||||||
"Add sessid to handler"
|
"Add sessid to handler"
|
||||||
_cache = self._cache
|
_cache = self._cache
|
||||||
if len(_cache) >= _SESSID_MAX:
|
if sessid not in _cache:
|
||||||
return False
|
if len(_cache) >= _SESSID_MAX:
|
||||||
_cache.add(int(sessid))
|
return
|
||||||
_SA(self.obj, "db_sessid", ",".join(str(val) for val in _cache))
|
_cache.append(sessid)
|
||||||
_GA(self.obj, "save")(update_fields=["db_sessid"])
|
_SA(self.obj, "db_sessid", ",".join(str(val) for val in _cache))
|
||||||
return True
|
_GA(self.obj, "save")(update_fields=["db_sessid"])
|
||||||
|
|
||||||
def remove(self, sessid):
|
def remove(self, sessid):
|
||||||
"Remove sessid from handler"
|
"Remove sessid from handler"
|
||||||
|
|
@ -81,7 +82,7 @@ class SessidHandler(object):
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
"Clear sessids"
|
"Clear sessids"
|
||||||
self._cache = set()
|
self._cache = []
|
||||||
_SA(self.obj, "db_sessid", None)
|
_SA(self.obj, "db_sessid", None)
|
||||||
_GA(self.obj, "save")(update_fields=["db_sessid"])
|
_GA(self.obj, "save")(update_fields=["db_sessid"])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -247,9 +247,9 @@ class PlayerDB(TypedObject, AbstractUser):
|
||||||
_GA(from_obj, "at_msg_send")(text=text, to_obj=_GA(self, "typeclass"), **kwargs)
|
_GA(from_obj, "at_msg_send")(text=text, to_obj=_GA(self, "typeclass"), **kwargs)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
sessions = _MULTISESSION_MODE > 1 and [sessid] and make_iter(_GA(self, "get_session")(sessid)) or None
|
sessions = _MULTISESSION_MODE > 1 and sessid and _GA(self, "get_session")(sessid) or None
|
||||||
if sessions:
|
if sessions:
|
||||||
for session in sessions:
|
for session in make_iter(sessions):
|
||||||
obj = session.puppet
|
obj = session.puppet
|
||||||
if obj and not obj.at_msg_receive(text=text, **kwargs):
|
if obj and not obj.at_msg_receive(text=text, **kwargs):
|
||||||
# if hook returns false, cancel send
|
# if hook returns false, cancel send
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ BASE_SCRIPT_TYPECLASS = "src.scripts.scripts.DoNothing"
|
||||||
DEFAULT_HOME = "#2"
|
DEFAULT_HOME = "#2"
|
||||||
# The start position for new characters. Default is Limbo (#2).
|
# The start position for new characters. Default is Limbo (#2).
|
||||||
# MULTISESSION_MODE = 0, 1 - used by default unloggedin create command
|
# MULTISESSION_MODE = 0, 1 - used by default unloggedin create command
|
||||||
# MULTISESSION_MODE = 2 - used by default character_create command
|
# MULTISESSION_MODE = 2,3 - used by default character_create command
|
||||||
START_LOCATION = "#2"
|
START_LOCATION = "#2"
|
||||||
# Lookups of Attributes, Tags, Nicks, Aliases can be aggressively
|
# Lookups of Attributes, Tags, Nicks, Aliases can be aggressively
|
||||||
# cached to avoid repeated database hits. This often gives noticeable
|
# cached to avoid repeated database hits. This often gives noticeable
|
||||||
|
|
@ -352,18 +352,20 @@ TIME_MONTH_PER_YEAR = 12
|
||||||
# Different Multisession modes allow a player (=account) to connect to the
|
# Different Multisession modes allow a player (=account) to connect to the
|
||||||
# game simultaneously with multiple clients (=sessions). In modes 0,1 there is
|
# game simultaneously with multiple clients (=sessions). In modes 0,1 there is
|
||||||
# only one character created to the same name as the account at first login.
|
# only one character created to the same name as the account at first login.
|
||||||
# In modes 1,2 no default character will be created and the MAX_NR_CHARACTERS
|
# In modes 2,3 no default character will be created and the MAX_NR_CHARACTERS
|
||||||
# value (below) defines how many characters are allowed.
|
# value (below) defines how many characters the default char_create command
|
||||||
|
# allow per player.
|
||||||
# 0 - single session, one player, one character, when a new session is
|
# 0 - single session, one player, one character, when a new session is
|
||||||
# connected, the old one is disconnected
|
# connected, the old one is disconnected
|
||||||
# 1 - multiple sessions, one player, one character, each session getting
|
# 1 - multiple sessions, one player, one character, each session getting
|
||||||
# the same data
|
# the same data
|
||||||
# 2 - multiple sessions, one player, many characters, each session getting
|
# 2 - multiple sessions, one player, many characters, one session per
|
||||||
# data from different characters
|
# character (disconnects multiplets)
|
||||||
|
# 3 - like mode 2, except multiple sessions can puppet one character, each
|
||||||
|
# session getting the same data.
|
||||||
MULTISESSION_MODE = 0
|
MULTISESSION_MODE = 0
|
||||||
# The maximum number of characters allowed for MULTISESSION_MODE 2. This is
|
# The maximum number of characters allowed for MULTISESSION_MODE 2,3. This is
|
||||||
# checked
|
# checked by the default ooc char-creation command. Forced to 1 for
|
||||||
# by the default ooc char-creation command. Forced to 1 for
|
|
||||||
# MULTISESSION_MODE 0 and 1.
|
# MULTISESSION_MODE 0 and 1.
|
||||||
MAX_NR_CHARACTERS = 1
|
MAX_NR_CHARACTERS = 1
|
||||||
# The access hiearchy, in climbing order. A higher permission in the
|
# The access hiearchy, in climbing order. A higher permission in the
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue