aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim-Source/OpenSim.GridInterfaces/Local/LocalAssetServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim-Source/OpenSim.GridInterfaces/Local/LocalAssetServer.cs')
-rw-r--r--OpenSim-Source/OpenSim.GridInterfaces/Local/LocalAssetServer.cs271
1 files changed, 271 insertions, 0 deletions
diff --git a/OpenSim-Source/OpenSim.GridInterfaces/Local/LocalAssetServer.cs b/OpenSim-Source/OpenSim.GridInterfaces/Local/LocalAssetServer.cs
new file mode 100644
index 0000000..5f75821
--- /dev/null
+++ b/OpenSim-Source/OpenSim.GridInterfaces/Local/LocalAssetServer.cs
@@ -0,0 +1,271 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading;
5using System.IO;
6using OpenSim.Framework.Interfaces;
7using OpenSim.Framework.Types;
8using OpenSim.Framework.Utilities;
9using OpenSim.Framework.Console;
10using libsecondlife;
11using Db4objects.Db4o;
12using Db4objects.Db4o.Query;
13
14namespace OpenSim.GridInterfaces.Local
15{
16 public class LocalAssetPlugin : IAssetPlugin
17 {
18 public LocalAssetPlugin()
19 {
20
21 }
22
23 public IAssetServer GetAssetServer()
24 {
25 return (new LocalAssetServer());
26 }
27 }
28
29 public class LocalAssetServer : IAssetServer
30 {
31 private IAssetReceiver _receiver;
32 private BlockingQueue<ARequest> _assetRequests;
33 private IObjectContainer db;
34 private Thread _localAssetServerThread;
35
36 public LocalAssetServer()
37 {
38 bool yapfile;
39 this._assetRequests = new BlockingQueue<ARequest>();
40 yapfile = System.IO.File.Exists("assets.yap");
41
42 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(LogPriority.VERBOSE,"Local Asset Server class created");
43 try
44 {
45 db = Db4oFactory.OpenFile("assets.yap");
46 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(LogPriority.VERBOSE,"Db4 Asset database creation");
47 }
48 catch (Exception e)
49 {
50 db.Close();
51 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(LogPriority.MEDIUM,"Db4 Asset server :Constructor - Exception occured");
52 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, e.ToString());
53 }
54 if (!yapfile)
55 {
56 this.SetUpAssetDatabase();
57 }
58 this._localAssetServerThread = new Thread(new ThreadStart(RunRequests));
59 this._localAssetServerThread.IsBackground = true;
60 this._localAssetServerThread.Start();
61
62 }
63
64 public void SetReceiver(IAssetReceiver receiver)
65 {
66 this._receiver = receiver;
67 }
68
69 public void RequestAsset(LLUUID assetID, bool isTexture)
70 {
71 ARequest req = new ARequest();
72 req.AssetID = assetID;
73 req.IsTexture = isTexture;
74 this._assetRequests.Enqueue(req);
75 }
76
77 public void UpdateAsset(AssetBase asset)
78 {
79
80 }
81
82 public void UploadNewAsset(AssetBase asset)
83 {
84 AssetStorage store = new AssetStorage();
85 store.Data = asset.Data;
86 store.Name = asset.Name;
87 store.UUID = asset.FullID;
88 db.Set(store);
89 db.Commit();
90 }
91
92 public void SetServerInfo(string ServerUrl, string ServerKey)
93 {
94
95 }
96 public void Close()
97 {
98 if (db != null)
99 {
100 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(LogPriority.VERBOSE, "Closing local asset server database");
101 db.Close();
102 }
103 }
104
105 private void RunRequests()
106 {
107 while (true)
108 {
109 byte[] idata = null;
110 bool found = false;
111 AssetStorage foundAsset = null;
112 ARequest req = this._assetRequests.Dequeue();
113 IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID));
114 if (result.Count > 0)
115 {
116 foundAsset = (AssetStorage)result.Next();
117 found = true;
118 }
119
120 AssetBase asset = new AssetBase();
121 if (found)
122 {
123 asset.FullID = foundAsset.UUID;
124 asset.Type = foundAsset.Type;
125 asset.InvType = foundAsset.Type;
126 asset.Name = foundAsset.Name;
127 idata = foundAsset.Data;
128 }
129 else
130 {
131 asset.FullID = LLUUID.Zero;
132 }
133 asset.Data = idata;
134 _receiver.AssetReceived(asset, req.IsTexture);
135 }
136
137 }
138
139 private void SetUpAssetDatabase()
140 {
141 try
142 {
143
144 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(LogPriority.VERBOSE, "Setting up asset database");
145
146 AssetBase Image = new AssetBase();
147 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001");
148 Image.Name = "Bricks";
149 this.LoadAsset(Image, true, "bricks.jp2");
150 AssetStorage store = new AssetStorage();
151 store.Data = Image.Data;
152 store.Name = Image.Name;
153 store.UUID = Image.FullID;
154 db.Set(store);
155 db.Commit();
156
157 Image = new AssetBase();
158 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002");
159 Image.Name = "Plywood";
160 this.LoadAsset(Image, true, "plywood.jp2");
161 store = new AssetStorage();
162 store.Data = Image.Data;
163 store.Name = Image.Name;
164 store.UUID = Image.FullID;
165 db.Set(store);
166 db.Commit();
167
168 Image = new AssetBase();
169 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003");
170 Image.Name = "Rocks";
171 this.LoadAsset(Image, true, "rocks.jp2");
172 store = new AssetStorage();
173 store.Data = Image.Data;
174 store.Name = Image.Name;
175 store.UUID = Image.FullID;
176 db.Set(store);
177 db.Commit();
178
179 Image = new AssetBase();
180 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004");
181 Image.Name = "Granite";
182 this.LoadAsset(Image, true, "granite.jp2");
183 store = new AssetStorage();
184 store.Data = Image.Data;
185 store.Name = Image.Name;
186 store.UUID = Image.FullID;
187 db.Set(store);
188 db.Commit();
189
190 Image = new AssetBase();
191 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005");
192 Image.Name = "Hardwood";
193 this.LoadAsset(Image, true, "hardwood.jp2");
194 store = new AssetStorage();
195 store.Data = Image.Data;
196 store.Name = Image.Name;
197 store.UUID = Image.FullID;
198 db.Set(store);
199 db.Commit();
200
201 Image = new AssetBase();
202 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005");
203 Image.Name = "Prim Base Texture";
204 this.LoadAsset(Image, true, "plywood.jp2");
205 store = new AssetStorage();
206 store.Data = Image.Data;
207 store.Name = Image.Name;
208 store.UUID = Image.FullID;
209 db.Set(store);
210 db.Commit();
211
212 Image = new AssetBase();
213 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000006");
214 Image.Name = "Map Base Texture";
215 this.LoadAsset(Image, true, "map_base.jp2");
216 store = new AssetStorage();
217 store.Data = Image.Data;
218 store.Name = Image.Name;
219 store.UUID = Image.FullID;
220 db.Set(store);
221 db.Commit();
222
223 Image = new AssetBase();
224 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000007");
225 Image.Name = "Map Texture";
226 this.LoadAsset(Image, true, "map1.jp2");
227 store = new AssetStorage();
228 store.Data = Image.Data;
229 store.Name = Image.Name;
230 store.UUID = Image.FullID;
231 db.Set(store);
232 db.Commit();
233
234 Image = new AssetBase();
235 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
236 Image.Name = "Shape";
237 this.LoadAsset(Image, false, "base_shape.dat");
238 store = new AssetStorage();
239 store.Data = Image.Data;
240 store.Name = Image.Name;
241 store.UUID = Image.FullID;
242 db.Set(store);
243 db.Commit();
244 }
245 catch (Exception e)
246 {
247 Console.WriteLine(e.Message);
248 }
249
250 }
251
252 private void LoadAsset(AssetBase info, bool image, string filename)
253 {
254 //should request Asset from storage manager
255 //but for now read from file
256
257 string dataPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
258 string fileName = Path.Combine(dataPath, filename);
259 FileInfo fInfo = new FileInfo(fileName);
260 long numBytes = fInfo.Length;
261 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
262 byte[] idata = new byte[numBytes];
263 BinaryReader br = new BinaryReader(fStream);
264 idata = br.ReadBytes((int)numBytes);
265 br.Close();
266 fStream.Close();
267 info.Data = idata;
268 //info.loaded=true;
269 }
270 }
271}