evennia.server.session

This module defines a generic session class. All connection instances (both on Portal and Server side) should inherit from this class.

class evennia.server.session.Session[源代码]

基类:object

This class represents a player’s session and is a template for both portal- and server-side sessions.

Each connection will see two session instances created:

  1. A Portal session. This is customized for the respective connection protocols that Evennia supports, like Telnet, SSH etc. The Portal session must call init_session() as part of its initialization. The respective hook methods should be connected to the methods unique for the respective protocol so that there is a unified interface to Evennia.

  2. A Server session. This is the same for all connected accounts, regardless of how they connect.

The Portal and Server have their own respective sessionhandlers. These are synced whenever new connections happen or the Server restarts etc, which means much of the same information must be stored in both places e.g. the portal can re-sync with the server when the server reboots.

init_session(protocol_key, address, sessionhandler)[源代码]

Initialize the Session. This should be called by the protocol when a new session is established.

参数
  • protocol_key (str) – By default, one of ‘telnet’, ‘telnet/ssl’, ‘ssh’, ‘webclient/websocket’ or ‘webclient/ajax’.

  • address (str) – Client address.

  • sessionhandler (SessionHandler) – Reference to the main sessionhandler instance.

get_sync_data()[源代码]

Get all data relevant to sync the session.

参数

syncdata (dict) – All syncdata values, based on the keys given by self._attrs_to_sync.

load_sync_data(sessdata)[源代码]

Takes a session dictionary, as created by get_sync_data, and loads it into the correct properties of the session.

参数

sessdata (dict) – Session data dictionary.

at_sync()[源代码]

Called after a session has been fully synced (including secondary operations such as setting self.account based on uid etc).

disconnect(reason=None)[源代码]

generic hook called from the outside to disconnect this session should be connected to the protocols actual disconnect mechanism.

参数

reason (str) – Eventual text motivating the disconnect.

data_out(**kwargs)[源代码]

Generic hook for sending data out through the protocol. Server protocols can use this right away. Portal sessions should overload this to format/handle the outgoing data as needed.

关键字参数

kwargs (any) – Other data to the protocol.

data_in(**kwargs)[源代码]

Hook for protocols to send incoming data to the engine.

关键字参数

kwargs (any) – Other data from the protocol.