From 55cbe615e9bf2f162f2392c3bb125eef0a0190b0 Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 4 Aug 2014 17:09:16 +0200 Subject: [PATCH] Tested all multisession modes against unittests. Seems to work. --- src/commands/default/player.py | 6 +++--- src/objects/models.py | 19 ++++++++++--------- src/players/models.py | 4 ++-- src/settings_default.py | 18 ++++++++++-------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/commands/default/player.py b/src/commands/default/player.py index a6da780b23..486dca1a44 100644 --- a/src/commands/default/player.py +++ b/src/commands/default/player.py @@ -248,21 +248,21 @@ class CmdIC(MuxPlayerCommand): self.msg("That is not a valid character choice.") return # 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) return if new_character.player: # may not puppet an already puppeted character if new_character.sessid.count() and new_character.player == player: # 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" txt2 = "Sharing {c%s{n with another of your sessions." else: 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." + player.unpuppet_object(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) 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) diff --git a/src/objects/models.py b/src/objects/models.py index aa3ba6cbf2..1973ff6f31 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -29,6 +29,7 @@ from src.utils import logger from src.utils.utils import (make_iter, to_str, to_unicode, lazy_property, variable_from_module, dbref) +MULTISESSION_MODE = settings.MULTISESSION_MODE from django.utils.translation import ugettext as _ #__all__ = ("ObjectDB", ) @@ -42,7 +43,7 @@ _SA = object.__setattr__ _DA = object.__delattr__ # 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): """ @@ -55,7 +56,7 @@ class SessidHandler(object): self._recache() 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): "Returns a single integer or a list" @@ -64,12 +65,12 @@ class SessidHandler(object): def add(self, sessid): "Add sessid to handler" _cache = self._cache - if len(_cache) >= _SESSID_MAX: - return False - _cache.add(int(sessid)) - _SA(self.obj, "db_sessid", ",".join(str(val) for val in _cache)) - _GA(self.obj, "save")(update_fields=["db_sessid"]) - return True + if sessid not in _cache: + if len(_cache) >= _SESSID_MAX: + return + _cache.append(sessid) + _SA(self.obj, "db_sessid", ",".join(str(val) for val in _cache)) + _GA(self.obj, "save")(update_fields=["db_sessid"]) def remove(self, sessid): "Remove sessid from handler" @@ -81,7 +82,7 @@ class SessidHandler(object): def clear(self): "Clear sessids" - self._cache = set() + self._cache = [] _SA(self.obj, "db_sessid", None) _GA(self.obj, "save")(update_fields=["db_sessid"]) diff --git a/src/players/models.py b/src/players/models.py index 9e5e707596..7c45195176 100644 --- a/src/players/models.py +++ b/src/players/models.py @@ -247,9 +247,9 @@ class PlayerDB(TypedObject, AbstractUser): _GA(from_obj, "at_msg_send")(text=text, to_obj=_GA(self, "typeclass"), **kwargs) except Exception: 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: - for session in sessions: + for session in make_iter(sessions): obj = session.puppet if obj and not obj.at_msg_receive(text=text, **kwargs): # if hook returns false, cancel send diff --git a/src/settings_default.py b/src/settings_default.py index c12c5f1324..bfcbede955 100644 --- a/src/settings_default.py +++ b/src/settings_default.py @@ -306,7 +306,7 @@ BASE_SCRIPT_TYPECLASS = "src.scripts.scripts.DoNothing" DEFAULT_HOME = "#2" # The start position for new characters. Default is Limbo (#2). # 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" # Lookups of Attributes, Tags, Nicks, Aliases can be aggressively # 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 # 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. -# In modes 1,2 no default character will be created and the MAX_NR_CHARACTERS -# value (below) defines how many characters are allowed. +# In modes 2,3 no default character will be created and the MAX_NR_CHARACTERS +# 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 # connected, the old one is disconnected # 1 - multiple sessions, one player, one character, each session getting # the same data -# 2 - multiple sessions, one player, many characters, each session getting -# data from different characters +# 2 - multiple sessions, one player, many characters, one session per +# character (disconnects multiplets) +# 3 - like mode 2, except multiple sessions can puppet one character, each +# session getting the same data. MULTISESSION_MODE = 0 -# The maximum number of characters allowed for MULTISESSION_MODE 2. This is -# checked -# by the default ooc char-creation command. Forced to 1 for +# The maximum number of characters allowed for MULTISESSION_MODE 2,3. This is +# checked by the default ooc char-creation command. Forced to 1 for # MULTISESSION_MODE 0 and 1. MAX_NR_CHARACTERS = 1 # The access hiearchy, in climbing order. A higher permission in the