evennia.server.portal.webclient_ajax¶
AJAX/COMET fallback webclient
The AJAX/COMET web client consists of two components running on twisted and django. They are both a part of the Evennia website url tree (so the testing website might be located on http://localhost:4001/, whereas the webclient can be found on http://localhost:4001/webclient.)
- /webclient - this url is handled through django’s template
system and serves the html page for the client itself along with its javascript chat program.
- /webclientdata - this url is called by the ajax chat using
POST requests (long-polling when necessary) The WebClient resource in this module will handle these requests and act as a gateway to sessions connected over the webclient.
-
class
evennia.server.portal.webclient_ajax.
LazyEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[源代码]¶ 基类:
json.encoder.JSONEncoder
-
default
(obj)[源代码]¶ Implement this method in a subclass such that it returns a serializable object for **o**, or calls the base implementation (to raise a **TypeError**).
For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o)
-
-
class
evennia.server.portal.webclient_ajax.
AjaxWebClientSession
(*args, **kwargs)[源代码]¶ 基类:
evennia.server.session.Session
This represents a session running in an AjaxWebclient.
-
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.
-
disconnect
(reason='Server disconnected.')[源代码]¶ Disconnect from server.
- 参数
reason (str) – Motivation for the disconnect.
-
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): Remove all color. - screenreader (bool): Use Screenreader mode. - send_prompt (bool): Send a prompt with parsed html
-
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.
-
-
class
evennia.server.portal.webclient_ajax.
AjaxWebClient
[源代码]¶ 基类:
twisted.web.resource.Resource
An ajax/comet long-polling transport
-
client_protocol
¶
-
isLeaf
= True¶
-
allowedMethods
= ('POST',)¶
-
get_client_sessid
(request)[源代码]¶ Helper to get the client session id out of the request.
- 参数
request (Request) – Incoming request object.
- 返回
csessid (int) – The client-session id.
-
get_client_page_id
(request)[源代码]¶ Helper to get the client page id out of the request.
- 参数
request (Request) – Incoming request object.
- 返回
csessid (int) – The client-page id.
-
get_browserstr
(request)[源代码]¶ Get browser-string out of the request.
- 参数
request (Request) – Incoming request object.
- 返回
str – The browser name.
-
lineSend
(csessid, data)[源代码]¶ This adds the data to the buffer and/or sends it to the client as soon as possible.
- 参数
csessid (int) – Session id.
data (list) – A send structure [cmdname, [args], {kwargs}].
-
client_disconnect
(csessid)[源代码]¶ Disconnect session with given id.
- 参数
csessid (int) – Client page+session id.
-
mode_init
(request)[源代码]¶ This is called by render_POST when the client requests an init mode operation (at startup)
- 参数
request (Request) – Incoming request.
-
mode_keepalive
(request)[源代码]¶ This is called by render_POST when the client is replying to the keepalive.
- 参数
request (Request) – Incoming request.
-
mode_input
(request)[源代码]¶ This is called by render_POST when the client is sending data to the server.
- 参数
request (Request) – Incoming request.
-
mode_receive
(request)[源代码]¶ This is called by render_POST when the client is telling us that it is ready to receive data as soon as it is available. This is the basis of a long-polling (comet) mechanism: the server will wait to reply until data is available.
- 参数
request (Request) – Incoming request.
-
mode_close
(request)[源代码]¶ This is called by render_POST when the client is signalling that it is about to be closed.
- 参数
request (Request) – Incoming request.
-
render_POST
(request)[源代码]¶ This function is what Twisted calls with POST requests coming in from the ajax client. The requests should be tagged with different modes depending on what needs to be done, such as initializing or sending/receving data through the request. It uses a long-polling mechanism to avoid sending data unless there is actual data available.
- 参数
request (Request) – Incoming request.
-