evennia.server.sessionhandler

This module defines handlers for storing sessions when handles sessions of users connecting to the server.

There are two similar but separate stores of sessions:

  • ServerSessionHandler - this stores generic game sessions

    for the game. These sessions has no knowledge about how they are connected to the world.

  • PortalSessionHandler - this stores sessions created by

    twisted protocols. These are dumb connectors that handle network communication but holds no game info.

class evennia.server.sessionhandler.DummySession[source]

Bases: object

sessid = 0
evennia.server.sessionhandler.delayed_import()[source]

Helper method for delayed import of all needed entities.

class evennia.server.sessionhandler.SessionHandler[source]

Bases: dict

This handler holds a stack of sessions.

get(key, default=None)[source]

Clean out None-sessions automatically.

get_sessions(include_unloggedin=False)[source]

Returns the connected session objects.

Parameters

include_unloggedin (bool, optional) – Also list Sessions that have not yet authenticated.

Returns

sessions (list) – A list of Session objects.

get_all_sync_data()[source]

Create a dictionary of sessdata dicts representing all sessions in store.

Returns

syncdata (dict) – A dict of sync data.

clean_senddata(session, kwargs)[source]

Clean up data for sending across the AMP wire. Also apply INLINEFUNCS.

Parameters
  • session (Session) – The relevant session instance.

  • kwargs (dict) – of the instruction (like “text”). Suitable values for each keyword are: - arg -> [[arg], {}] - [args] -> [[args], {}] - {kwargs} -> [[], {kwargs}] - [args, {kwargs}] -> [[arg], {kwargs}] - [[args], {kwargs}] -> [[args], {kwargs}]

Returns

kwargs (dict) – A cleaned dictionary of cmdname:[[args],{kwargs}] pairs, where the keys, args and kwargs have all been converted to send-safe entities (strings or numbers), and inlinefuncs have been applied.

class evennia.server.sessionhandler.ServerSessionHandler(*args, **kwargs)[source]

Bases: evennia.server.sessionhandler.SessionHandler

This object holds the stack of sessions active in the game at any time.

A session register with the handler in two steps, first by registering itself with the connect() method. This indicates an non-authenticated session. Whenever the session is authenticated the session together with the related account is sent to the login() method.

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

Init the handler.

portal_connect(portalsessiondata)[source]

Called by Portal when a new session has connected. Creates a new, unlogged-in game session.

Parameters

portalsessiondata (dict) – a dictionary of all property:value keys defining the session and which is marked to be synced.

portal_session_sync(portalsessiondata)[source]

Called by Portal when it wants to update a single session (e.g. because of all negotiation protocols have finally replied)

Parameters

portalsessiondata (dict) – a dictionary of all property:value keys defining the session and which is marked to be synced.

portal_sessions_sync(portalsessionsdata)[source]

Syncing all session ids of the portal with the ones of the server. This is instantiated by the portal when reconnecting.

Parameters

portalsessionsdata (dict) – A dictionary {sessid: {property:value},…} defining each session and the properties in it which should be synced.

portal_disconnect(session)[source]

Called from Portal when Portal session closed from the portal side. There is no message to report in this case.

Parameters

session (Session) – The Session to disconnect

portal_disconnect_all()[source]

Called from Portal when Portal is closing down. All Sessions should die. The Portal should not be informed.

start_bot_session(protocol_path, configdict)[source]

This method allows the server-side to force the Portal to create a new bot session.

Parameters
  • protocol_path (str) – The full python path to the bot’s class.

  • configdict (dict) – This dict will be used to configure the bot (this depends on the bot protocol).

Examples

start_bot_session(“evennia.server.portal.irc.IRCClient”,
{“uid”:1, “botname”:”evbot”, “channel”:”#evennia”,

“network:”irc.freenode.net”, “port”: 6667})

Notes

The new session will use the supplied account-bot uid to initiate an already logged-in connection. The Portal will treat this as a normal connection and henceforth so will the Server.

portal_restart_server()[source]

Called by server when reloading. We tell the portal to start a new server instance.

portal_reset_server()[source]

Called by server when reloading. We tell the portal to start a new server instance.

portal_shutdown()[source]

Called by server when it’s time to shut down (the portal will shut us down and then shut itself down)

login(session, account, force=False, testmode=False)[source]

Log in the previously unloggedin session and the account we by now should know is connected to it. After this point we assume the session to be logged in one way or another.

