aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Agent/Xfer
diff options
context:
space:
mode:
authorDr Scofield2009-02-09 09:16:15 +0000
committerDr Scofield2009-02-09 09:16:15 +0000
commita89d097355526d4dc52a75a9734c6a02c3008ef4 (patch)
treef12e2cf5807762e0fbaf2f304e75b618f62b4cf6 /OpenSim/Region/CoreModules/Agent/Xfer
parentadding bin/ScriptEngines/*/*.{dll,state}, bin/j2kDecodeCache, (diff)
downloadopensim-SC_OLD-a89d097355526d4dc52a75a9734c6a02c3008ef4.zip
opensim-SC_OLD-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.gz
opensim-SC_OLD-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.bz2
opensim-SC_OLD-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.xz
starting phase 2 of the OpenSim.Region.Environment commit: relocating
OpenSim.Region.Environment.Modules.Agent en bloc to OpenSim.Region.CoreModules
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent/Xfer')
-rw-r--r--OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs232
1 files changed, 232 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
new file mode 100644
index 0000000..cb81c0d
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
@@ -0,0 +1,232 @@
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;
29using System.Collections.Generic;
30using OpenMetaverse;
31using Nini.Config;
32using OpenSim.Framework;
33using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes;
35
36namespace OpenSim.Region.CoreModules.Agent.Xfer
37{
38 public class XferModule : IRegionModule, IXfer
39 {
40 private Scene m_scene;
41 public Dictionary<string, byte[]> NewFiles = new Dictionary<string, byte[]>();
42 public Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>();
43
44 #region IRegionModule Members
45
46 public void Initialise(Scene scene, IConfigSource config)
47 {
48 m_scene = scene;
49 m_scene.EventManager.OnNewClient += NewClient;
50
51 m_scene.RegisterModuleInterface<IXfer>(this);
52 }
53
54 public void PostInitialise()
55 {
56 }
57
58 public void Close()
59 {
60 }
61
62 public string Name
63 {
64 get { return "XferModule"; }
65 }
66
67 public bool IsSharedModule
68 {
69 get { return false; }
70 }
71
72 #endregion
73
74 #region IXfer Members
75
76 public bool AddNewFile(string fileName, byte[] data)
77 {
78 lock (NewFiles)
79 {
80 if (NewFiles.ContainsKey(fileName))
81 {
82 NewFiles[fileName] = data;
83 }
84 else
85 {
86 NewFiles.Add(fileName, data);
87 }
88 }
89 return true;
90 }
91
92 #endregion
93
94 public void NewClient(IClientAPI client)
95 {
96 client.OnRequestXfer += RequestXfer;
97 client.OnConfirmXfer += AckPacket;
98 }
99
100 /// <summary>
101 ///
102 /// </summary>
103 /// <param name="remoteClient"></param>
104 /// <param name="xferID"></param>
105 /// <param name="fileName"></param>
106 public void RequestXfer(IClientAPI remoteClient, ulong xferID, string fileName)
107 {
108
109 lock (NewFiles)
110 {
111 if (NewFiles.ContainsKey(fileName))
112 {
113 if (!Transfers.ContainsKey(xferID))
114 {
115 byte[] fileData = NewFiles[fileName];
116 XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient);
117 Transfers.Add(xferID, transaction);
118 NewFiles.Remove(fileName);
119
120 if (transaction.StartSend())
121 {
122 Transfers.Remove(xferID);
123 }
124 }
125 }
126 }
127 }
128
129 public void AckPacket(IClientAPI remoteClient, ulong xferID, uint packet)
130 {
131 if (Transfers.ContainsKey(xferID))
132 {
133 if (Transfers[xferID].AckPacket(packet))
134 {
135 {
136 Transfers.Remove(xferID);
137 }
138 }
139 }
140 }
141
142 #region Nested type: XferDownLoad
143
144 public class XferDownLoad
145 {
146 public IClientAPI Client;
147 private bool complete;
148 public byte[] Data = new byte[0];
149 public int DataPointer = 0;
150 public string FileName = String.Empty;
151 public uint Packet = 0;
152 public uint Serial = 1;
153 public ulong XferID = 0;
154
155 public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client)
156 {
157 FileName = fileName;
158 Data = data;
159 XferID = xferID;
160 Client = client;
161 }
162
163 public XferDownLoad()
164 {
165 }
166
167 /// <summary>
168 /// Start a transfer
169 /// </summary>
170 /// <returns>True if the transfer is complete, false if not</returns>
171 public bool StartSend()
172 {
173 if (Data.Length < 1000)
174 {
175 // for now (testing) we only support files under 1000 bytes
176 byte[] transferData = new byte[Data.Length + 4];
177 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4);
178 Array.Copy(Data, 0, transferData, 4, Data.Length);
179 Client.SendXferPacket(XferID, 0 + 0x80000000, transferData);
180
181 complete = true;
182 }
183 else
184 {
185 byte[] transferData = new byte[1000 + 4];
186 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4);
187 Array.Copy(Data, 0, transferData, 4, 1000);
188 Client.SendXferPacket(XferID, 0, transferData);
189 Packet++;
190 DataPointer = 1000;
191 }
192
193 return complete;
194 }
195
196 /// <summary>
197 /// Respond to an ack packet from the client
198 /// </summary>
199 /// <param name="packet"></param>
200 /// <returns>True if the transfer is complete, false otherwise</returns>
201 public bool AckPacket(uint packet)
202 {
203 if (!complete)
204 {
205 if ((Data.Length - DataPointer) > 1000)
206 {
207 byte[] transferData = new byte[1000];
208 Array.Copy(Data, DataPointer, transferData, 0, 1000);
209 Client.SendXferPacket(XferID, Packet, transferData);
210 Packet++;
211 DataPointer += 1000;
212 }
213 else
214 {
215 byte[] transferData = new byte[Data.Length - DataPointer];
216 Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer);
217 uint endPacket = Packet |= (uint) 0x80000000;
218 Client.SendXferPacket(XferID, endPacket, transferData);
219 Packet++;
220 DataPointer += (Data.Length - DataPointer);
221
222 complete = true;
223 }
224 }
225
226 return complete;
227 }
228 }
229
230 #endregion
231 }
232}