aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGridServices.AssetServer/Main.cs
diff options
context:
space:
mode:
authorMW2007-06-08 16:55:44 +0000
committerMW2007-06-08 16:55:44 +0000
commit591e1704283330b0120e99819ff68404d1c92d76 (patch)
treecdeeb0b8c5aff678b5558ea4c912d1c81f988d88 /OpenGridServices/OpenGridServices.AssetServer/Main.cs
parentDeleted OpenGridServices folder as the easiest way to reimport the latest ver... (diff)
downloadopensim-SC_OLD-591e1704283330b0120e99819ff68404d1c92d76.zip
opensim-SC_OLD-591e1704283330b0120e99819ff68404d1c92d76.tar.gz
opensim-SC_OLD-591e1704283330b0120e99819ff68404d1c92d76.tar.bz2
opensim-SC_OLD-591e1704283330b0120e99819ff68404d1c92d76.tar.xz
Re-imported OpenGridServices from trunk
Diffstat (limited to 'OpenGridServices/OpenGridServices.AssetServer/Main.cs')
-rw-r--r--OpenGridServices/OpenGridServices.AssetServer/Main.cs338
1 files changed, 338 insertions, 0 deletions
diff --git a/OpenGridServices/OpenGridServices.AssetServer/Main.cs b/OpenGridServices/OpenGridServices.AssetServer/Main.cs
new file mode 100644
index 0000000..e9b94ea
--- /dev/null
+++ b/OpenGridServices/OpenGridServices.AssetServer/Main.cs
@@ -0,0 +1,338 @@
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
29using System;
30using System.IO;
31using System.Text;
32using System.Timers;
33using System.Net;
34using System.Reflection;
35using System.Threading;
36using libsecondlife;
37using OpenSim.Framework;
38using OpenSim.Framework.Sims;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Types;
41using OpenSim.Framework.Interfaces;
42using OpenSim.Framework.Utilities;
43using OpenSim.GridInterfaces.Local; // REFACTORING IS NEEDED!!!!!!!!!!!
44using OpenSim.Servers;
45using Db4objects.Db4o;
46using Db4objects.Db4o.Query;
47
48namespace OpenGridServices.AssetServer
49{
50 /// <summary>
51 /// An asset server
52 /// </summary>
53 public class OpenAsset_Main : BaseServer, conscmd_callback
54 {
55 private IObjectContainer db;
56
57 public static OpenAsset_Main assetserver;
58
59 private ConsoleBase m_console;
60
61 [STAThread]
62 public static void Main(string[] args)
63 {
64 Console.WriteLine("Starting...\n");
65
66 assetserver = new OpenAsset_Main();
67 assetserver.Startup();
68
69 assetserver.Work();
70 }
71
72 private void Work()
73 {
74 m_console.Notice("Enter help for a list of commands");
75
76 while (true)
77 {
78 m_console.MainConsolePrompt();
79 }
80 }
81
82 private OpenAsset_Main()
83 {
84 m_console = new ConsoleBase("opengrid-AssetServer-console.log", "OpenAsset", this, false);
85 MainConsole.Instance = m_console;
86 }
87
88 public void Startup()
89 {
90 m_console.Verbose( "Main.cs:Startup() - Setting up asset DB");
91 setupDB();
92
93 m_console.Verbose( "Main.cs:Startup() - Starting HTTP process");
94 AssetHttpServer httpServer = new AssetHttpServer(8003);
95
96
97 httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod);
98 httpServer.AddRestHandler("POST", "/assets/", this.assetPostMethod);
99
100 httpServer.Start();
101
102 }
103
104 public string assetPostMethod(string requestBody, string path, string param)
105 {
106 AssetBase asset = new AssetBase();
107 asset.Name = "";
108 asset.FullID = new LLUUID(param);
109 Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
110 byte[] buffer = Windows1252Encoding.GetBytes(requestBody);
111 asset.Data = buffer;
112 AssetStorage store = new AssetStorage();
113 store.Data = asset.Data;
114 store.Name = asset.Name;
115 store.UUID = asset.FullID;
116 db.Set(store);
117 db.Commit();
118 return "";
119 }
120
121 public string assetGetMethod(string request, string path, string param)
122 {
123 Console.WriteLine("got a request " + param);
124 byte[] assetdata = getAssetData(new LLUUID(param), false);
125 if (assetdata != null)
126 {
127 Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
128 string ret = Windows1252Encoding.GetString(assetdata);
129 //string ret = System.Text.Encoding.Unicode.GetString(assetdata);
130
131 return ret;
132
133 }
134 else
135 {
136 return "";
137 }
138
139 }
140
141 public byte[] getAssetData(LLUUID assetID, bool isTexture)
142 {
143 bool found = false;
144 AssetStorage foundAsset = null;
145
146 IObjectSet result = db.Get(new AssetStorage(assetID));
147 if (result.Count > 0)
148 {
149 foundAsset = (AssetStorage)result.Next();
150 found = true;
151 }
152
153 if (found)
154 {
155 return foundAsset.Data;
156 }
157 else
158 {
159 return null;
160 }
161 }
162
163 public void setupDB()
164 {
165 bool yapfile = System.IO.File.Exists("assets.yap");
166 try
167 {
168 db = Db4oFactory.OpenFile("assets.yap");
169 OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Main.cs:setupDB() - creation");
170 }
171 catch (Exception e)
172 {
173 db.Close();
174 OpenSim.Framework.Console.MainConsole.Instance.Warn("Main.cs:setupDB() - Exception occured");
175 OpenSim.Framework.Console.MainConsole.Instance.Warn(e.ToString());
176 }
177 if (!yapfile)
178 {
179 this.LoadDB();
180 }
181 }
182
183 public void LoadDB()
184 {
185 try
186 {
187
188 Console.WriteLine("setting up Asset database");
189
190 AssetBase Image = new AssetBase();
191 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001");
192 Image.Name = "Bricks";
193 this.LoadAsset(Image, true, "bricks.jp2");
194 AssetStorage 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-9999-000000000002");
203 Image.Name = "Plywood";
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-000000000003");
214 Image.Name = "Rocks";
215 this.LoadAsset(Image, true, "rocks.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-000000000004");
225 Image.Name = "Granite";
226 this.LoadAsset(Image, true, "granite.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("00000000-0000-0000-9999-000000000005");
236 Image.Name = "Hardwood";
237 this.LoadAsset(Image, true, "hardwood.jp2");
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 Image = new AssetBase();
246 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005");
247 Image.Name = "Prim Base Texture";
248 this.LoadAsset(Image, true, "plywood.jp2");
249 store = new AssetStorage();
250 store.Data = Image.Data;
251 store.Name = Image.Name;
252 store.UUID = Image.FullID;
253 db.Set(store);
254 db.Commit();
255
256 Image = new AssetBase();
257 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
258 Image.Name = "Shape";
259 this.LoadAsset(Image, false, "base_shape.dat");
260 store = new AssetStorage();
261 store.Data = Image.Data;
262 store.Name = Image.Name;
263 store.UUID = Image.FullID;
264 db.Set(store);
265 db.Commit();
266 }
267 catch (Exception e)
268 {
269 Console.WriteLine(e.Message);
270 }
271 }
272
273 private void LoadAsset(AssetBase info, bool image, string filename)
274 {
275
276
277 string dataPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder;
278 string fileName = Path.Combine(dataPath, filename);
279 FileInfo fInfo = new FileInfo(fileName);
280 long numBytes = fInfo.Length;
281 FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
282 byte[] idata = new byte[numBytes];
283 BinaryReader br = new BinaryReader(fStream);
284 idata = br.ReadBytes((int)numBytes);
285 br.Close();
286 fStream.Close();
287 info.Data = idata;
288 //info.loaded=true;
289 }
290
291 /*private GridConfig LoadConfigDll(string dllName)
292 {
293 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
294 GridConfig config = null;
295
296 foreach (Type pluginType in pluginAssembly.GetTypes())
297 {
298 if (pluginType.IsPublic)
299 {
300 if (!pluginType.IsAbstract)
301 {
302 Type typeInterface = pluginType.GetInterface("IGridConfig", true);
303
304 if (typeInterface != null)
305 {
306 IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
307 config = plug.GetConfigObject();
308 break;
309 }
310
311 typeInterface = null;
312 }
313 }
314 }
315 pluginAssembly = null;
316 return config;
317 }*/
318
319 public void RunCmd(string cmd, string[] cmdparams)
320 {
321 switch (cmd)
322 {
323 case "help":
324 m_console.Notice("shutdown - shutdown this asset server (USE CAUTION!)");
325 break;
326
327 case "shutdown":
328 m_console.Close();
329 Environment.Exit(0);
330 break;
331 }
332 }
333
334 public void Show(string ShowWhat)
335 {
336 }
337 }
338}