From 4ab479bf58652573606fa08136e182260b180a0b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 10 Apr 2012 20:40:59 +0100 Subject: Add uri to various log messages when region registration fails. Upgrade some debug log messages to error. --- .../Connectors/Grid/GridServiceConnector.cs | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 1599a56..34ed0d7 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs @@ -113,29 +113,36 @@ namespace OpenSim.Services.Connectors } else if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "failure")) { - m_log.DebugFormat("[GRID CONNECTOR]: Registration failed: {0}", replyData["Message"].ToString()); + m_log.ErrorFormat( + "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData["Message"], uri); + return replyData["Message"].ToString(); } else if (!replyData.ContainsKey("Result")) { - m_log.DebugFormat("[GRID CONNECTOR]: reply data does not contain result field"); + m_log.ErrorFormat( + "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri); } else { - m_log.DebugFormat("[GRID CONNECTOR]: unexpected result {0}", replyData["Result"].ToString()); - return "Unexpected result "+replyData["Result"].ToString(); + m_log.ErrorFormat( + "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData["Result"], uri); + + return "Unexpected result " + replyData["Result"].ToString(); } - } else - m_log.DebugFormat("[GRID CONNECTOR]: RegisterRegion received null reply"); + { + m_log.ErrorFormat( + "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri); + } } catch (Exception e) { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + m_log.ErrorFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); } - return "Error communicating with grid service"; + return string.Format("Error communicating with the grid service at {0}", uri); } public bool DeregisterRegion(UUID regionID) -- cgit v1.1 From 4ac2f839bdba84569877f5ab8c2e9ea0cfe87413 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 20 Apr 2012 03:32:38 +0100 Subject: Remember to dispose of the bitmap opened from a file in GatekeeperServiceConnector.GetMapImage() --- .../Connectors/Hypergrid/GatekeeperServiceConnector.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs index 0430ef6..19dffc3 100644 --- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs @@ -154,7 +154,7 @@ namespace OpenSim.Services.Connectors.Hypergrid UUID mapTile = m_HGMapImage; string filename = string.Empty; - Bitmap bitmap = null; + try { WebClient c = new WebClient(); @@ -167,11 +167,18 @@ namespace OpenSim.Services.Connectors.Hypergrid c.DownloadFile(imageURL, filename); } else + { m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: using cached image"); + } + + byte[] imageData = null; - bitmap = new Bitmap(filename); - //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); - byte[] imageData = OpenJPEG.EncodeFromImage(bitmap, true); + using (Bitmap bitmap = new Bitmap(filename)) + { + //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); + imageData = OpenJPEG.EncodeFromImage(bitmap, true); + } + AssetBase ass = new AssetBase(UUID.Random(), "region " + name, (sbyte)AssetType.Texture, regionID.ToString()); // !!! for now -- cgit v1.1 From d8a78374aa11c5460d6e58a6f4110fca61dfded4 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 9 May 2012 23:25:01 +0100 Subject: Where necessary, rename OpenSim/Services/Connectors/*.cs files to reflect the actual class names. This is usually because the file name was singular (*Service*) but the class name was plural (*Services*). This is to make configuration easier rather than having to look in the c# code itself to find the slightly different name of the connector. This does not affect existing configuration since the files are being renamed rather than the classes. --- .../Connectors/Asset/AssetServiceConnector.cs | 329 ---------- .../Connectors/Asset/AssetServicesConnector.cs | 329 ++++++++++ .../AuthenticationServiceConnector.cs | 167 ----- .../AuthenticationServicesConnector.cs | 167 +++++ .../Authorization/AuthorizationServiceConnector.cs | 123 ---- .../AuthorizationServicesConnector.cs | 123 ++++ .../Connectors/Avatar/AvatarServiceConnector.cs | 326 ---------- .../Connectors/Avatar/AvatarServicesConnector.cs | 326 ++++++++++ .../Connectors/Friends/FriendsServiceConnector.cs | 267 -------- .../Connectors/Friends/FriendsServicesConnector.cs | 267 ++++++++ .../Connectors/Grid/GridServiceConnector.cs | 671 --------------------- .../Connectors/Grid/GridServicesConnector.cs | 671 +++++++++++++++++++++ .../GridUser/GridUserServiceConnector.cs | 290 --------- .../GridUser/GridUserServicesConnector.cs | 290 +++++++++ .../Hypergrid/HGFriendsServiceConnector.cs | 312 ---------- .../Hypergrid/HGFriendsServicesConnector.cs | 312 ++++++++++ .../Connectors/Hypergrid/HeloServiceConnector.cs | 100 --- .../Connectors/Hypergrid/HeloServicesConnector.cs | 100 +++ .../Connectors/Inventory/XInventoryConnector.cs | 623 ------------------- .../Inventory/XInventoryServicesConnector.cs | 623 +++++++++++++++++++ .../Connectors/Land/LandServiceConnector.cs | 133 ---- .../Connectors/Land/LandServicesConnector.cs | 133 ++++ .../MapImage/MapImageServiceConnector.cs | 159 ----- .../MapImage/MapImageServicesConnector.cs | 159 +++++ .../Neighbour/NeighbourServiceConnector.cs | 206 ------- .../Neighbour/NeighbourServicesConnector.cs | 206 +++++++ .../Presence/PresenceServiceConnector.cs | 378 ------------ .../Presence/PresenceServicesConnector.cs | 378 ++++++++++++ .../UserAccounts/UserAccountServiceConnector.cs | 287 --------- .../UserAccounts/UserAccountServicesConnector.cs | 287 +++++++++ 30 files changed, 4371 insertions(+), 4371 deletions(-) delete mode 100644 OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Authorization/AuthorizationServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Friends/FriendsServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Grid/GridServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Grid/GridServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Hypergrid/HeloServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs create mode 100644 OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Land/LandServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Land/LandServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs delete mode 100644 OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs create mode 100644 OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs deleted file mode 100644 index e4c3eaf..0000000 --- a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs +++ /dev/null @@ -1,329 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Console; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class AssetServicesConnector : IAssetService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - private IImprovedAssetCache m_Cache = null; - - private delegate void AssetRetrievedEx(AssetBase asset); - - // Keeps track of concurrent requests for the same asset, so that it's only loaded once. - // Maps: Asset ID -> Handlers which will be called when the asset has been loaded - private Dictionary m_AssetHandlers = new Dictionary(); - - - public AssetServicesConnector() - { - } - - public AssetServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public AssetServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig assetConfig = source.Configs["AssetService"]; - if (assetConfig == null) - { - m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpenSim.ini"); - throw new Exception("Asset connector init error"); - } - - string serviceURI = assetConfig.GetString("AssetServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[ASSET CONNECTOR]: No Server URI named in section AssetService"); - throw new Exception("Asset connector init error"); - } - - m_ServerURI = serviceURI; - } - - protected void SetCache(IImprovedAssetCache cache) - { - m_Cache = cache; - } - - public AssetBase Get(string id) - { -// m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Synchronous get request for {0}", id); - - string uri = m_ServerURI + "/assets/" + id; - - AssetBase asset = null; - if (m_Cache != null) - asset = m_Cache.Get(id); - - if (asset == null) - { - asset = SynchronousRestObjectRequester. - MakeRequest("GET", uri, 0); - - if (m_Cache != null) - m_Cache.Cache(asset); - } - return asset; - } - - public AssetBase GetCached(string id) - { -// m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Cache request for {0}", id); - - if (m_Cache != null) - return m_Cache.Get(id); - - return null; - } - - public AssetMetadata GetMetadata(string id) - { - if (m_Cache != null) - { - AssetBase fullAsset = m_Cache.Get(id); - - if (fullAsset != null) - return fullAsset.Metadata; - } - - string uri = m_ServerURI + "/assets/" + id + "/metadata"; - - AssetMetadata asset = SynchronousRestObjectRequester. - MakeRequest("GET", uri, 0); - return asset; - } - - public byte[] GetData(string id) - { - if (m_Cache != null) - { - AssetBase fullAsset = m_Cache.Get(id); - - if (fullAsset != null) - return fullAsset.Data; - } - - RestClient rc = new RestClient(m_ServerURI); - rc.AddResourcePath("assets"); - rc.AddResourcePath(id); - rc.AddResourcePath("data"); - - rc.RequestMethod = "GET"; - - Stream s = rc.Request(); - - if (s == null) - return null; - - if (s.Length > 0) - { - byte[] ret = new byte[s.Length]; - s.Read(ret, 0, (int)s.Length); - - return ret; - } - - return null; - } - - public bool Get(string id, Object sender, AssetRetrieved handler) - { -// m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Potentially asynchronous get request for {0}", id); - - string uri = m_ServerURI + "/assets/" + id; - - AssetBase asset = null; - if (m_Cache != null) - asset = m_Cache.Get(id); - - if (asset == null) - { - lock (m_AssetHandlers) - { - AssetRetrievedEx handlerEx = new AssetRetrievedEx(delegate(AssetBase _asset) { handler(id, sender, _asset); }); - - AssetRetrievedEx handlers; - if (m_AssetHandlers.TryGetValue(id, out handlers)) - { - // Someone else is already loading this asset. It will notify our handler when done. - handlers += handlerEx; - return true; - } - - // Load the asset ourselves - handlers += handlerEx; - m_AssetHandlers.Add(id, handlers); - } - - bool success = false; - try - { - AsynchronousRestObjectRequester.MakeRequest("GET", uri, 0, - delegate(AssetBase a) - { - if (m_Cache != null) - m_Cache.Cache(a); - - AssetRetrievedEx handlers; - lock (m_AssetHandlers) - { - handlers = m_AssetHandlers[id]; - m_AssetHandlers.Remove(id); - } - handlers.Invoke(a); - }); - - success = true; - } - finally - { - if (!success) - { - lock (m_AssetHandlers) - { - m_AssetHandlers.Remove(id); - } - } - } - } - else - { - handler(id, sender, asset); - } - - return true; - } - - public string Store(AssetBase asset) - { - if (asset.Temporary || asset.Local) - { - if (m_Cache != null) - m_Cache.Cache(asset); - - return asset.ID; - } - - string uri = m_ServerURI + "/assets/"; - - string newID = string.Empty; - try - { - newID = SynchronousRestObjectRequester. - MakeRequest("POST", uri, asset); - } - catch (Exception e) - { - m_log.WarnFormat("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1}", asset.ID, e.Message); - } - - if (newID != String.Empty) - { - // Placing this here, so that this work with old asset servers that don't send any reply back - // SynchronousRestObjectRequester returns somethins that is not an empty string - if (newID != null) - asset.ID = newID; - - if (m_Cache != null) - m_Cache.Cache(asset); - } - return newID; - } - - public bool UpdateContent(string id, byte[] data) - { - AssetBase asset = null; - - if (m_Cache != null) - asset = m_Cache.Get(id); - - if (asset == null) - { - AssetMetadata metadata = GetMetadata(id); - if (metadata == null) - return false; - - asset = new AssetBase(metadata.FullID, metadata.Name, metadata.Type, UUID.Zero.ToString()); - asset.Metadata = metadata; - } - asset.Data = data; - - string uri = m_ServerURI + "/assets/" + id; - - if (SynchronousRestObjectRequester. - MakeRequest("POST", uri, asset)) - { - if (m_Cache != null) - m_Cache.Cache(asset); - - return true; - } - return false; - } - - public bool Delete(string id) - { - string uri = m_ServerURI + "/assets/" + id; - - if (SynchronousRestObjectRequester. - MakeRequest("DELETE", uri, 0)) - { - if (m_Cache != null) - m_Cache.Expire(id); - - return true; - } - return false; - } - } -} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs new file mode 100644 index 0000000..e4c3eaf --- /dev/null +++ b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs @@ -0,0 +1,329 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Console; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class AssetServicesConnector : IAssetService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + private IImprovedAssetCache m_Cache = null; + + private delegate void AssetRetrievedEx(AssetBase asset); + + // Keeps track of concurrent requests for the same asset, so that it's only loaded once. + // Maps: Asset ID -> Handlers which will be called when the asset has been loaded + private Dictionary m_AssetHandlers = new Dictionary(); + + + public AssetServicesConnector() + { + } + + public AssetServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public AssetServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig assetConfig = source.Configs["AssetService"]; + if (assetConfig == null) + { + m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpenSim.ini"); + throw new Exception("Asset connector init error"); + } + + string serviceURI = assetConfig.GetString("AssetServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[ASSET CONNECTOR]: No Server URI named in section AssetService"); + throw new Exception("Asset connector init error"); + } + + m_ServerURI = serviceURI; + } + + protected void SetCache(IImprovedAssetCache cache) + { + m_Cache = cache; + } + + public AssetBase Get(string id) + { +// m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Synchronous get request for {0}", id); + + string uri = m_ServerURI + "/assets/" + id; + + AssetBase asset = null; + if (m_Cache != null) + asset = m_Cache.Get(id); + + if (asset == null) + { + asset = SynchronousRestObjectRequester. + MakeRequest("GET", uri, 0); + + if (m_Cache != null) + m_Cache.Cache(asset); + } + return asset; + } + + public AssetBase GetCached(string id) + { +// m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Cache request for {0}", id); + + if (m_Cache != null) + return m_Cache.Get(id); + + return null; + } + + public AssetMetadata GetMetadata(string id) + { + if (m_Cache != null) + { + AssetBase fullAsset = m_Cache.Get(id); + + if (fullAsset != null) + return fullAsset.Metadata; + } + + string uri = m_ServerURI + "/assets/" + id + "/metadata"; + + AssetMetadata asset = SynchronousRestObjectRequester. + MakeRequest("GET", uri, 0); + return asset; + } + + public byte[] GetData(string id) + { + if (m_Cache != null) + { + AssetBase fullAsset = m_Cache.Get(id); + + if (fullAsset != null) + return fullAsset.Data; + } + + RestClient rc = new RestClient(m_ServerURI); + rc.AddResourcePath("assets"); + rc.AddResourcePath(id); + rc.AddResourcePath("data"); + + rc.RequestMethod = "GET"; + + Stream s = rc.Request(); + + if (s == null) + return null; + + if (s.Length > 0) + { + byte[] ret = new byte[s.Length]; + s.Read(ret, 0, (int)s.Length); + + return ret; + } + + return null; + } + + public bool Get(string id, Object sender, AssetRetrieved handler) + { +// m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Potentially asynchronous get request for {0}", id); + + string uri = m_ServerURI + "/assets/" + id; + + AssetBase asset = null; + if (m_Cache != null) + asset = m_Cache.Get(id); + + if (asset == null) + { + lock (m_AssetHandlers) + { + AssetRetrievedEx handlerEx = new AssetRetrievedEx(delegate(AssetBase _asset) { handler(id, sender, _asset); }); + + AssetRetrievedEx handlers; + if (m_AssetHandlers.TryGetValue(id, out handlers)) + { + // Someone else is already loading this asset. It will notify our handler when done. + handlers += handlerEx; + return true; + } + + // Load the asset ourselves + handlers += handlerEx; + m_AssetHandlers.Add(id, handlers); + } + + bool success = false; + try + { + AsynchronousRestObjectRequester.MakeRequest("GET", uri, 0, + delegate(AssetBase a) + { + if (m_Cache != null) + m_Cache.Cache(a); + + AssetRetrievedEx handlers; + lock (m_AssetHandlers) + { + handlers = m_AssetHandlers[id]; + m_AssetHandlers.Remove(id); + } + handlers.Invoke(a); + }); + + success = true; + } + finally + { + if (!success) + { + lock (m_AssetHandlers) + { + m_AssetHandlers.Remove(id); + } + } + } + } + else + { + handler(id, sender, asset); + } + + return true; + } + + public string Store(AssetBase asset) + { + if (asset.Temporary || asset.Local) + { + if (m_Cache != null) + m_Cache.Cache(asset); + + return asset.ID; + } + + string uri = m_ServerURI + "/assets/"; + + string newID = string.Empty; + try + { + newID = SynchronousRestObjectRequester. + MakeRequest("POST", uri, asset); + } + catch (Exception e) + { + m_log.WarnFormat("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1}", asset.ID, e.Message); + } + + if (newID != String.Empty) + { + // Placing this here, so that this work with old asset servers that don't send any reply back + // SynchronousRestObjectRequester returns somethins that is not an empty string + if (newID != null) + asset.ID = newID; + + if (m_Cache != null) + m_Cache.Cache(asset); + } + return newID; + } + + public bool UpdateContent(string id, byte[] data) + { + AssetBase asset = null; + + if (m_Cache != null) + asset = m_Cache.Get(id); + + if (asset == null) + { + AssetMetadata metadata = GetMetadata(id); + if (metadata == null) + return false; + + asset = new AssetBase(metadata.FullID, metadata.Name, metadata.Type, UUID.Zero.ToString()); + asset.Metadata = metadata; + } + asset.Data = data; + + string uri = m_ServerURI + "/assets/" + id; + + if (SynchronousRestObjectRequester. + MakeRequest("POST", uri, asset)) + { + if (m_Cache != null) + m_Cache.Cache(asset); + + return true; + } + return false; + } + + public bool Delete(string id) + { + string uri = m_ServerURI + "/assets/" + id; + + if (SynchronousRestObjectRequester. + MakeRequest("DELETE", uri, 0)) + { + if (m_Cache != null) + m_Cache.Expire(id); + + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs deleted file mode 100644 index 2b77154..0000000 --- a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using OpenSim.Server.Base; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class AuthenticationServicesConnector : IAuthenticationService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public AuthenticationServicesConnector() - { - } - - public AuthenticationServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public AuthenticationServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig assetConfig = source.Configs["AuthenticationService"]; - if (assetConfig == null) - { - m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini"); - throw new Exception("Authentication connector init error"); - } - - string serviceURI = assetConfig.GetString("AuthenticationServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[AUTH CONNECTOR]: No Server URI named in section AuthenticationService"); - throw new Exception("Authentication connector init error"); - } - m_ServerURI = serviceURI; - } - - public string Authenticate(UUID principalID, string password, int lifetime) - { - Dictionary sendData = new Dictionary(); - sendData["LIFETIME"] = lifetime.ToString(); - sendData["PRINCIPAL"] = principalID.ToString(); - sendData["PASSWORD"] = password; - - sendData["METHOD"] = "authenticate"; - - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - m_ServerURI + "/auth/plain", - ServerUtils.BuildQueryString(sendData)); - - Dictionary replyData = ServerUtils.ParseXmlResponse( - reply); - - if (replyData["Result"].ToString() != "Success") - return String.Empty; - - return replyData["Token"].ToString(); - } - - public bool Verify(UUID principalID, string token, int lifetime) - { - Dictionary sendData = new Dictionary(); - sendData["LIFETIME"] = lifetime.ToString(); - sendData["PRINCIPAL"] = principalID.ToString(); - sendData["TOKEN"] = token; - - sendData["METHOD"] = "verify"; - - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - m_ServerURI + "/auth/plain", - ServerUtils.BuildQueryString(sendData)); - - Dictionary replyData = ServerUtils.ParseXmlResponse( - reply); - - if (replyData["Result"].ToString() != "Success") - return false; - - return true; - } - - public bool Release(UUID principalID, string token) - { - Dictionary sendData = new Dictionary(); - sendData["PRINCIPAL"] = principalID.ToString(); - sendData["TOKEN"] = token; - - sendData["METHOD"] = "release"; - - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - m_ServerURI + "/auth/plain", - ServerUtils.BuildQueryString(sendData)); - - Dictionary replyData = ServerUtils.ParseXmlResponse( - reply); - - if (replyData["Result"].ToString() != "Success") - return false; - - return true; - } - - public bool SetPassword(UUID principalID, string passwd) - { - // nope, we don't do this - return false; - } - - public AuthInfo GetAuthInfo(UUID principalID) - { - // not done from remote simulators - return null; - } - - public bool SetAuthInfo(AuthInfo info) - { - // not done from remote simulators - return false; - } - } -} diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs new file mode 100644 index 0000000..2b77154 --- /dev/null +++ b/OpenSim/Services/Connectors/Authentication/AuthenticationServicesConnector.cs @@ -0,0 +1,167 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using OpenSim.Server.Base; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class AuthenticationServicesConnector : IAuthenticationService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public AuthenticationServicesConnector() + { + } + + public AuthenticationServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public AuthenticationServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig assetConfig = source.Configs["AuthenticationService"]; + if (assetConfig == null) + { + m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini"); + throw new Exception("Authentication connector init error"); + } + + string serviceURI = assetConfig.GetString("AuthenticationServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[AUTH CONNECTOR]: No Server URI named in section AuthenticationService"); + throw new Exception("Authentication connector init error"); + } + m_ServerURI = serviceURI; + } + + public string Authenticate(UUID principalID, string password, int lifetime) + { + Dictionary sendData = new Dictionary(); + sendData["LIFETIME"] = lifetime.ToString(); + sendData["PRINCIPAL"] = principalID.ToString(); + sendData["PASSWORD"] = password; + + sendData["METHOD"] = "authenticate"; + + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/auth/plain", + ServerUtils.BuildQueryString(sendData)); + + Dictionary replyData = ServerUtils.ParseXmlResponse( + reply); + + if (replyData["Result"].ToString() != "Success") + return String.Empty; + + return replyData["Token"].ToString(); + } + + public bool Verify(UUID principalID, string token, int lifetime) + { + Dictionary sendData = new Dictionary(); + sendData["LIFETIME"] = lifetime.ToString(); + sendData["PRINCIPAL"] = principalID.ToString(); + sendData["TOKEN"] = token; + + sendData["METHOD"] = "verify"; + + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/auth/plain", + ServerUtils.BuildQueryString(sendData)); + + Dictionary replyData = ServerUtils.ParseXmlResponse( + reply); + + if (replyData["Result"].ToString() != "Success") + return false; + + return true; + } + + public bool Release(UUID principalID, string token) + { + Dictionary sendData = new Dictionary(); + sendData["PRINCIPAL"] = principalID.ToString(); + sendData["TOKEN"] = token; + + sendData["METHOD"] = "release"; + + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/auth/plain", + ServerUtils.BuildQueryString(sendData)); + + Dictionary replyData = ServerUtils.ParseXmlResponse( + reply); + + if (replyData["Result"].ToString() != "Success") + return false; + + return true; + } + + public bool SetPassword(UUID principalID, string passwd) + { + // nope, we don't do this + return false; + } + + public AuthInfo GetAuthInfo(UUID principalID) + { + // not done from remote simulators + return null; + } + + public bool SetAuthInfo(AuthInfo info) + { + // not done from remote simulators + return false; + } + } +} diff --git a/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs b/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs deleted file mode 100644 index 35b7109..0000000 --- a/OpenSim/Services/Connectors/Authorization/AuthorizationServiceConnector.cs +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class AuthorizationServicesConnector - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - private bool m_ResponseOnFailure = true; - - public AuthorizationServicesConnector() - { - } - - public AuthorizationServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public AuthorizationServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig authorizationConfig = source.Configs["AuthorizationService"]; - if (authorizationConfig == null) - { - //m_log.Info("[AUTHORIZATION CONNECTOR]: AuthorizationService missing from OpenSim.ini"); - throw new Exception("Authorization connector init error"); - } - - string serviceURI = authorizationConfig.GetString("AuthorizationServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[AUTHORIZATION CONNECTOR]: No Server URI named in section AuthorizationService"); - throw new Exception("Authorization connector init error"); - } - m_ServerURI = serviceURI; - - // this dictates what happens if the remote service fails, if the service fails and the value is true - // the user is authorized for the region. - bool responseOnFailure = authorizationConfig.GetBoolean("ResponseOnFailure",true); - - m_ResponseOnFailure = responseOnFailure; - m_log.Info("[AUTHORIZATION CONNECTOR]: AuthorizationService initialized"); - } - - public bool IsAuthorizedForRegion(string userID, string firstname, string surname, string email, string regionName, string regionID, out string message) - { - // do a remote call to the authorization server specified in the AuthorizationServerURI - m_log.InfoFormat("[AUTHORIZATION CONNECTOR]: IsAuthorizedForRegion checking {0} at remote server {1}", userID, m_ServerURI); - - string uri = m_ServerURI; - - AuthorizationRequest req = new AuthorizationRequest(userID, firstname, surname, email, regionName, regionID); - - AuthorizationResponse response; - try - { - response = SynchronousRestObjectRequester.MakeRequest("POST", uri, req); - } - catch (Exception e) - { - m_log.WarnFormat("[AUTHORIZATION CONNECTOR]: Unable to send authorize {0} for region {1} error thrown during comms with remote server. Reason: {2}", userID, regionID, e.Message); - message = ""; - return m_ResponseOnFailure; - } - if (response == null) - { - message = "Null response"; - return m_ResponseOnFailure; - } - m_log.DebugFormat("[AUTHORIZATION CONNECTOR] response from remote service was {0}", response.Message); - message = response.Message; - - return response.IsAuthorized; - } - - } -} diff --git a/OpenSim/Services/Connectors/Authorization/AuthorizationServicesConnector.cs b/OpenSim/Services/Connectors/Authorization/AuthorizationServicesConnector.cs new file mode 100644 index 0000000..35b7109 --- /dev/null +++ b/OpenSim/Services/Connectors/Authorization/AuthorizationServicesConnector.cs @@ -0,0 +1,123 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class AuthorizationServicesConnector + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + private bool m_ResponseOnFailure = true; + + public AuthorizationServicesConnector() + { + } + + public AuthorizationServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public AuthorizationServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig authorizationConfig = source.Configs["AuthorizationService"]; + if (authorizationConfig == null) + { + //m_log.Info("[AUTHORIZATION CONNECTOR]: AuthorizationService missing from OpenSim.ini"); + throw new Exception("Authorization connector init error"); + } + + string serviceURI = authorizationConfig.GetString("AuthorizationServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[AUTHORIZATION CONNECTOR]: No Server URI named in section AuthorizationService"); + throw new Exception("Authorization connector init error"); + } + m_ServerURI = serviceURI; + + // this dictates what happens if the remote service fails, if the service fails and the value is true + // the user is authorized for the region. + bool responseOnFailure = authorizationConfig.GetBoolean("ResponseOnFailure",true); + + m_ResponseOnFailure = responseOnFailure; + m_log.Info("[AUTHORIZATION CONNECTOR]: AuthorizationService initialized"); + } + + public bool IsAuthorizedForRegion(string userID, string firstname, string surname, string email, string regionName, string regionID, out string message) + { + // do a remote call to the authorization server specified in the AuthorizationServerURI + m_log.InfoFormat("[AUTHORIZATION CONNECTOR]: IsAuthorizedForRegion checking {0} at remote server {1}", userID, m_ServerURI); + + string uri = m_ServerURI; + + AuthorizationRequest req = new AuthorizationRequest(userID, firstname, surname, email, regionName, regionID); + + AuthorizationResponse response; + try + { + response = SynchronousRestObjectRequester.MakeRequest("POST", uri, req); + } + catch (Exception e) + { + m_log.WarnFormat("[AUTHORIZATION CONNECTOR]: Unable to send authorize {0} for region {1} error thrown during comms with remote server. Reason: {2}", userID, regionID, e.Message); + message = ""; + return m_ResponseOnFailure; + } + if (response == null) + { + message = "Null response"; + return m_ResponseOnFailure; + } + m_log.DebugFormat("[AUTHORIZATION CONNECTOR] response from remote service was {0}", response.Message); + message = response.Message; + + return response.IsAuthorized; + } + + } +} diff --git a/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs b/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs deleted file mode 100644 index ddfca57..0000000 --- a/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs +++ /dev/null @@ -1,326 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; -using IAvatarService = OpenSim.Services.Interfaces.IAvatarService; -using OpenSim.Server.Base; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class AvatarServicesConnector : IAvatarService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public AvatarServicesConnector() - { - } - - public AvatarServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public AvatarServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig gridConfig = source.Configs["AvatarService"]; - if (gridConfig == null) - { - m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini"); - throw new Exception("Avatar connector init error"); - } - - string serviceURI = gridConfig.GetString("AvatarServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[AVATAR CONNECTOR]: No Server URI named in section AvatarService"); - throw new Exception("Avatar connector init error"); - } - m_ServerURI = serviceURI; - } - - - #region IAvatarService - - public AvatarAppearance GetAppearance(UUID userID) - { - AvatarData avatar = GetAvatar(userID); - return avatar.ToAvatarAppearance(); - } - - public bool SetAppearance(UUID userID, AvatarAppearance appearance) - { - AvatarData avatar = new AvatarData(appearance); - return SetAvatar(userID,avatar); - } - - public AvatarData GetAvatar(UUID userID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getavatar"; - - sendData["UserID"] = userID; - - string reply = string.Empty; - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/avatar"; - // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); - if (reply == null || (reply != null && reply == string.Empty)) - { - m_log.DebugFormat("[AVATAR CONNECTOR]: GetAgent received null or empty reply"); - return null; - } - } - catch (Exception e) - { - m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - AvatarData avatar = null; - - if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - { - avatar = new AvatarData((Dictionary)replyData["result"]); - } - } - - return avatar; - - } - - public bool SetAvatar(UUID userID, AvatarData avatar) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "setavatar"; - - sendData["UserID"] = userID.ToString(); - - Dictionary structData = avatar.ToKeyValuePairs(); - - foreach (KeyValuePair kvp in structData) - sendData[kvp.Key] = kvp.Value.ToString(); - - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/avatar"; - //m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - { - m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar reply data does not contain result field"); - } - } - else - { - m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar received empty reply"); - } - } - catch (Exception e) - { - m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - return false; - } - - public bool ResetAvatar(UUID userID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "resetavatar"; - - sendData["UserID"] = userID.ToString(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/avatar"; - // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field"); - - } - else - m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - return false; - } - - public bool SetItems(UUID userID, string[] names, string[] values) - { - Dictionary sendData = new Dictionary(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "setitems"; - - sendData["UserID"] = userID.ToString(); - sendData["Names"] = new List(names); - sendData["Values"] = new List(values); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/avatar"; - // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field"); - - } - else - m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - return false; - } - - public bool RemoveItems(UUID userID, string[] names) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "removeitems"; - - sendData["UserID"] = userID.ToString(); - sendData["Names"] = new List(names); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/avatar"; - // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems reply data does not contain result field"); - - } - else - m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - return false; - } - - #endregion - - } -} diff --git a/OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs b/OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs new file mode 100644 index 0000000..ddfca57 --- /dev/null +++ b/OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs @@ -0,0 +1,326 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using IAvatarService = OpenSim.Services.Interfaces.IAvatarService; +using OpenSim.Server.Base; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class AvatarServicesConnector : IAvatarService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public AvatarServicesConnector() + { + } + + public AvatarServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public AvatarServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig gridConfig = source.Configs["AvatarService"]; + if (gridConfig == null) + { + m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini"); + throw new Exception("Avatar connector init error"); + } + + string serviceURI = gridConfig.GetString("AvatarServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[AVATAR CONNECTOR]: No Server URI named in section AvatarService"); + throw new Exception("Avatar connector init error"); + } + m_ServerURI = serviceURI; + } + + + #region IAvatarService + + public AvatarAppearance GetAppearance(UUID userID) + { + AvatarData avatar = GetAvatar(userID); + return avatar.ToAvatarAppearance(); + } + + public bool SetAppearance(UUID userID, AvatarAppearance appearance) + { + AvatarData avatar = new AvatarData(appearance); + return SetAvatar(userID,avatar); + } + + public AvatarData GetAvatar(UUID userID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getavatar"; + + sendData["UserID"] = userID; + + string reply = string.Empty; + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/avatar"; + // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); + if (reply == null || (reply != null && reply == string.Empty)) + { + m_log.DebugFormat("[AVATAR CONNECTOR]: GetAgent received null or empty reply"); + return null; + } + } + catch (Exception e) + { + m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + AvatarData avatar = null; + + if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) + { + if (replyData["result"] is Dictionary) + { + avatar = new AvatarData((Dictionary)replyData["result"]); + } + } + + return avatar; + + } + + public bool SetAvatar(UUID userID, AvatarData avatar) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "setavatar"; + + sendData["UserID"] = userID.ToString(); + + Dictionary structData = avatar.ToKeyValuePairs(); + + foreach (KeyValuePair kvp in structData) + sendData[kvp.Key] = kvp.Value.ToString(); + + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/avatar"; + //m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + { + m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar reply data does not contain result field"); + } + } + else + { + m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar received empty reply"); + } + } + catch (Exception e) + { + m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + return false; + } + + public bool ResetAvatar(UUID userID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "resetavatar"; + + sendData["UserID"] = userID.ToString(); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/avatar"; + // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field"); + + } + else + m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + return false; + } + + public bool SetItems(UUID userID, string[] names, string[] values) + { + Dictionary sendData = new Dictionary(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "setitems"; + + sendData["UserID"] = userID.ToString(); + sendData["Names"] = new List(names); + sendData["Values"] = new List(values); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/avatar"; + // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field"); + + } + else + m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + return false; + } + + public bool RemoveItems(UUID userID, string[] names) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "removeitems"; + + sendData["UserID"] = userID.ToString(); + sendData["Names"] = new List(names); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/avatar"; + // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems reply data does not contain result field"); + + } + else + m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + return false; + } + + #endregion + + } +} diff --git a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs deleted file mode 100644 index b1dd84e..0000000 --- a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs +++ /dev/null @@ -1,267 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; -using OpenSim.Server.Base; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors.Friends -{ - public class FriendsServicesConnector : IFriendsService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public FriendsServicesConnector() - { - } - - public FriendsServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public FriendsServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig gridConfig = source.Configs["FriendsService"]; - if (gridConfig == null) - { - m_log.Error("[FRIENDS SERVICE CONNECTOR]: FriendsService missing from OpenSim.ini"); - throw new Exception("Friends connector init error"); - } - - string serviceURI = gridConfig.GetString("FriendsServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[FRIENDS SERVICE CONNECTOR]: No Server URI named in section FriendsService"); - throw new Exception("Friends connector init error"); - } - m_ServerURI = serviceURI; - } - - - #region IFriendsService - - public FriendInfo[] GetFriends(UUID PrincipalID) - { - Dictionary sendData = new Dictionary(); - - sendData["PRINCIPALID"] = PrincipalID.ToString(); - sendData["METHOD"] = "getfriends"; - - return GetFriends(sendData, PrincipalID.ToString()); - } - - public FriendInfo[] GetFriends(string PrincipalID) - { - Dictionary sendData = new Dictionary(); - - sendData["PRINCIPALID"] = PrincipalID; - sendData["METHOD"] = "getfriends_string"; - - return GetFriends(sendData, PrincipalID); - } - - protected FriendInfo[] GetFriends(Dictionary sendData, string PrincipalID) - { - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/friends"; - - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - if (replyData.ContainsKey("result") && (replyData["result"].ToString().ToLower() == "null")) - { - return new FriendInfo[0]; - } - - List finfos = new List(); - Dictionary.ValueCollection finfosList = replyData.Values; - //m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); - foreach (object f in finfosList) - { - if (f is Dictionary) - { - FriendInfo finfo = new FriendInfo((Dictionary)f); - finfos.Add(finfo); - } - else - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: GetFriends {0} received invalid response type {1}", - PrincipalID, f.GetType()); - } - - // Success - return finfos.ToArray(); - } - else - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: GetFriends {0} received null response", - PrincipalID); - - } - } - catch (Exception e) - { - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); - } - - return new FriendInfo[0]; - - } - - public bool StoreFriend(string PrincipalID, string Friend, int flags) - { - - Dictionary sendData = ToKeyValuePairs(PrincipalID, Friend, flags); - - sendData["METHOD"] = "storefriend"; - - string reply = string.Empty; - string uri = m_ServerURI + "/friends"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); - return false; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) - { - bool success = false; - Boolean.TryParse(replyData["Result"].ToString(), out success); - return success; - } - else - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: StoreFriend {0} {1} received null response", - PrincipalID, Friend); - } - else - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: StoreFriend received null reply"); - - return false; - - } - - public bool Delete(string PrincipalID, string Friend) - { - Dictionary sendData = new Dictionary(); - sendData["PRINCIPALID"] = PrincipalID.ToString(); - sendData["FRIEND"] = Friend; - sendData["METHOD"] = "deletefriend_string"; - - return Delete(sendData, PrincipalID, Friend); - } - - public bool Delete(UUID PrincipalID, string Friend) - { - Dictionary sendData = new Dictionary(); - sendData["PRINCIPALID"] = PrincipalID.ToString(); - sendData["FRIEND"] = Friend; - sendData["METHOD"] = "deletefriend"; - - return Delete(sendData, PrincipalID.ToString(), Friend); - } - - public bool Delete(Dictionary sendData, string PrincipalID, string Friend) - { - string reply = string.Empty; - string uri = m_ServerURI + "/friends"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); - return false; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) - { - bool success = false; - Boolean.TryParse(replyData["Result"].ToString(), out success); - return success; - } - else - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: DeleteFriend {0} {1} received null response", - PrincipalID, Friend); - } - else - m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: DeleteFriend received null reply"); - - return false; - } - - #endregion - - public Dictionary ToKeyValuePairs(string principalID, string friend, int flags) - { - Dictionary result = new Dictionary(); - result["PrincipalID"] = principalID; - result["Friend"] = friend; - result["MyFlags"] = flags; - - return result; - } - - } -} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Friends/FriendsServicesConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsServicesConnector.cs new file mode 100644 index 0000000..b1dd84e --- /dev/null +++ b/OpenSim/Services/Connectors/Friends/FriendsServicesConnector.cs @@ -0,0 +1,267 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; +using OpenSim.Server.Base; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors.Friends +{ + public class FriendsServicesConnector : IFriendsService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public FriendsServicesConnector() + { + } + + public FriendsServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public FriendsServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig gridConfig = source.Configs["FriendsService"]; + if (gridConfig == null) + { + m_log.Error("[FRIENDS SERVICE CONNECTOR]: FriendsService missing from OpenSim.ini"); + throw new Exception("Friends connector init error"); + } + + string serviceURI = gridConfig.GetString("FriendsServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[FRIENDS SERVICE CONNECTOR]: No Server URI named in section FriendsService"); + throw new Exception("Friends connector init error"); + } + m_ServerURI = serviceURI; + } + + + #region IFriendsService + + public FriendInfo[] GetFriends(UUID PrincipalID) + { + Dictionary sendData = new Dictionary(); + + sendData["PRINCIPALID"] = PrincipalID.ToString(); + sendData["METHOD"] = "getfriends"; + + return GetFriends(sendData, PrincipalID.ToString()); + } + + public FriendInfo[] GetFriends(string PrincipalID) + { + Dictionary sendData = new Dictionary(); + + sendData["PRINCIPALID"] = PrincipalID; + sendData["METHOD"] = "getfriends_string"; + + return GetFriends(sendData, PrincipalID); + } + + protected FriendInfo[] GetFriends(Dictionary sendData, string PrincipalID) + { + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/friends"; + + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + if (replyData.ContainsKey("result") && (replyData["result"].ToString().ToLower() == "null")) + { + return new FriendInfo[0]; + } + + List finfos = new List(); + Dictionary.ValueCollection finfosList = replyData.Values; + //m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); + foreach (object f in finfosList) + { + if (f is Dictionary) + { + FriendInfo finfo = new FriendInfo((Dictionary)f); + finfos.Add(finfo); + } + else + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: GetFriends {0} received invalid response type {1}", + PrincipalID, f.GetType()); + } + + // Success + return finfos.ToArray(); + } + else + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: GetFriends {0} received null response", + PrincipalID); + + } + } + catch (Exception e) + { + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + } + + return new FriendInfo[0]; + + } + + public bool StoreFriend(string PrincipalID, string Friend, int flags) + { + + Dictionary sendData = ToKeyValuePairs(PrincipalID, Friend, flags); + + sendData["METHOD"] = "storefriend"; + + string reply = string.Empty; + string uri = m_ServerURI + "/friends"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + return false; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) + { + bool success = false; + Boolean.TryParse(replyData["Result"].ToString(), out success); + return success; + } + else + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: StoreFriend {0} {1} received null response", + PrincipalID, Friend); + } + else + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: StoreFriend received null reply"); + + return false; + + } + + public bool Delete(string PrincipalID, string Friend) + { + Dictionary sendData = new Dictionary(); + sendData["PRINCIPALID"] = PrincipalID.ToString(); + sendData["FRIEND"] = Friend; + sendData["METHOD"] = "deletefriend_string"; + + return Delete(sendData, PrincipalID, Friend); + } + + public bool Delete(UUID PrincipalID, string Friend) + { + Dictionary sendData = new Dictionary(); + sendData["PRINCIPALID"] = PrincipalID.ToString(); + sendData["FRIEND"] = Friend; + sendData["METHOD"] = "deletefriend"; + + return Delete(sendData, PrincipalID.ToString(), Friend); + } + + public bool Delete(Dictionary sendData, string PrincipalID, string Friend) + { + string reply = string.Empty; + string uri = m_ServerURI + "/friends"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + return false; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) + { + bool success = false; + Boolean.TryParse(replyData["Result"].ToString(), out success); + return success; + } + else + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: DeleteFriend {0} {1} received null response", + PrincipalID, Friend); + } + else + m_log.DebugFormat("[FRIENDS SERVICE CONNECTOR]: DeleteFriend received null reply"); + + return false; + } + + #endregion + + public Dictionary ToKeyValuePairs(string principalID, string friend, int flags) + { + Dictionary result = new Dictionary(); + result["PrincipalID"] = principalID; + result["Friend"] = friend; + result["MyFlags"] = flags; + + return result; + } + + } +} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs deleted file mode 100644 index 34ed0d7..0000000 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ /dev/null @@ -1,671 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; -using OpenSim.Server.Base; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class GridServicesConnector : IGridService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public GridServicesConnector() - { - } - - public GridServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public GridServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig gridConfig = source.Configs["GridService"]; - if (gridConfig == null) - { - m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); - throw new Exception("Grid connector init error"); - } - - string serviceURI = gridConfig.GetString("GridServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService"); - throw new Exception("Grid connector init error"); - } - m_ServerURI = serviceURI; - } - - - #region IGridService - - public string RegisterRegion(UUID scopeID, GridRegion regionInfo) - { - Dictionary rinfo = regionInfo.ToKeyValuePairs(); - Dictionary sendData = new Dictionary(); - foreach (KeyValuePair kvp in rinfo) - sendData[kvp.Key] = (string)kvp.Value; - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "register"; - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/grid"; - // m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "success")) - { - return String.Empty; - } - else if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "failure")) - { - m_log.ErrorFormat( - "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData["Message"], uri); - - return replyData["Message"].ToString(); - } - else if (!replyData.ContainsKey("Result")) - { - m_log.ErrorFormat( - "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri); - } - else - { - m_log.ErrorFormat( - "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData["Result"], uri); - - return "Unexpected result " + replyData["Result"].ToString(); - } - } - else - { - m_log.ErrorFormat( - "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri); - } - } - catch (Exception e) - { - m_log.ErrorFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - } - - return string.Format("Error communicating with the grid service at {0}", uri); - } - - public bool DeregisterRegion(UUID regionID) - { - Dictionary sendData = new Dictionary(); - - sendData["REGIONID"] = regionID.ToString(); - - sendData["METHOD"] = "deregister"; - - string uri = m_ServerURI + "/grid"; - - try - { - string reply - = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) - return true; - } - else - m_log.DebugFormat("[GRID CONNECTOR]: DeregisterRegion received null reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - } - - return false; - } - - public List GetNeighbours(UUID scopeID, UUID regionID) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["REGIONID"] = regionID.ToString(); - - sendData["METHOD"] = "get_neighbours"; - - List rinfos = new List(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; - } - - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - Dictionary.ValueCollection rinfosList = replyData.Values; - //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); - foreach (object r in rinfosList) - { - if (r is Dictionary) - { - GridRegion rinfo = new GridRegion((Dictionary)r); - rinfos.Add(rinfo); - } - } - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response", - scopeID, regionID); - - return rinfos; - } - - public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["REGIONID"] = regionID.ToString(); - - sendData["METHOD"] = "get_region_by_uuid"; - - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return null; - } - - GridRegion rinfo = null; - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - rinfo = new GridRegion((Dictionary)replyData["result"]); - //else - // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", - // scopeID, regionID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", - scopeID, regionID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID received null reply"); - - return rinfo; - } - - public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["X"] = x.ToString(); - sendData["Y"] = y.ToString(); - - sendData["METHOD"] = "get_region_by_position"; - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return null; - } - - GridRegion rinfo = null; - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - rinfo = new GridRegion((Dictionary)replyData["result"]); - //else - // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received no region", - // scopeID, x, y); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response", - scopeID, x, y); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply"); - - return rinfo; - } - - public GridRegion GetRegionByName(UUID scopeID, string regionName) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["NAME"] = regionName; - - sendData["METHOD"] = "get_region_by_name"; - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return null; - } - - GridRegion rinfo = null; - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - rinfo = new GridRegion((Dictionary)replyData["result"]); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response", - scopeID, regionName); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply"); - - return rinfo; - } - - public List GetRegionsByName(UUID scopeID, string name, int maxNumber) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["NAME"] = name; - sendData["MAX"] = maxNumber.ToString(); - - sendData["METHOD"] = "get_regions_by_name"; - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - Dictionary.ValueCollection rinfosList = replyData.Values; - foreach (object r in rinfosList) - { - if (r is Dictionary) - { - GridRegion rinfo = new GridRegion((Dictionary)r); - rinfos.Add(rinfo); - } - } - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response", - scopeID, name, maxNumber); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply"); - - return rinfos; - } - - public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["XMIN"] = xmin.ToString(); - sendData["XMAX"] = xmax.ToString(); - sendData["YMIN"] = ymin.ToString(); - sendData["YMAX"] = ymax.ToString(); - - sendData["METHOD"] = "get_region_range"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - - //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - Dictionary.ValueCollection rinfosList = replyData.Values; - foreach (object r in rinfosList) - { - if (r is Dictionary) - { - GridRegion rinfo = new GridRegion((Dictionary)r); - rinfos.Add(rinfo); - } - } - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response", - scopeID, xmin, xmax, ymin, ymax); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply"); - - return rinfos; - } - - public List GetDefaultRegions(UUID scopeID) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - - sendData["METHOD"] = "get_default_regions"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - - //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - Dictionary.ValueCollection rinfosList = replyData.Values; - foreach (object r in rinfosList) - { - if (r is Dictionary) - { - GridRegion rinfo = new GridRegion((Dictionary)r); - rinfos.Add(rinfo); - } - } - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", - scopeID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); - - return rinfos; - } - - public List GetFallbackRegions(UUID scopeID, int x, int y) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["X"] = x.ToString(); - sendData["Y"] = y.ToString(); - - sendData["METHOD"] = "get_fallback_regions"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - - //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - Dictionary.ValueCollection rinfosList = replyData.Values; - foreach (object r in rinfosList) - { - if (r is Dictionary) - { - GridRegion rinfo = new GridRegion((Dictionary)r); - rinfos.Add(rinfo); - } - } - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", - scopeID, x, y); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); - - return rinfos; - } - - public List GetHyperlinks(UUID scopeID) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - - sendData["METHOD"] = "get_hyperlinks"; - - List rinfos = new List(); - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - - //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return rinfos; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - Dictionary.ValueCollection rinfosList = replyData.Values; - foreach (object r in rinfosList) - { - if (r is Dictionary) - { - GridRegion rinfo = new GridRegion((Dictionary)r); - rinfos.Add(rinfo); - } - } - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks {0} received null response", - scopeID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply"); - - return rinfos; - } - - public int GetRegionFlags(UUID scopeID, UUID regionID) - { - Dictionary sendData = new Dictionary(); - - sendData["SCOPEID"] = scopeID.ToString(); - sendData["REGIONID"] = regionID.ToString(); - - sendData["METHOD"] = "get_region_flags"; - - string reply = string.Empty; - string uri = m_ServerURI + "/grid"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); - return -1; - } - - int flags = -1; - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) - { - Int32.TryParse((string)replyData["result"], out flags); - //else - // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", - // scopeID, regionID, replyData["result"].GetType()); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", - scopeID, regionID); - } - else - m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); - - return flags; - } - - #endregion - - } -} diff --git a/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs new file mode 100644 index 0000000..34ed0d7 --- /dev/null +++ b/OpenSim/Services/Connectors/Grid/GridServicesConnector.cs @@ -0,0 +1,671 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using OpenSim.Server.Base; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class GridServicesConnector : IGridService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public GridServicesConnector() + { + } + + public GridServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public GridServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig gridConfig = source.Configs["GridService"]; + if (gridConfig == null) + { + m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); + throw new Exception("Grid connector init error"); + } + + string serviceURI = gridConfig.GetString("GridServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService"); + throw new Exception("Grid connector init error"); + } + m_ServerURI = serviceURI; + } + + + #region IGridService + + public string RegisterRegion(UUID scopeID, GridRegion regionInfo) + { + Dictionary rinfo = regionInfo.ToKeyValuePairs(); + Dictionary sendData = new Dictionary(); + foreach (KeyValuePair kvp in rinfo) + sendData[kvp.Key] = (string)kvp.Value; + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "register"; + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/grid"; + // m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "success")) + { + return String.Empty; + } + else if (replyData.ContainsKey("Result")&& (replyData["Result"].ToString().ToLower() == "failure")) + { + m_log.ErrorFormat( + "[GRID CONNECTOR]: Registration failed: {0} when contacting {1}", replyData["Message"], uri); + + return replyData["Message"].ToString(); + } + else if (!replyData.ContainsKey("Result")) + { + m_log.ErrorFormat( + "[GRID CONNECTOR]: reply data does not contain result field when contacting {0}", uri); + } + else + { + m_log.ErrorFormat( + "[GRID CONNECTOR]: unexpected result {0} when contacting {1}", replyData["Result"], uri); + + return "Unexpected result " + replyData["Result"].ToString(); + } + } + else + { + m_log.ErrorFormat( + "[GRID CONNECTOR]: RegisterRegion received null reply when contacting grid server at {0}", uri); + } + } + catch (Exception e) + { + m_log.ErrorFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + } + + return string.Format("Error communicating with the grid service at {0}", uri); + } + + public bool DeregisterRegion(UUID regionID) + { + Dictionary sendData = new Dictionary(); + + sendData["REGIONID"] = regionID.ToString(); + + sendData["METHOD"] = "deregister"; + + string uri = m_ServerURI + "/grid"; + + try + { + string reply + = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) + return true; + } + else + m_log.DebugFormat("[GRID CONNECTOR]: DeregisterRegion received null reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + } + + return false; + } + + public List GetNeighbours(UUID scopeID, UUID regionID) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["REGIONID"] = regionID.ToString(); + + sendData["METHOD"] = "get_neighbours"; + + List rinfos = new List(); + + string reqString = ServerUtils.BuildQueryString(sendData); + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return rinfos; + } + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received null response", + scopeID, regionID); + + return rinfos; + } + + public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["REGIONID"] = regionID.ToString(); + + sendData["METHOD"] = "get_region_by_uuid"; + + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return null; + } + + GridRegion rinfo = null; + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData != null) && (replyData["result"] != null)) + { + if (replyData["result"] is Dictionary) + rinfo = new GridRegion((Dictionary)replyData["result"]); + //else + // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", + // scopeID, regionID); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", + scopeID, regionID); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID received null reply"); + + return rinfo; + } + + public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["X"] = x.ToString(); + sendData["Y"] = y.ToString(); + + sendData["METHOD"] = "get_region_by_position"; + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return null; + } + + GridRegion rinfo = null; + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData != null) && (replyData["result"] != null)) + { + if (replyData["result"] is Dictionary) + rinfo = new GridRegion((Dictionary)replyData["result"]); + //else + // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received no region", + // scopeID, x, y); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response", + scopeID, x, y); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply"); + + return rinfo; + } + + public GridRegion GetRegionByName(UUID scopeID, string regionName) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["NAME"] = regionName; + + sendData["METHOD"] = "get_region_by_name"; + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return null; + } + + GridRegion rinfo = null; + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData != null) && (replyData["result"] != null)) + { + if (replyData["result"] is Dictionary) + rinfo = new GridRegion((Dictionary)replyData["result"]); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response", + scopeID, regionName); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply"); + + return rinfo; + } + + public List GetRegionsByName(UUID scopeID, string name, int maxNumber) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["NAME"] = name; + sendData["MAX"] = maxNumber.ToString(); + + sendData["METHOD"] = "get_regions_by_name"; + List rinfos = new List(); + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return rinfos; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response", + scopeID, name, maxNumber); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply"); + + return rinfos; + } + + public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["XMIN"] = xmin.ToString(); + sendData["XMAX"] = xmax.ToString(); + sendData["YMIN"] = ymin.ToString(); + sendData["YMAX"] = ymax.ToString(); + + sendData["METHOD"] = "get_region_range"; + + List rinfos = new List(); + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + + //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return rinfos; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response", + scopeID, xmin, xmax, ymin, ymax); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply"); + + return rinfos; + } + + public List GetDefaultRegions(UUID scopeID) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + + sendData["METHOD"] = "get_default_regions"; + + List rinfos = new List(); + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + + //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return rinfos; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", + scopeID); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); + + return rinfos; + } + + public List GetFallbackRegions(UUID scopeID, int x, int y) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["X"] = x.ToString(); + sendData["Y"] = y.ToString(); + + sendData["METHOD"] = "get_fallback_regions"; + + List rinfos = new List(); + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + + //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return rinfos; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", + scopeID, x, y); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); + + return rinfos; + } + + public List GetHyperlinks(UUID scopeID) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + + sendData["METHOD"] = "get_hyperlinks"; + + List rinfos = new List(); + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + + //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return rinfos; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + Dictionary.ValueCollection rinfosList = replyData.Values; + foreach (object r in rinfosList) + { + if (r is Dictionary) + { + GridRegion rinfo = new GridRegion((Dictionary)r); + rinfos.Add(rinfo); + } + } + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks {0} received null response", + scopeID); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetHyperlinks received null reply"); + + return rinfos; + } + + public int GetRegionFlags(UUID scopeID, UUID regionID) + { + Dictionary sendData = new Dictionary(); + + sendData["SCOPEID"] = scopeID.ToString(); + sendData["REGIONID"] = regionID.ToString(); + + sendData["METHOD"] = "get_region_flags"; + + string reply = string.Empty; + string uri = m_ServerURI + "/grid"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server at {0}: {1}", uri, e.Message); + return -1; + } + + int flags = -1; + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) + { + Int32.TryParse((string)replyData["result"], out flags); + //else + // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", + // scopeID, regionID, replyData["result"].GetType()); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", + scopeID, regionID); + } + else + m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); + + return flags; + } + + #endregion + + } +} diff --git a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs deleted file mode 100644 index 20d7eaf..0000000 --- a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs +++ /dev/null @@ -1,290 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; -using OpenSim.Server.Base; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class GridUserServicesConnector : IGridUserService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public GridUserServicesConnector() - { - } - - public GridUserServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public GridUserServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig gridConfig = source.Configs["GridUserService"]; - if (gridConfig == null) - { - m_log.Error("[GRID USER CONNECTOR]: GridUserService missing from OpenSim.ini"); - throw new Exception("GridUser connector init error"); - } - - string serviceURI = gridConfig.GetString("GridUserServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService"); - throw new Exception("GridUser connector init error"); - } - m_ServerURI = serviceURI; - } - - - #region IGridUserService - - - public GridUserInfo LoggedIn(string userID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "loggedin"; - - sendData["UserID"] = userID; - - return Get(sendData); - - } - - public bool LoggedOut(string userID, UUID sessionID, UUID region, Vector3 position, Vector3 lookat) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "loggedout"; - - return Set(sendData, userID, region, position, lookat); - } - - public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "sethome"; - - return Set(sendData, userID, regionID, position, lookAt); - } - - public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "setposition"; - - return Set(sendData, userID, regionID, position, lookAt); - } - - public GridUserInfo GetGridUserInfo(string userID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getgriduserinfo"; - - sendData["UserID"] = userID; - - return Get(sendData); - } - - #endregion - - protected bool Set(Dictionary sendData, string userID, UUID regionID, Vector3 position, Vector3 lookAt) - { - sendData["UserID"] = userID; - sendData["RegionID"] = regionID.ToString(); - sendData["Position"] = position.ToString(); - sendData["LookAt"] = lookAt.ToString(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/griduser"; - // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition reply data does not contain result field"); - - } - else - m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); - } - - return false; - } - - protected GridUserInfo Get(Dictionary sendData) - { - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/griduser"; - // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - GridUserInfo guinfo = null; - - if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - guinfo = new GridUserInfo((Dictionary)replyData["result"]); - } - - return guinfo; - - } - else - m_log.DebugFormat("[GRID USER CONNECTOR]: Loggedin received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); - } - - return null; - - } - - public GridUserInfo[] GetGridUserInfo(string[] userIDs) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getgriduserinfos"; - - sendData["AgentIDs"] = new List(userIDs); - - string reply = string.Empty; - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/griduser"; - //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply == null || (reply != null && reply == string.Empty)) - { - m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null or empty reply"); - return null; - } - } - catch (Exception e) - { - m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); - } - - List rinfos = new List(); - - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - if (replyData.ContainsKey("result") && - (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) - { - return new GridUserInfo[0]; - } - - Dictionary.ValueCollection pinfosList = replyData.Values; - //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); - foreach (object griduser in pinfosList) - { - if (griduser is Dictionary) - { - GridUserInfo pinfo = new GridUserInfo((Dictionary)griduser); - rinfos.Add(pinfo); - } - else - m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received invalid response type {0}", - griduser.GetType()); - } - } - else - m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null response"); - - return rinfos.ToArray(); - } - } -} diff --git a/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs b/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs new file mode 100644 index 0000000..20d7eaf --- /dev/null +++ b/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs @@ -0,0 +1,290 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using OpenSim.Server.Base; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class GridUserServicesConnector : IGridUserService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public GridUserServicesConnector() + { + } + + public GridUserServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public GridUserServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig gridConfig = source.Configs["GridUserService"]; + if (gridConfig == null) + { + m_log.Error("[GRID USER CONNECTOR]: GridUserService missing from OpenSim.ini"); + throw new Exception("GridUser connector init error"); + } + + string serviceURI = gridConfig.GetString("GridUserServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService"); + throw new Exception("GridUser connector init error"); + } + m_ServerURI = serviceURI; + } + + + #region IGridUserService + + + public GridUserInfo LoggedIn(string userID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "loggedin"; + + sendData["UserID"] = userID; + + return Get(sendData); + + } + + public bool LoggedOut(string userID, UUID sessionID, UUID region, Vector3 position, Vector3 lookat) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "loggedout"; + + return Set(sendData, userID, region, position, lookat); + } + + public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "sethome"; + + return Set(sendData, userID, regionID, position, lookAt); + } + + public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "setposition"; + + return Set(sendData, userID, regionID, position, lookAt); + } + + public GridUserInfo GetGridUserInfo(string userID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getgriduserinfo"; + + sendData["UserID"] = userID; + + return Get(sendData); + } + + #endregion + + protected bool Set(Dictionary sendData, string userID, UUID regionID, Vector3 position, Vector3 lookAt) + { + sendData["UserID"] = userID; + sendData["RegionID"] = regionID.ToString(); + sendData["Position"] = position.ToString(); + sendData["LookAt"] = lookAt.ToString(); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/griduser"; + // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition reply data does not contain result field"); + + } + else + m_log.DebugFormat("[GRID USER CONNECTOR]: SetPosition received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); + } + + return false; + } + + protected GridUserInfo Get(Dictionary sendData) + { + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/griduser"; + // m_log.DebugFormat("[GRID USER CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + GridUserInfo guinfo = null; + + if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) + { + if (replyData["result"] is Dictionary) + guinfo = new GridUserInfo((Dictionary)replyData["result"]); + } + + return guinfo; + + } + else + m_log.DebugFormat("[GRID USER CONNECTOR]: Loggedin received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); + } + + return null; + + } + + public GridUserInfo[] GetGridUserInfo(string[] userIDs) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getgriduserinfos"; + + sendData["AgentIDs"] = new List(userIDs); + + string reply = string.Empty; + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/griduser"; + //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply == null || (reply != null && reply == string.Empty)) + { + m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null or empty reply"); + return null; + } + } + catch (Exception e) + { + m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); + } + + List rinfos = new List(); + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + if (replyData.ContainsKey("result") && + (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) + { + return new GridUserInfo[0]; + } + + Dictionary.ValueCollection pinfosList = replyData.Values; + //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); + foreach (object griduser in pinfosList) + { + if (griduser is Dictionary) + { + GridUserInfo pinfo = new GridUserInfo((Dictionary)griduser); + rinfos.Add(pinfo); + } + else + m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received invalid response type {0}", + griduser.GetType()); + } + } + else + m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null response"); + + return rinfos.ToArray(); + } + } +} diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs deleted file mode 100644 index e984a54..0000000 --- a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs +++ /dev/null @@ -1,312 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Services.Interfaces; -using OpenSim.Services.Connectors.Friends; -using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; -using OpenSim.Server.Base; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors.Hypergrid -{ - public class HGFriendsServicesConnector : FriendsSimConnector - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - private string m_ServiceKey = String.Empty; - private UUID m_SessionID; - - public HGFriendsServicesConnector() - { - } - - public HGFriendsServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public HGFriendsServicesConnector(string serverURI, UUID sessionID, string serviceKey) - { - m_ServerURI = serverURI.TrimEnd('/'); - m_ServiceKey = serviceKey; - m_SessionID = sessionID; - } - - protected override string ServicePath() - { - return "hgfriends"; - } - - #region IFriendsService - - public uint GetFriendPerms(UUID PrincipalID, UUID friendID) - { - Dictionary sendData = new Dictionary(); - - sendData["PRINCIPALID"] = PrincipalID.ToString(); - sendData["FRIENDID"] = friendID.ToString(); - sendData["METHOD"] = "getfriendperms"; - sendData["KEY"] = m_ServiceKey; - sendData["SESSIONID"] = m_SessionID.ToString(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/hgfriends"; - - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && replyData.ContainsKey("Value") && (replyData["Value"] != null)) - { - uint perms = 0; - uint.TryParse(replyData["Value"].ToString(), out perms); - return perms; - } - else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriendPerms {0} received null response", - PrincipalID); - - } - } - catch (Exception e) - { - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); - } - - return 0; - - } - - public bool NewFriendship(UUID PrincipalID, string Friend) - { - FriendInfo finfo = new FriendInfo(); - finfo.PrincipalID = PrincipalID; - finfo.Friend = Friend; - - Dictionary sendData = finfo.ToKeyValuePairs(); - - sendData["METHOD"] = "newfriendship"; - sendData["KEY"] = m_ServiceKey; - sendData["SESSIONID"] = m_SessionID.ToString(); - - string reply = string.Empty; - string uri = m_ServerURI + "/hgfriends"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); - return false; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) - { - bool success = false; - Boolean.TryParse(replyData["Result"].ToString(), out success); - return success; - } - else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend {0} {1} received null response", - PrincipalID, Friend); - } - else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend received null reply"); - - return false; - - } - - public bool DeleteFriendship(UUID PrincipalID, UUID Friend, string secret) - { - FriendInfo finfo = new FriendInfo(); - finfo.PrincipalID = PrincipalID; - finfo.Friend = Friend.ToString(); - - Dictionary sendData = finfo.ToKeyValuePairs(); - - sendData["METHOD"] = "deletefriendship"; - sendData["SECRET"] = secret; - - string reply = string.Empty; - string uri = m_ServerURI + "/hgfriends"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); - return false; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("RESULT")) - { - if (replyData["RESULT"].ToString().ToLower() == "true") - return true; - else - return false; - } - else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); - - } - else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); - - return false; - - } - - public bool ValidateFriendshipOffered(UUID fromID, UUID toID) - { - FriendInfo finfo = new FriendInfo(); - finfo.PrincipalID = fromID; - finfo.Friend = toID.ToString(); - - Dictionary sendData = finfo.ToKeyValuePairs(); - - sendData["METHOD"] = "validate_friendship_offered"; - - string reply = string.Empty; - string uri = m_ServerURI + "/hgfriends"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); - return false; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("RESULT")) - { - if (replyData["RESULT"].ToString().ToLower() == "true") - return true; - else - return false; - } - else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); - - } - else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); - - return false; - - } - - public List StatusNotification(List friends, UUID userID, bool online) - { - Dictionary sendData = new Dictionary(); - List friendsOnline = new List(); - - sendData["METHOD"] = "statusnotification"; - sendData["userID"] = userID.ToString(); - sendData["online"] = online.ToString(); - int i = 0; - foreach (string s in friends) - { - sendData["friend_" + i.ToString()] = s; - i++; - } - - string reply = string.Empty; - string uri = m_ServerURI + "/hgfriends"; - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - ServerUtils.BuildQueryString(sendData)); - } - catch (Exception e) - { - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); - return friendsOnline; - } - - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - // Here is the actual response - foreach (string key in replyData.Keys) - { - if (key.StartsWith("friend_") && replyData[key] != null) - { - UUID uuid; - if (UUID.TryParse(replyData[key].ToString(), out uuid)) - friendsOnline.Add(uuid); - } - } - } - else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Received empty reply from remote StatusNotify"); - - return friendsOnline; - - } - - #endregion - } -} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs new file mode 100644 index 0000000..e984a54 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs @@ -0,0 +1,312 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Services.Interfaces; +using OpenSim.Services.Connectors.Friends; +using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; +using OpenSim.Server.Base; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors.Hypergrid +{ + public class HGFriendsServicesConnector : FriendsSimConnector + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + private string m_ServiceKey = String.Empty; + private UUID m_SessionID; + + public HGFriendsServicesConnector() + { + } + + public HGFriendsServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public HGFriendsServicesConnector(string serverURI, UUID sessionID, string serviceKey) + { + m_ServerURI = serverURI.TrimEnd('/'); + m_ServiceKey = serviceKey; + m_SessionID = sessionID; + } + + protected override string ServicePath() + { + return "hgfriends"; + } + + #region IFriendsService + + public uint GetFriendPerms(UUID PrincipalID, UUID friendID) + { + Dictionary sendData = new Dictionary(); + + sendData["PRINCIPALID"] = PrincipalID.ToString(); + sendData["FRIENDID"] = friendID.ToString(); + sendData["METHOD"] = "getfriendperms"; + sendData["KEY"] = m_ServiceKey; + sendData["SESSIONID"] = m_SessionID.ToString(); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/hgfriends"; + + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData != null) && replyData.ContainsKey("Value") && (replyData["Value"] != null)) + { + uint perms = 0; + uint.TryParse(replyData["Value"].ToString(), out perms); + return perms; + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriendPerms {0} received null response", + PrincipalID); + + } + } + catch (Exception e) + { + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + } + + return 0; + + } + + public bool NewFriendship(UUID PrincipalID, string Friend) + { + FriendInfo finfo = new FriendInfo(); + finfo.PrincipalID = PrincipalID; + finfo.Friend = Friend; + + Dictionary sendData = finfo.ToKeyValuePairs(); + + sendData["METHOD"] = "newfriendship"; + sendData["KEY"] = m_ServiceKey; + sendData["SESSIONID"] = m_SessionID.ToString(); + + string reply = string.Empty; + string uri = m_ServerURI + "/hgfriends"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + return false; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) + { + bool success = false; + Boolean.TryParse(replyData["Result"].ToString(), out success); + return success; + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend {0} {1} received null response", + PrincipalID, Friend); + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend received null reply"); + + return false; + + } + + public bool DeleteFriendship(UUID PrincipalID, UUID Friend, string secret) + { + FriendInfo finfo = new FriendInfo(); + finfo.PrincipalID = PrincipalID; + finfo.Friend = Friend.ToString(); + + Dictionary sendData = finfo.ToKeyValuePairs(); + + sendData["METHOD"] = "deletefriendship"; + sendData["SECRET"] = secret; + + string reply = string.Empty; + string uri = m_ServerURI + "/hgfriends"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + return false; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("RESULT")) + { + if (replyData["RESULT"].ToString().ToLower() == "true") + return true; + else + return false; + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); + + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); + + return false; + + } + + public bool ValidateFriendshipOffered(UUID fromID, UUID toID) + { + FriendInfo finfo = new FriendInfo(); + finfo.PrincipalID = fromID; + finfo.Friend = toID.ToString(); + + Dictionary sendData = finfo.ToKeyValuePairs(); + + sendData["METHOD"] = "validate_friendship_offered"; + + string reply = string.Empty; + string uri = m_ServerURI + "/hgfriends"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + return false; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("RESULT")) + { + if (replyData["RESULT"].ToString().ToLower() == "true") + return true; + else + return false; + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); + + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); + + return false; + + } + + public List StatusNotification(List friends, UUID userID, bool online) + { + Dictionary sendData = new Dictionary(); + List friendsOnline = new List(); + + sendData["METHOD"] = "statusnotification"; + sendData["userID"] = userID.ToString(); + sendData["online"] = online.ToString(); + int i = 0; + foreach (string s in friends) + { + sendData["friend_" + i.ToString()] = s; + i++; + } + + string reply = string.Empty; + string uri = m_ServerURI + "/hgfriends"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + return friendsOnline; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + // Here is the actual response + foreach (string key in replyData.Keys) + { + if (key.StartsWith("friend_") && replyData[key] != null) + { + UUID uuid; + if (UUID.TryParse(replyData[key].ToString(), out uuid)) + friendsOnline.Add(uuid); + } + } + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Received empty reply from remote StatusNotify"); + + return friendsOnline; + + } + + #endregion + } +} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Hypergrid/HeloServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HeloServiceConnector.cs deleted file mode 100644 index 5c50936..0000000 --- a/OpenSim/Services/Connectors/Hypergrid/HeloServiceConnector.cs +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Net; -using System.Reflection; -using Nini.Config; - -namespace OpenSim.Services.Connectors -{ - public class HeloServicesConnector - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public HeloServicesConnector() - { - } - - public HeloServicesConnector(string serverURI) - { - if (!serverURI.EndsWith("=")) - m_ServerURI = serverURI.TrimEnd('/') + "/helo/"; - else - { - // Simian sends malformed urls like this: - // http://valley.virtualportland.org/simtest/Grid/?id= - // - try - { - Uri uri = new Uri(serverURI + "xxx"); - if (uri.Query == string.Empty) - m_ServerURI = serverURI.TrimEnd('/') + "/helo/"; - else - { - serverURI = serverURI + "xxx"; - m_ServerURI = serverURI.Replace(uri.Query, ""); - m_ServerURI = m_ServerURI.TrimEnd('/') + "/helo/"; - } - } - catch (UriFormatException) - { - m_log.WarnFormat("[HELO SERVICE]: Malformed URL {0}", serverURI); - } - } - } - - - public virtual string Helo() - { - HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); - // Eventually we need to switch to HEAD - /* req.Method = "HEAD"; */ - - try - { - WebResponse response = req.GetResponse(); - if (response.Headers.Get("X-Handlers-Provided") == null) // just in case this ever returns a null - return string.Empty; - return response.Headers.Get("X-Handlers-Provided"); - } - catch (Exception e) - { - m_log.DebugFormat("[HELO SERVICE]: Unable to perform HELO request to {0}: {1}", m_ServerURI, e.Message); - } - - // fail - return string.Empty; - } - - } -} diff --git a/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs new file mode 100644 index 0000000..5c50936 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs @@ -0,0 +1,100 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Net; +using System.Reflection; +using Nini.Config; + +namespace OpenSim.Services.Connectors +{ + public class HeloServicesConnector + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public HeloServicesConnector() + { + } + + public HeloServicesConnector(string serverURI) + { + if (!serverURI.EndsWith("=")) + m_ServerURI = serverURI.TrimEnd('/') + "/helo/"; + else + { + // Simian sends malformed urls like this: + // http://valley.virtualportland.org/simtest/Grid/?id= + // + try + { + Uri uri = new Uri(serverURI + "xxx"); + if (uri.Query == string.Empty) + m_ServerURI = serverURI.TrimEnd('/') + "/helo/"; + else + { + serverURI = serverURI + "xxx"; + m_ServerURI = serverURI.Replace(uri.Query, ""); + m_ServerURI = m_ServerURI.TrimEnd('/') + "/helo/"; + } + } + catch (UriFormatException) + { + m_log.WarnFormat("[HELO SERVICE]: Malformed URL {0}", serverURI); + } + } + } + + + public virtual string Helo() + { + HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); + // Eventually we need to switch to HEAD + /* req.Method = "HEAD"; */ + + try + { + WebResponse response = req.GetResponse(); + if (response.Headers.Get("X-Handlers-Provided") == null) // just in case this ever returns a null + return string.Empty; + return response.Headers.Get("X-Handlers-Provided"); + } + catch (Exception e) + { + m_log.DebugFormat("[HELO SERVICE]: Unable to perform HELO request to {0}: {1}", m_ServerURI, e.Message); + } + + // fail + return string.Empty; + } + + } +} diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs deleted file mode 100644 index 9d96703..0000000 --- a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs +++ /dev/null @@ -1,623 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Console; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using OpenSim.Server.Base; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class XInventoryServicesConnector : IInventoryService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - private object m_Lock = new object(); - - public XInventoryServicesConnector() - { - } - - public XInventoryServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public XInventoryServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig assetConfig = source.Configs["InventoryService"]; - if (assetConfig == null) - { - m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); - throw new Exception("Inventory connector init error"); - } - - string serviceURI = assetConfig.GetString("InventoryServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[INVENTORY CONNECTOR]: No Server URI named in section InventoryService"); - throw new Exception("Inventory connector init error"); - } - m_ServerURI = serviceURI; - } - - public bool CreateUserInventory(UUID principalID) - { - Dictionary ret = MakeRequest("CREATEUSERINVENTORY", - new Dictionary { - { "PRINCIPAL", principalID.ToString() } - }); - - if (ret == null) - return false; - if (ret.Count == 0) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public List GetInventorySkeleton(UUID principalID) - { - Dictionary ret = MakeRequest("GETINVENTORYSKELETON", - new Dictionary { - { "PRINCIPAL", principalID.ToString() } - }); - - if (ret == null) - return null; - if (ret.Count == 0) - return null; - - Dictionary folders = (Dictionary)ret["FOLDERS"]; - - List fldrs = new List(); - - try - { - foreach (Object o in folders.Values) - fldrs.Add(BuildFolder((Dictionary)o)); - } - catch (Exception e) - { - m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception unwrapping folder list: {0}", e.Message); - } - - return fldrs; - } - - public InventoryFolderBase GetRootFolder(UUID principalID) - { - Dictionary ret = MakeRequest("GETROOTFOLDER", - new Dictionary { - { "PRINCIPAL", principalID.ToString() } - }); - - if (ret == null) - return null; - if (ret.Count == 0) - return null; - - return BuildFolder((Dictionary)ret["folder"]); - } - - public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) - { - Dictionary ret = MakeRequest("GETFOLDERFORTYPE", - new Dictionary { - { "PRINCIPAL", principalID.ToString() }, - { "TYPE", ((int)type).ToString() } - }); - - if (ret == null) - return null; - if (ret.Count == 0) - return null; - - return BuildFolder((Dictionary)ret["folder"]); - } - - public InventoryCollection GetFolderContent(UUID principalID, UUID folderID) - { - InventoryCollection inventory = new InventoryCollection(); - inventory.Folders = new List(); - inventory.Items = new List(); - inventory.UserID = principalID; - - try - { - Dictionary ret = MakeRequest("GETFOLDERCONTENT", - new Dictionary { - { "PRINCIPAL", principalID.ToString() }, - { "FOLDER", folderID.ToString() } - }); - - if (ret == null) - return null; - if (ret.Count == 0) - return null; - - Dictionary folders = - (Dictionary)ret["FOLDERS"]; - Dictionary items = - (Dictionary)ret["ITEMS"]; - - foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i - inventory.Folders.Add(BuildFolder((Dictionary)o)); - foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i - inventory.Items.Add(BuildItem((Dictionary)o)); - } - catch (Exception e) - { - m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetFolderContent: {0}", e.Message); - } - - return inventory; - } - - public List GetFolderItems(UUID principalID, UUID folderID) - { - Dictionary ret = MakeRequest("GETFOLDERITEMS", - new Dictionary { - { "PRINCIPAL", principalID.ToString() }, - { "FOLDER", folderID.ToString() } - }); - - if (ret == null) - return null; - if (ret.Count == 0) - return null; - - Dictionary items = (Dictionary)ret["ITEMS"]; - List fitems = new List(); - foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i - fitems.Add(BuildItem((Dictionary)o)); - - return fitems; - } - - public bool AddFolder(InventoryFolderBase folder) - { - Dictionary ret = MakeRequest("ADDFOLDER", - new Dictionary { - { "ParentID", folder.ParentID.ToString() }, - { "Type", folder.Type.ToString() }, - { "Version", folder.Version.ToString() }, - { "Name", folder.Name.ToString() }, - { "Owner", folder.Owner.ToString() }, - { "ID", folder.ID.ToString() } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public bool UpdateFolder(InventoryFolderBase folder) - { - Dictionary ret = MakeRequest("UPDATEFOLDER", - new Dictionary { - { "ParentID", folder.ParentID.ToString() }, - { "Type", folder.Type.ToString() }, - { "Version", folder.Version.ToString() }, - { "Name", folder.Name.ToString() }, - { "Owner", folder.Owner.ToString() }, - { "ID", folder.ID.ToString() } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public bool MoveFolder(InventoryFolderBase folder) - { - Dictionary ret = MakeRequest("MOVEFOLDER", - new Dictionary { - { "ParentID", folder.ParentID.ToString() }, - { "ID", folder.ID.ToString() }, - { "PRINCIPAL", folder.Owner.ToString() } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public bool DeleteFolders(UUID principalID, List folderIDs) - { - List slist = new List(); - - foreach (UUID f in folderIDs) - slist.Add(f.ToString()); - - Dictionary ret = MakeRequest("DELETEFOLDERS", - new Dictionary { - { "PRINCIPAL", principalID.ToString() }, - { "FOLDERS", slist } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public bool PurgeFolder(InventoryFolderBase folder) - { - Dictionary ret = MakeRequest("PURGEFOLDER", - new Dictionary { - { "ID", folder.ID.ToString() } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public bool AddItem(InventoryItemBase item) - { - if (item.CreatorData == null) - item.CreatorData = String.Empty; - Dictionary ret = MakeRequest("ADDITEM", - new Dictionary { - { "AssetID", item.AssetID.ToString() }, - { "AssetType", item.AssetType.ToString() }, - { "Name", item.Name.ToString() }, - { "Owner", item.Owner.ToString() }, - { "ID", item.ID.ToString() }, - { "InvType", item.InvType.ToString() }, - { "Folder", item.Folder.ToString() }, - { "CreatorId", item.CreatorId.ToString() }, - { "CreatorData", item.CreatorData.ToString() }, - { "Description", item.Description.ToString() }, - { "NextPermissions", item.NextPermissions.ToString() }, - { "CurrentPermissions", item.CurrentPermissions.ToString() }, - { "BasePermissions", item.BasePermissions.ToString() }, - { "EveryOnePermissions", item.EveryOnePermissions.ToString() }, - { "GroupPermissions", item.GroupPermissions.ToString() }, - { "GroupID", item.GroupID.ToString() }, - { "GroupOwned", item.GroupOwned.ToString() }, - { "SalePrice", item.SalePrice.ToString() }, - { "SaleType", item.SaleType.ToString() }, - { "Flags", item.Flags.ToString() }, - { "CreationDate", item.CreationDate.ToString() } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public bool UpdateItem(InventoryItemBase item) - { - if (item.CreatorData == null) - item.CreatorData = String.Empty; - Dictionary ret = MakeRequest("UPDATEITEM", - new Dictionary { - { "AssetID", item.AssetID.ToString() }, - { "AssetType", item.AssetType.ToString() }, - { "Name", item.Name.ToString() }, - { "Owner", item.Owner.ToString() }, - { "ID", item.ID.ToString() }, - { "InvType", item.InvType.ToString() }, - { "Folder", item.Folder.ToString() }, - { "CreatorId", item.CreatorId.ToString() }, - { "CreatorData", item.CreatorData.ToString() }, - { "Description", item.Description.ToString() }, - { "NextPermissions", item.NextPermissions.ToString() }, - { "CurrentPermissions", item.CurrentPermissions.ToString() }, - { "BasePermissions", item.BasePermissions.ToString() }, - { "EveryOnePermissions", item.EveryOnePermissions.ToString() }, - { "GroupPermissions", item.GroupPermissions.ToString() }, - { "GroupID", item.GroupID.ToString() }, - { "GroupOwned", item.GroupOwned.ToString() }, - { "SalePrice", item.SalePrice.ToString() }, - { "SaleType", item.SaleType.ToString() }, - { "Flags", item.Flags.ToString() }, - { "CreationDate", item.CreationDate.ToString() } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public bool MoveItems(UUID principalID, List items) - { - List idlist = new List(); - List destlist = new List(); - - foreach (InventoryItemBase item in items) - { - idlist.Add(item.ID.ToString()); - destlist.Add(item.Folder.ToString()); - } - - Dictionary ret = MakeRequest("MOVEITEMS", - new Dictionary { - { "PRINCIPAL", principalID.ToString() }, - { "IDLIST", idlist }, - { "DESTLIST", destlist } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public bool DeleteItems(UUID principalID, List itemIDs) - { - List slist = new List(); - - foreach (UUID f in itemIDs) - slist.Add(f.ToString()); - - Dictionary ret = MakeRequest("DELETEITEMS", - new Dictionary { - { "PRINCIPAL", principalID.ToString() }, - { "ITEMS", slist } - }); - - if (ret == null) - return false; - - return bool.Parse(ret["RESULT"].ToString()); - } - - public InventoryItemBase GetItem(InventoryItemBase item) - { - try - { - Dictionary ret = MakeRequest("GETITEM", - new Dictionary { - { "ID", item.ID.ToString() } - }); - - if (ret == null) - return null; - if (ret.Count == 0) - return null; - - return BuildItem((Dictionary)ret["item"]); - } - catch (Exception e) - { - m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetItem: {0}", e.Message); - } - - return null; - } - - public InventoryFolderBase GetFolder(InventoryFolderBase folder) - { - try - { - Dictionary ret = MakeRequest("GETFOLDER", - new Dictionary { - { "ID", folder.ID.ToString() } - }); - - if (ret == null) - return null; - if (ret.Count == 0) - return null; - - return BuildFolder((Dictionary)ret["folder"]); - } - catch (Exception e) - { - m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetFolder: {0}", e.Message); - } - - return null; - } - - public List GetActiveGestures(UUID principalID) - { - Dictionary ret = MakeRequest("GETACTIVEGESTURES", - new Dictionary { - { "PRINCIPAL", principalID.ToString() } - }); - - if (ret == null) - return null; - - List items = new List(); - - foreach (Object o in ret.Values) // getting the values directly, we don't care about the keys item_i - items.Add(BuildItem((Dictionary)o)); - - return items; - } - - public int GetAssetPermissions(UUID principalID, UUID assetID) - { - Dictionary ret = MakeRequest("GETASSETPERMISSIONS", - new Dictionary { - { "PRINCIPAL", principalID.ToString() }, - { "ASSET", assetID.ToString() } - }); - - if (ret == null) - return 0; - - return int.Parse(ret["RESULT"].ToString()); - } - - public InventoryCollection GetUserInventory(UUID principalID) - { - InventoryCollection inventory = new InventoryCollection(); - inventory.Folders = new List(); - inventory.Items = new List(); - inventory.UserID = principalID; - - try - { - Dictionary ret = MakeRequest("GETUSERINVENTORY", - new Dictionary { - { "PRINCIPAL", principalID.ToString() } - }); - - if (ret == null) - return null; - if (ret.Count == 0) - return null; - - Dictionary folders = - (Dictionary)ret["FOLDERS"]; - Dictionary items = - (Dictionary)ret["ITEMS"]; - - foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i - inventory.Folders.Add(BuildFolder((Dictionary)o)); - foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i - inventory.Items.Add(BuildItem((Dictionary)o)); - } - catch (Exception e) - { - m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetUserInventory: {0}", e.Message); - } - - return inventory; - } - - public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback) - { - } - - public bool HasInventoryForUser(UUID principalID) - { - return false; - } - - // Helpers - // - private Dictionary MakeRequest(string method, - Dictionary sendData) - { - sendData["METHOD"] = method; - - string reply = string.Empty; - lock (m_Lock) - reply = SynchronousRestFormsRequester.MakeRequest("POST", - m_ServerURI + "/xinventory", - ServerUtils.BuildQueryString(sendData)); - - Dictionary replyData = ServerUtils.ParseXmlResponse( - reply); - - return replyData; - } - - private InventoryFolderBase BuildFolder(Dictionary data) - { - InventoryFolderBase folder = new InventoryFolderBase(); - - try - { - folder.ParentID = new UUID(data["ParentID"].ToString()); - folder.Type = short.Parse(data["Type"].ToString()); - folder.Version = ushort.Parse(data["Version"].ToString()); - folder.Name = data["Name"].ToString(); - folder.Owner = new UUID(data["Owner"].ToString()); - folder.ID = new UUID(data["ID"].ToString()); - } - catch (Exception e) - { - m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception building folder: {0}", e.Message); - } - - return folder; - } - - private InventoryItemBase BuildItem(Dictionary data) - { - InventoryItemBase item = new InventoryItemBase(); - - try - { - item.AssetID = new UUID(data["AssetID"].ToString()); - item.AssetType = int.Parse(data["AssetType"].ToString()); - item.Name = data["Name"].ToString(); - item.Owner = new UUID(data["Owner"].ToString()); - item.ID = new UUID(data["ID"].ToString()); - item.InvType = int.Parse(data["InvType"].ToString()); - item.Folder = new UUID(data["Folder"].ToString()); - item.CreatorId = data["CreatorId"].ToString(); - if (data.ContainsKey("CreatorData")) - item.CreatorData = data["CreatorData"].ToString(); - else - item.CreatorData = String.Empty; - item.Description = data["Description"].ToString(); - item.NextPermissions = uint.Parse(data["NextPermissions"].ToString()); - item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString()); - item.BasePermissions = uint.Parse(data["BasePermissions"].ToString()); - item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString()); - item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString()); - item.GroupID = new UUID(data["GroupID"].ToString()); - item.GroupOwned = bool.Parse(data["GroupOwned"].ToString()); - item.SalePrice = int.Parse(data["SalePrice"].ToString()); - item.SaleType = byte.Parse(data["SaleType"].ToString()); - item.Flags = uint.Parse(data["Flags"].ToString()); - item.CreationDate = int.Parse(data["CreationDate"].ToString()); - } - catch (Exception e) - { - m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception building item: {0}", e.Message); - } - - return item; - } - - } -} diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs new file mode 100644 index 0000000..9d96703 --- /dev/null +++ b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs @@ -0,0 +1,623 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Console; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using OpenSim.Server.Base; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class XInventoryServicesConnector : IInventoryService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + private object m_Lock = new object(); + + public XInventoryServicesConnector() + { + } + + public XInventoryServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public XInventoryServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig assetConfig = source.Configs["InventoryService"]; + if (assetConfig == null) + { + m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); + throw new Exception("Inventory connector init error"); + } + + string serviceURI = assetConfig.GetString("InventoryServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[INVENTORY CONNECTOR]: No Server URI named in section InventoryService"); + throw new Exception("Inventory connector init error"); + } + m_ServerURI = serviceURI; + } + + public bool CreateUserInventory(UUID principalID) + { + Dictionary ret = MakeRequest("CREATEUSERINVENTORY", + new Dictionary { + { "PRINCIPAL", principalID.ToString() } + }); + + if (ret == null) + return false; + if (ret.Count == 0) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public List GetInventorySkeleton(UUID principalID) + { + Dictionary ret = MakeRequest("GETINVENTORYSKELETON", + new Dictionary { + { "PRINCIPAL", principalID.ToString() } + }); + + if (ret == null) + return null; + if (ret.Count == 0) + return null; + + Dictionary folders = (Dictionary)ret["FOLDERS"]; + + List fldrs = new List(); + + try + { + foreach (Object o in folders.Values) + fldrs.Add(BuildFolder((Dictionary)o)); + } + catch (Exception e) + { + m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception unwrapping folder list: {0}", e.Message); + } + + return fldrs; + } + + public InventoryFolderBase GetRootFolder(UUID principalID) + { + Dictionary ret = MakeRequest("GETROOTFOLDER", + new Dictionary { + { "PRINCIPAL", principalID.ToString() } + }); + + if (ret == null) + return null; + if (ret.Count == 0) + return null; + + return BuildFolder((Dictionary)ret["folder"]); + } + + public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) + { + Dictionary ret = MakeRequest("GETFOLDERFORTYPE", + new Dictionary { + { "PRINCIPAL", principalID.ToString() }, + { "TYPE", ((int)type).ToString() } + }); + + if (ret == null) + return null; + if (ret.Count == 0) + return null; + + return BuildFolder((Dictionary)ret["folder"]); + } + + public InventoryCollection GetFolderContent(UUID principalID, UUID folderID) + { + InventoryCollection inventory = new InventoryCollection(); + inventory.Folders = new List(); + inventory.Items = new List(); + inventory.UserID = principalID; + + try + { + Dictionary ret = MakeRequest("GETFOLDERCONTENT", + new Dictionary { + { "PRINCIPAL", principalID.ToString() }, + { "FOLDER", folderID.ToString() } + }); + + if (ret == null) + return null; + if (ret.Count == 0) + return null; + + Dictionary folders = + (Dictionary)ret["FOLDERS"]; + Dictionary items = + (Dictionary)ret["ITEMS"]; + + foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i + inventory.Folders.Add(BuildFolder((Dictionary)o)); + foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i + inventory.Items.Add(BuildItem((Dictionary)o)); + } + catch (Exception e) + { + m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetFolderContent: {0}", e.Message); + } + + return inventory; + } + + public List GetFolderItems(UUID principalID, UUID folderID) + { + Dictionary ret = MakeRequest("GETFOLDERITEMS", + new Dictionary { + { "PRINCIPAL", principalID.ToString() }, + { "FOLDER", folderID.ToString() } + }); + + if (ret == null) + return null; + if (ret.Count == 0) + return null; + + Dictionary items = (Dictionary)ret["ITEMS"]; + List fitems = new List(); + foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i + fitems.Add(BuildItem((Dictionary)o)); + + return fitems; + } + + public bool AddFolder(InventoryFolderBase folder) + { + Dictionary ret = MakeRequest("ADDFOLDER", + new Dictionary { + { "ParentID", folder.ParentID.ToString() }, + { "Type", folder.Type.ToString() }, + { "Version", folder.Version.ToString() }, + { "Name", folder.Name.ToString() }, + { "Owner", folder.Owner.ToString() }, + { "ID", folder.ID.ToString() } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public bool UpdateFolder(InventoryFolderBase folder) + { + Dictionary ret = MakeRequest("UPDATEFOLDER", + new Dictionary { + { "ParentID", folder.ParentID.ToString() }, + { "Type", folder.Type.ToString() }, + { "Version", folder.Version.ToString() }, + { "Name", folder.Name.ToString() }, + { "Owner", folder.Owner.ToString() }, + { "ID", folder.ID.ToString() } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public bool MoveFolder(InventoryFolderBase folder) + { + Dictionary ret = MakeRequest("MOVEFOLDER", + new Dictionary { + { "ParentID", folder.ParentID.ToString() }, + { "ID", folder.ID.ToString() }, + { "PRINCIPAL", folder.Owner.ToString() } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public bool DeleteFolders(UUID principalID, List folderIDs) + { + List slist = new List(); + + foreach (UUID f in folderIDs) + slist.Add(f.ToString()); + + Dictionary ret = MakeRequest("DELETEFOLDERS", + new Dictionary { + { "PRINCIPAL", principalID.ToString() }, + { "FOLDERS", slist } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public bool PurgeFolder(InventoryFolderBase folder) + { + Dictionary ret = MakeRequest("PURGEFOLDER", + new Dictionary { + { "ID", folder.ID.ToString() } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public bool AddItem(InventoryItemBase item) + { + if (item.CreatorData == null) + item.CreatorData = String.Empty; + Dictionary ret = MakeRequest("ADDITEM", + new Dictionary { + { "AssetID", item.AssetID.ToString() }, + { "AssetType", item.AssetType.ToString() }, + { "Name", item.Name.ToString() }, + { "Owner", item.Owner.ToString() }, + { "ID", item.ID.ToString() }, + { "InvType", item.InvType.ToString() }, + { "Folder", item.Folder.ToString() }, + { "CreatorId", item.CreatorId.ToString() }, + { "CreatorData", item.CreatorData.ToString() }, + { "Description", item.Description.ToString() }, + { "NextPermissions", item.NextPermissions.ToString() }, + { "CurrentPermissions", item.CurrentPermissions.ToString() }, + { "BasePermissions", item.BasePermissions.ToString() }, + { "EveryOnePermissions", item.EveryOnePermissions.ToString() }, + { "GroupPermissions", item.GroupPermissions.ToString() }, + { "GroupID", item.GroupID.ToString() }, + { "GroupOwned", item.GroupOwned.ToString() }, + { "SalePrice", item.SalePrice.ToString() }, + { "SaleType", item.SaleType.ToString() }, + { "Flags", item.Flags.ToString() }, + { "CreationDate", item.CreationDate.ToString() } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public bool UpdateItem(InventoryItemBase item) + { + if (item.CreatorData == null) + item.CreatorData = String.Empty; + Dictionary ret = MakeRequest("UPDATEITEM", + new Dictionary { + { "AssetID", item.AssetID.ToString() }, + { "AssetType", item.AssetType.ToString() }, + { "Name", item.Name.ToString() }, + { "Owner", item.Owner.ToString() }, + { "ID", item.ID.ToString() }, + { "InvType", item.InvType.ToString() }, + { "Folder", item.Folder.ToString() }, + { "CreatorId", item.CreatorId.ToString() }, + { "CreatorData", item.CreatorData.ToString() }, + { "Description", item.Description.ToString() }, + { "NextPermissions", item.NextPermissions.ToString() }, + { "CurrentPermissions", item.CurrentPermissions.ToString() }, + { "BasePermissions", item.BasePermissions.ToString() }, + { "EveryOnePermissions", item.EveryOnePermissions.ToString() }, + { "GroupPermissions", item.GroupPermissions.ToString() }, + { "GroupID", item.GroupID.ToString() }, + { "GroupOwned", item.GroupOwned.ToString() }, + { "SalePrice", item.SalePrice.ToString() }, + { "SaleType", item.SaleType.ToString() }, + { "Flags", item.Flags.ToString() }, + { "CreationDate", item.CreationDate.ToString() } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public bool MoveItems(UUID principalID, List items) + { + List idlist = new List(); + List destlist = new List(); + + foreach (InventoryItemBase item in items) + { + idlist.Add(item.ID.ToString()); + destlist.Add(item.Folder.ToString()); + } + + Dictionary ret = MakeRequest("MOVEITEMS", + new Dictionary { + { "PRINCIPAL", principalID.ToString() }, + { "IDLIST", idlist }, + { "DESTLIST", destlist } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public bool DeleteItems(UUID principalID, List itemIDs) + { + List slist = new List(); + + foreach (UUID f in itemIDs) + slist.Add(f.ToString()); + + Dictionary ret = MakeRequest("DELETEITEMS", + new Dictionary { + { "PRINCIPAL", principalID.ToString() }, + { "ITEMS", slist } + }); + + if (ret == null) + return false; + + return bool.Parse(ret["RESULT"].ToString()); + } + + public InventoryItemBase GetItem(InventoryItemBase item) + { + try + { + Dictionary ret = MakeRequest("GETITEM", + new Dictionary { + { "ID", item.ID.ToString() } + }); + + if (ret == null) + return null; + if (ret.Count == 0) + return null; + + return BuildItem((Dictionary)ret["item"]); + } + catch (Exception e) + { + m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetItem: {0}", e.Message); + } + + return null; + } + + public InventoryFolderBase GetFolder(InventoryFolderBase folder) + { + try + { + Dictionary ret = MakeRequest("GETFOLDER", + new Dictionary { + { "ID", folder.ID.ToString() } + }); + + if (ret == null) + return null; + if (ret.Count == 0) + return null; + + return BuildFolder((Dictionary)ret["folder"]); + } + catch (Exception e) + { + m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetFolder: {0}", e.Message); + } + + return null; + } + + public List GetActiveGestures(UUID principalID) + { + Dictionary ret = MakeRequest("GETACTIVEGESTURES", + new Dictionary { + { "PRINCIPAL", principalID.ToString() } + }); + + if (ret == null) + return null; + + List items = new List(); + + foreach (Object o in ret.Values) // getting the values directly, we don't care about the keys item_i + items.Add(BuildItem((Dictionary)o)); + + return items; + } + + public int GetAssetPermissions(UUID principalID, UUID assetID) + { + Dictionary ret = MakeRequest("GETASSETPERMISSIONS", + new Dictionary { + { "PRINCIPAL", principalID.ToString() }, + { "ASSET", assetID.ToString() } + }); + + if (ret == null) + return 0; + + return int.Parse(ret["RESULT"].ToString()); + } + + public InventoryCollection GetUserInventory(UUID principalID) + { + InventoryCollection inventory = new InventoryCollection(); + inventory.Folders = new List(); + inventory.Items = new List(); + inventory.UserID = principalID; + + try + { + Dictionary ret = MakeRequest("GETUSERINVENTORY", + new Dictionary { + { "PRINCIPAL", principalID.ToString() } + }); + + if (ret == null) + return null; + if (ret.Count == 0) + return null; + + Dictionary folders = + (Dictionary)ret["FOLDERS"]; + Dictionary items = + (Dictionary)ret["ITEMS"]; + + foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i + inventory.Folders.Add(BuildFolder((Dictionary)o)); + foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i + inventory.Items.Add(BuildItem((Dictionary)o)); + } + catch (Exception e) + { + m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetUserInventory: {0}", e.Message); + } + + return inventory; + } + + public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback) + { + } + + public bool HasInventoryForUser(UUID principalID) + { + return false; + } + + // Helpers + // + private Dictionary MakeRequest(string method, + Dictionary sendData) + { + sendData["METHOD"] = method; + + string reply = string.Empty; + lock (m_Lock) + reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/xinventory", + ServerUtils.BuildQueryString(sendData)); + + Dictionary replyData = ServerUtils.ParseXmlResponse( + reply); + + return replyData; + } + + private InventoryFolderBase BuildFolder(Dictionary data) + { + InventoryFolderBase folder = new InventoryFolderBase(); + + try + { + folder.ParentID = new UUID(data["ParentID"].ToString()); + folder.Type = short.Parse(data["Type"].ToString()); + folder.Version = ushort.Parse(data["Version"].ToString()); + folder.Name = data["Name"].ToString(); + folder.Owner = new UUID(data["Owner"].ToString()); + folder.ID = new UUID(data["ID"].ToString()); + } + catch (Exception e) + { + m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception building folder: {0}", e.Message); + } + + return folder; + } + + private InventoryItemBase BuildItem(Dictionary data) + { + InventoryItemBase item = new InventoryItemBase(); + + try + { + item.AssetID = new UUID(data["AssetID"].ToString()); + item.AssetType = int.Parse(data["AssetType"].ToString()); + item.Name = data["Name"].ToString(); + item.Owner = new UUID(data["Owner"].ToString()); + item.ID = new UUID(data["ID"].ToString()); + item.InvType = int.Parse(data["InvType"].ToString()); + item.Folder = new UUID(data["Folder"].ToString()); + item.CreatorId = data["CreatorId"].ToString(); + if (data.ContainsKey("CreatorData")) + item.CreatorData = data["CreatorData"].ToString(); + else + item.CreatorData = String.Empty; + item.Description = data["Description"].ToString(); + item.NextPermissions = uint.Parse(data["NextPermissions"].ToString()); + item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString()); + item.BasePermissions = uint.Parse(data["BasePermissions"].ToString()); + item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString()); + item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString()); + item.GroupID = new UUID(data["GroupID"].ToString()); + item.GroupOwned = bool.Parse(data["GroupOwned"].ToString()); + item.SalePrice = int.Parse(data["SalePrice"].ToString()); + item.SaleType = byte.Parse(data["SaleType"].ToString()); + item.Flags = uint.Parse(data["Flags"].ToString()); + item.CreationDate = int.Parse(data["CreationDate"].ToString()); + } + catch (Exception e) + { + m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception building item: {0}", e.Message); + } + + return item; + } + + } +} diff --git a/OpenSim/Services/Connectors/Land/LandServiceConnector.cs b/OpenSim/Services/Connectors/Land/LandServiceConnector.cs deleted file mode 100644 index 30a73a4..0000000 --- a/OpenSim/Services/Connectors/Land/LandServiceConnector.cs +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using OpenMetaverse; -using Nwc.XmlRpc; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; - -namespace OpenSim.Services.Connectors -{ - public class LandServicesConnector : ILandService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - protected IGridService m_GridService = null; - - public LandServicesConnector() - { - } - - public LandServicesConnector(IGridService gridServices) - { - Initialise(gridServices); - } - - public virtual void Initialise(IGridService gridServices) - { - m_GridService = gridServices; - } - - public virtual LandData GetLandData(UUID scopeID, ulong regionHandle, uint x, uint y, out byte regionAccess) - { - LandData landData = null; - Hashtable hash = new Hashtable(); - hash["region_handle"] = regionHandle.ToString(); - hash["x"] = x.ToString(); - hash["y"] = y.ToString(); - - IList paramList = new ArrayList(); - paramList.Add(hash); - regionAccess = 42; // Default to adult. Better safe... - - try - { - uint xpos = 0, ypos = 0; - Utils.LongToUInts(regionHandle, out xpos, out ypos); - GridRegion info = m_GridService.GetRegionByPosition(scopeID, (int)xpos, (int)ypos); - if (info != null) // just to be sure - { - XmlRpcRequest request = new XmlRpcRequest("land_data", paramList); - XmlRpcResponse response = request.Send(info.ServerURI, 10000); - if (response.IsFault) - { - m_log.ErrorFormat("[LAND CONNECTOR]: remote call returned an error: {0}", response.FaultString); - } - else - { - hash = (Hashtable)response.Value; - try - { - landData = new LandData(); - landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]); - landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]); - landData.Area = Convert.ToInt32(hash["Area"]); - landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]); - landData.Description = (string)hash["Description"]; - landData.Flags = Convert.ToUInt32(hash["Flags"]); - landData.GlobalID = new UUID((string)hash["GlobalID"]); - landData.Name = (string)hash["Name"]; - landData.OwnerID = new UUID((string)hash["OwnerID"]); - landData.SalePrice = Convert.ToInt32(hash["SalePrice"]); - landData.SnapshotID = new UUID((string)hash["SnapshotID"]); - landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]); - if (hash["RegionAccess"] != null) - regionAccess = (byte)Convert.ToInt32((string)hash["RegionAccess"]); - m_log.DebugFormat("[LAND CONNECTOR]: Got land data for parcel {0}", landData.Name); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[LAND CONNECTOR]: Got exception while parsing land-data: {0} {1}", - e.Message, e.StackTrace); - } - } - } - else - m_log.WarnFormat("[LAND CONNECTOR]: Couldn't find region with handle {0}", regionHandle); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[LAND CONNECTOR]: Couldn't contact region {0}: {1} {2}", regionHandle, e.Message, e.StackTrace); - } - - return landData; - } - } -} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Land/LandServicesConnector.cs b/OpenSim/Services/Connectors/Land/LandServicesConnector.cs new file mode 100644 index 0000000..30a73a4 --- /dev/null +++ b/OpenSim/Services/Connectors/Land/LandServicesConnector.cs @@ -0,0 +1,133 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using OpenMetaverse; +using Nwc.XmlRpc; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; + +namespace OpenSim.Services.Connectors +{ + public class LandServicesConnector : ILandService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + protected IGridService m_GridService = null; + + public LandServicesConnector() + { + } + + public LandServicesConnector(IGridService gridServices) + { + Initialise(gridServices); + } + + public virtual void Initialise(IGridService gridServices) + { + m_GridService = gridServices; + } + + public virtual LandData GetLandData(UUID scopeID, ulong regionHandle, uint x, uint y, out byte regionAccess) + { + LandData landData = null; + Hashtable hash = new Hashtable(); + hash["region_handle"] = regionHandle.ToString(); + hash["x"] = x.ToString(); + hash["y"] = y.ToString(); + + IList paramList = new ArrayList(); + paramList.Add(hash); + regionAccess = 42; // Default to adult. Better safe... + + try + { + uint xpos = 0, ypos = 0; + Utils.LongToUInts(regionHandle, out xpos, out ypos); + GridRegion info = m_GridService.GetRegionByPosition(scopeID, (int)xpos, (int)ypos); + if (info != null) // just to be sure + { + XmlRpcRequest request = new XmlRpcRequest("land_data", paramList); + XmlRpcResponse response = request.Send(info.ServerURI, 10000); + if (response.IsFault) + { + m_log.ErrorFormat("[LAND CONNECTOR]: remote call returned an error: {0}", response.FaultString); + } + else + { + hash = (Hashtable)response.Value; + try + { + landData = new LandData(); + landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]); + landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]); + landData.Area = Convert.ToInt32(hash["Area"]); + landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]); + landData.Description = (string)hash["Description"]; + landData.Flags = Convert.ToUInt32(hash["Flags"]); + landData.GlobalID = new UUID((string)hash["GlobalID"]); + landData.Name = (string)hash["Name"]; + landData.OwnerID = new UUID((string)hash["OwnerID"]); + landData.SalePrice = Convert.ToInt32(hash["SalePrice"]); + landData.SnapshotID = new UUID((string)hash["SnapshotID"]); + landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]); + if (hash["RegionAccess"] != null) + regionAccess = (byte)Convert.ToInt32((string)hash["RegionAccess"]); + m_log.DebugFormat("[LAND CONNECTOR]: Got land data for parcel {0}", landData.Name); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[LAND CONNECTOR]: Got exception while parsing land-data: {0} {1}", + e.Message, e.StackTrace); + } + } + } + else + m_log.WarnFormat("[LAND CONNECTOR]: Couldn't find region with handle {0}", regionHandle); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[LAND CONNECTOR]: Couldn't contact region {0}: {1} {2}", regionHandle, e.Message, e.StackTrace); + } + + return landData; + } + } +} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs b/OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs deleted file mode 100644 index 30bfb70..0000000 --- a/OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Reflection; - -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Console; -using OpenSim.Framework.Communications; -using OpenSim.Server.Base; -using OpenSim.Services.Interfaces; -using OpenMetaverse; -using OpenMetaverse.StructuredData; - -namespace OpenSim.Services.Connectors -{ - public class MapImageServicesConnector : IMapImageService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public MapImageServicesConnector() - { - } - - public MapImageServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public MapImageServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig config = source.Configs["MapImageService"]; - if (config == null) - { - m_log.Error("[MAP IMAGE CONNECTOR]: MapImageService missing"); - throw new Exception("MapImage connector init error"); - } - - string serviceURI = config.GetString("MapImageServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[MAP IMAGE CONNECTOR]: No Server URI named in section MapImageService"); - throw new Exception("MapImage connector init error"); - } - m_ServerURI = serviceURI; - m_ServerURI = serviceURI.TrimEnd('/'); - } - - public bool AddMapTile(int x, int y, byte[] jpgData, out string reason) - { - reason = string.Empty; - int tickstart = Util.EnvironmentTickCount(); - Dictionary sendData = new Dictionary(); - sendData["X"] = x.ToString(); - sendData["Y"] = y.ToString(); - sendData["TYPE"] = "image/jpeg"; - sendData["DATA"] = Convert.ToBase64String(jpgData); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/map"; - - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "success")) - { - return true; - } - else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure")) - { - m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Registration failed: {0}", replyData["Message"].ToString()); - reason = replyData["Message"].ToString(); - return false; - } - else if (!replyData.ContainsKey("Result")) - { - m_log.DebugFormat("[MAP IMAGE CONNECTOR]: reply data does not contain result field"); - } - else - { - m_log.DebugFormat("[MAP IMAGE CONNECTOR]: unexpected result {0}", replyData["Result"].ToString()); - reason = "Unexpected result " + replyData["Result"].ToString(); - } - - } - else - { - m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Map post received null reply"); - } - } - catch (Exception e) - { - m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Exception when contacting map server at {0}: {1}", uri, e.Message); - } - finally - { - // This just dumps a warning for any operation that takes more than 100 ms - int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); - m_log.DebugFormat("[MAP IMAGE CONNECTOR]: map tile uploaded in {0}ms", tickdiff); - } - - return false; - - } - - public byte[] GetMapTile(string fileName, out string format) - { - format = string.Empty; - new Exception("GetMapTile method not Implemented"); - return null; - } - } -} diff --git a/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs b/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs new file mode 100644 index 0000000..30bfb70 --- /dev/null +++ b/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs @@ -0,0 +1,159 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Reflection; + +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Console; +using OpenSim.Framework.Communications; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +namespace OpenSim.Services.Connectors +{ + public class MapImageServicesConnector : IMapImageService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public MapImageServicesConnector() + { + } + + public MapImageServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public MapImageServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig config = source.Configs["MapImageService"]; + if (config == null) + { + m_log.Error("[MAP IMAGE CONNECTOR]: MapImageService missing"); + throw new Exception("MapImage connector init error"); + } + + string serviceURI = config.GetString("MapImageServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[MAP IMAGE CONNECTOR]: No Server URI named in section MapImageService"); + throw new Exception("MapImage connector init error"); + } + m_ServerURI = serviceURI; + m_ServerURI = serviceURI.TrimEnd('/'); + } + + public bool AddMapTile(int x, int y, byte[] jpgData, out string reason) + { + reason = string.Empty; + int tickstart = Util.EnvironmentTickCount(); + Dictionary sendData = new Dictionary(); + sendData["X"] = x.ToString(); + sendData["Y"] = y.ToString(); + sendData["TYPE"] = "image/jpeg"; + sendData["DATA"] = Convert.ToBase64String(jpgData); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/map"; + + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "success")) + { + return true; + } + else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure")) + { + m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Registration failed: {0}", replyData["Message"].ToString()); + reason = replyData["Message"].ToString(); + return false; + } + else if (!replyData.ContainsKey("Result")) + { + m_log.DebugFormat("[MAP IMAGE CONNECTOR]: reply data does not contain result field"); + } + else + { + m_log.DebugFormat("[MAP IMAGE CONNECTOR]: unexpected result {0}", replyData["Result"].ToString()); + reason = "Unexpected result " + replyData["Result"].ToString(); + } + + } + else + { + m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Map post received null reply"); + } + } + catch (Exception e) + { + m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Exception when contacting map server at {0}: {1}", uri, e.Message); + } + finally + { + // This just dumps a warning for any operation that takes more than 100 ms + int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); + m_log.DebugFormat("[MAP IMAGE CONNECTOR]: map tile uploaded in {0}ms", tickdiff); + } + + return false; + + } + + public byte[] GetMapTile(string fileName, out string format) + { + format = string.Empty; + new Exception("GetMapTile method not Implemented"); + return null; + } + } +} diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs deleted file mode 100644 index 888b072..0000000 --- a/OpenSim/Services/Connectors/Neighbour/NeighbourServiceConnector.cs +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Reflection; -using System.Text; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using OpenMetaverse; -using OpenMetaverse.StructuredData; - -using GridRegion = OpenSim.Services.Interfaces.GridRegion; - -namespace OpenSim.Services.Connectors -{ - public class NeighbourServicesConnector : INeighbourService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - protected IGridService m_GridService = null; - - public NeighbourServicesConnector() - { - } - - public NeighbourServicesConnector(IGridService gridServices) - { - Initialise(gridServices); - } - - public virtual void Initialise(IGridService gridServices) - { - m_GridService = gridServices; - } - - public virtual GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion) - { - uint x = 0, y = 0; - Utils.LongToUInts(regionHandle, out x, out y); - GridRegion regInfo = m_GridService.GetRegionByPosition(thisRegion.ScopeID, (int)x, (int)y); - if ((regInfo != null) && - // Don't remote-call this instance; that's a startup hickup - !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort))) - { - if (!DoHelloNeighbourCall(regInfo, thisRegion)) - return null; - } - else - return null; - - return regInfo; - } - - public bool DoHelloNeighbourCall(GridRegion region, RegionInfo thisRegion) - { - string uri = region.ServerURI + "region/" + thisRegion.RegionID + "/"; -// m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); - - WebRequest helloNeighbourRequest; - - try - { - helloNeighbourRequest = WebRequest.Create(uri); - } - catch (Exception e) - { - m_log.WarnFormat( - "[NEIGHBOUR SERVICE CONNCTOR]: Unable to parse uri {0} to send HelloNeighbour from {1} to {2}. Exception {3}{4}", - uri, thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); - - return false; - } - - helloNeighbourRequest.Method = "POST"; - helloNeighbourRequest.ContentType = "application/json"; - helloNeighbourRequest.Timeout = 10000; - - // Fill it in - OSDMap args = null; - try - { - args = thisRegion.PackRegionInfoData(); - } - catch (Exception e) - { - m_log.WarnFormat( - "[NEIGHBOUR SERVICE CONNCTOR]: PackRegionInfoData failed for HelloNeighbour from {0} to {1}. Exception {2}{3}", - thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); - - return false; - } - - // Add the regionhandle of the destination region - args["destination_handle"] = OSD.FromString(region.RegionHandle.ToString()); - - string strBuffer = ""; - byte[] buffer = new byte[1]; - - try - { - strBuffer = OSDParser.SerializeJsonString(args); - UTF8Encoding str = new UTF8Encoding(); - buffer = str.GetBytes(strBuffer); - } - catch (Exception e) - { - m_log.WarnFormat( - "[NEIGHBOUR SERVICE CONNCTOR]: Exception thrown on serialization of HelloNeighbour from {0} to {1}. Exception {2}{3}", - thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); - - return false; - } - - Stream os = null; - try - { // send the Post - helloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send - os = helloNeighbourRequest.GetRequestStream(); - os.Write(buffer, 0, strBuffer.Length); //Send it - //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri); - } - catch (Exception e) - { - m_log.WarnFormat( - "[NEIGHBOUR SERVICE CONNCTOR]: Unable to send HelloNeighbour from {0} to {1}. Exception {2}{3}", - thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); - - return false; - } - finally - { - if (os != null) - os.Close(); - } - - // Let's wait for the response - //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); - - StreamReader sr = null; - try - { - WebResponse webResponse = helloNeighbourRequest.GetResponse(); - if (webResponse == null) - { - m_log.DebugFormat( - "[REST COMMS]: Null reply on DoHelloNeighbourCall post from {0} to {1}", - thisRegion.RegionName, region.RegionName); - } - - sr = new StreamReader(webResponse.GetResponseStream()); - //reply = sr.ReadToEnd().Trim(); - sr.ReadToEnd().Trim(); - //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); - - } - catch (Exception e) - { - m_log.WarnFormat( - "[NEIGHBOUR SERVICE CONNCTOR]: Exception on reply of DoHelloNeighbourCall from {0} back to {1}. Exception {2}{3}", - region.RegionName, thisRegion.RegionName, e.Message, e.StackTrace); - - return false; - } - finally - { - if (sr != null) - sr.Close(); - } - - return true; - } - } -} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs new file mode 100644 index 0000000..888b072 --- /dev/null +++ b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs @@ -0,0 +1,206 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Reflection; +using System.Text; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +using GridRegion = OpenSim.Services.Interfaces.GridRegion; + +namespace OpenSim.Services.Connectors +{ + public class NeighbourServicesConnector : INeighbourService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + protected IGridService m_GridService = null; + + public NeighbourServicesConnector() + { + } + + public NeighbourServicesConnector(IGridService gridServices) + { + Initialise(gridServices); + } + + public virtual void Initialise(IGridService gridServices) + { + m_GridService = gridServices; + } + + public virtual GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion) + { + uint x = 0, y = 0; + Utils.LongToUInts(regionHandle, out x, out y); + GridRegion regInfo = m_GridService.GetRegionByPosition(thisRegion.ScopeID, (int)x, (int)y); + if ((regInfo != null) && + // Don't remote-call this instance; that's a startup hickup + !((regInfo.ExternalHostName == thisRegion.ExternalHostName) && (regInfo.HttpPort == thisRegion.HttpPort))) + { + if (!DoHelloNeighbourCall(regInfo, thisRegion)) + return null; + } + else + return null; + + return regInfo; + } + + public bool DoHelloNeighbourCall(GridRegion region, RegionInfo thisRegion) + { + string uri = region.ServerURI + "region/" + thisRegion.RegionID + "/"; +// m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri); + + WebRequest helloNeighbourRequest; + + try + { + helloNeighbourRequest = WebRequest.Create(uri); + } + catch (Exception e) + { + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: Unable to parse uri {0} to send HelloNeighbour from {1} to {2}. Exception {3}{4}", + uri, thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); + + return false; + } + + helloNeighbourRequest.Method = "POST"; + helloNeighbourRequest.ContentType = "application/json"; + helloNeighbourRequest.Timeout = 10000; + + // Fill it in + OSDMap args = null; + try + { + args = thisRegion.PackRegionInfoData(); + } + catch (Exception e) + { + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: PackRegionInfoData failed for HelloNeighbour from {0} to {1}. Exception {2}{3}", + thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); + + return false; + } + + // Add the regionhandle of the destination region + args["destination_handle"] = OSD.FromString(region.RegionHandle.ToString()); + + string strBuffer = ""; + byte[] buffer = new byte[1]; + + try + { + strBuffer = OSDParser.SerializeJsonString(args); + UTF8Encoding str = new UTF8Encoding(); + buffer = str.GetBytes(strBuffer); + } + catch (Exception e) + { + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: Exception thrown on serialization of HelloNeighbour from {0} to {1}. Exception {2}{3}", + thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); + + return false; + } + + Stream os = null; + try + { // send the Post + helloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send + os = helloNeighbourRequest.GetRequestStream(); + os.Write(buffer, 0, strBuffer.Length); //Send it + //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri); + } + catch (Exception e) + { + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: Unable to send HelloNeighbour from {0} to {1}. Exception {2}{3}", + thisRegion.RegionName, region.RegionName, e.Message, e.StackTrace); + + return false; + } + finally + { + if (os != null) + os.Close(); + } + + // Let's wait for the response + //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); + + StreamReader sr = null; + try + { + WebResponse webResponse = helloNeighbourRequest.GetResponse(); + if (webResponse == null) + { + m_log.DebugFormat( + "[REST COMMS]: Null reply on DoHelloNeighbourCall post from {0} to {1}", + thisRegion.RegionName, region.RegionName); + } + + sr = new StreamReader(webResponse.GetResponseStream()); + //reply = sr.ReadToEnd().Trim(); + sr.ReadToEnd().Trim(); + //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); + + } + catch (Exception e) + { + m_log.WarnFormat( + "[NEIGHBOUR SERVICE CONNCTOR]: Exception on reply of DoHelloNeighbourCall from {0} back to {1}. Exception {2}{3}", + region.RegionName, thisRegion.RegionName, e.Message, e.StackTrace); + + return false; + } + finally + { + if (sr != null) + sr.Close(); + } + + return true; + } + } +} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs deleted file mode 100644 index f7d8c53..0000000 --- a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs +++ /dev/null @@ -1,378 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Services.Interfaces; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; -using OpenSim.Server.Base; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class PresenceServicesConnector : IPresenceService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public PresenceServicesConnector() - { - } - - public PresenceServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public PresenceServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig gridConfig = source.Configs["PresenceService"]; - if (gridConfig == null) - { - m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini"); - throw new Exception("Presence connector init error"); - } - - string serviceURI = gridConfig.GetString("PresenceServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService"); - throw new Exception("Presence connector init error"); - } - m_ServerURI = serviceURI; - } - - - #region IPresenceService - - public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "login"; - - sendData["UserID"] = userID; - sendData["SessionID"] = sessionID.ToString(); - sendData["SecureSessionID"] = secureSessionID.ToString(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/presence"; - // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field"); - - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - return false; - - } - - public bool LogoutAgent(UUID sessionID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "logout"; - - sendData["SessionID"] = sessionID.ToString(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/presence"; - // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field"); - - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - return false; - } - - public bool LogoutRegionAgents(UUID regionID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "logoutregion"; - - sendData["RegionID"] = regionID.ToString(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/presence"; - // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field"); - - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - return false; - } - - public bool ReportAgent(UUID sessionID, UUID regionID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "report"; - - sendData["SessionID"] = sessionID.ToString(); - sendData["RegionID"] = regionID.ToString(); - - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/presence"; - // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field"); - - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - return false; - } - - public PresenceInfo GetAgent(UUID sessionID) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getagent"; - - sendData["SessionID"] = sessionID.ToString(); - - string reply = string.Empty; - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/presence"; - // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply == null || (reply != null && reply == string.Empty)) - { - m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); - return null; - } - } - catch (Exception e) - { - m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - PresenceInfo pinfo = null; - - if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - { - pinfo = new PresenceInfo((Dictionary)replyData["result"]); - } - } - - return pinfo; - } - - public PresenceInfo[] GetAgents(string[] userIDs) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getagents"; - - sendData["uuids"] = new List(userIDs); - - string reply = string.Empty; - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/presence"; - //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply == null || (reply != null && reply == string.Empty)) - { - m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null or empty reply"); - return null; - } - } - catch (Exception e) - { - m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); - } - - List rinfos = new List(); - - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - if (replyData.ContainsKey("result") && - (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) - { - return new PresenceInfo[0]; - } - - Dictionary.ValueCollection pinfosList = replyData.Values; - //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); - foreach (object presence in pinfosList) - { - if (presence is Dictionary) - { - PresenceInfo pinfo = new PresenceInfo((Dictionary)presence); - rinfos.Add(pinfo); - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}", - presence.GetType()); - } - } - else - m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response"); - - return rinfos.ToArray(); - } - - - #endregion - - } -} diff --git a/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs new file mode 100644 index 0000000..f7d8c53 --- /dev/null +++ b/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs @@ -0,0 +1,378 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using OpenSim.Server.Base; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class PresenceServicesConnector : IPresenceService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public PresenceServicesConnector() + { + } + + public PresenceServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public PresenceServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig gridConfig = source.Configs["PresenceService"]; + if (gridConfig == null) + { + m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini"); + throw new Exception("Presence connector init error"); + } + + string serviceURI = gridConfig.GetString("PresenceServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService"); + throw new Exception("Presence connector init error"); + } + m_ServerURI = serviceURI; + } + + + #region IPresenceService + + public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "login"; + + sendData["UserID"] = userID; + sendData["SessionID"] = sessionID.ToString(); + sendData["SecureSessionID"] = secureSessionID.ToString(); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/presence"; + // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field"); + + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + return false; + + } + + public bool LogoutAgent(UUID sessionID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "logout"; + + sendData["SessionID"] = sessionID.ToString(); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/presence"; + // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field"); + + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + return false; + } + + public bool LogoutRegionAgents(UUID regionID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "logoutregion"; + + sendData["RegionID"] = regionID.ToString(); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/presence"; + // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field"); + + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + return false; + } + + public bool ReportAgent(UUID sessionID, UUID regionID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "report"; + + sendData["SessionID"] = sessionID.ToString(); + sendData["RegionID"] = regionID.ToString(); + + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/presence"; + // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field"); + + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + return false; + } + + public PresenceInfo GetAgent(UUID sessionID) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getagent"; + + sendData["SessionID"] = sessionID.ToString(); + + string reply = string.Empty; + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/presence"; + // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply == null || (reply != null && reply == string.Empty)) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); + return null; + } + } + catch (Exception e) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + PresenceInfo pinfo = null; + + if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) + { + if (replyData["result"] is Dictionary) + { + pinfo = new PresenceInfo((Dictionary)replyData["result"]); + } + } + + return pinfo; + } + + public PresenceInfo[] GetAgents(string[] userIDs) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getagents"; + + sendData["uuids"] = new List(userIDs); + + string reply = string.Empty; + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/presence"; + //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply == null || (reply != null && reply == string.Empty)) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null or empty reply"); + return null; + } + } + catch (Exception e) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message); + } + + List rinfos = new List(); + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + if (replyData.ContainsKey("result") && + (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) + { + return new PresenceInfo[0]; + } + + Dictionary.ValueCollection pinfosList = replyData.Values; + //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); + foreach (object presence in pinfosList) + { + if (presence is Dictionary) + { + PresenceInfo pinfo = new PresenceInfo((Dictionary)presence); + rinfos.Add(pinfo); + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}", + presence.GetType()); + } + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response"); + + return rinfos.ToArray(); + } + + + #endregion + + } +} diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs deleted file mode 100644 index 6d5ce28..0000000 --- a/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs +++ /dev/null @@ -1,287 +0,0 @@ -/* - * 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 OpenSimulator 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 log4net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Server.Base; -using OpenSim.Services.Interfaces; -using OpenMetaverse; - -namespace OpenSim.Services.Connectors -{ - public class UserAccountServicesConnector : IUserAccountService - { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); - - private string m_ServerURI = String.Empty; - - public UserAccountServicesConnector() - { - } - - public UserAccountServicesConnector(string serverURI) - { - m_ServerURI = serverURI.TrimEnd('/'); - } - - public UserAccountServicesConnector(IConfigSource source) - { - Initialise(source); - } - - public virtual void Initialise(IConfigSource source) - { - IConfig assetConfig = source.Configs["UserAccountService"]; - if (assetConfig == null) - { - m_log.Error("[ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini"); - throw new Exception("User account connector init error"); - } - - string serviceURI = assetConfig.GetString("UserAccountServerURI", - String.Empty); - - if (serviceURI == String.Empty) - { - m_log.Error("[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService"); - throw new Exception("User account connector init error"); - } - m_ServerURI = serviceURI; - } - - public virtual UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getaccount"; - - sendData["ScopeID"] = scopeID; - sendData["FirstName"] = firstName.ToString(); - sendData["LastName"] = lastName.ToString(); - - return SendAndGetReply(sendData); - } - - public virtual UserAccount GetUserAccount(UUID scopeID, string email) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getaccount"; - - sendData["ScopeID"] = scopeID; - sendData["Email"] = email; - - return SendAndGetReply(sendData); - } - - public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID) - { - //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccount {0}", userID); - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getaccount"; - - sendData["ScopeID"] = scopeID; - sendData["UserID"] = userID.ToString(); - - return SendAndGetReply(sendData); - } - - public List GetUserAccounts(UUID scopeID, string query) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "getaccounts"; - - sendData["ScopeID"] = scopeID.ToString(); - sendData["query"] = query; - - string reply = string.Empty; - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/accounts"; - // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply == null || (reply != null && reply == string.Empty)) - { - m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received null or empty reply"); - return null; - } - } - catch (Exception e) - { - m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message); - } - - List accounts = new List(); - - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData != null) - { - if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null") - { - return accounts; - } - - Dictionary.ValueCollection accountList = replyData.Values; - //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); - foreach (object acc in accountList) - { - if (acc is Dictionary) - { - UserAccount pinfo = new UserAccount((Dictionary)acc); - accounts.Add(pinfo); - } - else - m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}", - acc.GetType()); - } - } - else - m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccounts received null response"); - - return accounts; - } - - public virtual bool StoreUserAccount(UserAccount data) - { - Dictionary sendData = new Dictionary(); - //sendData["SCOPEID"] = scopeID.ToString(); - sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); - sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); - sendData["METHOD"] = "setaccount"; - - Dictionary structData = data.ToKeyValuePairs(); - - foreach (KeyValuePair kvp in structData) - { - if (kvp.Value == null) - { - m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Null value for {0}", kvp.Key); - continue; - } - sendData[kvp.Key] = kvp.Value.ToString(); - } - - return SendAndGetBoolReply(sendData); - } - - private UserAccount SendAndGetReply(Dictionary sendData) - { - string reply = string.Empty; - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/accounts"; - // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); - try - { - reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply == null || (reply != null && reply == string.Empty)) - { - m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccount received null or empty reply"); - return null; - } - } - catch (Exception e) - { - m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message); - } - - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - UserAccount account = null; - - if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) - { - if (replyData["result"] is Dictionary) - { - account = new UserAccount((Dictionary)replyData["result"]); - } - } - - return account; - - } - - private bool SendAndGetBoolReply(Dictionary sendData) - { - string reqString = ServerUtils.BuildQueryString(sendData); - string uri = m_ServerURI + "/accounts"; - // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); - try - { - string reply = SynchronousRestFormsRequester.MakeRequest("POST", - uri, - reqString); - if (reply != string.Empty) - { - Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - - if (replyData.ContainsKey("result")) - { - if (replyData["result"].ToString().ToLower() == "success") - return true; - else - return false; - } - else - m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field"); - - } - else - m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply"); - } - catch (Exception e) - { - m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message); - } - - return false; - } - - } -} diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs new file mode 100644 index 0000000..6d5ce28 --- /dev/null +++ b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs @@ -0,0 +1,287 @@ +/* + * 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 OpenSimulator 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 log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + +namespace OpenSim.Services.Connectors +{ + public class UserAccountServicesConnector : IUserAccountService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private string m_ServerURI = String.Empty; + + public UserAccountServicesConnector() + { + } + + public UserAccountServicesConnector(string serverURI) + { + m_ServerURI = serverURI.TrimEnd('/'); + } + + public UserAccountServicesConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig assetConfig = source.Configs["UserAccountService"]; + if (assetConfig == null) + { + m_log.Error("[ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini"); + throw new Exception("User account connector init error"); + } + + string serviceURI = assetConfig.GetString("UserAccountServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService"); + throw new Exception("User account connector init error"); + } + m_ServerURI = serviceURI; + } + + public virtual UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getaccount"; + + sendData["ScopeID"] = scopeID; + sendData["FirstName"] = firstName.ToString(); + sendData["LastName"] = lastName.ToString(); + + return SendAndGetReply(sendData); + } + + public virtual UserAccount GetUserAccount(UUID scopeID, string email) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getaccount"; + + sendData["ScopeID"] = scopeID; + sendData["Email"] = email; + + return SendAndGetReply(sendData); + } + + public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID) + { + //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccount {0}", userID); + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getaccount"; + + sendData["ScopeID"] = scopeID; + sendData["UserID"] = userID.ToString(); + + return SendAndGetReply(sendData); + } + + public List GetUserAccounts(UUID scopeID, string query) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getaccounts"; + + sendData["ScopeID"] = scopeID.ToString(); + sendData["query"] = query; + + string reply = string.Empty; + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/accounts"; + // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply == null || (reply != null && reply == string.Empty)) + { + m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received null or empty reply"); + return null; + } + } + catch (Exception e) + { + m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message); + } + + List accounts = new List(); + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null") + { + return accounts; + } + + Dictionary.ValueCollection accountList = replyData.Values; + //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); + foreach (object acc in accountList) + { + if (acc is Dictionary) + { + UserAccount pinfo = new UserAccount((Dictionary)acc); + accounts.Add(pinfo); + } + else + m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}", + acc.GetType()); + } + } + else + m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccounts received null response"); + + return accounts; + } + + public virtual bool StoreUserAccount(UserAccount data) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "setaccount"; + + Dictionary structData = data.ToKeyValuePairs(); + + foreach (KeyValuePair kvp in structData) + { + if (kvp.Value == null) + { + m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Null value for {0}", kvp.Key); + continue; + } + sendData[kvp.Key] = kvp.Value.ToString(); + } + + return SendAndGetBoolReply(sendData); + } + + private UserAccount SendAndGetReply(Dictionary sendData) + { + string reply = string.Empty; + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/accounts"; + // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply == null || (reply != null && reply == string.Empty)) + { + m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccount received null or empty reply"); + return null; + } + } + catch (Exception e) + { + m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message); + } + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + UserAccount account = null; + + if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) + { + if (replyData["result"] is Dictionary) + { + account = new UserAccount((Dictionary)replyData["result"]); + } + } + + return account; + + } + + private bool SendAndGetBoolReply(Dictionary sendData) + { + string reqString = ServerUtils.BuildQueryString(sendData); + string uri = m_ServerURI + "/accounts"; + // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("result")) + { + if (replyData["result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field"); + + } + else + m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user accounts server at {0}: {1}", uri, e.Message); + } + + return false; + } + + } +} -- cgit v1.1 From bc543c1797c629a8584dd2e74d3c5f7a67de96c9 Mon Sep 17 00:00:00 2001 From: PixelTomsen Date: Wed, 23 May 2012 21:06:25 +0200 Subject: Environment Module - allows Environment settings for Viewer3 warning: includes database region store migrations for mssql, mysql, sqlite enable/disable this module: Cap_EnvironmentSettings = "localhost" (for enable) Cap_EnvironmentSettings = "" (for disable) at ClientStack.LindenCaps section (OpenSimDefaults.ini file) or owerwrite in OpenSim.ini mantis: http://opensimulator.org/mantis/view.php?id=5860 Signed-off-by: BlueWall --- .../Connectors/Simulation/SimulationDataService.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs b/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs index ccef50b..c9cbbfa 100644 --- a/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs +++ b/OpenSim/Services/Connectors/Simulation/SimulationDataService.cs @@ -148,5 +148,21 @@ namespace OpenSim.Services.Connectors { m_database.RemoveRegionWindlightSettings(regionID); } + + public string LoadRegionEnvironmentSettings(UUID regionUUID) + { + return m_database.LoadRegionEnvironmentSettings(regionUUID); + } + + public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings) + { + m_database.StoreRegionEnvironmentSettings(regionUUID, settings); + } + + public void RemoveRegionEnvironmentSettings(UUID regionUUID) + { + m_database.RemoveRegionEnvironmentSettings(regionUUID); + } + } } -- cgit v1.1 From 38ce9d45a523db277d3eb4d3ed310b7cd9ca6b43 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 24 May 2012 01:00:18 +0100 Subject: Make ISimulationScene.GetScene() used the more efficient region id for lookup rather than the region handle. --- OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs index cb003d1..cc46ba8 100644 --- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs @@ -62,7 +62,7 @@ namespace OpenSim.Services.Connectors.Simulation //m_Region = region; } - public IScene GetScene(ulong regionHandle) + public IScene GetScene(UUID regionId) { return null; } -- cgit v1.1 From 7cceab12956dcb8ebeff129375888541831f7976 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 25 May 2012 01:41:00 +0100 Subject: In remote QueryAccess, also receive the actual status (true|false) instead of always true no matter what the callee actually returned. This was due to two things 1) SimulationServiceConnector.QueryAccess was always looking to the outer result["success"]. But if a "_Result" map is returned (which is certainly the case right now), then the true success is _Result["success"], result["success"] is always true no matter what 2) If QueryAccess was false at the destination, then AgentHandlers.DoQueryAccess() was never putting this in the result. The default action of SerializeJsonString() is not to put false booleans in the JSON!!!, so this has to be explicitly set. --- OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs index cc46ba8..032beb5 100644 --- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs @@ -320,6 +320,10 @@ namespace OpenSim.Services.Connectors.Simulation { OSDMap data = (OSDMap)result["_Result"]; + // FIXME: If there is a _Result map then it's the success key here that indicates the true success + // or failure, not the sibling result node. + success = data["success"]; + reason = data["reason"].AsString(); if (data["version"] != null && data["version"].AsString() != string.Empty) version = data["version"].AsString(); -- cgit v1.1 From 96cde407ab0d40856fb10b3b9f304433ffe734a2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 25 May 2012 02:37:22 +0100 Subject: Fix bug where a failed QueryAccess to a remove region would always have the reason "Communications failure" no matter what the destination region actually returned --- .../Simulation/SimulationServiceConnector.cs | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs index 032beb5..95c4f87 100644 --- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs @@ -328,25 +328,32 @@ namespace OpenSim.Services.Connectors.Simulation if (data["version"] != null && data["version"].AsString() != string.Empty) version = data["version"].AsString(); - m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: QueryAccess to {0} returned {1} version {2} ({3})", uri, success, version, data["version"].AsString()); + m_log.DebugFormat( + "[REMOTE SIMULATION CONNECTOR]: QueryAccess to {0} returned {1}, reason {2}, version {3} ({4})", + uri, success, reason, version, data["version"].AsString()); } if (!success) { - if (result.ContainsKey("Message")) + // If we don't check this then OpenSimulator 0.7.3.1 and some period before will never see the + // actual failure message + if (!result.ContainsKey("_Result")) { - string message = result["Message"].AsString(); - if (message == "Service request failed: [MethodNotAllowed] MethodNotAllowed") // Old style region + if (result.ContainsKey("Message")) { - m_log.Info("[REMOTE SIMULATION CONNECTOR]: The above web util error was caused by a TP to a sim that doesn't support QUERYACCESS and can be ignored"); - return true; + string message = result["Message"].AsString(); + if (message == "Service request failed: [MethodNotAllowed] MethodNotAllowed") // Old style region + { + m_log.Info("[REMOTE SIMULATION CONNECTOR]: The above web util error was caused by a TP to a sim that doesn't support QUERYACCESS and can be ignored"); + return true; + } + + reason = result["Message"]; + } + else + { + reason = "Communications failure"; } - - reason = result["Message"]; - } - else - { - reason = "Communications failure"; } return false; @@ -356,7 +363,7 @@ namespace OpenSim.Services.Connectors.Simulation } catch (Exception e) { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] QueryAcess failed with exception; {0}",e.ToString()); + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] QueryAcesss failed with exception; {0}",e.ToString()); } return false; -- cgit v1.1 From 1b1f0a2d77fb4d2ac572f16c71a7560860c8c040 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 12 Jun 2012 02:43:33 +0100 Subject: OnConnectionClosed listeners, retrieve data from IClientAPI.SceneAgent rather than scanning all scene for the presence with the right id Stop checking IsLoggingOut on these listeners, if called with a root agent then we always want to perform these actions. This covers cases where the client is closed due to manual kick, simulator shutdown, etc. --- .../SimianGrid/SimianActivityDetector.cs | 28 ++++++---------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs index 2267325..95e4bab 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs @@ -79,27 +79,13 @@ namespace OpenSim.Services.Connectors.SimianGrid public void OnConnectionClose(IClientAPI client) { - if (client.IsLoggingOut) - { - object sp = null; - Vector3 position = new Vector3(128, 128, 0); - Vector3 lookat = new Vector3(0, 1, 0); - - if (client.Scene.TryGetScenePresence(client.AgentId, out sp)) - { - if (sp is ScenePresence) - { - if (((ScenePresence)sp).IsChildAgent) - return; - - position = ((ScenePresence)sp).AbsolutePosition; - lookat = ((ScenePresence)sp).Lookat; - } - } + if (client.SceneAgent.IsChildAgent) + return; -// m_log.DebugFormat("[SIMIAN ACTIVITY DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName); - m_GridUserService.LoggedOut(client.AgentId.ToString(), client.SessionId, client.Scene.RegionInfo.RegionID, position, lookat); - } +// m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName); + m_GridUserService.LoggedOut( + client.AgentId.ToString(), client.SessionId, client.Scene.RegionInfo.RegionID, + client.SceneAgent.AbsolutePosition, client.SceneAgent.Lookat); } void OnEnteringNewParcel(ScenePresence sp, int localLandID, UUID regionID) @@ -111,4 +97,4 @@ namespace OpenSim.Services.Connectors.SimianGrid }); } } -} +} \ No newline at end of file -- cgit v1.1 From 884d603cac6c3fe0cdbd199e13e1514146ff82bc Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 13 Jul 2012 01:03:28 +0100 Subject: Rather than instantiating a UTF8 encoding everywhere when we want to supress the BOM, use a single Util.UTF8NoBomEncoding. This class is thread-safe (as evidenced by the provision of the system-wide Encoding.UTF8 which does not suppress BOM on output). --- OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs index 888b072..7429293 100644 --- a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs +++ b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs @@ -132,8 +132,7 @@ namespace OpenSim.Services.Connectors try { strBuffer = OSDParser.SerializeJsonString(args); - UTF8Encoding str = new UTF8Encoding(); - buffer = str.GetBytes(strBuffer); + buffer = Util.UTF8NoBomEncoding.GetBytes(strBuffer); } catch (Exception e) { -- cgit v1.1