diff options
* Some work in progress code: Inventory cache, start of inventory server/service, userprofile cache, inventory handling. (non of it is enabled yet (or at least it shouldn't be).
* Fixed some of the problems with crossing regions when flying: you should no longer sink to ground level when crossing (should keep roughly your right height). Should no longer sometimes get sent back to the centre of the current region when attempting to border cross. But instead sometimes you will find you avatar stop at the edge of region and you will need to start moving again to retry the crossing (which should then work). This code is partly based on Babblefrog's issue #212 patch. [I think I have some ideas of how to solve the stopping at edges problem, just want to get the inventory code done first]
* Capabilities code has now been moved to the OpenSim.Framework.Communications project as some of the caps code will be tightly tied to inventory/asset handling and it was causing a two way reference problem when it was in its own project/dll.
This is a Big commit as I was going to keep my inventory work local until I had it in a working state, in case it brakes anything, but its getting harder to keep in sync with svn.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Communications/Capabilities/Caps.cs (renamed from OpenSim/Region/Capabilities/Caps.cs) | 689 |
1 files changed, 359 insertions, 330 deletions
diff --git a/OpenSim/Region/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs index 06a4bd5..3b1cc6a 100644 --- a/OpenSim/Region/Capabilities/Caps.cs +++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs | |||
@@ -1,330 +1,359 @@ | |||
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 | */ |
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | using System.IO; | 32 | using System.IO; |
33 | using libsecondlife; | 33 | using libsecondlife; |
34 | using OpenSim.Framework.Servers; | 34 | using OpenSim.Framework.Servers; |
35 | using OpenSim.Framework.Types; | 35 | using OpenSim.Framework.Types; |
36 | using OpenSim.Framework.Utilities; | 36 | using OpenSim.Framework.Utilities; |
37 | using OpenSim.Region.Caches; | 37 | using OpenSim.Framework.Communications.Caches; |
38 | 38 | ||
39 | namespace OpenSim.Region.Capabilities | 39 | namespace OpenSim.Region.Capabilities |
40 | { | 40 | { |
41 | public delegate void UpLoadedTexture(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data); | 41 | public delegate void UpLoadedTexture(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data); |
42 | 42 | ||
43 | public class Caps | 43 | public class Caps |
44 | { | 44 | { |
45 | private string m_httpListenerHostName; | 45 | private string m_httpListenerHostName; |
46 | private int m_httpListenPort; | 46 | private int m_httpListenPort; |
47 | private string m_capsObjectPath = "00001-"; | 47 | private string m_capsObjectPath = "00001-"; |
48 | private string m_requestPath = "0000/"; | 48 | private string m_requestPath = "0000/"; |
49 | private string m_mapLayerPath = "0001/"; | 49 | private string m_mapLayerPath = "0001/"; |
50 | private string m_newInventory = "0002/"; | 50 | private string m_newInventory = "0002/"; |
51 | // private string m_requestTexture = "0003/"; | 51 | // private string m_requestTexture = "0003/"; |
52 | //private string eventQueue = "0100/"; | 52 | private string m_notecardUpdatePath = "0004/"; |
53 | private BaseHttpServer httpListener; | 53 | //private string eventQueue = "0100/"; |
54 | private LLUUID agentID; | 54 | private BaseHttpServer httpListener; |
55 | private AssetCache assetCache; | 55 | private LLUUID agentID; |
56 | private int eventQueueCount = 1; | 56 | private AssetCache assetCache; |
57 | private Queue<string> CapsEventQueue = new Queue<string>(); | 57 | private int eventQueueCount = 1; |
58 | 58 | private Queue<string> CapsEventQueue = new Queue<string>(); | |
59 | public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent) | 59 | |
60 | { | 60 | public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent) |
61 | assetCache = assetCach; | 61 | { |
62 | m_capsObjectPath = capsPath; | 62 | assetCache = assetCach; |
63 | httpListener = httpServer; | 63 | m_capsObjectPath = capsPath; |
64 | m_httpListenerHostName = httpListen; | 64 | httpListener = httpServer; |
65 | m_httpListenPort = httpPort; | 65 | m_httpListenerHostName = httpListen; |
66 | agentID = agent; | 66 | m_httpListenPort = httpPort; |
67 | } | 67 | agentID = agent; |
68 | 68 | } | |
69 | /// <summary> | 69 | |
70 | /// | 70 | /// <summary> |
71 | /// </summary> | 71 | /// |
72 | public void RegisterHandlers() | 72 | /// </summary> |
73 | { | 73 | public void RegisterHandlers() |
74 | Console.WriteLine("registering CAPS handlers"); | 74 | { |
75 | string capsBase = "/CAPS/" + m_capsObjectPath; | 75 | Console.WriteLine("registering CAPS handlers"); |
76 | 76 | string capsBase = "/CAPS/" + m_capsObjectPath; | |
77 | httpListener.AddStreamHandler(new LLSDStreamhandler<LLSDMapRequest, LLSDMapLayerResponse>("POST", capsBase + m_mapLayerPath, this.GetMapLayer )); | 77 | |
78 | httpListener.AddStreamHandler( new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>("POST", capsBase + m_newInventory, this.NewAgentInventoryRequest)); | 78 | httpListener.AddStreamHandler(new LLSDStreamhandler<LLSDMapRequest, LLSDMapLayerResponse>("POST", capsBase + m_mapLayerPath, this.GetMapLayer )); |
79 | 79 | httpListener.AddStreamHandler( new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>("POST", capsBase + m_newInventory, this.NewAgentInventoryRequest)); | |
80 | AddLegacyCapsHandler(httpListener, m_requestPath, CapsRequest); | 80 | |
81 | } | 81 | AddLegacyCapsHandler(httpListener, m_requestPath, CapsRequest); |
82 | 82 | AddLegacyCapsHandler(httpListener, m_notecardUpdatePath, NoteCardAgentInventory); | |
83 | [Obsolete("Use BaseHttpServer.AddStreamHandler(new LLSDStreamHandler( LLSDMethod delegate )) instead.")] | 83 | } |
84 | private void AddLegacyCapsHandler(BaseHttpServer httpListener, string path, RestMethod restMethod) | 84 | |
85 | { | 85 | [Obsolete("Use BaseHttpServer.AddStreamHandler(new LLSDStreamHandler( LLSDMethod delegate )) instead.")] |
86 | string capsBase = "/CAPS/" + m_capsObjectPath; | 86 | private void AddLegacyCapsHandler(BaseHttpServer httpListener, string path, RestMethod restMethod) |
87 | httpListener.AddStreamHandler(new RestStreamHandler("POST", capsBase + path, restMethod)); | 87 | { |
88 | } | 88 | string capsBase = "/CAPS/" + m_capsObjectPath; |
89 | 89 | httpListener.AddStreamHandler(new RestStreamHandler("POST", capsBase + path, restMethod)); | |
90 | /// <summary> | 90 | } |
91 | /// | 91 | |
92 | /// </summary> | 92 | /// <summary> |
93 | /// <param name="request"></param> | 93 | /// |
94 | /// <param name="path"></param> | 94 | /// </summary> |
95 | /// <param name="param"></param> | 95 | /// <param name="request"></param> |
96 | /// <returns></returns> | 96 | /// <param name="path"></param> |
97 | public string CapsRequest(string request, string path, string param) | 97 | /// <param name="param"></param> |
98 | { | 98 | /// <returns></returns> |
99 | // Console.WriteLine("caps request " + request); | 99 | public string CapsRequest(string request, string path, string param) |
100 | string result = LLSDHelpers.SerialiseLLSDReply(this.GetCapabilities()); | 100 | { |
101 | return result; | 101 | //Console.WriteLine("caps request " + request); |
102 | } | 102 | string result = LLSDHelpers.SerialiseLLSDReply(this.GetCapabilities()); |
103 | 103 | return result; | |
104 | /// <summary> | 104 | } |
105 | /// | 105 | |
106 | /// </summary> | 106 | /// <summary> |
107 | /// <returns></returns> | 107 | /// |
108 | protected LLSDCapsDetails GetCapabilities() | 108 | /// </summary> |
109 | { | 109 | /// <returns></returns> |
110 | LLSDCapsDetails caps = new LLSDCapsDetails(); | 110 | protected LLSDCapsDetails GetCapabilities() |
111 | string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + m_capsObjectPath; | 111 | { |
112 | caps.MapLayer = capsBaseUrl + m_mapLayerPath; | 112 | LLSDCapsDetails caps = new LLSDCapsDetails(); |
113 | caps.NewFileAgentInventory = capsBaseUrl + m_newInventory; | 113 | string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + m_capsObjectPath; |
114 | //caps.RequestTextureDownload = capsBaseUrl + m_requestTexture; | 114 | caps.MapLayer = capsBaseUrl + m_mapLayerPath; |
115 | // caps.ChatSessionRequest = capsBaseUrl + m_requestTexture; | 115 | caps.NewFileAgentInventory = capsBaseUrl + m_newInventory; |
116 | return caps; | 116 | //caps.RequestTextureDownload = capsBaseUrl + m_requestTexture; |
117 | } | 117 | caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; |
118 | 118 | return caps; | |
119 | /// <summary> | 119 | } |
120 | /// | 120 | |
121 | /// </summary> | 121 | /// <summary> |
122 | /// <param name="mapReq"></param> | 122 | /// |
123 | /// <returns></returns> | 123 | /// </summary> |
124 | public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq) | 124 | /// <param name="mapReq"></param> |
125 | { | 125 | /// <returns></returns> |
126 | LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse(); | 126 | public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq) |
127 | mapResponse.LayerData.Array.Add(this.GetLLSDMapLayerResponse()); | 127 | { |
128 | return mapResponse; | 128 | LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse(); |
129 | } | 129 | mapResponse.LayerData.Array.Add(this.GetLLSDMapLayerResponse()); |
130 | 130 | return mapResponse; | |
131 | /// <summary> | 131 | } |
132 | /// | 132 | |
133 | /// </summary> | 133 | /// <summary> |
134 | /// <returns></returns> | 134 | /// |
135 | protected LLSDMapLayer GetLLSDMapLayerResponse() | 135 | /// </summary> |
136 | { | 136 | /// <returns></returns> |
137 | LLSDMapLayer mapLayer = new LLSDMapLayer(); | 137 | protected LLSDMapLayer GetLLSDMapLayerResponse() |
138 | mapLayer.Right = 5000; | 138 | { |
139 | mapLayer.Top = 5000; | 139 | LLSDMapLayer mapLayer = new LLSDMapLayer(); |
140 | mapLayer.ImageID = new LLUUID("00000000-0000-0000-9999-000000000006"); | 140 | mapLayer.Right = 5000; |
141 | return mapLayer; | 141 | mapLayer.Top = 5000; |
142 | } | 142 | mapLayer.ImageID = new LLUUID("00000000-0000-0000-9999-000000000006"); |
143 | 143 | return mapLayer; | |
144 | /// <summary> | 144 | } |
145 | /// | 145 | |
146 | /// </summary> | 146 | /// <summary> |
147 | /// <param name="request"></param> | 147 | /// |
148 | /// <param name="path"></param> | 148 | /// </summary> |
149 | /// <param name="param"></param> | 149 | /// <param name="request"></param> |
150 | /// <returns></returns> | 150 | /// <param name="path"></param> |
151 | public string RequestTexture(string request, string path, string param) | 151 | /// <param name="param"></param> |
152 | { | 152 | /// <returns></returns> |
153 | Console.WriteLine("texture request " + request); | 153 | public string RequestTexture(string request, string path, string param) |
154 | // Needs implementing (added to remove compiler warning) | 154 | { |
155 | return ""; | 155 | Console.WriteLine("texture request " + request); |
156 | } | 156 | // Needs implementing (added to remove compiler warning) |
157 | 157 | return ""; | |
158 | #region EventQueue (Currently not enabled) | 158 | } |
159 | /// <summary> | 159 | |
160 | /// | 160 | #region EventQueue (Currently not enabled) |
161 | /// </summary> | 161 | /// <summary> |
162 | /// <param name="request"></param> | 162 | /// |
163 | /// <param name="path"></param> | 163 | /// </summary> |
164 | /// <param name="param"></param> | 164 | /// <param name="request"></param> |
165 | /// <returns></returns> | 165 | /// <param name="path"></param> |
166 | public string ProcessEventQueue(string request, string path, string param) | 166 | /// <param name="param"></param> |
167 | { | 167 | /// <returns></returns> |
168 | string res = ""; | 168 | public string ProcessEventQueue(string request, string path, string param) |
169 | 169 | { | |
170 | if (this.CapsEventQueue.Count > 0) | 170 | string res = ""; |
171 | { | 171 | |
172 | lock (this.CapsEventQueue) | 172 | if (this.CapsEventQueue.Count > 0) |
173 | { | 173 | { |
174 | string item = CapsEventQueue.Dequeue(); | 174 | lock (this.CapsEventQueue) |
175 | res = item; | 175 | { |
176 | } | 176 | string item = CapsEventQueue.Dequeue(); |
177 | } | 177 | res = item; |
178 | else | 178 | } |
179 | { | 179 | } |
180 | res = this.CreateEmptyEventResponse(); | 180 | else |
181 | } | 181 | { |
182 | return res; | 182 | res = this.CreateEmptyEventResponse(); |
183 | } | 183 | } |
184 | 184 | return res; | |
185 | /// <summary> | 185 | } |
186 | /// | 186 | |
187 | /// </summary> | 187 | /// <summary> |
188 | /// <param name="caps"></param> | 188 | /// |
189 | /// <param name="ipAddressPort"></param> | 189 | /// </summary> |
190 | /// <returns></returns> | 190 | /// <param name="caps"></param> |
191 | public string CreateEstablishAgentComms(string caps, string ipAddressPort) | 191 | /// <param name="ipAddressPort"></param> |
192 | { | 192 | /// <returns></returns> |
193 | LLSDCapEvent eventItem = new LLSDCapEvent(); | 193 | public string CreateEstablishAgentComms(string caps, string ipAddressPort) |
194 | eventItem.id = eventQueueCount; | 194 | { |
195 | //should be creating a EstablishAgentComms item, but there isn't a class for it yet | 195 | LLSDCapEvent eventItem = new LLSDCapEvent(); |
196 | eventItem.events.Array.Add(new LLSDEmpty()); | 196 | eventItem.id = eventQueueCount; |
197 | string res = LLSDHelpers.SerialiseLLSDReply(eventItem); | 197 | //should be creating a EstablishAgentComms item, but there isn't a class for it yet |
198 | eventQueueCount++; | 198 | eventItem.events.Array.Add(new LLSDEmpty()); |
199 | 199 | string res = LLSDHelpers.SerialiseLLSDReply(eventItem); | |
200 | this.CapsEventQueue.Enqueue(res); | 200 | eventQueueCount++; |
201 | return res; | 201 | |
202 | } | 202 | this.CapsEventQueue.Enqueue(res); |
203 | 203 | return res; | |
204 | /// <summary> | 204 | } |
205 | /// | 205 | |
206 | /// </summary> | 206 | /// <summary> |
207 | /// <returns></returns> | 207 | /// |
208 | public string CreateEmptyEventResponse() | 208 | /// </summary> |
209 | { | 209 | /// <returns></returns> |
210 | LLSDCapEvent eventItem = new LLSDCapEvent(); | 210 | public string CreateEmptyEventResponse() |
211 | eventItem.id = eventQueueCount; | 211 | { |
212 | eventItem.events.Array.Add(new LLSDEmpty()); | 212 | LLSDCapEvent eventItem = new LLSDCapEvent(); |
213 | string res = LLSDHelpers.SerialiseLLSDReply(eventItem); | 213 | eventItem.id = eventQueueCount; |
214 | eventQueueCount++; | 214 | eventItem.events.Array.Add(new LLSDEmpty()); |
215 | return res; | 215 | string res = LLSDHelpers.SerialiseLLSDReply(eventItem); |
216 | } | 216 | eventQueueCount++; |
217 | #endregion | 217 | return res; |
218 | 218 | } | |
219 | /// <summary> | 219 | #endregion |
220 | /// | 220 | |
221 | /// </summary> | 221 | /// <summary> |
222 | /// <param name="llsdRequest"></param> | 222 | /// |
223 | /// <returns></returns> | 223 | /// </summary> |
224 | public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest) | 224 | /// <param name="request"></param> |
225 | { | 225 | /// <param name="path"></param> |
226 | // Console.WriteLine("asset upload request via CAPS"); | 226 | /// <param name="param"></param> |
227 | string assetName = llsdRequest.name; | 227 | /// <returns></returns> |
228 | string capsBase = "/CAPS/" + m_capsObjectPath; | 228 | public string NoteCardAgentInventory(string request, string path, string param) |
229 | LLUUID newAsset = LLUUID.Random(); | 229 | { |
230 | LLUUID newInvItem = LLUUID.Random(); | 230 | Console.WriteLine("notecard update request " + request); |
231 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | 231 | string assetName = "notecardupdate"; |
232 | 232 | string capsBase = "/CAPS/" + m_capsObjectPath; | |
233 | AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener); | 233 | LLUUID newAsset = LLUUID.Random(); |
234 | httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); | 234 | LLUUID newInvItem = LLUUID.Random(); |
235 | string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath; | 235 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); |
236 | 236 | ||
237 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | 237 | AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener); |
238 | uploadResponse.uploader = uploaderURL; | 238 | httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); |
239 | uploadResponse.state = "upload"; | 239 | string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath; |
240 | uploader.OnUpLoad += this.UploadCompleteHandler; | 240 | |
241 | return uploadResponse; | 241 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); |
242 | } | 242 | uploadResponse.uploader = uploaderURL; |
243 | 243 | uploadResponse.state = "upload"; | |
244 | /// <summary> | 244 | // uploader.OnUpLoad += this.UploadCompleteHandler; |
245 | /// | 245 | return LLSDHelpers.SerialiseLLSDReply(uploadResponse); |
246 | /// </summary> | 246 | } |
247 | /// <param name="assetID"></param> | 247 | |
248 | /// <param name="inventoryItem"></param> | 248 | /// <summary> |
249 | /// <param name="data"></param> | 249 | /// |
250 | public void UploadCompleteHandler(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data) | 250 | /// </summary> |
251 | { | 251 | /// <param name="llsdRequest"></param> |
252 | AssetBase asset; | 252 | /// <returns></returns> |
253 | asset = new AssetBase(); | 253 | public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest) |
254 | asset.FullID = assetID; | 254 | { |
255 | asset.Type = 0; | 255 | // Console.WriteLine("asset upload request via CAPS"); |
256 | asset.InvType = 0; | 256 | string assetName = llsdRequest.name; |
257 | asset.Name = assetName; | 257 | string capsBase = "/CAPS/" + m_capsObjectPath; |
258 | asset.Data = data; | 258 | LLUUID newAsset = LLUUID.Random(); |
259 | this.assetCache.AddAsset(asset); | 259 | LLUUID newInvItem = LLUUID.Random(); |
260 | } | 260 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); |
261 | 261 | ||
262 | public class AssetUploader | 262 | AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener); |
263 | { | 263 | httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); |
264 | public event UpLoadedTexture OnUpLoad; | 264 | string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath; |
265 | 265 | ||
266 | private string uploaderPath = ""; | 266 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); |
267 | private LLUUID newAssetID; | 267 | uploadResponse.uploader = uploaderURL; |
268 | private LLUUID inventoryItemID; | 268 | uploadResponse.state = "upload"; |
269 | private BaseHttpServer httpListener; | 269 | uploader.OnUpLoad += this.UploadCompleteHandler; |
270 | private bool SaveImages = false; | 270 | return uploadResponse; |
271 | private string m_assetName = ""; | 271 | } |
272 | 272 | ||
273 | /// <summary> | 273 | /// <summary> |
274 | /// | 274 | /// |
275 | /// </summary> | 275 | /// </summary> |
276 | /// <param name="assetID"></param> | 276 | /// <param name="assetID"></param> |
277 | /// <param name="inventoryItem"></param> | 277 | /// <param name="inventoryItem"></param> |
278 | /// <param name="path"></param> | 278 | /// <param name="data"></param> |
279 | /// <param name="httpServer"></param> | 279 | public void UploadCompleteHandler(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data) |
280 | public AssetUploader(string assetName, LLUUID assetID, LLUUID inventoryItem, string path, BaseHttpServer httpServer) | 280 | { |
281 | { | 281 | AssetBase asset; |
282 | m_assetName = assetName; | 282 | asset = new AssetBase(); |
283 | newAssetID = assetID; | 283 | asset.FullID = assetID; |
284 | inventoryItemID = inventoryItem; | 284 | asset.Type = 0; |
285 | uploaderPath = path; | 285 | asset.InvType = 0; |
286 | httpListener = httpServer; | 286 | asset.Name = assetName; |
287 | } | 287 | asset.Data = data; |
288 | 288 | this.assetCache.AddAsset(asset); | |
289 | /// <summary> | 289 | } |
290 | /// | 290 | |
291 | /// </summary> | 291 | public class AssetUploader |
292 | /// <param name="data"></param> | 292 | { |
293 | /// <param name="path"></param> | 293 | public event UpLoadedTexture OnUpLoad; |
294 | /// <param name="param"></param> | 294 | |
295 | /// <returns></returns> | 295 | private string uploaderPath = ""; |
296 | public string uploaderCaps(byte[] data, string path, string param) | 296 | private LLUUID newAssetID; |
297 | { | 297 | private LLUUID inventoryItemID; |
298 | LLUUID inv = this.inventoryItemID; | 298 | private BaseHttpServer httpListener; |
299 | string res = ""; | 299 | private bool SaveImages = true; |
300 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | 300 | private string m_assetName = ""; |
301 | uploadComplete.new_asset = newAssetID.ToStringHyphenated(); | 301 | |
302 | uploadComplete.new_inventory_item = inv; | 302 | /// <summary> |
303 | uploadComplete.state = "complete"; | 303 | /// |
304 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | 304 | /// </summary> |
305 | 305 | /// <param name="assetID"></param> | |
306 | httpListener.RemoveStreamHandler("POST", uploaderPath); | 306 | /// <param name="inventoryItem"></param> |
307 | 307 | /// <param name="path"></param> | |
308 | if(this.SaveImages) | 308 | /// <param name="httpServer"></param> |
309 | this.SaveImageToFile(m_assetName + ".jp2", data); | 309 | public AssetUploader(string assetName, LLUUID assetID, LLUUID inventoryItem, string path, BaseHttpServer httpServer) |
310 | 310 | { | |
311 | if (OnUpLoad != null) | 311 | m_assetName = assetName; |
312 | { | 312 | newAssetID = assetID; |
313 | OnUpLoad(m_assetName, newAssetID, inv, data); | 313 | inventoryItemID = inventoryItem; |
314 | } | 314 | uploaderPath = path; |
315 | 315 | httpListener = httpServer; | |
316 | return res; | 316 | } |
317 | } | 317 | |
318 | 318 | /// <summary> | |
319 | private void SaveImageToFile(string filename, byte[] data) | 319 | /// |
320 | { | 320 | /// </summary> |
321 | 321 | /// <param name="data"></param> | |
322 | FileStream fs = File.Create(filename); | 322 | /// <param name="path"></param> |
323 | BinaryWriter bw = new BinaryWriter(fs); | 323 | /// <param name="param"></param> |
324 | bw.Write(data); | 324 | /// <returns></returns> |
325 | bw.Close(); | 325 | public string uploaderCaps(byte[] data, string path, string param) |
326 | fs.Close(); | 326 | { |
327 | } | 327 | LLUUID inv = this.inventoryItemID; |
328 | } | 328 | string res = ""; |
329 | } | 329 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); |
330 | } | 330 | uploadComplete.new_asset = newAssetID.ToStringHyphenated(); |
331 | uploadComplete.new_inventory_item = inv; | ||
332 | uploadComplete.state = "complete"; | ||
333 | |||
334 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
335 | |||
336 | httpListener.RemoveStreamHandler("POST", uploaderPath); | ||
337 | |||
338 | if(this.SaveImages) | ||
339 | this.SaveImageToFile(m_assetName + ".jp2", data); | ||
340 | |||
341 | if (OnUpLoad != null) | ||
342 | { | ||
343 | OnUpLoad(m_assetName, newAssetID, inv, data); | ||
344 | } | ||
345 | |||
346 | return res; | ||
347 | } | ||
348 | |||
349 | private void SaveImageToFile(string filename, byte[] data) | ||
350 | { | ||
351 | FileStream fs = File.Create(filename); | ||
352 | BinaryWriter bw = new BinaryWriter(fs); | ||
353 | bw.Write(data); | ||
354 | bw.Close(); | ||
355 | fs.Close(); | ||
356 | } | ||
357 | } | ||
358 | } | ||
359 | } | ||