aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs')
-rw-r--r--OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs287
1 files changed, 287 insertions, 0 deletions
diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
new file mode 100644
index 0000000..19468c3
--- /dev/null
+++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
@@ -0,0 +1,287 @@
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
28using System.IO;
29using System.Text;
30using System.Xml;
31using OpenMetaverse;
32using OpenSim.Framework;
33using log4net;
34using System.Reflection;
35
36namespace OpenSim.Framework.Serialization.External
37{
38 /// <summary>
39 /// Serialize and deserialize region settings as an external format.
40 /// </summary>
41 public class RegionSettingsSerializer
42 {
43 /// <summary>
44 /// Deserialize settings
45 /// </summary>
46 /// <param name="serializedSettings"></param>
47 /// <returns></returns>
48 /// <exception cref="System.Xml.XmlException"></exception>
49 public static RegionSettings Deserialize(byte[] serializedSettings)
50 {
51 return Deserialize(Encoding.ASCII.GetString(serializedSettings, 0, serializedSettings.Length));
52 }
53
54 /// <summary>
55 /// Deserialize settings
56 /// </summary>
57 /// <param name="serializedSettings"></param>
58 /// <returns></returns>
59 /// <exception cref="System.Xml.XmlException"></exception>
60 public static RegionSettings Deserialize(string serializedSettings)
61 {
62 RegionSettings settings = new RegionSettings();
63
64 StringReader sr = new StringReader(serializedSettings);
65 XmlTextReader xtr = new XmlTextReader(sr);
66
67 xtr.ReadStartElement("RegionSettings");
68
69 xtr.ReadStartElement("General");
70
71 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
72 {
73 switch (xtr.Name)
74 {
75 case "AllowDamage":
76 settings.AllowDamage = bool.Parse(xtr.ReadElementContentAsString());
77 break;
78 case "AllowLandResell":
79 settings.AllowLandResell = bool.Parse(xtr.ReadElementContentAsString());
80 break;
81 case "AllowLandJoinDivide":
82 settings.AllowLandJoinDivide = bool.Parse(xtr.ReadElementContentAsString());
83 break;
84 case "BlockFly":
85 settings.BlockFly = bool.Parse(xtr.ReadElementContentAsString());
86 break;
87 case "BlockLandShowInSearch":
88 settings.BlockShowInSearch = bool.Parse(xtr.ReadElementContentAsString());
89 break;
90 case "BlockTerraform":
91 settings.BlockTerraform = bool.Parse(xtr.ReadElementContentAsString());
92 break;
93 case "DisableCollisions":
94 settings.DisableCollisions = bool.Parse(xtr.ReadElementContentAsString());
95 break;
96 case "DisablePhysics":
97 settings.DisablePhysics = bool.Parse(xtr.ReadElementContentAsString());
98 break;
99 case "DisableScripts":
100 settings.DisableScripts = bool.Parse(xtr.ReadElementContentAsString());
101 break;
102 case "MaturityRating":
103 settings.Maturity = int.Parse(xtr.ReadElementContentAsString());
104 break;
105 case "RestrictPushing":
106 settings.RestrictPushing = bool.Parse(xtr.ReadElementContentAsString());
107 break;
108 case "AgentLimit":
109 settings.AgentLimit = int.Parse(xtr.ReadElementContentAsString());
110 break;
111 case "ObjectBonus":
112 settings.ObjectBonus = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
113 break;
114 }
115 }
116
117 xtr.ReadEndElement();
118 xtr.ReadStartElement("GroundTextures");
119
120 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
121 {
122 switch (xtr.Name)
123 {
124 case "Texture1":
125 settings.TerrainTexture1 = UUID.Parse(xtr.ReadElementContentAsString());
126 break;
127 case "Texture2":
128 settings.TerrainTexture2 = UUID.Parse(xtr.ReadElementContentAsString());
129 break;
130 case "Texture3":
131 settings.TerrainTexture3 = UUID.Parse(xtr.ReadElementContentAsString());
132 break;
133 case "Texture4":
134 settings.TerrainTexture4 = UUID.Parse(xtr.ReadElementContentAsString());
135 break;
136 case "ElevationLowSW":
137 settings.Elevation1SW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
138 break;
139 case "ElevationLowNW":
140 settings.Elevation1NW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
141 break;
142 case "ElevationLowSE":
143 settings.Elevation1SE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
144 break;
145 case "ElevationLowNE":
146 settings.Elevation1NE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
147 break;
148 case "ElevationHighSW":
149 settings.Elevation2SW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
150 break;
151 case "ElevationHighNW":
152 settings.Elevation2NW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
153 break;
154 case "ElevationHighSE":
155 settings.Elevation2SE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
156 break;
157 case "ElevationHighNE":
158 settings.Elevation2NE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
159 break;
160 }
161 }
162
163 xtr.ReadEndElement();
164 xtr.ReadStartElement("Terrain");
165
166 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
167 {
168 switch (xtr.Name)
169 {
170 case "WaterHeight":
171 settings.WaterHeight = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
172 break;
173 case "TerrainRaiseLimit":
174 settings.TerrainRaiseLimit = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
175 break;
176 case "TerrainLowerLimit":
177 settings.TerrainLowerLimit = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
178 break;
179 case "UseEstateSun":
180 settings.UseEstateSun = bool.Parse(xtr.ReadElementContentAsString());
181 break;
182 case "FixedSun":
183 settings.FixedSun = bool.Parse(xtr.ReadElementContentAsString());
184 break;
185 case "SunPosition":
186 settings.SunPosition = double.Parse(xtr.ReadElementContentAsString());
187 break;
188 }
189 }
190
191 xtr.ReadEndElement();
192
193 if (xtr.IsStartElement("Telehub"))
194 {
195 xtr.ReadStartElement("Telehub");
196
197 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
198 {
199 switch (xtr.Name)
200 {
201 case "TelehubObject":
202 settings.TelehubObject = UUID.Parse(xtr.ReadElementContentAsString());
203 break;
204 case "SpawnPoint":
205 string str = xtr.ReadElementContentAsString();
206 SpawnPoint sp = SpawnPoint.Parse(str);
207 settings.AddSpawnPoint(sp);
208 break;
209 }
210 }
211 }
212
213 xtr.Close();
214 sr.Close();
215
216 return settings;
217 }
218
219 public static string Serialize(RegionSettings settings)
220 {
221 StringWriter sw = new StringWriter();
222 XmlTextWriter xtw = new XmlTextWriter(sw);
223 xtw.Formatting = Formatting.Indented;
224 xtw.WriteStartDocument();
225
226 xtw.WriteStartElement("RegionSettings");
227
228 xtw.WriteStartElement("General");
229 xtw.WriteElementString("AllowDamage", settings.AllowDamage.ToString());
230 xtw.WriteElementString("AllowLandResell", settings.AllowLandResell.ToString());
231 xtw.WriteElementString("AllowLandJoinDivide", settings.AllowLandJoinDivide.ToString());
232 xtw.WriteElementString("BlockFly", settings.BlockFly.ToString());
233 xtw.WriteElementString("BlockLandShowInSearch", settings.BlockShowInSearch.ToString());
234 xtw.WriteElementString("BlockTerraform", settings.BlockTerraform.ToString());
235 xtw.WriteElementString("DisableCollisions", settings.DisableCollisions.ToString());
236 xtw.WriteElementString("DisablePhysics", settings.DisablePhysics.ToString());
237 xtw.WriteElementString("DisableScripts", settings.DisableScripts.ToString());
238 xtw.WriteElementString("MaturityRating", settings.Maturity.ToString());
239 xtw.WriteElementString("RestrictPushing", settings.RestrictPushing.ToString());
240 xtw.WriteElementString("AgentLimit", settings.AgentLimit.ToString());
241 xtw.WriteElementString("ObjectBonus", settings.ObjectBonus.ToString());
242 xtw.WriteEndElement();
243
244 xtw.WriteStartElement("GroundTextures");
245 xtw.WriteElementString("Texture1", settings.TerrainTexture1.ToString());
246 xtw.WriteElementString("Texture2", settings.TerrainTexture2.ToString());
247 xtw.WriteElementString("Texture3", settings.TerrainTexture3.ToString());
248 xtw.WriteElementString("Texture4", settings.TerrainTexture4.ToString());
249 xtw.WriteElementString("ElevationLowSW", settings.Elevation1SW.ToString());
250 xtw.WriteElementString("ElevationLowNW", settings.Elevation1NW.ToString());
251 xtw.WriteElementString("ElevationLowSE", settings.Elevation1SE.ToString());
252 xtw.WriteElementString("ElevationLowNE", settings.Elevation1NE.ToString());
253 xtw.WriteElementString("ElevationHighSW", settings.Elevation2SW.ToString());
254 xtw.WriteElementString("ElevationHighNW", settings.Elevation2NW.ToString());
255 xtw.WriteElementString("ElevationHighSE", settings.Elevation2SE.ToString());
256 xtw.WriteElementString("ElevationHighNE", settings.Elevation2NE.ToString());
257 xtw.WriteEndElement();
258
259 xtw.WriteStartElement("Terrain");
260 xtw.WriteElementString("WaterHeight", settings.WaterHeight.ToString());
261 xtw.WriteElementString("TerrainRaiseLimit", settings.TerrainRaiseLimit.ToString());
262 xtw.WriteElementString("TerrainLowerLimit", settings.TerrainLowerLimit.ToString());
263 xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString());
264 xtw.WriteElementString("FixedSun", settings.FixedSun.ToString());
265 xtw.WriteElementString("SunPosition", settings.SunPosition.ToString());
266 // Note: 'SunVector' isn't saved because this value is owned by the Sun Module, which
267 // calculates it automatically according to the date and other factors.
268 xtw.WriteEndElement();
269
270 xtw.WriteStartElement("Telehub");
271 if (settings.TelehubObject != UUID.Zero)
272 {
273 xtw.WriteElementString("TelehubObject", settings.TelehubObject.ToString());
274 foreach (SpawnPoint sp in settings.SpawnPoints())
275 xtw.WriteElementString("SpawnPoint", sp.ToString());
276 }
277 xtw.WriteEndElement();
278
279 xtw.WriteEndElement();
280
281 xtw.Close();
282 sw.Close();
283
284 return sw.ToString();
285 }
286 }
287}