More fixes to webclient

This commit is contained in:
Griatch 2015-02-15 10:17:20 +01:00
parent 850c5effaa
commit 950c107ed4
2 changed files with 32 additions and 40 deletions

View file

@ -150,7 +150,7 @@ class WebSocketClient(Protocol, Session):
if "prompt" in kwargs: if "prompt" in kwargs:
self.sendLine("PROMPT" + parse_html(kwargs["prompt"], strip_ansi=nomarkup)) self.sendLine("PROMPT" + parse_html(kwargs["prompt"], strip_ansi=nomarkup))
if raw: if raw:
self.sendLine(text) self.sendLine("CMD" + text)
else: else:
self.sendLine(parse_html(text, strip_ansi=nomarkup)) self.sendLine("CMD" + parse_html(text, strip_ansi=nomarkup))

View file

@ -99,38 +99,34 @@ function onMessage(evt) {
// dynamically call oob methods, if available // dynamically call oob methods, if available
// The variables are come on the form [(cmname, [args], {kwargs}), ...] // The variables are come on the form [(cmname, [args], {kwargs}), ...]
var oobcmds = JSON.parse(message); var oobcmds = JSON.parse(message);
var errmsg = "";
try { try {
if (oobcmds instanceof Array == false) { if (oobcmds instanceof Array == false) {
errmsg = "oob instruction's outermost level must be an Array."; throw "oob instruction's outermost level must be an Array.";
throw }
for (var icmd = 0; i < oobcmds.length; icmd++) {
// call each command tuple in turn
var cmdname = oobcmds[icmd][0];
var args = oobcmds[icmd][1];
var kwargs = oobcmds[icmd][2];
// match cmdname with a command existing in the
// CMD_MAP mapping
if (cmdname in CMD_MAP == false) {
throw "oob command " + cmdname + " is not supported by client.";
} }
for (var icmd = 0; i < oobcmds.length; icmd++) { // we have a matching oob command in CMD_MAP.
// call each command tuple in turn // Prepare the error message beforehand
var cmdname = oobcmds[icmd][0]; // Execute
var args = oobcmds[icmd][1]; try {
var kwargs = oobcmds[icmd][2];
// match cmdname with a command existing in the
// CMD_MAP mapping
if (cmdname in CMD_MAP == false) {
errmsg = "oob command " + cmdname + " is not supported by client.";
throw
}
// we have a matching oob command in CMD_MAP.
// Prepare the error message beforehand
errmsg = "Client could not execute OOB function" + "cmdname" + "(" + args + kwargs + ").";
// Execute
CMD_MAP[cmdname](args, kwargs); CMD_MAP[cmdname](args, kwargs);
} }
catch(error) {
doShow("err", "Client could not execute OOB function" + "cmdname" + "(" + args + kwargs + ").");
}
} }
}
catch(error) { catch(error) {
if (errmsg) { doShow("err", error);
doShow("err", errmsg);
}
else {
doShow("err", "Client could not execute OOB function in " + oobcmds);
}
} }
} }
else if (mode == "PRT") { else if (mode == "PRT") {
@ -194,22 +190,21 @@ function doSend(){
function doOOB(cmdstring){ function doOOB(cmdstring){
// Send OOB data from client to Evennia. // Send OOB data from client to Evennia.
// Takes input strings with syntax ["cmdname", args, kwargs] // Takes input strings with syntax ["cmdname", args, kwargs]
var errmsg = "";
try { try {
var cmdtuple = JSON.parse(cmdstring); var cmdtuple = JSON.parse(cmdstring);
var oobmsg = ""; var oobmsg = "";
if (cmdtuple instanceof Array == false) { if (cmdtuple instanceof Array == false) {
// a single command instruction without arguments // a single command instruction without arguments
oobmsg = [cmdtuple, (), {}]; oobmsg = [cmdtuple, [], {}];
} }
else if { else {
switch (cmdtuple.length) { switch (cmdtuple.length) {
case 0: case 0:
throw; throw "No command given";
break; return
case 1: case 1:
// [cmdname] // [cmdname]
oobmsg = [cmdtuple[0], (), {}]; oobmsg = [cmdtuple[0], [], {}];
break; break;
case 2: case 2:
// [cmdname, args] // [cmdname, args]
@ -221,18 +216,15 @@ function doOOB(cmdstring){
break; break;
default: default:
errmsg = "Malformed OOB instruction:" + cmdstring errmsg = "Malformed OOB instruction:" + cmdstring
return
} }
// convert to string and send it to the server // convert to string and send it to the server
oobmsg = JSON.stringify(oobmsg); oobmsg = JSON.stringify(oobmsg);
websocket.send("OOB" + oobmsg); websocket.send("OOB" + oobmsg);
} }
catch { }
if (errmsg) { catch(error) {
doSend("err", errmsg); doSend("err", "OOB output " + cmdtuple + " is not on the right form: " + error);
}
else {
doSend("err", "OOB output " + cmdtuple + " is not on the right form.");
}
} }
} }