public LLSD GetLLSD() { LLSDMap permissions = new LLSDMap(5); permissions["BaseMask"] = LLSD.FromUInteger((uint)BaseMask); permissions["EveryoneMask"] = LLSD.FromUInteger((uint)EveryoneMask); permissions["GroupMask"] = LLSD.FromUInteger((uint)GroupMask); permissions["NextOwnerMask"] = LLSD.FromUInteger((uint)NextOwnerMask); permissions["OwnerMask"] = LLSD.FromUInteger((uint)OwnerMask); return(permissions); }
public LLSD ToLLSD() { LLSDMap map = new LLSDMap(); map["color"] = Color.ToLLSD(); map["intensity"] = LLSD.FromReal(Intensity); map["radius"] = LLSD.FromReal(Radius); map["cutoff"] = LLSD.FromReal(Cutoff); map["falloff"] = LLSD.FromReal(Falloff); return(map); }
public LLSD ToLLSD() { LLSDMap path = new LLSDMap(14); path["begin"] = LLSD.FromReal(Data.PathBegin); path["curve"] = LLSD.FromInteger((int)Data.PathCurve); path["end"] = LLSD.FromReal(Data.PathEnd); path["radius_offset"] = LLSD.FromReal(Data.PathRadiusOffset); path["revolutions"] = LLSD.FromReal(Data.PathRevolutions); path["scale_x"] = LLSD.FromReal(Data.PathScaleX); path["scale_y"] = LLSD.FromReal(Data.PathScaleY); path["shear_x"] = LLSD.FromReal(Data.PathShearX); path["shear_y"] = LLSD.FromReal(Data.PathShearY); path["skew"] = LLSD.FromReal(Data.PathSkew); path["taper_x"] = LLSD.FromReal(Data.PathTaperX); path["taper_y"] = LLSD.FromReal(Data.PathTaperY); path["twist"] = LLSD.FromReal(Data.PathTwist); path["twist_begin"] = LLSD.FromReal(Data.PathTwistBegin); LLSDMap profile = new LLSDMap(4); profile["begin"] = LLSD.FromReal(Data.ProfileBegin); profile["curve"] = LLSD.FromInteger((int)Data.ProfileCurve); profile["hole"] = LLSD.FromInteger((int)Data.ProfileHole); profile["end"] = LLSD.FromReal(Data.ProfileEnd); profile["hollow"] = LLSD.FromReal(Data.ProfileHollow); LLSDMap volume = new LLSDMap(2); volume["path"] = path; volume["profile"] = profile; LLSDMap prim = new LLSDMap(9); prim["phantom"] = LLSD.FromBoolean(((Flags & ObjectFlags.Phantom) != 0)); prim["physical"] = LLSD.FromBoolean(((Flags & ObjectFlags.Physics) != 0)); prim["position"] = Position.ToLLSD(); prim["rotation"] = Rotation.ToLLSD(); prim["scale"] = Scale.ToLLSD(); prim["shadows"] = LLSD.FromBoolean(((Flags & ObjectFlags.CastShadows) != 0)); prim["textures"] = Textures.ToLLSD(); prim["volume"] = volume; if (ParentID != 0) { prim["parentid"] = LLSD.FromInteger(ParentID); } prim["light"] = Light.ToLLSD(); prim["flex"] = Flexible.ToLLSD(); prim["sculpt"] = Sculpt.ToLLSD(); return(prim); }
/// <summary> /// Attempts to convert an LLSD structure to a known Packet type /// </summary> /// <param name="capsEventName">Event name, this must match an actual /// packet name for a Packet to be successfully built</param> /// <param name="body">LLSD to convert to a Packet</param> /// <returns>A Packet on success, otherwise null</returns> public static Packet BuildPacket(string capsEventName, LLSDMap body) { Assembly assembly = Assembly.GetExecutingAssembly(); // Check if we have a subclass of packet with the same name as this event Type type = assembly.GetType("OpenMetaverse.Packets." + capsEventName + "Packet", false); if (type == null) return null; Packet packet = null; try { // Create an instance of the object packet = (Packet)Activator.CreateInstance(type); // Iterate over all of the fields in the packet class, looking for matches in the LLSD foreach (FieldInfo field in type.GetFields()) { if (body.ContainsKey(field.Name)) { Type blockType = field.FieldType; if (blockType.IsArray) { LLSDArray array = (LLSDArray)body[field.Name]; Type elementType = blockType.GetElementType(); object[] blockArray = (object[])Array.CreateInstance(elementType, array.Count); for (int i = 0; i < array.Count; i++) { LLSDMap map = (LLSDMap)array[i]; blockArray[i] = ParseLLSDBlock(map, elementType); } field.SetValue(packet, blockArray); } else { LLSDMap map = (LLSDMap)((LLSDArray)body[field.Name])[0]; field.SetValue(packet, ParseLLSDBlock(map, blockType)); } } } } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, e); } return packet; }
public static string ParseString(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) { return(llsd.AsString()); } else { return(String.Empty); } }
public static LLUUID ParseUUID(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) { return(llsd.AsUUID()); } else { return(LLUUID.Zero); } }
public static uint ParseUInt(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) { return((uint)llsd.AsInteger()); } else { return(0); } }
private void ProvisionCapsResponse(CapsClient client, LLSD response, Exception error) { if (response is LLSDMap) { LLSDMap respTable = (LLSDMap)response; if (OnProvisionAccount != null) { try { OnProvisionAccount(respTable["username"].AsString(), respTable["password"].AsString()); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } } }
/// <summary> /// /// </summary> /// <returns></returns> public LLSD ToLLSD() { LLSDMap map = new LLSDMap(); map["simulate_lod"] = LLSD.FromInteger(Softness); map["gravity"] = LLSD.FromReal(Gravity); map["air_friction"] = LLSD.FromReal(Drag); map["wind_sensitivity"] = LLSD.FromReal(Wind); map["tension"] = LLSD.FromReal(Tension); map["user_force"] = Force.ToLLSD(); return(map); }
/// <summary> /// /// </summary> /// <param name="layer"></param> public void RequestMapLayer(GridLayerType layer) { Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("MapLayer"); if (url != null) { LLSDMap body = new LLSDMap(); body["Flags"] = LLSD.FromInteger((int)layer); CapsClient request = new CapsClient(url); request.OnComplete += new CapsClient.CompleteCallback(MapLayerResponseHandler); request.StartRequest(body); } }
public static SculptData FromLLSD(LLSD llsd) { SculptData sculpt = new SculptData(); if (llsd.Type == LLSDType.Map) { LLSDMap map = (LLSDMap)llsd; sculpt.SculptTexture = map["texture"].AsUUID(); sculpt.Type = (SculptType)map["type"].AsInteger(); } return(sculpt); }
public static LightData FromLLSD(LLSD llsd) { LightData light = new LightData(); if (llsd.Type == LLSDType.Map) { LLSDMap map = (LLSDMap)llsd; light.Color.FromLLSD(map["color"]); light.Intensity = (float)map["intensity"].AsReal(); light.Radius = (float)map["radius"].AsReal(); light.Cutoff = (float)map["cutoff"].AsReal(); light.Falloff = (float)map["falloff"].AsReal(); } return(light); }
public void SerializeNestedComposite() { LLSDArray llsdNested = new LLSDArray(); LLSDMap llsdMap = new LLSDMap(); LLSDArray llsdArray = new LLSDArray(); llsdArray.Add(LLSD.FromInteger(1)); llsdArray.Add(LLSD.FromInteger(2)); llsdMap["t0st"] = llsdArray; llsdMap["test"] = LLSD.FromString("what"); llsdNested.Add(llsdMap); llsdNested.Add(LLSD.FromInteger(124)); llsdNested.Add(LLSD.FromInteger(987)); byte[] binaryNestedSerialized = LLSDParser.SerializeBinary(llsdNested); // Because maps don't preserve order, we compare here to a deserialized value. LLSDArray llsdNestedDeserialized = (LLSDArray)LLSDParser.DeserializeBinary(binaryNestedSerialized); Assert.AreEqual(LLSDType.Array, llsdNestedDeserialized.Type); Assert.AreEqual(3, llsdNestedDeserialized.Count); LLSDMap llsdMapDeserialized = (LLSDMap)llsdNestedDeserialized[0]; Assert.AreEqual(LLSDType.Map, llsdMapDeserialized.Type); Assert.AreEqual(2, llsdMapDeserialized.Count); Assert.AreEqual(LLSDType.Array, llsdMapDeserialized["t0st"].Type); LLSDArray llsdNestedArray = (LLSDArray)llsdMapDeserialized["t0st"]; Assert.AreEqual(LLSDType.Array, llsdNestedArray.Type); Assert.AreEqual(2, llsdNestedArray.Count); Assert.AreEqual(LLSDType.Integer, llsdNestedArray[0].Type); Assert.AreEqual(1, llsdNestedArray[0].AsInteger()); Assert.AreEqual(LLSDType.Integer, llsdNestedArray[1].Type); Assert.AreEqual(2, llsdNestedArray[1].AsInteger()); Assert.AreEqual(LLSDType.String, llsdMapDeserialized["test"].Type); Assert.AreEqual("what", llsdMapDeserialized["test"].AsString()); Assert.AreEqual(LLSDType.Integer, llsdNestedDeserialized[1].Type); Assert.AreEqual(124, llsdNestedDeserialized[1].AsInteger()); Assert.AreEqual(LLSDType.Integer, llsdNestedDeserialized[2].Type); Assert.AreEqual(987, llsdNestedDeserialized[2].AsInteger()); }
public static Permissions FromLLSD(LLSD llsd) { Permissions permissions = new Permissions(); LLSDMap map = (LLSDMap)llsd; byte[] bytes = map["BaseMask"].AsBinary(); permissions.BaseMask = (PermissionMask)Utils.BytesToUInt(bytes); bytes = map["EveryoneMask"].AsBinary(); permissions.EveryoneMask = (PermissionMask)Utils.BytesToUInt(bytes); bytes = map["GroupMask"].AsBinary(); permissions.GroupMask = (PermissionMask)Utils.BytesToUInt(bytes); bytes = map["NextOwnerMask"].AsBinary(); permissions.NextOwnerMask = (PermissionMask)Utils.BytesToUInt(bytes); bytes = map["OwnerMask"].AsBinary(); permissions.OwnerMask = (PermissionMask)Utils.BytesToUInt(bytes); return(permissions); }
public static FlexibleData FromLLSD(LLSD llsd) { FlexibleData flex = new FlexibleData(); if (llsd.Type == LLSDType.Map) { LLSDMap map = (LLSDMap)llsd; flex.Softness = map["simulate_lod"].AsInteger(); flex.Gravity = (float)map["gravity"].AsReal(); flex.Drag = (float)map["air_friction"].AsReal(); flex.Wind = (float)map["wind_sensitivity"].AsReal(); flex.Tension = (float)map["tension"].AsReal(); flex.Force.FromLLSD(map["user_force"]); } return(flex); }
public void Start(Simian server) { this.server = server; LLSD llsd; try { XmlTextReader reader = new XmlTextReader(File.OpenRead(server.DataDir + "simiandata.xml")); llsd = LLSDParser.DeserializeXml(reader); reader.Close(); } catch (FileNotFoundException) { return; } catch (Exception ex) { Logger.Log("Failed to load saved data: " + ex.Message, Helpers.LogLevel.Error); return; } if (llsd is LLSDMap) { LLSDMap dictionary = (LLSDMap)llsd; for (int i = 0; i < server.PersistentExtensions.Count; i++) { IPersistable persistable = server.PersistentExtensions[i]; LLSD savedData; if (dictionary.TryGetValue(persistable.ToString(), out savedData)) { Logger.DebugLog("Loading saved data for " + persistable.ToString()); persistable.Deserialize(savedData); } else { Logger.DebugLog("No saved data found for " + persistable.ToString()); } } } }
public static Vector3 ParseVector3(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) { if (llsd.Type == LLSDType.Array) { return(((LLSDArray)llsd).AsVector3()); } else if (llsd.Type == LLSDType.String) { LLSDArray array = (LLSDArray)LLSDParser.DeserializeNotation(llsd.AsString()); return(array.AsVector3()); } } return(Vector3.Zero); }
public void DeserializeMap() { string sMapOne = " { } "; LLSDMap llsdMapOne = (LLSDMap)LLSDParser.DeserializeNotation(sMapOne); Assert.AreEqual(LLSDType.Map, llsdMapOne.Type); Assert.AreEqual(0, llsdMapOne.Count); string sMapTwo = " { \"test\":i2 } "; LLSDMap llsdMapTwo = (LLSDMap)LLSDParser.DeserializeNotation(sMapTwo); Assert.AreEqual(LLSDType.Map, llsdMapTwo.Type); Assert.AreEqual(1, llsdMapTwo.Count); Assert.AreEqual(LLSDType.Integer, llsdMapTwo["test"].Type); Assert.AreEqual(2, llsdMapTwo["test"].AsInteger()); string sMapThree = " { 'test':\"testtesttest\", 'aha':\"muahahaha\" , \"anywhere\":! } "; LLSDMap llsdMapThree = (LLSDMap)LLSDParser.DeserializeNotation(sMapThree); Assert.AreEqual(LLSDType.Map, llsdMapThree.Type); Assert.AreEqual(3, llsdMapThree.Count); Assert.AreEqual(LLSDType.String, llsdMapThree["test"].Type); Assert.AreEqual("testtesttest", llsdMapThree["test"].AsString()); Assert.AreEqual(LLSDType.String, llsdMapThree["test"].Type); Assert.AreEqual("muahahaha", llsdMapThree["aha"].AsString()); Assert.AreEqual(LLSDType.Unknown, llsdMapThree["self"].Type); string sMapFour = " { 'test' : { 'test' : i1, 't0st' : r2.5 }, 'tist' : \"hello world!\", 'tast' : \"last\" } "; LLSDMap llsdMapFour = (LLSDMap)LLSDParser.DeserializeNotation(sMapFour); Assert.AreEqual(LLSDType.Map, llsdMapFour.Type); Assert.AreEqual(3, llsdMapFour.Count); Assert.AreEqual("hello world!", llsdMapFour["tist"].AsString()); Assert.AreEqual("last", llsdMapFour["tast"].AsString()); LLSDMap llsdMapFive = (LLSDMap)llsdMapFour["test"]; Assert.AreEqual(LLSDType.Map, llsdMapFive.Type); Assert.AreEqual(2, llsdMapFive.Count); Assert.AreEqual(LLSDType.Integer, llsdMapFive["test"].Type); Assert.AreEqual(1, llsdMapFive["test"].AsInteger()); Assert.AreEqual(LLSDType.Real, llsdMapFive["t0st"].Type); Assert.AreEqual(2.5d, llsdMapFive["t0st"].AsReal()); }
private void GatherCapsResponse(CapsClient client, LLSD response, Exception error) { if (response is LLSDMap) { LLSDMap respTable = (LLSDMap)response; // parse _caps = new RegistrationCaps(); _caps.CreateUser = respTable["create_user"].AsUri(); _caps.CheckName = respTable["check_name"].AsUri(); _caps.GetLastNames = respTable["get_last_names"].AsUri(); _caps.GetErrorCodes = respTable["get_error_codes"].AsUri(); // finalize _initializing++; GatherErrorMessages(); } }
private void RequiredVoiceVersionEventHandler(string message, LLSD llsd, Simulator simulator) { LLSDMap body = (LLSDMap)llsd; if (body.ContainsKey("major_version")) { int majorVersion = body["major_version"].AsInteger(); if (VOICE_MAJOR_VERSION != majorVersion) { Logger.Log(String.Format("Voice version mismatch! Got {0}, expecting {1}. Disabling the voice manager", majorVersion, VOICE_MAJOR_VERSION), Helpers.LogLevel.Error, Client); Enabled = false; } else { Logger.DebugLog("Voice version " + majorVersion + " verified", Client); } } }
public static LLUUID ParseMappedUUID(string key, string key2, LLSDMap reply) { LLSD folderLLSD; if (reply.TryGetValue(key, out folderLLSD) && folderLLSD.Type == LLSDType.Array) { LLSDArray array = (LLSDArray)folderLLSD; if (array.Count == 1 && array[0].Type == LLSDType.Map) { LLSDMap map = (LLSDMap)array[0]; LLSD folder; if (map.TryGetValue(key2, out folder)) { return(folder.AsUUID()); } } } return(LLUUID.Zero); }
public void SerializeLongMessage() { // each 80 chars string sOne = "asdklfjasadlfkjaerotiudfgjkhsdklgjhsdklfghasdfklhjasdfkjhasdfkljahsdfjklaasdfkj8"; string sTwo = "asdfkjlaaweoiugsdfjkhsdfg,.mnasdgfkljhrtuiohfglökajsdfoiwghjkdlaaaaseldkfjgheus9"; LLSD stringOne = LLSD.FromString(sOne); LLSD stringTwo = LLSD.FromString(sTwo); LLSDMap llsdMap = new LLSDMap(); llsdMap["testOne"] = stringOne; llsdMap["testTwo"] = stringTwo; llsdMap["testThree"] = stringOne; llsdMap["testFour"] = stringTwo; llsdMap["testFive"] = stringOne; llsdMap["testSix"] = stringTwo; llsdMap["testSeven"] = stringOne; llsdMap["testEight"] = stringTwo; llsdMap["testNine"] = stringOne; llsdMap["testTen"] = stringTwo; byte[] binaryData = LLSDParser.SerializeBinary(llsdMap); LLSDMap llsdMapDS = (LLSDMap)LLSDParser.DeserializeBinary(binaryData); Assert.AreEqual(LLSDType.Map, llsdMapDS.Type); Assert.AreEqual(10, llsdMapDS.Count); Assert.AreEqual(sOne, llsdMapDS["testOne"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testTwo"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testThree"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testFour"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testFive"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testSix"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testSeven"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testEight"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testNine"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testTen"].AsString()); }
public void LLSDTerseParsing() { string testOne = "[r0.99967899999999998428,r-0.025334599999999998787,r0]"; string testTwo = "[[r1,r1,r1],r0]"; string testThree = "{'region_handle':[r255232, r256512], 'position':[r33.6, r33.71, r43.13], 'look_at':[r34.6, r33.71, r43.13]}"; LLSD obj = LLSDParser.DeserializeNotation(testOne); Assert.IsInstanceOfType(typeof(LLSDArray), obj, "Expected LLSDArray, got " + obj.GetType().ToString()); LLSDArray array = (LLSDArray)obj; Assert.IsTrue(array.Count == 3, "Expected three contained objects, got " + array.Count); Assert.IsTrue(array[0].AsReal() > 0.9d && array[0].AsReal() < 1.0d, "Unexpected value for first real " + array[0].AsReal()); Assert.IsTrue(array[1].AsReal() < 0.0d && array[1].AsReal() > -0.03d, "Unexpected value for second real " + array[1].AsReal()); Assert.IsTrue(array[2].AsReal() == 0.0d, "Unexpected value for third real " + array[2].AsReal()); obj = LLSDParser.DeserializeNotation(testTwo); Assert.IsInstanceOfType(typeof(LLSDArray), obj, "Expected LLSDArray, got " + obj.GetType().ToString()); array = (LLSDArray)obj; Assert.IsTrue(array.Count == 2, "Expected two contained objects, got " + array.Count); Assert.IsTrue(array[1].AsReal() == 0.0d, "Unexpected value for real " + array[1].AsReal()); obj = array[0]; Assert.IsInstanceOfType(typeof(LLSDArray), obj, "Expected ArrayList, got " + obj.GetType().ToString()); array = (LLSDArray)obj; Assert.IsTrue(array[0].AsReal() == 1.0d && array[1].AsReal() == 1.0d && array[2].AsReal() == 1.0d, "Unexpected value(s) for nested array: " + array[0].AsReal() + ", " + array[1].AsReal() + ", " + array[2].AsReal()); obj = LLSDParser.DeserializeNotation(testThree); Assert.IsInstanceOfType(typeof(LLSDMap), obj, "Expected LLSDMap, got " + obj.GetType().ToString()); LLSDMap hashtable = (LLSDMap)obj; Assert.IsTrue(hashtable.Count == 3, "Expected three contained objects, got " + hashtable.Count); Assert.IsInstanceOfType(typeof(LLSDArray), hashtable["region_handle"]); Assert.IsTrue(((LLSDArray)hashtable["region_handle"]).Count == 2); Assert.IsInstanceOfType(typeof(LLSDArray), hashtable["position"]); Assert.IsTrue(((LLSDArray)hashtable["position"]).Count == 3); Assert.IsInstanceOfType(typeof(LLSDArray), hashtable["look_at"]); Assert.IsTrue(((LLSDArray)hashtable["look_at"]).Count == 3); }
public void DeserializeNestedComposite() { LLSD llsdNested = LLSDParser.DeserializeBinary(binaryNested); Assert.AreEqual(LLSDType.Array, llsdNested.Type); LLSDArray llsdArray = (LLSDArray)llsdNested; Assert.AreEqual(3, llsdArray.Count); LLSDMap llsdMap = (LLSDMap)llsdArray[0]; Assert.AreEqual(LLSDType.Map, llsdMap.Type); Assert.AreEqual(2, llsdMap.Count); LLSDArray llsdNestedArray = (LLSDArray)llsdMap["t0st"]; Assert.AreEqual(LLSDType.Array, llsdNestedArray.Type); LLSDInteger llsdNestedIntOne = (LLSDInteger)llsdNestedArray[0]; Assert.AreEqual(LLSDType.Integer, llsdNestedIntOne.Type); Assert.AreEqual(1, llsdNestedIntOne.AsInteger()); LLSDInteger llsdNestedIntTwo = (LLSDInteger)llsdNestedArray[1]; Assert.AreEqual(LLSDType.Integer, llsdNestedIntTwo.Type); Assert.AreEqual(2, llsdNestedIntTwo.AsInteger()); LLSDString llsdString = (LLSDString)llsdMap["test"]; Assert.AreEqual(LLSDType.String, llsdString.Type); Assert.AreEqual("what", llsdString.AsString()); LLSDInteger llsdIntOne = (LLSDInteger)llsdArray[1]; Assert.AreEqual(LLSDType.Integer, llsdIntOne.Type); Assert.AreEqual(124, llsdIntOne.AsInteger()); LLSDInteger llsdIntTwo = (LLSDInteger)llsdArray[2]; Assert.AreEqual(LLSDType.Integer, llsdIntTwo.Type); Assert.AreEqual(987, llsdIntTwo.AsInteger()); }
private void ParcelVoiceInfoResponse(CapsClient client, LLSD response, Exception error) { if (response is LLSDMap) { LLSDMap respTable = (LLSDMap)response; string regionName = respTable["region_name"].AsString(); int localID = (int)respTable["parcel_local_id"].AsInteger(); string channelURI = null; if (respTable["voice_credentials"] is LLSDMap) { LLSDMap creds = (LLSDMap)respTable["voice_credentials"]; channelURI = creds["channel_uri"].AsString(); } if (OnParcelVoiceInfo != null) { OnParcelVoiceInfo(regionName, localID, channelURI); } } }
private void GatherLastNamesResponse(CapsClient client, LLSD response, Exception error) { if (response is LLSDMap) { LLSDMap respTable = (LLSDMap)response; //FIXME: //_lastNames = new List<LastName>(respTable.Count); //for (Dictionary<string, object>.Enumerator it = respTable.GetEnumerator(); it.MoveNext(); ) //{ // LastName ln = new LastName(); // ln.ID = int.Parse(it.Current.Key.ToString()); // ln.Name = it.Current.Value.ToString(); // _lastNames.Add(ln); //} //_lastNames.Sort(new Comparison<LastName>(delegate(LastName a, LastName b) { return a.Name.CompareTo(b.Name); })); } }
public static TextureEntryFace FromLLSD(LLSD llsd, TextureEntryFace defaultFace, out int faceNumber) { LLSDMap map = (LLSDMap)llsd; TextureEntryFace face = new TextureEntryFace(defaultFace); faceNumber = (map.ContainsKey("face_number")) ? map["face_number"].AsInteger() : -1; face.RGBA = LLColor.FromLLSD(map["colors"]); face.RepeatU = (float)map["scales"].AsReal(); face.RepeatV = (float)map["scalet"].AsReal(); face.OffsetU = (float)map["offsets"].AsReal(); face.OffsetV = (float)map["offsett"].AsReal(); face.Rotation = (float)map["imagerot"].AsReal(); face.Bump = (Bumpiness)map["bump"].AsInteger(); face.Shiny = (Shininess)map["shiny"].AsInteger(); face.Fullbright = map["fullbright"].AsBoolean(); face.MediaFlags = map["media_flags"].AsBoolean(); face.TexMapType = (MappingType)map["mapping"].AsInteger(); face.Glow = (float)map["glow"].AsReal(); face.TextureID = map["imageid"].AsUUID(); return(face); }
public static LLVector3 ParseLLVector3(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) { if (llsd.Type == LLSDType.Array) { LLVector3 vec = new LLVector3(); vec.FromLLSD(llsd); return(vec); } else if (llsd.Type == LLSDType.String) { LLSDArray array = (LLSDArray)LLSDParser.DeserializeNotation(llsd.AsString()); LLVector3 vec = new LLVector3(); vec.FromLLSD(array); return(vec); } } return(LLVector3.Zero); }
private static LLSD BuildLLSDBlock(object block) { LLSDMap map = new LLSDMap(); Type blockType = block.GetType(); foreach (FieldInfo field in blockType.GetFields()) { if (field.IsPublic) { map[field.Name] = LLSD.FromObject(field.GetValue(block)); } } foreach (PropertyInfo property in blockType.GetProperties()) { if (property.Name != "Length") { map[property.Name] = LLSD.FromObject(property.GetValue(block, null)); } } return(map); }
private void Client_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { bool raiseEvent = false; if (!_Dead) { if (!_Running) { raiseEvent = true; } // We are connected to the event queue _Running = true; } // Create an EventQueueGet request LLSDMap request = new LLSDMap(); request["ack"] = new LLSD(); request["done"] = LLSD.FromBoolean(false); byte[] postData = LLSDParser.SerializeXmlBytes(request); _Client.UploadDataAsync(_Client.Location, postData); if (raiseEvent) { SecondLife.DebugLogStatic("Capabilities event queue connected"); // The event queue is starting up for the first time if (OnConnected != null) { try { OnConnected(); } catch (Exception ex) { SecondLife.LogStatic(ex.ToString(), Helpers.LogLevel.Error); } } } }
public void DeserializeDictionary() { LLSDMap llsdEmptyMap = (LLSDMap)LLSDParser.DeserializeBinary(binaryEmptyMap); Assert.AreEqual(LLSDType.Map, llsdEmptyMap.Type); Assert.AreEqual(0, llsdEmptyMap.Count); LLSDMap llsdSimpleMap = (LLSDMap)LLSDParser.DeserializeBinary(binarySimpleMap); Assert.AreEqual(LLSDType.Map, llsdSimpleMap.Type); Assert.AreEqual(1, llsdSimpleMap.Count); Assert.AreEqual(LLSDType.Integer, llsdSimpleMap["test"].Type); Assert.AreEqual(0, llsdSimpleMap["test"].AsInteger()); LLSDMap llsdSimpleMapTwo = (LLSDMap)LLSDParser.DeserializeBinary(binarySimpleMapTwo); Assert.AreEqual(LLSDType.Map, llsdSimpleMapTwo.Type); Assert.AreEqual(3, llsdSimpleMapTwo.Count); Assert.AreEqual(LLSDType.Unknown, llsdSimpleMapTwo["test"].Type); Assert.AreEqual(LLSDType.String, llsdSimpleMapTwo["tes1"].Type); Assert.AreEqual("aha", llsdSimpleMapTwo["tes1"].AsString()); Assert.AreEqual(LLSDType.Integer, llsdSimpleMapTwo["t0st"].Type); Assert.AreEqual(241, llsdSimpleMapTwo["t0st"].AsInteger()); }
public static LLSD GetLLSD(Packet packet) { LLSDMap body = new LLSDMap(); Type type = packet.GetType(); foreach (FieldInfo field in type.GetFields()) { if (field.IsPublic) { Type blockType = field.FieldType; if (blockType.IsArray) { object blockArray = field.GetValue(packet); Array array = (Array)blockArray; LLSDArray blockList = new LLSDArray(array.Length); IEnumerator ie = array.GetEnumerator(); while (ie.MoveNext()) { object block = ie.Current; blockList.Add(BuildLLSDBlock(block)); } body[field.Name] = blockList; } else { object block = field.GetValue(packet); body[field.Name] = BuildLLSDBlock(block); } } } return body; }
public static Vector3 ParseVector3(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) { if (llsd.Type == LLSDType.Array) { Vector3 vec = new Vector3(); vec.FromLLSD(llsd); return vec; } else if (llsd.Type == LLSDType.String) { LLSDArray array = (LLSDArray)LLSDParser.DeserializeNotation(llsd.AsString()); Vector3 vec = new Vector3(); vec.FromLLSD(array); return vec; } } return Vector3.Zero; }
public static string ParseString(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) return llsd.AsString(); else return String.Empty; }
public static UUID ParseUUID(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) return llsd.AsUUID(); else return UUID.Zero; }
public static uint ParseUInt(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) return (uint)llsd.AsInteger(); else return 0; }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="notecardID"></param> /// <param name="callback"></param> public void RequestUploadNotecardAsset(byte[] data, UUID notecardID, NotecardUploadedAssetCallback callback) { if (_Network.CurrentSim == null || _Network.CurrentSim.Caps == null) throw new Exception("UpdateNotecardAgentInventory capability is not currently available"); Uri url = _Network.CurrentSim.Caps.CapabilityURI("UpdateNotecardAgentInventory"); if (url != null) { LLSDMap query = new LLSDMap(); query.Add("item_id", LLSD.FromUUID(notecardID)); byte[] postData = StructuredData.LLSDParser.SerializeXmlBytes(query); // Make the request CapsClient request = new CapsClient(url); request.OnComplete += new CapsClient.CompleteCallback(UploadNotecardAssetResponse); request.UserData = new object[2] { new KeyValuePair<NotecardUploadedAssetCallback, byte[]>(callback, data), notecardID }; request.StartRequest(postData); } else { throw new Exception("UpdateNotecardAgentInventory capability is not currently available"); } }
/// <summary> /// /// </summary> /// <returns></returns> public LLSD ToLLSD() { LLSDMap map = new LLSDMap(); map["simulate_lod"] = LLSD.FromInteger(Softness); map["gravity"] = LLSD.FromReal(Gravity); map["air_friction"] = LLSD.FromReal(Drag); map["wind_sensitivity"] = LLSD.FromReal(Wind); map["tension"] = LLSD.FromReal(Tension); map["user_force"] = Force.ToLLSD(); return map; }
private void BeginLogin() { LoginParams loginParams = CurrentContext.Value; // Sanity check if (loginParams.Options == null) loginParams.Options = new List<string>(); // Convert the password to MD5 if it isn't already if (loginParams.Password.Length != 35 && !loginParams.Password.StartsWith("$1$")) loginParams.Password = Helpers.MD5(loginParams.Password); // Override SSL authentication mechanisms. DO NOT convert this to the // .NET 2.0 preferred method, the equivalent function in Mono has a // different name and it will break compatibility! #pragma warning disable 0618 ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy(); // TODO: At some point, maybe we should check the cert? // Create the CAPS login structure LLSDMap loginLLSD = new LLSDMap(); loginLLSD["first"] = LLSD.FromString(loginParams.FirstName); loginLLSD["last"] = LLSD.FromString(loginParams.LastName); loginLLSD["passwd"] = LLSD.FromString(loginParams.Password); loginLLSD["start"] = LLSD.FromString(loginParams.Start); loginLLSD["channel"] = LLSD.FromString(loginParams.Channel); loginLLSD["version"] = LLSD.FromString(loginParams.Version); loginLLSD["platform"] = LLSD.FromString(loginParams.Platform); loginLLSD["mac"] = LLSD.FromString(loginParams.MAC); loginLLSD["agree_to_tos"] = LLSD.FromBoolean(true); loginLLSD["read_critical"] = LLSD.FromBoolean(true); loginLLSD["viewer_digest"] = LLSD.FromString(loginParams.ViewerDigest); loginLLSD["id0"] = LLSD.FromString(loginParams.id0); // Create the options LLSD array LLSDArray optionsLLSD = new LLSDArray(); for (int i = 0; i < loginParams.Options.Count; i++) optionsLLSD.Add(LLSD.FromString(loginParams.Options[i])); foreach (string[] callbackOpts in CallbackOptions.Values) { if (callbackOpts != null) { for (int i = 0; i < callbackOpts.Length; i++) { if (!optionsLLSD.Contains(callbackOpts[i])) optionsLLSD.Add(callbackOpts[i]); } } } loginLLSD["options"] = optionsLLSD; // Make the CAPS POST for login Uri loginUri; try { loginUri = new Uri(loginParams.URI); } catch (Exception ex) { Logger.Log(String.Format("Failed to parse login URI {0}, {1}", loginParams.URI, ex.Message), Helpers.LogLevel.Error, Client); return; } CapsClient loginRequest = new CapsClient(new Uri(loginParams.URI)); loginRequest.OnComplete += new CapsClient.CompleteCallback(LoginReplyHandler); loginRequest.UserData = CurrentContext; loginRequest.StartRequest(LLSDParser.SerializeXmlBytes(loginLLSD), "application/xml+llsd"); }
private bool FixupSeedCapsResponse(CapsRequest capReq, CapsStage stage) { if (stage != CapsStage.Response) return false; LLSDMap nm = new LLSDMap(); if (capReq.Response.Type == LLSDType.Map) { LLSDMap m = (LLSDMap)capReq.Response; foreach (string key in m.Keys) { string val = m[key].AsString(); if (!String.IsNullOrEmpty(val)) { if (!KnownCaps.ContainsKey(val)) { CapInfo newCap = new CapInfo(val, capReq.Info.Sim, key); newCap.AddDelegate(new CapsDelegate(KnownCapDelegate)); lock (this) { KnownCaps[val] = newCap; } } nm[key] = LLSD.FromString(loginURI + val); } else { nm[key] = LLSD.FromString(val); } } } capReq.Response = nm; return false; }
public LLSD ToLLSD() { LLSDMap map = new LLSDMap(); map["texture"] = LLSD.FromUUID(SculptTexture); map["type"] = LLSD.FromInteger((int)Type); return map; }
private static object ParseLLSDBlock(LLSDMap blockData, Type blockType) { object block = Activator.CreateInstance(blockType); // Iterate over each field and set the value if a match was found in the LLSD foreach (FieldInfo field in blockType.GetFields()) { if (blockData.ContainsKey(field.Name)) { Type fieldType = field.FieldType; if (fieldType == typeof(ulong)) { // ulongs come in as a byte array, convert it manually here byte[] bytes = blockData[field.Name].AsBinary(); ulong value = Utils.BytesToUInt64(bytes); field.SetValue(block, value); } else if (fieldType == typeof(uint)) { // uints come in as a byte array, convert it manually here byte[] bytes = blockData[field.Name].AsBinary(); uint value = Utils.BytesToUInt(bytes); field.SetValue(block, value); } else if (fieldType == typeof(ushort)) { // Just need a bit of manual typecasting love here field.SetValue(block, (ushort)blockData[field.Name].AsInteger()); } else if (fieldType == typeof(byte)) { // Just need a bit of manual typecasting love here field.SetValue(block, (byte)blockData[field.Name].AsInteger()); } else if (fieldType == typeof(short)) { field.SetValue(block, (short)blockData[field.Name].AsInteger()); } else if (fieldType == typeof(string)) { field.SetValue(block, blockData[field.Name].AsString()); } else if (fieldType == typeof(bool)) { field.SetValue(block, blockData[field.Name].AsBoolean()); } else if (fieldType == typeof(float)) { field.SetValue(block, (float)blockData[field.Name].AsReal()); } else if (fieldType == typeof(double)) { field.SetValue(block, blockData[field.Name].AsReal()); } else if (fieldType == typeof(int)) { field.SetValue(block, blockData[field.Name].AsInteger()); } else if (fieldType == typeof(UUID)) { field.SetValue(block, blockData[field.Name].AsUUID()); } else if (fieldType == typeof(Vector3)) { Vector3 vec = ((LLSDArray)blockData[field.Name]).AsVector3(); field.SetValue(block, vec); } else if (fieldType == typeof(Vector4)) { Vector4 vec = ((LLSDArray)blockData[field.Name]).AsVector4(); field.SetValue(block, vec); } else if (fieldType == typeof(Quaternion)) { Quaternion quat = ((LLSDArray)blockData[field.Name]).AsQuaternion(); field.SetValue(block, quat); } } } // Additional fields come as properties, Handle those as well. foreach (PropertyInfo property in blockType.GetProperties()) { if (blockData.ContainsKey(property.Name)) { LLSDType proptype = blockData[property.Name].Type; MethodInfo set = property.GetSetMethod(); if (proptype.Equals(LLSDType.Binary)) { set.Invoke(block, new object[] { blockData[property.Name].AsBinary() }); } else set.Invoke(block, new object[] { Utils.StringToBytes(blockData[property.Name].AsString()) }); } } return block; }
private void EventQueueEventHandler(string eventName, LLSDMap body) { if (Simulator.Client.Settings.SYNC_PACKETCALLBACKS) Simulator.Client.Network.CapsEvents.RaiseEvent(eventName, body, Simulator); else Simulator.Client.Network.CapsEvents.BeginRaiseEvent(eventName, body, Simulator); }
public static UUID ParseMappedUUID(string key, string key2, LLSDMap reply) { LLSD folderLLSD; if (reply.TryGetValue(key, out folderLLSD) && folderLLSD.Type == LLSDType.Array) { LLSDArray array = (LLSDArray)folderLLSD; if (array.Count == 1 && array[0].Type == LLSDType.Map) { LLSDMap map = (LLSDMap)array[0]; LLSD folder; if (map.TryGetValue(key2, out folder)) return folder.AsUUID(); } } return UUID.Zero; }
private static LLSDMap ParseXmlMap(XmlTextReader reader) { if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "map") throw new NotImplementedException("Expected <map>"); LLSDMap map = new LLSDMap(); if (reader.IsEmptyElement) { reader.Read(); return map; } if (reader.Read()) { while (true) { SkipWhitespace(reader); if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "map") { reader.Read(); break; } if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "key") throw new LLSDException("Expected <key>"); string key = reader.ReadString(); if (reader.NodeType != XmlNodeType.EndElement || reader.LocalName != "key") throw new LLSDException("Expected </key>"); if (reader.Read()) map[key] = ParseXmlElement(reader); else throw new LLSDException("Failed to parse a value for key " + key); } } return map; }
public static FolderData[] ParseInventoryFolders(string key, UUID owner, LLSDMap reply) { List<FolderData> folders = new List<FolderData>(); LLSD skeleton; if (reply.TryGetValue(key, out skeleton) && skeleton.Type == LLSDType.Array) { LLSDArray array = (LLSDArray)skeleton; for (int i = 0; i < array.Count; i++) { if (array[i].Type == LLSDType.Map) { LLSDMap map = (LLSDMap)array[i]; FolderData folder = new FolderData(map["folder_id"].AsUUID()); folder.PreferredType = (AssetType)map["type_default"].AsInteger(); folder.Version = map["version"].AsInteger(); folder.OwnerID = owner; folder.ParentUUID = map["parent_id"].AsUUID(); folder.Name = map["name"].AsString(); folders.Add(folder); } } } return folders.ToArray(); }
private static LLSD ParseBinaryMap(MemoryStream stream) { int numElements = NetworkToHostInt( ConsumeBytes( stream, int32Length )); int crrElement = 0; LLSDMap llsdMap = new LLSDMap(); while( crrElement < numElements ) { if (!FindByte( stream, keyBinaryMarker )) throw new LLSDException( "Binary LLSD parsing: Missing key marker in map." ); int keyLength = NetworkToHostInt( ConsumeBytes( stream, int32Length )); string key = Encoding.UTF8.GetString( ConsumeBytes( stream, keyLength )); llsdMap[key] = ParseBinaryElement( stream ); crrElement++; } if ( !FindByte( stream, mapEndBinaryMarker )) throw new LLSDException( "Binary LLSD parsing: Missing end marker in map." ); return (LLSD)llsdMap; }
public LLSD ToLLSD() { LLSDMap map = new LLSDMap(); map["color"] = Color.ToLLSD(); map["intensity"] = LLSD.FromReal(Intensity); map["radius"] = LLSD.FromReal(Radius); map["cutoff"] = LLSD.FromReal(Cutoff); map["falloff"] = LLSD.FromReal(Falloff); return map; }
public void Parse(LLSDMap reply) { try { AgentID = ParseUUID("agent_id", reply); SessionID = ParseUUID("session_id", reply); SecureSessionID = ParseUUID("secure_session_id", reply); FirstName = ParseString("first_name", reply).Trim('"'); LastName = ParseString("last_name", reply).Trim('"'); StartLocation = ParseString("start_location", reply); AgentAccess = ParseString("agent_access", reply); LookAt = ParseVector3("look_at", reply); } catch (LLSDException e) { // FIXME: sometimes look_at comes back with invalid values e.g: 'look_at':'[r1,r2.0193899999999998204e-06,r0]' // need to handle that somehow Logger.DebugLog("login server returned (some) invalid data: " + e.Message); } // Home LLSDMap home = null; LLSD llsdHome = LLSDParser.DeserializeNotation(reply["home"].AsString()); if (llsdHome.Type == LLSDType.Map) { home = (LLSDMap)llsdHome; LLSD homeRegion; if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == LLSDType.Array) { LLSDArray homeArray = (LLSDArray)homeRegion; if (homeArray.Count == 2) HomeRegion = Helpers.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger()); else HomeRegion = 0; } HomePosition = ParseVector3("position", home); HomeLookAt = ParseVector3("look_at", home); } else { HomeRegion = 0; HomePosition = Vector3.Zero; HomeLookAt = Vector3.Zero; } CircuitCode = ParseUInt("circuit_code", reply); RegionX = ParseUInt("region_x", reply); RegionY = ParseUInt("region_y", reply); SimPort = (ushort)ParseUInt("sim_port", reply); string simIP = ParseString("sim_ip", reply); IPAddress.TryParse(simIP, out SimIP); SeedCapability = ParseString("seed_capability", reply); // Buddy list LLSD buddyLLSD; if (reply.TryGetValue("buddy-list", out buddyLLSD) && buddyLLSD.Type == LLSDType.Array) { LLSDArray buddyArray = (LLSDArray)buddyLLSD; BuddyList = new FriendInfo[buddyArray.Count]; for (int i = 0; i < buddyArray.Count; i++) { if (buddyArray[i].Type == LLSDType.Map) { LLSDMap buddy = (LLSDMap)buddyArray[i]; BuddyList[i] = new FriendInfo( ParseUUID("buddy_id", buddy), (FriendRights)ParseUInt("buddy_rights_given", buddy), (FriendRights)ParseUInt("buddy_rights_has", buddy)); } } } SecondsSinceEpoch = Helpers.UnixTimeToDateTime(ParseUInt("seconds_since_epoch", reply)); InventoryRoot = ParseMappedUUID("inventory-root", "folder_id", reply); InventoryFolders = ParseInventoryFolders("inventory-skeleton", AgentID, reply); LibraryRoot = ParseMappedUUID("inventory-lib-root", "folder_id", reply); LibraryOwner = ParseMappedUUID("inventory-lib-owner", "agent_id", reply); LibraryFolders = ParseInventoryFolders("inventory-skel-lib", LibraryOwner, reply); }
private void Client_UploadDataCompleted(object sender, CapsBase.UploadDataCompletedEventArgs e) { LLSDArray events = null; int ack = 0; if (e.Error != null) { // Error occurred string message = e.Error.Message.ToLower(); // Check what kind of exception happened if (Helpers.StringContains(message, "404") || Helpers.StringContains(message, "410")) { Logger.Log("Closing event queue at " + _Client.Location + " due to missing caps URI", Helpers.LogLevel.Info); _Running = false; _Dead = true; } else if (!e.Cancelled) { HttpWebResponse errResponse = null; if (e.Error is WebException) { WebException err = (WebException)e.Error; errResponse = (HttpWebResponse)err.Response; } // Figure out what type of error was thrown so we can print a meaningful // error message if (errResponse != null) { switch (errResponse.StatusCode) { case HttpStatusCode.BadGateway: // This is not good (server) protocol design, but it's normal. // The EventQueue server is a proxy that connects to a Squid // cache which will time out periodically. The EventQueue server // interprets this as a generic error and returns a 502 to us // that we ignore break; default: Logger.Log(String.Format( "Unrecognized caps connection problem from {0}: {1} (Server returned: {2})", _Client.Location, errResponse.StatusCode, errResponse.StatusDescription), Helpers.LogLevel.Warning); break; } } else if (e.Error.InnerException != null) { Logger.Log(String.Format("Unrecognized caps exception from {0}: {1}", _Client.Location, e.Error.InnerException.Message), Helpers.LogLevel.Warning); } else { Logger.Log(String.Format("Unrecognized caps exception from {0}: {1}", _Client.Location, e.Error.Message), Helpers.LogLevel.Warning); } } } else if (!e.Cancelled && e.Result != null) { // Got a response LLSD result = LLSDParser.DeserializeXml(e.Result); if (result != null && result.Type == LLSDType.Map) { // Parse any events returned by the event queue LLSDMap map = (LLSDMap)result; events = (LLSDArray)map["events"]; ack = map["id"].AsInteger(); } } else if (e.Cancelled) { // Connection was cancelled Logger.DebugLog("Cancelled connection to event queue at " + _Client.Location); } if (_Running) { LLSDMap request = new LLSDMap(); if (ack != 0) request["ack"] = LLSD.FromInteger(ack); else request["ack"] = new LLSD(); request["done"] = LLSD.FromBoolean(_Dead); byte[] postData = LLSDParser.SerializeXmlBytes(request); _Client.UploadDataAsync(_Client.Location, postData); // If the event queue is dead at this point, turn it off since // that was the last thing we want to do if (_Dead) { _Running = false; Logger.DebugLog("Sent event queue shutdown message"); } } if (OnEvent != null && events != null && events.Count > 0) { // Fire callbacks for each event received foreach (LLSDMap evt in events) { string msg = evt["message"].AsString(); LLSDMap body = (LLSDMap)evt["body"]; try { OnEvent(msg, body); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, ex); } } } }
public LLSD ToLLSD() { LLSDMap path = new LLSDMap(14); path["begin"] = LLSD.FromReal(Data.PathBegin); path["curve"] = LLSD.FromInteger((int)Data.PathCurve); path["end"] = LLSD.FromReal(Data.PathEnd); path["radius_offset"] = LLSD.FromReal(Data.PathRadiusOffset); path["revolutions"] = LLSD.FromReal(Data.PathRevolutions); path["scale_x"] = LLSD.FromReal(Data.PathScaleX); path["scale_y"] = LLSD.FromReal(Data.PathScaleY); path["shear_x"] = LLSD.FromReal(Data.PathShearX); path["shear_y"] = LLSD.FromReal(Data.PathShearY); path["skew"] = LLSD.FromReal(Data.PathSkew); path["taper_x"] = LLSD.FromReal(Data.PathTaperX); path["taper_y"] = LLSD.FromReal(Data.PathTaperY); path["twist"] = LLSD.FromReal(Data.PathTwist); path["twist_begin"] = LLSD.FromReal(Data.PathTwistBegin); LLSDMap profile = new LLSDMap(4); profile["begin"] = LLSD.FromReal(Data.ProfileBegin); profile["curve"] = LLSD.FromInteger((int)Data.ProfileCurve); profile["hole"] = LLSD.FromInteger((int)Data.ProfileHole); profile["end"] = LLSD.FromReal(Data.ProfileEnd); profile["hollow"] = LLSD.FromReal(Data.ProfileHollow); LLSDMap volume = new LLSDMap(2); volume["path"] = path; volume["profile"] = profile; LLSDMap prim = new LLSDMap(9); prim["name"] = LLSD.FromString(Properties.Name); prim["description"] = LLSD.FromString(Properties.Description); prim["phantom"] = LLSD.FromBoolean(((Flags & ObjectFlags.Phantom) != 0)); prim["physical"] = LLSD.FromBoolean(((Flags & ObjectFlags.Physics) != 0)); prim["position"] = Position.ToLLSD(); prim["rotation"] = Rotation.ToLLSD(); prim["scale"] = Scale.ToLLSD(); prim["material"] = LLSD.FromInteger((int)Data.Material); prim["shadows"] = LLSD.FromBoolean(((Flags & ObjectFlags.CastShadows) != 0)); prim["textures"] = Textures.ToLLSD(); prim["volume"] = volume; if (ParentID != 0) prim["parentid"] = LLSD.FromInteger(ParentID); prim["light"] = Light.ToLLSD(); prim["flex"] = Flexible.ToLLSD(); prim["sculpt"] = Sculpt.ToLLSD(); return prim; }
private static LLSD ParseNotationElement(string notationData, out int endPos) { if (notationData.Length == 0) { endPos = 0; return null; } // Identify what type of object this is switch (notationData[0]) { case '!': endPos = 1; return new LLSD(); case '1': endPos = 1; return LLSD.FromBoolean(true); case '0': endPos = 1; return LLSD.FromBoolean(false); case 'i': { if (notationData.Length < 2) { endPos = notationData.Length; return LLSD.FromInteger(0); } int value; endPos = FindEnd(notationData, 1); if (Helpers.TryParse(notationData.Substring(1, endPos - 1), out value)) return LLSD.FromInteger(value); else return LLSD.FromInteger(0); } case 'r': { if (notationData.Length < 2) { endPos = notationData.Length; return LLSD.FromReal(0d); } double value; endPos = FindEnd(notationData, 1); if (Helpers.TryParse(notationData.Substring(1, endPos - 1), out value)) return LLSD.FromReal(value); else return LLSD.FromReal(0d); } case 'u': { if (notationData.Length < 17) { endPos = notationData.Length; return LLSD.FromUUID(LLUUID.Zero); } LLUUID value; endPos = FindEnd(notationData, 1); if (Helpers.TryParse(notationData.Substring(1, endPos - 1), out value)) return LLSD.FromUUID(value); else return LLSD.FromUUID(LLUUID.Zero); } case 'b': throw new NotImplementedException("Notation binary type is unimplemented"); case 's': case '"': case '\'': if (notationData.Length < 2) { endPos = notationData.Length; return LLSD.FromString(String.Empty); } endPos = FindEnd(notationData, 1); return LLSD.FromString(notationData.Substring(1, endPos - 1).Trim(new char[] { '"', '\'' })); case 'l': throw new NotImplementedException("Notation URI type is unimplemented"); case 'd': throw new NotImplementedException("Notation date type is unimplemented"); case '[': { if (notationData.IndexOf(']') == -1) throw new LLSDException("Invalid notation array"); int pos = 0; LLSDArray array = new LLSDArray(); while (notationData[pos] != ']') { ++pos; // Advance past comma if need be if (notationData[pos] == ',') ++pos; // Allow a single whitespace character if (pos < notationData.Length && notationData[pos] == ' ') ++pos; int end; array.Add(ParseNotationElement(notationData.Substring(pos), out end)); pos += end; } endPos = pos + 1; return array; } case '{': { if (notationData.IndexOf('}') == -1) throw new LLSDException("Invalid notation map"); int pos = 0; LLSDMap hashtable = new LLSDMap(); while (notationData[pos] != '}') { ++pos; // Advance past comma if need be if (notationData[pos] == ',') ++pos; // Allow a single whitespace character if (pos < notationData.Length && notationData[pos] == ' ') ++pos; if (notationData[pos] != '\'') throw new LLSDException("Expected a map key"); int endquote = notationData.IndexOf('\'', pos + 1); if (endquote == -1 || (endquote + 1) >= notationData.Length || notationData[endquote + 1] != ':') throw new LLSDException("Invalid map format"); string key = notationData.Substring(pos, endquote - pos); key = key.Trim(new char[] { '"', '\'' }); //key.Replace("'", String.Empty); pos += (endquote - pos) + 2; int end; hashtable[key] = ParseNotationElement(notationData.Substring(pos), out end); pos += end; } endPos = pos + 1; return hashtable; } default: throw new LLSDException("Unknown notation value type"); } }
private static void SerializeBinaryMap( MemoryStream stream, LLSDMap llsdMap ) { stream.WriteByte( mapBeginBinaryMarker ); byte[] binaryNumElementsNetEnd = HostToNetworkIntBytes( llsdMap.Count ); stream.Write( binaryNumElementsNetEnd, 0, int32Length ); foreach( KeyValuePair<string, LLSD> kvp in llsdMap ) { stream.WriteByte( keyBinaryMarker ); byte[] binaryKey = Encoding.UTF8.GetBytes( kvp.Key ); byte[] binaryKeyLength = HostToNetworkIntBytes( binaryKey.Length ); stream.Write( binaryKeyLength, 0, int32Length ); stream.Write( binaryKey, 0, binaryKey.Length ); SerializeBinaryElement( stream, kvp.Value ); } stream.WriteByte( mapEndBinaryMarker ); }
/// <summary> /// Moderate a chat session /// </summary> /// <param name="sessionID">the <see cref="UUID"/> of the session to moderate, for group chats this will be the groups UUID</param> /// <param name="memberID">the <see cref="UUID"/> of the avatar to moderate</param> /// <param name="moderateText">true to moderate (silence user), false to allow avatar to speak</param> public void ModerateChatSessions(UUID sessionID, UUID memberID, bool moderateText) { if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Caps == null) throw new Exception("ChatSessionRequest capability is not currently available"); Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("ChatSessionRequest"); if (url != null) { LLSDMap req = new LLSDMap(); req.Add("method", LLSD.FromString("mute update")); LLSDMap mute_info = new LLSDMap(); mute_info.Add("text", LLSD.FromBoolean(moderateText)); LLSDMap parameters = new LLSDMap(); parameters["agent_id"] = LLSD.FromUUID(memberID); parameters["mute_info"] = mute_info; req["params"] = parameters; req.Add("session-id", LLSD.FromUUID(sessionID)); byte[] postData = StructuredData.LLSDParser.SerializeXmlBytes(req); CapsClient request = new CapsClient(url); request.StartRequest(postData); } else { throw new Exception("ChatSessionRequest capability is not currently available"); } }
private void Client_OpenWriteCompleted(object sender, CapsBase.OpenWriteCompletedEventArgs e) { bool raiseEvent = false; if (!_Dead) { if (!_Running) raiseEvent = true; // We are connected to the event queue _Running = true; } // Create an EventQueueGet request LLSDMap request = new LLSDMap(); request["ack"] = new LLSD(); request["done"] = LLSD.FromBoolean(false); byte[] postData = LLSDParser.SerializeXmlBytes(request); _Client.UploadDataAsync(_Client.Location, postData); if (raiseEvent) { Logger.DebugLog("Capabilities event queue connected"); // The event queue is starting up for the first time if (OnConnected != null) { try { OnConnected(); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, ex); } } } }
public LLSD ToLLSD(int faceNumber) { LLSDMap tex = new LLSDMap(10); if (faceNumber >= 0) tex["face_number"] = LLSD.FromInteger(faceNumber); tex["colors"] = RGBA.ToLLSD(); tex["scales"] = LLSD.FromReal(RepeatU); tex["scalet"] = LLSD.FromReal(RepeatV); tex["offsets"] = LLSD.FromReal(OffsetU); tex["offsett"] = LLSD.FromReal(OffsetV); tex["imagerot"] = LLSD.FromReal(Rotation); tex["bump"] = LLSD.FromInteger((int)Bump); tex["shiny"] = LLSD.FromInteger((int)Shiny); tex["fullbright"] = LLSD.FromBoolean(Fullbright); tex["media_flags"] = LLSD.FromInteger(Convert.ToInt32(MediaFlags)); tex["mapping"] = LLSD.FromInteger((int)TexMapType); tex["glow"] = LLSD.FromReal(Glow); tex["imageid"] = LLSD.FromUUID(TextureID); return tex; }
private static LLSD BuildLLSDBlock(object block) { LLSDMap map = new LLSDMap(); Type blockType = block.GetType(); foreach (FieldInfo field in blockType.GetFields()) { if (field.IsPublic) map[field.Name] = LLSD.FromObject(field.GetValue(block)); } foreach (PropertyInfo property in blockType.GetProperties()) { if (property.Name != "Length") { map[property.Name] = LLSD.FromObject(property.GetValue(block, null)); } } return map; }
public void RequestCreateItemFromAsset(byte[] data, string name, string description, AssetType assetType, InventoryType invType, LLUUID folderID, ItemCreatedFromAssetCallback callback) { if (_Client.Network.CurrentSim == null || _Client.Network.CurrentSim.Caps == null) throw new Exception("NewFileAgentInventory capability is not currently available"); Uri url = _Client.Network.CurrentSim.Caps.CapabilityURI("NewFileAgentInventory"); if (url != null) { LLSDMap query = new LLSDMap(); query.Add("folder_id", LLSD.FromUUID(folderID)); query.Add("asset_type", LLSD.FromString(AssetTypeToString(assetType))); query.Add("inventory_type", LLSD.FromString(InventoryTypeToString(invType))); query.Add("name", LLSD.FromString(name)); query.Add("description", LLSD.FromString(description)); byte[] postData = StructuredData.LLSDParser.SerializeXmlBytes(query); // Make the request CapsClient request = new CapsClient(url); request.OnComplete += new CapsClient.CompleteCallback(CreateItemFromAssetResponse); request.UserData = new KeyValuePair<ItemCreatedFromAssetCallback, byte[]>(callback, data); request.StartRequest(postData); } else { throw new Exception("NewFileAgentInventory capability is not currently available"); } }
public void RequestCreateItemFromAsset(byte[] data, string name, string description, AssetType assetType, InventoryType invType, UUID folderID, CapsClient.ProgressCallback progCallback, ItemCreatedFromAssetCallback callback) { if (_Network.CurrentSim == null || _Network.CurrentSim.Caps == null) throw new Exception("NewFileAgentInventory capability is not currently available"); Uri url = _Network.CurrentSim.Caps.CapabilityURI("NewFileAgentInventory"); if (url != null) { LLSDMap query = new LLSDMap(); query.Add("folder_id", LLSD.FromUUID(folderID)); query.Add("asset_type", LLSD.FromString(AssetTypeToString(assetType))); query.Add("inventory_type", LLSD.FromString(InventoryTypeToString(invType))); query.Add("name", LLSD.FromString(name)); query.Add("description", LLSD.FromString(description)); // Make the request CapsClient request = new CapsClient(url); request.OnComplete += new CapsClient.CompleteCallback(CreateItemFromAssetResponse); request.UserData = new object[] { progCallback, callback, data }; request.StartRequest(query); } else { throw new Exception("NewFileAgentInventory capability is not currently available"); } }