aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
authorAdam Frisby2008-04-21 09:12:47 +0000
committerAdam Frisby2008-04-21 09:12:47 +0000
commitf741a62d540f0c04eedebd9c7eb072fc50c4a111 (patch)
treef94ce4b084c538feb450dc5827358d231da37dbe /OpenSim/Region/Environment/Modules
parentUpdate svn properties. (diff)
downloadopensim-SC-f741a62d540f0c04eedebd9c7eb072fc50c4a111.zip
opensim-SC-f741a62d540f0c04eedebd9c7eb072fc50c4a111.tar.gz
opensim-SC-f741a62d540f0c04eedebd9c7eb072fc50c4a111.tar.bz2
opensim-SC-f741a62d540f0c04eedebd9c7eb072fc50c4a111.tar.xz
* Formatted ExportSerialiserModule and SvnBackupModule
* Added a form of GZip compression support to object.xml files produced by exportserialiser. Will look towards standard GZip support. File compression seems to be highly worthwhile reducing a 1.5mb sim state to 62kb.
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs97
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs4
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/IRegionSerialiser.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs41
-rw-r--r--OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs4
-rw-r--r--OpenSim/Region/Environment/Modules/ModuleFramework/Commander.cs58
6 files changed, 112 insertions, 94 deletions
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs
index f811f22..91770af 100644
--- a/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs
@@ -37,10 +37,54 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
37{ 37{
38 public class ExportSerialisationModule : IRegionModule, IRegionSerialiser 38 public class ExportSerialisationModule : IRegionModule, IRegionSerialiser
39 { 39 {
40 private List<Scene> m_regions = new List<Scene>();
41 private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>();
42 private Commander m_commander = new Commander("Export"); 40 private Commander m_commander = new Commander("Export");
41 private List<Scene> m_regions = new List<Scene>();
43 private string m_savedir = "exports" + "/"; 42 private string m_savedir = "exports" + "/";
43 private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>();
44
45 #region IRegionModule Members
46
47 public void Initialise(Scene scene, IConfigSource source)
48 {
49 scene.RegisterModuleCommander("Export", m_commander);
50 scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
51 scene.RegisterModuleInterface<IRegionSerialiser>(this);
52
53 lock (m_regions)
54 {
55 m_regions.Add(scene);
56 }
57 }
58
59 public void PostInitialise()
60 {
61 lock (m_serialisers)
62 {
63 m_serialisers.Add(new SerialiseTerrain());
64 m_serialisers.Add(new SerialiseObjects());
65 }
66
67 LoadCommanderCommands();
68 }
69
70 public void Close()
71 {
72 m_regions.Clear();
73 }
74
75 public string Name
76 {
77 get { return "ExportSerialisationModule"; }
78 }
79
80 public bool IsSharedModule
81 {
82 get { return true; }
83 }
84
85 #endregion
86
87 #region IRegionSerialiser Members
44 88
45 public List<string> SerialiseRegion(Scene scene, string saveDir) 89 public List<string> SerialiseRegion(Scene scene, string saveDir)
46 { 90 {
@@ -76,22 +120,9 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
76 return results; 120 return results;
77 } 121 }
78 122
123 #endregion
79 124
80 #region IRegionModule Members 125 private void EventManager_OnPluginConsole(string[] args)
81
82 public void Initialise(Scene scene, IConfigSource source)
83 {
84 scene.RegisterModuleCommander("Export", m_commander);
85 scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
86 scene.RegisterModuleInterface<IRegionSerialiser>(this);
87
88 lock (m_regions)
89 {
90 m_regions.Add(scene);
91 }
92 }
93
94 void EventManager_OnPluginConsole(string[] args)
95 { 126 {
96 if (args[0] == "export") 127 if (args[0] == "export")
97 { 128 {
@@ -108,7 +139,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
108 { 139 {
109 foreach (Scene region in m_regions) 140 foreach (Scene region in m_regions)
110 { 141 {
111 if (region.RegionInfo.RegionName == (string)args[0]) 142 if (region.RegionInfo.RegionName == (string) args[0])
112 { 143 {
113 List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/"); 144 List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/");
114 } 145 }
@@ -133,33 +164,5 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
133 m_commander.RegisterCommand("save", serialiseSceneCommand); 164 m_commander.RegisterCommand("save", serialiseSceneCommand);
134 m_commander.RegisterCommand("save-all", serialiseAllScenesCommand); 165 m_commander.RegisterCommand("save-all", serialiseAllScenesCommand);
135 } 166 }
136
137 public void PostInitialise()
138 {
139 lock (m_serialisers)
140 {
141 m_serialisers.Add(new SerialiseTerrain());
142 m_serialisers.Add(new SerialiseObjects());
143 }
144
145 LoadCommanderCommands();
146 }
147
148 public void Close()
149 {
150 m_regions.Clear();
151 }
152
153 public string Name
154 {
155 get { return "ExportSerialisationModule"; }
156 }
157
158 public bool IsSharedModule
159 {
160 get { return true; }
161 }
162
163 #endregion
164 } 167 }
165} 168} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs
index 8cd97a8..77a418f 100644
--- a/OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/IFileSerialiser.cs
@@ -29,8 +29,8 @@ using OpenSim.Region.Environment.Scenes;
29 29
30namespace OpenSim.Region.Environment.Modules.ExportSerialiser 30namespace OpenSim.Region.Environment.Modules.ExportSerialiser
31{ 31{
32 interface IFileSerialiser 32 internal interface IFileSerialiser
33 { 33 {
34 string WriteToFile(Scene scene, string dir); 34 string WriteToFile(Scene scene, string dir);
35 } 35 }
36} 36} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/IRegionSerialiser.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/IRegionSerialiser.cs
index 5b10957..e1721ff 100644
--- a/OpenSim/Region/Environment/Modules/ExportSerialiser/IRegionSerialiser.cs
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/IRegionSerialiser.cs
@@ -34,4 +34,4 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
34 { 34 {
35 List<string> SerialiseRegion(Scene scene, string saveDir); 35 List<string> SerialiseRegion(Scene scene, string saveDir);
36 } 36 }
37} 37} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs
index ac80f40..7e5cf47 100644
--- a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseObjects.cs
@@ -27,20 +27,30 @@
27 27
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.IO; 29using System.IO;
30using System.IO.Compression;
30using System.Text; 31using System.Text;
31using System.Xml; 32using System.Xml;
32using OpenSim.Region.Environment.Scenes; 33using OpenSim.Region.Environment.Scenes;
33 34
34namespace OpenSim.Region.Environment.Modules.ExportSerialiser 35namespace OpenSim.Region.Environment.Modules.ExportSerialiser
35{ 36{
36 class SerialiseObjects : IFileSerialiser 37 internal class SerialiseObjects : IFileSerialiser
37 { 38 {
38 #region IFileSerialiser Members 39 #region IFileSerialiser Members
39 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
40 51
41 public void SaveSerialisedToFile(string fileName, Scene scene) 52 public void SaveSerialisedToFile(string fileName, Scene scene)
42 { 53 {
43 int primCount = 0;
44 string xmlstream = "<scene>"; 54 string xmlstream = "<scene>";
45 55
46 List<EntityBase> EntityList = scene.GetEntities(); 56 List<EntityBase> EntityList = scene.GetEntities();
@@ -50,8 +60,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
50 { 60 {
51 if (ent is SceneObjectGroup) 61 if (ent is SceneObjectGroup)
52 { 62 {
53 EntityXml.Add(((SceneObjectGroup)ent).ToXmlString2()); 63 EntityXml.Add(((SceneObjectGroup) ent).ToXmlString2());
54 primCount++;
55 } 64 }
56 } 65 }
57 EntityXml.Sort(); 66 EntityXml.Sort();
@@ -69,26 +78,24 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
69 formatter.Formatting = Formatting.Indented; 78 formatter.Formatting = Formatting.Indented;
70 doc.WriteContentTo(formatter); 79 doc.WriteContentTo(formatter);
71 formatter.Flush(); 80 formatter.Flush();
72 StreamReader reader = new StreamReader(stream);
73 81
74 stream.Seek(0, SeekOrigin.Begin); 82 stream.Seek(0, SeekOrigin.Begin);
75 83
76 FileStream objectsFile = new FileStream(fileName, FileMode.Create); 84 FileStream objectsFile = new FileStream(fileName, FileMode.Create);
85
77 stream.WriteTo(objectsFile); 86 stream.WriteTo(objectsFile);
78 objectsFile.Flush(); 87 objectsFile.Flush();
79 objectsFile.Close(); 88 objectsFile.Close();
80 89
90 #region GZip Compressed Version
91 FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create);
92 MemoryStream gzipMSStream = new MemoryStream();
93 GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress);
94 stream.WriteTo(gzipStream);
95 gzipMSStream.WriteTo(objectsFileCompressed);
96 objectsFileCompressed.Flush();
97 objectsFileCompressed.Close();
98 #endregion
81 } 99 }
82
83 public string WriteToFile(Scene scene, string dir)
84 {
85 string targetFileName = dir + "objects.xml";
86
87 SaveSerialisedToFile(targetFileName, scene);
88
89 return "objects.xml";
90 }
91
92 #endregion
93 } 100 }
94} 101} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs
index 8555089..c4790c2 100644
--- a/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs
+++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/SerialiseTerrain.cs
@@ -31,7 +31,7 @@ using OpenSim.Region.Environment.Scenes;
31 31
32namespace OpenSim.Region.Environment.Modules.ExportSerialiser 32namespace OpenSim.Region.Environment.Modules.ExportSerialiser
33{ 33{
34 class SerialiseTerrain : IFileSerialiser 34 internal class SerialiseTerrain : IFileSerialiser
35 { 35 {
36 #region IFileSerialiser Members 36 #region IFileSerialiser Members
37 37
@@ -50,4 +50,4 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
50 50
51 #endregion 51 #endregion
52 } 52 }
53} 53} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/ModuleFramework/Commander.cs b/OpenSim/Region/Environment/Modules/ModuleFramework/Commander.cs
index 27d73b5..7ef087d 100644
--- a/OpenSim/Region/Environment/Modules/ModuleFramework/Commander.cs
+++ b/OpenSim/Region/Environment/Modules/ModuleFramework/Commander.cs
@@ -42,11 +42,11 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
42 public class Command : ICommand 42 public class Command : ICommand
43 { 43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 private List<CommandArgument> m_args = new List<CommandArgument>();
45 46
46 private Action<object[]> m_command; 47 private Action<object[]> m_command;
47 private string m_name;
48 private string m_help; 48 private string m_help;
49 private List<CommandArgument> m_args = new List<CommandArgument>(); 49 private string m_name;
50 50
51 public Command(string name, Action<Object[]> command, string help) 51 public Command(string name, Action<Object[]> command, string help)
52 { 52 {
@@ -55,6 +55,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
55 m_help = help; 55 m_help = help;
56 } 56 }
57 57
58 #region ICommand Members
59
58 public void AddArgument(string name, string helptext, string type) 60 public void AddArgument(string name, string helptext, string type)
59 { 61 {
60 m_args.Add(new CommandArgument(name, helptext, type)); 62 m_args.Add(new CommandArgument(name, helptext, type));
@@ -143,8 +145,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
143 catch (FormatException) 145 catch (FormatException)
144 { 146 {
145 m_log.Error("Argument number " + (i + 1) + 147 m_log.Error("Argument number " + (i + 1) +
146 " (" + m_args[i].Name + ") must be a valid " + 148 " (" + m_args[i].Name + ") must be a valid " +
147 m_args[i].ArgumentType.ToLower() + "."); 149 m_args[i].ArgumentType.ToLower() + ".");
148 } 150 }
149 cleanArgs[i] = m_args[i].ArgumentValue; 151 cleanArgs[i] = m_args[i].ArgumentValue;
150 152
@@ -153,6 +155,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
153 155
154 m_command.Invoke(cleanArgs); 156 m_command.Invoke(cleanArgs);
155 } 157 }
158
159 #endregion
156 } 160 }
157 161
158 /// <summary> 162 /// <summary>
@@ -160,8 +164,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
160 /// </summary> 164 /// </summary>
161 public class CommandArgument 165 public class CommandArgument
162 { 166 {
163 private string m_name;
164 private string m_help; 167 private string m_help;
168 private string m_name;
165 private string m_type; 169 private string m_type;
166 private Object m_val; 170 private Object m_val;
167 171
@@ -208,29 +212,13 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
208 m_name = name; 212 m_name = name;
209 } 213 }
210 214
215 #region ICommander Members
216
211 public void RegisterCommand(string commandName, ICommand command) 217 public void RegisterCommand(string commandName, ICommand command)
212 { 218 {
213 m_commands[commandName] = command; 219 m_commands[commandName] = command;
214 } 220 }
215 221
216 void ShowConsoleHelp()
217 {
218 m_log.Info("===" + m_name + "===");
219 foreach (ICommand com in m_commands.Values)
220 {
221 m_log.Info("* " + com.Name + " - " + com.Help);
222 }
223 }
224
225 string EscapeRuntimeAPICommand(string command)
226 {
227 command = command.Replace('-', '_');
228 StringBuilder tmp = new StringBuilder(command);
229 tmp[0] = tmp[0].ToString().ToUpper().ToCharArray()[0];
230
231 return tmp.ToString();
232 }
233
234 /// <summary> 222 /// <summary>
235 /// Generates a runtime C# class which can be compiled and inserted via reflection to enable modules to register new script commands 223 /// Generates a runtime C# class which can be compiled and inserted via reflection to enable modules to register new script commands
236 /// </summary> 224 /// </summary>
@@ -253,7 +241,7 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
253 { 241 {
254 classSrc += "\t\targs[" + i.ToString() + "] = " + Util.Md5Hash(arg.Key) + " " + ";\n"; 242 classSrc += "\t\targs[" + i.ToString() + "] = " + Util.Md5Hash(arg.Key) + " " + ";\n";
255 i++; 243 i++;
256 } 244 }
257 classSrc += "\t\tGetCommander(\"" + m_name + "\").Run(\"" + com.Name + "\", args);\n"; 245 classSrc += "\t\tGetCommander(\"" + m_name + "\").Run(\"" + com.Name + "\", args);\n";
258 classSrc += "\t}\n"; 246 classSrc += "\t}\n";
259 } 247 }
@@ -296,5 +284,25 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
296 ShowConsoleHelp(); 284 ShowConsoleHelp();
297 } 285 }
298 } 286 }
287
288 #endregion
289
290 private void ShowConsoleHelp()
291 {
292 m_log.Info("===" + m_name + "===");
293 foreach (ICommand com in m_commands.Values)
294 {
295 m_log.Info("* " + com.Name + " - " + com.Help);
296 }
297 }
298
299 private string EscapeRuntimeAPICommand(string command)
300 {
301 command = command.Replace('-', '_');
302 StringBuilder tmp = new StringBuilder(command);
303 tmp[0] = tmp[0].ToString().ToUpper().ToCharArray()[0];
304
305 return tmp.ToString();
306 }
299 } 307 }
300} 308} \ No newline at end of file