Sessionhandler for portal sessions

class evennia.server.portal.portalsessionhandler.PortalSessionHandler(*args, **kwargs)[source]

Bases: evennia.server.sessionhandler.SessionHandler

This object holds the sessions connected to the portal at any time. It is synced with the server’s equivalent SessionHandler over the AMP connection.

Sessions register with the handler using the connect() method. This will assign a new unique sessionid to the session and send that sessid to the server using the AMP connection.

__init__(*args, **kwargs)[source]

Init the handler


Called when the Portal establishes connection with the Server. At this point, the AMP connection is already established.


Called by protocol at first connect. This adds a not-yet authenticated session using an ever-increasing counter for sessid.


session (PortalSession) – The Session connecting.


We implement a throttling mechanism here to limit the speed at which new connections are accepted - this is both a stop against DoS attacks as well as helps using the Dummyrunner tester with a large number of connector dummies.


Called by the protocol of an already connected session. This can be used to sync the session info in a delayed manner, such as when negotiation and handshakes are delayed.


session (PortalSession) – Session to sync.


Called from portal when the connection is closed from the portal side.

  • session (PortalSession) – Session to disconnect.

  • delete (bool, optional) – Delete the session from the handler. Only time to not do this is when this is called from a loop, such as from self.disconnect_all().


Disconnect all sessions, informing the Server.

server_connect(protocol_path='', config={})[source]

Called by server to force the initialization of a new protocol instance. Server wants this instance to get a unique sessid and to be connected back as normal. This is used to initiate irc/rss etc connections.

  • protocol_path (str) – Full python path to the class factory for the protocol used, eg ‘evennia.server.portal.irc.IRCClientFactory’

  • config (dict) – Dictionary of configuration options, fed as **kwarg to protocol class __init__ method.


RuntimeError – If The correct factory class is not found.


The called protocol class must have a method start() that calls the portalsession.connect() as a normal protocol.

server_disconnect(session, reason='')[source]

Called by server to force a disconnect by sessid.

  • session (portalsession) – Session to disconnect.

  • reason (str, optional) – Motivation for disconnect.


Called by server when forcing a clean disconnect for everyone.


reason (str, optional) – Motivation for disconnect.

server_logged_in(session, data)[source]

The server tells us that the session has been authenticated. Update it. Called by the Server.

  • session (Session) – Session logging in.

  • data (dict) – The session sync data.

server_session_sync(serversessions, clean=True)[source]

Server wants to save data to the portal, maybe because it’s about to shut down. We don’t overwrite any sessions here, just update them in-place.

  • serversessions (dict) –

    This is a dictionary

    {sessid:{property:value},…} describing the properties to sync on all sessions.

  • clean (bool) – If True, remove any Portal sessions that are not included in serversessions.


Count loggedin connections, alternatively count all connections.

  • include_unloggedin (bool) – Also count sessions that have

  • yet authenticated. (not) –


count (int) – Number of sessions.


Given a session id, retrieve the session (this is primarily intended to be called by web clients)


csessid (int) – Session id.


session (list) – The matching session, if found.


Send message to all connected sessions.


message (str) – Message to relay.


This will create an on-the fly text-type send command.

data_in(session, **kwargs)[source]

Called by portal sessions for relaying data coming in from the protocol to the server.


session (PortalSession) – Session receiving data.

Keyword Arguments

kwargs (any) – Other data from protocol.


Data is serialized before passed on.

data_out(session, **kwargs)[source]

Called by server for having the portal relay messages and data to the correct session protocol.


session (Session) – Session sending data.

Keyword Arguments

kwargs (any) – Each key is a command instruction to the protocol on the form key = [[args],{kwargs}]. This will call a method send_<key> on the protocol. If no such method exixts, it sends the data to a method send_default.