aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Serialiser
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Serialiser')
-rw-r--r--OpenSim/Region/CoreModules/World/Serialiser/IFileSerialiser.cs36
-rw-r--r--OpenSim/Region/CoreModules/World/Serialiser/SerialiseObjects.cs125
-rw-r--r--OpenSim/Region/CoreModules/World/Serialiser/SerialiseTerrain.cs53
-rw-r--r--OpenSim/Region/CoreModules/World/Serialiser/SerialiserModule.cs226
4 files changed, 440 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Serialiser/IFileSerialiser.cs b/OpenSim/Region/CoreModules/World/Serialiser/IFileSerialiser.cs
new file mode 100644
index 0000000..acc7bb8
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Serialiser/IFileSerialiser.cs
@@ -0,0 +1,36 @@
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 OpenSim.Region.Framework.Scenes;
29
30namespace OpenSim.Region.CoreModules.World.Serialiser
31{
32 internal interface IFileSerialiser
33 {
34 string WriteToFile(Scene scene, string dir);
35 }
36} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Serialiser/SerialiseObjects.cs b/OpenSim/Region/CoreModules/World/Serialiser/SerialiseObjects.cs
new file mode 100644
index 0000000..ed6448f
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Serialiser/SerialiseObjects.cs
@@ -0,0 +1,125 @@
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.Collections.Generic;
29using System.IO;
30using System.IO.Compression;
31using System.Text;
32using System.Xml;
33using OpenSim.Region.Framework.Scenes;
34
35namespace OpenSim.Region.CoreModules.World.Serialiser
36{
37 internal class SerialiseObjects : IFileSerialiser
38 {
39 #region IFileSerialiser Members
40
41 public string WriteToFile(Scene scene, string dir)
42 {
43 string targetFileName = dir + "objects.xml";
44
45 SaveSerialisedToFile(targetFileName, scene);
46
47 return "objects.xml";
48 }
49
50 #endregion
51
52 public void SaveSerialisedToFile(string fileName, Scene scene)
53 {
54 string xmlstream = GetObjectXml(scene);
55
56 MemoryStream stream = ReformatXmlString(xmlstream);
57
58 stream.Seek(0, SeekOrigin.Begin);
59 CreateXmlFile(stream, fileName);
60
61 stream.Seek(0, SeekOrigin.Begin);
62 CreateCompressedXmlFile(stream, fileName);
63 }
64
65 private static MemoryStream ReformatXmlString(string xmlstream)
66 {
67 MemoryStream stream = new MemoryStream();
68 XmlTextWriter formatter = new XmlTextWriter(stream, Encoding.UTF8);
69 XmlDocument doc = new XmlDocument();
70
71 doc.LoadXml(xmlstream);
72 formatter.Formatting = Formatting.Indented;
73 doc.WriteContentTo(formatter);
74 formatter.Flush();
75 return stream;
76 }
77
78 private static string GetObjectXml(Scene scene)
79 {
80 string xmlstream = "<scene>";
81
82 List<EntityBase> EntityList = scene.GetEntities();
83 List<string> EntityXml = new List<string>();
84
85 foreach (EntityBase ent in EntityList)
86 {
87 if (ent is SceneObjectGroup)
88 {
89 EntityXml.Add(((SceneObjectGroup) ent).ToXmlString2());
90 }
91 }
92 EntityXml.Sort();
93
94 foreach (string xml in EntityXml)
95 xmlstream += xml;
96
97 xmlstream += "</scene>";
98 return xmlstream;
99 }
100
101 private static void CreateXmlFile(MemoryStream xmlStream, string fileName)
102 {
103 FileStream objectsFile = new FileStream(fileName, FileMode.Create);
104
105 xmlStream.WriteTo(objectsFile);
106 objectsFile.Flush();
107 objectsFile.Close();
108 }
109
110 private static void CreateCompressedXmlFile(MemoryStream xmlStream, string fileName)
111 {
112 #region GZip Compressed Version
113
114 FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create);
115 MemoryStream gzipMSStream = new MemoryStream();
116 GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress);
117 xmlStream.WriteTo(gzipStream);
118 gzipMSStream.WriteTo(objectsFileCompressed);
119 objectsFileCompressed.Flush();
120 objectsFileCompressed.Close();
121
122 #endregion
123 }
124 }
125}
diff --git a/OpenSim/Region/CoreModules/World/Serialiser/SerialiseTerrain.cs b/OpenSim/Region/CoreModules/World/Serialiser/SerialiseTerrain.cs
new file mode 100644
index 0000000..924218a
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Serialiser/SerialiseTerrain.cs
@@ -0,0 +1,53 @@
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 OpenSim.Region.CoreModules.World.Terrain;
29using OpenSim.Region.CoreModules.World.Terrain.FileLoaders;
30using OpenSim.Region.Framework.Scenes;
31
32namespace OpenSim.Region.CoreModules.World.Serialiser
33{
34 internal class SerialiseTerrain : IFileSerialiser
35 {
36 #region IFileSerialiser Members
37
38 public string WriteToFile(Scene scene, string dir)
39 {
40 ITerrainLoader fileSystemExporter = new RAW32();
41 string targetFileName = dir + "heightmap.r32";
42
43 lock (scene.Heightmap)
44 {
45 fileSystemExporter.SaveFile(targetFileName, scene.Heightmap);
46 }
47
48 return "heightmap.r32";
49 }
50
51 #endregion
52 }
53} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Serialiser/SerialiserModule.cs b/OpenSim/Region/CoreModules/World/Serialiser/SerialiserModule.cs
new file mode 100644
index 0000000..7080d5f
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Serialiser/SerialiserModule.cs
@@ -0,0 +1,226 @@
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;
29using System.Collections.Generic;
30using System.IO;
31using OpenMetaverse;
32using Nini.Config;
33using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes;
35using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
36
37namespace OpenSim.Region.CoreModules.World.Serialiser
38{
39 public class SerialiserModule : IRegionModule, IRegionSerialiserModule
40 {
41 private Commander m_commander = new Commander("export");
42 private List<Scene> m_regions = new List<Scene>();
43 private string m_savedir = "exports" + "/";
44 private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>();
45
46 #region IRegionModule Members
47
48 public void Initialise(Scene scene, IConfigSource source)
49 {
50 scene.RegisterModuleCommander(m_commander);
51 scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
52 scene.RegisterModuleInterface<IRegionSerialiserModule>(this);
53
54 lock (m_regions)
55 {
56 m_regions.Add(scene);
57 }
58 }
59
60 public void PostInitialise()
61 {
62 lock (m_serialisers)
63 {
64 m_serialisers.Add(new SerialiseTerrain());
65 m_serialisers.Add(new SerialiseObjects());
66 }
67
68 LoadCommanderCommands();
69 }
70
71 public void Close()
72 {
73 m_regions.Clear();
74 }
75
76 public string Name
77 {
78 get { return "ExportSerialisationModule"; }
79 }
80
81 public bool IsSharedModule
82 {
83 get { return true; }
84 }
85
86 #endregion
87
88 #region IRegionSerialiser Members
89
90 public void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset)
91 {
92 SceneXmlLoader.LoadPrimsFromXml(scene, fileName, newIDS, loadOffset);
93 }
94
95 public void SavePrimsToXml(Scene scene, string fileName)
96 {
97 SceneXmlLoader.SavePrimsToXml(scene, fileName);
98 }
99
100 public void LoadPrimsFromXml2(Scene scene, string fileName)
101 {
102 SceneXmlLoader.LoadPrimsFromXml2(scene, fileName);
103 }
104
105 public void LoadPrimsFromXml2(Scene scene, TextReader reader, bool startScripts)
106 {
107 SceneXmlLoader.LoadPrimsFromXml2(scene, reader, startScripts);
108 }
109
110 public void SavePrimsToXml2(Scene scene, string fileName)
111 {
112 SceneXmlLoader.SavePrimsToXml2(scene, fileName);
113 }
114
115 public void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max)
116 {
117 SceneXmlLoader.SavePrimsToXml2(scene, stream, min, max);
118 }
119
120 public void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName)
121 {
122 SceneXmlLoader.SaveNamedPrimsToXml2(scene, primName, fileName);
123 }
124
125 public SceneObjectGroup DeserializeGroupFromXml2(string xmlString)
126 {
127 return SceneXmlLoader.DeserializeGroupFromXml2(xmlString);
128 }
129
130 public string SaveGroupToXml2(SceneObjectGroup grp)
131 {
132 return SceneXmlLoader.SaveGroupToXml2(grp);
133 }
134
135 public void SavePrimListToXml2(List<EntityBase> entityList, string fileName)
136 {
137 SceneXmlLoader.SavePrimListToXml2(entityList, fileName);
138 }
139
140 public void SavePrimListToXml2(List<EntityBase> entityList, TextWriter stream, Vector3 min, Vector3 max)
141 {
142 SceneXmlLoader.SavePrimListToXml2(entityList, stream, min, max);
143 }
144
145 public List<string> SerialiseRegion(Scene scene, string saveDir)
146 {
147 List<string> results = new List<string>();
148
149 if (!Directory.Exists(saveDir))
150 {
151 Directory.CreateDirectory(saveDir);
152 }
153
154 lock (m_serialisers)
155 {
156 foreach (IFileSerialiser serialiser in m_serialisers)
157 {
158 results.Add(serialiser.WriteToFile(scene, saveDir));
159 }
160 }
161
162 TextWriter regionInfoWriter = new StreamWriter(saveDir + "README.TXT");
163 regionInfoWriter.WriteLine("Region Name: " + scene.RegionInfo.RegionName);
164 regionInfoWriter.WriteLine("Region ID: " + scene.RegionInfo.RegionID.ToString());
165 regionInfoWriter.WriteLine("Backup Time: UTC " + DateTime.UtcNow.ToString());
166 regionInfoWriter.WriteLine("Serialise Version: 0.1");
167 regionInfoWriter.Close();
168
169 TextWriter manifestWriter = new StreamWriter(saveDir + "region.manifest");
170 foreach (string line in results)
171 {
172 manifestWriter.WriteLine(line);
173 }
174 manifestWriter.Close();
175
176 return results;
177 }
178
179 #endregion
180
181 private void EventManager_OnPluginConsole(string[] args)
182 {
183 if (args[0] == "export")
184 {
185 string[] tmpArgs = new string[args.Length - 2];
186 int i = 0;
187 for (i = 2; i < args.Length; i++)
188 tmpArgs[i - 2] = args[i];
189
190 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
191 }
192 }
193
194 private void InterfaceSaveRegion(Object[] args)
195 {
196 foreach (Scene region in m_regions)
197 {
198 if (region.RegionInfo.RegionName == (string) args[0])
199 {
200 // List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/");
201 SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/");
202 }
203 }
204 }
205
206 private void InterfaceSaveAllRegions(Object[] args)
207 {
208 foreach (Scene region in m_regions)
209 {
210 // List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/");
211 SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/");
212 }
213 }
214
215 private void LoadCommanderCommands()
216 {
217 Command serialiseSceneCommand = new Command("save", CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceSaveRegion, "Saves the named region into the exports directory.");
218 serialiseSceneCommand.AddArgument("region-name", "The name of the region you wish to export", "String");
219
220 Command serialiseAllScenesCommand = new Command("save-all",CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceSaveAllRegions, "Saves all regions into the exports directory.");
221
222 m_commander.RegisterCommand("save", serialiseSceneCommand);
223 m_commander.RegisterCommand("save-all", serialiseAllScenesCommand);
224 }
225 }
226}