Made unittests work with changed Session apis. Resolves #808.
This commit is contained in:
parent
efefe3e5ff
commit
45f973fdb6
8 changed files with 60 additions and 38 deletions
|
|
@ -318,8 +318,11 @@ class Command(with_metaclass(CommandMeta, object)):
|
||||||
"""
|
"""
|
||||||
from_obj = from_obj or self.caller
|
from_obj = from_obj or self.caller
|
||||||
to_obj = to_obj or from_obj
|
to_obj = to_obj or from_obj
|
||||||
if not session or to_obj == self.caller:
|
if not session:
|
||||||
session = to_obj.sessions.get()
|
if to_obj == self.caller:
|
||||||
|
session = self.session
|
||||||
|
else:
|
||||||
|
session = to_obj.sessions.get()
|
||||||
to_obj.msg(msg, from_obj=from_obj, session=session, **kwargs)
|
to_obj.msg(msg, from_obj=from_obj, session=session, **kwargs)
|
||||||
|
|
||||||
# Common Command hooks
|
# Common Command hooks
|
||||||
|
|
|
||||||
|
|
@ -1870,7 +1870,7 @@ class CmdExamine(ObjManipCommand):
|
||||||
string += "\n{wAliases{n: %s" % (", ".join(utils.make_iter(str(obj.aliases))))
|
string += "\n{wAliases{n: %s" % (", ".join(utils.make_iter(str(obj.aliases))))
|
||||||
if hasattr(obj, "sessions") and obj.sessions:
|
if hasattr(obj, "sessions") and obj.sessions:
|
||||||
string += "\n{wsession(s){n: %s" % (", ".join(str(sess.sessid)
|
string += "\n{wsession(s){n: %s" % (", ".join(str(sess.sessid)
|
||||||
for sess in obj.sessions))
|
for sess in obj.sessions.all()))
|
||||||
if hasattr(obj, "has_player") and obj.has_player:
|
if hasattr(obj, "has_player") and obj.has_player:
|
||||||
string += "\n{wPlayer{n: {c%s{n" % obj.player.name
|
string += "\n{wPlayer{n: {c%s{n" % obj.player.name
|
||||||
perms = obj.player.permissions.all()
|
perms = obj.player.permissions.all()
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,7 @@ class CmdSessions(MuxPlayerCommand):
|
||||||
def func(self):
|
def func(self):
|
||||||
"Implement function"
|
"Implement function"
|
||||||
player = self.player
|
player = self.player
|
||||||
sessions = player.get_all_sessions()
|
sessions = player.sessions.all()
|
||||||
|
|
||||||
table = prettytable.PrettyTable(["{wsessid",
|
table = prettytable.PrettyTable(["{wsessid",
|
||||||
"{wprotocol",
|
"{wprotocol",
|
||||||
|
|
@ -284,9 +284,8 @@ class CmdSessions(MuxPlayerCommand):
|
||||||
"{wpuppet/character",
|
"{wpuppet/character",
|
||||||
"{wlocation"])
|
"{wlocation"])
|
||||||
for sess in sorted(sessions, key=lambda x: x.sessid):
|
for sess in sorted(sessions, key=lambda x: x.sessid):
|
||||||
sessid = sess.sessid
|
char = player.get_puppet(sess)
|
||||||
char = player.get_puppet(sessid)
|
table.add_row([str(sess.sessid), str(sess.protocol_key),
|
||||||
table.add_row([str(sessid), str(sess.protocol_key),
|
|
||||||
type(sess.address) == tuple and sess.address[0] or sess.address,
|
type(sess.address) == tuple and sess.address[0] or sess.address,
|
||||||
char and str(char) or "None",
|
char and str(char) or "None",
|
||||||
char and str(char.location) or "N/A"])
|
char and str(char.location) or "N/A"])
|
||||||
|
|
@ -602,7 +601,7 @@ class CmdQuell(MuxPlayerCommand):
|
||||||
def _recache_locks(self, player):
|
def _recache_locks(self, player):
|
||||||
"Helper method to reset the lockhandler on an already puppeted object"
|
"Helper method to reset the lockhandler on an already puppeted object"
|
||||||
if self.session:
|
if self.session:
|
||||||
char = session.puppet
|
char = self.session.puppet
|
||||||
if char:
|
if char:
|
||||||
# we are already puppeting an object. We need to reset
|
# we are already puppeting an object. We need to reset
|
||||||
# the lock caches (otherwise the superuser status change
|
# the lock caches (otherwise the superuser status change
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class ObjectSessionHandler(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self._cache = set()
|
self._sessid_cache = set()
|
||||||
self._recache()
|
self._recache()
|
||||||
|
|
||||||
def _recache(self):
|
def _recache(self):
|
||||||
|
|
@ -149,8 +149,9 @@ class ObjectSessionHandler(object):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
sesslen (int): Number of sessions handled.
|
sesslen (int): Number of sessions handled.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return len(self._cache)
|
return len(self._sessid_cache)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -470,6 +471,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
||||||
|
|
||||||
# relay to session(s)
|
# relay to session(s)
|
||||||
sessions = make_iter(session) if session else self.sessions.all()
|
sessions = make_iter(session) if session else self.sessions.all()
|
||||||
|
from evennia.utils.utils import calledby
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
session.msg(text=text, **kwargs)
|
session.msg(text=text, **kwargs)
|
||||||
|
|
||||||
|
|
@ -478,8 +480,12 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
||||||
Runs a function on every object contained within this one.
|
Runs a function on every object contained within this one.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
func (callable): Function to call.
|
func (callable): Function to call. This must have the
|
||||||
exclude (list, optional): A list of object not to call the function on.
|
formal call sign func(obj, **kwargs), where obj is the
|
||||||
|
object currently being processed and `**kwargs` are
|
||||||
|
passed on from the call to `for_contents`.
|
||||||
|
exclude (list, optional): A list of object not to call the
|
||||||
|
function on.
|
||||||
|
|
||||||
Kwargs:
|
Kwargs:
|
||||||
Keyword arguments will be passed to the function for all objects.
|
Keyword arguments will be passed to the function for all objects.
|
||||||
|
|
@ -771,7 +777,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
||||||
|
|
||||||
# See if we need to kick the player off.
|
# See if we need to kick the player off.
|
||||||
|
|
||||||
for session in self.sessions:
|
for session in self.sessions.all():
|
||||||
session.msg(_("Your character %s has been destroyed.") % self.key)
|
session.msg(_("Your character %s has been destroyed.") % self.key)
|
||||||
# no need to disconnect, Player just jumps to OOC mode.
|
# no need to disconnect, Player just jumps to OOC mode.
|
||||||
# sever the connection (important!)
|
# sever the connection (important!)
|
||||||
|
|
@ -1472,12 +1478,14 @@ class DefaultCharacter(DefaultObject):
|
||||||
session (Session): Session controlling the connection that
|
session (Session): Session controlling the connection that
|
||||||
just disconnected.
|
just disconnected.
|
||||||
"""
|
"""
|
||||||
if self.location: # have to check, in case of multiple connections closing
|
if not self.sessions.count():
|
||||||
def message(obj, from_obj):
|
# only remove this char from grid if no sessions control it anymore.
|
||||||
obj.msg("%s has left the game." % self.get_display_name(obj), from_obj=from_obj)
|
if self.location:
|
||||||
self.location.for_contents(message, exclude=[self], from_obj=self)
|
def message(obj, from_obj):
|
||||||
self.db.prelogout_location = self.location
|
obj.msg("%s has left the game." % self.get_display_name(obj), from_obj=from_obj)
|
||||||
self.location = None
|
self.location.for_contents(message, exclude=[self], from_obj=self)
|
||||||
|
self.db.prelogout_location = self.location
|
||||||
|
self.location = None
|
||||||
|
|
||||||
#
|
#
|
||||||
# Base Room object
|
# Base Room object
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ class Bot(DefaultPlayer):
|
||||||
a reset.
|
a reset.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for session in self.get_all_sessions():
|
for session in self.sessions.all():
|
||||||
session.sessionhandler.disconnect(session)
|
session.sessionhandler.disconnect(session)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,16 @@ class PlayerSessionHandler(object):
|
||||||
"""
|
"""
|
||||||
return self.get()
|
return self.get()
|
||||||
|
|
||||||
|
def count(self):
|
||||||
|
"""
|
||||||
|
Get amount of sessions connected.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
sesslen (int): Number of sessions handled.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return len(self.get())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
|
|
@ -290,7 +300,7 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
obj.sessions.remove(session)
|
obj.sessions.remove(session)
|
||||||
if not obj.sessions.count():
|
if not obj.sessions.count():
|
||||||
del obj.player
|
del obj.player
|
||||||
obj.at_post_unpuppet(self, session=session)
|
obj.at_post_unpuppet(self, session=session)
|
||||||
# Just to be sure we're always clear.
|
# Just to be sure we're always clear.
|
||||||
session.puppet = None
|
session.puppet = None
|
||||||
session.puid = None
|
session.puid = None
|
||||||
|
|
@ -357,7 +367,7 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
mechanism (these are usually not used).
|
mechanism (these are usually not used).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for session in self.get_all_sessions():
|
for session in self.sessions.all():
|
||||||
# unpuppeting all objects and disconnecting the user, if any
|
# unpuppeting all objects and disconnecting the user, if any
|
||||||
# sessions remain (should usually be handled from the
|
# sessions remain (should usually be handled from the
|
||||||
# deleting command)
|
# deleting command)
|
||||||
|
|
@ -786,7 +796,6 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
else:
|
else:
|
||||||
# list of targets - make list
|
# list of targets - make list
|
||||||
characters = target
|
characters = target
|
||||||
|
|
||||||
sessions = self.sessions.all()
|
sessions = self.sessions.all()
|
||||||
is_su = self.is_superuser
|
is_su = self.is_superuser
|
||||||
|
|
||||||
|
|
@ -798,7 +807,7 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
for isess, sess in enumerate(sessions):
|
for isess, sess in enumerate(sessions):
|
||||||
csessid = sess.sessid
|
csessid = sess.sessid
|
||||||
addr = "%s (%s)" % (sess.protocol_key, isinstance(sess.address, tuple) and str(sess.address[0]) or str(sess.address))
|
addr = "%s (%s)" % (sess.protocol_key, isinstance(sess.address, tuple) and str(sess.address[0]) or str(sess.address))
|
||||||
string += "\n %s %s" % (session.sessid == csessid and "{w%s{n" % (isess + 1) or (isess + 1), addr)
|
string += "\n %s %s" % (session.sessid == csessid and "{w* %s{n" % (isess + 1) or " %s" % (isess + 1), addr)
|
||||||
string += "\n\n {whelp{n - more commands"
|
string += "\n\n {whelp{n - more commands"
|
||||||
string += "\n {wooc <Text>{n - talk on public channel"
|
string += "\n {wooc <Text>{n - talk on public channel"
|
||||||
|
|
||||||
|
|
@ -821,13 +830,14 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
|
|
||||||
for char in characters:
|
for char in characters:
|
||||||
csessions = char.sessions.all()
|
csessions = char.sessions.all()
|
||||||
for sess in csessions:
|
if csessions:
|
||||||
# character is already puppeted
|
for sess in csessions:
|
||||||
sid = sess in sessions and sessions.index(sess) + 1
|
# character is already puppeted
|
||||||
if sess and sid:
|
sid = sess in sessions and sessions.index(sess) + 1
|
||||||
string += "\n - {G%s{n [%s] (played by you in session %i)" % (char.key, ", ".join(char.permissions.all()), sid)
|
if sess and sid:
|
||||||
else:
|
string += "\n - {G%s{n [%s] (played by you in session %i)" % (char.key, ", ".join(char.permissions.all()), sid)
|
||||||
string += "\n - {R%s{n [%s] (played by someone else)" % (char.key, ", ".join(char.permissions.all()))
|
else:
|
||||||
|
string += "\n - {R%s{n [%s] (played by someone else)" % (char.key, ", ".join(char.permissions.all()))
|
||||||
else:
|
else:
|
||||||
# character is "free to puppet"
|
# character is "free to puppet"
|
||||||
string += "\n - %s [%s]" % (char.key, ", ".join(char.permissions.all()))
|
string += "\n - %s [%s]" % (char.key, ", ".join(char.permissions.all()))
|
||||||
|
|
|
||||||
|
|
@ -443,10 +443,11 @@ class ServerSessionHandler(SessionHandler):
|
||||||
Get session based on sessid, or None if not found
|
Get session based on sessid, or None if not found
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
sessid (int or list): Session id(s)
|
sessid (int or list): Session id(s).
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
sessions (Session or list): Session(s) found.
|
sessions (Session or list): Session(s) found. This
|
||||||
|
is a list if input was a list.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if is_iter(sessid):
|
if is_iter(sessid):
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,12 @@ class EvenniaTest(TestCase):
|
||||||
|
|
||||||
# set up a fake session
|
# set up a fake session
|
||||||
|
|
||||||
session = ServerSession()
|
dummysession = ServerSession()
|
||||||
session.init_session("telnet", ("localhost", "testmode"), SESSIONS)
|
dummysession.init_session("telnet", ("localhost", "testmode"), SESSIONS)
|
||||||
session.sessid = 1
|
dummysession.sessid = 1
|
||||||
SESSIONS.portal_connect(session.get_sync_data())
|
SESSIONS.portal_connect(dummysession.get_sync_data()) # note that this creates a new Session!
|
||||||
SESSIONS.login(SESSIONS.session_from_sessid(1), self.player, testmode=True)
|
session = SESSIONS.session_from_sessid(1) # the real session
|
||||||
|
SESSIONS.login(session, self.player, testmode=True)
|
||||||
self.session = session
|
self.session = session
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue