aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/XferModule.cs
diff options
context:
space:
mode:
authorSean Dague2007-10-19 20:27:34 +0000
committerSean Dague2007-10-19 20:27:34 +0000
commit139994757c7dab04dd03801266525e8c53395a5e (patch)
tree003ec2557de6dd80dbe1e7bc78efe8958d02d5ae /OpenSim/Region/Environment/Modules/XferModule.cs
parent* Test thy commits! (oops, sorry!) (diff)
downloadopensim-SC-139994757c7dab04dd03801266525e8c53395a5e.zip
opensim-SC-139994757c7dab04dd03801266525e8c53395a5e.tar.gz
opensim-SC-139994757c7dab04dd03801266525e8c53395a5e.tar.bz2
opensim-SC-139994757c7dab04dd03801266525e8c53395a5e.tar.xz
changes to pass nini config object to the modules that get
loaded so that they may read out any bits they are interested in
Diffstat (limited to 'OpenSim/Region/Environment/Modules/XferModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/XferModule.cs403
1 files changed, 202 insertions, 201 deletions
diff --git a/OpenSim/Region/Environment/Modules/XferModule.cs b/OpenSim/Region/Environment/Modules/XferModule.cs
index 7bc831f..2adb1c9 100644
--- a/OpenSim/Region/Environment/Modules/XferModule.cs
+++ b/OpenSim/Region/Environment/Modules/XferModule.cs
@@ -1,201 +1,202 @@
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*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using libsecondlife; 31using libsecondlife;
32using OpenSim.Framework.Interfaces; 32using OpenSim.Framework.Interfaces;
33using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes; 34using OpenSim.Region.Environment.Scenes;
35 35using Nini.Config;
36namespace OpenSim.Region.Environment.Modules 36
37{ 37namespace OpenSim.Region.Environment.Modules
38 public class XferModule : IRegionModule, IXfer 38{
39 { 39 public class XferModule : IRegionModule, IXfer
40 public Dictionary<string, byte[]> NewFiles = new Dictionary<string, byte[]>(); 40 {
41 public Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>(); 41 public Dictionary<string, byte[]> NewFiles = new Dictionary<string, byte[]>();
42 42 public Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>();
43 private Scene m_scene; 43
44 44 private Scene m_scene;
45 public XferModule() 45
46 { 46 public XferModule()
47 } 47 {
48 48 }
49 public void Initialise(Scene scene) 49
50 { 50 public void Initialise(Scene scene, IConfigSource config)
51 m_scene = scene; 51 {
52 m_scene.EventManager.OnNewClient += NewClient; 52 m_scene = scene;
53 53 m_scene.EventManager.OnNewClient += NewClient;
54 m_scene.RegisterModuleInterface<IXfer>(this); 54
55 } 55 m_scene.RegisterModuleInterface<IXfer>(this);
56 56 }
57 public void PostInitialise() 57
58 { 58 public void PostInitialise()
59 } 59 {
60 60 }
61 public void Close() 61
62 { 62 public void Close()
63 } 63 {
64 64 }
65 public string Name 65
66 { 66 public string Name
67 get { return "XferModule"; } 67 {
68 } 68 get { return "XferModule"; }
69 69 }
70 public bool IsSharedModule 70
71 { 71 public bool IsSharedModule
72 get { return false; } 72 {
73 } 73 get { return false; }
74 74 }
75 public void NewClient(IClientAPI client) 75
76 { 76 public void NewClient(IClientAPI client)
77 client.OnRequestXfer += RequestXfer; 77 {
78 client.OnConfirmXfer += AckPacket; 78 client.OnRequestXfer += RequestXfer;
79 } 79 client.OnConfirmXfer += AckPacket;
80 80 }
81 /// <summary> 81
82 /// 82 /// <summary>
83 /// </summary> 83 ///
84 /// <param name="remoteClient"></param> 84 /// </summary>
85 /// <param name="xferID"></param> 85 /// <param name="remoteClient"></param>
86 /// <param name="fileName"></param> 86 /// <param name="xferID"></param>
87 public void RequestXfer(IClientAPI remoteClient, ulong xferID, string fileName) 87 /// <param name="fileName"></param>
88 { 88 public void RequestXfer(IClientAPI remoteClient, ulong xferID, string fileName)
89 lock (NewFiles) 89 {
90 { 90 lock (NewFiles)
91 if (NewFiles.ContainsKey(fileName)) 91 {
92 { 92 if (NewFiles.ContainsKey(fileName))
93 if (!Transfers.ContainsKey(xferID)) 93 {
94 { 94 if (!Transfers.ContainsKey(xferID))
95 byte[] fileData = NewFiles[fileName]; 95 {
96 XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient); 96 byte[] fileData = NewFiles[fileName];
97 Transfers.Add(xferID, transaction); 97 XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient);
98 NewFiles.Remove(fileName); 98 Transfers.Add(xferID, transaction);
99 transaction.StartSend(); 99 NewFiles.Remove(fileName);
100 } 100 transaction.StartSend();
101 } 101 }
102 } 102 }
103 } 103 }
104 104 }
105 public void AckPacket(IClientAPI remoteClient, ulong xferID, uint packet) 105
106 { 106 public void AckPacket(IClientAPI remoteClient, ulong xferID, uint packet)
107 if (Transfers.ContainsKey(xferID)) 107 {
108 { 108 if (Transfers.ContainsKey(xferID))
109 Transfers[xferID].AckPacket(packet); 109 {
110 } 110 Transfers[xferID].AckPacket(packet);
111 } 111 }
112 112 }
113 public bool AddNewFile(string fileName, byte[] data) 113
114 { 114 public bool AddNewFile(string fileName, byte[] data)
115 lock (NewFiles) 115 {
116 { 116 lock (NewFiles)
117 if (NewFiles.ContainsKey(fileName)) 117 {
118 { 118 if (NewFiles.ContainsKey(fileName))
119 NewFiles[fileName] = data; 119 {
120 } 120 NewFiles[fileName] = data;
121 else 121 }
122 { 122 else
123 NewFiles.Add(fileName, data); 123 {
124 } 124 NewFiles.Add(fileName, data);
125 } 125 }
126 return true; 126 }
127 } 127 return true;
128 128 }
129 129
130 public class XferDownLoad 130
131 { 131 public class XferDownLoad
132 public byte[] Data = new byte[0]; 132 {
133 public string FileName = ""; 133 public byte[] Data = new byte[0];
134 public ulong XferID = 0; 134 public string FileName = "";
135 public int DataPointer = 0; 135 public ulong XferID = 0;
136 public uint Packet = 0; 136 public int DataPointer = 0;
137 public IClientAPI Client; 137 public uint Packet = 0;
138 public uint Serial = 1; 138 public IClientAPI Client;
139 private bool complete = false; 139 public uint Serial = 1;
140 140 private bool complete = false;
141 public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client) 141
142 { 142 public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client)
143 FileName = fileName; 143 {
144 Data = data; 144 FileName = fileName;
145 XferID = xferID; 145 Data = data;
146 Client = client; 146 XferID = xferID;
147 } 147 Client = client;
148 148 }
149 public XferDownLoad() 149
150 { 150 public XferDownLoad()
151 } 151 {
152 152 }
153 public void StartSend() 153
154 { 154 public void StartSend()
155 if (Data.Length < 1000) 155 {
156 { 156 if (Data.Length < 1000)
157 // for now (testing ) we only support files under 1000 bytes 157 {
158 byte[] transferData = new byte[Data.Length + 4]; 158 // for now (testing ) we only support files under 1000 bytes
159 Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4); 159 byte[] transferData = new byte[Data.Length + 4];
160 Array.Copy(Data, 0, transferData, 4, Data.Length); 160 Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4);
161 Client.SendXferPacket(XferID, 0 + 0x80000000, transferData); 161 Array.Copy(Data, 0, transferData, 4, Data.Length);
162 complete = true; 162 Client.SendXferPacket(XferID, 0 + 0x80000000, transferData);
163 } 163 complete = true;
164 else 164 }
165 { 165 else
166 byte[] transferData = new byte[1000 + 4]; 166 {
167 Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4); 167 byte[] transferData = new byte[1000 + 4];
168 Array.Copy(Data, 0, transferData, 4, 1000); 168 Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4);
169 Client.SendXferPacket(XferID, 0, transferData); 169 Array.Copy(Data, 0, transferData, 4, 1000);
170 Packet++; 170 Client.SendXferPacket(XferID, 0, transferData);
171 DataPointer = 1000; 171 Packet++;
172 } 172 DataPointer = 1000;
173 } 173 }
174 174 }
175 public void AckPacket(uint packet) 175
176 { 176 public void AckPacket(uint packet)
177 if (!complete) 177 {
178 { 178 if (!complete)
179 if ((Data.Length - DataPointer) > 1000) 179 {
180 { 180 if ((Data.Length - DataPointer) > 1000)
181 byte[] transferData = new byte[1000]; 181 {
182 Array.Copy(Data, DataPointer, transferData, 0, 1000); 182 byte[] transferData = new byte[1000];
183 Client.SendXferPacket(XferID, Packet, transferData); 183 Array.Copy(Data, DataPointer, transferData, 0, 1000);
184 Packet++; 184 Client.SendXferPacket(XferID, Packet, transferData);
185 DataPointer += 1000; 185 Packet++;
186 } 186 DataPointer += 1000;
187 else 187 }
188 { 188 else
189 byte[] transferData = new byte[Data.Length - DataPointer]; 189 {
190 Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer); 190 byte[] transferData = new byte[Data.Length - DataPointer];
191 uint endPacket = Packet |= (uint) 0x80000000; 191 Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer);
192 Client.SendXferPacket(XferID, endPacket, transferData); 192 uint endPacket = Packet |= (uint) 0x80000000;
193 Packet++; 193 Client.SendXferPacket(XferID, endPacket, transferData);
194 DataPointer += (Data.Length - DataPointer); 194 Packet++;
195 complete = true; 195 DataPointer += (Data.Length - DataPointer);
196 } 196 complete = true;
197 } 197 }
198 } 198 }
199 } 199 }
200 } 200 }
201} 201 }
202}