Added validationMade() to websocket protocol, to be able to parse the
incoming host information at connection (for getting the browser session id directly from the path as ws://.../?csessid).
This commit is contained in:
parent
a39d52dd7e
commit
81170b69d0
2 changed files with 11 additions and 3 deletions
|
|
@ -48,6 +48,7 @@ class WebSocketClient(Protocol, Session):
|
||||||
This is called when the connection is first established.
|
This is called when the connection is first established.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
self.transport.validationMade = self.validationMade
|
||||||
client_address = self.transport.client
|
client_address = self.transport.client
|
||||||
client_address = client_address[0] if client_address else None
|
client_address = client_address[0] if client_address else None
|
||||||
self.init_session("websocket", client_address, self.factory.sessionhandler)
|
self.init_session("websocket", client_address, self.factory.sessionhandler)
|
||||||
|
|
@ -55,6 +56,14 @@ class WebSocketClient(Protocol, Session):
|
||||||
self.transport.setTcpKeepAlive(1)
|
self.transport.setTcpKeepAlive(1)
|
||||||
self.sessionhandler.connect(self)
|
self.sessionhandler.connect(self)
|
||||||
|
|
||||||
|
def validationMade(self):
|
||||||
|
"""
|
||||||
|
This is called from the (modified) txws websocket library when
|
||||||
|
the ws handshake and validation has completed fully.
|
||||||
|
"""
|
||||||
|
#print "validationMade:", self.transport.location.split("?", 1)[1]
|
||||||
|
pass
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -80,6 +89,7 @@ class WebSocketClient(Protocol, Session):
|
||||||
self.sessionhandler.disconnect(self)
|
self.sessionhandler.disconnect(self)
|
||||||
self.transport.close()
|
self.transport.close()
|
||||||
|
|
||||||
|
|
||||||
def dataReceived(self, string):
|
def dataReceived(self, string):
|
||||||
"""
|
"""
|
||||||
Method called when data is coming in over the websocket
|
Method called when data is coming in over the websocket
|
||||||
|
|
@ -101,7 +111,6 @@ class WebSocketClient(Protocol, Session):
|
||||||
line (str): Text to send.
|
line (str): Text to send.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.transport.write(line)
|
return self.transport.write(line)
|
||||||
|
|
||||||
def data_in(self, **kwargs):
|
def data_in(self, **kwargs):
|
||||||
|
|
@ -175,7 +184,6 @@ class WebSocketClient(Protocol, Session):
|
||||||
args[0] = text
|
args[0] = text
|
||||||
else:
|
else:
|
||||||
args[0] = parse_html(text, strip_ansi=nomarkup)
|
args[0] = parse_html(text, strip_ansi=nomarkup)
|
||||||
print "send_text:", cmd, args, kwargs
|
|
||||||
|
|
||||||
# send to client on required form [cmdname, args, kwargs]
|
# send to client on required form [cmdname, args, kwargs]
|
||||||
self.sendLine(json.dumps([cmd, args, kwargs]))
|
self.sendLine(json.dumps([cmd, args, kwargs]))
|
||||||
|
|
@ -200,5 +208,4 @@ class WebSocketClient(Protocol, Session):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not cmdname == "options":
|
if not cmdname == "options":
|
||||||
#print "websocket.send_default", cmdname, args, kwargs
|
|
||||||
session.sendLine(json.dumps([cmdname, args, kwargs]))
|
session.sendLine(json.dumps([cmdname, args, kwargs]))
|
||||||
|
|
|
||||||
|
|
@ -537,6 +537,7 @@ class WebSocketProtocol(ProtocolWrapper):
|
||||||
log.msg("Can't support protocol version %s!" % version)
|
log.msg("Can't support protocol version %s!" % version)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self.validationMade() # custom Evennia addition
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def dataReceived(self, data):
|
def dataReceived(self, data):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue