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