direct encode to llsdxml cap seeds response

This commit is contained in:
UbitUmarov
2024-04-17 16:09:57 +01:00
parent c8adcb66d0
commit b7e897f741
5 changed files with 106 additions and 48 deletions

View File

@@ -33,6 +33,7 @@ using System.Reflection;
using System.Threading;
using log4net;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.HttpServer;
@@ -68,6 +69,7 @@ namespace OpenSim.Framework.Capabilities
private readonly UUID m_agentID;
private readonly string m_regionName;
private ManualResetEvent m_capsActive = new(false);
private readonly string m_baseCapsURL;
public UUID AgentID
{
@@ -123,7 +125,8 @@ namespace OpenSim.Framework.Capabilities
ObjectAnim = 0x100,
WLEnv = 0x200,
AdvEnv = 0x400,
PBR = 0x800
PBR = 0x800,
ViewerBenefits = 0x1000
}
public CapsFlags Flags { get; set;}
@@ -149,6 +152,15 @@ namespace OpenSim.Framework.Capabilities
m_regionName = regionName;
Flags = CapsFlags.None;
m_capsActive.Reset();
if (MainServer.Instance.UseSSL)
m_baseCapsURL = $"https://{MainServer.Instance.SSLCommonName}:{MainServer.Instance.SSLPort}";
else
{
if (MainServer.Instance is null)
m_baseCapsURL = $"http://{m_httpListenerHostName}:0";
else
m_baseCapsURL = $"http://{m_httpListenerHostName}:{MainServer.Instance.Port}";
}
}
~Caps()
@@ -311,16 +323,7 @@ namespace OpenSim.Framework.Capabilities
{
if (!requestedCaps.Contains(kvp.Key))
continue;
if (MainServer.Instance.UseSSL)
caps[kvp.Key] = $"https://{MainServer.Instance.SSLCommonName}:{MainServer.Instance.SSLPort}{kvp.Value.Url}";
else
{
if(MainServer.Instance is null)
caps[kvp.Key] = $"http://{m_httpListenerHostName}:0{kvp.Value.Url}";
else
caps[kvp.Key] = $"http://{m_httpListenerHostName}:{MainServer.Instance.Port}{kvp.Value.Url}";
}
caps[kvp.Key] = m_baseCapsURL + kvp.Value.Url;
}
}
@@ -334,6 +337,28 @@ namespace OpenSim.Framework.Capabilities
return caps;
}
public void GetCapsDetailsLLSDxml(HashSet<string> requestedCaps, osUTF8 sb)
{
CapsHandlers.GetCapsDetailsLLSDxml(requestedCaps, sb);
lock (m_pollServiceHandlers)
{
foreach (KeyValuePair<string, PollServiceEventArgs> kvp in m_pollServiceHandlers)
{
if (requestedCaps.Contains(kvp.Key))
LLSDxmlEncode2.AddElem(kvp.Key, m_baseCapsURL + kvp.Value.Url, sb);
}
}
// Add the external too
foreach (KeyValuePair<string, string> kvp in ExternalCapsHandlers)
{
if (requestedCaps.Contains(kvp.Key))
LLSDxmlEncode2.AddElem(kvp.Key, kvp.Value, sb);
}
}
public void Activate()
{
m_capsActive.Set();

View File

@@ -30,6 +30,8 @@ using System.Collections.Generic;
using System.Collections.Concurrent;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.HttpServer;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
namespace OpenSim.Framework.Capabilities
{
@@ -46,6 +48,7 @@ namespace OpenSim.Framework.Capabilities
private string m_httpListenerHostName;
private uint m_httpListenerPort;
private bool m_useSSL = false;
private readonly string m_baseURL;
/// <summary></summary>
/// CapsHandlers is a cap handler container but also takes
@@ -61,9 +64,15 @@ namespace OpenSim.Framework.Capabilities
m_httpListenerHostName = httpListenerHostname;
m_httpListenerPort = httpListenerPort;
if (httpListener != null && httpListener.UseSSL)
{
m_useSSL = true;
m_baseURL = $"https://{m_httpListenerHostName}:{m_httpListenerPort}";
}
else
{
m_useSSL = false;
m_baseURL = $"http://{m_httpListenerHostName}:{m_httpListenerPort}";
}
}
/// <summary>
@@ -171,17 +180,14 @@ namespace OpenSim.Framework.Capabilities
{
Hashtable caps = new Hashtable();
string protocol = m_useSSL ? "https://" : "http://";
string baseUrl = protocol + m_httpListenerHostName + ":" + m_httpListenerPort.ToString();
if (requestedCaps == null)
{
lock (m_capsHandlers)
{
foreach (KeyValuePair<string, ISimpleStreamHandler> kvp in m_capsSimpleHandlers)
caps[kvp.Key] = baseUrl + kvp.Value.Path;
caps[kvp.Key] = m_baseURL + kvp.Value.Path;
foreach (KeyValuePair<string, IRequestHandler> kvp in m_capsHandlers)
caps[kvp.Key] = baseUrl + kvp.Value.Path;
caps[kvp.Key] = m_baseURL + kvp.Value.Path;
}
return caps;
}
@@ -196,12 +202,12 @@ namespace OpenSim.Framework.Capabilities
if (m_capsSimpleHandlers.TryGetValue(capsName, out ISimpleStreamHandler shdr))
{
caps[capsName] = baseUrl + shdr.Path;
caps[capsName] = m_baseURL + shdr.Path;
continue;
}
if (m_capsHandlers.TryGetValue(capsName, out IRequestHandler chdr))
{
caps[capsName] = baseUrl + chdr.Path;
caps[capsName] = m_baseURL + chdr.Path;
}
}
}
@@ -212,18 +218,14 @@ namespace OpenSim.Framework.Capabilities
public Hashtable GetCapsDetails2(bool excludeSeed, HashSet<string> requestedCaps)
{
Hashtable caps = new Hashtable();
string protocol = m_useSSL ? "https://" : "http://";
string baseUrl = protocol + m_httpListenerHostName + ":" + m_httpListenerPort.ToString();
if (requestedCaps is null)
{
lock (m_capsHandlers)
{
foreach (KeyValuePair<string, ISimpleStreamHandler> kvp in m_capsSimpleHandlers)
caps[kvp.Key] = baseUrl + kvp.Value.Path;
caps[kvp.Key] = m_baseURL + kvp.Value.Path;
foreach (KeyValuePair<string, IRequestHandler> kvp in m_capsHandlers)
caps[kvp.Key] = baseUrl + kvp.Value.Path;
caps[kvp.Key] = m_baseURL + kvp.Value.Path;
}
return caps;
}
@@ -236,20 +238,32 @@ namespace OpenSim.Framework.Capabilities
continue;
if (m_capsSimpleHandlers.TryGetValue(capsName, out ISimpleStreamHandler shdr))
{
caps[capsName] = baseUrl + shdr.Path;
continue;
}
if (m_capsHandlers.TryGetValue(capsName, out IRequestHandler chdr))
{
caps[capsName] = baseUrl + chdr.Path;
}
caps[capsName] = m_baseURL + shdr.Path;
else if (m_capsHandlers.TryGetValue(capsName, out IRequestHandler chdr))
caps[capsName] = m_baseURL + chdr.Path;
}
}
return caps;
}
public void GetCapsDetailsLLSDxml(HashSet<string> requestedCaps, osUTF8 sb)
{
lock (m_capsHandlers)
{
if (requestedCaps is null)
return;
foreach (string capsName in requestedCaps)
{
if (m_capsSimpleHandlers.TryGetValue(capsName, out ISimpleStreamHandler shdr))
LLSDxmlEncode2.AddElem(capsName, m_baseURL + shdr.Path, sb);
else if (m_capsHandlers.TryGetValue(capsName, out IRequestHandler chdr))
LLSDxmlEncode2.AddElem(capsName, m_baseURL + chdr.Path, sb);
}
}
}
/// <summary>
/// Returns a copy of the dictionary of all the HTTP cap handlers
/// </summary>

