diff options
Diffstat (limited to 'OpenSim/Framework/Serialization/External/LandDataSerializer.cs')
-rw-r--r-- | OpenSim/Framework/Serialization/External/LandDataSerializer.cs | 266 |
1 files changed, 266 insertions, 0 deletions
diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs new file mode 100644 index 0000000..e42d56f --- /dev/null +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs | |||
@@ -0,0 +1,266 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using System.Xml; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | |||
38 | namespace OpenSim.Framework.Serialization.External | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Serialize and deserialize LandData as an external format. | ||
42 | /// </summary> | ||
43 | public class LandDataSerializer | ||
44 | { | ||
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private static Dictionary<string, Action<LandData, XmlReader>> m_ldProcessors | ||
48 | = new Dictionary<string, Action<LandData, XmlReader>>(); | ||
49 | |||
50 | private static Dictionary<string, Action<LandAccessEntry, XmlReader>> m_laeProcessors | ||
51 | = new Dictionary<string, Action<LandAccessEntry, XmlReader>>(); | ||
52 | |||
53 | static LandDataSerializer() | ||
54 | { | ||
55 | // LandData processors | ||
56 | m_ldProcessors.Add( | ||
57 | "Area", (ld, xtr) => ld.Area = Convert.ToInt32(xtr.ReadElementString("Area"))); | ||
58 | m_ldProcessors.Add( | ||
59 | "AuctionID", (ld, xtr) => ld.AuctionID = Convert.ToUInt32(xtr.ReadElementString("AuctionID"))); | ||
60 | m_ldProcessors.Add( | ||
61 | "AuthBuyerID", (ld, xtr) => ld.AuthBuyerID = UUID.Parse(xtr.ReadElementString("AuthBuyerID"))); | ||
62 | m_ldProcessors.Add( | ||
63 | "Category", (ld, xtr) => ld.Category = (ParcelCategory)Convert.ToSByte(xtr.ReadElementString("Category"))); | ||
64 | m_ldProcessors.Add( | ||
65 | "ClaimDate", (ld, xtr) => ld.ClaimDate = Convert.ToInt32(xtr.ReadElementString("ClaimDate"))); | ||
66 | m_ldProcessors.Add( | ||
67 | "ClaimPrice", (ld, xtr) => ld.ClaimPrice = Convert.ToInt32(xtr.ReadElementString("ClaimPrice"))); | ||
68 | m_ldProcessors.Add( | ||
69 | "GlobalID", (ld, xtr) => ld.GlobalID = UUID.Parse(xtr.ReadElementString("GlobalID"))); | ||
70 | m_ldProcessors.Add( | ||
71 | "GroupID", (ld, xtr) => ld.GroupID = UUID.Parse(xtr.ReadElementString("GroupID"))); | ||
72 | m_ldProcessors.Add( | ||
73 | "IsGroupOwned", (ld, xtr) => ld.IsGroupOwned = Convert.ToBoolean(xtr.ReadElementString("IsGroupOwned"))); | ||
74 | m_ldProcessors.Add( | ||
75 | "Bitmap", (ld, xtr) => ld.Bitmap = Convert.FromBase64String(xtr.ReadElementString("Bitmap"))); | ||
76 | m_ldProcessors.Add( | ||
77 | "Description", (ld, xtr) => ld.Description = xtr.ReadElementString("Description")); | ||
78 | m_ldProcessors.Add( | ||
79 | "Flags", (ld, xtr) => ld.Flags = Convert.ToUInt32(xtr.ReadElementString("Flags"))); | ||
80 | m_ldProcessors.Add( | ||
81 | "LandingType", (ld, xtr) => ld.LandingType = Convert.ToByte(xtr.ReadElementString("LandingType"))); | ||
82 | m_ldProcessors.Add( | ||
83 | "Name", (ld, xtr) => ld.Name = xtr.ReadElementString("Name")); | ||
84 | m_ldProcessors.Add( | ||
85 | "Status", (ld, xtr) => ld.Status = (ParcelStatus)Convert.ToSByte(xtr.ReadElementString("Status"))); | ||
86 | m_ldProcessors.Add( | ||
87 | "LocalID", (ld, xtr) => ld.LocalID = Convert.ToInt32(xtr.ReadElementString("LocalID"))); | ||
88 | m_ldProcessors.Add( | ||
89 | "MediaAutoScale", (ld, xtr) => ld.MediaAutoScale = Convert.ToByte(xtr.ReadElementString("MediaAutoScale"))); | ||
90 | m_ldProcessors.Add( | ||
91 | "MediaID", (ld, xtr) => ld.MediaID = UUID.Parse(xtr.ReadElementString("MediaID"))); | ||
92 | m_ldProcessors.Add( | ||
93 | "MediaURL", (ld, xtr) => ld.MediaURL = xtr.ReadElementString("MediaURL")); | ||
94 | m_ldProcessors.Add( | ||
95 | "MusicURL", (ld, xtr) => ld.MusicURL = xtr.ReadElementString("MusicURL")); | ||
96 | m_ldProcessors.Add( | ||
97 | "OwnerID", (ld, xtr) => ld.OwnerID = UUID.Parse(xtr.ReadElementString("OwnerID"))); | ||
98 | |||
99 | m_ldProcessors.Add( | ||
100 | "ParcelAccessList", ProcessParcelAccessList); | ||
101 | |||
102 | m_ldProcessors.Add( | ||
103 | "PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours"))); | ||
104 | m_ldProcessors.Add( | ||
105 | "PassPrice", (ld, xtr) => ld.PassPrice = Convert.ToInt32(xtr.ReadElementString("PassPrice"))); | ||
106 | m_ldProcessors.Add( | ||
107 | "SalePrice", (ld, xtr) => ld.SalePrice = Convert.ToInt32(xtr.ReadElementString("SalePrice"))); | ||
108 | m_ldProcessors.Add( | ||
109 | "SnapshotID", (ld, xtr) => ld.SnapshotID = UUID.Parse(xtr.ReadElementString("SnapshotID"))); | ||
110 | m_ldProcessors.Add( | ||
111 | "UserLocation", (ld, xtr) => ld.UserLocation = Vector3.Parse(xtr.ReadElementString("UserLocation"))); | ||
112 | m_ldProcessors.Add( | ||
113 | "UserLookAt", (ld, xtr) => ld.UserLookAt = Vector3.Parse(xtr.ReadElementString("UserLookAt"))); | ||
114 | |||
115 | // No longer used here // | ||
116 | // m_ldProcessors.Add("Dwell", (landData, xtr) => return); | ||
117 | |||
118 | m_ldProcessors.Add( | ||
119 | "OtherCleanTime", (ld, xtr) => ld.OtherCleanTime = Convert.ToInt32(xtr.ReadElementString("OtherCleanTime"))); | ||
120 | |||
121 | // LandAccessEntryProcessors | ||
122 | m_laeProcessors.Add( | ||
123 | "AgentID", (lae, xtr) => lae.AgentID = UUID.Parse(xtr.ReadElementString("AgentID"))); | ||
124 | m_laeProcessors.Add( | ||
125 | "Time", (lae, xtr) => | ||
126 | { | ||
127 | // We really don't care about temp vs perm here and this | ||
128 | // would break on old oars. Assume all bans are perm | ||
129 | xtr.ReadElementString("Time"); | ||
130 | lae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time")); | ||
131 | } | ||
132 | ); | ||
133 | m_laeProcessors.Add( | ||
134 | "AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList"))); | ||
135 | } | ||
136 | |||
137 | public static void ProcessParcelAccessList(LandData ld, XmlReader xtr) | ||
138 | { | ||
139 | if (!xtr.IsEmptyElement) | ||
140 | { | ||
141 | while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) | ||
142 | { | ||
143 | LandAccessEntry lae = new LandAccessEntry(); | ||
144 | |||
145 | xtr.ReadStartElement("ParcelAccessEntry"); | ||
146 | |||
147 | ExternalRepresentationUtils.ExecuteReadProcessors<LandAccessEntry>(lae, m_laeProcessors, xtr); | ||
148 | |||
149 | xtr.ReadEndElement(); | ||
150 | |||
151 | ld.ParcelAccessList.Add(lae); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | xtr.Read(); | ||
156 | } | ||
157 | |||
158 | /// <summary> | ||
159 | /// Reify/deserialize landData | ||
160 | /// </summary> | ||
161 | /// <param name="serializedLandData"></param> | ||
162 | /// <returns></returns> | ||
163 | /// <exception cref="System.Xml.XmlException"></exception> | ||
164 | public static LandData Deserialize(byte[] serializedLandData) | ||
165 | { | ||
166 | return Deserialize(Encoding.UTF8.GetString(serializedLandData, 0, serializedLandData.Length)); | ||
167 | } | ||
168 | |||
169 | /// <summary> | ||
170 | /// Reify/deserialize landData | ||
171 | /// </summary> | ||
172 | /// <param name="serializedLandData"></param> | ||
173 | /// <returns></returns> | ||
174 | /// <exception cref="System.Xml.XmlException"></exception> | ||
175 | public static LandData Deserialize(string serializedLandData) | ||
176 | { | ||
177 | LandData landData = new LandData(); | ||
178 | |||
179 | using (XmlTextReader reader = new XmlTextReader(new StringReader(serializedLandData))) | ||
180 | { | ||
181 | reader.ReadStartElement("LandData"); | ||
182 | |||
183 | ExternalRepresentationUtils.ExecuteReadProcessors<LandData>(landData, m_ldProcessors, reader); | ||
184 | |||
185 | reader.ReadEndElement(); | ||
186 | } | ||
187 | |||
188 | return landData; | ||
189 | } | ||
190 | |||
191 | /// <summary> | ||
192 | /// Serialize land data | ||
193 | /// </summary> | ||
194 | /// <param name='landData'></param> | ||
195 | /// <param name='options'> | ||
196 | /// Serialization options. | ||
197 | /// Can be null if there are no options. | ||
198 | /// "wipe-owners" will write UUID.Zero rather than the ownerID so that a later reload loads all parcels with the estate owner as the owner | ||
199 | /// </param> | ||
200 | public static string Serialize(LandData landData, Dictionary<string, object> options) | ||
201 | { | ||
202 | StringWriter sw = new StringWriter(); | ||
203 | XmlTextWriter xtw = new XmlTextWriter(sw); | ||
204 | xtw.Formatting = Formatting.Indented; | ||
205 | |||
206 | xtw.WriteStartDocument(); | ||
207 | xtw.WriteStartElement("LandData"); | ||
208 | |||
209 | xtw.WriteElementString("Area", Convert.ToString(landData.Area)); | ||
210 | xtw.WriteElementString("AuctionID", Convert.ToString(landData.AuctionID)); | ||
211 | xtw.WriteElementString("AuthBuyerID", landData.AuthBuyerID.ToString()); | ||
212 | xtw.WriteElementString("Category", Convert.ToString((sbyte)landData.Category)); | ||
213 | xtw.WriteElementString("ClaimDate", Convert.ToString(landData.ClaimDate)); | ||
214 | xtw.WriteElementString("ClaimPrice", Convert.ToString(landData.ClaimPrice)); | ||
215 | xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); | ||
216 | |||
217 | UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.GroupID; | ||
218 | xtw.WriteElementString("GroupID", groupID.ToString()); | ||
219 | |||
220 | bool isGroupOwned = options.ContainsKey("wipe-owners") ? false : landData.IsGroupOwned; | ||
221 | xtw.WriteElementString("IsGroupOwned", Convert.ToString(isGroupOwned)); | ||
222 | |||
223 | xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap)); | ||
224 | xtw.WriteElementString("Description", landData.Description); | ||
225 | xtw.WriteElementString("Flags", Convert.ToString((uint)landData.Flags)); | ||
226 | xtw.WriteElementString("LandingType", Convert.ToString((byte)landData.LandingType)); | ||
227 | xtw.WriteElementString("Name", landData.Name); | ||
228 | xtw.WriteElementString("Status", Convert.ToString((sbyte)landData.Status)); | ||
229 | xtw.WriteElementString("LocalID", landData.LocalID.ToString()); | ||
230 | xtw.WriteElementString("MediaAutoScale", Convert.ToString(landData.MediaAutoScale)); | ||
231 | xtw.WriteElementString("MediaID", landData.MediaID.ToString()); | ||
232 | xtw.WriteElementString("MediaURL", landData.MediaURL); | ||
233 | xtw.WriteElementString("MusicURL", landData.MusicURL); | ||
234 | |||
235 | UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.OwnerID; | ||
236 | xtw.WriteElementString("OwnerID", ownerID.ToString()); | ||
237 | |||
238 | xtw.WriteStartElement("ParcelAccessList"); | ||
239 | foreach (LandAccessEntry pal in landData.ParcelAccessList) | ||
240 | { | ||
241 | xtw.WriteStartElement("ParcelAccessEntry"); | ||
242 | xtw.WriteElementString("AgentID", pal.AgentID.ToString()); | ||
243 | xtw.WriteElementString("Time", pal.Expires.ToString()); | ||
244 | xtw.WriteElementString("AccessList", Convert.ToString((uint)pal.Flags)); | ||
245 | xtw.WriteEndElement(); | ||
246 | } | ||
247 | xtw.WriteEndElement(); | ||
248 | |||
249 | xtw.WriteElementString("PassHours", Convert.ToString(landData.PassHours)); | ||
250 | xtw.WriteElementString("PassPrice", Convert.ToString(landData.PassPrice)); | ||
251 | xtw.WriteElementString("SalePrice", Convert.ToString(landData.SalePrice)); | ||
252 | xtw.WriteElementString("SnapshotID", landData.SnapshotID.ToString()); | ||
253 | xtw.WriteElementString("UserLocation", landData.UserLocation.ToString()); | ||
254 | xtw.WriteElementString("UserLookAt", landData.UserLookAt.ToString()); | ||
255 | xtw.WriteElementString("Dwell", "0"); | ||
256 | xtw.WriteElementString("OtherCleanTime", Convert.ToString(landData.OtherCleanTime)); | ||
257 | |||
258 | xtw.WriteEndElement(); | ||
259 | |||
260 | xtw.Close(); | ||
261 | sw.Close(); | ||
262 | |||
263 | return sw.ToString(); | ||
264 | } | ||
265 | } | ||
266 | } | ||