From e5dbb652d5118d193de794fb948252195594b344 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 9 May 2012 00:11:10 +0100 Subject: Remove physics actor related race conditions in SetVehicleFlags() and SetPhysicsAxisRotation() sop.PhysActor can currently become null at any time. --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 4bec2d4..f911ef8 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -3321,10 +3321,10 @@ namespace OpenSim.Region.Framework.Scenes public void SetVehicleFlags(int param, bool remove) { - if (PhysActor != null) - { - PhysActor.VehicleFlags(param, remove); - } + PhysicsActor pa = PhysActor; + + if (pa != null) + pa.VehicleFlags(param, remove); } public void SetGroup(UUID groupID, IClientAPI client) @@ -3356,10 +3356,12 @@ namespace OpenSim.Region.Framework.Scenes public void SetPhysicsAxisRotation() { - if (PhysActor != null) + PhysicsActor pa = PhysActor; + + if (pa != null) { - PhysActor.LockAngularMotion(RotationAxis); - ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); + pa.LockAngularMotion(RotationAxis); + ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa); } } -- cgit v1.1 From 61e99bcdcba5480aa8a2a8b8e2f2b0a66c08e6b4 Mon Sep 17 00:00:00 2001 From: Talun Date: Tue, 8 May 2012 15:52:25 +0100 Subject: Mantis 6015 new LSL function llGetAgentList. Details in the lsl wiki --- .../Shared/Api/Implementation/LSL_Api.cs | 85 ++++++++++++++++++++++ .../ScriptEngine/Shared/Api/Interface/ILSL_Api.cs | 1 + .../Shared/Api/Runtime/LSL_Constants.cs | 5 ++ .../ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs | 5 ++ 4 files changed, 96 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index afd943b..5b5cab8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -5529,6 +5529,91 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); return "en-us"; } + /// + /// http://wiki.secondlife.com/wiki/LlGetAgentList + /// The list of options is currently not used in SL + /// scope is one of:- + /// AGENT_LIST_REGION - all in the region + /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object + /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the + /// current parcel. + /// + public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options) + { + m_host.AddScriptLPS(1); + + // the constants are 1, 2 and 4 so bits are being set, but you + // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4 + bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION; + bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER; + bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL; + + LSL_List result = new LSL_List(); + + if (!regionWide && !parcelOwned && !parcel) + { + result.Add("INVALID_SCOPE"); + return result; + } + + ILandObject land; + Vector3 pos; + UUID id = UUID.Zero; + if (parcel || parcelOwned) + { + pos = m_host.ParentGroup.RootPart.GetWorldPosition(); + land = World.LandChannel.GetLandObject(pos.X, pos.Y); + if (land == null) + { + id = UUID.Zero; + } + else + { + if (parcelOwned) + { + id = land.LandData.OwnerID; + } + else + { + id = land.LandData.GlobalID; + } + } + } + List presenceIds = new List(); + + World.ForEachRootScenePresence( + delegate (ScenePresence ssp) + { + // Gods are not listed in SL + if (!ssp.IsDeleted && ssp.GodLevel == 0.0 && !ssp.IsChildAgent) + { + if (!regionWide) + { + pos = ssp.AbsolutePosition; + land = World.LandChannel.GetLandObject(pos.X, pos.Y); + if (land != null) + { + if (parcelOwned && land.LandData.OwnerID == id || + parcel && land.LandData.GlobalID == id) + { + result.Add(ssp.UUID.ToString()); + } + } + } + else + { + result.Add(ssp.UUID.ToString()); + } + } + // Maximum of 100 results + if (result.Length > 99) + { + return; + } + } + ); + return result; + } public void llAdjustSoundVolume(double volume) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs index 7a797ac..7f5d1fe 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs @@ -109,6 +109,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_Vector llGetAccel(); LSL_Integer llGetAgentInfo(string id); LSL_String llGetAgentLanguage(string id); + LSL_List llGetAgentList(LSL_Integer scope, LSL_List options); LSL_Vector llGetAgentSize(string id); LSL_Float llGetAlpha(int face); LSL_Float llGetAndResetTime(); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 2a28542..b6c21e6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -501,6 +501,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int OBJECT_STREAMING_COST = 15; public const int OBJECT_PHYSICS_COST = 16; + // for llGetAgentList + public const int AGENT_LIST_PARCEL = 1; + public const int AGENT_LIST_PARCEL_OWNER = 2; + public const int AGENT_LIST_REGION = 4; + // Can not be public const? public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); public static readonly rotation ZERO_ROTATION = new rotation(0.0, 0.0, 0.0, 1.0); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs index 80fa530..c0bf29c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs @@ -389,6 +389,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_LSL_Functions.llGetAgentLanguage(id); } + public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options) + { + return m_LSL_Functions.llGetAgentList(scope, options); + } + public LSL_Vector llGetAgentSize(string id) { return m_LSL_Functions.llGetAgentSize(id); -- cgit v1.1 From e813f41478eefb50748e9bdc2b825fa8bc25c971 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 9 May 2012 20:52:54 +0100 Subject: Escape and unescape xml element names if necessary in ServerUtils.BuildXmlData() and ParseElement() If AvatarService appearance data is retrieved over the network, then ServerUtils was attempting to transfer names such as "Wearable 0:0" directly to xml element names, resulting in an exception. Space is not valid in xml element names. Neither is : in this case since the intention is not to namespace. Using names directly as keys is not a good idea. To get around this problem this patch escapes and unescapes the element names as appropriate. This has no impact on existing xml (since it had to be valid in the first place) but allows AvatarService data to be used over the network. Setting appearance (from simulator to AvatarService) did not suffer this problem since the values are passed in the query string which is already properly escaped. --- OpenSim/Server/Base/ServerUtils.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index 0cc2a4b..42c82cf 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs @@ -268,7 +268,7 @@ namespace OpenSim.Server.Base continue; XmlElement elem = parent.OwnerDocument.CreateElement("", - kvp.Key, ""); + XmlConvert.EncodeLocalName(kvp.Key), ""); if (kvp.Value is Dictionary) { @@ -323,11 +323,11 @@ namespace OpenSim.Server.Base XmlNode type = part.Attributes.GetNamedItem("type"); if (type == null || type.Value != "List") { - ret[part.Name] = part.InnerText; + ret[XmlConvert.DecodeName(part.Name)] = part.InnerText; } else { - ret[part.Name] = ParseElement(part); + ret[XmlConvert.DecodeName(part.Name)] = ParseElement(part); } } -- cgit v1.1 From 6987aef38dbc4f5c24b6e2cc73601f9a7c5f4431 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 9 May 2012 23:12:30 +0100 Subject: Improve logging on the prim inventory script asset request path for future use. This adds name and description of the request handler to http request logging when DebugLevel >= 1 --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 4 ++-- .../ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 2 +- OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | 13 ++++++++----- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 4 ++++ 4 files changed, 15 insertions(+), 8 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index d0463c8..401dfd3 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -447,8 +447,8 @@ namespace OpenSim.Framework.Servers.HttpServer { if (DebugLevel >= 1) m_log.DebugFormat( - "[BASE HTTP SERVER]: Found stream handler for {0} {1}", - request.HttpMethod, request.Url.PathAndQuery); + "[BASE HTTP SERVER]: Found stream handler for {0} {1} {2} {3}", + request.HttpMethod, request.Url.PathAndQuery, requestHandler.Name, requestHandler.Description); // Okay, so this is bad, but should be considered temporary until everything is IStreamHandler. byte[] buffer = null; diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 9791885..6c28e78 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -309,7 +309,7 @@ namespace OpenSim.Region.ClientStack.Linden m_HostCapsObj.HttpListener.AddStreamHandler( new BinaryStreamHandler( - "POST", capsBase + uploaderPath, uploader.uploaderCaps, "BunchOfCaps", null)); + "POST", capsBase + uploaderPath, uploader.uploaderCaps, "TaskInventoryScriptUpdater", null)); string protocol = "http://"; diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index ae5cbff..4d6081c 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -11955,21 +11955,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP protected void MakeAssetRequest(TransferRequestPacket transferRequest, UUID taskID) { UUID requestID = UUID.Zero; - if (transferRequest.TransferInfo.SourceType == (int)SourceType.Asset) + int sourceType = transferRequest.TransferInfo.SourceType; + + if (sourceType == (int)SourceType.Asset) { requestID = new UUID(transferRequest.TransferInfo.Params, 0); } - else if (transferRequest.TransferInfo.SourceType == (int)SourceType.SimInventoryItem) + else if (sourceType == (int)SourceType.SimInventoryItem) { requestID = new UUID(transferRequest.TransferInfo.Params, 80); } - else if (transferRequest.TransferInfo.SourceType == (int)SourceType.SimEstate) + else if (sourceType == (int)SourceType.SimEstate) { requestID = taskID; } - -// m_log.DebugFormat("[CLIENT]: {0} requesting asset {1}", Name, requestID); +// m_log.DebugFormat( +// "[LLCLIENTVIEW]: Received transfer request for {0} in {1} type {2} by {3}", +// requestID, taskID, (SourceType)sourceType, Name); m_assetService.Get(requestID.ToString(), transferRequest, AssetReceived); } diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 816d3b6..8a26df1 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -300,6 +300,10 @@ namespace OpenSim.Region.Framework.Scenes AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data, remoteClient.AgentId); AssetService.Store(asset); +// m_log.DebugFormat( +// "[PRIM INVENTORY]: Stored asset {0} when updating item {1} in prim {2} for {3}", +// asset.ID, item.Name, part.Name, remoteClient.Name); + if (isScriptRunning) { part.Inventory.RemoveScriptInstance(item.ItemID, false); -- 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') 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 de44734fe9a0b31cd8cb78c0f58e61a35fe2a259 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Thu, 10 May 2012 09:08:40 -0700 Subject: Saving estate state is really slow (relatively) and it gets completely rewritten every time a region starts up. This makes the data write only when the data was not already read from the database. There is a still a major race condition whenever two regions share the same estate data, but at least it won't be triggered on startup. --- OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs | 5 +++-- OpenSim/Region/Application/OpenSim.cs | 5 +++-- OpenSim/Region/Application/OpenSimBase.cs | 12 +++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs index 45b8d6f..0065702 100644 --- a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs +++ b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs @@ -122,9 +122,10 @@ namespace OpenSim.ApplicationPlugins.LoadRegions Thread.CurrentThread.ManagedThreadId.ToString() + ")"); - m_openSim.PopulateRegionEstateInfo(regionsToLoad[i]); + bool changed = m_openSim.PopulateRegionEstateInfo(regionsToLoad[i]); m_openSim.CreateRegion(regionsToLoad[i], true, out scene); - regionsToLoad[i].EstateSettings.Save(); + if (changed) + regionsToLoad[i].EstateSettings.Save(); if (scene != null) { diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 4ec64ee..6796f2b 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -618,10 +618,11 @@ namespace OpenSim return; } - PopulateRegionEstateInfo(regInfo); + bool changed = PopulateRegionEstateInfo(regInfo); IScene scene; CreateRegion(regInfo, true, out scene); - regInfo.EstateSettings.Save(); + if (changed) + regInfo.EstateSettings.Save(); } /// diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 79259d8..045e8d2 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -977,13 +977,13 @@ namespace OpenSim /// Load the estate information for the provided RegionInfo object. /// /// - public void PopulateRegionEstateInfo(RegionInfo regInfo) + public bool PopulateRegionEstateInfo(RegionInfo regInfo) { if (EstateDataService != null) regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, false); if (regInfo.EstateSettings.EstateID != 0) - return; + return false; // estate info in the database did not change m_log.WarnFormat("[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName); @@ -1018,7 +1018,7 @@ namespace OpenSim } if (defaultEstateJoined) - return; + return true; // need to update the database else m_log.ErrorFormat( "[OPENSIM BASE]: Joining default estate {0} failed", defaultEstateName); @@ -1080,8 +1080,10 @@ namespace OpenSim MainConsole.Instance.Output("Joining the estate failed. Please try again."); } } - } - } + } + + return true; // need to update the database + } } public class OpenSimConfigSource -- cgit v1.1