aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAdam Frisby2008-04-15 04:26:39 +0000
committerAdam Frisby2008-04-15 04:26:39 +0000
commit00dbca468a924a6e567300cbdaa6d6889586ab2f (patch)
tree7c2bca186ab3770dd4064717637680690557cd84
parent* Quick patch before I start on a bigger project (diff)
downloadopensim-SC-00dbca468a924a6e567300cbdaa6d6889586ab2f.zip
opensim-SC-00dbca468a924a6e567300cbdaa6d6889586ab2f.tar.gz
opensim-SC-00dbca468a924a6e567300cbdaa6d6889586ab2f.tar.bz2
opensim-SC-00dbca468a924a6e567300cbdaa6d6889586ab2f.tar.xz
* Committing shell of a whole-region serialiser. This is not complete and will be worked on more over the next few days. Undocumented/trusted. Use at own risk, etc etc.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs142
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs13
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs33
3 files changed, 188 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs
new file mode 100644
index 0000000..76f7249
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs
@@ -0,0 +1,142 @@
1
2using System;
3using System.Collections.Generic;
4using System.Drawing;
5using libsecondlife;
6using Nini.Config;
7using OpenSim.Framework;
8using OpenSim.Region.Environment.Interfaces;
9using OpenSim.Region.Environment.Scenes;
10using OpenSim.Region.Environment.Modules.ModuleFramework;
11using System.IO;
12
13namespace OpenSim.Region.Environment.Modules.ExportSerialiser
14{
15 public class ExportSerialisationModule : IRegionModule
16 {
17 private List<Scene> m_regions = new List<Scene>();
18 private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>();
19 private Commander m_commander = new Commander("Export");
20 private string m_savedir = "exports" + "/";
21
22 private List<string> SerialiseRegion(Scene scene)
23 {
24 List<string> results = new List<string>();
25
26 string saveDir = m_savedir + scene.RegionInfo.RegionID.ToString() + "/";
27
28 if (!Directory.Exists(saveDir))
29 {
30 Directory.CreateDirectory(saveDir);
31 }
32
33 lock (m_serialisers)
34 {
35 foreach (IFileSerialiser serialiser in m_serialisers)
36 {
37 results.Add(serialiser.WriteToFile(scene, saveDir));
38 }
39 }
40
41 TextWriter regionInfoWriter = new StreamWriter(saveDir + "README.TXT");
42 regionInfoWriter.WriteLine("Region Name: " + scene.RegionInfo.RegionName);
43 regionInfoWriter.WriteLine("Region ID: " + scene.RegionInfo.RegionID.ToString());
44 regionInfoWriter.WriteLine("Backup Time: " + Util.UnixTimeSinceEpoch().ToString());
45 regionInfoWriter.WriteLine("Serialise Version: 0.1");
46 regionInfoWriter.Close();
47
48 TextWriter manifestWriter = new StreamWriter(saveDir + "region.manifest");
49 foreach (string line in results)
50 {
51 manifestWriter.WriteLine(line);
52 }
53 manifestWriter.Close();
54
55 return results;
56 }
57
58
59 #region IRegionModule Members
60
61 public void Initialise(Scene scene, IConfigSource source)
62 {
63 scene.RegisterModuleCommander("Export", m_commander);
64 scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
65
66 lock (m_regions)
67 {
68 m_regions.Add(scene);
69 }
70 }
71
72 void EventManager_OnPluginConsole(string[] args)
73 {
74 if (args[0] == "export")
75 {
76 string[] tmpArgs = new string[args.Length - 2];
77 int i = 0;
78 for (i = 2; i < args.Length; i++)
79 tmpArgs[i - 2] = args[i];
80
81 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
82 }
83 }
84
85 private void InterfaceSaveRegion(Object[] args)
86 {
87 foreach (Scene region in m_regions)
88 {
89 if (region.RegionInfo.RegionName == (string)args[0])
90 {
91 List<string> results = SerialiseRegion(region);
92 }
93 }
94 }
95
96 private void InterfaceSaveAllRegions(Object[] args)
97 {
98 foreach (Scene region in m_regions)
99 {
100 List<string> results = SerialiseRegion(region);
101 }
102 }
103
104 private void LoadCommanderCommands()
105 {
106 Command serialiseSceneCommand = new Command("save", InterfaceSaveRegion, "Saves the named region into the exports directory.");
107 serialiseSceneCommand.AddArgument("region-name", "The name of the region you wish to export", "String");
108
109 Command serialiseAllScenesCommand = new Command("save-all", InterfaceSaveAllRegions, "Saves all regions into the exports directory.");
110
111 m_commander.RegisterCommand("save", serialiseSceneCommand);
112 m_commander.RegisterCommand("save-all", serialiseAllScenesCommand);
113 }
114
115 public void PostInitialise()
116 {
117 lock (m_serialisers)
118 {
119 m_serialisers.Add(new SerialiseTerrain());
120 }
121
122 LoadCommanderCommands();
123 }
124
125 public void Close()
126 {
127 m_regions.Clear();
128 }
129
130 public string Name
131 {
132 get { return "ExportSerialisationModule"; }
133 }
134
135 public bool IsSharedModule
136 {
137 get { return true; }
138 }
139
140 #endregion
141 }
142}
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs
new file mode 100644
index 0000000..4d5e42b
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs
@@ -0,0 +1,13 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using OpenSim.Region.Environment.Scenes;
6
7namespace OpenSim.Region.Environment.Modules.ExportSerialiser
8{
9 interface IFileSerialiser
10 {
11 string WriteToFile(Scene scene, string dir);
12 }
13}
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs
new file mode 100644
index 0000000..2076490
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs
@@ -0,0 +1,33 @@
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using libsecondlife;
5using Nini.Config;
6using OpenSim.Framework;
7using OpenSim.Region.Environment.Interfaces;
8using OpenSim.Region.Environment.Scenes;
9using OpenSim.Region.Environment.Modules.ModuleFramework;
10using OpenSim.Region.Environment.Modules.Terrain;
11
12namespace OpenSim.Region.Environment.Modules.ExportSerialiser
13{
14 class SerialiseTerrain : IFileSerialiser
15 {
16 #region IFileSerialiser Members
17
18 public string WriteToFile(Scene scene, string dir)
19 {
20 ITerrainLoader fileSystemExporter = new Terrain.FileLoaders.RAW32();
21 string targetFileName = dir + "heightmap.r32";
22
23 lock (scene.Heightmap)
24 {
25 fileSystemExporter.SaveFile(targetFileName, scene.Heightmap);
26 }
27
28 return "heightmap.r32";
29 }
30
31 #endregion
32 }
33}