Got the initial connect screen to display in webclient again.

This commit is contained in:
Griatch 2016-02-12 12:25:30 +01:00
parent 66641b54ab
commit d48691e121
5 changed files with 52 additions and 43 deletions

View file

@ -369,13 +369,21 @@ class PortalSessionHandler(SessionHandler):
# distribute outgoing data to the correct session methods. # distribute outgoing data to the correct session methods.
if session: if session:
print ("portalsessionhandler.data_out:", session, kwargs)
for cmdname, (cmdargs, cmdkwargs) in kwargs.iteritems(): for cmdname, (cmdargs, cmdkwargs) in kwargs.iteritems():
try: funcname = "send_%s" % cmdname
getattr(session, "send_%s" % cmdname)(*cmdargs, **cmdkwargs) if hasattr(session, funcname):
except AttributeError: # better to use hassattr here over try..except
session.send_default(cmdname, *cmdargs, **cmdkwargs) # - avoids hiding AttributeErrors in the call.
except Exception: try:
log_trace() getattr(session, funcname)(*cmdargs, **cmdkwargs)
except Exception:
log_trace()
else:
try:
# note that send_default always takes cmdname
# as arg too.
session.send_default(cmdname, *cmdargs, **cmdkwargs)
except Exception:
log_trace()
PORTAL_SESSIONS = PortalSessionHandler() PORTAL_SESSIONS = PortalSessionHandler()

View file

@ -143,7 +143,8 @@ class WebSocketClient(Protocol, Session):
""" """
if args: if args:
text = args.pop(0) args = list(args)
text = args[0]
if text is None: if text is None:
return return
options = kwargs.get("options", {}) options = kwargs.get("options", {})
@ -156,16 +157,14 @@ class WebSocketClient(Protocol, Session):
# screenreader mode cleans up output # screenreader mode cleans up output
text = parse_ansi(text, strip_ansi=True, xterm256=False, mxp=False) text = parse_ansi(text, strip_ansi=True, xterm256=False, mxp=False)
text = _RE_SCREENREADER_REGEX.sub("", text) text = _RE_SCREENREADER_REGEX.sub("", text)
cmd = "prompt" if prompt else "text" cmd = "prompt" if prompt else "text"
if raw: if raw:
# no processing args[0] = text
data = json.dumps([cmd, (text,) + args, kwargs])
else: else:
# send normally, with html processing args[0] = parse_html(text, strip_ansi=nomarkup)
data = json.dumps([cmd, (parse_html(text, strip_ansi=nomarkup),) + args, kwargs])
self.sendLine(data) # send to client on required form [cmdname, args, kwargs]
self.sendLine(json.dumps([cmd, args, kwargs]))
def send_prompt(self, *args, **kwargs): def send_prompt(self, *args, **kwargs):
@ -186,4 +185,5 @@ class WebSocketClient(Protocol, Session):
client instead. client instead.
""" """
print "send_default", cmdname, args, kwargs
session.sendLine(json.dumps([cmdname, args, kwargs])) session.sendLine(json.dumps([cmdname, args, kwargs]))

View file

