replace GetDisplaynames by a handler really usable as a client cap. Most capabilities.handlers are so it all things not propor PER CLIENT CAP handlers

melanie
UbitUmarov 2016-12-04 15:50:48 +00:00
parent 2a29a270da
commit e1cf34d6fb
2 changed files with 84 additions and 143 deletions

View File

@ -29,9 +29,11 @@ using System;
using System.Timers; using System.Timers;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Web;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
@ -125,6 +127,8 @@ namespace OpenSim.Region.ClientStack.Linden
private bool m_AllowCapHomeLocation = true; private bool m_AllowCapHomeLocation = true;
private bool m_AllowCapGroupMemberData = true; private bool m_AllowCapGroupMemberData = true;
private IUserManagement m_UserManager;
private enum FileAgentInventoryState : int private enum FileAgentInventoryState : int
{ {
@ -196,6 +200,7 @@ namespace OpenSim.Region.ClientStack.Linden
m_assetService = m_Scene.AssetService; m_assetService = m_Scene.AssetService;
m_regionName = m_Scene.RegionInfo.RegionName; m_regionName = m_Scene.RegionInfo.RegionName;
m_UserManager = m_Scene.RequestModuleInterface<IUserManagement>();
RegisterHandlers(); RegisterHandlers();
@ -229,6 +234,7 @@ namespace OpenSim.Region.ClientStack.Linden
RegisterRegionServiceHandlers(); RegisterRegionServiceHandlers();
RegisterInventoryServiceHandlers(); RegisterInventoryServiceHandlers();
RegisterOtherHandlers();
} }
public void RegisterRegionServiceHandlers() public void RegisterRegionServiceHandlers()
@ -314,6 +320,19 @@ namespace OpenSim.Region.ClientStack.Linden
} }
} }
public void RegisterOtherHandlers()
{
try
{
IRequestHandler GetDisplayNamesHandler = new RestStreamHandler(
"GET", GetNewCapPath(), GetDisplayNames, "GetDisplayNames", null);
m_HostCapsObj.RegisterHandler("GetDisplayNames", GetDisplayNamesHandler);
}
catch (Exception e)
{
m_log.Error("[CAPS]: " + e.ToString());
}
}
/// <summary> /// <summary>
/// Construct a client response detailing all the capabilities this server can provide. /// Construct a client response detailing all the capabilities this server can provide.
/// </summary> /// </summary>
@ -1794,6 +1813,71 @@ namespace OpenSim.Region.ClientStack.Linden
response = OSDParser.SerializeLLSDXmlString(resp); response = OSDParser.SerializeLLSDXmlString(resp);
return response; return response;
} }
public string GetDisplayNames(string request, string path,
string param, IOSHttpRequest httpRequest,
IOSHttpResponse httpResponse)
{
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NoContent;
httpResponse.ContentType = "text/plain";
ScenePresence sp = m_Scene.GetScenePresence(m_AgentID);
if(sp == null || sp.IsDeleted)
return "";
NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
string[] ids = query.GetValues("ids");
if (m_UserManager == null)
{
m_log.Error("[GET_DISPLAY_NAMES]: Cannot fetch display names without a user management component");
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
return "";
}
Dictionary<UUID,string> names = m_UserManager.GetUsersNames(ids);
OSDMap osdReply = new OSDMap();
OSDArray agents = new OSDArray();
osdReply["agents"] = agents;
foreach (KeyValuePair<UUID,string> kvp in names)
{
if (string.IsNullOrEmpty(kvp.Value))
continue;
if(kvp.Key == UUID.Zero)
continue;
string[] parts = kvp.Value.Split(new char[] {' '});
OSDMap osdname = new OSDMap();
if(parts[0] == "Unknown")
{
osdname["display_name_next_update"] = OSD.FromDate(DateTime.UtcNow.AddHours(1));
osdname["display_name_expires"] = OSD.FromDate(DateTime.UtcNow.AddHours(2));
}
else
{
osdname["display_name_next_update"] = OSD.FromDate(DateTime.UtcNow.AddDays(8));
osdname["display_name_expires"] = OSD.FromDate(DateTime.UtcNow.AddMonths(1));
}
osdname["display_name"] = OSD.FromString(kvp.Value);
osdname["legacy_first_name"] = parts[0];
osdname["legacy_last_name"] = parts[1];
osdname["username"] = OSD.FromString(kvp.Value);
osdname["id"] = OSD.FromUUID(kvp.Key);
osdname["is_display_name_default"] = OSD.FromBoolean(true);
agents.Add(osdname);
}
// Full content request
httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK;
//httpResponse.ContentLength = ??;
httpResponse.ContentType = "application/llsd+xml";
string reply = OSDParser.SerializeLLSDXmlString(osdReply);
return reply;
}
} }
public class AssetUploader public class AssetUploader

View File

@ -1,143 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
using System.IO;
using System.Web;
using log4net;
using Nini.Config;
using Mono.Addins;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenMetaverse.Imaging;
using OpenSim.Framework;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using Caps = OpenSim.Framework.Capabilities.Caps;
using OpenSim.Capabilities.Handlers;
namespace OpenSim.Region.ClientStack.Linden
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetDisplayNamesModule")]
public class GetDisplayNamesModule : INonSharedRegionModule
{
private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected Scene m_scene;
protected IUserManagement m_UserManager;
protected bool m_Enabled = false;
protected string m_URL;
#region ISharedRegionModule Members
public virtual void Initialise(IConfigSource source)
{
IConfig config = source.Configs["ClientStack.LindenCaps"];
if (config == null)
return;
m_URL = config.GetString("Cap_GetDisplayNames", string.Empty);
if (m_URL != string.Empty)
m_Enabled = true;
}
public virtual void AddRegion(Scene s)
{
if (!m_Enabled)
return;
m_scene = s;
}
public virtual void RemoveRegion(Scene s)
{
if (!m_Enabled)
return;
m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
m_scene = null;
}
public virtual void RegionLoaded(Scene s)
{
if (!m_Enabled)
return;
m_UserManager = m_scene.RequestModuleInterface<IUserManagement>();
m_scene.EventManager.OnRegisterCaps += RegisterCaps;
}
public virtual void PostInitialise()
{
}
public virtual void Close() { }
public virtual string Name { get { return "GetDisplayNamesModule"; } }
public virtual Type ReplaceableInterface
{
get { return null; }
}
#endregion
public virtual void RegisterCaps(UUID agentID, Caps caps)
{
if (m_URL == "localhost")
{
string capUrl = "/CAPS/" + UUID.Random() + "/";
// m_log.DebugFormat("[GET_DISPLAY_NAMES]: {0} in region {1}", capUrl, m_scene.RegionInfo.RegionName);
caps.RegisterHandler(
"GetDisplayNames",
new GetDisplayNamesHandler(capUrl, m_UserManager, "GetDisplayNames", agentID.ToString()));
}
else
{
// m_log.DebugFormat("[GETTEXTURE]: {0} in region {1}", m_URL, m_scene.RegionInfo.RegionName);
IExternalCapsModule handler = m_scene.RequestModuleInterface<IExternalCapsModule>();
if (handler != null)
handler.RegisterExternalUserCapsHandler(agentID,caps,"GetDisplayNames", m_URL);
else
caps.RegisterHandler("GetDisplayNames", m_URL);
}
}
}
}