Parameters
  • session (Session) – The Session to authenticate.

  • account (Account) – The Account identified as associated with this Session.

  • force (bool) – Login also if the session thinks it’s already logged in (this can happen for auto-authenticating protocols)

  • testmode (bool, optional) – This is used by unittesting for faking login without any AMP being actually active.

disconnect(session, reason='', sync_portal=True)[source]

Called from server side to remove session and inform portal of this fact.

Parameters
  • session (Session) – The Session to disconnect.

  • reason (str, optional) – A motivation for the disconnect.

  • sync_portal (bool, optional) – Sync the disconnect to Portal side. This should be done unless this was called by self.portal_disconnect().

all_sessions_portal_sync()[source]

This is called by the server when it reboots. It syncs all session data to the portal. Returns a deferred!

session_portal_sync(session)[source]

This is called by the server when it wants to sync a single session with the Portal for whatever reason. Returns a deferred!

session_portal_partial_sync(session_data)[source]

Call to make a partial update of the session, such as only a particular property.

Parameters

session_data (dict) – Store {sessid: {property:value}, …} defining one or more sessions in detail.

disconnect_all_sessions(reason='You have been disconnected.')[source]

Cleanly disconnect all of the connected sessions.

Parameters

reason (str, optional) – The reason for the disconnection.

disconnect_duplicate_sessions(curr_session, reason='Logged in from elsewhere. Disconnecting.')[source]

Disconnects any existing sessions with the same user.

Parameters
  • curr_session (Session) – Disconnect all Sessions matching this one.

  • reason (str, optional) – A motivation for disconnecting.

validate_sessions()[source]

Check all currently connected sessions (logged in and not) and see if any are dead or idle.

account_count()[source]

Get the number of connected accounts (not sessions since a account may have more than one session depending on settings). Only logged-in accounts are counted here.

Returns

naccount (int) – Number of connected accounts

all_connected_accounts()[source]

Get a unique list of connected and logged-in Accounts.

Returns

accounts (list)

All conected Accounts (which may be fewer than the

amount of Sessions due to multi-playing).

session_from_sessid(sessid)[source]

Get session based on sessid, or None if not found

Parameters

sessid (int or list) – Session id(s).

Returns

sessions (Session or list)

Session(s) found. This

is a list if input was a list.

session_from_account(account, sessid)[source]

Given an account and a session id, return the actual session object.

Parameters
  • account (Account) – The Account to get the Session from.

  • sessid (int or list) – Session id(s).

Returns

sessions (Session or list) – Session(s) found.

sessions_from_account(account)[source]

Given an account, return all matching sessions.

Parameters

account (Account) – Account to get sessions from.

Returns

sessions (list) – All Sessions associated with this account.

sessions_from_puppet(puppet)[source]

Given a puppeted object, return all controlling sessions.

Parameters

puppet (Object) – Object puppeted

Returns.
sessions (Session or list): Can be more than one of Object is controlled by

more than one Session (MULTISESSION_MODE > 1).

sessions_from_character(puppet)

Given a puppeted object, return all controlling sessions.

Parameters

puppet (Object) – Object puppeted

Returns.
sessions (Session or list): Can be more than one of Object is controlled by

more than one Session (MULTISESSION_MODE > 1).

sessions_from_csessid(csessid)[source]

Given a client identification hash (for session types that offer them) return all sessions with a matching hash.

Args

csessid (str): The session hash.

Returns

sessions (list) – The sessions with matching .csessid, if any.

announce_all(message)[source]

Send message to all connected sessions

Parameters

message (str) – Message to send.

data_out(session, **kwargs)[source]

Sending data Server -> Portal

Parameters
  • session (Session) – Session to relay to.

  • text (str, optional) – text data to return

Notes

The outdata will be scrubbed for sending across the wire here.

get_inputfuncs()[source]

Get all registered inputfuncs (access function)

Returns

inputfuncs (dict) – A dict of {key:inputfunc,…}

data_in(session, **kwargs)[source]

We let the data take a “detour” to session.data_in so the user can override and see it all in one place. That method is responsible to in turn always call this class’ sessionhandler.call_inputfunc with the (possibly processed) data.

call_inputfuncs(session, **kwargs)[source]

Split incoming data into its inputfunc counterparts. This should be called by the serversession.data_in as sessionhandler.call_inputfunc(self, **kwargs).

We also intercept OOB communication here.

Parameters

sessions (Session) – Session.

Keyword Arguments

any (tuple) – Incoming data from protocol, each on the form commandname=((args), {kwargs}).