32 using OpenSim.Framework;
33 using OpenSim.Framework.ServiceAuth;
34 using OpenSim.Framework.Console;
35 using OpenSim.Server.Base;
36 using OpenSim.Services.Interfaces;
37 using OpenSim.Framework.Servers.HttpServer;
38 using OpenSim.Server.Handlers.Base;
45 private string m_ConfigName =
"AssetService";
48 base(config, server, configName)
50 if (configName != String.Empty)
51 m_ConfigName = configName;
53 IConfig serverConfig = config.Configs[m_ConfigName];
54 if (serverConfig == null)
55 throw new Exception(String.Format(
"No section '{0}' in config file", m_ConfigName));
57 string assetService = serverConfig.GetString(
"LocalServiceModule",
60 if (assetService == String.Empty)
61 throw new Exception(
"No LocalServiceModule in config file");
63 Object[] args =
new Object[] { config, m_ConfigName };
67 if (m_AssetService == null)
68 throw new Exception(String.Format(
"Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName));
70 bool allowDelete = serverConfig.GetBoolean(
"AllowRemoteDelete",
false);
71 bool allowDeleteAllTypes = serverConfig.GetBoolean(
"AllowRemoteDeleteAllTypes",
false);
73 string redirectURL = serverConfig.GetString(
"RedirectURL", string.Empty);
79 allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.None;
83 if (allowDeleteAllTypes)
84 allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.All;
86 allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile;
89 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
96 MainConsole.Instance.Commands.AddCommand(
"Assets",
false,
99 "Show asset information",
102 MainConsole.Instance.Commands.AddCommand(
"Assets",
false,
105 "Delete asset from database",
108 MainConsole.Instance.Commands.AddCommand(
"Assets",
false,
111 "Dump asset to a file",
112 "The filename is the same as the ID given.",
116 void HandleDeleteAsset(
string module,
string[] args)
120 MainConsole.Instance.Output(
"Syntax: delete asset <ID>");
124 AssetBase asset = m_AssetService.Get(args[2]);
126 if (asset == null || asset.
Data.Length == 0)
128 MainConsole.Instance.OutputFormat(
"Could not find asset with ID {0}", args[2]);
132 if (!m_AssetService.Delete(asset.
ID))
135 MainConsole.Instance.OutputFormat(
"Deleted asset {0} {1}", asset.ID, asset.Name);
138 void HandleDumpAsset(
string module,
string[] args)
142 MainConsole.Instance.Output(
"Usage is dump asset <ID>");
147 string rawAssetId = args[2];
149 if (!UUID.TryParse(rawAssetId, out assetId))
151 MainConsole.Instance.OutputFormat(
"ERROR: {0} is not a valid ID format", rawAssetId);
155 AssetBase asset = m_AssetService.Get(assetId.ToString());
158 MainConsole.Instance.OutputFormat(
"ERROR: No asset found with ID {0}", assetId);
162 string fileName = rawAssetId;
167 using (FileStream fs =
new FileStream(fileName, FileMode.CreateNew))
169 using (BinaryWriter bw =
new BinaryWriter(fs))
171 bw.Write(asset.Data);
175 MainConsole.Instance.OutputFormat(
"Asset dumped to file {0}", fileName);
178 void HandleShowAsset(
string module,
string[] args)
182 MainConsole.Instance.Output(
"Syntax: show asset <ID>");
186 AssetBase asset = m_AssetService.Get(args[2]);
188 if (asset == null || asset.
Data.Length == 0)
190 MainConsole.Instance.Output(
"Asset not found");
196 MainConsole.Instance.OutputFormat(
"Name: {0}", asset.Name);
197 MainConsole.Instance.OutputFormat(
"Description: {0}", asset.Description);
198 MainConsole.Instance.OutputFormat(
"Type: {0} (type number = {1})", (AssetType)asset.
Type, asset.
Type);
199 MainConsole.Instance.OutputFormat(
"Content-type: {0}", asset.Metadata.ContentType);
200 MainConsole.Instance.OutputFormat(
"Size: {0} bytes", asset.Data.Length);
201 MainConsole.Instance.OutputFormat(
"Temporary: {0}", asset.Temporary ?
"yes" :
"no");
202 MainConsole.Instance.OutputFormat(
"Flags: {0}", asset.Metadata.Flags);
204 for (i = 0 ; i < 5 ; i++)
207 if (asset.
Data.Length <= off)
210 if (asset.
Data.Length < off + len)
211 len = asset.Data.Length - off;
213 byte[] line =
new byte[len];
214 Array.Copy(asset.Data, off, line, 0, len);
216 string text = BitConverter.ToString(line);
217 MainConsole.Instance.Output(String.Format(
"{0:x4}: {1}", off, text));
void OutputFormat(string format, params object[] components)
AllowedRemoteDeleteTypes
Remote deletes allowed.
sbyte Type
(sbyte) AssetType enum
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
AssetServiceConnector(IConfigSource config, IHttpServer server, string configName)
Asset class. All Assets are reference by this class or a class derived from this class ...
static ICommandConsole Instance
Interactive OpenSim region server
static bool CheckFileDoesNotExist(ICommandConsole console, string path)
Check if the given file path exists.
string ID
Asset MetaData ID (transferring from UUID to string ID)