diff options
Some more code refactoring, plus a restructuring of the directories so that the Grid servers can be a separate solution to the region server.
Diffstat (limited to 'OpenGridServices.AssetServer/Main.cs')
-rw-r--r-- | OpenGridServices.AssetServer/Main.cs | 338 |
1 files changed, 0 insertions, 338 deletions
diff --git a/OpenGridServices.AssetServer/Main.cs b/OpenGridServices.AssetServer/Main.cs deleted file mode 100644 index 684d683..0000000 --- a/OpenGridServices.AssetServer/Main.cs +++ /dev/null | |||
@@ -1,338 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (c) OpenSim project, http://osgrid.org/ | ||
3 | |||
4 | |||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.IO; | ||
32 | using System.Text; | ||
33 | using System.Timers; | ||
34 | using System.Net; | ||
35 | using System.Reflection; | ||
36 | using System.Threading; | ||
37 | using libsecondlife; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Sims; | ||
40 | using OpenSim.Framework.Console; | ||
41 | using OpenSim.Framework.Types; | ||
42 | using OpenSim.Framework.Interfaces; | ||
43 | using OpenSim.Framework.Utilities; | ||
44 | using OpenSim.GridInterfaces.Local; // REFACTORING IS NEEDED!!!!!!!!!!! | ||
45 | using OpenSim.Servers; | ||
46 | using Db4objects.Db4o; | ||
47 | using Db4objects.Db4o.Query; | ||
48 | |||
49 | namespace OpenGridServices.AssetServer | ||
50 | { | ||
51 | /// <summary> | ||
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.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "\nEnter help for a list of commands\n"); | ||
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", "OpenGrid", this, false); | ||
85 | MainConsole.Instance = m_console; | ||
86 | } | ||
87 | |||
88 | public void Startup() | ||
89 | { | ||
90 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Setting up asset DB"); | ||
91 | setupDB(); | ||
92 | |||
93 | m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "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.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:setupDB() - creation"); | ||
170 | } | ||
171 | catch (Exception e) | ||
172 | { | ||
173 | db.Close(); | ||
174 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "Main.cs:setupDB() - Exception occured"); | ||
175 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, 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.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "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 | } | ||