Adding the SimianGrid connectors

slimupdates
John Hurliman 2010-03-11 10:05:03 -08:00
parent b18ca2fee6
commit 2040649871
13 changed files with 3736 additions and 0 deletions

View File

@ -0,0 +1,407 @@
/*
* 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 System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Connects to the SimianGrid asset service
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianAssetServiceConnector : IAssetService, ISharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private static string ZeroID = UUID.Zero.ToString();
private string m_serverUrl = String.Empty;
private IImprovedAssetCache m_cache;
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene)
{
if (m_cache == null)
{
IImprovedAssetCache cache = scene.RequestModuleInterface<IImprovedAssetCache>();
if (cache is ISharedRegionModule)
m_cache = cache;
}
}
public void PostInitialise() { }
public void Close() { }
public SimianAssetServiceConnector() { }
public string Name { get { return "SimianAssetServiceConnector"; } }
public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IAssetService>(this); }
public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IAssetService>(this); }
#endregion ISharedRegionModule
public SimianAssetServiceConnector(IConfigSource source)
{
Initialise(source);
}
public void Initialise(IConfigSource source)
{
IConfig gridConfig = source.Configs["AssetService"];
if (gridConfig == null)
{
m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpenSim.ini");
throw new Exception("Asset connector init error");
}
string serviceUrl = gridConfig.GetString("AssetServerURI");
if (String.IsNullOrEmpty(serviceUrl))
{
m_log.Error("[ASSET CONNECTOR]: No AssetServerURI in section AssetService");
throw new Exception("Asset connector init error");
}
if (!serviceUrl.EndsWith("/"))
serviceUrl = serviceUrl + '/';
m_serverUrl = serviceUrl;
}
#region IAssetService
public AssetBase Get(string id)
{
AssetBase asset = null;
// Cache fetch
if (m_cache != null)
{
asset = m_cache.Get(id);
if (asset != null)
return asset;
}
Uri url;
// Determine if id is an absolute URL or a grid-relative UUID
if (!Uri.TryCreate(id, UriKind.Absolute, out url))
url = new Uri(m_serverUrl + id);
try
{
HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
using (WebResponse response = request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
string creatorID = response.Headers.GetOne("X-Asset-Creator-Id") ?? String.Empty;
// Create the asset object
asset = new AssetBase(id, String.Empty, SLUtil.ContentTypeToSLAssetType(response.ContentType), creatorID);
UUID assetID;
if (UUID.TryParse(id, out assetID))
asset.FullID = assetID;
// Grab the asset data from the response stream
using (MemoryStream stream = new MemoryStream())
{
responseStream.CopyTo(stream, Int32.MaxValue);
asset.Data = stream.ToArray();
}
}
}
// Cache store
if (m_cache != null && asset != null)
m_cache.Cache(asset);
return asset;
}
catch (Exception ex)
{
m_log.Warn("[ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message);
return null;
}
}
/// <summary>
/// Get an asset's metadata
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public AssetMetadata GetMetadata(string id)
{
AssetMetadata metadata = null;
// Cache fetch
if (m_cache != null)
{
AssetBase asset = m_cache.Get(id);
if (asset != null)
return asset.Metadata;
}
Uri url;
// Determine if id is an absolute URL or a grid-relative UUID
if (!Uri.TryCreate(id, UriKind.Absolute, out url))
url = new Uri(m_serverUrl + id);
try
{
HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
request.Method = "HEAD";
using (WebResponse response = request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
// Create the metadata object
metadata = new AssetMetadata();
metadata.ContentType = response.ContentType;
metadata.ID = id;
UUID uuid;
if (UUID.TryParse(id, out uuid))
metadata.FullID = uuid;
string lastModifiedStr = response.Headers.Get("Last-Modified");
if (!String.IsNullOrEmpty(lastModifiedStr))
{
DateTime lastModified;
if (DateTime.TryParse(lastModifiedStr, out lastModified))
metadata.CreationDate = lastModified;
}
}
}
}
catch (Exception ex)
{
m_log.Warn("[ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message);
}
return metadata;
}
public byte[] GetData(string id)
{
AssetBase asset = Get(id);
if (asset != null)
return asset.Data;
return null;
}
/// <summary>
/// Get an asset asynchronously
/// </summary>
/// <param name="id">The asset id</param>
/// <param name="sender">Represents the requester. Passed back via the handler</param>
/// <param name="handler">The handler to call back once the asset has been retrieved</param>
/// <returns>True if the id was parseable, false otherwise</returns>
public bool Get(string id, Object sender, AssetRetrieved handler)
{
Util.FireAndForget(
delegate(object o)
{
AssetBase asset = Get(id);
handler(id, sender, asset);
}
);
return true;
}
/// <summary>
/// Creates a new asset
/// </summary>
/// Returns a random ID if none is passed into it
/// <param name="asset"></param>
/// <returns></returns>
public string Store(AssetBase asset)
{
bool storedInCache = false;
string errorMessage = null;
// AssetID handling
if (String.IsNullOrEmpty(asset.ID) || asset.ID == ZeroID)
{
asset.FullID = UUID.Random();
asset.ID = asset.FullID.ToString();
}
// Cache handling
if (m_cache != null)
{
m_cache.Cache(asset);
storedInCache = true;
}
// Local asset handling
if (asset.Local)
{
if (!storedInCache)
{
m_log.Error("Cannot store local " + asset.Metadata.ContentType + " asset without an asset cache");
asset.ID = null;
asset.FullID = UUID.Zero;
}
return asset.ID;
}
// Distinguish public and private assets
bool isPublic = true;
switch ((AssetType)asset.Type)
{
case AssetType.CallingCard:
case AssetType.Gesture:
case AssetType.LSLBytecode:
case AssetType.LSLText:
isPublic = false;
break;
}
// Make sure ContentType is set
if (String.IsNullOrEmpty(asset.Metadata.ContentType))
asset.Metadata.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type);
// Build the remote storage request
List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
{
new MultipartForm.Parameter("AssetID", asset.FullID.ToString()),
new MultipartForm.Parameter("CreatorID", asset.Metadata.CreatorID),
new MultipartForm.Parameter("Temporary", asset.Temporary ? "1" : "0"),
new MultipartForm.Parameter("Public", isPublic ? "1" : "0"),
new MultipartForm.File("Asset", asset.Name, asset.Metadata.ContentType, asset.Data)
};
// Make the remote storage request
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);
HttpWebResponse response = MultipartForm.Post(request, postParameters);
using (Stream responseStream = response.GetResponseStream())
{
try
{
string responseStr = responseStream.GetStreamString();
OSD responseOSD = OSDParser.Deserialize(responseStr);
if (responseOSD.Type == OSDType.Map)
{
OSDMap responseMap = (OSDMap)responseOSD;
if (responseMap["Success"].AsBoolean())
return asset.ID;
else
errorMessage = "Upload failed: " + responseMap["Message"].AsString();
}
else
{
errorMessage = "Response format was invalid.";
}
}
catch
{
errorMessage = "Failed to parse the response.";
}
}
}
catch (WebException ex)
{
errorMessage = ex.Message;
}
m_log.WarnFormat("[ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}",
asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage);
return null;
}
/// <summary>
/// Update an asset's content
/// </summary>
/// Attachments and bare scripts need this!!
/// <param name="id"> </param>
/// <param name="data"></param>
/// <returns></returns>
public bool UpdateContent(string id, byte[] data)
{
AssetBase asset = Get(id);
if (asset == null)
{
m_log.Warn("[ASSET CONNECTOR]: Failed to fetch asset " + id + " for updating");
return false;
}
asset.Data = data;
string result = Store(asset);
return !String.IsNullOrEmpty(result);
}
/// <summary>
/// Delete an asset
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool Delete(string id)
{
if (m_cache != null)
m_cache.Expire(id);
string url = m_serverUrl + id;
OSDMap response = WebUtil.ServiceRequest(url, "DELETE");
if (response["Success"].AsBoolean())
return true;
else
m_log.Warn("[ASSET CONNECTOR]: Failed to delete asset " + id + " from the asset service");
return false;
}
#endregion IAssetService
}
}

View File

@ -0,0 +1,198 @@
/*
* 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 System;
using System.Collections.Specialized;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Connects authentication/authorization to the SimianGrid backend
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianAuthenticationServiceConnector : IAuthenticationService, ISharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private string m_serverUrl = String.Empty;
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void PostInitialise() { }
public void Close() { }
public SimianAuthenticationServiceConnector() { }
public string Name { get { return "SimianAuthenticationServiceConnector"; } }
public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IAuthenticationService>(this); }
public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IAuthenticationService>(this); }
#endregion ISharedRegionModule
public SimianAuthenticationServiceConnector(IConfigSource source)
{
Initialise(source);
}
public 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");
if (String.IsNullOrEmpty(serviceURI))
{
m_log.Error("[AUTH CONNECTOR]: No Server URI named in section AuthenticationService");
throw new Exception("Authentication connector init error");
}
m_serverUrl = serviceURI;
}
public string Authenticate(UUID principalID, string password, int lifetime)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetIdentities" },
{ "UserID", principalID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Identities"] is OSDArray)
{
OSDArray identities = (OSDArray)response["Identities"];
for (int i = 0; i < identities.Count; i++)
{
OSDMap identity = identities[i] as OSDMap;
if (identity != null)
{
if (identity["Type"].AsString() == "md5hash")
{
string credential = identity["Credential"].AsString();
if (password == credential || Utils.MD5String(password) == credential)
return Authorize(principalID);
}
}
}
m_log.Warn("[AUTH CONNECTOR]: Authentication failed for " + principalID);
}
else
{
m_log.Warn("[AUTH CONNECTOR]: Failed to retrieve identities for " + principalID + ": " +
response["Message"].AsString());
}
return String.Empty;
}
public bool Verify(UUID principalID, string token, int lifetime)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetSession" },
{ "SessionID", token }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
return true;
}
else
{
m_log.Warn("[AUTH CONNECTOR]: Could not verify session for " + principalID + ": " +
response["Message"].AsString());
}
return false;
}
public bool Release(UUID principalID, string token)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "RemoveSession" },
{ "UserID", principalID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
return true;
}
else
{
m_log.Warn("[AUTH CONNECTOR]: Failed to remove session for " + principalID + ": " +
response["Message"].AsString());
}
return false;
}
public bool SetPassword(UUID principalID, string passwd)
{
// TODO: Use GetIdentities to find the md5hash identity for principalID
// and then update it with AddIdentity
m_log.Error("[AUTH CONNECTOR]: Changing passwords is not implemented yet");
return false;
}
private string Authorize(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddSession" },
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
return response["SessionID"].AsUUID().ToString();
else
return String.Empty;
}
}
}

View File

@ -0,0 +1,259 @@
/*
* 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 System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Connects avatar appearance data to the SimianGrid backend
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianAvatarServiceConnector : IAvatarService, ISharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private static string ZeroID = UUID.Zero.ToString();
private string m_serverUrl = String.Empty;
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void PostInitialise() { }
public void Close() { }
public SimianAvatarServiceConnector() { }
public string Name { get { return "SimianAvatarServiceConnector"; } }
public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IAvatarService>(this); }
public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IAvatarService>(this); }
#endregion ISharedRegionModule
public SimianAvatarServiceConnector(IConfigSource source)
{
Initialise(source);
}
public 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 serviceUrl = gridConfig.GetString("AvatarServerURI");
if (String.IsNullOrEmpty(serviceUrl))
{
m_log.Error("[AVATAR CONNECTOR]: No AvatarServerURI in section AvatarService");
throw new Exception("Avatar connector init error");
}
if (!serviceUrl.EndsWith("/"))
serviceUrl = serviceUrl + '/';
m_serverUrl = serviceUrl;
}
#region IAvatarService
public AvatarData GetAvatar(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap map = null;
try { map = OSDParser.DeserializeJson(response["LLAppearance"].AsString()) as OSDMap; }
catch { }
if (map != null)
{
AvatarWearable[] wearables = new AvatarWearable[13];
wearables[0] = new AvatarWearable(map["ShapeItem"].AsUUID(), map["ShapeAsset"].AsUUID());
wearables[1] = new AvatarWearable(map["SkinItem"].AsUUID(), map["SkinAsset"].AsUUID());
wearables[2] = new AvatarWearable(map["HairItem"].AsUUID(), map["HairAsset"].AsUUID());
wearables[3] = new AvatarWearable(map["EyesItem"].AsUUID(), map["EyesAsset"].AsUUID());
wearables[4] = new AvatarWearable(map["ShirtItem"].AsUUID(), map["ShirtAsset"].AsUUID());
wearables[5] = new AvatarWearable(map["PantsItem"].AsUUID(), map["PantsAsset"].AsUUID());
wearables[6] = new AvatarWearable(map["ShoesItem"].AsUUID(), map["ShoesAsset"].AsUUID());
wearables[7] = new AvatarWearable(map["SocksItem"].AsUUID(), map["SocksAsset"].AsUUID());
wearables[8] = new AvatarWearable(map["JacketItem"].AsUUID(), map["JacketAsset"].AsUUID());
wearables[9] = new AvatarWearable(map["GlovesItem"].AsUUID(), map["GlovesAsset"].AsUUID());
wearables[10] = new AvatarWearable(map["UndershirtItem"].AsUUID(), map["UndershirtAsset"].AsUUID());
wearables[11] = new AvatarWearable(map["UnderpantsItem"].AsUUID(), map["UnderpantsAsset"].AsUUID());
wearables[12] = new AvatarWearable(map["SkirtItem"].AsUUID(), map["SkirtAsset"].AsUUID());
AvatarAppearance appearance = new AvatarAppearance(userID);
appearance.Wearables = wearables;
appearance.AvatarHeight = (float)map["Height"].AsReal();
AvatarData avatar = new AvatarData(appearance);
// Get attachments
map = null;
try { map = OSDParser.DeserializeJson(response["LLAttachments"].AsString()) as OSDMap; }
catch { }
if (map != null)
{
foreach (KeyValuePair<string, OSD> kvp in map)
avatar.Data[kvp.Key] = kvp.Value.AsString();
}
return avatar;
}
else
{
m_log.Warn("[AVATAR CONNECTOR]: Failed to get user appearance for " + userID +
", LLAppearance is missing or invalid");
return null;
}
}
else
{
m_log.Warn("[AVATAR CONNECTOR]: Failed to get user appearance for " + userID + ": " +
response["Message"].AsString());
}
return null;
}
public bool SetAvatar(UUID userID, AvatarData avatar)
{
m_log.Debug("[AVATAR CONNECTOR]: SetAvatar called for " + userID);
if (avatar.AvatarType == 1) // LLAvatar
{
AvatarAppearance appearance = avatar.ToAvatarAppearance(userID);
OSDMap map = new OSDMap();
map["Height"] = OSD.FromReal(appearance.AvatarHeight);
map["ShapeItem"] = OSD.FromUUID(appearance.BodyItem);
map["ShapeAsset"] = OSD.FromUUID(appearance.BodyAsset);
map["SkinItem"] = OSD.FromUUID(appearance.SkinItem);
map["SkinAsset"] = OSD.FromUUID(appearance.SkinAsset);
map["HairItem"] = OSD.FromUUID(appearance.HairItem);
map["HairAsset"] = OSD.FromUUID(appearance.HairAsset);
map["EyesItem"] = OSD.FromUUID(appearance.EyesItem);
map["EyesAsset"] = OSD.FromUUID(appearance.EyesAsset);
map["ShirtItem"] = OSD.FromUUID(appearance.ShirtItem);
map["ShirtAsset"] = OSD.FromUUID(appearance.ShirtAsset);
map["PantsItem"] = OSD.FromUUID(appearance.PantsItem);
map["PantsAsset"] = OSD.FromUUID(appearance.PantsAsset);
map["ShoesItem"] = OSD.FromUUID(appearance.ShoesItem);
map["ShoesAsset"] = OSD.FromUUID(appearance.ShoesAsset);
map["SocksItem"] = OSD.FromUUID(appearance.SocksItem);
map["SocksAsset"] = OSD.FromUUID(appearance.SocksAsset);
map["JacketItem"] = OSD.FromUUID(appearance.JacketItem);
map["JacketAsset"] = OSD.FromUUID(appearance.JacketAsset);
map["GlovesItem"] = OSD.FromUUID(appearance.GlovesItem);
map["GlovesAsset"] = OSD.FromUUID(appearance.GlovesAsset);
map["UndershirtItem"] = OSD.FromUUID(appearance.UnderShirtItem);
map["UndershirtAsset"] = OSD.FromUUID(appearance.UnderShirtAsset);
map["UnderpantsItem"] = OSD.FromUUID(appearance.UnderPantsItem);
map["UnderpantsAsset"] = OSD.FromUUID(appearance.UnderPantsAsset);
map["SkirtItem"] = OSD.FromUUID(appearance.SkirtItem);
map["SkirtAsset"] = OSD.FromUUID(appearance.SkirtAsset);
OSDMap items = new OSDMap();
foreach (KeyValuePair<string, string> kvp in avatar.Data)
{
if (kvp.Key.StartsWith("_ap_"))
items.Add(kvp.Key, OSD.FromString(kvp.Value));
}
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddUserData" },
{ "UserID", userID.ToString() },
{ "LLAppearance", OSDParser.SerializeJsonString(map) },
{ "LLAttachments", OSDParser.SerializeJsonString(items) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[AVATAR CONNECTOR]: Failed saving appearance for " + userID + ": " + response["Message"].AsString());
return success;
}
else
{
m_log.Error("[AVATAR CONNECTOR]: Can't save appearance for " + userID + ". Unhandled avatar type " + avatar.AvatarType);
return false;
}
}
public bool ResetAvatar(UUID userID)
{
m_log.Error("[AVATAR CONNECTOR]: ResetAvatar called for " + userID + ", implement this");
return false;
}
public bool SetItems(UUID userID, string[] names, string[] values)
{
m_log.Error("[AVATAR CONNECTOR]: SetItems called for " + userID + " with " + names.Length + " names and " + values.Length + " values, implement this");
return false;
}
public bool RemoveItems(UUID userID, string[] names)
{
m_log.Error("[AVATAR CONNECTOR]: RemoveItems called for " + userID + " with " + names.Length + " names, implement this");
return false;
}
#endregion IAvatarService
}
}

View File

@ -0,0 +1,229 @@
/*
* 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 System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Stores and retrieves friend lists from the SimianGrid backend
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianFriendsServiceConnector : IFriendsService, ISharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private string m_serverUrl = String.Empty;
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void PostInitialise() { }
public void Close() { }
public SimianFriendsServiceConnector() { }
public string Name { get { return "SimianFriendsServiceConnector"; } }
public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IFriendsService>(this); }
public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IFriendsService>(this); }
#endregion ISharedRegionModule
public SimianFriendsServiceConnector(IConfigSource source)
{
Initialise(source);
}
public void Initialise(IConfigSource source)
{
IConfig assetConfig = source.Configs["FriendsService"];
if (assetConfig == null)
{
m_log.Error("[FRIENDS CONNECTOR]: FriendsService missing from OpenSim.ini");
throw new Exception("Friends connector init error");
}
string serviceURI = assetConfig.GetString("FriendsServerURI");
if (String.IsNullOrEmpty(serviceURI))
{
m_log.Error("[FRIENDS CONNECTOR]: No Server URI named in section FriendsService");
throw new Exception("Friends connector init error");
}
m_serverUrl = serviceURI;
}
#region IFriendsService
public FriendInfo[] GetFriends(UUID principalID)
{
Dictionary<UUID, FriendInfo> friends = new Dictionary<UUID, FriendInfo>();
OSDArray friendsArray = GetFriended(principalID);
OSDArray friendedMeArray = GetFriendedBy(principalID);
// Load the list of friends and their granted permissions
for (int i = 0; i < friendsArray.Count; i++)
{
OSDMap friendEntry = friendsArray[i] as OSDMap;
if (friendEntry != null)
{
UUID friendID = friendEntry["Key"].AsUUID();
FriendInfo friend = new FriendInfo();
friend.PrincipalID = principalID;
friend.Friend = friendID.ToString();
friend.MyFlags = friendEntry["Value"].AsInteger();
friend.TheirFlags = -1;
friends[friendID] = friend;
}
}
// Load the permissions those friends have granted to this user
for (int i = 0; i < friendedMeArray.Count; i++)
{
OSDMap friendedMeEntry = friendedMeArray[i] as OSDMap;
if (friendedMeEntry != null)
{
UUID friendID = friendedMeEntry["OwnerID"].AsUUID();
FriendInfo friend;
if (friends.TryGetValue(friendID, out friend))
friend.TheirFlags = friendedMeEntry["Value"].AsInteger();
}
}
// Convert the dictionary of friends to an array and return it
FriendInfo[] array = new FriendInfo[friends.Count];
int j = 0;
foreach (FriendInfo friend in friends.Values)
array[j++] = friend;
return array;
}
public bool StoreFriend(UUID principalID, string friend, int flags)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddGeneric" },
{ "OwnerID", principalID.ToString() },
{ "Type", "Friend" },
{ "Key", friend },
{ "Value", flags.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Error("[FRIENDS CONNECTOR]: Failed to store friend " + friend + " for user " + principalID + ": " + response["Message"].AsString());
return success;
}
public bool Delete(UUID principalID, string friend)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "RemoveGeneric" },
{ "OwnerID", principalID.ToString() },
{ "Type", "Friend" },
{ "Key", friend }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Error("[FRIENDS CONNECTOR]: Failed to remove friend " + friend + " for user " + principalID + ": " + response["Message"].AsString());
return success;
}
#endregion IFriendsService
private OSDArray GetFriended(UUID ownerID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetGenerics" },
{ "OwnerID", ownerID.ToString() },
{ "Type", "Friend" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Entries"] is OSDArray)
{
return (OSDArray)response["Entries"];
}
else
{
m_log.Warn("[FRIENDS CONNECTOR]: Failed to retrieve friends for user " + ownerID + ": " + response["Message"].AsString());
return new OSDArray(0);
}
}
private OSDArray GetFriendedBy(UUID ownerID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetGenerics" },
{ "Key", ownerID.ToString() },
{ "Type", "Friend" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Entries"] is OSDArray)
{
return (OSDArray)response["Entries"];
}
else
{
m_log.Warn("[FRIENDS CONNECTOR]: Failed to retrieve reverse friends for user " + ownerID + ": " + response["Message"].AsString());
return new OSDArray(0);
}
}
}
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the 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 Mono.Addins;
[assembly: Addin("SimianGrid", "1.0")]
[assembly: AddinDependency("OpenSim", "0.5")]

View File

@ -0,0 +1,418 @@
/*
* 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 System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using OpenSim.Server.Base;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Connects region registration and neighbor lookups to the SimianGrid
/// backend
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianGridServiceConnector : IGridService, ISharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private string m_serverUrl = String.Empty;
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void PostInitialise() { }
public void Close() { }
public SimianGridServiceConnector() { }
public string Name { get { return "SimianGridServiceConnector"; } }
public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IGridService>(this); }
public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IGridService>(this); }
#endregion ISharedRegionModule
public SimianGridServiceConnector(IConfigSource source)
{
Initialise(source);
}
public 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 serviceUrl = gridConfig.GetString("GridServerURI");
if (String.IsNullOrEmpty(serviceUrl))
{
m_log.Error("[GRID CONNECTOR]: No Server URI named in section GridService");
throw new Exception("Grid connector init error");
}
m_serverUrl = serviceUrl;
}
#region IGridService
public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
{
Vector3d minPosition = new Vector3d(regionInfo.RegionLocX, regionInfo.RegionLocY, 0.0);
Vector3d maxPosition = minPosition + new Vector3d(Constants.RegionSize, Constants.RegionSize, 4096.0);
string httpAddress = "http://" + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "/";
OSDMap extraData = new OSDMap
{
{ "ServerURI", OSD.FromString(regionInfo.ServerURI) },
{ "InternalAddress", OSD.FromString(regionInfo.InternalEndPoint.Address.ToString()) },
{ "InternalPort", OSD.FromInteger(regionInfo.InternalEndPoint.Port) },
{ "ExternalAddress", OSD.FromString(regionInfo.ExternalEndPoint.Address.ToString()) },
{ "ExternalPort", OSD.FromInteger(regionInfo.ExternalEndPoint.Port) },
{ "MapTexture", OSD.FromUUID(regionInfo.TerrainImage) },
{ "Access", OSD.FromInteger(regionInfo.Access) },
{ "RegionSecret", OSD.FromString(regionInfo.RegionSecret) },
{ "EstateOwner", OSD.FromUUID(regionInfo.EstateOwner) },
{ "Token", OSD.FromString(regionInfo.Token) }
};
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddScene" },
{ "SceneID", regionInfo.RegionID.ToString() },
{ "Name", regionInfo.RegionName },
{ "MinPosition", minPosition.ToString() },
{ "MaxPosition", maxPosition.ToString() },
{ "Address", httpAddress },
{ "Enabled", "1" },
{ "ExtraData", OSDParser.SerializeJsonString(extraData) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
return String.Empty;
else
return "Region registration for " + regionInfo.RegionName + " failed: " + response["Message"].AsString();
}
public bool DeregisterRegion(UUID regionID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddScene" },
{ "SceneID", regionID.ToString() },
{ "Enabled", "0" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[GRID CONNECTOR]: Region deregistration for " + regionID + " failed: " + response["Message"].AsString());
return success;
}
public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
{
const int NEIGHBOR_RADIUS = 128;
GridRegion region = GetRegionByUUID(scopeID, regionID);
if (region != null)
{
List<GridRegion> regions = GetRegionRange(scopeID,
region.RegionLocX - NEIGHBOR_RADIUS, region.RegionLocX + (int)Constants.RegionSize + NEIGHBOR_RADIUS,
region.RegionLocY - NEIGHBOR_RADIUS, region.RegionLocY + (int)Constants.RegionSize + NEIGHBOR_RADIUS);
for (int i = 0; i < regions.Count; i++)
{
if (regions[i].RegionID == regionID)
{
regions.RemoveAt(i);
break;
}
}
m_log.Debug("[GRID CONNECTOR]: Found " + regions.Count + " neighbors for region " + regionID);
return regions;
}
return new List<GridRegion>(0);
}
public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetScene" },
{ "SceneID", regionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
return ResponseToGridRegion(response);
}
else
{
m_log.Warn("[GRID CONNECTOR]: Grid service did not find a match for region " + regionID);
return null;
}
}
public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
{
// Go one meter in from the requested x/y coords to avoid requesting a position
// that falls on the border of two sims
Vector3d position = new Vector3d(x + 1, y + 1, 0.0);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetScene" },
{ "Position", position.ToString() },
{ "Enabled", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
return ResponseToGridRegion(response);
}
else
{
//m_log.InfoFormat("[GRID CONNECTOR]: Grid service did not find a match for region at {0},{1}",
// x / Constants.RegionSize, y / Constants.RegionSize);
return null;
}
}
public GridRegion GetRegionByName(UUID scopeID, string regionName)
{
List<GridRegion> regions = GetRegionsByName(scopeID, regionName, 1);
m_log.Debug("[GRID CONNECTOR]: Got " + regions.Count + " matches for region name " + regionName);
if (regions.Count > 0)
return regions[0];
return null;
}
public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
{
List<GridRegion> foundRegions = new List<GridRegion>();
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetScenes" },
{ "NameQuery", name },
{ "Enabled", "1" }
};
if (maxNumber > 0)
requestArgs["MaxNumber"] = maxNumber.ToString();
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDArray array = response["Scenes"] as OSDArray;
if (array != null)
{
for (int i = 0; i < array.Count; i++)
{
GridRegion region = ResponseToGridRegion(array[i] as OSDMap);
if (region != null)
foundRegions.Add(region);
}
}
}
return foundRegions;
}
public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
{
List<GridRegion> foundRegions = new List<GridRegion>();
Vector3d minPosition = new Vector3d(xmin, ymin, 0.0);
Vector3d maxPosition = new Vector3d(xmax, ymax, 4096.0);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetScenes" },
{ "MinPosition", minPosition.ToString() },
{ "MaxPosition", maxPosition.ToString() },
{ "Enabled", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDArray array = response["Scenes"] as OSDArray;
if (array != null)
{
for (int i = 0; i < array.Count; i++)
{
GridRegion region = ResponseToGridRegion(array[i] as OSDMap);
if (region != null)
foundRegions.Add(region);
}
}
}
return foundRegions;
}
public List<GridRegion> GetDefaultRegions(UUID scopeID)
{
// TODO: Allow specifying the default grid location
const int DEFAULT_X = 1000 * 256;
const int DEFAULT_Y = 1000 * 256;
GridRegion defRegion = GetNearestRegion(new Vector3d(DEFAULT_X, DEFAULT_Y, 0.0), true);
if (defRegion != null)
return new List<GridRegion>(1) { defRegion };
else
return new List<GridRegion>(0);
}
public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
{
GridRegion defRegion = GetNearestRegion(new Vector3d(x, y, 0.0), true);
if (defRegion != null)
return new List<GridRegion>(1) { defRegion };
else
return new List<GridRegion>(0);
}
public int GetRegionFlags(UUID scopeID, UUID regionID)
{
const int REGION_ONLINE = 4;
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetScene" },
{ "SceneID", regionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
return response["Enabled"].AsBoolean() ? REGION_ONLINE : 0;
}
else
{
m_log.Warn("[GRID CONNECTOR]: Grid service did not find a match for region " + regionID + " during region flags check");
return -1;
}
}
#endregion IGridService
private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetScene" },
{ "Position", position.ToString() },
{ "FindClosest", "1" }
};
if (onlyEnabled)
requestArgs["Enabled"] = "1";
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
return ResponseToGridRegion(response);
}
else
{
m_log.Warn("[GRID CONNECTOR]: Grid service did not find a match for region at " + position);
return null;
}
}
private GridRegion ResponseToGridRegion(OSDMap response)
{
if (response == null)
return null;
OSDMap extraData = response["ExtraData"] as OSDMap;
if (extraData == null)
return null;
GridRegion region = new GridRegion();
region.RegionID = response["SceneID"].AsUUID();
region.RegionName = response["Name"].AsString();
Vector3d minPosition = response["MinPosition"].AsVector3d();
region.RegionLocX = (int)minPosition.X;
region.RegionLocY = (int)minPosition.Y;
Uri httpAddress = response["Address"].AsUri();
region.ExternalHostName = httpAddress.Host;
region.HttpPort = (uint)httpAddress.Port;
region.ServerURI = extraData["ServerURI"].AsString();
IPAddress internalAddress;
IPAddress.TryParse(extraData["InternalAddress"].AsString(), out internalAddress);
if (internalAddress == null)
internalAddress = IPAddress.Any;
region.InternalEndPoint = new IPEndPoint(internalAddress, extraData["InternalPort"].AsInteger());
region.TerrainImage = extraData["MapTexture"].AsUUID();
region.Access = (byte)extraData["Access"].AsInteger();
region.RegionSecret = extraData["RegionSecret"].AsString();
region.EstateOwner = extraData["EstateOwner"].AsUUID();
region.Token = extraData["Token"].AsString();
return region;
}
}
}

View File

@ -0,0 +1,880 @@
/*
* 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 System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Permissions bitflags
/// </summary>
[Flags]
public enum PermissionMask : uint
{
None = 0,
Transfer = 1 << 13,
Modify = 1 << 14,
Copy = 1 << 15,
Move = 1 << 19,
Damage = 1 << 20,
All = 0x7FFFFFFF
}
/// <summary>
/// Connects avatar inventories to the SimianGrid backend
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianInventoryServiceConnector : IInventoryService, ISharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private string m_serverUrl = String.Empty;
private string m_userServerUrl = String.Empty;
private object m_gestureSyncRoot = new object();
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void PostInitialise() { }
public void Close() { }
public SimianInventoryServiceConnector() { }
public string Name { get { return "SimianInventoryServiceConnector"; } }
public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IInventoryService>(this); }
public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IInventoryService>(this); }
#endregion ISharedRegionModule
public SimianInventoryServiceConnector(IConfigSource source)
{
Initialise(source);
}
public void Initialise(IConfigSource source)
{
IConfig gridConfig = source.Configs["InventoryService"];
if (gridConfig == null)
{
m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
throw new Exception("Inventory connector init error");
}
string serviceUrl = gridConfig.GetString("InventoryServerURI");
if (String.IsNullOrEmpty(serviceUrl))
{
m_log.Error("[INVENTORY CONNECTOR]: No Server URI named in section InventoryService");
throw new Exception("Inventory connector init error");
}
// FIXME: Get the user server URL too
m_serverUrl = serviceUrl;
}
/// <summary>
/// Create the entire inventory for a given user
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
public bool CreateUserInventory(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddInventory" },
{ "OwnerID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[INVENTORY CONNECTOR]: Inventory creation for " + userID + " failed: " + response["Message"].AsString());
return success;
}
/// <summary>
/// Gets the skeleton of the inventory -- folders only
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
public List<InventoryFolderBase> GetInventorySkeleton(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetInventoryNode" },
{ "ItemID", userID.ToString() },
{ "OwnerID", userID.ToString() },
{ "IncludeFolders", "1" },
{ "IncludeItems", "0" },
{ "ChildrenOnly", "0" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
return GetFoldersFromResponse(items, userID, true);
}
else
{
m_log.Warn("[INVENTORY CONNECTOR]: Failed to retrieve inventory skeleton for " + userID + ": " +
response["Message"].AsString());
return new List<InventoryFolderBase>(0);
}
}
/// <summary>
/// Synchronous inventory fetch.
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
[Obsolete]
public InventoryCollection GetUserInventory(UUID userID)
{
m_log.Error("[INVENTORY CONNECTOR]: Obsolete GetUserInventory called for " + userID);
InventoryCollection inventory = new InventoryCollection();
inventory.UserID = userID;
inventory.Folders = new List<InventoryFolderBase>();
inventory.Items = new List<InventoryItemBase>();
return inventory;
}
/// <summary>
/// Request the inventory for a user. This is an asynchronous operation that will call the callback when the
/// inventory has been received
/// </summary>
/// <param name="userID"></param>
/// <param name="callback"></param>
[Obsolete]
public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
{
m_log.Error("[INVENTORY CONNECTOR]: Obsolete GetUserInventory called for " + userID);
callback(new List<InventoryFolderImpl>(0), new List<InventoryItemBase>(0));
}
/// <summary>
/// Retrieve the root inventory folder for the given user.
/// </summary>
/// <param name="userID"></param>
/// <returns>null if no root folder was found</returns>
public InventoryFolderBase GetRootFolder(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetInventoryNode" },
{ "ItemID", userID.ToString() },
{ "OwnerID", userID.ToString() },
{ "IncludeFolders", "1" },
{ "IncludeItems", "0" },
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
List<InventoryFolderBase> folders = GetFoldersFromResponse(items, userID, true);
if (folders.Count > 0)
return folders[0];
}
return null;
}
/// <summary>
/// Gets the user folder for the given folder-type
/// </summary>
/// <param name="userID"></param>
/// <param name="type"></param>
/// <returns></returns>
public InventoryFolderBase GetFolderForType(UUID userID, AssetType type)
{
string contentType = SLUtil.SLAssetTypeToContentType((int)type);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetFolderForType" },
{ "ContentType", contentType },
{ "OwnerID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Folder"] is OSDMap)
{
OSDMap folder = (OSDMap)response["Folder"];
return new InventoryFolderBase(
folder["ID"].AsUUID(),
folder["Name"].AsString(),
folder["OwnerID"].AsUUID(),
(short)SLUtil.ContentTypeToSLAssetType(folder["ContentType"].AsString()),
folder["ParentID"].AsUUID(),
(ushort)folder["Version"].AsInteger()
);
}
else
{
m_log.Warn("[INVENTORY CONNECTOR]: Default folder not found for content type " + contentType);
return GetRootFolder(userID);
}
}
/// <summary>
/// Get an item, given by its UUID
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public InventoryItemBase GetItem(InventoryItemBase item)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetInventoryNode" },
{ "ItemID", item.ID.ToString() },
{ "OwnerID", item.Owner.ToString() },
{ "IncludeFolders", "1" },
{ "IncludeItems", "1" },
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
List<InventoryItemBase> items = GetItemsFromResponse((OSDArray)response["Items"]);
if (items.Count > 0)
{
// The requested item should be the first in this list, but loop through
// and sanity check just in case
for (int i = 0; i < items.Count; i++)
{
if (items[i].ID == item.ID)
return items[i];
}
}
}
m_log.Warn("[INVENTORY CONNECTOR]: Item " + item.ID + " owned by " + item.Owner + " not found");
return null;
}
/// <summary>
/// Get a folder, given by its UUID
/// </summary>
/// <param name="folder"></param>
/// <returns></returns>
public InventoryFolderBase GetFolder(InventoryFolderBase folder)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetInventoryNode" },
{ "ItemID", folder.ID.ToString() },
{ "OwnerID", folder.Owner.ToString() },
{ "IncludeFolders", "1" },
{ "IncludeItems", "0" },
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
List<InventoryFolderBase> folders = GetFoldersFromResponse(items, folder.ID, true);
if (folders.Count > 0)
return folders[0];
}
return null;
}
/// <summary>
/// Gets everything (folders and items) inside a folder
/// </summary>
/// <param name="userID"></param>
/// <param name="folderID"></param>
/// <returns></returns>
public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
{
InventoryCollection inventory = new InventoryCollection();
inventory.UserID = userID;
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetInventoryNode" },
{ "ItemID", folderID.ToString() },
{ "OwnerID", userID.ToString() },
{ "IncludeFolders", "1" },
{ "IncludeItems", "1" },
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
inventory.Folders = GetFoldersFromResponse(items, folderID, false);
inventory.Items = GetItemsFromResponse(items);
}
else
{
m_log.Warn("[INVENTORY CONNECTOR]: Error fetching folder " + folderID + " content for " + userID + ": " +
response["Message"].AsString());
inventory.Folders = new List<InventoryFolderBase>(0);
inventory.Items = new List<InventoryItemBase>(0);
}
return inventory;
}
/// <summary>
/// Gets the items inside a folder
/// </summary>
/// <param name="userID"></param>
/// <param name="folderID"></param>
/// <returns></returns>
public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
{
InventoryCollection inventory = new InventoryCollection();
inventory.UserID = userID;
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetInventoryNode" },
{ "ItemID", folderID.ToString() },
{ "OwnerID", userID.ToString() },
{ "IncludeFolders", "0" },
{ "IncludeItems", "1" },
{ "ChildrenOnly", "1" }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
{
OSDArray items = (OSDArray)response["Items"];
return GetItemsFromResponse(items);
}
else
{
m_log.Warn("[INVENTORY CONNECTOR]: Error fetching folder " + folderID + " for " + userID + ": " +
response["Message"].AsString());
return new List<InventoryItemBase>(0);
}
}
/// <summary>
/// Add a new folder to the user's inventory
/// </summary>
/// <param name="folder"></param>
/// <returns>true if the folder was successfully added</returns>
public bool AddFolder(InventoryFolderBase folder)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddInventoryFolder" },
{ "FolderID", folder.ID.ToString() },
{ "ParentID", folder.ParentID.ToString() },
{ "OwnerID", folder.Owner.ToString() },
{ "Name", folder.Name },
{ "ContentType", SLUtil.SLAssetTypeToContentType(folder.Type) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
{
m_log.Warn("[INVENTORY CONNECTOR]: Error creating folder " + folder.Name + " for " + folder.Owner + ": " +
response["Message"].AsString());
}
return success;
}
/// <summary>
/// Update a folder in the user's inventory
/// </summary>
/// <param name="folder"></param>
/// <returns>true if the folder was successfully updated</returns>
public bool UpdateFolder(InventoryFolderBase folder)
{
return AddFolder(folder);
}
/// <summary>
/// Move an inventory folder to a new location
/// </summary>
/// <param name="folder">A folder containing the details of the new location</param>
/// <returns>true if the folder was successfully moved</returns>
public bool MoveFolder(InventoryFolderBase folder)
{
return AddFolder(folder);
}
/// <summary>
/// Delete an item from the user's inventory
/// </summary>
/// <param name="item"></param>
/// <returns>true if the item was successfully deleted</returns>
//bool DeleteItem(InventoryItemBase item);
public bool DeleteFolders(UUID userID, List<UUID> folderIDs)
{
return DeleteItems(userID, folderIDs);
}
/// <summary>
/// Delete an item from the user's inventory
/// </summary>
/// <param name="item"></param>
/// <returns>true if the item was successfully deleted</returns>
public bool DeleteItems(UUID userID, List<UUID> itemIDs)
{
// TODO: RemoveInventoryNode should be replaced with RemoveInventoryNodes
bool allSuccess = true;
for (int i = 0; i < itemIDs.Count; i++)
{
UUID itemID = itemIDs[i];
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "RemoveInventoryNode" },
{ "OwnerID", userID.ToString() },
{ "ItemID", itemID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
{
m_log.Warn("[INVENTORY CONNECTOR]: Error removing item " + itemID + " for " + userID + ": " +
response["Message"].AsString());
allSuccess = false;
}
}
return allSuccess;
}
/// <summary>
/// Purge an inventory folder of all its items and subfolders.
/// </summary>
/// <param name="folder"></param>
/// <returns>true if the folder was successfully purged</returns>
public bool PurgeFolder(InventoryFolderBase folder)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "PurgeInventoryFolder" },
{ "OwnerID", folder.Owner.ToString() },
{ "FolderID", folder.ID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
{
m_log.Warn("[INVENTORY CONNECTOR]: Error purging folder " + folder.ID + " for " + folder.Owner + ": " +
response["Message"].AsString());
}
return success;
}
/// <summary>
/// Add a new item to the user's inventory
/// </summary>
/// <param name="item"></param>
/// <returns>true if the item was successfully added</returns>
public bool AddItem(InventoryItemBase item)
{
// A folder of UUID.Zero means we need to find the most appropriate home for this item
if (item.Folder == UUID.Zero)
{
InventoryFolderBase folder = GetFolderForType(item.Owner, (AssetType)item.AssetType);
if (folder != null && folder.ID != UUID.Zero)
item.Folder = folder.ID;
else
item.Folder = item.Owner; // Root folder
}
if ((AssetType)item.AssetType == AssetType.Gesture)
UpdateGesture(item.Owner, item.ID, item.Flags == 1);
if (item.BasePermissions == 0)
m_log.WarnFormat("[INVENTORY CONNECTOR]: Adding inventory item {0} ({1}) with no base permissions", item.Name, item.ID);
OSDMap permissions = new OSDMap
{
{ "BaseMask", OSD.FromInteger(item.BasePermissions) },
{ "EveryoneMask", OSD.FromInteger(item.EveryOnePermissions) },
{ "GroupMask", OSD.FromInteger(item.GroupPermissions) },
{ "NextOwnerMask", OSD.FromInteger(item.NextPermissions) },
{ "OwnerMask", OSD.FromInteger(item.CurrentPermissions) }
};
OSDMap extraData = new OSDMap()
{
{ "Flags", OSD.FromInteger(item.Flags) },
{ "GroupID", OSD.FromUUID(item.GroupID) },
{ "GroupOwned", OSD.FromBoolean(item.GroupOwned) },
{ "SalePrice", OSD.FromInteger(item.SalePrice) },
{ "SaleType", OSD.FromInteger(item.SaleType) },
{ "Permissions", permissions }
};
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddInventoryItem" },
{ "ItemID", item.ID.ToString() },
{ "AssetID", item.AssetID.ToString() },
{ "ParentID", item.Folder.ToString() },
{ "OwnerID", item.Owner.ToString() },
{ "Name", item.Name },
{ "Description", item.Description },
{ "CreatorID", item.CreatorId },
{ "ExtraData", OSDParser.SerializeJsonString(extraData) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
{
m_log.Warn("[INVENTORY CONNECTOR]: Error creating item " + item.Name + " for " + item.Owner + ": " +
response["Message"].AsString());
}
return success;
}
/// <summary>
/// Update an item in the user's inventory
/// </summary>
/// <param name="item"></param>
/// <returns>true if the item was successfully updated</returns>
public bool UpdateItem(InventoryItemBase item)
{
if (item.AssetID != UUID.Zero)
{
return AddItem(item);
}
else
{
// This is actually a folder update
InventoryFolderBase folder = new InventoryFolderBase(item.ID, item.Name, item.Owner, (short)item.AssetType, item.Folder, 0);
return UpdateFolder(folder);
}
}
public bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
{
bool success = true;
while (items.Count > 0)
{
List<InventoryItemBase> currentItems = new List<InventoryItemBase>();
UUID destFolderID = items[0].Folder;
// Find all of the items being moved to the current destination folder
for (int i = 0; i < items.Count; i++)
{
InventoryItemBase item = items[i];
if (item.Folder == destFolderID)
currentItems.Add(item);
}
// Do the inventory move for the current items
success &= MoveItems(ownerID, items, destFolderID);
// Remove the processed items from the list
for (int i = 0; i < currentItems.Count; i++)
items.Remove(currentItems[i]);
}
return success;
}
/// <summary>
/// Does the given user have an inventory structure?
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
public bool HasInventoryForUser(UUID userID)
{
return GetRootFolder(userID) != null;
}
/// <summary>
/// Get the active gestures of the agent.
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
public List<InventoryItemBase> GetActiveGestures(UUID userID)
{
OSDArray items = FetchGestures(userID);
string[] itemIDs = new string[items.Count];
for (int i = 0; i < items.Count; i++)
itemIDs[i] = items[i].AsUUID().ToString();
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetInventoryNodes" },
{ "OwnerID", userID.ToString() },
{ "Items", String.Join(",", itemIDs) }
};
// FIXME: Implement this in SimianGrid
return new List<InventoryItemBase>(0);
}
/// <summary>
/// Get the union of permissions of all inventory items
/// that hold the given assetID.
/// </summary>
/// <param name="userID"></param>
/// <param name="assetID"></param>
/// <returns>The permissions or 0 if no such asset is found in
/// the user's inventory</returns>
public int GetAssetPermissions(UUID userID, UUID assetID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetInventoryNodes" },
{ "OwnerID", userID.ToString() },
{ "AssetID", assetID.ToString() }
};
// FIXME: Implement this in SimianGrid
return (int)PermissionMask.All;
}
private List<InventoryFolderBase> GetFoldersFromResponse(OSDArray items, UUID baseFolder, bool includeBaseFolder)
{
List<InventoryFolderBase> invFolders = new List<InventoryFolderBase>(items.Count);
for (int i = 0; i < items.Count; i++)
{
OSDMap item = items[i] as OSDMap;
if (item != null && item["Type"].AsString() == "Folder")
{
UUID folderID = item["ID"].AsUUID();
if (folderID == baseFolder && !includeBaseFolder)
continue;
invFolders.Add(new InventoryFolderBase(
folderID,
item["Name"].AsString(),
item["OwnerID"].AsUUID(),
(short)SLUtil.ContentTypeToSLAssetType(item["ContentType"].AsString()),
item["ParentID"].AsUUID(),
(ushort)item["Version"].AsInteger()
));
}
}
return invFolders;
}
private List<InventoryItemBase> GetItemsFromResponse(OSDArray items)
{
List<InventoryItemBase> invItems = new List<InventoryItemBase>(items.Count);
for (int i = 0; i < items.Count; i++)
{
OSDMap item = items[i] as OSDMap;
if (item != null && item["Type"].AsString() == "Item")
{
InventoryItemBase invItem = new InventoryItemBase();
invItem.AssetID = item["AssetID"].AsUUID();
invItem.AssetType = SLUtil.ContentTypeToSLAssetType(item["ContentType"].AsString());
invItem.CreationDate = item["CreationDate"].AsInteger();
invItem.CreatorId = item["CreatorID"].AsString();
invItem.CreatorIdAsUuid = item["CreatorID"].AsUUID();
invItem.Description = item["Description"].AsString();
invItem.Folder = item["ParentID"].AsUUID();
invItem.ID = item["ID"].AsUUID();
invItem.InvType = SLUtil.ContentTypeToSLInvType(item["ContentType"].AsString());
invItem.Name = item["Name"].AsString();
invItem.Owner = item["OwnerID"].AsUUID();
OSDMap extraData = item["ExtraData"] as OSDMap;
if (extraData != null && extraData.Count > 0)
{
invItem.Flags = extraData["Flags"].AsUInteger();
invItem.GroupID = extraData["GroupID"].AsUUID();
invItem.GroupOwned = extraData["GroupOwned"].AsBoolean();
invItem.SalePrice = extraData["SalePrice"].AsInteger();
invItem.SaleType = (byte)extraData["SaleType"].AsInteger();
OSDMap perms = extraData["Permissions"] as OSDMap;
if (perms != null)
{
invItem.BasePermissions = perms["BaseMask"].AsUInteger();
invItem.CurrentPermissions = perms["OwnerMask"].AsUInteger();
invItem.EveryOnePermissions = perms["EveryoneMask"].AsUInteger();
invItem.GroupPermissions = perms["GroupMask"].AsUInteger();
invItem.NextPermissions = perms["NextOwnerMask"].AsUInteger();
}
}
if (invItem.BasePermissions == 0)
{
m_log.InfoFormat("[INVENTORY CONNECTOR]: Forcing item permissions to full for item {0} ({1})",
invItem.Name, invItem.ID);
invItem.BasePermissions = (uint)PermissionMask.All;
invItem.CurrentPermissions = (uint)PermissionMask.All;
invItem.EveryOnePermissions = (uint)PermissionMask.All;
invItem.GroupPermissions = (uint)PermissionMask.All;
invItem.NextPermissions = (uint)PermissionMask.All;
}
invItems.Add(invItem);
}
}
return invItems;
}
private bool MoveItems(UUID ownerID, List<InventoryItemBase> items, UUID destFolderID)
{
string[] itemIDs = new string[items.Count];
for (int i = 0; i < items.Count; i++)
itemIDs[i] = items[i].ID.ToString();
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "MoveInventoryNodes" },
{ "OwnerID", ownerID.ToString() },
{ "FolderID", destFolderID.ToString() },
{ "Items", String.Join(",", itemIDs) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
{
m_log.Warn("[INVENTORY CONNECTOR]: Failed to move " + items.Count + " items to " +
destFolderID + ": " + response["Message"].AsString());
}
return success;
}
private void UpdateGesture(UUID userID, UUID itemID, bool enabled)
{
OSDArray gestures = FetchGestures(userID);
OSDArray newGestures = new OSDArray();
for (int i = 0; i < gestures.Count; i++)
{
UUID gesture = gestures[i].AsUUID();
if (gesture != itemID)
newGestures.Add(OSD.FromUUID(gesture));
}
if (enabled)
newGestures.Add(OSD.FromUUID(itemID));
SaveGestures(userID, newGestures);
}
private OSDArray FetchGestures(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_userServerUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap user = response["User"] as OSDMap;
if (user != null && response.ContainsKey("Gestures"))
{
OSD gestures = OSDParser.DeserializeJson(response["Gestures"].AsString());
if (gestures != null && gestures is OSDArray)
return (OSDArray)gestures;
else
m_log.Error("[INVENTORY CONNECTOR]: Unrecognized active gestures data for " + userID);
}
}
else
{
m_log.Warn("[INVENTORY CONNECTOR]: Failed to fetch active gestures for " + userID + ": " +
response["Message"].AsString());
}
return new OSDArray();
}
private void SaveGestures(UUID userID, OSDArray gestures)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddUserData" },
{ "UserID", userID.ToString() },
{ "Gestures", OSDParser.SerializeJsonString(gestures) }
};
OSDMap response = WebUtil.PostToService(m_userServerUrl, requestArgs);
if (!response["Success"].AsBoolean())
{
m_log.Warn("[INVENTORY CONNECTOR]: Failed to save active gestures for " + userID + ": " +
response["Message"].AsString());
}
}
}
}

View File

@ -0,0 +1,502 @@
/*
* 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 System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using OpenSim.Server.Base;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Connects avatar presence information (for tracking current location and
/// message routing) to the SimianGrid backend
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianPresenceServiceConnector : IPresenceService, ISharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private string m_serverUrl = String.Empty;
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void PostInitialise() { }
public void Close() { }
public SimianPresenceServiceConnector() { }
public string Name { get { return "SimianPresenceServiceConnector"; } }
public void AddRegion(Scene scene)
{
scene.RegisterModuleInterface<IPresenceService>(this);
scene.EventManager.OnMakeRootAgent += MakeRootAgentHandler;
scene.EventManager.OnNewClient += NewClientHandler;
scene.EventManager.OnSignificantClientMovement += SignificantClientMovementHandler;
LogoutRegionAgents(scene.RegionInfo.RegionID);
}
public void RemoveRegion(Scene scene)
{
scene.UnregisterModuleInterface<IPresenceService>(this);
scene.EventManager.OnMakeRootAgent -= MakeRootAgentHandler;
scene.EventManager.OnNewClient -= NewClientHandler;
scene.EventManager.OnSignificantClientMovement -= SignificantClientMovementHandler;
LogoutRegionAgents(scene.RegionInfo.RegionID);
}
#endregion ISharedRegionModule
public SimianPresenceServiceConnector(IConfigSource source)
{
Initialise(source);
}
public 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 serviceUrl = gridConfig.GetString("PresenceServerURI");
if (String.IsNullOrEmpty(serviceUrl))
{
m_log.Error("[PRESENCE CONNECTOR]: No PresenceServerURI in section PresenceService");
throw new Exception("Presence connector init error");
}
m_serverUrl = serviceUrl;
}
#region IPresenceService
public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
{
m_log.ErrorFormat("[PRESENCE CONNECTOR]: Login requested, UserID={0}, SessionID={1}, SecureSessionID={2}",
userID, sessionID, secureSessionID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddSession" },
{ "UserID", userID.ToString() }
};
if (sessionID != UUID.Zero)
{
requestArgs["SessionID"] = sessionID.ToString();
requestArgs["SecureSessionID"] = secureSessionID.ToString();
}
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[PRESENCE CONNECTOR]: Failed to login agent " + userID + ": " + response["Message"].AsString());
return success;
}
public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookAt)
{
m_log.InfoFormat("[PRESENCE CONNECTOR]: Logout requested for agent with sessionID " + sessionID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "RemoveSession" },
{ "SessionID", sessionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[PRESENCE CONNECTOR]: Failed to logout agent with sessionID " + sessionID + ": " + response["Message"].AsString());
return success;
}
public bool LogoutRegionAgents(UUID regionID)
{
m_log.InfoFormat("[PRESENCE CONNECTOR]: Logout requested for all agents in region " + regionID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "RemoveSessions" },
{ "SceneID", regionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[PRESENCE CONNECTOR]: Failed to logout agents from region " + regionID + ": " + response["Message"].AsString());
return success;
}
public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
{
//m_log.DebugFormat("[PRESENCE CONNECTOR]: Updating session data for agent with sessionID " + sessionID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "UpdateSession" },
{ "SessionID", sessionID.ToString() },
{ "SceneID", regionID.ToString() },
{ "ScenePosition", position.ToString() },
{ "SceneLookAt", lookAt.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[PRESENCE CONNECTOR]: Failed to update agent session " + sessionID + ": " + response["Message"].AsString());
return success;
}
public PresenceInfo GetAgent(UUID sessionID)
{
m_log.DebugFormat("[PRESENCE CONNECTOR]: Requesting session data for agent with sessionID " + sessionID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetSession" },
{ "SessionID", sessionID.ToString() }
};
OSDMap sessionResponse = WebUtil.PostToService(m_serverUrl, requestArgs);
if (sessionResponse["Success"].AsBoolean())
{
UUID userID = sessionResponse["UserID"].AsUUID();
m_log.DebugFormat("[PRESENCE CONNECTOR]: Requesting user data for " + userID);
requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "UserID", userID.ToString() }
};
OSDMap userResponse = WebUtil.PostToService(m_serverUrl, requestArgs);
if (userResponse["Success"].AsBoolean())
return ResponseToPresenceInfo(sessionResponse, userResponse);
else
m_log.Warn("[PRESENCE CONNECTOR]: Failed to retrieve user data for " + userID + ": " + userResponse["Message"].AsString());
}
else
{
m_log.Warn("[PRESENCE CONNECTOR]: Failed to retrieve session " + sessionID + ": " + sessionResponse["Message"].AsString());
}
return null;
}
public PresenceInfo[] GetAgents(string[] userIDs)
{
List<PresenceInfo> presences = new List<PresenceInfo>(userIDs.Length);
for (int i = 0; i < userIDs.Length; i++)
{
UUID userID;
if (UUID.TryParse(userIDs[i], out userID) && userID != UUID.Zero)
presences.AddRange(GetSessions(userID));
}
return presences.ToArray();
}
public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
{
m_log.DebugFormat("[PRESENCE CONNECTOR]: Setting home location for user " + userID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddUserData" },
{ "UserID", userID.ToString() },
{ "HomeLocation", SerializeLocation(regionID, position, lookAt) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[PRESENCE CONNECTOR]: Failed to set home location for " + userID + ": " + response["Message"].AsString());
return success;
}
#endregion IPresenceService
#region Presence Detection
private void MakeRootAgentHandler(ScenePresence sp)
{
m_log.DebugFormat("[PRESENCE DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName);
ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
SetLastLocation(sp.UUID, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
}
private void NewClientHandler(IClientAPI client)
{
client.OnConnectionClosed += LogoutHandler;
}
private void SignificantClientMovementHandler(IClientAPI client)
{
ScenePresence sp;
if (client.Scene is Scene && ((Scene)client.Scene).TryGetAvatar(client.AgentId, out sp))
ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
}
private void LogoutHandler(IClientAPI client)
{
if (client.IsLoggingOut)
{
client.OnConnectionClosed -= LogoutHandler;
object obj;
if (client.Scene.TryGetAvatar(client.AgentId, out obj) && obj is ScenePresence)
{
// The avatar is still in the scene, we can get the exact logout position
ScenePresence sp = (ScenePresence)obj;
SetLastLocation(client.AgentId, client.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
}
else
{
// The avatar was already removed from the scene, store LastLocation using the most recent session data
m_log.Warn("[PRESENCE]: " + client.Name + " has already been removed from the scene, storing approximate LastLocation");
SetLastLocation(client.SessionId);
}
LogoutAgent(client.SessionId, Vector3.Zero, Vector3.UnitX);
}
}
#endregion Presence Detection
#region Helpers
private OSDMap GetUserData(UUID userID)
{
m_log.DebugFormat("[PRESENCE CONNECTOR]: Requesting user data for " + userID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["User"] is OSDMap)
return response;
else
m_log.Warn("[PRESENCE CONNECTOR]: Failed to retrieve user data for " + userID + ": " + response["Message"].AsString());
return null;
}
private OSDMap GetSessionData(UUID sessionID)
{
m_log.DebugFormat("[PRESENCE CONNECTOR]: Requesting session data for session " + sessionID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetSession" },
{ "SessionID", sessionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
return response;
else
m_log.Warn("[PRESENCE CONNECTOR]: Failed to retrieve session data for session " + sessionID);
return null;
}
private List<PresenceInfo> GetSessions(UUID userID)
{
List<PresenceInfo> presences = new List<PresenceInfo>(1);
OSDMap userResponse = GetUserData(userID);
if (userResponse != null)
{
m_log.DebugFormat("[PRESENCE CONNECTOR]: Requesting sessions for " + userID);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetSession" },
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
PresenceInfo presence = ResponseToPresenceInfo(response, userResponse);
if (presence != null)
presences.Add(presence);
}
else
{
m_log.Warn("[PRESENCE CONNECTOR]: Failed to retrieve sessions for " + userID + ": " + response["Message"].AsString());
}
}
return presences;
}
/// <summary>
/// Fetch the last known avatar location with GetSession and persist it
/// as user data with AddUserData
/// </summary>
private bool SetLastLocation(UUID sessionID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetSession" },
{ "SessionID", sessionID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (success)
{
UUID userID = response["UserID"].AsUUID();
UUID sceneID = response["SceneID"].AsUUID();
Vector3 position = response["ScenePosition"].AsVector3();
Vector3 lookAt = response["SceneLookAt"].AsVector3();
return SetLastLocation(userID, sceneID, position, lookAt);
}
else
{
m_log.Warn("[PRESENCE CONNECTOR]: Failed to retrieve presence information for session " + sessionID +
" while saving last location: " + response["Message"].AsString());
}
return success;
}
private bool SetLastLocation(UUID userID, UUID sceneID, Vector3 position, Vector3 lookAt)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddUserData" },
{ "UserID", userID.ToString() },
{ "LastLocation", SerializeLocation(sceneID, position, lookAt) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.Warn("[PRESENCE CONNECTOR]: Failed to set last location for " + userID + ": " + response["Message"].AsString());
return success;
}
private PresenceInfo ResponseToPresenceInfo(OSDMap sessionResponse, OSDMap userResponse)
{
if (sessionResponse == null)
return null;
PresenceInfo info = new PresenceInfo();
info.Online = true;
info.UserID = sessionResponse["UserID"].AsUUID().ToString();
info.RegionID = sessionResponse["SceneID"].AsUUID();
info.Position = sessionResponse["ScenePosition"].AsVector3();
info.LookAt = sessionResponse["SceneLookAt"].AsVector3();
if (userResponse != null && userResponse["User"] is OSDMap)
{
OSDMap user = (OSDMap)userResponse["User"];
info.Login = user["LastLoginDate"].AsDate();
info.Logout = user["LastLogoutDate"].AsDate();
DeserializeLocation(user["HomeLocation"].AsString(), out info.HomeRegionID, out info.HomePosition, out info.HomeLookAt);
}
return info;
}
private string SerializeLocation(UUID regionID, Vector3 position, Vector3 lookAt)
{
return "{" + String.Format("\"SceneID\":\"{0}\",\"Position\":\"{1}\",\"LookAt\":\"{2}\"", regionID, position, lookAt) + "}";
}
private bool DeserializeLocation(string location, out UUID regionID, out Vector3 position, out Vector3 lookAt)
{
OSDMap map = null;
try { map = OSDParser.DeserializeJson(location) as OSDMap; }
catch { }
if (map != null)
{
regionID = map["SceneID"].AsUUID();
if (Vector3.TryParse(map["Position"].AsString(), out position) &&
Vector3.TryParse(map["LookAt"].AsString(), out lookAt))
{
return true;
}
}
regionID = UUID.Zero;
position = Vector3.Zero;
lookAt = Vector3.Zero;
return false;
}
#endregion Helpers
}
}

View File

@ -0,0 +1,432 @@
/*
* 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 System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework;
using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Avatar profile flags
/// </summary>
[Flags]
public enum ProfileFlags : uint
{
AllowPublish = 1,
MaturePublish = 2,
Identified = 4,
Transacted = 8,
Online = 16
}
/// <summary>
/// Connects avatar profile and classified queries to the SimianGrid
/// backend
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianProfiles : INonSharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private string m_serverUrl = String.Empty;
#region INonSharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void Close() { }
public SimianProfiles() { }
public string Name { get { return "SimianProfiles"; } }
public void AddRegion(Scene scene) { CheckEstateManager(scene); scene.EventManager.OnClientConnect += ClientConnectHandler; }
public void RemoveRegion(Scene scene) { scene.EventManager.OnClientConnect -= ClientConnectHandler; }
#endregion INonSharedRegionModule
public SimianProfiles(IConfigSource source)
{
Initialise(source);
}
public void Initialise(IConfigSource source)
{
IConfig gridConfig = source.Configs["UserAccountService"];
if (gridConfig == null)
{
m_log.Error("[PROFILES]: UserAccountService missing from OpenSim.ini");
throw new Exception("Profiles init error");
}
string serviceUrl = gridConfig.GetString("UserAccountServerURI");
if (String.IsNullOrEmpty(serviceUrl))
{
m_log.Error("[PROFILES]: No UserAccountServerURI in section UserAccountService");
throw new Exception("Profiles init error");
}
if (!serviceUrl.EndsWith("/"))
serviceUrl = serviceUrl + '/';
m_serverUrl = serviceUrl;
}
private void ClientConnectHandler(IClientCore clientCore)
{
if (clientCore is IClientAPI)
{
IClientAPI client = (IClientAPI)clientCore;
// Classifieds
client.AddGenericPacketHandler("avatarclassifiedsrequest", AvatarClassifiedsRequestHandler);
client.OnClassifiedInfoRequest += ClassifiedInfoRequestHandler;
client.OnClassifiedInfoUpdate += ClassifiedInfoUpdateHandler;
client.OnClassifiedDelete += ClassifiedDeleteHandler;
// Picks
client.AddGenericPacketHandler("avatarpicksrequest", HandleAvatarPicksRequest);
client.AddGenericPacketHandler("pickinforequest", HandlePickInfoRequest);
client.OnPickInfoUpdate += PickInfoUpdateHandler;
client.OnPickDelete += PickDeleteHandler;
// Notes
client.AddGenericPacketHandler("avatarnotesrequest", HandleAvatarNotesRequest);
client.OnAvatarNotesUpdate += AvatarNotesUpdateHandler;
// Profiles
client.OnRequestAvatarProperties += RequestAvatarPropertiesHandler;
client.OnUpdateAvatarProperties += UpdateAvatarPropertiesHandler;
client.OnAvatarInterestUpdate += AvatarInterestUpdateHandler;
client.OnUserInfoRequest += UserInfoRequestHandler;
client.OnUpdateUserInfo += UpdateUserInfoHandler;
}
}
#region Classifieds
private void AvatarClassifiedsRequestHandler(Object sender, string method, List<String> args)
{
if (!(sender is IClientAPI))
return;
IClientAPI client = (IClientAPI)sender;
UUID targetAvatarID;
if (args.Count < 1 || !UUID.TryParse(args[0], out targetAvatarID))
{
m_log.Error("[PROFILES]: Unrecognized arguments for " + method);
return;
}
// FIXME: Query the generic key/value store for classifieds
client.SendAvatarClassifiedReply(targetAvatarID, new Dictionary<UUID, string>(0));
}
private void ClassifiedInfoRequestHandler(UUID classifiedID, IClientAPI client)
{
// FIXME: Fetch this info
client.SendClassifiedInfoReply(classifiedID, UUID.Zero, 0, Utils.DateTimeToUnixTime(DateTime.UtcNow + TimeSpan.FromDays(1)),
0, String.Empty, String.Empty, UUID.Zero, 0, UUID.Zero, String.Empty, Vector3.Zero, String.Empty, 0, 0);
}
private void ClassifiedInfoUpdateHandler(UUID classifiedID, uint category, string name, string description,
UUID parcelID, uint parentEstate, UUID snapshotID, Vector3 globalPos, byte classifiedFlags, int price,
IClientAPI client)
{
// FIXME: Save this info
}
private void ClassifiedDeleteHandler(UUID classifiedID, IClientAPI client)
{
// FIXME: Delete the specified classified ad
}
#endregion Classifieds
#region Picks
private void HandleAvatarPicksRequest(Object sender, string method, List<String> args)
{
if (!(sender is IClientAPI))
return;
IClientAPI client = (IClientAPI)sender;
UUID targetAvatarID;
if (args.Count < 1 || !UUID.TryParse(args[0], out targetAvatarID))
{
m_log.Error("[PROFILES]: Unrecognized arguments for " + method);
return;
}
// FIXME: Fetch these
client.SendAvatarPicksReply(targetAvatarID, new Dictionary<UUID, string>(0));
}
private void HandlePickInfoRequest(Object sender, string method, List<String> args)
{
if (!(sender is IClientAPI))
return;
IClientAPI client = (IClientAPI)sender;
UUID avatarID;
UUID pickID;
if (args.Count < 2 || !UUID.TryParse(args[0], out avatarID) || !UUID.TryParse(args[1], out pickID))
{
m_log.Error("[PROFILES]: Unrecognized arguments for " + method);
return;
}
// FIXME: Fetch this
client.SendPickInfoReply(pickID, avatarID, false, UUID.Zero, String.Empty, String.Empty, UUID.Zero, String.Empty,
String.Empty, String.Empty, Vector3.Zero, 0, false);
}
private void PickInfoUpdateHandler(IClientAPI client, UUID pickID, UUID creatorID, bool topPick, string name,
string desc, UUID snapshotID, int sortOrder, bool enabled)
{
// FIXME: Save this
}
private void PickDeleteHandler(IClientAPI client, UUID pickID)
{
// FIXME: Delete
}
#endregion Picks
#region Notes
private void HandleAvatarNotesRequest(Object sender, string method, List<String> args)
{
if (!(sender is IClientAPI))
return;
IClientAPI client = (IClientAPI)sender;
UUID targetAvatarID;
if (args.Count < 1 || !UUID.TryParse(args[0], out targetAvatarID))
{
m_log.Error("[PROFILES]: Unrecognized arguments for " + method);
return;
}
// FIXME: Fetch this
client.SendAvatarNotesReply(targetAvatarID, String.Empty);
}
private void AvatarNotesUpdateHandler(IClientAPI client, UUID targetID, string notes)
{
// FIXME: Save this
}
#endregion Notes
#region Profiles
private void RequestAvatarPropertiesHandler(IClientAPI client, UUID avatarID)
{
OSDMap user = FetchUserData(avatarID);
ProfileFlags flags = ProfileFlags.AllowPublish | ProfileFlags.MaturePublish;
if (user != null)
{
OSDMap about = null;
if (user.ContainsKey("LLAbout"))
{
try { about = OSDParser.DeserializeJson(user["LLAbout"].AsString()) as OSDMap; }
catch { }
}
if (about == null)
about = new OSDMap(0);
// Check if this user is a grid operator
byte[] charterMember;
if (user["AccessLevel"].AsInteger() >= 200)
charterMember = Utils.StringToBytes("Operator");
else
charterMember = Utils.EmptyBytes;
// Check if the user is online
if (client.Scene is Scene)
{
OpenSim.Services.Interfaces.PresenceInfo[] presences = ((Scene)client.Scene).PresenceService.GetAgents(new string[] { avatarID.ToString() });
if (presences != null && presences.Length > 0)
flags |= ProfileFlags.Online;
}
// Check if the user is identified
if (user["Identified"].AsBoolean())
flags |= ProfileFlags.Identified;
client.SendAvatarProperties(avatarID, about["About"].AsString(), user["CreationDate"].AsDate().ToString("M/d/yyyy",
System.Globalization.CultureInfo.InvariantCulture), charterMember, about["FLAbout"].AsString(), (uint)flags,
about["FLImage"].AsUUID(), about["Image"].AsUUID(), about["URL"].AsString(), user["Partner"].AsUUID());
}
else
{
m_log.Warn("[PROFILES]: Failed to fetch profile information for " + client.Name + ", returning default values");
client.SendAvatarProperties(avatarID, String.Empty, "1/1/1970", Utils.EmptyBytes,
String.Empty, (uint)flags, UUID.Zero, UUID.Zero, String.Empty, UUID.Zero);
}
}
private void UpdateAvatarPropertiesHandler(IClientAPI client, UserProfileData profileData)
{
OSDMap map = new OSDMap
{
{ "About", OSD.FromString(profileData.AboutText) },
{ "Image", OSD.FromUUID(profileData.Image) },
{ "FLAbout", OSD.FromString(profileData.FirstLifeAboutText) },
{ "FLImage", OSD.FromUUID(profileData.FirstLifeImage) },
{ "URL", OSD.FromString(profileData.ProfileUrl) }
};
AddUserData(client.AgentId, "LLAbout", map);
}
private void AvatarInterestUpdateHandler(IClientAPI client, uint wantmask, string wanttext, uint skillsmask,
string skillstext, string languages)
{
OSDMap map = new OSDMap
{
{ "WantMask", OSD.FromInteger(wantmask) },
{ "WantText", OSD.FromString(wanttext) },
{ "SkillsMask", OSD.FromInteger(skillsmask) },
{ "SkillsText", OSD.FromString(skillstext) },
{ "Languages", OSD.FromString(languages) }
};
AddUserData(client.AgentId, "LLInterests", map);
}
private void UserInfoRequestHandler(IClientAPI client)
{
m_log.Error("[PROFILES]: UserInfoRequestHandler");
// Fetch this user's e-mail address
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "UserID", client.AgentId.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
string email = response["Email"].AsString();
if (!response["Success"].AsBoolean())
m_log.Warn("[PROFILES]: GetUser failed during a user info request for " + client.Name);
client.SendUserInfoReply(false, true, email);
}
private void UpdateUserInfoHandler(bool imViaEmail, bool visible, IClientAPI client)
{
m_log.Info("[PROFILES]: Ignoring user info update from " + client.Name);
}
#endregion Profiles
/// <summary>
/// Sanity checks regions for a valid estate owner at startup
/// </summary>
private void CheckEstateManager(Scene scene)
{
EstateSettings estate = scene.RegionInfo.EstateSettings;
if (estate.EstateOwner == UUID.Zero)
{
// Attempt to lookup the grid admin
UserAccount admin = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, UUID.Zero);
if (admin != null)
{
m_log.InfoFormat("[PROFILES]: Setting estate {0} (ID: {1}) owner to {2}", estate.EstateName,
estate.EstateID, admin.Name);
estate.EstateOwner = admin.PrincipalID;
estate.Save();
}
else
{
m_log.WarnFormat("[PROFILES]: Estate {0} (ID: {1}) does not have an owner", estate.EstateName, estate.EstateID);
}
}
}
private bool AddUserData(UUID userID, string key, OSDMap value)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddUserData" },
{ "UserID", userID.ToString() },
{ key, OSDParser.SerializeJsonString(value) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (!success)
m_log.WarnFormat("[PROFILES]: Failed to add user data with key {0} for {1}: {2}", key, userID, response["Message"].AsString());
return success;
}
private OSDMap FetchUserData(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean() && response["User"] is OSDMap)
{
return (OSDMap)response["User"];
}
else
{
m_log.Error("[PROFILES]: Failed to fetch user data for " + userID + ": " + response["Message"].AsString());
}
return null;
}
}
}

View File

@ -0,0 +1,307 @@
/*
* 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 System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Reflection;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
namespace OpenSim.Services.Connectors.SimianGrid
{
/// <summary>
/// Connects user account data (creating new users, looking up existing
/// users) to the SimianGrid backend
/// </summary>
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class SimianUserAccountServiceConnector : IUserAccountService, ISharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private string m_serverUrl = String.Empty;
private ExpiringCache<UUID, UserAccount> m_accountCache = new ExpiringCache<UUID, UserAccount>();
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void PostInitialise() { }
public void Close() { }
public SimianUserAccountServiceConnector() { }
public string Name { get { return "SimianUserAccountServiceConnector"; } }
public void AddRegion(Scene scene) { scene.RegisterModuleInterface<IUserAccountService>(this); }
public void RemoveRegion(Scene scene) { scene.UnregisterModuleInterface<IUserAccountService>(this); }
#endregion ISharedRegionModule
public SimianUserAccountServiceConnector(IConfigSource source)
{
Initialise(source);
}
public 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");
if (String.IsNullOrEmpty(serviceURI))
{
m_log.Error("[ACCOUNT CONNECTOR]: No UserAccountServerURI in section UserAccountService");
throw new Exception("User account connector init error");
}
m_serverUrl = serviceURI;
}
public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "Name", firstName + ' ' + lastName }
};
return GetUser(requestArgs);
}
public UserAccount GetUserAccount(UUID scopeID, string email)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "Email", email }
};
return GetUser(requestArgs);
}
public UserAccount GetUserAccount(UUID scopeID, UUID userID)
{
// Cache check
UserAccount account;
if (m_accountCache.TryGetValue(userID, out account))
return account;
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "UserID", userID.ToString() }
};
return GetUser(requestArgs);
}
public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
{
List<UserAccount> accounts = new List<UserAccount>();
m_log.DebugFormat("[ACCOUNT CONNECTOR]: Searching for user accounts with name query " + query);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUsers" },
{ "NameQuery", query }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDArray array = response["Users"] as OSDArray;
if (array != null && array.Count > 0)
{
for (int i = 0; i < array.Count; i++)
{
UserAccount account = ResponseToUserAccount(array[i] as OSDMap);
if (account != null)
accounts.Add(account);
}
}
else
{
m_log.Warn("[ACCOUNT CONNECTOR]: Account search failed, response data was in an invalid format");
}
}
else
{
m_log.Warn("[ACCOUNT CONNECTOR]: Failed to search for account data by name " + query);
}
return accounts;
}
public bool StoreUserAccount(UserAccount data)
{
m_log.InfoFormat("[ACCOUNT CONNECTOR]: Storing user account for " + data.Name);
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddUser" },
{ "UserID", data.PrincipalID.ToString() },
{ "Name", data.Name },
{ "Email", data.Email },
{ "AccessLevel", data.UserLevel.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
m_log.InfoFormat("[ACCOUNT CONNECTOR]: Storing user account data for " + data.Name);
requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddUserData" },
{ "UserID", data.PrincipalID.ToString() },
{ "CreationDate", data.Created.ToString() },
{ "UserFlags", data.UserFlags.ToString() },
{ "UserTitle", data.UserTitle }
};
response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (success)
{
// Cache the user account info
m_accountCache.AddOrUpdate(data.PrincipalID, data, DateTime.Now + TimeSpan.FromMinutes(2.0d));
}
else
{
m_log.Warn("[ACCOUNT CONNECTOR]: Failed to store user account data for " + data.Name + ": " + response["Message"].AsString());
}
return success;
}
else
{
m_log.Warn("[ACCOUNT CONNECTOR]: Failed to store user account for " + data.Name + ": " + response["Message"].AsString());
}
return false;
}
/// <summary>
/// Helper method for the various ways of retrieving a user account
/// </summary>
/// <param name="requestArgs">Service query parameters</param>
/// <returns>A UserAccount object on success, null on failure</returns>
private UserAccount GetUser(NameValueCollection requestArgs)
{
string lookupValue = (requestArgs.Count > 1) ? requestArgs[1] : "(Unknown)";
m_log.DebugFormat("[ACCOUNT CONNECTOR]: Looking up user account with query: " + lookupValue);
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap user = response["User"] as OSDMap;
if (user != null)
return ResponseToUserAccount(user);
else
m_log.Warn("[ACCOUNT CONNECTOR]: Account search failed, response data was in an invalid format");
}
else
{
m_log.Warn("[ACCOUNT CONNECTOR]: Failed to lookup user account with query: " + lookupValue);
}
return null;
}
/// <summary>
/// Convert a User object in LLSD format to a UserAccount
/// </summary>
/// <param name="response">LLSD containing user account data</param>
/// <returns>A UserAccount object on success, null on failure</returns>
private UserAccount ResponseToUserAccount(OSDMap response)
{
if (response == null)
return null;
UserAccount account = new UserAccount();
account.PrincipalID = response["UserID"].AsUUID();
account.Created = response["CreationDate"].AsInteger();
account.Email = response["Email"].AsString();
account.ServiceURLs = new Dictionary<string, object>(0);
account.UserFlags = response["UserFlags"].AsInteger();
account.UserLevel = response["AccessLevel"].AsInteger();
account.UserTitle = response["UserTitle"].AsString();
GetFirstLastName(response["Name"].AsString(), out account.FirstName, out account.LastName);
// Cache the user account info
m_accountCache.AddOrUpdate(account.PrincipalID, account, DateTime.Now + TimeSpan.FromMinutes(2.0d));
return account;
}
/// <summary>
/// Convert a name with a single space in it to a first and last name
/// </summary>
/// <param name="name">A full name such as "John Doe"</param>
/// <param name="firstName">First name</param>
/// <param name="lastName">Last name (surname)</param>
private static void GetFirstLastName(string name, out string firstName, out string lastName)
{
if (String.IsNullOrEmpty(name))
{
firstName = String.Empty;
lastName = String.Empty;
}
else
{
string[] names = name.Split(' ');
if (names.Length == 2)
{
firstName = names[0];
lastName = names[1];
}
else
{
firstName = String.Empty;
lastName = name;
}
}
}
}
}

View File

@ -1248,6 +1248,7 @@
;Include-HGStandalone = "config-include/StandaloneHypergrid.ini"
;Include-Grid = "config-include/Grid.ini"
;Include-HGGrid = "config-include/GridHypergrid.ini"
;Include-SimianGrid = "config-include/SimianGrid.ini"
; Then choose
; config-include/StandaloneCommon.ini.example (if you're in standlone) OR

View File

@ -0,0 +1,70 @@
[Modules]
GridServices = "OpenSim.Services.Connectors.dll:SimianGridServiceConnector"
PresenceServices = "OpenSim.Services.Connectors.dll:SimianPresenceServiceConnector"
UserAccountServices = "OpenSim.Services.Connectors.dll:SimianGridUserAccountServiceConnector"
AuthenticationServices = "OpenSim.Services.Connectors.dll:SimianAuthenticationServiceConnector"
AssetServices = "OpenSim.Services.Connectors.dll:SimianAssetServiceConnector"
InventoryServices = "OpenSim.Services.Connectors.dll:SimianInventoryServiceConnector"
AvatarServices = "OpenSim.Services.Connectors.dll:SimianAvatarServiceConnector"
NeighbourServices = "RemoteNeighbourServicesConnector"
SimulationServices = "RemoteSimulationConnectorModule"
EntityTransferModule = "BasicEntityTransferModule"
InventoryAccessModule = "BasicInventoryAccessModule"
LandServiceInConnector = true
NeighbourServiceInConnector = true
SimulationServiceInConnector = true
LibraryModule = false
AssetCaching = "FlotsamAssetCache"
[Friends]
Connector = "OpenSim.Services.Connectors.dll:SimianFriendsServiceConnector"
[GridService]
LocalServiceModule = "OpenSim.Services.GridService.dll:GridService"
StorageProvider = "OpenSim.Data.Null.dll:NullRegionData"
GridServerURI = "http://localhost/Grid/"
[LibraryService]
LocalServiceModule = "OpenSim.Services.InventoryService.dll:LibraryService"
LibraryName = "OpenSim Library"
DefaultLibrary = "./inventory/Libraries.xml"
[AssetService]
DefaultAssetLoader = "OpenSim.Framework.AssetLoader.Filesystem.dll"
AssetLoaderArgs = "assets/AssetSets.xml"
AssetServerURI = "http://localhost/Grid/?id="
[InventoryService]
InventoryServerURI = "http://localhost/Grid/"
[AvatarService]
AvatarServerURI = "http://localhost/Grid/"
[PresenceService]
PresenceServerURI = "http://localhost/Grid/"
[UserAccountService]
UserAccountServerURI = "http://localhost/Grid/"
[AuthenticationService]
AuthenticationServerURI = "http://localhost/Grid/"
[FriendsService]
FriendsServerURI = "http://localhost/Grid/"
[AssetCache]
CacheDirectory = ./assetcache
LogLevel = 0
HitRateDisplay = 100
MemoryCacheEnabled = false
; How long {in hours} to keep assets cached in memory, .5 == 30 minutes
MemoryCacheTimeout = 2
; How long {in hours} to keep assets cached on disk, .5 == 30 minutes
; Specify 0 if you do not want your disk cache to expire
FileCacheTimeout = 0
; How often {in hours} should the disk be checked for expired filed
; Specify 0 to disable expiration checking
FileCleanupTimer = 0 ;roughly every 10 minutes

View File

@ -929,7 +929,9 @@
<Reference name="OpenSim.Framework.Communications"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
<Reference name="OpenSim.Region.Framework"/>
<Reference name="OpenSim.Server.Base"/>
<Reference name="Mono.Addins" />
<Reference name="Nini.dll" />
<Reference name="log4net.dll"/>
<Reference name="XMLRPC.dll" />