Add webclient browser name identifier. Resolve #1650
This commit is contained in:
parent
6fef01a3b1
commit
a0c70ce465
3 changed files with 50 additions and 4 deletions
|
|
@ -54,6 +54,7 @@ class WebSocketClient(WebSocketServerProtocol, _BASE_SESSION_CLASS):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.protocol_key = "webclient/websocket"
|
self.protocol_key = "webclient/websocket"
|
||||||
|
self.browserstr = ""
|
||||||
|
|
||||||
def get_client_session(self):
|
def get_client_session(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -65,7 +66,8 @@ class WebSocketClient(WebSocketServerProtocol, _BASE_SESSION_CLASS):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.csessid = self.http_request_uri.split("?", 1)[1]
|
# client will connect with wsurl?csessid&browserid
|
||||||
|
webarg = self.http_request_uri.split("?", 1)[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# this may happen for custom webclients not caring for the
|
# this may happen for custom webclients not caring for the
|
||||||
# browser session.
|
# browser session.
|
||||||
|
|
@ -77,6 +79,11 @@ class WebSocketClient(WebSocketServerProtocol, _BASE_SESSION_CLASS):
|
||||||
self.csessid = None
|
self.csessid = None
|
||||||
logger.log_trace(str(self))
|
logger.log_trace(str(self))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
self.csessid, *browserstr = webarg.split("&", 1)
|
||||||
|
if browserstr:
|
||||||
|
self.browserstr = str(browserstr[0])
|
||||||
|
|
||||||
if self.csessid:
|
if self.csessid:
|
||||||
return _CLIENT_SESSIONS(session_key=self.csessid)
|
return _CLIENT_SESSIONS(session_key=self.csessid)
|
||||||
|
|
||||||
|
|
@ -118,7 +125,8 @@ class WebSocketClient(WebSocketServerProtocol, _BASE_SESSION_CLASS):
|
||||||
self.sessid = old_session.sessid
|
self.sessid = old_session.sessid
|
||||||
self.sessionhandler.disconnect(old_session)
|
self.sessionhandler.disconnect(old_session)
|
||||||
|
|
||||||
self.protocol_flags["CLIENTNAME"] = "Evennia Webclient (websocket)"
|
browserstr = f":{self.browserstr}" if self.browserstr else ""
|
||||||
|
self.protocol_flags["CLIENTNAME"] = f"Evennia Webclient (websocket{browserstr})"
|
||||||
self.protocol_flags["UTF-8"] = True
|
self.protocol_flags["UTF-8"] = True
|
||||||
self.protocol_flags["OOB"] = True
|
self.protocol_flags["OOB"] = True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,19 @@ class AjaxWebClient(resource.Resource):
|
||||||
"""
|
"""
|
||||||
return html.escape(request.args[b"csessid"][0].decode("utf-8"))
|
return html.escape(request.args[b"csessid"][0].decode("utf-8"))
|
||||||
|
|
||||||
|
def get_browserstr(self, request):
|
||||||
|
"""
|
||||||
|
Get browser-string out of the request.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (Request): Incoming request object.
|
||||||
|
Returns:
|
||||||
|
str: The browser name.
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
return html.escape(request.args[b"browserstr"][0].decode("utf-8"))
|
||||||
|
|
||||||
def at_login(self):
|
def at_login(self):
|
||||||
"""
|
"""
|
||||||
Called when this session gets authenticated by the server.
|
Called when this session gets authenticated by the server.
|
||||||
|
|
@ -181,6 +194,7 @@ class AjaxWebClient(resource.Resource):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
csessid = self.get_client_sessid(request)
|
csessid = self.get_client_sessid(request)
|
||||||
|
browserstr = self.get_browserstr(request)
|
||||||
|
|
||||||
remote_addr = request.getClientIP()
|
remote_addr = request.getClientIP()
|
||||||
|
|
||||||
|
|
@ -204,6 +218,7 @@ class AjaxWebClient(resource.Resource):
|
||||||
sess.init_session("ajax/comet", remote_addr, self.sessionhandler)
|
sess.init_session("ajax/comet", remote_addr, self.sessionhandler)
|
||||||
|
|
||||||
sess.csessid = csessid
|
sess.csessid = csessid
|
||||||
|
sess.browserstr = browserstr
|
||||||
csession = _CLIENT_SESSIONS(session_key=sess.csessid)
|
csession = _CLIENT_SESSIONS(session_key=sess.csessid)
|
||||||
uid = csession and csession.get("webclient_authenticated_uid", False)
|
uid = csession and csession.get("webclient_authenticated_uid", False)
|
||||||
if uid:
|
if uid:
|
||||||
|
|
@ -218,6 +233,11 @@ class AjaxWebClient(resource.Resource):
|
||||||
self.keep_alive = LoopingCall(self._keepalive)
|
self.keep_alive = LoopingCall(self._keepalive)
|
||||||
self.keep_alive.start(_KEEPALIVE, now=False)
|
self.keep_alive.start(_KEEPALIVE, now=False)
|
||||||
|
|
||||||
|
browserstr = f":{browserstr}" if browserstr else ""
|
||||||
|
sess.protocol_flags["CLIENTNAME"] = f"Evennia Webclient (ajax{browserstr})"
|
||||||
|
sess.protocol_flags["UTF-8"] = True
|
||||||
|
sess.protocol_flags["OOB"] = True
|
||||||
|
|
||||||
# actually do the connection
|
# actually do the connection
|
||||||
sess.sessionhandler.connect(sess)
|
sess.sessionhandler.connect(sess)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ An "emitter" object must have a function
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Important - we pass csessid tacked on the url
|
// Important - we pass csessid tacked on the url
|
||||||
websocket = new WebSocket(wsurl + '?' + csessid);
|
websocket = new WebSocket(wsurl + '?' + csessid + '&' + browser);
|
||||||
|
|
||||||
// Handle Websocket open event
|
// Handle Websocket open event
|
||||||
websocket.onopen = function (event) {
|
websocket.onopen = function (event) {
|
||||||
|
|
@ -310,7 +310,7 @@ An "emitter" object must have a function
|
||||||
$.ajax({type: "POST", url: "/webclientdata",
|
$.ajax({type: "POST", url: "/webclientdata",
|
||||||
async: true, cache: false, timeout: 50000,
|
async: true, cache: false, timeout: 50000,
|
||||||
datatype: "json",
|
datatype: "json",
|
||||||
data: {mode: "init", csessid: csessid},
|
data: {mode: "init", csessid: csessid, browserstr: browser},
|
||||||
|
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
open = true;
|
open = true;
|
||||||
|
|
@ -450,6 +450,24 @@ function log() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// figure out the browser info string
|
||||||
|
var browser = (function (agent) {
|
||||||
|
"use strict"
|
||||||
|
switch (true) {
|
||||||
|
case agent.indexOf("edge") > -1: return "edge";
|
||||||
|
case agent.indexOf("edg") > -1: return "chromium based edge (dev or canary)";
|
||||||
|
case agent.indexOf("opr") > -1 && !!window.opr: return "opera";
|
||||||
|
case agent.indexOf("chrome") > -1 && !!window.chrome: return "chrome";
|
||||||
|
case agent.indexOf("trident") > -1: return "ie";
|
||||||
|
case agent.indexOf("firefox") > -1: return "firefox";
|
||||||
|
case agent.indexOf("safari") > -1: return "safari";
|
||||||
|
default: return "other";
|
||||||
|
}
|
||||||
|
})(window.navigator.userAgent.toLowerCase());
|
||||||
|
console.log(window.navigator.userAgent.toLowerCase() + "\n" + browser);
|
||||||
|
|
||||||
|
|
||||||
// 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 () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue