evennia.server.portal.webclient

Webclient based on websockets.

This implements a webclient with WebSockets (http://en.wikipedia.org/wiki/WebSocket) by use of the autobahn-python package’s implementation (https://github.com/crossbario/autobahn-python). It is used together with evennia/web/media/javascript/evennia_websocket_webclient.js.

All data coming into the webclient is in the form of valid JSON on the form

[“inputfunc_name”, [args], {kwarg}]

which represents an “inputfunc” to be called on the Evennia side with args, **kwargs. The most common inputfunc is “text”, which takes just the text input from the command line and interprets it as an Evennia Command: **[“text”, [“look”], {}]*

class evennia.server.portal.webclient.WebSocketClient(*args, **kwargs)[源代码]

基类:autobahn.twisted.websocket.WebSocketServerProtocol, evennia.server.session.Session

Implements the server-side of the Websocket connection.

nonce = 0
__init__(*args, **kwargs)[源代码]

Initialize self. See help(type(self)) for accurate signature.

get_client_session()[源代码]

Get the Client browser session (used for auto-login based on browser session)

返回

csession (ClientSession)

This is a django-specific internal representation

of the browser session.

onOpen()[源代码]

This is called when the WebSocket connection is fully established.

disconnect(reason=None)[源代码]

Generic hook for the engine to call in order to disconnect this protocol.

参数

reason (str or None) – Motivation for the disconnection.

onClose(wasClean, code=None, reason=None)[源代码]

This is executed when the connection is lost for whatever reason. it can also be called directly, from the disconnect method.

参数
  • wasClean (bool) – **True** if the WebSocket was closed cleanly.

  • code (int or None) – Close status as sent by the WebSocket peer.

  • reason (str or None) – Close reason as sent by the WebSocket peer.

onMessage(payload, isBinary)[源代码]

Callback fired when a complete WebSocket message was received.

参数
  • payload (bytes) – The WebSocket message received.

  • isBinary (bool) – Flag indicating whether payload is binary or UTF-8 encoded text.

sendLine(line)[源代码]

Send data to client.

参数

line (str) – Text to send.

at_login()[源代码]
data_in(**kwargs)[源代码]

Data User > Evennia.

参数
  • text (str) – Incoming text.

  • kwargs (any) – Options from protocol.

提示

At initilization, the client will send the special ‘csessid’ command to identify its browser session hash with the Evennia side.

The websocket client will also pass ‘websocket_close’ command to report that the client has been closed and that the session should be disconnected.

Both those commands are parsed and extracted already at this point.

send_text(*args, **kwargs)[源代码]

Send text data. This will pre-process the text for color-replacement, conversion to html etc.

参数

text (str) – Text to send.

关键字参数

options (dict) – Options-dict with the following keys understood: - raw (bool): No parsing at all (leave ansi-to-html markers unparsed). - nocolor (bool): Clean out all color. - screenreader (bool): Use Screenreader mode. - send_prompt (bool): Send a prompt with parsed html

send_prompt(*args, **kwargs)[源代码]
send_default(cmdname, *args, **kwargs)[源代码]

Data Evennia -> User.

参数
  • cmdname (str) – The first argument will always be the oob cmd name.

  • *args (any) – Remaining args will be arguments for cmd.

关键字参数

options (dict) – These are ignored for oob commands. Use command arguments (which can hold dicts) to send instructions to the client instead.