clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
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 | using OpenSim.Framework; |
||
37 | using OpenSim.Framework.Console; |
||
38 | using OpenSim.Region.Framework.Interfaces; |
||
39 | using OpenSim.Region.Framework.Scenes; |
||
40 | |||
41 | namespace OpenSim.Region.CoreModules.World.Archiver |
||
42 | { |
||
43 | /// <summary> |
||
44 | /// This module loads and saves OpenSimulator region archives |
||
45 | /// </summary> |
||
46 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ArchiverModule")] |
||
47 | public class ArchiverModule : INonSharedRegionModule, IRegionArchiverModule |
||
48 | { |
||
49 | private static readonly ILog m_log = |
||
50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
51 | |||
52 | public Scene Scene { get; private set; } |
||
53 | public IRegionCombinerModule RegionCombinerModule { get; private set; } |
||
54 | |||
55 | /// <value> |
||
56 | /// The file used to load and save an opensimulator archive if no filename has been specified |
||
57 | /// </value> |
||
58 | protected const string DEFAULT_OAR_BACKUP_FILENAME = "region.oar"; |
||
59 | |||
60 | public string Name |
||
61 | { |
||
62 | get { return "RegionArchiverModule"; } |
||
63 | } |
||
64 | |||
65 | public Type ReplaceableInterface |
||
66 | { |
||
67 | get { return null; } |
||
68 | } |
||
69 | |||
70 | |||
71 | public void Initialise(IConfigSource source) |
||
72 | { |
||
73 | //m_log.Debug("[ARCHIVER] Initialising"); |
||
74 | } |
||
75 | |||
76 | public void AddRegion(Scene scene) |
||
77 | { |
||
78 | Scene = scene; |
||
79 | Scene.RegisterModuleInterface<IRegionArchiverModule>(this); |
||
80 | //m_log.DebugFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName); |
||
81 | } |
||
82 | |||
83 | public void RegionLoaded(Scene scene) |
||
84 | { |
||
85 | RegionCombinerModule = scene.RequestModuleInterface<IRegionCombinerModule>(); |
||
86 | } |
||
87 | |||
88 | public void RemoveRegion(Scene scene) |
||
89 | { |
||
90 | } |
||
91 | |||
92 | public void Close() |
||
93 | { |
||
94 | } |
||
95 | |||
96 | /// <summary> |
||
97 | /// Load a whole region from an opensimulator archive. |
||
98 | /// </summary> |
||
99 | /// <param name="cmdparams"></param> |
||
100 | public void HandleLoadOarConsoleCommand(string module, string[] cmdparams) |
||
101 | { |
||
102 | bool mergeOar = false; |
||
103 | bool skipAssets = false; |
||
104 | |||
105 | OptionSet options = new OptionSet().Add("m|merge", delegate (string v) { mergeOar = v != null; }); |
||
106 | options.Add("s|skip-assets", delegate (string v) { skipAssets = v != null; }); |
||
107 | |||
108 | // Send a message to the region ready module |
||
109 | /* bluewall* Disable this for the time being |
||
110 | IRegionReadyModule rready = m_scene.RequestModuleInterface<IRegionReadyModule>(); |
||
111 | |||
112 | if (rready != null) |
||
113 | { |
||
114 | rready.OarLoadingAlert("load"); |
||
115 | } |
||
116 | */ |
||
117 | |||
118 | List<string> mainParams = options.Parse(cmdparams); |
||
119 | |||
120 | // m_log.DebugFormat("MERGE OAR IS [{0}]", mergeOar); |
||
121 | // |
||
122 | // foreach (string param in mainParams) |
||
123 | // m_log.DebugFormat("GOT PARAM [{0}]", param); |
||
124 | |||
125 | if (mainParams.Count > 2) |
||
126 | { |
||
127 | DearchiveRegion(mainParams[2], mergeOar, skipAssets, Guid.Empty); |
||
128 | } |
||
129 | else |
||
130 | { |
||
131 | DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, skipAssets, Guid.Empty); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | /// <summary> |
||
136 | /// Save a region to a file, including all the assets needed to restore it. |
||
137 | /// </summary> |
||
138 | /// <param name="cmdparams"></param> |
||
139 | public void HandleSaveOarConsoleCommand(string module, string[] cmdparams) |
||
140 | { |
||
141 | Dictionary<string, object> options = new Dictionary<string, object>(); |
||
142 | |||
143 | OptionSet ops = new OptionSet(); |
||
144 | |||
145 | // legacy argument [obsolete] |
||
146 | ops.Add("p|profile=", delegate(string v) { Console.WriteLine("\n WARNING: -profile option is obsolete and it will not work. Use -home instead.\n"); }); |
||
147 | // preferred |
||
148 | ops.Add("h|home=", delegate(string v) { options["home"] = v; }); |
||
149 | |||
150 | ops.Add("noassets", delegate(string v) { options["noassets"] = v != null; }); |
||
151 | ops.Add("publish", v => options["wipe-owners"] = v != null); |
||
152 | ops.Add("perm=", delegate(string v) { options["checkPermissions"] = v; }); |
||
153 | ops.Add("all", delegate(string v) { options["all"] = v != null; }); |
||
154 | |||
155 | List<string> mainParams = ops.Parse(cmdparams); |
||
156 | |||
157 | string path; |
||
158 | if (mainParams.Count > 2) |
||
159 | path = mainParams[2]; |
||
160 | else |
||
161 | path = DEFAULT_OAR_BACKUP_FILENAME; |
||
162 | |||
163 | // Not doing this right now as this causes some problems with auto-backup systems. Maybe a force flag is |
||
164 | // needed |
||
165 | // if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, path)) |
||
166 | // return; |
||
167 | |||
168 | ArchiveRegion(path, options); |
||
169 | } |
||
170 | |||
171 | public void ArchiveRegion(string savePath, Dictionary<string, object> options) |
||
172 | { |
||
173 | ArchiveRegion(savePath, Guid.Empty, options); |
||
174 | } |
||
175 | |||
176 | public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options) |
||
177 | { |
||
178 | m_log.InfoFormat( |
||
179 | "[ARCHIVER]: Writing archive for region {0} to {1}", Scene.RegionInfo.RegionName, savePath); |
||
180 | |||
181 | new ArchiveWriteRequest(Scene, savePath, requestId).ArchiveRegion(options); |
||
182 | } |
||
183 | |||
184 | public void ArchiveRegion(Stream saveStream) |
||
185 | { |
||
186 | ArchiveRegion(saveStream, Guid.Empty); |
||
187 | } |
||
188 | |||
189 | public void ArchiveRegion(Stream saveStream, Guid requestId) |
||
190 | { |
||
191 | ArchiveRegion(saveStream, requestId, new Dictionary<string, object>()); |
||
192 | } |
||
193 | |||
194 | public void ArchiveRegion(Stream saveStream, Guid requestId, Dictionary<string, object> options) |
||
195 | { |
||
196 | new ArchiveWriteRequest(Scene, saveStream, requestId).ArchiveRegion(options); |
||
197 | } |
||
198 | |||
199 | public void DearchiveRegion(string loadPath) |
||
200 | { |
||
201 | DearchiveRegion(loadPath, false, false, Guid.Empty); |
||
202 | } |
||
203 | |||
204 | public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId) |
||
205 | { |
||
206 | m_log.InfoFormat( |
||
207 | "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath); |
||
208 | |||
209 | new ArchiveReadRequest(Scene, loadPath, merge, skipAssets, requestId).DearchiveRegion(); |
||
210 | } |
||
211 | |||
212 | public void DearchiveRegion(Stream loadStream) |
||
213 | { |
||
214 | DearchiveRegion(loadStream, false, false, Guid.Empty); |
||
215 | } |
||
216 | |||
217 | public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId) |
||
218 | { |
||
219 | new ArchiveReadRequest(Scene, loadStream, merge, skipAssets, requestId).DearchiveRegion(); |
||
220 | } |
||
221 | } |
||
222 | } |