Some work in progress LLSD serialise / de-serialise functions.
parent
bc1862ecde
commit
49b9913210
|
@ -0,0 +1,173 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
|
using libsecondlife;
|
||||||
|
|
||||||
|
namespace OpenSim.Framework
|
||||||
|
{
|
||||||
|
public class LLSDHelpers
|
||||||
|
{
|
||||||
|
public static string SerialiseLLSDReply(object obj)
|
||||||
|
{
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
XmlTextWriter writer = new XmlTextWriter(sw);
|
||||||
|
writer.Formatting = Formatting.None;
|
||||||
|
writer.WriteStartElement(String.Empty, "llsd", String.Empty);
|
||||||
|
LLSDHelpers.SerializeLLSDType(writer, obj);
|
||||||
|
writer.WriteEndElement();
|
||||||
|
writer.Close();
|
||||||
|
return sw.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SerializeLLSDType(XmlTextWriter writer, object obj)
|
||||||
|
{
|
||||||
|
Type myType = obj.GetType();
|
||||||
|
LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false);
|
||||||
|
if (llsdattributes.Length > 0)
|
||||||
|
{
|
||||||
|
switch (llsdattributes[0].ObjectType)
|
||||||
|
{
|
||||||
|
case "MAP":
|
||||||
|
writer.WriteStartElement(String.Empty, "map", String.Empty);
|
||||||
|
System.Reflection.FieldInfo[] fields = myType.GetFields();
|
||||||
|
for (int i = 0; i < fields.Length; i++)
|
||||||
|
{
|
||||||
|
object fieldValue = fields[i].GetValue(obj);
|
||||||
|
LLSDType[] fieldAttributes = (LLSDType[])fieldValue.GetType().GetCustomAttributes(typeof(LLSDType), false);
|
||||||
|
if (fieldAttributes.Length > 0)
|
||||||
|
{
|
||||||
|
writer.WriteStartElement(String.Empty, "key", String.Empty);
|
||||||
|
writer.WriteString(fields[i].Name);
|
||||||
|
writer.WriteEndElement();
|
||||||
|
SerializeLLSDType(writer, fieldValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Console.WriteLine("LLSD field name" + fields[i].Name + " , " + fields[i].GetValue(obj).GetType());
|
||||||
|
writer.WriteStartElement(String.Empty, "key", String.Empty);
|
||||||
|
writer.WriteString(fields[i].Name);
|
||||||
|
writer.WriteEndElement();
|
||||||
|
LLSD.LLSDWriteOne(writer, fieldValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writer.WriteEndElement();
|
||||||
|
break;
|
||||||
|
case "ARRAY":
|
||||||
|
// LLSDArray arrayObject = obj as LLSDArray;
|
||||||
|
// ArrayList a = arrayObject.Array;
|
||||||
|
ArrayList a = (ArrayList)obj.GetType().GetField("Array").GetValue(obj);
|
||||||
|
writer.WriteStartElement(String.Empty, "array", String.Empty);
|
||||||
|
foreach (object item in a)
|
||||||
|
{
|
||||||
|
SerializeLLSDType(writer, item);
|
||||||
|
}
|
||||||
|
writer.WriteEndElement();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LLSD.LLSDWriteOne(writer, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object DeserialiseLLSDMap(Hashtable llsd, object obj)
|
||||||
|
{
|
||||||
|
Type myType = obj.GetType();
|
||||||
|
LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false);
|
||||||
|
if (llsdattributes.Length > 0)
|
||||||
|
{
|
||||||
|
switch (llsdattributes[0].ObjectType)
|
||||||
|
{
|
||||||
|
case "MAP":
|
||||||
|
IDictionaryEnumerator enumerator = llsd.GetEnumerator();
|
||||||
|
while (enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
System.Reflection.FieldInfo field = myType.GetField((string)enumerator.Key);
|
||||||
|
if (field != null)
|
||||||
|
{
|
||||||
|
field.SetValue(obj, enumerator.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[LLSDType("MAP")]
|
||||||
|
public class LLSDMapLayer
|
||||||
|
{
|
||||||
|
public int Left = 0;
|
||||||
|
public int Right = 0;
|
||||||
|
public int Top = 0;
|
||||||
|
public int Bottom = 0;
|
||||||
|
public LLUUID ImageID = LLUUID.Zero;
|
||||||
|
|
||||||
|
public LLSDArray TestArray = new LLSDArray();
|
||||||
|
public LLSDMapLayer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[LLSDType("ARRAY")]
|
||||||
|
public class LLSDArray
|
||||||
|
{
|
||||||
|
public ArrayList Array = new ArrayList();
|
||||||
|
|
||||||
|
public LLSDArray()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[LLSDType("MAP")]
|
||||||
|
public class LLSDMapRequest
|
||||||
|
{
|
||||||
|
public int Flags = 0;
|
||||||
|
|
||||||
|
public LLSDMapRequest()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[LLSDType("MAP")]
|
||||||
|
public class LLSDTest
|
||||||
|
{
|
||||||
|
public int Test1 = 20;
|
||||||
|
public int Test2 = 10;
|
||||||
|
|
||||||
|
public LLSDTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class LLSDType : Attribute
|
||||||
|
{
|
||||||
|
private string myHandler;
|
||||||
|
|
||||||
|
|
||||||
|
public LLSDType(string type)
|
||||||
|
{
|
||||||
|
myHandler = type;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ObjectType
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return myHandler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ProjectType>Local</ProjectType>
|
<ProjectType>Local</ProjectType>
|
||||||
<ProductVersion>8.0.50727</ProductVersion>
|
<ProductVersion>8.0.50727</ProductVersion>
|
||||||
|
@ -6,7 +6,8 @@
|
||||||
<ProjectGuid>{8ACA2445-0000-0000-0000-000000000000}</ProjectGuid>
|
<ProjectGuid>{8ACA2445-0000-0000-0000-000000000000}</ProjectGuid>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ApplicationIcon></ApplicationIcon>
|
<ApplicationIcon>
|
||||||
|
</ApplicationIcon>
|
||||||
<AssemblyKeyContainerName>
|
<AssemblyKeyContainerName>
|
||||||
</AssemblyKeyContainerName>
|
</AssemblyKeyContainerName>
|
||||||
<AssemblyName>OpenSim.Framework</AssemblyName>
|
<AssemblyName>OpenSim.Framework</AssemblyName>
|
||||||
|
@ -15,9 +16,11 @@
|
||||||
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
||||||
<DelaySign>false</DelaySign>
|
<DelaySign>false</DelaySign>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder></AppDesignerFolder>
|
<AppDesignerFolder>
|
||||||
|
</AppDesignerFolder>
|
||||||
<RootNamespace>OpenSim.Framework</RootNamespace>
|
<RootNamespace>OpenSim.Framework</RootNamespace>
|
||||||
<StartupObject></StartupObject>
|
<StartupObject>
|
||||||
|
</StartupObject>
|
||||||
<FileUpgradeFlags>
|
<FileUpgradeFlags>
|
||||||
</FileUpgradeFlags>
|
</FileUpgradeFlags>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -28,7 +31,8 @@
|
||||||
<ConfigurationOverrideFile>
|
<ConfigurationOverrideFile>
|
||||||
</ConfigurationOverrideFile>
|
</ConfigurationOverrideFile>
|
||||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||||
<DocumentationFile></DocumentationFile>
|
<DocumentationFile>
|
||||||
|
</DocumentationFile>
|
||||||
<DebugSymbols>True</DebugSymbols>
|
<DebugSymbols>True</DebugSymbols>
|
||||||
<FileAlignment>4096</FileAlignment>
|
<FileAlignment>4096</FileAlignment>
|
||||||
<Optimize>False</Optimize>
|
<Optimize>False</Optimize>
|
||||||
|
@ -37,7 +41,8 @@
|
||||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<NoWarn></NoWarn>
|
<NoWarn>
|
||||||
|
</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||||
|
@ -46,7 +51,8 @@
|
||||||
<ConfigurationOverrideFile>
|
<ConfigurationOverrideFile>
|
||||||
</ConfigurationOverrideFile>
|
</ConfigurationOverrideFile>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<DocumentationFile></DocumentationFile>
|
<DocumentationFile>
|
||||||
|
</DocumentationFile>
|
||||||
<DebugSymbols>False</DebugSymbols>
|
<DebugSymbols>False</DebugSymbols>
|
||||||
<FileAlignment>4096</FileAlignment>
|
<FileAlignment>4096</FileAlignment>
|
||||||
<Optimize>True</Optimize>
|
<Optimize>True</Optimize>
|
||||||
|
@ -55,22 +61,24 @@
|
||||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<NoWarn></NoWarn>
|
<NoWarn>
|
||||||
|
</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Db4objects.Db4o.dll" >
|
<Reference Include="Db4objects.Db4o.dll">
|
||||||
<HintPath>..\..\bin\Db4objects.Db4o.dll</HintPath>
|
<HintPath>..\..\bin\Db4objects.Db4o.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="libsecondlife.dll" >
|
<Reference Include="libsecondlife.dll">
|
||||||
<HintPath>..\..\bin\libsecondlife.dll</HintPath>
|
<HintPath>..\..\bin\libsecondlife.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" >
|
<Reference Include="System">
|
||||||
<HintPath>System.dll</HintPath>
|
<HintPath>System.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Xml" >
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml">
|
||||||
<HintPath>System.Xml.dll</HintPath>
|
<HintPath>System.Xml.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -102,6 +110,7 @@
|
||||||
<Compile Include="IRegionCommsListener.cs">
|
<Compile Include="IRegionCommsListener.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="LLSDHelpers.cs" />
|
||||||
<Compile Include="Logger.cs">
|
<Compile Include="Logger.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
<include name="AuthenticateSessionBase.cs" />
|
<include name="AuthenticateSessionBase.cs" />
|
||||||
<include name="BlockingQueue.cs" />
|
<include name="BlockingQueue.cs" />
|
||||||
<include name="IRegionCommsListener.cs" />
|
<include name="IRegionCommsListener.cs" />
|
||||||
|
<include name="LLSDHelpers.cs" />
|
||||||
<include name="Logger.cs" />
|
<include name="Logger.cs" />
|
||||||
<include name="LoginService.cs" />
|
<include name="LoginService.cs" />
|
||||||
<include name="RegionCommsListener.cs" />
|
<include name="RegionCommsListener.cs" />
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
using OpenSim.Servers;
|
using OpenSim.Servers;
|
||||||
|
using OpenSim.Framework;
|
||||||
using OpenSim.Framework.Utilities;
|
using OpenSim.Framework.Utilities;
|
||||||
using OpenSim.Framework.Types;
|
using OpenSim.Framework.Types;
|
||||||
using OpenSim.Caches;
|
using OpenSim.Caches;
|
||||||
|
@ -91,6 +94,11 @@ namespace OpenSim.Region
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string MapLayer(string request, string path, string param)
|
public string MapLayer(string request, string path, string param)
|
||||||
{
|
{
|
||||||
|
Encoding _enc = System.Text.Encoding.UTF8;
|
||||||
|
Hashtable hash =(Hashtable) LLSD.LLSDDeserialize(_enc.GetBytes(request));
|
||||||
|
LLSDMapRequest mapReq = new LLSDMapRequest();
|
||||||
|
LLSDHelpers.DeserialiseLLSDMap(hash, mapReq );
|
||||||
|
|
||||||
string res = "<llsd><map><key>AgentData</key><map><key>Flags</key><integer>0</integer></map><key>LayerData</key><array>";
|
string res = "<llsd><map><key>AgentData</key><map><key>Flags</key><integer>0</integer></map><key>LayerData</key><array>";
|
||||||
res += this.BuildLLSDMapLayerResponse();
|
res += this.BuildLLSDMapLayerResponse();
|
||||||
res += "</array></map></llsd>";
|
res += "</array></map></llsd>";
|
||||||
|
@ -152,9 +160,9 @@ namespace OpenSim.Region
|
||||||
res += "<key>events</key><array><map>";
|
res += "<key>events</key><array><map>";
|
||||||
res += "<key>message</key><string>EstablishAgentCommunication</string>";
|
res += "<key>message</key><string>EstablishAgentCommunication</string>";
|
||||||
res += "<key>body</key><map>";
|
res += "<key>body</key><map>";
|
||||||
res += "<key>sim-ip-and-port</key><string>"+ipAddressPort +"</string>";
|
res += "<key>sim-ip-and-port</key><string>" + ipAddressPort + "</string>";
|
||||||
res += "<key>seed-capability</key><string>"+caps+"</string>";
|
res += "<key>seed-capability</key><string>" + caps + "</string>";
|
||||||
res += "<key>agent-id</key><uuid>"+this.agentID.ToStringHyphenated()+"</uuid>";
|
res += "<key>agent-id</key><uuid>" + this.agentID.ToStringHyphenated() + "</uuid>";
|
||||||
res += "</map>";
|
res += "</map>";
|
||||||
res += "</map></array>";
|
res += "</map></array>";
|
||||||
res += "</map></llsd>";
|
res += "</map></llsd>";
|
||||||
|
|
Loading…
Reference in New Issue