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.
-
evennia.server.sessionhandler.
delayed_import
()[源代码]¶ Helper method for delayed import of all needed entities.
-
class
evennia.server.sessionhandler.
SessionHandler
[源代码]¶ 基类:
dict
This handler holds a stack of sessions.
-
get_sessions
(include_unloggedin=False)[源代码]¶ Returns the connected session objects.
- 参数
include_unloggedin (bool, optional) – Also list Sessions that have not yet authenticated.
- 返回
sessions (list) – A list of Session objects.
-
get_all_sync_data
()[源代码]¶ Create a dictionary of sessdata dicts representing all sessions in store.
- 返回
syncdata (dict) – A dict of sync data.
-
clean_senddata
(session, kwargs)[源代码]¶ Clean up data for sending across the AMP wire. Also apply the FuncParser using callables from settings.FUNCPARSER_OUTGOING_MESSAGES_MODULES.
- 参数
session (Session) – The relevant session instance.
kwargs (dict) – the name 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}]
- 返回
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 funcparser parsing has been applied.
-
-
class
evennia.server.sessionhandler.
ServerSessionHandler
(*args, **kwargs)[源代码]¶ 基类:
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.
-
portal_connect
(portalsessiondata)[源代码]¶ Called by Portal when a new session has connected. Creates a new, unlogged-in game session.
- 参数
portalsessiondata (dict) – a dictionary of all property:value keys defining the session and which is marked to be synced.
-
portal_session_sync
(portalsessiondata)[源代码]¶ Called by Portal when it wants to update a single session (e.g. because of all negotiation protocols have finally replied)
- 参数
portalsessiondata (dict) – a dictionary of all property:value keys defining the session and which is marked to be synced.
-
portal_sessions_sync
(portalsessionsdata)[源代码]¶ Syncing all session ids of the portal with the ones of the server. This is instantiated by the portal when reconnecting.
- 参数
portalsessionsdata (dict) – A dictionary {sessid: {property:value},…} defining each session and the properties in it which should be synced.
-
portal_disconnect
(session)[源代码]¶ Called from Portal when Portal session closed from the portal side. There is no message to report in this case.
- 参数
session (Session) – The Session to disconnect
-
portal_disconnect_all
()[源代码]¶ Called from Portal when Portal is closing down. All Sessions should die. The Portal should not be informed.
-
start_bot_session
(protocol_path, configdict)[源代码]¶ This method allows the server-side to force the Portal to create a new bot session.
- 参数
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).
实际案例
- start_bot_session(“evennia.server.portal.irc.IRCClient”,
- {“uid”:1, “botname”:”evbot”, “channel”:”#evennia”,
“network:”irc.freenode.net”, “port”: 6667})
提示
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
()[源代码]¶ Called by server when reloading. We tell the portal to start a new server instance.
-
portal_reset_server
()[源代码]¶ Called by server when reloading. We tell the portal to start a new server instance.
-
portal_shutdown
()[源代码]¶ 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)[源代码]¶ 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.
- 参数
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)[源代码]¶ Called from server side to remove session and inform portal of this fact.
- 参数
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
()[源代码]¶ This is called by the server when it reboots. It syncs all session data to the portal. Returns a deferred!
-
session_portal_sync
(session)[源代码]¶ 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)[源代码]¶ Call to make a partial update of the session, such as only a particular property.
- 参数
session_data (dict) – Store {sessid: {property:value}, …} defining one or more sessions in detail.
-
disconnect_all_sessions
(reason='You have been disconnected.')[源代码]¶ Cleanly disconnect all of the connected sessions.
- 参数
reason (str, optional) – The reason for the disconnection.
-
disconnect_duplicate_sessions
(curr_session, reason='Logged in from elsewhere. Disconnecting.')[源代码]¶ Disconnects any existing sessions with the same user.
- 参数
curr_session (Session) – Disconnect all Sessions matching this one.
reason (str, optional) – A motivation for disconnecting.
-
validate_sessions
()[源代码]¶ Check all currently connected sessions (logged in and not) and see if any are dead or idle.
-
account_count
()[源代码]¶ 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.
- 返回
naccount (int) – Number of connected accounts
-
all_connected_accounts
()[源代码]¶ Get a unique list of connected and logged-in Accounts.
- 返回
accounts (list) –
- All connected Accounts (which may be fewer than the
amount of Sessions due to multi-playing).
-
session_from_sessid
(sessid)[源代码]¶ Get session based on sessid, or None if not found
- 参数
sessid (int or list) – Session id(s).
- 返回
sessions (Session or list) –
- Session(s) found. This
is a list if input was a list.
-
session_from_account
(account, sessid)[源代码]¶ Given an account and a session id, return the actual session object.
- 参数
account (Account) – The Account to get the Session from.
sessid (int or list) – Session id(s).
- 返回
sessions (Session or list) – Session(s) found.
-
sessions_from_account
(account)[源代码]¶ Given an account, return all matching sessions.
- 参数
account (Account) – Account to get sessions from.
- 返回
sessions (list) – All Sessions associated with this account.
-
sessions_from_puppet
(puppet)[源代码]¶ Given a puppeted object, return all controlling sessions.
- 参数
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.
- 参数
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)[源代码]¶ Given a client identification hash (for session types that offer them) return all sessions with a matching hash.
- Args
csessid (str): The session hash.
- 返回
sessions (list) – The sessions with matching .csessid, if any.
-
announce_all
(message)[源代码]¶ Send message to all connected sessions
- 参数
message (str) – Message to send.
-
data_out
(session, **kwargs)[源代码]¶ Sending data Server -> Portal
- 参数
session (Session) – Session to relay to.
text (str, optional) – text data to return
提示
The outdata will be scrubbed for sending across the wire here.
-
get_inputfuncs
()[源代码]¶ Get all registered inputfuncs (access function)
- 返回
inputfuncs (dict) – A dict of {key:inputfunc,…}
-
data_in
(session, **kwargs)[源代码]¶ 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)[源代码]¶ 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.
- 参数
sessions (Session) – Session.
- 关键字参数
any (tuple) – Incoming data from protocol, each on the form commandname=((args), {kwargs}).
-