evennia.server.portal.portalsessionhandler¶
Sessionhandler for portal sessions.
-
class
evennia.server.portal.portalsessionhandler.
PortalSessionHandler
(*args, **kwargs)[源代码]¶ 基类:
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.
-
at_server_connection
()[源代码]¶ Called when the Portal establishes connection with the Server. At this point, the AMP connection is already established.
-
generate_sessid
()[源代码]¶ Simply generates a sessid that’s guaranteed to be unique for this Portal run.
- 返回
sessid
-
connect
(session)[源代码]¶ 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.
-
sync
(session)[源代码]¶ 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.
-
disconnect
(session)[源代码]¶ 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().
-
server_connect
(protocol_path='', config={})[源代码]¶ 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='')[源代码]¶ Called by server to force a disconnect by sessid.
- 参数
session (portalsession) – Session to disconnect.
reason (str, optional) – Motivation for disconnect.
-
server_disconnect_all
(reason='')[源代码]¶ Called by server when forcing a clean disconnect for everyone.
- 参数
reason (str, optional) – Motivation for disconnect.
-
server_logged_in
(session, data)[源代码]¶ 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)[源代码]¶ 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
(include_unloggedin=False)[源代码]¶ Count loggedin connections, alternatively count all connections.
- 参数
include_unloggedin (bool) – Also count sessions that have
yet authenticated. (not) –
- 返回
count (int) – Number of sessions.
-
sessions_from_csessid
(csessid)[源代码]¶ 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.
-
announce_all
(message)[源代码]¶ 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)[源代码]¶ Called by portal sessions for relaying data coming in from the protocol to the server.
- 参数
session (PortalSession) – Session receiving data.
- 关键字参数
kwargs (any) – Other data from protocol.
提示
Data is serialized before passed on.
-
data_out
(session, **kwargs)[源代码]¶ Called by server for having the portal relay messages and data to the correct session protocol.
- 参数
session (Session) – Session sending data.
- 关键字参数
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 exits, it sends the data to a method send_default.
-