Still messing with getting the webclient to talk properly to the server.
This commit is contained in:
parent
c511263f63
commit
2890371900
6 changed files with 57 additions and 46 deletions
|
|
@ -105,6 +105,9 @@ def text(session, *args, **kwargs):
|
||||||
cmdhandler(session, text, callertype="session", session=session)
|
cmdhandler(session, text, callertype="session", session=session)
|
||||||
session.update_session_counters()
|
session.update_session_counters()
|
||||||
|
|
||||||
|
def echo(session, *args, **kwargs):
|
||||||
|
session.data_out(text=(args, kwargs))
|
||||||
|
|
||||||
def default(session, cmdname, *args, **kwargs):
|
def default(session, cmdname, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Default catch-function. This is like all other input functions except
|
Default catch-function. This is like all other input functions except
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,9 @@ class PortalSessionHandler(SessionHandler):
|
||||||
self.data_out(session, text=_ERROR_COMMAND_OVERFLOW)
|
self.data_out(session, text=_ERROR_COMMAND_OVERFLOW)
|
||||||
return
|
return
|
||||||
# scrub data
|
# scrub data
|
||||||
|
print ("portalsessionhandler before clean:", session, kwargs)
|
||||||
kwargs = self.clean_senddata(session, kwargs)
|
kwargs = self.clean_senddata(session, kwargs)
|
||||||
|
print ("portalsessionhandler after clean:", session, kwargs)
|
||||||
|
|
||||||
# relay data to Server
|
# relay data to Server
|
||||||
self.command_counter += 1
|
self.command_counter += 1
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,6 @@ class WebSocketClient(Protocol, Session):
|
||||||
self.transport.setTcpKeepAlive(1)
|
self.transport.setTcpKeepAlive(1)
|
||||||
self.sessionhandler.connect(self)
|
self.sessionhandler.connect(self)
|
||||||
|
|
||||||
self.datamap = {"text": self.send_text,
|
|
||||||
"prompt": self.send_prompt,
|
|
||||||
"_default": self.data_oob}
|
|
||||||
|
|
||||||
def disconnect(self, reason=None):
|
def disconnect(self, reason=None):
|
||||||
"""
|
"""
|
||||||
Generic hook for the engine to call in order to
|
Generic hook for the engine to call in order to
|
||||||
|
|
@ -95,8 +91,9 @@ class WebSocketClient(Protocol, Session):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cmdarray = json.loads(string)
|
cmdarray = json.loads(string)
|
||||||
|
print "dataReceived:", cmdarray
|
||||||
if cmdarray:
|
if cmdarray:
|
||||||
self.data_in(**{cmdarray[0]:cmdarray[1:]})
|
self.data_in(**{cmdarray[0]:[cmdarray[1], cmdarray[2]]})
|
||||||
|
|
||||||
def sendLine(self, line):
|
def sendLine(self, line):
|
||||||
"""
|
"""
|
||||||
|
|
@ -129,8 +126,7 @@ class WebSocketClient(Protocol, Session):
|
||||||
"""
|
"""
|
||||||
self.sessionhandler.data_out(self, **kwargs)
|
self.sessionhandler.data_out(self, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
def send_text(self, *args, **kwargs):
|
||||||
def send_text(session, *args, **kwargs):
|
|
||||||
"""
|
"""
|
||||||
Send text data. This will pre-process the text for
|
Send text data. This will pre-process the text for
|
||||||
color-replacement, conversion to html etc.
|
color-replacement, conversion to html etc.
|
||||||
|
|
@ -165,25 +161,23 @@ class WebSocketClient(Protocol, Session):
|
||||||
|
|
||||||
if raw:
|
if raw:
|
||||||
# no processing
|
# no processing
|
||||||
data = json.dumps((text,) + args)
|
data = json.dumps([cmd, (text,) + args, kwargs])
|
||||||
else:
|
else:
|
||||||
# send normally, with html processing
|
# send normally, with html processing
|
||||||
data = json.dumps((cmd, parse_html(text, strip_ansi=nomarkup)) + args)
|
data = json.dumps([cmd, (parse_html(text, strip_ansi=nomarkup),) + args, kwargs])
|
||||||
session.sendLine(data)
|
self.sendLine(data)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
def send_prompt(self, *args, **kwargs):
|
||||||
def send_prompt(session, *args, **kwargs):
|
|
||||||
kwargs["options"].update({"send_prompt": True})
|
kwargs["options"].update({"send_prompt": True})
|
||||||
session.send_text(*args, **kwargs)
|
self.send_text(*args, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
def send_default(session, cmdname, *args, **kwargs):
|
||||||
def send_oob(session, *args, **kwargs):
|
|
||||||
"""
|
"""
|
||||||
Data Evennia -> User.
|
Data Evennia -> User.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cmd (str): The first argument will always be the oob cmd name.
|
cmdname (str): The first argument will always be the oob cmd name.
|
||||||
*args (any): Remaining args will be arguments for `cmd`.
|
*args (any): Remaining args will be arguments for `cmd`.
|
||||||
|
|
||||||
Kwargs:
|
Kwargs:
|
||||||
|
|
@ -192,5 +186,4 @@ class WebSocketClient(Protocol, Session):
|
||||||
client instead.
|
client instead.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if args:
|
session.sendLine(json.dumps([cmdname, args, kwargs]))
|
||||||
session.sendLine(json.dumps(args))
|
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,7 @@ class SessionHandler(dict):
|
||||||
|
|
||||||
rkwargs = {}
|
rkwargs = {}
|
||||||
for key, data in kwargs.iteritems():
|
for key, data in kwargs.iteritems():
|
||||||
|
print "sessionhandler.clean_senddata:", key, data
|
||||||
if not data:
|
if not data:
|
||||||
rkwargs[key] = [ [], {} ]
|
rkwargs[key] = [ [], {} ]
|
||||||
elif isinstance(data, dict):
|
elif isinstance(data, dict):
|
||||||
|
|
|
||||||
|
|
@ -94,16 +94,18 @@ An "emitter" object must have a function
|
||||||
// callback (func): If given, will be given an eventual return
|
// callback (func): If given, will be given an eventual return
|
||||||
// value from the backend.
|
// value from the backend.
|
||||||
//
|
//
|
||||||
msg: function (cmdname, kwargs, callback) {
|
msg: function (cmdname, args, kwargs, callback) {
|
||||||
kwargs.cmdid = cmdid++;
|
kwargs.cmdid = cmdid++;
|
||||||
var data = kwargs ? [cmdname, kwargs] : [cmdname, {}];
|
var outargs = args ? args : [];
|
||||||
|
var outkwargs = kwargs ? kwargs : {};
|
||||||
|
var data = [cmdname, outargs, outkwargs];
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
cmdmap[cmdid] = callback;
|
cmdmap[cmdid] = callback;
|
||||||
}
|
}
|
||||||
this.connection.msg(data);
|
this.connection.msg(data);
|
||||||
|
|
||||||
log('cmd called with following args: ' + cmdname, ', ' + kwargs + ', ' + callback);
|
log('client msg sending: ' + cmdname + " " + args + " " + outargs + " " + outkwargs);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Evennia -> Client.
|
// Evennia -> Client.
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,18 @@
|
||||||
<h1>Webclient!</h1>
|
<h1>Webclient!</h1>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
<input type="text" name="input">
|
<input id="maininput" type="text" name="input">
|
||||||
<input type="button" value="Send" onClick="Evennia.msg">
|
<input type="button" value="Send" onClick="sendInput()">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script language="javascript" type="text/javascript">
|
||||||
|
|
||||||
|
var sendInput = function() {
|
||||||
|
var inmsg = $("#maininput").val();
|
||||||
|
log("sendInput: " + inmsg);
|
||||||
|
Evennia.msg("text", [inmsg], {});
|
||||||
|
};
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue