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