From 2912aafe259727351eb9405532e45aa3501b7e9a Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Mon, 25 Aug 2008 07:35:17 +0000 Subject: * This commit incorporates the heart of the OpenGridProtocol patch that is currently on Forge in a nice, friendly modular format. * There are a lot of changes and this is quite experimental. It's off by default, but you can turn it on by examining the bottom of the opensim.ini.example for the proper OpenSim.ini settings. Remember, you still need an agent domain.. * Furthermore, it isn't quite right when it comes to teleporting to remote regions (place_avatar) --- OpenSim/Framework/AgentCircuitManager.cs | 31 ++++ .../Cache/UserProfileCacheService.cs | 25 +++ .../Capabilities/LLSDMethodString.cs | 31 ++++ .../Framework/Communications/UserManagerBase.cs | 5 + OpenSim/Framework/IClientAPI.cs | 6 + OpenSim/Framework/Servers/BaseHttpServer.cs | 168 ++++++++++++++++++--- OpenSim/Framework/Servers/LLSDMethod.cs | 3 +- OpenSim/Framework/Servers/LLSDMethodString.cs | 33 ++++ 8 files changed, 278 insertions(+), 24 deletions(-) create mode 100644 OpenSim/Framework/Communications/Capabilities/LLSDMethodString.cs create mode 100644 OpenSim/Framework/Servers/LLSDMethodString.cs (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AgentCircuitManager.cs b/OpenSim/Framework/AgentCircuitManager.cs index 426e8e2..80e2f87 100644 --- a/OpenSim/Framework/AgentCircuitManager.cs +++ b/OpenSim/Framework/AgentCircuitManager.cs @@ -103,10 +103,41 @@ namespace OpenSim.Framework AgentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname; AgentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname; AgentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos; + + // Updated for when we don't know them before calling Scene.NewUserConnection + AgentCircuits[(uint) agentData.circuitcode].SecureSessionID = agentData.SecureSessionID; + AgentCircuits[(uint) agentData.circuitcode].SessionID = agentData.SessionID; + // Console.WriteLine("update user start pos is " + agentData.startpos.X + " , " + agentData.startpos.Y + " , " + agentData.startpos.Z); } } + + /// + /// Sometimes the circuitcode may not be known before setting up the connection + /// + /// + /// + + public bool TryChangeCiruitCode(uint circuitcode, uint newcircuitcode) + { + lock (AgentCircuits) + { + if (AgentCircuits.ContainsKey((uint)circuitcode) && !AgentCircuits.ContainsKey((uint)newcircuitcode)) + { + AgentCircuitData agentData = AgentCircuits[(uint)circuitcode]; + + agentData.circuitcode = newcircuitcode; + + AgentCircuits.Remove((uint)circuitcode); + AgentCircuits.Add(newcircuitcode, agentData); + return true; + } + } + return false; + + } + public void UpdateAgentChildStatus(uint circuitcode, bool childstatus) { if (AgentCircuits.ContainsKey(circuitcode)) diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs index 4e3840b..3b02c88 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs @@ -160,6 +160,31 @@ namespace OpenSim.Framework.Communications.Cache } /// + /// Preloads User data into the region cache. Modules may use this service to add non-standard clients + /// + /// + /// + public void PreloadUserCache(LLUUID userID, UserProfileData userData) + { + if (userID == LLUUID.Zero) + return; + + lock (m_userProfiles) + { + if (m_userProfiles.ContainsKey(userID)) + { + return; + } + else + { + + CachedUserInfo userInfo = new CachedUserInfo(m_commsManager, userData); + m_userProfiles.Add(userID, userInfo); + } + } + } + + /// /// Handle an inventory folder creation request from the client. /// /// diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDMethodString.cs b/OpenSim/Framework/Communications/Capabilities/LLSDMethodString.cs new file mode 100644 index 0000000..31325d8 --- /dev/null +++ b/OpenSim/Framework/Communications/Capabilities/LLSDMethodString.cs @@ -0,0 +1,31 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace OpenSim.Framework.Communications.Capabilities +{ + public delegate TResponse LLSDMethodString(TRequest request, string path); +} diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index fd02382..a35ed72 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs @@ -339,6 +339,11 @@ namespace OpenSim.Framework.Communications public void ClearUserAgent(LLUUID agentID) { UserProfileData profile = GetUserProfile(agentID); + + if (profile == null) + { + return; + } profile.CurrentAgent = null; UpdateUserProfile(profile); diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index b2d13c7..f437902 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -349,6 +349,11 @@ namespace OpenSim.Framework set; } + bool SendLogoutPacketWhenClosing + { + set; + } + // [Obsolete("LLClientView Specific - Circuits are unique to LLClientView")] uint CircuitCode { get; } // [Obsolete("LLClientView Specific - Replace with more bare-bones arguments.")] @@ -741,5 +746,6 @@ namespace OpenSim.Framework void SendRegionHandle(LLUUID regoinID, ulong handle); void SendParcelInfo(RegionInfo info, LandData land, LLUUID parcelID, uint x, uint y); + void KillEndDone(); } } diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index 23c28e6..7b2b599 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs @@ -47,8 +47,9 @@ namespace OpenSim.Framework.Servers protected Thread m_workerThread; protected HttpListener m_httpListener; - protected Dictionary m_rpcHandlers = new Dictionary(); - protected LLSDMethod m_llsdHandler = null; + protected Dictionary m_rpcHandlers = new Dictionary(); + protected DefaultLLSDMethod m_defaultLlsdHandler = null; // <-- Moving away from the monolithic.. and going to /registered/ + protected Dictionary m_llsdHandlers = new Dictionary(); protected Dictionary m_streamHandlers = new Dictionary(); protected Dictionary m_HTTPHandlers = new Dictionary(); protected Dictionary m_agentHandlers = new Dictionary(); @@ -148,9 +149,28 @@ namespace OpenSim.Framework.Servers return false; } - public bool SetLLSDHandler(LLSDMethod handler) + /// + /// Adds a LLSD handler, yay. + /// + /// /resource/ path + /// handle the LLSD response + /// + public bool AddLLSDHandler(string path, LLSDMethod handler) { - m_llsdHandler = handler; + lock (m_llsdHandlers) + { + if (!m_llsdHandlers.ContainsKey(path)) + { + m_llsdHandlers.Add(path, handler); + return true; + } + } + return false; + } + + public bool SetDefaultLLSDHandler(DefaultLLSDMethod handler) + { + m_defaultLlsdHandler = handler; return true; } @@ -239,20 +259,21 @@ namespace OpenSim.Framework.Servers switch (request.ContentType) { - case null: - case "text/html": - HandleHTTPRequest(request, response); - return; + case null: + case "text/html": + HandleHTTPRequest(request, response); + return; - case "application/xml+llsd": - HandleLLSDRequests(request, response); - return; + case "application/llsd+xml": + case "application/xml+llsd": + HandleLLSDRequests(request, response); + return; - case "text/xml": - case "application/xml": - default: - HandleXmlRpcRequests(request, response); - return; + case "text/xml": + case "application/xml": + default: + HandleXmlRpcRequests(request, response); + return; } } catch (SocketException e) @@ -456,17 +477,37 @@ namespace OpenSim.Framework.Servers m_log.Warn("[HTTPD]: Error - " + ex.Message); } - if (llsdRequest != null && m_llsdHandler != null) + if (llsdRequest != null)// && m_defaultLlsdHandler != null) { - llsdResponse = m_llsdHandler(llsdRequest); + + LLSDMethod llsdhandler = null; + + if (TryGetLLSDHandler(request.RawUrl, out llsdhandler)) + { + // we found a registered llsd handler to service this request + llsdResponse = llsdhandler(request.RawUrl, llsdRequest, request.RemoteIPEndPoint.ToString()); + } + else + { + // we didn't find a registered llsd handler to service this request + // check if we have a default llsd handler + + if (m_defaultLlsdHandler != null) + { + // LibOMV path + llsdResponse = m_defaultLlsdHandler(llsdRequest); + } + else + { + // Oops, no handler for this.. give em the failed message + llsdResponse = GenerateNoLLSDHandlerResponse(); + } + } + } else { - LLSDMap map = new LLSDMap(); - map["reason"] = LLSD.FromString("LLSDRequest"); - map["message"] = LLSD.FromString("No handler registered for LLSD Requests"); - map["login"] = LLSD.FromString("false"); - llsdResponse = map; + llsdResponse = GenerateNoLLSDHandlerResponse(); } response.ContentType = "application/xml+llsd"; @@ -491,6 +532,68 @@ namespace OpenSim.Framework.Servers } } + private bool TryGetLLSDHandler(string path, out LLSDMethod llsdHandler) + { + llsdHandler = null; + // Pull out the first part of the path + // splitting the path by '/' means we'll get the following return.. + // {0}/{1}/{2} + // where {0} isn't something we really control 100% + + string[] pathbase = path.Split('/'); + string searchquery = "/"; + + if (pathbase.Length < 1) + return false; + + for (int i=1; i bestMatch.Length) + { + bestMatch = pattern; + } + } + } + + if (String.IsNullOrEmpty(bestMatch)) + { + llsdHandler = null; + return false; + } + else + { + llsdHandler = m_llsdHandlers[bestMatch]; + return true; + } + } + + private LLSDMap GenerateNoLLSDHandlerResponse() + { + LLSDMap map = new LLSDMap(); + map["reason"] = LLSD.FromString("LLSDRequest"); + map["message"] = LLSD.FromString("No handler registered for LLSD Requests"); + map["login"] = LLSD.FromString("false"); + return map; + } /// /// A specific agent handler was provided. Such a handler is expecetd to have an /// intimate, and highly specific relationship with the client. Consequently, @@ -809,6 +912,25 @@ namespace OpenSim.Framework.Servers return false; } + public bool RemoveLLSDHandler(string path, LLSDMethod handler) + { + + try + { + if (handler == m_llsdHandlers[path]) + { + m_llsdHandlers.Remove(path); + return true; + } + } + catch (KeyNotFoundException) + { + // This is an exception to prevent crashing because of invalid code + } + + return false; + } + public string GetHTTP404(string host) { diff --git a/OpenSim/Framework/Servers/LLSDMethod.cs b/OpenSim/Framework/Servers/LLSDMethod.cs index 05c23b0..7bb946e 100644 --- a/OpenSim/Framework/Servers/LLSDMethod.cs +++ b/OpenSim/Framework/Servers/LLSDMethod.cs @@ -29,5 +29,6 @@ using libsecondlife.StructuredData; namespace OpenSim.Framework.Servers { - public delegate LLSD LLSDMethod(LLSD request); + public delegate LLSD LLSDMethod( string path, LLSD request, string endpoint ); + public delegate LLSD DefaultLLSDMethod(LLSD request); } diff --git a/OpenSim/Framework/Servers/LLSDMethodString.cs b/OpenSim/Framework/Servers/LLSDMethodString.cs new file mode 100644 index 0000000..8d20b69 --- /dev/null +++ b/OpenSim/Framework/Servers/LLSDMethodString.cs @@ -0,0 +1,33 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using libsecondlife.StructuredData; + +namespace OpenSim.Framework.Servers +{ + public delegate LLSD LLSDMethodString(LLSD request, string thePath); +} -- cgit v1.1