@ -73,7 +73,7 @@ An "emitter" object must have a function
// make it safe to call multiple times. // make it safe to call multiple times.
return; return;
} }
this.initialized = true; this.initialized = true;
opts = opts || {}; opts = opts || {};
this.emitter = opts.emitter || new DefaultEmitter(); this.emitter = opts.emitter || new DefaultEmitter();
@ -112,7 +112,7 @@ An "emitter" object must have a function
} }
this.connection.msg(data); this.connection.msg(data);
log('client msg sending: ' + cmdname + " " + args + " " + outargs + " " + outkwargs); log('client msg sending: ', cmdname, args, outargs, outkwargs);
}, },
// Evennia -> Client. // Evennia -> Client.
@ -126,7 +126,6 @@ An "emitter" object must have a function
// kwargs (obj): keyword-args to listener // kwargs (obj): keyword-args to listener
// //
emit: function (cmdname, args, kwargs) { emit: function (cmdname, args, kwargs) {
log('emit called with args: ' + cmdname + ',' + args + ',' + kwargs);
if (kwargs.cmdid) { if (kwargs.cmdid) {
cmdmap[kwargs.cmdid].apply(this, [args, kwargs]); cmdmap[kwargs.cmdid].apply(this, [args, kwargs]);
delete cmdmap[kwargs.cmdid]; delete cmdmap[kwargs.cmdid];
@ -153,8 +152,7 @@ An "emitter" object must have a function
// kwargs (obj): Argument to the listener. // kwargs (obj): Argument to the listener.
// //
var emit = function (cmdname, args, kwargs) { var emit = function (cmdname, args, kwargs) {
log('emit', cmdname, args, kwargs); log("DefaultEmitter.emit:", cmdname, args, kwargs);
if (listeners[cmdname]) { if (listeners[cmdname]) {
listeners[cmdname].apply(this, [args, kwargs]); listeners[cmdname].apply(this, [args, kwargs]);
}; };
@ -168,6 +166,7 @@ An "emitter" object must have a function
// to listen to cmdname events. // to listen to cmdname events.
// //
var on = function (cmdname, listener) { var on = function (cmdname, listener) {
log("DefaultEmitter.on", cmdname, listener);
if (typeof(listener === 'function')) { if (typeof(listener === 'function')) {
listeners[cmdname] = listener; listeners[cmdname] = listener;
}; };
@ -203,7 +202,7 @@ An "emitter" object must have a function
websocket.onerror = function (event) { websocket.onerror = function (event) {
log("Websocket error to ", wsurl, event); log("Websocket error to ", wsurl, event);
Evennia.emit('socket:error', [], event); Evennia.emit('socket:error', [], event);
if (websocket.readyState === websocket.CLOSED) { if (websocket.readyState === websocket.CLOSED) {
log("Websocket failed. Falling back to Ajax..."); log("Websocket failed. Falling back to Ajax...");
Evennia.connection = AjaxCometConnection(); Evennia.connection = AjaxCometConnection();
} }
@ -221,7 +220,7 @@ An "emitter" object must have a function
Evennia.emit(data[0], data[1], data[2]); Evennia.emit(data[0], data[1], data[2]);
}; };
websocket.msg = function(cmdname, args, kwargs) { websocket.msg = function(cmdname, args, kwargs) {
// send // send
websocket.send(JSON.stringify([cmdname, args, kwargs])); websocket.send(JSON.stringify([cmdname, args, kwargs]));
}; };
@ -290,17 +289,17 @@ An "emitter" object must have a function
// Args: // Args:
// msg (str): Message to log to console. // msg (str): Message to log to console.
// //
function log(msg) { function log() {
if (Evennia.debug) { if (Evennia.debug) {
console.log(msg); console.log(arguments);
} }
} }
// Called when page has finished loading (kicks the client into gear) // Called when page has finished loading (kicks the client into gear)
$(document).ready(function() { $(document).ready(function() {
setTimeout( function () { setTimeout( function () {
Evennia.init() Evennia.init()
}, },
500 500
); );
}); });

View file

@ -7,12 +7,12 @@
* *
* The job of this code is to create listeners to subscribe to evennia * The job of this code is to create listeners to subscribe to evennia
* messages, via Evennia.emitter.on(cmdname, listener) and to handle * messages, via Evennia.emitter.on(cmdname, listener) and to handle
* input from the user and send it to * input from the user and send it to
* Evennia.msg(cmdname, args, kwargs, [callback]). * Evennia.msg(cmdname, args, kwargs, [callback]).
* *
*/ */
// //
// GUI Elements // GUI Elements
// //
@ -28,9 +28,9 @@ var inputlog = function() {
history[0] = ''; // the very latest input is empty for new entry. history[0] = ''; // the very latest input is empty for new entry.
function history_back() { function history_back() {
// step backwards in history stack // step backwards in history stack
history_pos = Math.min(++history_pos, history.length - 1); history_pos = Math.min(++history_pos, history.length - 1);
return history[history.length - 1 - history_pos]; return history[history.length - 1 - history_pos];
} }
function history_fwd() { function history_fwd() {
// step forwards in history stack // step forwards in history stack
@ -47,7 +47,7 @@ var inputlog = function() {
history[history.length] = ''; history[history.length] = '';
} }
} }
return {back: history_back, return {back: history_back,
fwd: history_fwd, fwd: history_fwd,
add: history_add} add: history_add}
}; };
@ -91,7 +91,7 @@ $.fn.appendCaret = function() {
}; };
// GUI Event Handlers // GUI Event Handlers
$(document).keydown( function(event) { $(document).keydown( function(event) {
// catch all keyboard input, handle special chars // catch all keyboard input, handle special chars
@ -126,16 +126,17 @@ function set_window_size() {
$(window).resize(set_window_size); $(window).resize(set_window_size);
// //
// Listeners // Listeners
// //
function doText(args, kwargs) { function doText(args, kwargs) {
// append message to previous ones // append message to previous ones
log("doText:", args, kwargs);
$("#messagewindow").append( $("#messagewindow").append(
"<div class='msg out>" + args[0] + "</div>"); "<div class='msg out'>" + args[0] + "</div>");
// scroll message window to bottom // scroll message window to bottom
$("#messagewindow").animate({scrollTop: $('#messageindow')[0].scrollHeight}); $("#messagewindow").animate({scrollTop: $('#messagewindow')[0].scrollHeight});
} }
function doPrompt(args, kwargs) { function doPrompt(args, kwargs) {
@ -147,17 +148,18 @@ function doPrompt(args, kwargs) {
$(document).ready(function() { $(document).ready(function() {
// a small timeout to stop 'loading' indicator in Chrome // a small timeout to stop 'loading' indicator in Chrome
Evennia.init() Evennia.init()
// register listeners // register listeners
log("register listeners ...");
Evennia.emitter.on("text", doText); Evennia.emitter.on("text", doText);
Evennia.emitter.on("prompt", doPrompt); Evennia.emitter.on("prompt", doPrompt);
set_window_size(); set_window_size();
// set an idle timer to avoid proxy servers to time out on us (every 3 minutes) // set an idle timer to avoid proxy servers to time out on us (every 3 minutes)
setInterval(function() { setInterval(function() {
log('Idle tick.'); log('Idle tick.');
Evennia.msg("text", ["idle"], {}); Evennia.msg("text", ["idle"], {});
}, },
60000*3 60000*3
); );
}); });

View file

@ -4,14 +4,14 @@
- connecting - custom connect messages - connecting - custom connect messages
- jquery_import - for changing to a local jquery version - jquery_import - for changing to a local jquery version
- guilib_import - for using your own gui lib - guilib_import - for using your own gui lib
--> -->
{% block client %} {% block client %}
<div id="client"> <div id="client">
<div id="messagewindow"> mainarea </div> <div id="messagewindow"></div>
<div id="inputform"> <div id="inputform">
<textarea name="inputfield" type="text"> </textarea> <textarea name="inputfield" type="text"> </textarea>
</div> </div>
</div> </div>