Skip to content

Commit

Permalink
Added validationMade() to websocket protocol, to be able to parse the
Browse files Browse the repository at this point in the history
incoming host information at connection (for getting the browser
session id directly from the path as ws://.../?csessid).
  • Loading branch information
Griatch committed May 31, 2016
1 parent a39d52d commit 81170b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions evennia/server/portal/webclient.py
Expand Up @@ -48,13 +48,22 @@ def connectionMade(self):
This is called when the connection is first established.
"""
self.transport.validationMade = self.validationMade
client_address = self.transport.client
client_address = client_address[0] if client_address else None
self.init_session("websocket", client_address, self.factory.sessionhandler)
# watch for dead links
self.transport.setTcpKeepAlive(1)
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):
"""
Generic hook for the engine to call in order to
Expand All @@ -80,6 +89,7 @@ def connectionLost(self, reason):
self.sessionhandler.disconnect(self)
self.transport.close()


def dataReceived(self, string):
"""
Method called when data is coming in over the websocket
Expand All @@ -101,7 +111,6 @@ def sendLine(self, line):
line (str): Text to send.
"""

return self.transport.write(line)

def data_in(self, **kwargs):
Expand Down Expand Up @@ -175,7 +184,6 @@ def send_text(self, *args, **kwargs):
args[0] = text
else:
args[0] = parse_html(text, strip_ansi=nomarkup)
print "send_text:", cmd, args, kwargs

# send to client on required form [cmdname, args, kwargs]
self.sendLine(json.dumps([cmd, args, kwargs]))
Expand All @@ -200,5 +208,4 @@ def send_default(session, cmdname, *args, **kwargs):
"""
if not cmdname == "options":
#print "websocket.send_default", cmdname, args, kwargs
session.sendLine(json.dumps([cmdname, args, kwargs]))
1 change: 1 addition & 0 deletions evennia/utils/txws.py
Expand Up @@ -537,6 +537,7 @@ def validateHeaders(self):
log.msg("Can't support protocol version %s!" % version)
return False

self.validationMade() # custom Evennia addition
return True

def dataReceived(self, data):
Expand Down

0 comments on commit 81170b6

Please sign in to comment.