clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 String defaultUser = "";
112 float rotation = 0f;
113 Vector3 rotationCenter = new Vector3(Constants.RegionSize / 2f, Constants.RegionSize / 2f, 0);
114  
115 OptionSet options = new OptionSet();
116 options.Add("m|merge", delegate (string v) { mergeOar = (v != null); });
117 options.Add("s|skip-assets", delegate (string v) { skipAssets = (v != null); });
118 options.Add("force-terrain", delegate (string v) { forceTerrain = (v != null); });
119 options.Add("forceterrain", delegate (string v) { forceTerrain = (v != null); }); // downward compatibility
120 options.Add("force-parcels", delegate (string v) { forceParcels = (v != null); });
121 options.Add("forceparcels", delegate (string v) { forceParcels = (v != null); }); // downward compatibility
122 options.Add("no-objects", delegate (string v) { noObjects = (v != null); });
123 options.Add("default-user=", delegate(string v) { defaultUser = (v == null) ? "" : v; });
124 options.Add("displacement=", delegate (string v) {
125 try
126 {
127 displacement = v == null ? Vector3.Zero : Vector3.Parse(v);
128 }
129 catch
130 {
131 m_log.ErrorFormat("[ARCHIVER MODULE] failure parsing displacement");
132 m_log.ErrorFormat("[ARCHIVER MODULE] Must be represented as vector3: --displacement \"<128,128,0>\"");
133 return;
134 }
135 });
136 options.Add("rotation=", delegate(string v)
137 {
138 try
139 {
140 rotation = v == null ? 0f : float.Parse(v);
141 }
142 catch
143 {
144 m_log.ErrorFormat("[ARCHIVER MODULE] failure parsing rotation");
145 m_log.ErrorFormat("[ARCHIVER MODULE] Must be an angle in degrees between -360 and +360: --rotation 45");
146 return;
147 }
148 // Convert to radians for internals
149 rotation = Util.Clamp<float>(rotation, -359f, 359f) / 180f * (float)Math.PI;
150 });
151 options.Add("rotation-center=", delegate (string v) {
152 try
153 {
154 rotationCenter = v == null ? Vector3.Zero : Vector3.Parse(v);
155 }
156 catch
157 {
158 m_log.ErrorFormat("[ARCHIVER MODULE] failure parsing rotation displacement");
159 m_log.ErrorFormat("[ARCHIVER MODULE] Must be represented as vector3: --rotation-center \"<128,128,0>\"");
160 return;
161 }
162 });
163  
164 // Send a message to the region ready module
165 /* bluewall* Disable this for the time being
166 IRegionReadyModule rready = m_scene.RequestModuleInterface<IRegionReadyModule>();
167  
168 if (rready != null)
169 {
170 rready.OarLoadingAlert("load");
171 }
172 */
173  
174 List<string> mainParams = options.Parse(cmdparams);
175  
176 // m_log.DebugFormat("MERGE OAR IS [{0}]", mergeOar);
177 //
178 // foreach (string param in mainParams)
179 // m_log.DebugFormat("GOT PARAM [{0}]", param);
180  
181 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
182 if (mergeOar) archiveOptions.Add("merge", null);
183 if (skipAssets) archiveOptions.Add("skipAssets", null);
184 if (forceTerrain) archiveOptions.Add("force-terrain", null);
185 if (forceParcels) archiveOptions.Add("force-parcels", null);
186 if (noObjects) archiveOptions.Add("no-objects", null);
187 if (defaultUser != "")
188 {
189 UUID defaultUserUUID = UUID.Zero;
190 try
191 {
192 defaultUserUUID = Scene.UserManagementModule.GetUserIdByName(defaultUser);
193 }
194 catch
195 {
196 m_log.ErrorFormat("[ARCHIVER MODULE] default user must be in format \"First Last\"", defaultUser);
197 }
198 if (defaultUserUUID == UUID.Zero)
199 {
200 m_log.ErrorFormat("[ARCHIVER MODULE] cannot find specified default user {0}", defaultUser);
201 return;
202 }
203 else
204 {
205 archiveOptions.Add("default-user", defaultUserUUID);
206 }
207 }
208 archiveOptions.Add("displacement", displacement);
209 archiveOptions.Add("rotation", rotation);
210 archiveOptions.Add("rotation-center", rotationCenter);
211  
212 if (mainParams.Count > 2)
213 {
214 DearchiveRegion(mainParams[2], Guid.Empty, archiveOptions);
215 }
216 else
217 {
218 DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, Guid.Empty, archiveOptions);
219 }
220 }
221  
222 /// <summary>
223 /// Save a region to a file, including all the assets needed to restore it.
224 /// </summary>
225 /// <param name="cmdparams"></param>
226 public void HandleSaveOarConsoleCommand(string module, string[] cmdparams)
227 {
228 Dictionary<string, object> options = new Dictionary<string, object>();
229  
230 OptionSet ops = new OptionSet();
231  
232 // legacy argument [obsolete]
233 ops.Add("p|profile=", delegate(string v) { Console.WriteLine("\n WARNING: -profile option is obsolete and it will not work. Use -home instead.\n"); });
234 // preferred
235 ops.Add("h|home=", delegate(string v) { options["home"] = v; });
236  
237 ops.Add("noassets", delegate(string v) { options["noassets"] = v != null; });
238 ops.Add("publish", v => options["wipe-owners"] = v != null);
239 ops.Add("perm=", delegate(string v) { options["checkPermissions"] = v; });
240 ops.Add("all", delegate(string v) { options["all"] = v != null; });
241  
242 List<string> mainParams = ops.Parse(cmdparams);
243  
244 string path;
245 if (mainParams.Count > 2)
246 path = mainParams[2];
247 else
248 path = DEFAULT_OAR_BACKUP_FILENAME;
249  
250 // Not doing this right now as this causes some problems with auto-backup systems. Maybe a force flag is
251 // needed
252 // if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, path))
253 // return;
254  
255 ArchiveRegion(path, options);
256 }
257  
258 public void ArchiveRegion(string savePath, Dictionary<string, object> options)
259 {
260 ArchiveRegion(savePath, Guid.Empty, options);
261 }
262  
263 public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options)
264 {
265 m_log.InfoFormat(
266 "[ARCHIVER]: Writing archive for region {0} to {1}", Scene.RegionInfo.RegionName, savePath);
267  
268 new ArchiveWriteRequest(Scene, savePath, requestId).ArchiveRegion(options);
269 }
270  
271 public void ArchiveRegion(Stream saveStream)
272 {
273 ArchiveRegion(saveStream, Guid.Empty);
274 }
275  
276 public void ArchiveRegion(Stream saveStream, Guid requestId)
277 {
278 ArchiveRegion(saveStream, requestId, new Dictionary<string, object>());
279 }
280  
281 public void ArchiveRegion(Stream saveStream, Guid requestId, Dictionary<string, object> options)
282 {
283 new ArchiveWriteRequest(Scene, saveStream, requestId).ArchiveRegion(options);
284 }
285  
286 public void DearchiveRegion(string loadPath)
287 {
288 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
289 DearchiveRegion(loadPath, Guid.Empty, archiveOptions);
290 }
291  
292 public void DearchiveRegion(string loadPath, Guid requestId, Dictionary<string,object> options)
293 {
294 m_log.InfoFormat(
295 "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
296  
297 new ArchiveReadRequest(Scene, loadPath, requestId, options).DearchiveRegion();
298 }
299  
300 public void DearchiveRegion(Stream loadStream)
301 {
302 Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
303 DearchiveRegion(loadStream, Guid.Empty, archiveOptions);
304 }
305  
306 public void DearchiveRegion(Stream loadStream, Guid requestId, Dictionary<string, object> options)
307 {
308 new ArchiveReadRequest(Scene, loadStream, requestId, options).DearchiveRegion();
309 }
310 }
311 }