Made 'idle' a default in the inputfuncs since this is sent by the webclient. settings.IDLE_CMD will still work but will work alongside idle, the latter will always work like a no-op.

This commit is contained in:
Griatch 2016-04-27 23:47:29 +02:00
parent fc08fc0970
commit 2e692cc639
2 changed files with 20 additions and 18 deletions

View file

@ -26,7 +26,9 @@ from evennia.utils.logger import log_err
from evennia.utils.utils import to_str, to_unicode from evennia.utils.utils import to_str, to_unicode
# always let "idle" work since we use this in the webclient
_IDLE_COMMAND = settings.IDLE_COMMAND _IDLE_COMMAND = settings.IDLE_COMMAND
_IDLE_COMMAND = (_IDLE_COMMAND, ) if _IDLE_COMMAND == "idle" else (_IDLE_COMMAND, "idle")
_GA = object.__getattribute__ _GA = object.__getattribute__
_SA = object.__setattr__ _SA = object.__setattr__
_NA = lambda o: "N/A" _NA = lambda o: "N/A"
@ -56,7 +58,7 @@ def text(session, *args, **kwargs):
return return
# this is treated as a command input # this is treated as a command input
# handle the 'idle' command # handle the 'idle' command
if text.strip() == _IDLE_COMMAND: if text.strip() in _IDLE_COMMAND:
session.update_session_counters(idle=True) session.update_session_counters(idle=True)
return return
if session.player: if session.player:

View file

@ -92,7 +92,7 @@ An "emitter" object must have a function
} }
log('Evennia initialized.') log('Evennia initialized.')
}, },
// Connect to the Evennia server. // Connect to the Evennia server.
// Re-establishes the connection after it is lost. // Re-establishes the connection after it is lost.
// //
@ -104,11 +104,11 @@ An "emitter" object must have a function
this.connection.connect(); this.connection.connect();
log('Evenna reconnecting.') log('Evenna reconnecting.')
}, },
// Returns true if the connection is open. // Returns true if the connection is open.
// //
isConnected: function () { isConnected: function () {
return this.connection.isOpen(); return this.connection.isOpen();
}, },
// client -> Evennia. // client -> Evennia.
@ -217,14 +217,14 @@ An "emitter" object must have a function
var ever_open = false; var ever_open = false;
var websocket = null; var websocket = null;
var wsurl = window.wsurl; var wsurl = window.wsurl;
var connect = function() { var connect = function() {
if (websocket && websocket.readyState != websocket.CLOSED) { if (websocket && websocket.readyState != websocket.CLOSED) {
// No-op if a connection is already open. // No-op if a connection is already open.
return; return;
} }
websocket = new WebSocket(wsurl); websocket = new WebSocket(wsurl);
// Handle Websocket open event // Handle Websocket open event
websocket.onopen = function (event) { websocket.onopen = function (event) {
open = true; open = true;
@ -267,12 +267,12 @@ An "emitter" object must have a function
Evennia.emit(data[0], data[1], data[2]); Evennia.emit(data[0], data[1], data[2]);
}; };
} }
var msg = function(data) { var msg = function(data) {
// send data across the wire. Make sure to json it. // send data across the wire. Make sure to json it.
websocket.send(JSON.stringify(data)); websocket.send(JSON.stringify(data));
}; };
var close = function() { var close = function() {
// tell the server this connection is closing (usually // tell the server this connection is closing (usually
// tied to when the client window is closed). This // tied to when the client window is closed). This
@ -280,13 +280,13 @@ An "emitter" object must have a function
websocket.send(JSON.stringify(["websocket_close", [], {}])); websocket.send(JSON.stringify(["websocket_close", [], {}]));
open = false; open = false;
} }
var isOpen = function() { var isOpen = function() {
return open; return open;
} }
connect(); connect();
return {connect: connect, msg: msg, close: close, isOpen: isOpen}; return {connect: connect, msg: msg, close: close, isOpen: isOpen};
}; };
@ -296,7 +296,7 @@ An "emitter" object must have a function
log("Trying ajax ..."); log("Trying ajax ...");
var client_hash = '0'; var client_hash = '0';
var stop_polling = false; var stop_polling = false;
var is_closing = false; var is_closing = false;
// initialize connection and get hash // initialize connection and get hash
var init = function() { var init = function() {
@ -367,13 +367,13 @@ An "emitter" object must have a function
Evennia.emit("connection_error", ["AJAX/COMET receive error"], err); Evennia.emit("connection_error", ["AJAX/COMET receive error"], err);
log("AJAX/COMET: Server returned error on receive.",req,stat,err); log("AJAX/COMET: Server returned error on receive.",req,stat,err);
stop_polling = true; stop_polling = true;
} }
else { else {
// We'd expect to see a keepalive message rather than // We'd expect to see a keepalive message rather than
// a timeout. Ping the server to see if it's still there. // a timeout. Ping the server to see if it's still there.
msg("idle"); msg("idle");
} }
if (stop_polling) { if (stop_polling) {
// An error of some kind occurred. // An error of some kind occurred.
// Close the connection, if possible. // Close the connection, if possible.
@ -387,8 +387,8 @@ An "emitter" object must have a function
} }
}); });
}; };
// Kill the connection and do house cleaning on the server. // Kill the connection and do house cleaning on the server.
var close = function webclient_close(){ var close = function webclient_close(){
if (is_closing || client_hash === '0') { if (is_closing || client_hash === '0') {
// Already closed or trying to close. // Already closed or trying to close.
@ -420,7 +420,7 @@ An "emitter" object must have a function
} }
}); });
}; };
var isOpen = function () { var isOpen = function () {
return !(is_closing || client_hash === '0'); return !(is_closing || client_hash === '0');
} }