From 3c9cba162739b93a07067d8a286f6dad55e02217 Mon Sep 17 00:00:00 2001 From: diva Date: Sun, 5 Apr 2009 03:27:50 +0000 Subject: Added CreateObject(regionhandle, userID, itemID) to post objects that are to be fetched from the user's inventory server and rezzed in the region. Added all code necessary to fetch the item and the asset, and rez it inworld. The access to the item is uncap-ed and unverified -- I may place it later either under a cap or with auth verification. But in this model regions don't have the user's inventory, so they would have to guess the item IDs. Added safemode config to Standalone Hypergrid, similar effect to AllowRegionAccessToInventory in Inventory Server. Everyone should have these vars set to their default values except me! --- .../Communications/Clients/InventoryClient.cs | 78 ++++++++++++++++++++++ .../Communications/Clients/RegionClient.cs | 76 +++++++++++++++++++++ .../Communications/Services/HGInventoryService.cs | 18 ++++- 3 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 OpenSim/Framework/Communications/Clients/InventoryClient.cs (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/Clients/InventoryClient.cs b/OpenSim/Framework/Communications/Clients/InventoryClient.cs new file mode 100644 index 0000000..8fe4268 --- /dev/null +++ b/OpenSim/Framework/Communications/Clients/InventoryClient.cs @@ -0,0 +1,78 @@ +/** + * Copyright (c), Contributors. All rights reserved. + * 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 Organizations nor the names of Individual + * Contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR 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 System; +using OpenSim.Framework.Servers; + +using OpenMetaverse; + +namespace OpenSim.Framework.Communications.Clients +{ + public class InventoryClient + { + private string ServerURL; + + public InventoryClient(string url) + { + ServerURL = url; + } + + public void GetInventoryItemAsync(InventoryItemBase item, ReturnResponse callBack) + { + System.Console.WriteLine("[HGrid] GetInventory from " + ServerURL); + try + { + RestSessionObjectPosterResponse requester + = new RestSessionObjectPosterResponse(); + requester.ResponseCallback = callBack; + + requester.BeginPostObject(ServerURL + "/GetItem/", item, string.Empty, string.Empty); + } + catch (Exception e) + { + System.Console.WriteLine("[HGrid]: Exception posting to inventory: " + e); + } + } + + public InventoryItemBase GetInventoryItem(InventoryItemBase item) + { + System.Console.WriteLine("[HGrid] GetInventory " + item.ID + " from " + ServerURL); + try + { + item = SynchronousRestSessionObjectPoster.BeginPostObject("POST", ServerURL + "/GetItem/", item.ID.Guid, "", ""); + return item; + } + catch (Exception e) + { + System.Console.WriteLine("[HGrid]: Exception posting to inventory: " + e); + } + return null; + } + + } +} diff --git a/OpenSim/Framework/Communications/Clients/RegionClient.cs b/OpenSim/Framework/Communications/Clients/RegionClient.cs index d98852b..196bcf9 100644 --- a/OpenSim/Framework/Communications/Clients/RegionClient.cs +++ b/OpenSim/Framework/Communications/Clients/RegionClient.cs @@ -417,6 +417,82 @@ namespace OpenSim.Framework.Communications.Clients } + public bool DoCreateObjectCall(RegionInfo region, UUID userID, UUID itemID) + { + ulong regionHandle = GetRegionHandle(region.RegionHandle); + string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/object/" + UUID.Zero + "/" + regionHandle.ToString() + "/"; + //m_log.Debug(" >>> DoCreateChildAgentCall <<< " + uri); + + WebRequest ObjectCreateRequest = WebRequest.Create(uri); + ObjectCreateRequest.Method = "PUT"; + ObjectCreateRequest.ContentType = "application/json"; + ObjectCreateRequest.Timeout = 10000; + + OSDMap args = new OSDMap(2); + args["userid"] = OSD.FromUUID(userID); + args["itemid"] = OSD.FromUUID(itemID); + + 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("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message); + // ignore. buffer will be empty, caller should check. + } + + Stream os = null; + try + { // send the Post + ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send + os = ObjectCreateRequest.GetRequestStream(); + os.Write(buffer, 0, strBuffer.Length); //Send it + os.Close(); + //m_log.InfoFormat("[REST COMMS]: Posted CreateObject request to remote sim {0}", uri); + } + //catch (WebException ex) + catch + { + // m_log.InfoFormat("[REST COMMS]: Bad send on CreateObject {0}", ex.Message); + + return false; + } + + // Let's wait for the response + //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall"); + + try + { + WebResponse webResponse = ObjectCreateRequest.GetResponse(); + if (webResponse == null) + { + m_log.Info("[REST COMMS]: Null reply on DoCreateObjectCall post"); + } + + StreamReader sr = new StreamReader(webResponse.GetResponseStream()); + sr.ReadToEnd().Trim(); + sr.ReadToEnd().Trim(); + sr.Close(); + + //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply); + + } + catch (WebException ex) + { + m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObjectCall {0}", ex.Message); + // ignore, really + } + + return true; + + } + public bool DoHelloNeighbourCall(RegionInfo region, RegionInfo thisRegion) { string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/"; diff --git a/OpenSim/Framework/Communications/Services/HGInventoryService.cs b/OpenSim/Framework/Communications/Services/HGInventoryService.cs index abb9b92..a3234bf 100644 --- a/OpenSim/Framework/Communications/Services/HGInventoryService.cs +++ b/OpenSim/Framework/Communications/Services/HGInventoryService.cs @@ -107,6 +107,17 @@ namespace OpenSim.Framework.Communications.Services public virtual void AddHttpHandlers() { httpServer.AddHTTPHandler("/InvCap/", CapHandler); + + // Un-cap'ed for now + httpServer.AddStreamHandler(new RestDeserialiseSecureHandler( + "POST", "/GetItem/", GetInventoryItem, CheckAuthSession)); + + } + + public InventoryItemBase GetInventoryItem(Guid id) + { + UUID itemID = new UUID(id); + return m_inventoryService.GetInventoryItem(itemID); } public bool CheckAuthSession(string session_id, string avatar_id) @@ -353,10 +364,15 @@ namespace OpenSim.Framework.Communications.Services m_log.DebugFormat("[HGStandaloneInvService]: client with uuid {0} is trying to get an item of owner {1}", item.Owner, item2.Owner); return asset; } + UUID assetID = item2.AssetID; + if (assetID != item.AssetID) + { + m_log.WarnFormat("[HGStandaloneInvService]: asset IDs don't match {0}, {1}", item.AssetID, item2.AssetID); + } // All good, get the asset //AssetBase theasset = m_assetProvider.FetchAsset(item.AssetID); - AssetBase theasset = FetchAsset(item.AssetID, (item.InvType == (int)InventoryType.Texture)); + AssetBase theasset = FetchAsset(assetID, (item.InvType == (int)InventoryType.Texture)); m_log.Debug("[HGStandaloneInvService] Found asset " + ((theasset == null) ? "NULL" : "Not Null")); if (theasset != null) -- cgit v1.1