opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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  
28 using System;
29 using System.Collections.Generic;
30 using System.IO;
31 using System.Reflection;
32 using log4net;
33 using NDesk.Options;
34 using Nini.Config;
35 using Mono.Addins;
36  
37 using OpenSim.Framework;
38 using OpenSim.Framework.Console;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41  
42 using OpenMetaverse;
43  
44 namespace OpenSim.Region.CoreModules.World.Archiver
45 {
46 /// <summary>
47 /// This module loads and saves OpenSimulator region archives
48 /// </summary>
49 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ArchiverModule")]
50 public class ArchiverModule : INonSharedRegionModule, IRegionArchiverModule
51 {
52 private static readonly ILog m_log =
53 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54  
55 public Scene Scene { get; private set; }
56 public IRegionCombinerModule RegionCombinerModule { get; private set; }
57  
58 /// <value>
59 /// The file used to load and save an opensimulator archive if no filename has been specified
60 /// </value>
61 protected const string DEFAULT_OAR_BACKUP_FILENAME = "region.oar";
62  
63 public string Name
64 {
65 get { return "RegionArchiverModule"; }
66 }
67  
68 public Type ReplaceableInterface
69 {
70 get { return null; }
71 }
72  
73  
74 public void Initialise(IConfigSource source)
75 {
76 //m_log.Debug("[ARCHIVER] Initialising");
77 }
78  
79 public void AddRegion(Scene scene)
80 {
81 Scene = scene;
82 Scene.RegisterModuleInterface<IRegionArchiverModule>(this);
83 //m_log.DebugFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName);
84 }
85  
86 public void RegionLoaded(Scene scene)
87 {
88 RegionCombinerModule = scene.RequestModuleInterface<IRegionCombinerModule>();
89 }
90  
91 public void RemoveRegion(Scene scene)
92 {
93 }
94  
95 public void Close()
96 {
97 }
98  
99 /// <summary>
100 /// Load a whole region from an opensimulator archive.
101 /// </summary>
102 /// <param name="cmdparams"></param>
103 public void HandleLoadOarConsoleCommand(string module, string[] cmdparams)
104 {
105 bool mergeOar = false;
106 bool skipAssets = false;
107 bool forceTerrain = false;
108 bool forceParcels = false;
109 bool noObjects = false;
110 Vector3 displacement = new Vector3(0f, 0f, 0f);
111 float rotation = 0f;
112 Vector3 rotationCenter = new Vector3(Constants.RegionSize / 2f, Constants.RegionSize / 2f, 0);
113  
114 OptionSet options = new OptionSet();
115 options.Add("m|merge", delegate (string v) { mergeOar = (v != null); });
116 options.Add("s|skip-assets", delegate (string v) { skipAssets = (v != null); });
117 options.Add("force-terrain", delegate (string v) { forceTerrain = (v != null); });
118 options.Add("forceterrain", delegate (string v) { forceTerrain = (v != null); }); // downward compatibility
119 options.Add("force-parcels", delegate (string v) { forceParcels = (v != null); });
120 options.Add("forceparcels", delegate (string v) { forceParcels = (v != null); }); // downward compatibility
121 options.Add("no-objects", delegate (string v) { noObjects = (v != null); });
122 options.Add("displacement=", delegate (string v) {
123 try
124 {
125 displacement = v == null ? Vector3.Zero : Vector3.Parse(v);
126 }
127 catch
128 {
129 m_log.ErrorFormat("[ARCHIVER MODULE] failure parsing displacement");
130 m_log.ErrorFormat("[ARCHIVER MODULE] Must be represented as vector3: --displacement \"<128,128,0>\"");
131 return;
132 }
133 });
134 options.Add("rotation=", delegate (string v) {
135 try
136 {
137 rotation = v == null ? 0f : float.Parse(v);
138 }
139 catch
140 {
141 m_log.ErrorFormat("[ARCHIVER MODULE] failure parsing rotation");
142 m_log.ErrorFormat("[ARCHIVER MODULE] Must be an angle in degrees between -360 and +360: --rotation 45");
143 return;
144 }
145 // Convert to radians for internals
146 rotation = Util.Clamp<float>(rotation, -359f, 359f) / 180f * (float)Math.PI;
147 });
148 options.Add("rotation-center=", delegate (string v) {
149 try
150 {
151 rotationCenter = v == null ? Vector3.Zero : Vector3.Parse(v);
152 }
153 catch
154 {
155 m_log.ErrorFormat("[ARCHIVER MODULE] failure parsing rotation displacement");
156 m_log.ErrorFormat("[ARCHIVER MODULE] Must be represented as vector3: --rotation-center \"<128,128,0>\"");
157 return;
158 }
159 });
160  
161 // Send a message to the region ready module
162 /* bluewall* Disable this for the time being
163 IRegionReadyModule rready = m_scene.RequestModuleInterface<IRegionReadyModule>();
164  
165 if (rready != null)
166 {
167 rready.OarLoadingAlert("load");
168 }
169 */
170  
171 List<string> mainParams = options.Parse(cmdparams);
172  
173 // m_log.DebugFormat("MERGE OAR IS [{0}]", mergeOar);
174 //
175 // foreach (string param in mainParams)
176 // m_log.DebugFormat("GOT PARAM [{0}]", param);
177  
178 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
179 if (mergeOar) archiveOptions.Add("merge", null);
180 if (skipAssets) archiveOptions.Add("skipAssets", null);
181 if (forceTerrain) archiveOptions.Add("force-terrain", null);
182 if (forceParcels) archiveOptions.Add("force-parcels", null);
183 if (noObjects) archiveOptions.Add("no-objects", null);
184 archiveOptions.Add("displacement", displacement);
185 archiveOptions.Add("rotation", rotation);
186 archiveOptions.Add("rotation-center", rotationCenter);
187  
188 if (mainParams.Count > 2)
189 {
190 DearchiveRegion(mainParams[2], Guid.Empty, archiveOptions);
191 }
192 else
193 {
194 DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, Guid.Empty, archiveOptions);
195 }
196 }
197  
198 /// <summary>
199 /// Save a region to a file, including all the assets needed to restore it.
200 /// </summary>
201 /// <param name="cmdparams"></param>
202 public void HandleSaveOarConsoleCommand(string module, string[] cmdparams)
203 {
204 Dictionary<string, object> options = new Dictionary<string, object>();
205  
206 OptionSet ops = new OptionSet();
207  
208 // legacy argument [obsolete]
209 ops.Add("p|profile=", delegate(string v) { Console.WriteLine("\n WARNING: -profile option is obsolete and it will not work. Use -home instead.\n"); });
210 // preferred
211 ops.Add("h|home=", delegate(string v) { options["home"] = v; });
212  
213 ops.Add("noassets", delegate(string v) { options["noassets"] = v != null; });
214 ops.Add("publish", v => options["wipe-owners"] = v != null);
215 ops.Add("perm=", delegate(string v) { options["checkPermissions"] = v; });
216 ops.Add("all", delegate(string v) { options["all"] = v != null; });
217  
218 List<string> mainParams = ops.Parse(cmdparams);
219  
220 string path;
221 if (mainParams.Count > 2)
222 path = mainParams[2];
223 else
224 path = DEFAULT_OAR_BACKUP_FILENAME;
225  
226 // Not doing this right now as this causes some problems with auto-backup systems. Maybe a force flag is
227 // needed
228 // if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, path))
229 // return;
230  
231 ArchiveRegion(path, options);
232 }
233  
234 public void ArchiveRegion(string savePath, Dictionary<string, object> options)
235 {
236 ArchiveRegion(savePath, Guid.Empty, options);
237 }
238  
239 public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options)
240 {
241 m_log.InfoFormat(
242 "[ARCHIVER]: Writing archive for region {0} to {1}", Scene.RegionInfo.RegionName, savePath);
243  
244 new ArchiveWriteRequest(Scene, savePath, requestId).ArchiveRegion(options);
245 }
246  
247 public void ArchiveRegion(Stream saveStream)
248 {
249 ArchiveRegion(saveStream, Guid.Empty);
250 }
251  
252 public void ArchiveRegion(Stream saveStream, Guid requestId)
253 {
254 ArchiveRegion(saveStream, requestId, new Dictionary<string, object>());
255 }
256  
257 public void ArchiveRegion(Stream saveStream, Guid requestId, Dictionary<string, object> options)
258 {
259 new ArchiveWriteRequest(Scene, saveStream, requestId).ArchiveRegion(options);
260 }
261  
262 public void DearchiveRegion(string loadPath)
263 {
264 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
265 DearchiveRegion(loadPath, Guid.Empty, archiveOptions);
266 }
267  
268 public void DearchiveRegion(string loadPath, Guid requestId, Dictionary<string,object> options)
269 {
270 m_log.InfoFormat(
271 "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
272  
273 new ArchiveReadRequest(Scene, loadPath, requestId, options).DearchiveRegion();
274 }
275  
276 public void DearchiveRegion(Stream loadStream)
277 {
278 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
279 DearchiveRegion(loadStream, Guid.Empty, archiveOptions);
280 }
281  
282 public void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string, object> options)
283 {
284 new ArchiveReadRequest(Scene, loadStream, requestId, options).DearchiveRegion();
285 }
286 }
287 }