First version of changed sessid->session change that starts properly. Not fully tested yet.
This commit is contained in:
parent
d496606a3c
commit
efefe3e5ff
11 changed files with 28 additions and 25 deletions
|
|
@ -14,7 +14,7 @@ from evennia.comms.models import ChannelDB, Msg
|
||||||
from evennia.players.models import PlayerDB
|
from evennia.players.models import PlayerDB
|
||||||
from evennia.players import bots
|
from evennia.players import bots
|
||||||
from evennia.comms.channelhandler import CHANNELHANDLER
|
from evennia.comms.channelhandler import CHANNELHANDLER
|
||||||
from evennia.utils import create, utils, prettytable, evtable
|
from evennia.utils import create, utils, evtable
|
||||||
from evennia.utils.utils import make_iter
|
from evennia.utils.utils import make_iter
|
||||||
from evennia.commands.default.muxcommand import MuxCommand, MuxPlayerCommand
|
from evennia.commands.default.muxcommand import MuxCommand, MuxPlayerCommand
|
||||||
|
|
||||||
|
|
@ -740,7 +740,7 @@ class CmdPage(MuxPlayerCommand):
|
||||||
rstrings.append("You are not allowed to page %s." % pobj)
|
rstrings.append("You are not allowed to page %s." % pobj)
|
||||||
continue
|
continue
|
||||||
pobj.msg("%s %s" % (header, message))
|
pobj.msg("%s %s" % (header, message))
|
||||||
if hasattr(pobj, 'sessions') and not pobj.sessions:
|
if hasattr(pobj, 'sessions') and not pobj.sessions.count():
|
||||||
received.append("{C%s{n" % pobj.name)
|
received.append("{C%s{n" % pobj.name)
|
||||||
rstrings.append("%s is offline. They will see your message if they list their pages later." % received[-1])
|
rstrings.append("%s is offline. They will see your message if they list their pages later." % received[-1])
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -481,7 +481,7 @@ class CmdQuit(MuxPlayerCommand):
|
||||||
|
|
||||||
if 'all' in self.switches:
|
if 'all' in self.switches:
|
||||||
player.msg("{RQuitting{n all sessions. Hope to see you soon again.", session=self.session)
|
player.msg("{RQuitting{n all sessions. Hope to see you soon again.", session=self.session)
|
||||||
for session in player.sessions.all()
|
for session in player.sessions.all():
|
||||||
player.disconnect_session_from_player(session)
|
player.disconnect_session_from_player(session)
|
||||||
else:
|
else:
|
||||||
nsess = len(player.sessions.all())
|
nsess = len(player.sessions.all())
|
||||||
|
|
|
||||||
|
|
@ -489,9 +489,6 @@ class CmdService(MuxCommand):
|
||||||
return
|
return
|
||||||
|
|
||||||
# get all services
|
# get all services
|
||||||
sessions = caller.sessions
|
|
||||||
if not sessions:
|
|
||||||
return
|
|
||||||
service_collection = SESSIONS.server.services
|
service_collection = SESSIONS.server.services
|
||||||
|
|
||||||
if not switches or switches[0] == "list":
|
if not switches or switches[0] == "list":
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
||||||
currently connected to this object.
|
currently connected to this object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return any(self.sessions)
|
return self.sessions.count()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_superuser(self):
|
def is_superuser(self):
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,9 @@ class PlayerSessionHandler(object):
|
||||||
if not _SESSIONS:
|
if not _SESSIONS:
|
||||||
from evennia.server.sessionhandler import SESSIONS as _SESSIONS
|
from evennia.server.sessionhandler import SESSIONS as _SESSIONS
|
||||||
if sessid:
|
if sessid:
|
||||||
return make_iter(_SESSIONS.session_from_player(self, sessid))
|
return make_iter(_SESSIONS.session_from_player(self.player, sessid))
|
||||||
else:
|
else:
|
||||||
return _SESSIONS.sessions_from_player(self)
|
return _SESSIONS.sessions_from_player(self.player)
|
||||||
|
|
||||||
def all(self):
|
def all(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -258,7 +258,7 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
obj.at_pre_puppet(self, session=session)
|
obj.at_pre_puppet(self, session=session)
|
||||||
|
|
||||||
# do the connection
|
# do the connection
|
||||||
obj.session.add(session)
|
obj.sessions.add(session)
|
||||||
obj.player = self
|
obj.player = self
|
||||||
session.puid = obj.id
|
session.puid = obj.id
|
||||||
session.puppet = obj
|
session.puppet = obj
|
||||||
|
|
@ -508,7 +508,7 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
Returns the idle time of the least idle session in seconds. If
|
Returns the idle time of the least idle session in seconds. If
|
||||||
no sessions are connected it returns nothing.
|
no sessions are connected it returns nothing.
|
||||||
"""
|
"""
|
||||||
idle = [session.cmd_last_visible for session in self.sessions]
|
idle = [session.cmd_last_visible for session in self.sessions.all()]
|
||||||
if idle:
|
if idle:
|
||||||
return time.time() - float(max(idle))
|
return time.time() - float(max(idle))
|
||||||
|
|
||||||
|
|
@ -518,7 +518,7 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
||||||
Returns the maximum connection time of all connected sessions
|
Returns the maximum connection time of all connected sessions
|
||||||
in seconds. Returns nothing if there are no sessions.
|
in seconds. Returns nothing if there are no sessions.
|
||||||
"""
|
"""
|
||||||
conn = [session.conn_time for session in self.sessions]
|
conn = [session.conn_time for session in self.sessions.all()]
|
||||||
if conn:
|
if conn:
|
||||||
return time.time() - float(min(conn))
|
return time.time() - float(min(conn))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ from twisted.internet.defer import Deferred
|
||||||
from evennia.utils import logger
|
from evennia.utils import logger
|
||||||
from evennia.utils.utils import to_str, variable_from_module
|
from evennia.utils.utils import to_str, variable_from_module
|
||||||
|
|
||||||
|
class DummySession(object):
|
||||||
|
sessid = 0
|
||||||
|
DUMMYSESSION = DummySession()
|
||||||
|
|
||||||
# communication bits
|
# communication bits
|
||||||
|
|
||||||
PCONN = chr(1) # portal session connect
|
PCONN = chr(1) # portal session connect
|
||||||
|
|
@ -358,7 +362,7 @@ class AMPProtocol(amp.AMP):
|
||||||
# only the portal has the 'portal' property, so we know we are
|
# only the portal has the 'portal' property, so we know we are
|
||||||
# on the portal side and can initialize the connection.
|
# on the portal side and can initialize the connection.
|
||||||
sessdata = self.factory.portal.sessions.get_all_sync_data()
|
sessdata = self.factory.portal.sessions.get_all_sync_data()
|
||||||
self.send_AdminPortal2Server(0,
|
self.send_AdminPortal2Server(DUMMYSESSION,
|
||||||
PSYNC,
|
PSYNC,
|
||||||
sessiondata=sessdata)
|
sessiondata=sessdata)
|
||||||
self.factory.portal.sessions.at_server_connection()
|
self.factory.portal.sessions.at_server_connection()
|
||||||
|
|
@ -478,7 +482,6 @@ class AMPProtocol(amp.AMP):
|
||||||
sessid, kwargs = loads(packed_data)
|
sessid, kwargs = loads(packed_data)
|
||||||
operation = kwargs.pop("operation", "")
|
operation = kwargs.pop("operation", "")
|
||||||
server_sessionhandler = self.factory.server.sessions
|
server_sessionhandler = self.factory.server.sessions
|
||||||
session = server_sessionhandler[sessid]
|
|
||||||
|
|
||||||
if operation == PCONN: # portal_session_connect
|
if operation == PCONN: # portal_session_connect
|
||||||
# create a new session and sync it
|
# create a new session and sync it
|
||||||
|
|
@ -489,6 +492,7 @@ class AMPProtocol(amp.AMP):
|
||||||
|
|
||||||
elif operation == PDISCONN: # portal_session_disconnect
|
elif operation == PDISCONN: # portal_session_disconnect
|
||||||
# session closed from portal side
|
# session closed from portal side
|
||||||
|
session = server_sessionhandler[sessid]
|
||||||
self.factory.server.sessions.portal_disconnect(session)
|
self.factory.server.sessions.portal_disconnect(session)
|
||||||
|
|
||||||
elif operation == PSYNC: # portal_session_sync
|
elif operation == PSYNC: # portal_session_sync
|
||||||
|
|
@ -534,14 +538,15 @@ class AMPProtocol(amp.AMP):
|
||||||
operation = kwargs.pop("operation")
|
operation = kwargs.pop("operation")
|
||||||
portal_sessionhandler = self.factory.portal.sessions
|
portal_sessionhandler = self.factory.portal.sessions
|
||||||
|
|
||||||
session = portal_sessionhandler[sessid]
|
|
||||||
|
|
||||||
if operation == SLOGIN: # server_session_login
|
if operation == SLOGIN: # server_session_login
|
||||||
# a session has authenticated; sync it.
|
# a session has authenticated; sync it.
|
||||||
|
session = portal_sessionhandler[sessid]
|
||||||
portal_sessionhandler.server_logged_in(session, kwargs.get("sessiondata"))
|
portal_sessionhandler.server_logged_in(session, kwargs.get("sessiondata"))
|
||||||
|
|
||||||
elif operation == SDISCONN: # server_session_disconnect
|
elif operation == SDISCONN: # server_session_disconnect
|
||||||
# the server is ordering to disconnect the session
|
# the server is ordering to disconnect the session
|
||||||
|
session = portal_sessionhandler[sessid]
|
||||||
portal_sessionhandler.server_disconnect(session, reason=kwargs.get("reason"))
|
portal_sessionhandler.server_disconnect(session, reason=kwargs.get("reason"))
|
||||||
|
|
||||||
elif operation == SDISCONNALL: # server_session_disconnect_all
|
elif operation == SDISCONNALL: # server_session_disconnect_all
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class PortalSessionHandler(SessionHandler):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Init the handler
|
Init the handler
|
||||||
|
|
||||||
|
|
@ -111,7 +111,7 @@ class PortalSessionHandler(SessionHandler):
|
||||||
|
|
||||||
self[session.sessid] = session
|
self[session.sessid] = session
|
||||||
session.server_connected = True
|
session.server_connected = True
|
||||||
self.portal.amp_protocol.send_AdminPortal2Server(session.sessid,
|
self.portal.amp_protocol.send_AdminPortal2Server(session,
|
||||||
operation=PCONN,
|
operation=PCONN,
|
||||||
sessiondata=sessdata)
|
sessiondata=sessdata)
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ class PortalSessionHandler(SessionHandler):
|
||||||
"conn_time",
|
"conn_time",
|
||||||
"protocol_flags",
|
"protocol_flags",
|
||||||
"server_data",))
|
"server_data",))
|
||||||
self.portal.amp_protocol.send_AdminPortal2Server(session.sessid,
|
self.portal.amp_protocol.send_AdminPortal2Server(session,
|
||||||
operation=PCONNSYNC,
|
operation=PCONNSYNC,
|
||||||
sessiondata=sessdata)
|
sessiondata=sessdata)
|
||||||
|
|
||||||
|
|
@ -159,8 +159,7 @@ class PortalSessionHandler(SessionHandler):
|
||||||
# to forward this to the Server, so now we just remove it.
|
# to forward this to the Server, so now we just remove it.
|
||||||
_CONNECTION_QUEUE.remove(session)
|
_CONNECTION_QUEUE.remove(session)
|
||||||
return
|
return
|
||||||
sessid = session.sessid
|
self.portal.amp_protocol.send_AdminPortal2Server(session,
|
||||||
self.portal.amp_protocol.send_AdminPortal2Server(sessid,
|
|
||||||
operation=PDISCONN)
|
operation=PDISCONN)
|
||||||
|
|
||||||
def server_connect(self, protocol_path="", config=dict()):
|
def server_connect(self, protocol_path="", config=dict()):
|
||||||
|
|
@ -397,7 +396,7 @@ class PortalSessionHandler(SessionHandler):
|
||||||
return
|
return
|
||||||
# relay data to Server
|
# relay data to Server
|
||||||
self.command_counter += 1
|
self.command_counter += 1
|
||||||
self.portal.amp_protocol.send_MsgPortal2Server(session.sessid,
|
self.portal.amp_protocol.send_MsgPortal2Server(session,
|
||||||
text=text,
|
text=text,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ class ServerSessionHandler(SessionHandler):
|
||||||
self.server.amp_protocol.send_AdminServer2Portal(session,
|
self.server.amp_protocol.send_AdminServer2Portal(session,
|
||||||
operation=SLOGIN,
|
operation=SLOGIN,
|
||||||
sessiondata={"logged_in": True})
|
sessiondata={"logged_in": True})
|
||||||
player.at_post_login(sessid=session.sessid)
|
player.at_post_login(session=session)
|
||||||
|
|
||||||
def disconnect(self, session, reason=""):
|
def disconnect(self, session, reason=""):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -620,7 +620,6 @@ class NickHandler(AttributeHandler):
|
||||||
their nick equivalents.
|
their nick equivalents.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
raw_string
|
|
||||||
obj_nicks, player_nicks = [], []
|
obj_nicks, player_nicks = [], []
|
||||||
for category in make_iter(categories):
|
for category in make_iter(categories):
|
||||||
obj_nicks.extend([n for n in make_iter(self.get(category=category, return_obj=True)) if n])
|
obj_nicks.extend([n for n in make_iter(self.get(category=category, return_obj=True)) if n])
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,10 @@ class EvMore(object):
|
||||||
self._npages = []
|
self._npages = []
|
||||||
self._npos = []
|
self._npos = []
|
||||||
# we use the first session here
|
# we use the first session here
|
||||||
session = caller.sessions[0]
|
sessions = caller.sessions.get()
|
||||||
|
if not sessions:
|
||||||
|
return
|
||||||
|
session = sessions[0]
|
||||||
# set up individual pages for different sessions
|
# set up individual pages for different sessions
|
||||||
height = session.protocol_flags.get("SCREENHEIGHT", {0:_SCREEN_HEIGHT})[0] - 2
|
height = session.protocol_flags.get("SCREENHEIGHT", {0:_SCREEN_HEIGHT})[0] - 2
|
||||||
self._pages = ["\n".join(lines[i:i+height]) for i in range(0, len(lines), height)]
|
self._pages = ["\n".join(lines[i:i+height]) for i in range(0, len(lines), height)]
|
||||||
|
|
|
||||||
|
|
@ -59,4 +59,4 @@ class EvenniaTest(TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
flush_cache()
|
flush_cache()
|
||||||
del SESSIONS.sessions[self.session.sessid]
|
del SESSIONS[self.session.sessid]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue