aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/GridInterfaces/Local/LocalAssetServer.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/GridInterfaces/Local/LocalAssetServer.cs622
1 files changed, 311 insertions, 311 deletions
diff --git a/OpenSim/Region/GridInterfaces/Local/LocalAssetServer.cs b/OpenSim/Region/GridInterfaces/Local/LocalAssetServer.cs
index 1023820..f3d7a2c 100644
--- a/OpenSim/Region/GridInterfaces/Local/LocalAssetServer.cs
+++ b/OpenSim/Region/GridInterfaces/Local/LocalAssetServer.cs
@@ -1,311 +1,311 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Threading; 30using System.Threading;
31using Db4objects.Db4o; 31using Db4objects.Db4o;
32using Db4objects.Db4o.Query; 32using Db4objects.Db4o.Query;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Console; 34using OpenSim.Framework.Console;
35using OpenSim.Framework.Interfaces; 35using OpenSim.Framework.Interfaces;
36using OpenSim.Framework.Types; 36using OpenSim.Framework.Types;
37using OpenSim.Framework.Utilities; 37using OpenSim.Framework.Utilities;
38 38
39namespace OpenSim.Region.GridInterfaces.Local 39namespace OpenSim.Region.GridInterfaces.Local
40{ 40{
41 public class LocalAssetPlugin : IAssetPlugin 41 public class LocalAssetPlugin : IAssetPlugin
42 { 42 {
43 public LocalAssetPlugin() 43 public LocalAssetPlugin()
44 { 44 {
45 45
46 } 46 }
47 47
48 public IAssetServer GetAssetServer() 48 public IAssetServer GetAssetServer()
49 { 49 {
50 return (new LocalAssetServer()); 50 return (new LocalAssetServer());
51 } 51 }
52 } 52 }
53 53
54 public class LocalAssetServer : IAssetServer 54 public class LocalAssetServer : IAssetServer
55 { 55 {
56 private IAssetReceiver _receiver; 56 private IAssetReceiver _receiver;
57 private BlockingQueue<ARequest> _assetRequests; 57 private BlockingQueue<ARequest> _assetRequests;
58 private IObjectContainer db; 58 private IObjectContainer db;
59 private Thread _localAssetServerThread; 59 private Thread _localAssetServerThread;
60 60
61 public LocalAssetServer() 61 public LocalAssetServer()
62 { 62 {
63 bool yapfile; 63 bool yapfile;
64 this._assetRequests = new BlockingQueue<ARequest>(); 64 this._assetRequests = new BlockingQueue<ARequest>();
65 yapfile = File.Exists("regionassets.yap"); 65 yapfile = File.Exists("regionassets.yap");
66 66
67 MainLog.Instance.Verbose( "Local Asset Server class created"); 67 MainLog.Instance.Verbose( "Local Asset Server class created");
68 try 68 try
69 { 69 {
70 db = Db4oFactory.OpenFile("regionassets.yap"); 70 db = Db4oFactory.OpenFile("regionassets.yap");
71 MainLog.Instance.Verbose( "Db4 Asset database creation"); 71 MainLog.Instance.Verbose( "Db4 Asset database creation");
72 } 72 }
73 catch (Exception e) 73 catch (Exception e)
74 { 74 {
75 db.Close(); 75 db.Close();
76 MainLog.Instance.WriteLine(LogPriority.MEDIUM, "Db4 Asset server :Constructor - Exception occured"); 76 MainLog.Instance.WriteLine(LogPriority.MEDIUM, "Db4 Asset server :Constructor - Exception occured");
77 MainLog.Instance.Warn(e.ToString()); 77 MainLog.Instance.Warn(e.ToString());
78 } 78 }
79 if (!yapfile) 79 if (!yapfile)
80 { 80 {
81 this.SetUpAssetDatabase(); 81 this.SetUpAssetDatabase();
82 } 82 }
83 this._localAssetServerThread = new Thread(new ThreadStart(RunRequests)); 83 this._localAssetServerThread = new Thread(new ThreadStart(RunRequests));
84 this._localAssetServerThread.IsBackground = true; 84 this._localAssetServerThread.IsBackground = true;
85 this._localAssetServerThread.Start(); 85 this._localAssetServerThread.Start();
86 86
87 } 87 }
88 88
89 public void SetReceiver(IAssetReceiver receiver) 89 public void SetReceiver(IAssetReceiver receiver)
90 { 90 {
91 this._receiver = receiver; 91 this._receiver = receiver;
92 } 92 }
93 93
94 public void RequestAsset(LLUUID assetID, bool isTexture) 94 public void RequestAsset(LLUUID assetID, bool isTexture)
95 { 95 {
96 ARequest req = new ARequest(); 96 ARequest req = new ARequest();
97 req.AssetID = assetID; 97 req.AssetID = assetID;
98 req.IsTexture = isTexture; 98 req.IsTexture = isTexture;
99 this._assetRequests.Enqueue(req); 99 this._assetRequests.Enqueue(req);
100 } 100 }
101 101
102 public void UpdateAsset(AssetBase asset) 102 public void UpdateAsset(AssetBase asset)
103 { 103 {
104 104
105 } 105 }
106 106
107 public void UploadNewAsset(AssetBase asset) 107 public void UploadNewAsset(AssetBase asset)
108 { 108 {
109 AssetStorage store = new AssetStorage(); 109 AssetStorage store = new AssetStorage();
110 store.Data = asset.Data; 110 store.Data = asset.Data;
111 store.Name = asset.Name; 111 store.Name = asset.Name;
112 store.UUID = asset.FullID; 112 store.UUID = asset.FullID;
113 db.Set(store); 113 db.Set(store);
114 db.Commit(); 114 db.Commit();
115 } 115 }
116 116
117 public void SetServerInfo(string ServerUrl, string ServerKey) 117 public void SetServerInfo(string ServerUrl, string ServerKey)
118 { 118 {
119 119
120 } 120 }
121 public void Close() 121 public void Close()
122 { 122 {
123 if (db != null) 123 if (db != null)
124 { 124 {
125 MainLog.Instance.Verbose( "Closing local asset server database"); 125 MainLog.Instance.Verbose( "Closing local asset server database");
126 db.Close(); 126 db.Close();
127 } 127 }
128 } 128 }
129 129
130 private void RunRequests() 130 private void RunRequests()
131 { 131 {
132 while (true) 132 while (true)
133 { 133 {
134 byte[] idata = null; 134 byte[] idata = null;
135 bool found = false; 135 bool found = false;
136 AssetStorage foundAsset = null; 136 AssetStorage foundAsset = null;
137 ARequest req = this._assetRequests.Dequeue(); 137 ARequest req = this._assetRequests.Dequeue();
138 IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID)); 138 IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID));
139 if (result.Count > 0) 139 if (result.Count > 0)
140 { 140 {
141 foundAsset = (AssetStorage)result.Next(); 141 foundAsset = (AssetStorage)result.Next();
142 found = true; 142 found = true;
143 } 143 }
144 144
145 AssetBase asset = new AssetBase(); 145 AssetBase asset = new AssetBase();
146 if (found) 146 if (found)
147 { 147 {
148 asset.FullID = foundAsset.UUID; 148 asset.FullID = foundAsset.UUID;
149 asset.Type = foundAsset.Type; 149 asset.Type = foundAsset.Type;
150 asset.InvType = foundAsset.Type; 150 asset.InvType = foundAsset.Type;
151 asset.Name = foundAsset.Name; 151 asset.Name = foundAsset.Name;
152 idata = foundAsset.Data; 152 idata = foundAsset.Data;
153 } 153 }
154 else 154 else
155 { 155 {
156 asset.FullID = LLUUID.Zero; 156 asset.FullID = LLUUID.Zero;
157 } 157 }
158 asset.Data = idata; 158 asset.Data = idata;
159 _receiver.AssetReceived(asset, req.IsTexture); 159 _receiver.AssetReceived(asset, req.IsTexture);
160 } 160 }
161 161
162 } 162 }
163 163
164 private void SetUpAssetDatabase() 164 private void SetUpAssetDatabase()
165 { 165 {
166 try 166 try
167 { 167 {
168 168
169 MainLog.Instance.Verbose( "Setting up asset database"); 169 MainLog.Instance.Verbose( "Setting up asset database");
170 170
171 AssetBase Image = new AssetBase(); 171 AssetBase Image = new AssetBase();
172 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); 172 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001");
173 Image.Name = "Bricks"; 173 Image.Name = "Bricks";
174 this.LoadAsset(Image, true, "bricks.jp2"); 174 this.LoadAsset(Image, true, "bricks.jp2");
175 AssetStorage store = new AssetStorage(); 175 AssetStorage store = new AssetStorage();
176 store.Data = Image.Data; 176 store.Data = Image.Data;
177 store.Name = Image.Name; 177 store.Name = Image.Name;
178 store.UUID = Image.FullID; 178 store.UUID = Image.FullID;
179 db.Set(store); 179 db.Set(store);
180 db.Commit(); 180 db.Commit();
181 181
182 Image = new AssetBase(); 182 Image = new AssetBase();
183 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); 183 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002");
184 Image.Name = "Plywood"; 184 Image.Name = "Plywood";
185 this.LoadAsset(Image, true, "plywood.jp2"); 185 this.LoadAsset(Image, true, "plywood.jp2");
186 store = new AssetStorage(); 186 store = new AssetStorage();
187 store.Data = Image.Data; 187 store.Data = Image.Data;
188 store.Name = Image.Name; 188 store.Name = Image.Name;
189 store.UUID = Image.FullID; 189 store.UUID = Image.FullID;
190 db.Set(store); 190 db.Set(store);
191 db.Commit(); 191 db.Commit();
192 192
193 Image = new AssetBase(); 193 Image = new AssetBase();
194 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); 194 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003");
195 Image.Name = "Rocks"; 195 Image.Name = "Rocks";
196 this.LoadAsset(Image, true, "rocks.jp2"); 196 this.LoadAsset(Image, true, "rocks.jp2");
197 store = new AssetStorage(); 197 store = new AssetStorage();
198 store.Data = Image.Data; 198 store.Data = Image.Data;
199 store.Name = Image.Name; 199 store.Name = Image.Name;
200 store.UUID = Image.FullID; 200 store.UUID = Image.FullID;
201 db.Set(store); 201 db.Set(store);
202 db.Commit(); 202 db.Commit();
203 203
204 Image = new AssetBase(); 204 Image = new AssetBase();
205 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); 205 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004");
206 Image.Name = "Granite"; 206 Image.Name = "Granite";
207 this.LoadAsset(Image, true, "granite.jp2"); 207 this.LoadAsset(Image, true, "granite.jp2");
208 store = new AssetStorage(); 208 store = new AssetStorage();
209 store.Data = Image.Data; 209 store.Data = Image.Data;
210 store.Name = Image.Name; 210 store.Name = Image.Name;
211 store.UUID = Image.FullID; 211 store.UUID = Image.FullID;
212 db.Set(store); 212 db.Set(store);
213 db.Commit(); 213 db.Commit();
214 214
215 Image = new AssetBase(); 215 Image = new AssetBase();
216 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); 216 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005");
217 Image.Name = "Hardwood"; 217 Image.Name = "Hardwood";
218 this.LoadAsset(Image, true, "hardwood.jp2"); 218 this.LoadAsset(Image, true, "hardwood.jp2");
219 store = new AssetStorage(); 219 store = new AssetStorage();
220 store.Data = Image.Data; 220 store.Data = Image.Data;
221 store.Name = Image.Name; 221 store.Name = Image.Name;
222 store.UUID = Image.FullID; 222 store.UUID = Image.FullID;
223 db.Set(store); 223 db.Set(store);
224 db.Commit(); 224 db.Commit();
225 225
226 Image = new AssetBase(); 226 Image = new AssetBase();
227 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); 227 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005");
228 Image.Name = "Prim Base Texture"; 228 Image.Name = "Prim Base Texture";
229 this.LoadAsset(Image, true, "plywood.jp2"); 229 this.LoadAsset(Image, true, "plywood.jp2");
230 store = new AssetStorage(); 230 store = new AssetStorage();
231 store.Data = Image.Data; 231 store.Data = Image.Data;
232 store.Name = Image.Name; 232 store.Name = Image.Name;
233 store.UUID = Image.FullID; 233 store.UUID = Image.FullID;
234 db.Set(store); 234 db.Set(store);
235 db.Commit(); 235 db.Commit();
236 236
237 Image = new AssetBase(); 237 Image = new AssetBase();
238 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006"); 238 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006");
239 Image.Name = "Map Base Texture"; 239 Image.Name = "Map Base Texture";
240 this.LoadAsset(Image, true, "map_base.jp2"); 240 this.LoadAsset(Image, true, "map_base.jp2");
241 store = new AssetStorage(); 241 store = new AssetStorage();
242 store.Data = Image.Data; 242 store.Data = Image.Data;
243 store.Name = Image.Name; 243 store.Name = Image.Name;
244 store.UUID = Image.FullID; 244 store.UUID = Image.FullID;
245 db.Set(store); 245 db.Set(store);
246 db.Commit(); 246 db.Commit();
247 247
248 Image = new AssetBase(); 248 Image = new AssetBase();
249 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007"); 249 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007");
250 Image.Name = "Map Texture"; 250 Image.Name = "Map Texture";
251 this.LoadAsset(Image, true, "map1.jp2"); 251 this.LoadAsset(Image, true, "map1.jp2");
252 store = new AssetStorage(); 252 store = new AssetStorage();
253 store.Data = Image.Data; 253 store.Data = Image.Data;
254 store.Name = Image.Name; 254 store.Name = Image.Name;
255 store.UUID = Image.FullID; 255 store.UUID = Image.FullID;
256 db.Set(store); 256 db.Set(store);
257 db.Commit(); 257 db.Commit();
258 258
259 Image = new AssetBase(); 259 Image = new AssetBase();
260 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); 260 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
261 Image.Name = "Shape"; 261 Image.Name = "Shape";
262 this.LoadAsset(Image, false, "base_shape.dat"); 262 this.LoadAsset(Image, false, "base_shape.dat");
263 store = new AssetStorage(); 263 store = new AssetStorage();
264 store.Data = Image.Data; 264 store.Data = Image.Data;
265 store.Name = Image.Name; 265 store.Name = Image.Name;
266 store.UUID = Image.FullID; 266 store.UUID = Image.FullID;
267 db.Set(store); 267 db.Set(store);
268 db.Commit(); 268 db.Commit();
269 } 269 }
270 catch (Exception e) 270 catch (Exception e)
271 { 271 {
272 Console.WriteLine("exception loading default assets into database"); 272 Console.WriteLine("exception loading default assets into database");
273 Console.WriteLine(e.Message); 273 Console.WriteLine(e.Message);
274 } 274 }
275 275
276 } 276 }
277 277
278 private void LoadAsset(AssetBase info, bool image, string filename) 278 private void LoadAsset(AssetBase info, bool image, string filename)
279 { 279 {
280 //should request Asset from storage manager 280 //should request Asset from storage manager
281 //but for now read from file 281 //but for now read from file
282 282
283 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; 283 string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
284 string fileName = Path.Combine(dataPath, filename); 284 string fileName = Path.Combine(dataPath, filename);
285 FileInfo fInfo = new FileInfo(fileName); 285 FileInfo fInfo = new FileInfo(fileName);
286 long numBytes = fInfo.Length; 286 long numBytes = fInfo.Length;
287 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); 287 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
288 byte[] idata = new byte[numBytes]; 288 byte[] idata = new byte[numBytes];
289 BinaryReader br = new BinaryReader(fStream); 289 BinaryReader br = new BinaryReader(fStream);
290 idata = br.ReadBytes((int)numBytes); 290 idata = br.ReadBytes((int)numBytes);
291 br.Close(); 291 br.Close();
292 fStream.Close(); 292 fStream.Close();
293 info.Data = idata; 293 info.Data = idata;
294 //info.loaded=true; 294 //info.loaded=true;
295 } 295 }
296 } 296 }
297 public class AssetUUIDQuery : Predicate 297 public class AssetUUIDQuery : Predicate
298 { 298 {
299 private LLUUID _findID; 299 private LLUUID _findID;
300 300
301 public AssetUUIDQuery(LLUUID find) 301 public AssetUUIDQuery(LLUUID find)
302 { 302 {
303 _findID = find; 303 _findID = find;
304 } 304 }
305 public bool Match(AssetStorage asset) 305 public bool Match(AssetStorage asset)
306 { 306 {
307 return (asset.UUID == _findID); 307 return (asset.UUID == _findID);
308 } 308 }
309 } 309 }
310 310
311} 311}