diff options
Deleted a few old files that are no longer used.
Deleted the GridInterfaces projects, and for now moved the old local asset server into Framework.Communications, as we prepare to rewrite the asset cache and asset server.
Deleted Framework.manager as I am sure this is no longer in use.
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetServer.cs')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/AssetServer.cs | 392 |
1 files changed, 392 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetServer.cs b/OpenSim/Framework/Communications/Cache/AssetServer.cs new file mode 100644 index 0000000..fd203f7 --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/AssetServer.cs | |||
@@ -0,0 +1,392 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.IO; | ||
30 | using System.Threading; | ||
31 | using Db4objects.Db4o; | ||
32 | using Db4objects.Db4o.Query; | ||
33 | using libsecondlife; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Framework.Interfaces; | ||
37 | using OpenSim.Framework.Types; | ||
38 | using OpenSim.Framework.Utilities; | ||
39 | |||
40 | namespace OpenSim.Framework.Communications.Caches | ||
41 | { | ||
42 | |||
43 | public class LocalAssetServer : IAssetServer | ||
44 | { | ||
45 | private IAssetReceiver _receiver; | ||
46 | private BlockingQueue<ARequest> _assetRequests; | ||
47 | private IObjectContainer db; | ||
48 | private Thread _localAssetServerThread; | ||
49 | |||
50 | public LocalAssetServer() | ||
51 | { | ||
52 | bool yapfile; | ||
53 | this._assetRequests = new BlockingQueue<ARequest>(); | ||
54 | yapfile = File.Exists(Path.Combine(Util.dataDir(), "regionassets.yap")); | ||
55 | |||
56 | MainLog.Instance.Verbose("Local Asset Server class created"); | ||
57 | db = Db4oFactory.OpenFile(Path.Combine(Util.dataDir(), "regionassets.yap")); | ||
58 | MainLog.Instance.Verbose("Db4 Asset database creation"); | ||
59 | |||
60 | if (!yapfile) | ||
61 | { | ||
62 | this.SetUpAssetDatabase(); | ||
63 | } | ||
64 | |||
65 | this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); | ||
66 | this._localAssetServerThread.IsBackground = true; | ||
67 | this._localAssetServerThread.Start(); | ||
68 | |||
69 | } | ||
70 | |||
71 | public void SetReceiver(IAssetReceiver receiver) | ||
72 | { | ||
73 | this._receiver = receiver; | ||
74 | } | ||
75 | |||
76 | public void RequestAsset(LLUUID assetID, bool isTexture) | ||
77 | { | ||
78 | ARequest req = new ARequest(); | ||
79 | req.AssetID = assetID; | ||
80 | req.IsTexture = isTexture; | ||
81 | this._assetRequests.Enqueue(req); | ||
82 | } | ||
83 | |||
84 | public void UpdateAsset(AssetBase asset) | ||
85 | { | ||
86 | |||
87 | } | ||
88 | |||
89 | public void UploadNewAsset(AssetBase asset) | ||
90 | { | ||
91 | AssetStorage store = new AssetStorage(); | ||
92 | store.Data = asset.Data; | ||
93 | store.Name = asset.Name; | ||
94 | store.UUID = asset.FullID; | ||
95 | db.Set(store); | ||
96 | db.Commit(); | ||
97 | } | ||
98 | |||
99 | public void SetServerInfo(string ServerUrl, string ServerKey) | ||
100 | { | ||
101 | |||
102 | } | ||
103 | public void Close() | ||
104 | { | ||
105 | if (db != null) | ||
106 | { | ||
107 | MainLog.Instance.Verbose("Closing local asset server database"); | ||
108 | db.Close(); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | private void RunRequests() | ||
113 | { | ||
114 | while (true) | ||
115 | { | ||
116 | byte[] idata = null; | ||
117 | bool found = false; | ||
118 | AssetStorage foundAsset = null; | ||
119 | ARequest req = this._assetRequests.Dequeue(); | ||
120 | IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID)); | ||
121 | if (result.Count > 0) | ||
122 | { | ||
123 | foundAsset = (AssetStorage)result.Next(); | ||
124 | found = true; | ||
125 | } | ||
126 | |||
127 | AssetBase asset = new AssetBase(); | ||
128 | if (found) | ||
129 | { | ||
130 | asset.FullID = foundAsset.UUID; | ||
131 | asset.Type = foundAsset.Type; | ||
132 | asset.InvType = foundAsset.Type; | ||
133 | asset.Name = foundAsset.Name; | ||
134 | idata = foundAsset.Data; | ||
135 | asset.Data = idata; | ||
136 | _receiver.AssetReceived(asset, req.IsTexture); | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | //asset.FullID = ; | ||
141 | _receiver.AssetNotFound(req.AssetID); | ||
142 | } | ||
143 | |||
144 | } | ||
145 | |||
146 | } | ||
147 | |||
148 | private void SetUpAssetDatabase() | ||
149 | { | ||
150 | MainLog.Instance.Verbose("Setting up asset database"); | ||
151 | |||
152 | AssetBase Image = new AssetBase(); | ||
153 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); | ||
154 | Image.Name = "Bricks"; | ||
155 | this.LoadAsset(Image, true, "bricks.jp2"); | ||
156 | AssetStorage store = new AssetStorage(); | ||
157 | store.Data = Image.Data; | ||
158 | store.Name = Image.Name; | ||
159 | store.UUID = Image.FullID; | ||
160 | db.Set(store); | ||
161 | db.Commit(); | ||
162 | |||
163 | Image = new AssetBase(); | ||
164 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); | ||
165 | Image.Name = "Plywood"; | ||
166 | this.LoadAsset(Image, true, "plywood.jp2"); | ||
167 | store = new AssetStorage(); | ||
168 | store.Data = Image.Data; | ||
169 | store.Name = Image.Name; | ||
170 | store.UUID = Image.FullID; | ||
171 | db.Set(store); | ||
172 | db.Commit(); | ||
173 | |||
174 | Image = new AssetBase(); | ||
175 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); | ||
176 | Image.Name = "Rocks"; | ||
177 | this.LoadAsset(Image, true, "rocks.jp2"); | ||
178 | store = new AssetStorage(); | ||
179 | store.Data = Image.Data; | ||
180 | store.Name = Image.Name; | ||
181 | store.UUID = Image.FullID; | ||
182 | db.Set(store); | ||
183 | db.Commit(); | ||
184 | |||
185 | Image = new AssetBase(); | ||
186 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); | ||
187 | Image.Name = "Granite"; | ||
188 | this.LoadAsset(Image, true, "granite.jp2"); | ||
189 | store = new AssetStorage(); | ||
190 | store.Data = Image.Data; | ||
191 | store.Name = Image.Name; | ||
192 | store.UUID = Image.FullID; | ||
193 | db.Set(store); | ||
194 | db.Commit(); | ||
195 | |||
196 | Image = new AssetBase(); | ||
197 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); | ||
198 | Image.Name = "Hardwood"; | ||
199 | this.LoadAsset(Image, true, "hardwood.jp2"); | ||
200 | store = new AssetStorage(); | ||
201 | store.Data = Image.Data; | ||
202 | store.Name = Image.Name; | ||
203 | store.UUID = Image.FullID; | ||
204 | db.Set(store); | ||
205 | db.Commit(); | ||
206 | |||
207 | Image = new AssetBase(); | ||
208 | Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); | ||
209 | Image.Name = "Prim Base Texture"; | ||
210 | this.LoadAsset(Image, true, "plywood.jp2"); | ||
211 | store = new AssetStorage(); | ||
212 | store.Data = Image.Data; | ||
213 | store.Name = Image.Name; | ||
214 | store.UUID = Image.FullID; | ||
215 | db.Set(store); | ||
216 | db.Commit(); | ||
217 | |||
218 | Image = new AssetBase(); | ||
219 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006"); | ||
220 | Image.Name = "Map Base Texture"; | ||
221 | this.LoadAsset(Image, true, "map_base.jp2"); | ||
222 | store = new AssetStorage(); | ||
223 | store.Data = Image.Data; | ||
224 | store.Name = Image.Name; | ||
225 | store.UUID = Image.FullID; | ||
226 | db.Set(store); | ||
227 | db.Commit(); | ||
228 | |||
229 | Image = new AssetBase(); | ||
230 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007"); | ||
231 | Image.Name = "Map Texture"; | ||
232 | this.LoadAsset(Image, true, "map1.jp2"); | ||
233 | store = new AssetStorage(); | ||
234 | store.Data = Image.Data; | ||
235 | store.Name = Image.Name; | ||
236 | store.UUID = Image.FullID; | ||
237 | db.Set(store); | ||
238 | db.Commit(); | ||
239 | |||
240 | Image = new AssetBase(); | ||
241 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000010"); | ||
242 | Image.Name = "Female Body Texture"; | ||
243 | this.LoadAsset(Image, true, "femalebody.jp2"); | ||
244 | store = new AssetStorage(); | ||
245 | store.Data = Image.Data; | ||
246 | store.Name = Image.Name; | ||
247 | store.UUID = Image.FullID; | ||
248 | db.Set(store); | ||
249 | db.Commit(); | ||
250 | |||
251 | Image = new AssetBase(); | ||
252 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000011"); | ||
253 | Image.Name = "Female Bottom Texture"; | ||
254 | this.LoadAsset(Image, true, "femalebottom.jp2"); | ||
255 | store = new AssetStorage(); | ||
256 | store.Data = Image.Data; | ||
257 | store.Name = Image.Name; | ||
258 | store.UUID = Image.FullID; | ||
259 | db.Set(store); | ||
260 | db.Commit(); | ||
261 | |||
262 | Image = new AssetBase(); | ||
263 | Image.FullID = new LLUUID("00000000-0000-1111-9999-000000000012"); | ||
264 | Image.Name = "Female Face Texture"; | ||
265 | this.LoadAsset(Image, true, "femaleface.jp2"); | ||
266 | store = new AssetStorage(); | ||
267 | store.Data = Image.Data; | ||
268 | store.Name = Image.Name; | ||
269 | store.UUID = Image.FullID; | ||
270 | db.Set(store); | ||
271 | db.Commit(); | ||
272 | |||
273 | Image = new AssetBase(); | ||
274 | Image.FullID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); | ||
275 | Image.Name = "Skin"; | ||
276 | Image.Type = 13; | ||
277 | Image.InvType = 13; | ||
278 | this.LoadAsset(Image, false, "base_skin.dat"); | ||
279 | store = new AssetStorage(); | ||
280 | store.Data = Image.Data; | ||
281 | store.Name = Image.Name; | ||
282 | store.UUID = Image.FullID; | ||
283 | db.Set(store); | ||
284 | db.Commit(); | ||
285 | |||
286 | |||
287 | Image = new AssetBase(); | ||
288 | Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); | ||
289 | Image.Name = "Shape"; | ||
290 | Image.Type = 13; | ||
291 | Image.InvType = 13; | ||
292 | this.LoadAsset(Image, false, "base_shape.dat"); | ||
293 | store = new AssetStorage(); | ||
294 | store.Data = Image.Data; | ||
295 | store.Name = Image.Name; | ||
296 | store.UUID = Image.FullID; | ||
297 | db.Set(store); | ||
298 | db.Commit(); | ||
299 | |||
300 | Image = new AssetBase(); | ||
301 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111110"); | ||
302 | Image.Name = "Shirt"; | ||
303 | Image.Type = 5; | ||
304 | Image.InvType = 18; | ||
305 | this.LoadAsset(Image, false, "newshirt.dat"); | ||
306 | store = new AssetStorage(); | ||
307 | store.Data = Image.Data; | ||
308 | store.Name = Image.Name; | ||
309 | store.UUID = Image.FullID; | ||
310 | db.Set(store); | ||
311 | db.Commit(); | ||
312 | |||
313 | Image = new AssetBase(); | ||
314 | Image.FullID = new LLUUID("00000000-38f9-1111-024e-222222111120"); | ||
315 | Image.Name = "Shirt"; | ||
316 | Image.Type = 5; | ||
317 | Image.InvType = 18; | ||
318 | this.LoadAsset(Image, false, "newpants.dat"); | ||
319 | store = new AssetStorage(); | ||
320 | store.Data = Image.Data; | ||
321 | store.Name = Image.Name; | ||
322 | store.UUID = Image.FullID; | ||
323 | db.Set(store); | ||
324 | db.Commit(); | ||
325 | |||
326 | string filePath = Path.Combine(Util.configDir(), "OpenSimAssetSet.xml"); | ||
327 | if (File.Exists(filePath)) | ||
328 | { | ||
329 | XmlConfigSource source = new XmlConfigSource(filePath); | ||
330 | ReadAssetDetails(source); | ||
331 | } | ||
332 | } | ||
333 | |||
334 | protected void ReadAssetDetails(IConfigSource source) | ||
335 | { | ||
336 | AssetBase newAsset = null; | ||
337 | for (int i = 0; i < source.Configs.Count; i++) | ||
338 | { | ||
339 | newAsset = new AssetBase(); | ||
340 | newAsset.FullID = new LLUUID(source.Configs[i].GetString("assetID", LLUUID.Random().ToStringHyphenated())); | ||
341 | newAsset.Name = source.Configs[i].GetString("name", ""); | ||
342 | newAsset.Type = (sbyte)source.Configs[i].GetInt("assetType", 0); | ||
343 | newAsset.InvType = (sbyte)source.Configs[i].GetInt("inventoryType", 0); | ||
344 | string fileName = source.Configs[i].GetString("fileName", ""); | ||
345 | if (fileName != "") | ||
346 | { | ||
347 | this.LoadAsset(newAsset, false, fileName); | ||
348 | AssetStorage store = new AssetStorage(); | ||
349 | store.Data = newAsset.Data; | ||
350 | store.Name = newAsset.Name; | ||
351 | store.UUID = newAsset.FullID; | ||
352 | db.Set(store); | ||
353 | db.Commit(); | ||
354 | } | ||
355 | } | ||
356 | } | ||
357 | |||
358 | private void LoadAsset(AssetBase info, bool image, string filename) | ||
359 | { | ||
360 | //should request Asset from storage manager | ||
361 | //but for now read from file | ||
362 | |||
363 | string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; | ||
364 | string fileName = Path.Combine(dataPath, filename); | ||
365 | FileInfo fInfo = new FileInfo(fileName); | ||
366 | long numBytes = fInfo.Length; | ||
367 | FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); | ||
368 | byte[] idata = new byte[numBytes]; | ||
369 | BinaryReader br = new BinaryReader(fStream); | ||
370 | idata = br.ReadBytes((int)numBytes); | ||
371 | br.Close(); | ||
372 | fStream.Close(); | ||
373 | info.Data = idata; | ||
374 | //info.loaded=true; | ||
375 | } | ||
376 | } | ||
377 | public class AssetUUIDQuery : Predicate | ||
378 | { | ||
379 | private LLUUID _findID; | ||
380 | |||
381 | public AssetUUIDQuery(LLUUID find) | ||
382 | { | ||
383 | _findID = find; | ||
384 | } | ||
385 | public bool Match(AssetStorage asset) | ||
386 | { | ||
387 | return (asset.UUID == _findID); | ||
388 | } | ||
389 | } | ||
390 | |||
391 | } | ||
392 | |||