protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { string message; using (StreamReader reader = new StreamReader(request)) message = reader.ReadToEnd(); OSD osd = OSDParser.DeserializeLLSDXml(message); if (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_agentID) && !m_isGod) { m_consoleModule.SendConsoleOutput(m_agentID, "No access"); return(new byte[0]); } string cmd = osd.AsString(); if (cmd == "set console on") { if (m_isGod) { MainConsole.Instance.OnOutput += ConsoleSender; m_consoleIsOn = true; m_consoleModule.SendConsoleOutput(m_agentID, "Console is now on"); } return(new byte[0]); } else if (cmd == "set console off") { MainConsole.Instance.OnOutput -= ConsoleSender; m_consoleIsOn = false; m_consoleModule.SendConsoleOutput(m_agentID, "Console is now off"); return(new byte[0]); } if (m_consoleIsOn == false && m_consoleModule.RunCommand(osd.AsString().Trim(), m_agentID)) { return(new byte[0]); } if (m_isGod && m_consoleIsOn) { MainConsole.Instance.RunCommand(osd.AsString().Trim()); } else { m_consoleModule.SendConsoleOutput(m_agentID, "Unknown command"); } return(new byte[0]); }
public void SerializeString() { OSD llsdString = OSD.FromString("abcdefghijklmnopqrstuvwxyz01234567890"); byte[] binaryLongStringSerialized = OSDParser.SerializeLLSDBinary(llsdString); Assert.AreEqual(binaryLongString, binaryLongStringSerialized); // A test with some utf8 characters string contentAStringXML = "<x>ƖȔȠȨɆɒ</x>"; byte[] bytes = Encoding.UTF8.GetBytes(contentAStringXML); XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); xtr.Read(); xtr.Read(); string contentAString = xtr.ReadString(); OSD llsdAString = OSD.FromString(contentAString); byte[] binaryAString = OSDParser.SerializeLLSDBinary(llsdAString); OSD llsdAStringDS = OSDParser.DeserializeLLSDBinary(binaryAString); Assert.AreEqual(OSDType.String, llsdAStringDS.Type); Assert.AreEqual(contentAString, llsdAStringDS.AsString()); // we also test for a 4byte character. string xml = "<x>𐄷</x>"; byte[] bytesTwo = Encoding.UTF8.GetBytes(xml); XmlTextReader xtrTwo = new XmlTextReader(new MemoryStream(bytesTwo, false)); xtrTwo.Read(); xtrTwo.Read(); string content = xtrTwo.ReadString(); OSD llsdStringOne = OSD.FromString(content); byte[] binaryAStringOneSerialized = OSDParser.SerializeLLSDBinary(llsdStringOne); OSD llsdStringOneDS = OSDParser.DeserializeLLSDBinary(binaryAStringOneSerialized); Assert.AreEqual(OSDType.String, llsdStringOneDS.Type); Assert.AreEqual(content, llsdStringOneDS.AsString()); }
private Hashtable SimConsoleAsyncResponder(Hashtable m_dhttpMethod, UUID agentID) { Hashtable responsedata = new Hashtable(); responsedata["int_response_code"] = 200; //501; //410; //404; responsedata["content_type"] = "text/plain"; responsedata["keepalive"] = false; responsedata["str_response_string"] = ""; IScenePresence SP = findScene(agentID).GetScenePresence(agentID); if (SP == null) { return(responsedata); //They don't exist } OSD rm = OSDParser.DeserializeLLSDXml((string)m_dhttpMethod["requestbody"]); string message = rm.AsString(); //Is a god, or they authenticated to the server and have write access if (AuthenticateUser(SP, message) && CanWrite(SP.UUID)) { FireConsole(message); responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(""); } else { responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(""); } return(responsedata); }
public void HandleAvatarNotesRequest(object sender, string method, List <string> args) { if (!(sender is IClientAPI)) { MainConsole.Instance.Debug("sender isn't IClientAPI"); return; } IClientAPI remoteClient = (IClientAPI)sender; IUserProfileInfo UPI = ProfileFrontend.GetUserProfile(remoteClient.AgentId); if (UPI == null) { return; } OSD notes = ""; string targetNotesUUID = args [0]; if (!UPI.Notes.TryGetValue(targetNotesUUID, out notes)) { notes = ""; } remoteClient.SendAvatarNotesReply(new UUID(targetNotesUUID), notes.AsString()); }
public void DoSomeStringSerializingActionsAndAsserts(string s) { OSD llsdOne = OSD.FromString(s); string sOne = OSDParser.SerializeLLSDNotation(llsdOne); OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); Assert.AreEqual(OSDType.String, llsdOne.Type); Assert.AreEqual(s, llsdOneDS.AsString()); }
public void DeserializeString() { string sOne = "''"; OSD llsdOne = OSDParser.DeserializeLLSDNotation(sOne); Assert.AreEqual(OSDType.String, llsdOne.Type); Assert.AreEqual("", llsdOne.AsString()); // This is double escaping. Once for the encoding, and once for csharp. string sTwo = "'test\\'\"test'"; OSD llsdTwo = OSDParser.DeserializeLLSDNotation(sTwo); Assert.AreEqual(OSDType.String, llsdTwo.Type); Assert.AreEqual("test'\"test", llsdTwo.AsString()); // "test \\lest" char[] cThree = { (char)0x27, (char)0x74, (char)0x65, (char)0x73, (char)0x74, (char)0x20, (char)0x5c, (char)0x5c, (char)0x6c, (char)0x65, (char)0x73, (char)0x74, (char)0x27 }; string sThree = new string(cThree); OSD llsdThree = OSDParser.DeserializeLLSDNotation(sThree); Assert.AreEqual(OSDType.String, llsdThree.Type); Assert.AreEqual("test \\lest", llsdThree.AsString()); string sFour = "'aa\t la'"; OSD llsdFour = OSDParser.DeserializeLLSDNotation(sFour); Assert.AreEqual(OSDType.String, llsdFour.Type); Assert.AreEqual("aa\t la", llsdFour.AsString()); char[] cFive = { (char)0x27, (char)0x5c, (char)0x5c, (char)0x27 }; string sFive = new String(cFive); OSD llsdFive = OSDParser.DeserializeLLSDNotation(sFive); Assert.AreEqual(OSDType.String, llsdFive.Type); Assert.AreEqual("\\", llsdFive.AsString()); string sSix = "s(10)\"1234567890\""; OSD llsdSix = OSDParser.DeserializeLLSDNotation(sSix); Assert.AreEqual(OSDType.String, llsdSix.Type); Assert.AreEqual("1234567890", llsdSix.AsString()); string sSeven = "s(5)\"\\\\\\\\\\\""; OSD llsdSeven = OSDParser.DeserializeLLSDNotation(sSeven); Assert.AreEqual(OSDType.String, llsdSeven.Type); Assert.AreEqual("\\\\\\\\\\", llsdSeven.AsString()); string sEight = "\"aouAOUhsdjklfghskldjfghqeiurtzwieortzaslxfjkgh\""; OSD llsdEight = OSDParser.DeserializeLLSDNotation(sEight); Assert.AreEqual(OSDType.String, llsdEight.Type); Assert.AreEqual("aouAOUhsdjklfghskldjfghqeiurtzwieortzaslxfjkgh", llsdEight.AsString()); }
public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { var reader = new StreamReader(request); string message = reader.ReadToEnd(); OSD osd = OSDParser.DeserializeLLSDXml(message); string cmd = osd.AsString(); if (cmd == "set console on") { if (m_isGod) { MainConsole.Instance.OnOutput += ConsoleSender; m_consoleIsOn = true; m_consoleModule.SendConsoleOutput(m_agentID, "Console is now on"); } return(new byte[0]); } else if (cmd == "set console off") { MainConsole.Instance.OnOutput -= ConsoleSender; m_consoleIsOn = false; m_consoleModule.SendConsoleOutput(m_agentID, "Console is now off"); return(new byte[0]); } if (m_consoleIsOn == false && m_consoleModule.RunCommand(osd.AsString().Trim(), m_agentID)) { return(new byte[0]); } if (m_isGod && m_consoleIsOn) { MainConsole.Instance.RunCommand(osd.AsString().Trim()); } else { m_consoleModule.SendConsoleOutput(m_agentID, "Unknown command"); } return(new byte[0]); }
public void DeserializeUUID() { OSD llsdAUUID = OSDParser.DeserializeLLSDBinary(binaryAUUID); Assert.AreEqual(OSDType.UUID, llsdAUUID.Type); Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdAUUID.AsString()); OSD llsdZeroUUID = OSDParser.DeserializeLLSDBinary(binaryZeroUUID); Assert.AreEqual(OSDType.UUID, llsdZeroUUID.Type); Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdZeroUUID.AsString()); }
public static object SerializeLisp(OSD osd) { switch (osd.Type) { case OSDType.Unknown: throw new InvalidCastException(); case OSDType.Boolean: return(osd.AsBoolean()); case OSDType.Integer: return(osd.AsInteger()); case OSDType.Real: return(osd.AsReal()); case OSDType.String: return(osd.AsString()); case OSDType.Date: return(osd.AsDate()); case OSDType.URI: return(osd.AsUri()); case OSDType.UUID: return(osd.AsUUID()); case OSDType.Binary: return(osd.AsBinary()); case OSDType.Array: OSDArray args = (OSDArray)osd; Cons ret = null; for (int i = args.Count - 1; i >= 0; --i) { ret = new Cons(args[i], ret); } return(ret); case OSDType.Map: Cons list = null; OSDMap map = (OSDMap)osd; foreach (KeyValuePair <string, OSD> kvp in map) { Cons kv = new Cons(kvp.Key, new Cons(SerializeLisp(kvp.Value))); list = new Cons(kv, list); } return(Cons.Reverse(list)); default: return(osd); } }
public void DeserializeString() { OSD llsdEmptyString = OSDParser.DeserializeLLSDBinary(binaryEmptyString); Assert.AreEqual(OSDType.String, llsdEmptyString.Type); string contentEmptyString = ""; Assert.AreEqual(contentEmptyString, llsdEmptyString.AsString()); OSD llsdLongString = OSDParser.DeserializeLLSDBinary(binaryLongString); Assert.AreEqual(OSDType.String, llsdLongString.Type); string contentLongString = "abcdefghijklmnopqrstuvwxyz01234567890"; Assert.AreEqual(contentLongString, llsdLongString.AsString()); }
// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- protected static bool ConvertOutputValue(OSD result, out string value, bool useJson) { value = String.Empty; // If we couldn't process the path if (result == null) { return(false); } if (useJson) { // The path pointed to an intermediate hash structure if (result.Type == OSDType.Map) { value = OSDParser.SerializeJsonString(result as OSDMap, true); return(true); } // The path pointed to an intermediate hash structure if (result.Type == OSDType.Array) { value = OSDParser.SerializeJsonString(result as OSDArray, true); return(true); } value = "'" + result.AsString() + "'"; return(true); } if (OSDBaseType(result.Type)) { value = result.AsString(); return(true); } return(false); }
public void DeserializeURI() { string sUriOne = "l\"http://test.com/test test>\\\"/&yes\""; OSD llsdOne = OSDParser.DeserializeLLSDNotation(sUriOne); Assert.AreEqual(OSDType.URI, llsdOne.Type); Assert.AreEqual("http://test.com/test%20test%3E%22/&yes", llsdOne.AsString()); string sUriTwo = "l\"test/test/test?test=1&toast=2\""; OSD llsdTwo = OSDParser.DeserializeLLSDNotation(sUriTwo); Assert.AreEqual(OSDType.URI, llsdTwo.Type); Assert.AreEqual("test/test/test?test=1&toast=2", llsdTwo.AsString()); }
public void DeserializeUUID() { String uuidOne = "u97f4aeca-88a1-42a1-b385-b97b18abb255"; OSD llsdOne = OSDParser.DeserializeLLSDNotation(uuidOne); Assert.AreEqual(OSDType.UUID, llsdOne.Type); Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOne.AsString()); String uuidTwo = "u00000000-0000-0000-0000-000000000000"; OSD llsdTwo = OSDParser.DeserializeLLSDNotation(uuidTwo); Assert.AreEqual(OSDType.UUID, llsdTwo.Type); Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwo.AsString()); }
public void SerializeUUID() { OSD llsdOne = OSD.FromUUID(new UUID("97f4aeca-88a1-42a1-b385-b97b18abb255")); string sOne = OSDParser.SerializeLLSDNotation(llsdOne); OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); Assert.AreEqual(OSDType.UUID, llsdOneDS.Type); Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOneDS.AsString()); OSD llsdTwo = OSD.FromUUID(new UUID("00000000-0000-0000-0000-000000000000")); string sTwo = OSDParser.SerializeLLSDNotation(llsdTwo); OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo); Assert.AreEqual(OSDType.UUID, llsdTwoDS.Type); Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwoDS.AsString()); }
public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers) { try { OSD o = OSDParser.DeserializeJson(json); OSD specVal = JsonGetSpecific(o, specifiers, 0); if (specVal != null) { return(specVal.AsString()); } else { return(ScriptBaseClass.JSON_INVALID); } } catch (Exception) { return(ScriptBaseClass.JSON_INVALID); } }
private byte[] SimConsoleAsyncResponder(Stream request, UUID agentID) { IScenePresence SP = m_Scene.GetScenePresence(agentID); if (SP == null) { return(new byte[0]); //They don't exist } OSD rm = OSDParser.DeserializeLLSDXml(HttpServerHandlerHelpers.ReadFully(request)); string message = rm.AsString(); //Is a god, or they authenticated to the server and have write access if (AuthenticateUser(SP, message) && CanWrite(SP.UUID)) { FireConsole(message); } return(OSDParser.SerializeLLSDXmlBytes("")); }
object ParseJsonNode(OSD node) { if (node.Type == OSDType.Integer) { return(new LSL_Integer(node.AsInteger())); } if (node.Type == OSDType.Boolean) { return(new LSL_Integer(node.AsBoolean() ? 1 : 0)); } if (node.Type == OSDType.Real) { return(new LSL_Float(node.AsReal())); } if (node.Type == OSDType.UUID || node.Type == OSDType.String) { return(new LSL_String(node.AsString())); } if (node.Type == OSDType.Array) { LSL_List resp = new LSL_List(); OSDArray ar = node as OSDArray; foreach (OSD o in ar) { resp.Add(ParseJsonNode(o)); } return(resp); } if (node.Type == OSDType.Map) { LSL_List resp = new LSL_List(); OSDMap ar = node as OSDMap; foreach (KeyValuePair <string, OSD> o in ar) { resp.Add(new LSL_String(o.Key)); resp.Add(ParseJsonNode(o.Value)); } return(resp); } throw new Exception(ScriptBaseClass.JSON_INVALID); }
public static JsonData SerializeJson(OSD osd) { switch (osd.Type) { case OSDType.Boolean: return new JsonData(osd.AsBoolean()); case OSDType.Integer: return new JsonData(osd.AsInteger()); case OSDType.Real: return new JsonData(osd.AsReal()); case OSDType.String: case OSDType.Date: case OSDType.URI: case OSDType.UUID: return new JsonData(osd.AsString()); case OSDType.Binary: byte[] binary = osd.AsBinary(); JsonData jsonbinarray = new JsonData(); jsonbinarray.SetJsonType(JsonType.Array); for (int i = 0; i < binary.Length; i++) jsonbinarray.Add(new JsonData(binary[i])); return jsonbinarray; case OSDType.Array: JsonData jsonarray = new JsonData(); jsonarray.SetJsonType(JsonType.Array); OSDArray array = (OSDArray)osd; for (int i = 0; i < array.Count; i++) jsonarray.Add(SerializeJson(array[i])); return jsonarray; case OSDType.Map: JsonData jsonmap = new JsonData(); jsonmap.SetJsonType(JsonType.Object); OSDMap map = (OSDMap)osd; foreach (KeyValuePair<string, OSD> kvp in map) jsonmap[kvp.Key] = SerializeJson(kvp.Value); return jsonmap; case OSDType.Unknown: default: return new JsonData(); } }
/// <summary> /// /// </summary> /// <param name="writer"></param> /// <param name="data"></param> public static void SerializeLLSDXmlElement(XmlTextWriter writer, OSD data) { switch (data.Type) { case OSDType.Unknown: writer.WriteStartElement(String.Empty, "undef", String.Empty); writer.WriteEndElement(); break; case OSDType.Boolean: writer.WriteStartElement(String.Empty, "boolean", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Integer: writer.WriteStartElement(String.Empty, "integer", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Real: writer.WriteStartElement(String.Empty, "real", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.String: writer.WriteStartElement(String.Empty, "string", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Guid: writer.WriteStartElement(String.Empty, "Guid", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Date: writer.WriteStartElement(String.Empty, "date", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.URI: writer.WriteStartElement(String.Empty, "uri", String.Empty); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Binary: writer.WriteStartElement(String.Empty, "binary", String.Empty); writer.WriteStartAttribute(String.Empty, "encoding", String.Empty); writer.WriteString("base64"); writer.WriteEndAttribute(); writer.WriteString(data.AsString()); writer.WriteEndElement(); break; case OSDType.Map: OSDMap map = (OSDMap)data; writer.WriteStartElement(String.Empty, "map", String.Empty); foreach (KeyValuePair<string, OSD> kvp in map) { writer.WriteStartElement(String.Empty, "key", String.Empty); writer.WriteString(kvp.Key); writer.WriteEndElement(); SerializeLLSDXmlElement(writer, kvp.Value); } writer.WriteEndElement(); break; case OSDType.Array: OSDArray array = (OSDArray)data; writer.WriteStartElement(String.Empty, "array", String.Empty); for (int i = 0; i < array.Count; i++) { SerializeLLSDXmlElement(writer, array[i]); } writer.WriteEndElement(); break; } }
private object ParseJsonNode(OSD node) { if (node.Type == OSDType.Integer) return new LSL_Integer(node.AsInteger()); if (node.Type == OSDType.Boolean) return new LSL_Integer(node.AsBoolean() ? 1 : 0); if (node.Type == OSDType.Real) return new LSL_Float(node.AsReal()); if (node.Type == OSDType.UUID || node.Type == OSDType.String) return new LSL_String(node.AsString()); if (node.Type == OSDType.Array) { LSL_List resp = new LSL_List(); OSDArray ar = node as OSDArray; foreach (OSD o in ar) resp.Add(ParseJsonNode(o)); return resp; } if (node.Type == OSDType.Map) { LSL_List resp = new LSL_List(); OSDMap ar = node as OSDMap; foreach (KeyValuePair<string, OSD> o in ar) { resp.Add(new LSL_String(o.Key)); resp.Add(ParseJsonNode(o.Value)); } return resp; } throw new Exception(ScriptBaseClass.JSON_INVALID); }
public static JsonData SerializeJson(OSD osd) { switch (osd.Type) { case OSDType.Boolean: return new JsonData(osd.AsBoolean()); case OSDType.Integer: return new JsonData(osd.AsInteger()); case OSDType.Real: return new JsonData(osd.AsReal()); case OSDType.String: return new JsonData(osd.AsString()); case OSDType.Date: return new JsonData("date::" + osd.AsString()); case OSDType.URI: return new JsonData("uri::" + osd.AsString()); case OSDType.UUID: return new JsonData("uuid::" + osd.AsString()); case OSDType.Binary: return new JsonData("b64::" + Convert.ToBase64String(osd.AsBinary())); case OSDType.Array: JsonData jsonarray = new JsonData(); jsonarray.SetJsonType(JsonType.Array); OSDArray array = (OSDArray)osd; for (int i = 0; i < array.Count; i++) jsonarray.Add(SerializeJson(array[i])); return jsonarray; case OSDType.Map: JsonData jsonmap = new JsonData(); jsonmap.SetJsonType(JsonType.Object); OSDMap map = (OSDMap)osd; foreach (KeyValuePair<string, OSD> kvp in map) jsonmap[kvp.Key] = SerializeJson(kvp.Value); return jsonmap; case OSDType.Unknown: default: return new JsonData(); } }
private Object osdToObject(OSD decoded) { if ( decoded is OSDString ) { return (string) decoded.AsString(); } else if ( decoded is OSDInteger ) { return (int) decoded.AsInteger(); } else if ( decoded is OSDReal ) { return (float) decoded.AsReal(); } else if ( decoded is OSDBoolean ) { return (bool) decoded.AsBoolean(); } else if ( decoded is OSDMap ) { return osdToHashtable((OSDMap) decoded); } else if ( decoded is OSDArray ) { return osdToArray((OSDArray) decoded); } else { return null; } }
private static JsonData SerializeJsonNoDefaults(OSD osd) { switch (osd.Type) { case OSDType.Boolean: bool b = osd.AsBoolean(); if (!b) return null; return new JsonData(b); case OSDType.Integer: int v = osd.AsInteger(); if (v == 0) return null; return new JsonData(v); case OSDType.Real: double d = osd.AsReal(); if (d == 0.0d) return null; return new JsonData(d); case OSDType.String: case OSDType.Date: case OSDType.URI: string str = osd.AsString(); if (String.IsNullOrEmpty(str)) return null; return new JsonData(str); case OSDType.UUID: UUID uuid = osd.AsUUID(); if (uuid == UUID.Zero) return null; return new JsonData(uuid.ToString()); case OSDType.Binary: byte[] binary = osd.AsBinary(); if (binary == Utils.EmptyBytes) return null; JsonData jsonbinarray = new JsonData(); jsonbinarray.SetJsonType(JsonType.Array); for (int i = 0; i < binary.Length; i++) jsonbinarray.Add(new JsonData(binary[i])); return jsonbinarray; case OSDType.Array: JsonData jsonarray = new JsonData(); jsonarray.SetJsonType(JsonType.Array); OSDArray array = (OSDArray)osd; for (int i = 0; i < array.Count; i++) jsonarray.Add(SerializeJson(array[i])); return jsonarray; case OSDType.Map: JsonData jsonmap = new JsonData(); jsonmap.SetJsonType(JsonType.Object); OSDMap map = (OSDMap)osd; foreach (KeyValuePair<string, OSD> kvp in map) { JsonData data = SerializeJsonNoDefaults(kvp.Value); if (data != null) jsonmap[kvp.Key] = data; } return jsonmap; case OSDType.Unknown: default: return null; } }
// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- protected static bool ConvertOutputValue(OSD result, out string value, bool useJson) { value = String.Empty; // If we couldn't process the path if (result == null) return false; if (useJson) { // The path pointed to an intermediate hash structure if (result.Type == OSDType.Map) { value = OSDParser.SerializeJsonString(result as OSDMap,true); return true; } // The path pointed to an intermediate hash structure if (result.Type == OSDType.Array) { value = OSDParser.SerializeJsonString(result as OSDArray,true); return true; } value = "'" + result.AsString() + "'"; return true; } if (OSDBaseType(result.Type)) { value = result.AsString(); return true; } return false; }
private static void SerializeLLSDNotationElementFormatted(StringWriter writer, string indent, OSD osd) { switch (osd.Type) { case OSDType.Unknown: writer.Write(undefNotationValue); break; case OSDType.Boolean: if (osd.AsBoolean()) writer.Write(trueNotationValueTwo); else writer.Write(falseNotationValueTwo); break; case OSDType.Integer: writer.Write(integerNotationMarker); writer.Write(osd.AsString()); break; case OSDType.Real: writer.Write(realNotationMarker); writer.Write(osd.AsString()); break; case OSDType.UUID: writer.Write(uuidNotationMarker); writer.Write(osd.AsString()); break; case OSDType.String: writer.Write(singleQuotesNotationMarker); writer.Write(EscapeCharacter(osd.AsString(), singleQuotesNotationMarker)); writer.Write(singleQuotesNotationMarker); break; case OSDType.Binary: writer.Write(binaryNotationMarker); writer.Write("64"); writer.Write(doubleQuotesNotationMarker); writer.Write(osd.AsString()); writer.Write(doubleQuotesNotationMarker); break; case OSDType.Date: writer.Write(dateNotationMarker); writer.Write(doubleQuotesNotationMarker); writer.Write(osd.AsString()); writer.Write(doubleQuotesNotationMarker); break; case OSDType.URI: writer.Write(uriNotationMarker); writer.Write(doubleQuotesNotationMarker); writer.Write(EscapeCharacter(osd.AsString(), doubleQuotesNotationMarker)); writer.Write(doubleQuotesNotationMarker); break; case OSDType.Array: SerializeLLSDNotationArrayFormatted(writer, indent + baseIndent, (OSDArray)osd); break; case OSDType.Map: SerializeLLSDNotationMapFormatted(writer, indent + baseIndent, (OSDMap)osd); break; default: throw new OSDException("Notation serialization: Not existing element discovered."); } }
public static object SerializeLisp(OSD osd) { switch (osd.Type) { case OSDType.Unknown: throw new InvalidCastException(); case OSDType.Boolean: return osd.AsBoolean(); case OSDType.Integer: return osd.AsInteger(); case OSDType.Real: return osd.AsReal(); case OSDType.String: return osd.AsString(); case OSDType.Date: return osd.AsDate(); case OSDType.URI: return osd.AsUri(); case OSDType.UUID: return osd.AsUUID(); case OSDType.Binary: return osd.AsBinary(); case OSDType.Array: OSDArray args = (OSDArray) osd; Cons ret = null; for (int i = args.Count - 1; i >= 0; --i) { ret = new Cons(args[i], ret); } return ret; case OSDType.Map: Cons list = null; OSDMap map = (OSDMap) osd; foreach (KeyValuePair<string, OSD> kvp in map) { Cons kv = new Cons(kvp.Key, new Cons(SerializeLisp(kvp.Value))); list = new Cons(kv,list); } return Cons.Reverse(list); default: return osd; } }
/// <summary> /// Set member values by decoding out of propertyData. Should only /// be called in initialization time (e.g. from constructor). /// </summary> /// <param name="propertyData"></param> private void FromOSDArray(OSDArray propertyData) { Property = (SyncableProperties.Type)(propertyData[0].AsInteger()); LastUpdateTimeStamp = propertyData[1].AsLong(); LastUpdateSyncID = propertyData[2].AsString(); OSD value = propertyData[3]; switch (Property) { /////////////////////////////////////// // Complex structure properties /////////////////////////////////////// case SyncableProperties.Type.AgentCircuitData: case SyncableProperties.Type.AvatarAppearance: LastUpdateValue = (OSDMap)value; break; case SyncableProperties.Type.Animations: LastUpdateValue = (OSDArray)value; break; //////////////////////////// // Integer/enum type properties //////////////////////////// case SyncableProperties.Type.CreationDate: // int case SyncableProperties.Type.LinkNum: // int case SyncableProperties.Type.OwnershipCost: // int case SyncableProperties.Type.SalePrice: // int case SyncableProperties.Type.ScriptAccessPin: // int case SyncableProperties.Type.AggregateScriptEvents: // enum case SyncableProperties.Type.Flags: // enum case SyncableProperties.Type.LocalFlags: // enum case SyncableProperties.Type.PresenceType: // enum LastUpdateValue = value.AsInteger(); break; case SyncableProperties.Type.ClickAction: case SyncableProperties.Type.Material: case SyncableProperties.Type.ObjectSaleType: LastUpdateValue = (byte)value.AsInteger(); break; //////////////////////////// // Boolean type properties //////////////////////////// case SyncableProperties.Type.AllowedDrop: case SyncableProperties.Type.IsAttachment: case SyncableProperties.Type.PassTouches: case SyncableProperties.Type.VolumeDetectActive: case SyncableProperties.Type.Flying: case SyncableProperties.Type.IsColliding: case SyncableProperties.Type.CollidingGround: case SyncableProperties.Type.Kinematic: case SyncableProperties.Type.IsSelected: case SyncableProperties.Type.AllowMovement: LastUpdateValue = value.AsBoolean(); break; //////////////////////////// // Vector3 type properties //////////////////////////// case SyncableProperties.Type.AngularVelocity: case SyncableProperties.Type.AttachedPos: case SyncableProperties.Type.GroupPosition: case SyncableProperties.Type.OffsetPosition: case SyncableProperties.Type.Scale: case SyncableProperties.Type.SitTargetPosition: case SyncableProperties.Type.SitTargetPositionLL: case SyncableProperties.Type.SOP_Acceleration: case SyncableProperties.Type.Velocity: case SyncableProperties.Type.Force: case SyncableProperties.Type.PA_Acceleration: case SyncableProperties.Type.PA_Velocity: case SyncableProperties.Type.PA_TargetVelocity: case SyncableProperties.Type.Position: case SyncableProperties.Type.RotationalVelocity: case SyncableProperties.Type.Size: case SyncableProperties.Type.Torque: case SyncableProperties.Type.AbsolutePosition: LastUpdateValue = value.AsVector3(); break; //////////////////////////// // UUID type properties //////////////////////////// case SyncableProperties.Type.AttachedAvatar: case SyncableProperties.Type.CollisionSound: case SyncableProperties.Type.CreatorID: case SyncableProperties.Type.FolderID: case SyncableProperties.Type.GroupID: case SyncableProperties.Type.LastOwnerID: case SyncableProperties.Type.OwnerID: case SyncableProperties.Type.Sound: LastUpdateValue = value.AsUUID(); break; //////////////////////////// // UInt type properties //////////////////////////// case SyncableProperties.Type.LocalId: case SyncableProperties.Type.AttachmentPoint: case SyncableProperties.Type.BaseMask: case SyncableProperties.Type.Category: case SyncableProperties.Type.EveryoneMask: case SyncableProperties.Type.GroupMask: case SyncableProperties.Type.InventorySerial: case SyncableProperties.Type.NextOwnerMask: case SyncableProperties.Type.OwnerMask: case SyncableProperties.Type.AgentControlFlags: case SyncableProperties.Type.ParentId: LastUpdateValue = value.AsUInteger(); break; //////////////////////////// // Float type properties //////////////////////////// case SyncableProperties.Type.CollisionSoundVolume: case SyncableProperties.Type.Buoyancy: LastUpdateValue = (float)value.AsReal(); break; //////////////////////////// // String type properties //////////////////////////// case SyncableProperties.Type.Color: case SyncableProperties.Type.CreatorData: case SyncableProperties.Type.Description: case SyncableProperties.Type.MediaUrl: case SyncableProperties.Type.Name: case SyncableProperties.Type.RealRegion: case SyncableProperties.Type.Shape: case SyncableProperties.Type.SitName: case SyncableProperties.Type.TaskInventory: case SyncableProperties.Type.Text: case SyncableProperties.Type.TouchName: LastUpdateValue = value.AsString(); break; //////////////////////////// // byte[] (binary data) type properties //////////////////////////// case SyncableProperties.Type.ParticleSystem: case SyncableProperties.Type.TextureAnimation: LastUpdateValue = value.AsBinary(); break; //////////////////////////// // Quaternion type properties //////////////////////////// case SyncableProperties.Type.RotationOffset: case SyncableProperties.Type.SitTargetOrientation: case SyncableProperties.Type.SitTargetOrientationLL: case SyncableProperties.Type.Orientation: case SyncableProperties.Type.Rotation: LastUpdateValue = value.AsQuaternion(); break; default: DebugLog.WarnFormat("[SYNCED PROPERTY] FromOSDArray: No handler for property {0} ", Property); break; } }