View File

@@ -304,9 +304,8 @@ namespace OpenSim.Region.ClientStack.Linden
/// <returns></returns>
public void SeedCapRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
UUID agentID = m_HostCapsObj.AgentID;
m_log.Debug(
$"[CAPS]: Received SEED caps request in {m_regionName} for agent {agentID}");
$"[CAPS]: Received SEED caps request in {m_regionName} for agent {m_HostCapsObj.AgentID}");
if(httpRequest.HttpMethod != "POST" || httpRequest.ContentType != "application/llsd+xml")
{
@@ -321,11 +320,10 @@ namespace OpenSim.Region.ClientStack.Linden
return;
}
if (!m_Scene.CheckClient(agentID, httpRequest.RemoteIPEndPoint))
if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint))
{
m_log.WarnFormat(
"[CAPS]: Unauthorized CAPS client {0} from {1}",
agentID, httpRequest.RemoteIPEndPoint);
$"[CAPS]: Unauthorized CAPS client {m_HostCapsObj.AgentID} from {httpRequest.RemoteIPEndPoint}");
httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
return;
}
@@ -346,19 +344,39 @@ namespace OpenSim.Region.ClientStack.Linden
foreach (OSD c in capsRequested)
{
string cstr = c.AsString();
if (cstr.Equals("ObjectAnimation"))
m_HostCapsObj.Flags |= Caps.CapsFlags.ObjectAnim;
else if (cstr.Equals("EnvironmentSettings"))
m_HostCapsObj.Flags |= Caps.CapsFlags.WLEnv;
else if (cstr.Equals("ExtEnvironment"))
m_HostCapsObj.Flags |= Caps.CapsFlags.AdvEnv;
else if(cstr.Equals("ModifyMaterialParams")) // will not work if a viewer has no edit features
m_HostCapsObj.Flags |= Caps.CapsFlags.PBR;
if (string.IsNullOrEmpty(cstr))
continue;
switch (cstr)
{
case "SEED":
continue;
case "ViewerBenefits": // this may need a proper cap but not currently
m_HostCapsObj.Flags |= Caps.CapsFlags.ViewerBenefits;
continue;
case "ObjectAnimation":
m_HostCapsObj.Flags |= Caps.CapsFlags.ObjectAnim;
break;
case "EnvironmentSettings":
m_HostCapsObj.Flags |= Caps.CapsFlags.WLEnv;
break;
case "ExtEnvironment":
m_HostCapsObj.Flags |= Caps.CapsFlags.AdvEnv;
break;
case "ModifyMaterialParams": // will not work if a viewer has no edit features
m_HostCapsObj.Flags |= Caps.CapsFlags.PBR;
break;
default:
break;
}
validCaps.Add(cstr);
}
osUTF8 sb = LLSDxmlEncode2.Start();
LLSDxmlEncode2.AddMap(sb);
m_HostCapsObj.GetCapsDetailsLLSDxml(validCaps, sb);
LLSDxmlEncode2.AddEndMap(sb);
string result = LLSDHelpers.SerialiseLLSDReply(m_HostCapsObj.GetCapsDetails2(true, validCaps));
httpResponse.RawBuffer = Util.UTF8NBGetbytes(result);
httpResponse.RawBuffer = LLSDxmlEncode2.EndToBytes(sb);
httpResponse.StatusCode = (int)HttpStatusCode.OK;
m_HostCapsObj.Flags |= Caps.CapsFlags.SentSeeds;

View File

@@ -346,7 +346,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
if (UUID.TryParse(friendID, out UUID _))
return base.FriendshipMessage(friendID);
return "Please confirm this friendship you made while you where on another HG grid";
return "Please confirm this friendship you made while you were on another HG grid";
}
protected override FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)

View File

@@ -298,6 +298,7 @@
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
<Reference name="OpenSim.Services.Interfaces"/>
<Reference name="OpenMetaverse"/>
<Reference name="OpenMetaverse.StructuredData"/>
<Reference name="OpenMetaverseTypes"/>
<Reference name="Nini"/>
<Reference name="log4net"/>