mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
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 import bots
|
||||
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.commands.default.muxcommand import MuxCommand, MuxPlayerCommand
|
||||
|
||||
|
|
@ -740,7 +740,7 @@ class CmdPage(MuxPlayerCommand):
|
|||
rstrings.append("You are not allowed to page %s." % pobj)
|
||||
continue
|
||||
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)
|
||||
rstrings.append("%s is offline. They will see your message if they list their pages later." % received[-1])
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -481,7 +481,7 @@ class CmdQuit(MuxPlayerCommand):
|
|||
|
||||
if 'all' in self.switches:
|
||||
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)
|
||||
else:
|
||||
nsess = len(player.sessions.all())
|
||||
|
|
|
|||
|
|
@ -489,9 +489,6 @@ class CmdService(MuxCommand):
|
|||
return
|
||||
|
||||
# get all services
|
||||
sessions = caller.sessions
|
||||
if not sessions:
|
||||
return
|
||||
service_collection = SESSIONS.server.services
|
||||
|
||||
if not switches or switches[0] == "list":
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
|||
currently connected to this object.
|
||||
|
||||
"""
|
||||
return any(self.sessions)
|
||||
return self.sessions.count()
|
||||
|
||||
@property
|
||||
def is_superuser(self):
|
||||
|
|
|
|||
|
|
@ -73,9 +73,9 @@ class PlayerSessionHandler(object):
|
|||
if not _SESSIONS:
|
||||
from evennia.server.sessionhandler import SESSIONS as _SESSIONS
|
||||
if sessid:
|
||||
return make_iter(_SESSIONS.session_from_player(self, sessid))
|
||||
return make_iter(_SESSIONS.session_from_player(self.player, sessid))
|
||||
else:
|
||||
return _SESSIONS.sessions_from_player(self)
|
||||
return _SESSIONS.sessions_from_player(self.player)
|
||||
|
||||
def all(self):
|
||||
"""
|
||||
|
|
@ -258,7 +258,7 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
|||
obj.at_pre_puppet(self, session=session)
|
||||
|
||||
# do the connection
|
||||
obj.session.add(session)
|
||||
obj.sessions.add(session)
|
||||
obj.player = self
|
||||
session.puid = obj.id
|
||||
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
|
||||
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:
|
||||
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
|
||||
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:
|
||||
return time.time() - float(min(conn))
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ from twisted.internet.defer import Deferred
|
|||
from evennia.utils import logger
|
||||
from evennia.utils.utils import to_str, variable_from_module
|
||||
|
||||
class DummySession(object):
|
||||
sessid = 0
|
||||
DUMMYSESSION = DummySession()
|
||||
|
||||
# communication bits
|
||||
|
||||
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
|
||||
# on the portal side and can initialize the connection.
|
||||
sessdata = self.factory.portal.sessions.get_all_sync_data()
|
||||
self.send_AdminPortal2Server(0,
|
||||
self.send_AdminPortal2Server(DUMMYSESSION,
|
||||
PSYNC,
|
||||
sessiondata=sessdata)
|
||||
self.factory.portal.sessions.at_server_connection()
|
||||
|
|
@ -478,7 +482,6 @@ class AMPProtocol(amp.AMP):
|
|||
sessid, kwargs = loads(packed_data)
|
||||
operation = kwargs.pop("operation", "")
|
||||
server_sessionhandler = self.factory.server.sessions
|
||||
session = server_sessionhandler[sessid]
|
||||
|
||||
if operation == PCONN: # portal_session_connect
|
||||
# create a new session and sync it
|
||||
|
|
@ -489,6 +492,7 @@ class AMPProtocol(amp.AMP):
|
|||
|
||||
elif operation == PDISCONN: # portal_session_disconnect
|
||||
# session closed from portal side
|
||||
session = server_sessionhandler[sessid]
|
||||
self.factory.server.sessions.portal_disconnect(session)
|
||||
|
||||
elif operation == PSYNC: # portal_session_sync
|
||||
|
|
@ -534,14 +538,15 @@ class AMPProtocol(amp.AMP):
|
|||
operation = kwargs.pop("operation")
|
||||
portal_sessionhandler = self.factory.portal.sessions
|
||||
|
||||
session = portal_sessionhandler[sessid]
|
||||
|
||||
if operation == SLOGIN: # server_session_login
|
||||
# a session has authenticated; sync it.
|
||||
session = portal_sessionhandler[sessid]
|
||||
portal_sessionhandler.server_logged_in(session, kwargs.get("sessiondata"))
|
||||
|
||||
elif operation == SDISCONN: # server_session_disconnect
|
||||
# the server is ordering to disconnect the session
|
||||
session = portal_sessionhandler[sessid]
|
||||
portal_sessionhandler.server_disconnect(session, reason=kwargs.get("reason"))
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
|
||||
self[session.sessid] = session
|
||||
session.server_connected = True
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(session.sessid,
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(session,
|
||||
operation=PCONN,
|
||||
sessiondata=sessdata)
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
"conn_time",
|
||||
"protocol_flags",
|
||||
"server_data",))
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(session.sessid,
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(session,
|
||||
operation=PCONNSYNC,
|
||||
sessiondata=sessdata)
|
||||
|
||||
|
|
@ -159,8 +159,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
# to forward this to the Server, so now we just remove it.
|
||||
_CONNECTION_QUEUE.remove(session)
|
||||
return
|
||||
sessid = session.sessid
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(sessid,
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(session,
|
||||
operation=PDISCONN)
|
||||
|
||||
def server_connect(self, protocol_path="", config=dict()):
|
||||
|
|
@ -397,7 +396,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
return
|
||||
# relay data to Server
|
||||
self.command_counter += 1
|
||||
self.portal.amp_protocol.send_MsgPortal2Server(session.sessid,
|
||||
self.portal.amp_protocol.send_MsgPortal2Server(session,
|
||||
text=text,
|
||||
**kwargs)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ class ServerSessionHandler(SessionHandler):
|
|||
self.server.amp_protocol.send_AdminServer2Portal(session,
|
||||
operation=SLOGIN,
|
||||
sessiondata={"logged_in": True})
|
||||
player.at_post_login(sessid=session.sessid)
|
||||
player.at_post_login(session=session)
|
||||
|
||||
def disconnect(self, session, reason=""):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -620,7 +620,6 @@ class NickHandler(AttributeHandler):
|
|||
their nick equivalents.
|
||||
|
||||
"""
|
||||
raw_string
|
||||
obj_nicks, player_nicks = [], []
|
||||
for category in make_iter(categories):
|
||||
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._npos = []
|
||||
# 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
|
||||
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)]
|
||||
|
|
|
|||
|
|
@ -59,4 +59,4 @@ class EvenniaTest(TestCase):
|
|||
|
||||
def tearDown(self):
|
||||
flush_cache()
|
||||
del SESSIONS.sessions[self.session.sessid]
|
||||
del SESSIONS[self.session.sessid]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue