From 31246ecd04c0f57631587e25ae0245d086098ddc Mon Sep 17 00:00:00 2001 From: teravus Date: Fri, 4 Oct 2013 20:53:01 -0500 Subject: [PATCH] * Added a unique and interesting WebSocket grid login processor by hijacking the LLSD login code. This sends the data through the normal login channels and spits out a JSON object back that mimics the login response. Feel free to comment on the best way to set this up as a config option. --- .../Server/Handlers/Login/LLLoginHandlers.cs | 56 +++++++++++++++++++ .../Login/LLLoginServiceInConnector.cs | 1 + 2 files changed, 57 insertions(+) diff --git a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs index f83a23998a..e4a0ffa3cd 100644 --- a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs +++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs @@ -53,6 +53,7 @@ namespace OpenSim.Server.Handlers.Login private ILoginService m_LocalService; private bool m_Proxy; + public LLLoginHandlers(ILoginService service, bool hasProxy) { @@ -213,6 +214,61 @@ namespace OpenSim.Server.Handlers.Login return FailedOSDResponse(); } + public void HandleWebSocketLoginEvents(string path, WebSocketHttpServerHandler sock) + { + sock.MaxPayloadSize = 16384; //16 kb payload + sock.InitialMsgTimeout = 5000; //5 second first message to trigger at least one of these events + sock.NoDelay_TCP_Nagle = true; + sock.OnData += delegate(object sender, WebsocketDataEventArgs data) { sock.Close("fail"); }; + sock.OnPing += delegate(object sender, PingEventArgs pingdata) { sock.Close("fail"); }; + sock.OnPong += delegate(object sender, PongEventArgs pongdata) { sock.Close("fail"); }; + sock.OnText += delegate(object sender, WebsocketTextEventArgs text) + { + OSD request = null; + try + { + request = OSDParser.DeserializeJson(text.Data); + if (!(request is OSDMap)) + { + sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse())); + } + else + { + OSDMap req = request as OSDMap; + string first = req["firstname"].AsString(); + string last = req["lastname"].AsString(); + string passwd = req["passwd"].AsString(); + string start = req["startlocation"].AsString(); + string version = req["version"].AsString(); + string channel = req["channel"].AsString(); + string mac = req["mac"].AsString(); + string id0 = req["id0"].AsString(); + UUID scope = UUID.Zero; + IPEndPoint endPoint = + (sender as WebSocketHttpServerHandler).GetRemoteIPEndpoint(); + LoginResponse reply = null; + reply = m_LocalService.Login(first, last, passwd, start, scope, version, + channel, mac, id0, endPoint); + sock.SendMessage(OSDParser.SerializeJsonString(reply.ToOSDMap())); + + } + + } + catch (Exception) + { + sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse())); + } + finally + { + sock.Close("success"); + } + }; + + sock.HandshakeAndUpgrade(); + + } + + private XmlRpcResponse FailedXMLRPCResponse() { Hashtable hash = new Hashtable(); diff --git a/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs index 1fb0dbc70b..97e8295690 100644 --- a/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs +++ b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs @@ -98,6 +98,7 @@ namespace OpenSim.Server.Handlers.Login server.AddXmlRPCHandler("login_to_simulator", loginHandlers.HandleXMLRPCLogin, false); server.AddXmlRPCHandler("set_login_level", loginHandlers.HandleXMLRPCSetLoginLevel, false); server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin); + server.AddWebSocketHandler("/WebSocket/GridLogin", loginHandlers.HandleWebSocketLoginEvents); } } }