opensim – Blame information for rev 1
?pathlinks?
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 System.Text; |
||
33 | using log4net; |
||
34 | using Mono.Addins; |
||
35 | using Nini.Config; |
||
36 | using OpenMetaverse; |
||
37 | using OpenSim.Framework; |
||
38 | using OpenSim.Framework.Console; |
||
39 | using OpenSim.Region.Framework.Interfaces; |
||
40 | using OpenSim.Region.Framework.Scenes; |
||
41 | |||
42 | namespace OpenSim.Region.OptionalModules.Asset |
||
43 | { |
||
44 | /// <summary> |
||
45 | /// A module that just holds commands for inspecting assets. |
||
46 | /// </summary> |
||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AssetInfoModule")] |
||
48 | public class AssetInfoModule : ISharedRegionModule |
||
49 | { |
||
50 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
51 | |||
52 | private Scene m_scene; |
||
53 | |||
54 | public string Name { get { return "Asset Information Module"; } } |
||
55 | |||
56 | public Type ReplaceableInterface { get { return null; } } |
||
57 | |||
58 | public void Initialise(IConfigSource source) |
||
59 | { |
||
60 | // m_log.DebugFormat("[ASSET INFO MODULE]: INITIALIZED MODULE"); |
||
61 | } |
||
62 | |||
63 | public void PostInitialise() |
||
64 | { |
||
65 | // m_log.DebugFormat("[ASSET INFO MODULE]: POST INITIALIZED MODULE"); |
||
66 | } |
||
67 | |||
68 | public void Close() |
||
69 | { |
||
70 | // m_log.DebugFormat("[ASSET INFO MODULE]: CLOSED MODULE"); |
||
71 | } |
||
72 | |||
73 | public void AddRegion(Scene scene) |
||
74 | { |
||
75 | // m_log.DebugFormat("[ASSET INFO MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); |
||
76 | } |
||
77 | |||
78 | public void RemoveRegion(Scene scene) |
||
79 | { |
||
80 | // m_log.DebugFormat("[ASSET INFO MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); |
||
81 | } |
||
82 | |||
83 | public void RegionLoaded(Scene scene) |
||
84 | { |
||
85 | // m_log.DebugFormat("[ASSET INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); |
||
86 | |||
87 | if (m_scene == null) |
||
88 | m_scene = scene; |
||
89 | |||
90 | MainConsole.Instance.Commands.AddCommand( |
||
91 | "Assets", |
||
92 | false, |
||
93 | "show asset", |
||
94 | "show asset <ID>", |
||
95 | "Show asset information", |
||
96 | HandleShowAsset); |
||
97 | |||
98 | MainConsole.Instance.Commands.AddCommand( |
||
99 | "Assets", false, "dump asset", |
||
100 | "dump asset <id>", |
||
101 | "Dump an asset", |
||
102 | HandleDumpAsset); |
||
103 | } |
||
104 | |||
105 | void HandleDumpAsset(string module, string[] args) |
||
106 | { |
||
107 | if (args.Length < 3) |
||
108 | { |
||
109 | MainConsole.Instance.Output("Usage is dump asset <ID>"); |
||
110 | return; |
||
111 | } |
||
112 | |||
113 | UUID assetId; |
||
114 | string rawAssetId = args[2]; |
||
115 | |||
116 | if (!UUID.TryParse(rawAssetId, out assetId)) |
||
117 | { |
||
118 | MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId); |
||
119 | return; |
||
120 | } |
||
121 | |||
122 | AssetBase asset = m_scene.AssetService.Get(assetId.ToString()); |
||
123 | if (asset == null) |
||
124 | { |
||
125 | MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId); |
||
126 | return; |
||
127 | } |
||
128 | |||
129 | string fileName = rawAssetId; |
||
130 | |||
131 | if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName)) |
||
132 | return; |
||
133 | |||
134 | using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) |
||
135 | { |
||
136 | using (BinaryWriter bw = new BinaryWriter(fs)) |
||
137 | { |
||
138 | bw.Write(asset.Data); |
||
139 | } |
||
140 | } |
||
141 | |||
142 | MainConsole.Instance.OutputFormat("Asset dumped to file {0}", fileName); |
||
143 | } |
||
144 | |||
145 | void HandleShowAsset(string module, string[] args) |
||
146 | { |
||
147 | if (args.Length < 3) |
||
148 | { |
||
149 | MainConsole.Instance.Output("Syntax: show asset <ID>"); |
||
150 | return; |
||
151 | } |
||
152 | |||
153 | AssetBase asset = m_scene.AssetService.Get(args[2]); |
||
154 | |||
155 | if (asset == null || asset.Data.Length == 0) |
||
156 | { |
||
157 | MainConsole.Instance.Output("Asset not found"); |
||
158 | return; |
||
159 | } |
||
160 | |||
161 | int i; |
||
162 | |||
163 | MainConsole.Instance.OutputFormat("Name: {0}", asset.Name); |
||
164 | MainConsole.Instance.OutputFormat("Description: {0}", asset.Description); |
||
165 | MainConsole.Instance.OutputFormat("Type: {0} (type number = {1})", (AssetType)asset.Type, asset.Type); |
||
166 | MainConsole.Instance.OutputFormat("Content-type: {0}", asset.Metadata.ContentType); |
||
167 | MainConsole.Instance.OutputFormat("Size: {0} bytes", asset.Data.Length); |
||
168 | MainConsole.Instance.OutputFormat("Temporary: {0}", asset.Temporary ? "yes" : "no"); |
||
169 | MainConsole.Instance.OutputFormat("Flags: {0}", asset.Metadata.Flags); |
||
170 | |||
171 | for (i = 0 ; i < 5 ; i++) |
||
172 | { |
||
173 | int off = i * 16; |
||
174 | if (asset.Data.Length <= off) |
||
175 | break; |
||
176 | int len = 16; |
||
177 | if (asset.Data.Length < off + len) |
||
178 | len = asset.Data.Length - off; |
||
179 | |||
180 | byte[] line = new byte[len]; |
||
181 | Array.Copy(asset.Data, off, line, 0, len); |
||
182 | |||
183 | string text = BitConverter.ToString(line); |
||
184 | MainConsole.Instance.Output(String.Format("{0:x4}: {1}", off, text)); |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | } |