aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs228
1 files changed, 0 insertions, 228 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs
deleted file mode 100644
index f907ecd..0000000
--- a/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs
+++ /dev/null
@@ -1,228 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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
28using System.Collections.Generic;
29using OpenMetaverse;
30using OpenMetaverse.Packets;
31using Nini.Config;
32using OpenSim.Framework;
33using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes;
35
36namespace OpenSim.Region.Environment.Modules.Agent.AssetDownload
37{
38 public class AssetDownloadModule : IRegionModule
39 {
40 /// <summary>
41 /// Asset requests with data which are ready to be sent back to requesters. This includes textures.
42 /// </summary>
43 private List<AssetRequest> AssetRequests;
44
45 private Scene m_scene;
46 private Dictionary<UUID, Scene> RegisteredScenes = new Dictionary<UUID, Scene>();
47
48 ///
49 /// Assets requests (for each user) which are waiting for asset server data. This includes texture requests
50 /// </summary>
51 private Dictionary<UUID, Dictionary<UUID, AssetRequest>> RequestedAssets;
52
53 public AssetDownloadModule()
54 {
55 RequestedAssets = new Dictionary<UUID, Dictionary<UUID, AssetRequest>>();
56 AssetRequests = new List<AssetRequest>();
57 }
58
59 #region IRegionModule Members
60
61 public void Initialise(Scene scene, IConfigSource config)
62 {
63 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
64 {
65 RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
66 // scene.EventManager.OnNewClient += NewClient;
67 }
68
69 if (m_scene == null)
70 {
71 m_scene = scene;
72 // m_thread = new Thread(new ThreadStart(RunAssetQueue));
73 // m_thread.Name = "AssetDownloadQueueThread";
74 // m_thread.IsBackground = true;
75 // m_thread.Start();
76 // OpenSim.Framework.ThreadTracker.Add(m_thread);
77 }
78 }
79
80 public void PostInitialise()
81 {
82 }
83
84 public void Close()
85 {
86 }
87
88 public string Name
89 {
90 get { return "AssetDownloadModule"; }
91 }
92
93 public bool IsSharedModule
94 {
95 get { return true; }
96 }
97
98 #endregion
99
100 public void NewClient(IClientAPI client)
101 {
102 // client.OnRequestAsset += AddAssetRequest;
103 }
104
105 /// <summary>
106 /// Make an asset request the result of which will be packeted up and sent directly back to the client.
107 /// </summary>
108 /// <param name="userInfo"></param>
109 /// <param name="transferRequest"></param>
110 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest)
111 {
112 UUID requestID = UUID.Zero;
113 byte source = 2;
114 if (transferRequest.TransferInfo.SourceType == 2)
115 {
116 //direct asset request
117 requestID = new UUID(transferRequest.TransferInfo.Params, 0);
118 }
119 else if (transferRequest.TransferInfo.SourceType == 3)
120 {
121 //inventory asset request
122 requestID = new UUID(transferRequest.TransferInfo.Params, 80);
123 source = 3;
124 //Console.WriteLine("asset request " + requestID);
125 }
126
127 //not found asset
128 // so request from asset server
129 Dictionary<UUID, AssetRequest> userRequests = null;
130 if (RequestedAssets.TryGetValue(userInfo.AgentId, out userRequests))
131 {
132 if (!userRequests.ContainsKey(requestID))
133 {
134 AssetRequest request = new AssetRequest();
135 request.RequestUser = userInfo;
136 request.RequestAssetID = requestID;
137 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
138 request.AssetRequestSource = source;
139 request.Params = transferRequest.TransferInfo.Params;
140 userRequests[requestID] = request;
141 m_scene.AssetCache.GetAsset(requestID, AssetCallback, false);
142 }
143 }
144 else
145 {
146 userRequests = new Dictionary<UUID, AssetRequest>();
147 AssetRequest request = new AssetRequest();
148 request.RequestUser = userInfo;
149 request.RequestAssetID = requestID;
150 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
151 request.AssetRequestSource = source;
152 request.Params = transferRequest.TransferInfo.Params;
153 userRequests.Add(requestID, request);
154 RequestedAssets[userInfo.AgentId] = userRequests;
155 m_scene.AssetCache.GetAsset(requestID, AssetCallback, false);
156 }
157 }
158
159 public void AssetCallback(UUID assetID, AssetBase asset)
160 {
161 if (asset != null)
162 {
163 foreach (Dictionary<UUID, AssetRequest> userRequests in RequestedAssets.Values)
164 {
165 if (userRequests.ContainsKey(assetID))
166 {
167 AssetRequest req = userRequests[assetID];
168 if (req != null)
169 {
170 req.AssetInf = asset;
171 req.NumPackets = CalculateNumPackets(asset.Data);
172
173 userRequests.Remove(assetID);
174 AssetRequests.Add(req);
175 }
176 }
177 }
178 }
179 }
180
181 /// <summary>
182 /// Calculate the number of packets required to send the asset to the client.
183 /// </summary>
184 /// <param name="data"></param>
185 /// <returns></returns>
186 private int CalculateNumPackets(byte[] data)
187 {
188 const uint m_maxPacketSize = 600;
189 int numPackets = 1;
190
191 if (data.LongLength > m_maxPacketSize)
192 {
193 // over max number of bytes so split up file
194 long restData = data.LongLength - m_maxPacketSize;
195 int restPackets = (int) ((restData + m_maxPacketSize - 1) / m_maxPacketSize);
196 numPackets += restPackets;
197 }
198
199 return numPackets;
200 }
201
202 #region Nested type: AssetRequest
203
204 public class AssetRequest
205 {
206 public AssetBase AssetInf;
207 public byte AssetRequestSource = 2;
208 public long DataPointer = 0;
209 public int DiscardLevel = -1;
210 public AssetBase ImageInfo;
211 public bool IsTextureRequest;
212 public int NumPackets = 0;
213 public int PacketCounter = 0;
214 public byte[] Params = null;
215 public UUID RequestAssetID;
216 public IClientAPI RequestUser;
217 public UUID TransferRequestID;
218 //public bool AssetInCache;
219 //public int TimeRequested;
220
221 public AssetRequest()
222 {
223 }
224 }
225
226 #endregion
227 }
228}