aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-03-27 18:13:34 +0000
committerJustin Clarke Casey2009-03-27 18:13:34 +0000
commit561f24156476041bdcd2ef2fdccd296a4127d0b0 (patch)
treed06fa3bbff0f6755ff022d4d761ec1acda25b48c /OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
parent* Also temporarily disable T032_CrossAttachments() since this relies on the e... (diff)
downloadopensim-SC_OLD-561f24156476041bdcd2ef2fdccd296a4127d0b0.zip
opensim-SC_OLD-561f24156476041bdcd2ef2fdccd296a4127d0b0.tar.gz
opensim-SC_OLD-561f24156476041bdcd2ef2fdccd296a4127d0b0.tar.bz2
opensim-SC_OLD-561f24156476041bdcd2ef2fdccd296a4127d0b0.tar.xz
* minor: move RegionSettingsSerializer into OpenSim.Framework.Serialization
Diffstat (limited to 'OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs')
-rw-r--r--OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs254
1 files changed, 254 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..3ee9e1b
--- /dev/null
+++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
@@ -0,0 +1,254 @@
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 OpenSim 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;
33
34namespace OpenSim.Framework.Serialization.External
35{
36 /// <summary>
37 /// Serialize and deserialize region settings for an archive file format.
38 /// </summary>
39 /// We didn't simply use automatic .NET serializagion for OpenSim.Framework.RegionSettings since this is really
40 /// a file format rather than an object serialization.
41 public class RegionSettingsSerializer
42 {
43 protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
44
45 /// <summary>
46 /// Deserialize region settings
47 /// </summary>
48 /// <param name="serializedSettings"></param>
49 /// <returns></returns>
50 /// <exception cref="System.Xml.XmlException"></exception>
51 public static RegionSettings Deserialize(byte[] serializedSettings)
52 {
53 return Deserialize(m_asciiEncoding.GetString(serializedSettings, 0, serializedSettings.Length));
54 }
55
56 /// <summary>
57 /// Deserialize region settings
58 /// </summary>
59 /// <param name="serializedSettings"></param>
60 /// <returns></returns>
61 /// <exception cref="System.Xml.XmlException"></exception>
62 public static RegionSettings Deserialize(string serializedSettings)
63 {
64 RegionSettings settings = new RegionSettings();
65
66 StringReader sr = new StringReader(serializedSettings);
67 XmlTextReader xtr = new XmlTextReader(sr);
68
69 xtr.ReadStartElement("RegionSettings");
70
71 xtr.ReadStartElement("General");
72
73 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
74 {
75 switch (xtr.Name)
76 {
77 case "AllowDamage":
78 settings.AllowDamage = bool.Parse(xtr.ReadElementContentAsString());
79 break;
80 case "AllowLandResell":
81 settings.AllowLandResell = bool.Parse(xtr.ReadElementContentAsString());
82 break;
83 case "AllowLandJoinDivide":
84 settings.AllowLandJoinDivide = bool.Parse(xtr.ReadElementContentAsString());
85 break;
86 case "BlockFly":
87 settings.BlockFly = bool.Parse(xtr.ReadElementContentAsString());
88 break;
89 case "BlockLandShowInSearch":
90 settings.BlockShowInSearch = bool.Parse(xtr.ReadElementContentAsString());
91 break;
92 case "BlockTerraform":
93 settings.BlockTerraform = bool.Parse(xtr.ReadElementContentAsString());
94 break;
95 case "DisableCollisions":
96 settings.DisableCollisions = bool.Parse(xtr.ReadElementContentAsString());
97 break;
98 case "DisablePhysics":
99 settings.DisablePhysics = bool.Parse(xtr.ReadElementContentAsString());
100 break;
101 case "DisableScripts":
102 settings.DisableScripts = bool.Parse(xtr.ReadElementContentAsString());
103 break;
104 case "MaturityRating":
105 settings.Maturity = int.Parse(xtr.ReadElementContentAsString());
106 break;
107 case "RestrictPushing":
108 settings.RestrictPushing = bool.Parse(xtr.ReadElementContentAsString());
109 break;
110 case "AgentLimit":
111 settings.AgentLimit = int.Parse(xtr.ReadElementContentAsString());
112 break;
113 case "ObjectBonus":
114 settings.ObjectBonus = double.Parse(xtr.ReadElementContentAsString());
115 break;
116 }
117 }
118
119 xtr.ReadEndElement();
120 xtr.ReadStartElement("GroundTextures");
121
122 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
123 {
124 switch (xtr.Name)
125 {
126 case "Texture1":
127 settings.TerrainTexture1 = UUID.Parse(xtr.ReadElementContentAsString());
128 break;
129 case "Texture2":
130 settings.TerrainTexture2 = UUID.Parse(xtr.ReadElementContentAsString());
131 break;
132 case "Texture3":
133 settings.TerrainTexture3 = UUID.Parse(xtr.ReadElementContentAsString());
134 break;
135 case "Texture4":
136 settings.TerrainTexture4 = UUID.Parse(xtr.ReadElementContentAsString());
137 break;
138 case "ElevationLowSW":
139 settings.Elevation1SW = double.Parse(xtr.ReadElementContentAsString());
140 break;
141 case "ElevationLowNW":
142 settings.Elevation1NW = double.Parse(xtr.ReadElementContentAsString());
143 break;
144 case "ElevationLowSE":
145 settings.Elevation1SE = double.Parse(xtr.ReadElementContentAsString());
146 break;
147 case "ElevationLowNE":
148 settings.Elevation1NE = double.Parse(xtr.ReadElementContentAsString());
149 break;
150 case "ElevationHighSW":
151 settings.Elevation2SW = double.Parse(xtr.ReadElementContentAsString());
152 break;
153 case "ElevationHighNW":
154 settings.Elevation2NW = double.Parse(xtr.ReadElementContentAsString());
155 break;
156 case "ElevationHighSE":
157 settings.Elevation2SE = double.Parse(xtr.ReadElementContentAsString());
158 break;
159 case "ElevationHighNE":
160 settings.Elevation2NE = double.Parse(xtr.ReadElementContentAsString());
161 break;
162 }
163 }
164
165 xtr.ReadEndElement();
166 xtr.ReadStartElement("Terrain");
167
168 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
169 {
170 switch (xtr.Name)
171 {
172 case "WaterHeight":
173 settings.WaterHeight = double.Parse(xtr.ReadElementContentAsString());
174 break;
175 case "TerrainRaiseLimit":
176 settings.TerrainRaiseLimit = double.Parse(xtr.ReadElementContentAsString());
177 break;
178 case "TerrainLowerLimit":
179 settings.TerrainLowerLimit = double.Parse(xtr.ReadElementContentAsString());
180 break;
181 case "UseEstateSun":
182 settings.UseEstateSun = bool.Parse(xtr.ReadElementContentAsString());
183 break;
184 case "FixedSun":
185 settings.FixedSun = bool.Parse(xtr.ReadElementContentAsString());
186 break;
187 }
188 }
189
190 xtr.Close();
191 sr.Close();
192
193 return settings;
194 }
195
196 public static string Serialize(RegionSettings settings)
197 {
198 StringWriter sw = new StringWriter();
199 XmlTextWriter xtw = new XmlTextWriter(sw);
200 xtw.Formatting = Formatting.Indented;
201 xtw.WriteStartDocument();
202
203 xtw.WriteStartElement("RegionSettings");
204
205 xtw.WriteStartElement("General");
206 xtw.WriteElementString("AllowDamage", settings.AllowDamage.ToString());
207 xtw.WriteElementString("AllowLandResell", settings.AllowLandResell.ToString());
208 xtw.WriteElementString("AllowLandJoinDivide", settings.AllowLandJoinDivide.ToString());
209 xtw.WriteElementString("BlockFly", settings.BlockFly.ToString());
210 xtw.WriteElementString("BlockLandShowInSearch", settings.BlockShowInSearch.ToString());
211 xtw.WriteElementString("BlockTerraform", settings.BlockTerraform.ToString());
212 xtw.WriteElementString("DisableCollisions", settings.DisableCollisions.ToString());
213 xtw.WriteElementString("DisablePhysics", settings.DisablePhysics.ToString());
214 xtw.WriteElementString("DisableScripts", settings.DisableScripts.ToString());
215 xtw.WriteElementString("MaturityRating", settings.Maturity.ToString());
216 xtw.WriteElementString("RestrictPushing", settings.RestrictPushing.ToString());
217 xtw.WriteElementString("AgentLimit", settings.AgentLimit.ToString());
218 xtw.WriteElementString("ObjectBonus", settings.ObjectBonus.ToString());
219 xtw.WriteEndElement();
220
221 xtw.WriteStartElement("GroundTextures");
222 xtw.WriteElementString("Texture1", settings.TerrainTexture1.ToString());
223 xtw.WriteElementString("Texture2", settings.TerrainTexture2.ToString());
224 xtw.WriteElementString("Texture3", settings.TerrainTexture3.ToString());
225 xtw.WriteElementString("Texture4", settings.TerrainTexture4.ToString());
226 xtw.WriteElementString("ElevationLowSW", settings.Elevation1SW.ToString());
227 xtw.WriteElementString("ElevationLowNW", settings.Elevation1NW.ToString());
228 xtw.WriteElementString("ElevationLowSE", settings.Elevation1SE.ToString());
229 xtw.WriteElementString("ElevationLowNE", settings.Elevation1NE.ToString());
230 xtw.WriteElementString("ElevationHighSW", settings.Elevation2SW.ToString());
231 xtw.WriteElementString("ElevationHighNW", settings.Elevation2NW.ToString());
232 xtw.WriteElementString("ElevationHighSE", settings.Elevation2SE.ToString());
233 xtw.WriteElementString("ElevationHighNE", settings.Elevation2NE.ToString());
234 xtw.WriteEndElement();
235
236 xtw.WriteStartElement("Terrain");
237 xtw.WriteElementString("WaterHeight", settings.WaterHeight.ToString());
238 xtw.WriteElementString("TerrainRaiseLimit", settings.TerrainRaiseLimit.ToString());
239 xtw.WriteElementString("TerrainLowerLimit", settings.TerrainLowerLimit.ToString());
240 xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString());
241 xtw.WriteElementString("FixedSun", settings.FixedSun.ToString());
242 // XXX: Need to expose interface to get sun phase information from sun module
243 // xtw.WriteStartElement("SunPhase",
244 xtw.WriteEndElement();
245
246 xtw.WriteEndElement();
247
248 xtw.Close();
249 sw.Close();
250
251 return sw.ToString();
252 }
253 }
254}